一、ReplayKit2 框架回调中
视频、micphone声音、系统声音三路回调
- (void)processSampleBuffer:(CMSampleBufferRef)sampleBuffer withType:(RPSampleBufferType)sampleBufferType { switch (sampleBufferType) { case RPSampleBufferTypeVideo:{ // Handle video sample buffer QG_Debug(MODULE_LIVE_ASS, @"SampleHandler processSampleBuffer RPSampleBufferTypeVideo"); } break; case RPSampleBufferTypeAudioApp: // Handle audio sample buffer for app audio QG_Debug(MODULE_LIVE_ASS, @"SampleHandler processSampleBuffer RPSampleBufferTypeAudioApp ---------------"); break; case RPSampleBufferTypeAudioMic: // Handle audio sample buffer for mic audio QG_Debug(MODULE_LIVE_ASS, @"SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic"); break; default: break; } }
现在的问题是,micphone的回调几乎是实时的,每秒42次
默认 16:01:49.626272 +0800 LABroadcastUpload 2018-10-31 16:01:49.625 [48679] Debug|be27|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:49.633504 +0800 LABroadcastUpload 2018-10-31 16:01:49.633 [48679] Debug|be27|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.657628 +0800 LABroadcastUpload 2018-10-31 16:01:49.657 [48679] Debug|be27|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.669175 +0800 LABroadcastUpload 2018-10-31 16:01:49.668 [48679] Debug|be27|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:49.680324 +0800 LABroadcastUpload 2018-10-31 16:01:49.679 [45831] Debug|b307|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.692136 +0800 LABroadcastUpload 2018-10-31 16:01:49.691 [45831] Debug|b307|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:49.704546 +0800 LABroadcastUpload 2018-10-31 16:01:49.704 [8599] Debug|2197|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.732569 +0800 LABroadcastUpload 2018-10-31 16:01:49.726 [8599] Debug|2197|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:49.736873 +0800 LABroadcastUpload 2018-10-31 16:01:49.726 [8599] Debug|2197|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.783538 +0800 LABroadcastUpload 2018-10-31 16:01:49.749 [45831] Debug|b307|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.793023 +0800 LABroadcastUpload 2018-10-31 16:01:49.759 [45831] Debug|b307|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:49.806903 +0800 LABroadcastUpload 2018-10-31 16:01:49.774 [48679] Debug|be27|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.832517 +0800 LABroadcastUpload 2018-10-31 16:01:49.795 [45831] Debug|b307|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.838011 +0800 LABroadcastUpload 2018-10-31 16:01:49.800 [8599] Debug|2197|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:49.876397 +0800 LABroadcastUpload 2018-10-31 16:01:49.823 [45831] Debug|b307|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.907369 +0800 LABroadcastUpload 2018-10-31 16:01:49.842 [45831] Debug|b307|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.912447 +0800 LABroadcastUpload 2018-10-31 16:01:49.845 [48679] Debug|be27|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:49.937406 +0800 LABroadcastUpload 2018-10-31 16:01:49.859 [9219] Debug|2403|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:49.940732 +0800 LABroadcastUpload 2018-10-31 16:01:49.865 [45831] Debug|b307|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.946041 +0800 LABroadcastUpload 2018-10-31 16:01:49.889 [45831] Debug|b307|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.948695 +0800 LABroadcastUpload 2018-10-31 16:01:49.893 [9219] Debug|2403|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:49.949680 +0800 LABroadcastUpload 2018-10-31 16:01:49.911 [48679] Debug|be27|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.951007 +0800 LABroadcastUpload 2018-10-31 16:01:49.926 [45831] Debug|b307|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:49.951684 +0800 LABroadcastUpload 2018-10-31 16:01:49.934 [48679] Debug|be27|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.958768 +0800 LABroadcastUpload 2018-10-31 16:01:49.958 [45831] Debug|b307|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:49.964717 +0800 LABroadcastUpload 2018-10-31 16:01:49.964 [45831] Debug|b307|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:49.982194 +0800 LABroadcastUpload 2018-10-31 16:01:49.981 [9219] Debug|2403|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:50.006942 +0800 LABroadcastUpload 2018-10-31 16:01:50.006 [45831] Debug|b307|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:50.007363 +0800 LABroadcastUpload 2018-10-31 16:01:50.007 [9219] Debug|2403|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:50.028539 +0800 LABroadcastUpload 2018-10-31 16:01:50.027 [48679] Debug|be27|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:50.029291 +0800 LABroadcastUpload 2018-10-31 16:01:50.028 [8599] Debug|2197|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:50.051188 +0800 LABroadcastUpload 2018-10-31 16:01:50.050 [8599] Debug|2197|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:50.058217 +0800 LABroadcastUpload 2018-10-31 16:01:50.058 [8599] Debug|2197|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:50.074354 +0800 LABroadcastUpload 2018-10-31 16:01:50.074 [8599] Debug|2197|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:50.099753 +0800 LABroadcastUpload 2018-10-31 16:01:50.093 [45831] Debug|b307|SampleHandler.m:307|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 16:01:50.103660 +0800 LABroadcastUpload 2018-10-31 16:01:50.097 [48679] Debug|be27|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic 默认 16:01:50.132583 +0800 LABroadcastUpload 2018-10-31 16:01:50.124 [45831] Debug|b307|SampleHandler.m:320|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioMic
但是App的声音是几乎500ms一次
默认 11:02:28.314940 +0800 LABroadcastUpload 2018-10-31 11:02:28.313 [84535] Debug|14a37|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.338789 +0800 LABroadcastUpload 2018-10-31 11:02:28.337 [84535] Debug|14a37|SampleHandler.m:312|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioApp --------------- 默认 11:02:28.346683 +0800 LABroadcastUpload 2018-10-31 11:02:28.346 [84535] Debug|14a37|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.380657 +0800 LABroadcastUpload 2018-10-31 11:02:28.380 [84535] Debug|14a37|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.413895 +0800 LABroadcastUpload 2018-10-31 11:02:28.413 [84535] Debug|14a37|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.453964 +0800 LABroadcastUpload 2018-10-31 11:02:28.453 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.479968 +0800 LABroadcastUpload 2018-10-31 11:02:28.479 [8491] Debug|212b|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.514081 +0800 LABroadcastUpload 2018-10-31 11:02:28.513 [8491] Debug|212b|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.548224 +0800 LABroadcastUpload 2018-10-31 11:02:28.547 [84535] Debug|14a37|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.581848 +0800 LABroadcastUpload 2018-10-31 11:02:28.581 [84535] Debug|14a37|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.624133 +0800 LABroadcastUpload 2018-10-31 11:02:28.623 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.646465 +0800 LABroadcastUpload 2018-10-31 11:02:28.646 [8491] Debug|212b|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.680087 +0800 LABroadcastUpload 2018-10-31 11:02:28.679 [8491] Debug|212b|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.713644 +0800 LABroadcastUpload 2018-10-31 11:02:28.713 [8491] Debug|212b|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.752759 +0800 LABroadcastUpload 2018-10-31 11:02:28.752 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.779585 +0800 LABroadcastUpload 2018-10-31 11:02:28.779 [84535] Debug|14a37|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.813878 +0800 LABroadcastUpload 2018-10-31 11:02:28.813 [84535] Debug|14a37|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.854994 +0800 LABroadcastUpload 2018-10-31 11:02:28.854 [84535] Debug|14a37|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.855188 +0800 LABroadcastUpload 2018-10-31 11:02:28.854 [27415] Debug|6b17|SampleHandler.m:312|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioApp --------------- 默认 11:02:28.883123 +0800 LABroadcastUpload 2018-10-31 11:02:28.882 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.932190 +0800 LABroadcastUpload 2018-10-31 11:02:28.931 [84535] Debug|14a37|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.947889 +0800 LABroadcastUpload 2018-10-31 11:02:28.947 [8491] Debug|212b|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:28.981193 +0800 LABroadcastUpload 2018-10-31 11:02:28.980 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.016192 +0800 LABroadcastUpload 2018-10-31 11:02:29.015 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.047840 +0800 LABroadcastUpload 2018-10-31 11:02:29.047 [8491] Debug|212b|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.095569 +0800 LABroadcastUpload 2018-10-31 11:02:29.095 [8491] Debug|212b|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.115072 +0800 LABroadcastUpload 2018-10-31 11:02:29.113 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.270830 +0800 LABroadcastUpload 2018-10-31 11:02:29.216 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.271530 +0800 LABroadcastUpload 2018-10-31 11:02:29.217 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.272777 +0800 LABroadcastUpload 2018-10-31 11:02:29.218 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.322329 +0800 LABroadcastUpload 2018-10-31 11:02:29.248 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.350062 +0800 LABroadcastUpload 2018-10-31 11:02:29.287 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.363928 +0800 LABroadcastUpload 2018-10-31 11:02:29.320 [8491] Debug|212b|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.384039 +0800 LABroadcastUpload 2018-10-31 11:02:29.359 [84535] Debug|14a37|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.384695 +0800 LABroadcastUpload 2018-10-31 11:02:29.361 [8491] Debug|212b|SampleHandler.m:312|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioApp --------------- 默认 11:02:29.390916 +0800 LABroadcastUpload 2018-10-31 11:02:29.381 [24835] Debug|6103|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.414419 +0800 LABroadcastUpload 2018-10-31 11:02:29.414 [8491] Debug|212b|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.455207 +0800 LABroadcastUpload 2018-10-31 11:02:29.454 [84535] Debug|14a37|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.489226 +0800 LABroadcastUpload 2018-10-31 11:02:29.488 [24835] Debug|6103|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.513677 +0800 LABroadcastUpload 2018-10-31 11:02:29.513 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.547077 +0800 LABroadcastUpload 2018-10-31 11:02:29.546 [24835] Debug|6103|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.581483 +0800 LABroadcastUpload 2018-10-31 11:02:29.581 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.615560 +0800 LABroadcastUpload 2018-10-31 11:02:29.615 [24835] Debug|6103|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.659048 +0800 LABroadcastUpload 2018-10-31 11:02:29.658 [27415] Debug|6b17|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.680790 +0800 LABroadcastUpload 2018-10-31 11:02:29.680 [24835] Debug|6103|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.715018 +0800 LABroadcastUpload 2018-10-31 11:02:29.714 [24835] Debug|6103|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.748573 +0800 LABroadcastUpload 2018-10-31 11:02:29.748 [24835] Debug|6103|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.789083 +0800 LABroadcastUpload 2018-10-31 11:02:29.788 [84535] Debug|14a37|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.832327 +0800 LABroadcastUpload 2018-10-31 11:02:29.831 [24835] Debug|6103|SampleHandler.m:306|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeVideo 默认 11:02:29.877877 +0800 LABroadcastUpload 2018-10-31 11:02:29.876 [84535] Debug|14a37|SampleHandler.m:312|MODULE_LIVE_ASS| SampleHandler processSampleBuffer RPSampleBufferTypeAudioApp ---------------
这个带来两个声音之间的混音同步问题,
如果强制同步App的声音,必将带来500ms的延时
如果不同步,会带来App路的声音500ms的延时,绝地求生中开枪声音迟滞的问题
暂时没有太好的方法:
一种办法,用户选择声音输出到扬声器,而不是听筒,这样micphone采集到是App声音和环境声音,自然同步;然后屏蔽掉App的声音