我们在做RTMP、RTSP播放器的时候,有开发者需要自己处理拉取到的YUV数据,做二次分析之用,为此,我们做了以下的设计:
InitPlayer之后,再调用SmartPlayerStart()接口之前,设置yuv数据回调即可。
-(bool)StartPlayer { NSLog(@"[daniusdk]StartPlayer++"); if ( _smart_player_sdk == nil ) { NSLog(@"StartPlayer, player SDK with nil"); return false; } //设置视频画面的填充模式,如填充整个view、等比例填充view NSInteger render_scale_mode = 1; [_smart_player_sdk SmartPlayerSetRenderScaleMode:render_scale_mode]; //设置视频view旋转角度 [_smart_player_sdk SmartPlayerSetRotation:rotate_degrees_]; float f = audioVolumeSlider.value; //读取滑块的值 [_smart_player_sdk SmartPlayerSetAudioVolume:(NSInteger)f]; //软/硬解码模式设置 [_smart_player_sdk SmartPlayerSetVideoDecoderMode:is_hardware_decoder_]; if (is_audio_only_) { [_smart_player_sdk SmartPlayerSetPlayView:nil]; } else { //如果只需外部回调YUV数据,自己绘制,无需创建view和设置view到SDK _glView = (__bridge UIView *)([SmartPlayerSDK SmartPlayerCreatePlayView:0 y:50 width:player_view_width_ height:player_view_height_]); if (_glView == nil ) { NSLog(@"CreatePlayView failed.."); return false; } [self.view addSubview:_glView]; [_smart_player_sdk SmartPlayerSetPlayView:(__bridge void *)(_glView)]; } _smart_player_sdk.yuvDataBlock = ^void(int width, int height, unsigned long long time_stamp, unsigned char*yData, unsigned char* uData, unsigned char*vData, int yStride, int uStride, int vStride) { NSLog(@"[PlaySideYuvCallback] width:%d, height:%d, ts:%lld, y:%d, u:%d, v:%d", width, height, time_stamp, yStride, uStride, vStride); //这里接收底层回调的YUV数据 }; //设置YUV数据回调输出 [_smart_player_sdk SmartPlayerSetYuvBlock:true]; NSInteger ret = [_smart_player_sdk SmartPlayerStart]; if(ret != DANIULIVE_RETURN_OK) { NSLog(@"Call SmartPlayerStart failed..ret:%ld", (long)ret); return false; } NSLog(@"[daniusdk]StartPlayer--"); return true; }
具体YUV数据回调的代码如下:
_smart_player_sdk.yuvDataBlock = ^void(int width, int height, unsigned long long time_stamp, unsigned char*yData, unsigned char* uData, unsigned char*vData, int yStride, int uStride, int vStride) { NSLog(@"[PlaySideYuvCallback] width:%d, height:%d, ts:%lld, y:%d, u:%d, v:%d", width, height, time_stamp, yStride, uStride, vStride); //这里接收底层回调的YUV数据 }; //设置YUV数据回调输出 [_smart_player_sdk SmartPlayerSetYuvBlock:true];
如果仅需要处理回调的YUV数据,不需要额外的绘制(当然也可以自己绘制YUV数据),只要不创建设置view到底层即可,感兴趣的开发者,可以单独跟我沟通。