我已经设置了音频格式为 kAudioFormatMPEG4AAC(我相信是 AAC-LC)的音频队列。我正在寻找一些代码来通过 RTP 发送这些 AAC 数据包(我只需要添加一个标头吗?)以及制作一个好的 SDP 的提示,因为我没有找到任何关于 iphone AAC 硬件编码器的文档。我试过这个没有成功:
-(OSStatus) initializeAQ{
aqData.mDataFormat.mSampleRate = 44100;
aqData.mDataFormat.mFormatID = kAudioFormatMPEG4AAC;
aqData.mDataFormat.mFormatFlags = 0;
aqData.mDataFormat.mBytesPerPacket = 0; // 0 for VBR
aqData.mDataFormat.mFramesPerPacket = 1024;
aqData.mDataFormat.mBytesPerFrame = 0; // 0 for compressed format
aqData.mDataFormat.mChannelsPerFrame = 1;
aqData.mDataFormat.mBitsPerChannel = 0; // 0 for compressed format
aqData.bufferByteSize = 0x1388; // quite random
AudioQueueNewInput(&aqData.mDataFormat, HandleInputBuffer, &aqData, CFRunLoopGetMain(), kCFRunLoopCommonModes, 0, &aqData.mQueue);
aqData.mCurrentPacket = 0;
aqData.mIsRunning = true;
//--- prepare set of audio queue buffers ---//
for(int i = 0 ; i < nBuffer ; i++){
AudioQueueAllocateBuffer(aqData.mQueue, aqData.bufferByteSize, &aqData.mBuffers[i]);
AudioQueueEnqueueBuffer(aqData.mQueue, aqData.mBuffers[i], 0, NULL);
}
NSLog(@"starting audio queue");
//--- start ---//
return AudioQueueStart(aqData.mQueue, NULL);
}
static void HandleInputBuffer(
void *aqData,
AudioQueueRef inAq,
AudioQueueBufferRef inBuffer,
const AudioTimeStamp *inStartTime,
UInt32 inNumPackets,
const AudioStreamPacketDescription *inPacketDesc
) {
AQRecorderState *pAqData = (AQRecorderState*) aqData;
if( inNumPackets == 0 && pAqData->mDataFormat.mBytesPerPacket != 0 ){
inNumPackets = inBuffer->mAudioDataByteSize/pAqData->mDataFormat.mBytesPerPacket;
}
UInt32 x = 0;
for(; x < inNumPackets ; x++){
SInt64 offset = inPacketDesc[x].mStartOffset;
UInt32 len = inPacketDesc[x].mDataByteSize;
unsigned char *packet[len];
bzero(packet, len);
memcpy(packet,(unsigned char*)(inBuffer->mAudioData)+offset,len);
NSData* data = [[NSData alloc]initWithBytes:packet length:len];
//[s send:data];
[s send:data withTime:inStartTime->mHostTime];
}
AudioQueueEnqueueBuffer(pAqData->mQueue,inBuffer,0,NULL);
}
send() 添加一个像这样的 RTP 标头并通过 udp 发送数据包。