IOS硬件解码VTDecompressionSession失效
2016-01-18 02:06
489 查看
IOS硬件解码VideoToolbox在应用中进入后台VTDecompressionSession失效解决办法
Author:baohonglaiEmail:baohonglai@gmail.com
版权所有。转载本BLOG内任何文章,请以超链接形式注明出处。
*前段时间在IOS上用VideoToolbox进行视频播放器硬件解码时遇到一个问题,就是播放器进入进入到后台后再切换回来会导致VTDecompressionSession直接失效,这个问题纠结了很久,后来终于找到解决办法了,直接重新初始化session,下面展示一段示例代码。
参考链接
http://www.zhihu.com/question/20692215
引用了stevenyao/iOSHardwareDecoder · GitHub的代码,这段代码里面没有对session失效了进行处理,我在里面加了下面这段处理,就可以了。
- (void)resetH264Decoder { if(_deocderSession) { VTDecompressionSessionInvalidate(_deocderSession); CFRelease(_deocderSession); _deocderSession = NULL; } CFDictionaryRef attrs = NULL; const void *keys[] = { kCVPixelBufferPixelFormatTypeKey }; // kCVPixelFormatType_420YpCbCr8Planar is YUV420 // kCVPixelFormatType_420YpCbCr8BiPlanarFullRange is NV12 uint32_t v = kCVPixelFormatType_420YpCbCr8BiPlanarFullRange; const void *values[] = { CFNumberCreate(NULL, kCFNumberSInt32Type, &v) }; attrs = CFDictionaryCreate(NULL, keys, values, 1, NULL, NULL); VTDecompressionOutputCallbackRecord callBackRecord; callBackRecord.decompressionOutputCallback = didDecompress; callBackRecord.decompressionOutputRefCon = NULL; if(VTDecompressionSessionCanAcceptFormatDescription(_deocderSession, _decoderFormatDescription)) { NSLog(@"yes"); } OSStatus status = VTDecompressionSessionCreate(kCFAllocatorSystemDefault, _decoderFormatDescription, NULL, attrs, &callBackRecord, &_deocderSession); CFRelease(attrs); }
然后在遇到session失效时调用
if(decodeStatus == kVTInvalidSessionErr) { NSLog(@"IOS8VT: Invalid session, reset decoder session"); [self resetH264Decoder]; }
相关文章推荐
- iOS应用分发与内测(二)
- iOS开发高手进阶之路
- IOS之多线程
- 在蜂窝教育iOS培训四个月,我改变了自己的未来
- iOS-地图定位、CLLocationManager简单使用
- IOS,十六进制颜色和RGB颜色的宏定义
- iOS--计算多行文本尺寸
- ios layout机制相关方法
- iOS第三方类库汇总【持续更新】
- iOS 调用系统相机和相册的功能
- How to use cocoa pod in your iOS project
- IOS开发中常用的知识点汇总
- iOS上传视频到服务器
- nagios监控端的安装
- iOS应用分发与内测(一)
- iOS上传语音到服务器
- iOS崩溃调试
- NSURLSession(三)
- 监听键盘的弹出与隐藏(界面跟随键盘一起上下移动)
- iOS上传图片到服务器