Hello i am trying to record audio/video from one device and send to another with NSStream, I have created avcapturesession and generated audio/video data . The video data is sent fine to another device and displayed correct but the audio data is so distorted like very robotic and skipping. I have got audiobufferlist from the cmsamplebufferref and sent thye resukting 2048 bytes data to another device
CMBlockBufferRef blockBuffer;
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(sampleBuffer, NULL, ¤tInputAudioBufferList, sizeof(currentInputAudioBufferList), NULL, NULL, 0, &blockBuffer);
if( captureOutput == _captureAudioOutput ){
for (int y = 0; y < currentInputAudioBufferList.mNumberBuffers; y++) {
AudioBuffer audioBuffer = currentInputAudioBufferList.mBuffers[y];
Float32 *frame = (Float32*)audioBuffer.mData;
[audiodata appendBytes:frame length:audioBuffer.mDataByteSize];
}
[self sendMIxedData:audioData]; // for sending audiodata
}
else {
////// sample buffer to image to NSData
[self sendMIxedData:audioData:imageData]; // for sending images
}
On the other side i am again converting the data into audiobufferlist and playing with AudioUnit Services.
static OSStatus playbackCallback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {
for (int i=0; i < ioData->mNumberBuffers; i++) {
AudioBuffer buffer = ioData->mBuffers[0];
UInt32 size = min(buffer.mDataByteSize, THIS->tempBuffer.mDataByteSize);
memcpy(buffer.mData, THIS->tempBuffer.mData, size);
buffer.mDataByteSize = size;
}
return noErr;
}
Here tempbuffer is where i am storing the incoming audio data from NSInputStream . The problem is the the audio played is very distorted and robotic . I have tested audiounitservices in other project where i record and play audio simultaneously with AudioUnit services and audio is very clear there . But on sending through stream it becomes. disorted.
Also when i send just the audio data over stream then it is a bit clear but when i send both images and audio data recieved from avcapturesession delegate then the audio is very distorted.Please help me out . What i am doing wrong ? Also can i send audio/video data at same time rather than at different times and extract that on other side ?