iOS WebRTC视频解码

本文详细介绍了iOS上WebRTC视频解码的基本流程,包括创建解码器、配置参数、解码及释放解码器的步骤。同时,通过分析WebRTC源码,展示了WebRTC如何使用VideoToolbox进行解码操作,包括创建解码器、配置实时解码、解码回调函数的实现。
摘要由CSDN通过智能技术生成

1、解码的基本流程

与编码器流程基本一致,流程如下:

  • 创建解码器实例。

  • 配置解码器。

  • 解码。

  • 释放解码器。

下面我们看一下几个关键函数的原型。

1.1 创建解器

在 iOS 中使用 VTDecompressionSessionCreate 方法创建解码器。其函数原型如下:

VTDecompressionSessionCreate(
    allocator: CFAllocator, //session分配器,NULL使用默认分配器
    videoFormatDescription: CMVideoFormatDescription, //视频帧格式描述信息
    videoDecoderSpecification: CFDictionary, //视频解码器,如果NULL,表示让VideoToolbox选择视频解码器。
    destinationImageBufferAttributes: CFDictionary, //像素缓冲区要求的属性
    outputCallback: VTDecompressionOutputCallbackRecord *, //解码完一帧后的回调函数。
    decompressionSessionOut: VTDecompressionSession* //创建出的解码Session实例。
) -> OSStatus

各参数详细介绍:

  • allocator : session分配器,NULL使用默认分配器。

  • videoFormatDescription : 源视频帧格式描述信息。

  • videoDecoderSpecification : 视频解码器。如果是NULL表式让 VideoToolbox自己选择视频解码器。

  • destinationImageBufferAttributes: 像素缓冲区要求的属性。

  • outputCallback: 解码后的回调函数。

  • decompressionSessionOut: 输出Session实列。

1.2 配置参数

在iOS下通过VTSessionSetProperty函数来配置 CompressionSession。函数原型如下:

VTSessionSetProperty(
    session: VTSession, //就是上面创建的 VTCompressionSession 对象。
    propertyKey: CFString, // 属性
    propertyValue: CFTypeRef //属性值
) -> OSStatus //返回的状态值

其与编码器的设置是一样的。在设置解码器时只需要设置是否实时解码即可。

1.3 解码

使用 VTDecompressionSessionDecodeFrame 函数进行解码。其原型如下:

OSStatus
VTDecompressionSessionDecodeFrame(
    VTDecompressionSessionRef   session, //解码器 Session
    CMSampleBufferRef   sampleBuffer, // 源视频帧
    VTDecodeFrameFlags  decodeFlags, // 解码标志位。bit 0 is enableAsynchronousDecompression
    void *  sourceFrameRefCon,  //用户自定义参数指针。
    VTDecodeInfoFlags * infoFlagsOut //解码输出标志
)
  • session : 创建解码器时创建的 Session。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值