2015-05-19 3 views
1

Я выделить буферы и начать аудио очереди, какAudio Queue опустошения буфера Ошибка

// allocate the buffers and prime the queue with some data before starting 
AudioQueueBufferRef buffers[kNumberPlaybackBuffers]; 
isDone = false; 
packetPosition = 0; 
int i; 
for (i = 0; i < kNumberPlaybackBuffers; ++i) 
{ 
    CheckError(AudioQueueAllocateBuffer(queue, packetBufferSize, &buffers[i]), "AudioQueueAllocateBuffer failed"); 

    // manually invoke callback to fill buffers with data 
    MyAQOutputCallBack((__bridge void *)(self), queue, buffers[i]); 

    // EOF (the entire file's contents fit in the buffers) 
    if (isDone) 
     break; 
} 

// start the queue. this function returns immedatly and begins 
// invoking the callback, as needed, asynchronously. 
CheckError(AudioQueueStart(queue, NULL), "AudioQueueStart failed"); 

Над кодом успешно вызвать outputcallback функцию

#pragma mark playback callback function 
static void MyAQOutputCallBack(void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inCompleteAQBuffer) 
{ 
    // this is called by the audio queue when it has finished decoding our data. 
    // The buffer is now free to be reused. 
    printf("MyAQOutputCallBack...\n"); 
    printf("######################\n"); 
    AnotherPlayer* player = (__bridge AnotherPlayer *)inUserData; 
    [player handleBufferCompleteForQueue:inAQ buffer:inCompleteAQBuffer]; 
} 

, который вызывает функцию Objective-C, где я заполнить буферы и enqueu их.

- (void)handleBufferCompleteForQueue:(AudioQueueRef)inAQ 
           buffer:(AudioQueueBufferRef)inBuffer 
{ 
    BOOL isBufferFilled=NO; 

    size_t bytesFilled=0;    // how many bytes have been filled 
    size_t packetsFilled=0;   // how many packets have been filled 
    size_t bufSpaceRemaining; 

    while (isBufferFilled==NO) { 
     if (currentlyReadingBufferIndex<[sharedCache.baseAudioCache count]) { 

      printf("currentlyReadingBufferIndex %i\n",currentlyReadingBufferIndex); 
      //loop thru untill buffer is enqued 
      if (sharedCache.baseAudioCache) { 

       NSMutableDictionary *myDict= [[NSMutableDictionary alloc] init]; 
       myDict=[sharedCache.baseAudioCache objectAtIndex:currentlyReadingBufferIndex]; 

       //UInt32 inNumberBytes =[[myDict objectForKey:@"inNumberBytes"] intValue]; 
       UInt32 inNumberPackets =[[myDict objectForKey:@"inNumberPackets"] intValue]; 
       NSData *convert=[myDict objectForKey:@"inInputData"]; 
       const void *inInputData=(const char *)[convert bytes]; 

       //AudioStreamPacketDescription *inPacketDescriptions; 
       AudioStreamPacketDescription *inPacketDescriptions= malloc(sizeof(AudioStreamPacketDescription)); 

       NSNumber *mStartOffset = [myDict objectForKey:@"mStartOffset"]; 
       NSNumber *mDataByteSize = [myDict objectForKey:@"mDataByteSize"]; 
       NSNumber *mVariableFramesInPacket = [myDict objectForKey:@"mVariableFramesInPacket"]; 

       inPacketDescriptions->mVariableFramesInPacket=[mVariableFramesInPacket intValue]; 
       inPacketDescriptions->mStartOffset=[mStartOffset intValue]; 
       inPacketDescriptions->mDataByteSize=[mDataByteSize intValue]; 



       for (int i = 0; i < inNumberPackets; ++i) 
       { 
        SInt64 packetOffset = [mStartOffset intValue]; 
        SInt64 packetSize = [mDataByteSize intValue]; 
        printf("packetOffset %lli\n",packetOffset); 
        printf("packetSize %lli\n",packetSize); 

        currentlyReadingBufferIndex++; 

        if (packetSize > packetBufferSize) 
        { 
         //[self failWithErrorCode:AS_AUDIO_BUFFER_TOO_SMALL]; 
        } 

        bufSpaceRemaining = packetBufferSize - bytesFilled; 
        printf("bufSpaceRemaining %zu\n",bufSpaceRemaining); 

        // if the space remaining in the buffer is not enough for this packet, then enqueue the buffer. 
        if (bufSpaceRemaining < packetSize) 
        { 
         CheckError(AudioQueueEnqueueBuffer(inAQ, 
                  inBuffer, 
                  packetsFilled, 
                  packetDescs), "AudioQueueEnqueueBuffer failed"); 

         //      OSStatus status = AudioQueueEnqueueBuffer(inAQ, 
         //                 fillBuf, 
         //                 packetsFilled, 
         //                 packetDescs); 
         //      if (status) { 
         //       // This is also not called. 
         //       NSLog(@"Error enqueueing buffer %d", (int)status); 
         //      } 

         //printf("bufSpaceRemaining < packetSize\n"); 
         //go to the next item on keepbuffer array 
         isBufferFilled=YES; 
        } 
        @synchronized(self) 
        { 

         // 
         // If there was some kind of issue with enqueueBuffer and we didn't 
         // make space for the new audio data then back out 
         // 
         if (bytesFilled + packetSize > packetBufferSize) 
         { 
          return; 
         } 

         // copy data to the audio queue buffer 
         //error -66686 refers to 
         //kAudioQueueErr_BufferEmpty   = -66686 
         memcpy((char*)inBuffer->mAudioData + bytesFilled, (const char*)inInputData + packetOffset, packetSize); 
         //memcpy(inBuffer->mAudioData, (const char*)inInputData + packetOffset, packetSize); 

         // fill out packet description 
         packetDescs[packetsFilled] = inPacketDescriptions[0]; 
         packetDescs[packetsFilled].mStartOffset = bytesFilled; 
         bytesFilled += packetSize; 
         packetsFilled += 1; 
         free(inPacketDescriptions); 
        } 

        // if that was the last free packet description, then enqueue the buffer. 
        size_t packetsDescsRemaining = kAQMaxPacketDescs - packetsFilled; 
        if (packetsDescsRemaining == 0) { 
         CheckError(AudioQueueEnqueueBuffer(inAQ, 
                  inBuffer, 
                  packetsFilled, 
                  packetDescs), "AudioQueueEnqueueBuffer failed"); 
         printf("if that was the last free packet description, then enqueue the buffer\n"); 
         //go to the next item on keepbuffer array 
         isBufferFilled=YES; 
        } 

       } 

      } 
     } 
     else 
     { 
      isDone=YES; 
     } 
    } 

} 

Здесь когда буфер полон я называю AudioQueueEnqueueBuffer, я думаю, что проблема может быть memcpy(, но через точку разрыва, кажется, есть некоторые данные в буфере, но он по-прежнему дает мне

Ошибки: AudioQueueEnqueueBuffer не удался (-66686) Это означает, что в AudioQueue.h kAudioQueueErr_BufferEmpty = -66686,

enter image description here

ответ

1

заполнения mAudioDataByteSize буфера перед тем enquing его решить проблему

inBuffer->mAudioDataByteSize = bytesFilled; 
         CheckError(AudioQueueEnqueueBuffer(inAQ, 
                  inBuffer, 
                  packetsFilled, 
                  packetDescs), "AudioQueueEnqueueBuffer failed"); 

 Смежные вопросы

  • Нет связанных вопросов^_^