0
這是我第一篇文章,以stackoverflow。目前我正在爲ios開發一個voip應用程序。我想要做這樣的事情。iOs爲VOIP應用播放音頻
//in a thread
while(callIsOnGoing){
data = getDataFromNetwork()
playData()
sleep(10ms)
}
但問題是,在IOS音頻「拉」模式工作(使用回調以獲取數據)。但我需要推動數據來播放它。我嘗試過AudioQueue,但在audioQueue中,我在回調之外的緩衝區中推入的數據不會播放,儘管回調被調用。
再次,我已經看到AVCaptureToAudioUnit示例由蘋果(http://developer.apple.com/library/ios/#samplecode/AVCaptureToAudioUnit/Introduction/Intro.html)他們在延遲音頻單元的情況下同步調用AudioUnitRender。我嘗試了類似的RemoteI/O音頻單元。但每次它返回OSStatus -50。 下面
//in a separate thread
do { // 5
int data_length = [NativeLibraryHelper GetData:(playBuff)];
if(data_length == 0){
}else{
double numberOfFrameCount = data_length/player->audioStreamDesc->mBytesPerFrame;
currentSampleTime += numberOfFrameCount;
//AudioUnitRenderActionFlags flags = 0;
AudioTimeStamp timeStamp;
memset(&timeStamp, 0, sizeof(AudioTimeStamp));
timeStamp.mSampleTime = currentSampleTime;
timeStamp.mFlags |= kAudioTimeStampSampleTimeValid;
AudioUnitRenderActionFlags flags = 0;
AudioBuffer buffer;
buffer.mNumberChannels = player->audioStreamDesc->mChannelsPerFrame;
buffer.mDataByteSize = data_length;
buffer.mData = malloc(data_length);
memcpy(buffer.mData, playBuff, data_length);
AudioBufferList audBuffList;
audBuffList.mBuffers[0] = buffer;
audBuffList.mNumberBuffers = 1;
printf("Audio REnder call back funciotn called with data size %d\n", data_length);
status = AudioUnitRender(audioUnitInstance, &flags, &timeStamp, 0, numberOfFrameCount, &audBuffList);
printf("osstatus %d\n", status);
}//end if else
CFRunLoopRunInMode ( // 6
kCFRunLoopDefaultMode, // 7
0.25, // 8
false // 9
);
//} while (aqData.mIsRunning);
[NSThread sleepForTimeInterval:.05];
}while (player->isRunning == YES);
的代碼給我帶音頻播放部分掙扎了一個多月。請幫忙。提前致謝。