【发布时间】:2016-02-17 10:05:53
【问题描述】:
在我的应用程序中,我必须捕获麦克风并在 rtp 数据包中发送音频数据。但我只看到接收 rtp 数据,如iOS RTP live audio receiving 或未答复的one。
我使用以下代码和AsuncUdpSocket 发送音频数据,但它没有包装在 rtp 数据包中。是否有任何库可以将我的音频数据包装到 rtp 数据包中?
初始 AsyncUdpSocket:
udpSender = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
NSError *error;
[udpSender connectToHost:@"192.168.1.29" onPort:1024 error:&error];
我在播放回调函数中发送音频数据:
static OSStatus playbackCallback(void *inRefCon,
AudioUnitRenderActionFlags *ioActionFlags,
const AudioTimeStamp *inTimeStamp,
UInt32 inBusNumber,
UInt32 inNumberFrames,
AudioBufferList *ioData) {
/**
This is the reference to the object who owns the callback.
*/
AudioProcessor *audioProcessor = (AudioProcessor*) inRefCon;
// iterate over incoming stream an copy to output stream
for (int i=0; i < ioData->mNumberBuffers; i++) {
AudioBuffer buffer = ioData->mBuffers[i];
// find minimum size
UInt32 size = min(buffer.mDataByteSize, [audioProcessor audioBuffer].mDataByteSize);
// copy buffer to audio buffer which gets played after function return
memcpy(buffer.mData, [audioProcessor audioBuffer].mData, size);
// set data size
buffer.mDataByteSize = size;
//Send data to remote server
NSMutableData *data=[[NSMutableData alloc] init];
Float32 *frame = (Float32*)buffer.mData;
[data appendBytes:frame length:size];
if ([udpSender isConnected])
{
[udpSender sendData:data withTimeout:-1 tag:1];
}
}
return noErr;
}
我该如何做到这一点?
谢谢。
【问题讨论】:
标签: objective-c audio-streaming rtp