我正在使用网络应用程序,所以我会丢失数据包或我开始播放的地方,没有播放数据。这是我的源代码:
struct AQPlayerState *pAqData = (struct AQPlayerState *) m_aqData ;
UInt32 numBytesReadFromFile = 0 ;
UInt32 numPackets = 0 ;
char * pdata = (char *)inBuffer->mAudioData ;
for ( int i = 0 ; i < pAqData->mNumPacketsToRead ; ++i )
{
unsigned int uiRead =GetOneFrame(pdata, pAqData->bufferByteSize - numBytesReadFromFile) ;
if ( uiRead == 0 )
break ;
AudioStreamPacketDescription * packetDescs = pAqData->mPacketDescs + i ;
packetDescs->mDataByteSize = uiRead ;
packetDescs->mStartOffset = numBytesReadFromFile ;
packetDescs->mVariableFramesInPacket = 0 ;
numBytesReadFromFile += uiRead ;
pdata += uiRead ;
++numPackets ;
}
if (numPackets > 0)
{
inBuffer->mAudioDataByteSize = numBytesReadFromFile ;
OSStatus state = AudioQueueEnqueueBuffer (pAqData->mQueue, inBuffer, (pAqData->mPacketDescs ? numPackets : 0), pAqData->mPacketDescs) ;
NSLog(@"HandleOutputBuffer packet count:%lu, res:%lu", numPackets, state) ;
}
else
{
inBuffer->mAudioDataByteSize = 0 ;
(*(pAqData->mPacketDescs)).mDataByteSize = 0 ;
(*(pAqData->mPacketDescs)).mStartOffset = 0 ;
(*(pAqData->mPacketDescs)).mVariableFramesInPacket = 0 ;
OSStatus state = AudioQueueEnqueueBuffer (pAqData->mQueue, inBuffer, 0, nil) ;
NSLog(@"no packet: enqueuebuffer res:%ld", state) ;
}
但如果这些不是数据包,我会收到错误 kAudioQueueErr_BufferEmpty,所以我只想知道如何使用 aac_he 类型播放静音帧(vbr)