AVFrame AudioUnit 播放回调填充音频流

如何用AudioUnit播放从流服务器上获取的的音频数据

正在学习,FFMpeg解码后得到音频流,怎么填充到AudioUnit的播放回调函数中,现在还没有解决,如果有路过的大神,还望指教一二,小弟不胜感激...

static OSStatus playbackCallback(void *inRefCon,
                                AudioUnitRenderActionFlags *ioActionFlags,
                                const AudioTimeStamp *inTimeStamp,
                                UInt32 inBusNumber,
                                UInt32 inNumberFrames,
                                AudioBufferList *ioData) {
    NSLog(@"sdsd");
    
    HZAudioPlayTool *audioTool = [HZAudioPlayTool shareHZAudioPlayTool];
    [audioTool ReceiveAudioWithAudio:^(char *pcm) {
        AudioBuffer buffer  ;
        buffer.mNumberChannels = 1;
        buffer.mDataByteSize = 320 ;
        buffer.mData = malloc (320 );
        NSLog(@"sss1-%d",pcm);
        memcpy(buffer.mData, pcm, 320);
        NSLog(@"buffer.mData-%d",buffer.mData);
        NSLog(@"%d",memcmp(buffer.mData, pcm, 320));
        AudioBufferList bufferList;
        bufferList.mNumberBuffers = 1;
        bufferList.mBuffers[0] = buffer;
        OSStatus status;
        status = AudioUnitRender(audioUnit,
                                 ioActionFlags,
                                 inTimeStamp,
                                 inBusNumber,
                                 inNumberFrames,
                                 &bufferList);
        NSLog(@"sss-%d", bufferList.mBuffers[0].mData);

    }];
    return noErr;
}

你可能感兴趣的:(AVFrame AudioUnit 播放回调填充音频流)