Issue with Audio Queue Implementation

# I amtrying to implement real-time streaming of voice i.e., here we need to records voice as small chunks


# I tried to implement this using AudioQueue concept in Objective-C.


# But , the app crashes when trying to record the voice. It crashes when callback method is called for recording.


# I have attached sample code snippet which I’ve used for implementation. Please help me in resolving the issue

- (void)startRecording
{
    [self setupAudioFormat:&recordState.dataFormat];
  
    recordState.currentPacket = 0;
  
    OSStatus status;
    status = AudioQueueNewInput(&recordState.dataFormat,
                                AudioInputCallback,
                                &recordState,
                                CFRunLoopGetCurrent(),
                                kCFRunLoopCommonModes,
                                0,
                                &recordState.queue);
  
    if (status == 0)
    {
        // Prime recording buffers with empty data
        for (int i = 0; i < NUM_BUFFERS; i++)
        {
            AudioQueueAllocateBuffer(recordState.queue, 16000, &recordState.buffers[i]);
            AudioQueueEnqueueBuffer (recordState.queue, recordState.buffers[i], 0, NULL);
        }
      
        status = AudioFileCreateWithURL(fileURL,
                                        kAudioFileAIFFType,
                                        &recordState.dataFormat,
                                        kAudioFileFlags_EraseFile,
                                        &recordState.audioFile);
        if (status == 0)
        {
            recordState.recording = true;
            status = AudioQueueStart(recordState.queue, NULL);
            if (status == 0)
            {
                //labelStatus.text = @"Recording";
            }
        }
    }
  
    if (status != 0)
    {
        [self stopRecording];
        //labelStatus.text = @"Record Failed";
    }
}
void AudioInputCallback(void * inUserData,
                        AudioQueueRef inAQ,
                        AudioQueueBufferRef inBuffer,
                        const AudioTimeStamp * inStartTime,
                        UInt32 inNumberPacketDescriptions,
                        const AudioStreamPacketDescription * inPacketDescs)
{
    RecordState * recordState = (RecordState*)inUserData;
    if (!recordState->recording)
    {
        printf("Not recording, returning\n");
    }
   
    // if (inNumberPacketDescriptions == 0 && recordState->dataFormat.mBytesPerPacket != 0)
    // {
    //     inNumberPacketDescriptions = inBuffer->mAudioDataByteSize / recordState->dataFormat.mBytesPerPacket;
    // }
   
    printf("Writing buffer %lld\n", recordState->currentPacket);
    OSStatus status = AudioFileWritePackets(recordState->audioFile,
                                            false,
                                            inBuffer->mAudioDataByteSize,
                                            inPacketDescs,
                                            recordState->currentPacket,
                                            &inNumberPacketDescriptions,
                                            inBuffer->mAudioData);
    if (status == 0)
    {
        recordState->currentPacket += inNumberPacketDescriptions;
    }
   
    AudioQueueEnqueueBuffer(recordState->queue, inBuffer, 0, NULL);
}
-void)setupAudioFormat:(AudioStreamBasicDescription*)format
{
    format->mSampleRate = 8000.0;
    format->mFormatID = kAudioFormatLinearPCM;
    format->mFramesPerPacket = 1;
    format->mChannelsPerFrame = 1;
    format->mBytesPerFrame = 2;
    format->mBytesPerPacket = 2;
    format->mBitsPerChannel = 16;
    format->mReserved = 0;
    format->mFormatFlags = kLinearPCMFormatFlagIsBigEndian     |
    kLinearPCMFormatFlagIsSignedInteger |
    kLinearPCMFormatFlagIsPacked;
}

Is there anyone who can help me with this issue

Hello , though six years passed , i meet the same error, how to solve it

void inputBufferHandler(void *inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer, const AudioTimeStamp *inStartTime,UInt32 inNumPackets, const AudioStreamPacketDescription *inPacketDesc) {   @try{     if (isRecording) {       if (inNumPackets > 0) {         CaptureG711 recorder = (__bridge CaptureG711)inUserData; // crash at this line         [recorder processAudioBuffer:inBuffer withQueue:inAQ];       }             AudioQueueEnqueueBuffer(inAQ, inBuffer, 0, NULL);     }   }@catch(NSException *err){     NSLog(@"inputBufferHandler err is %@", err);   } }

Issue with Audio Queue Implementation
 
 
Q