iOS硬件编解码库VideoToolBox的调用

在iOS平台,要实现真正的视频硬件编解码,必须调用私有库VideoToolBox,但有个致命的弊端的是:如果调用这个私有库,那么app在必须在越狱的设备上运行,也就是app的权限要彻底放开

这里目前只给出VideoToolBox动态库路径和函数符号表

VideoToolBox动态库路径:  "/System/Library/PrivateFrameworks/VideoToolbox.framework/VideoToolbox"

有关VideoToolBox的函数符号表的头文件:

#ifndef __GST_VT_API_H__
#define __GST_VT_API_H__
#import "CoreMedia/CoreMedia.h"

//typedef struct _GstVTApiClass GstVTApiClass;

enum _VTStatus
{  kVTSuccess = 0,
    KVTFail = 1
};

typedef enum _VTStatus VTStatus;

typedef int VTFormatId;

typedef CFTypeRef VTCompressionSessionRef;
typedef CFTypeRef VTDecompressionSessionRef;

//extern OSStatus CMVideoFormatDescriptionCreate(CFAllocatorRef allocator, CMVideoCodecType codecType, int32_t width, int32_t height, 
//                                               CFDictionaryRef extensions, CMVideoFormatDescriptionRef *outDesc);

enum _VTFormat
{
  kVTFormatH264 = 'avc1',
  kVTFormatJPEG = 'jpeg'
};

typedef VTStatus (* VTCompressionOutputCallbackFunc) (void * data, int a2,
                                                      int a3, int a4, CMSampleBufferRef sbuf, int a6, int a7);
typedef void (* VTDecompressionOutputCallbackFunc) (void * data, size_t unk1,
                                                    VTStatus result, size_t unk2, CVBufferRef cvbuf);

struct _VTCompressionOutputCallback
{
  VTCompressionOutputCallbackFunc func;
  void * data;
};

struct _VTDecompressionOutputCallback
{
  VTDecompressionOutputCallbackFunc func;
  void * data;
};

typedef struct _VTCompressionOutputCallback VTCompressionOutputCallback;
typedef struct _VTDecompressionOutputCallback VTDecompressionOutputCallback;

typedef VTStatus (* pVTCompressionSessionCompleteFrames)
(VTCompressionSessionRef session, CMTime completeUntilDisplayTimestamp);

typedef VTStatus (* pVTCompressionSessionCopyProperty)
(VTCompressionSessionRef session, CFTypeRef key, void* unk,
 CFTypeRef * value);

typedef VTStatus (* pVTCompressionSessionCopySupportedPropertyDictionary)
(VTCompressionSessionRef session, CFDictionaryRef * dict);

typedef VTStatus (* pVTCompressionSessionCreate)
(CFAllocatorRef allocator, int width, int height, VTFormatId formatId,
 size_t unk1, CFDictionaryRef sourcePixelBufferAttributes, size_t unk2,
 VTCompressionOutputCallback outputCallback,
 VTCompressionSessionRef * session);

typedef VTStatus (* pVTCompressionSessionEncodeFrame)
(VTCompressionSessionRef session, CVPixelBufferRef pixelBuffer,
 CMTime displayTimestamp, CMTime displayDuration,
 CFDictionaryRef frameOptions, void * sourceTrackingCallback,
 void * sourceFrameRefCon);

typedef void (* pVTCompressionSessionInvalidate)
(VTCompressionSessionRef session);

typedef void (* pVTCompressionSessionRelease)
(VTCompressionSessionRef session);

typedef VTCompressionSessionRef (* pVTCompressionSessionRetain)
(VTCompressionSessionRef session);

typedef VTStatus (* pVTCompressionSessionSetProperty)
(VTCompressionSessionRef session, CFStringRef propName,
 CFTypeRef propValue);

typedef VTStatus (* pVTDecompressionSessionCreate)
(CFAllocatorRef allocator,
 CMFormatDescriptionRef videoFormatDescription,
 CFTypeRef sessionOptions,
 CFDictionaryRef destinationPixelBufferAttributes,
 VTDecompressionOutputCallback * outputCallback,
 VTDecompressionSessionRef * session);

typedef VTStatus (* pVTDecompressionSessionDecodeFrame)
(VTDecompressionSessionRef session, CMSampleBufferRef sbuf, size_t unk1,
 size_t unk2, size_t unk3);

typedef void (* pVTDecompressionSessionInvalidate)
(VTDecompressionSessionRef session);

typedef void (* pVTDecompressionSessionRelease)
(VTDecompressionSessionRef session);

typedef VTDecompressionSessionRef (* pVTDecompressionSessionRetain)
(VTDecompressionSessionRef session);

typedef VTStatus (* pVTDecompressionSessionWaitForAsynchronousFrames)
(VTDecompressionSessionRef session);

typedef OSStatus (* pFigVideoFormatDescriptionCreateWithSampleDescriptionExtensionAtom)(CFAllocatorRef allocator, UInt32 formatId, UInt32 width, UInt32 height, UInt32 atomId, const UInt8 *data, CFIndex len, void *unk1, CMFormatDescriptionRef *formatDesc);

struct _GstVTApi
{

  VTStatus (* VTCompressionSessionCompleteFrames)
      (VTCompressionSessionRef session, CMTime completeUntilDisplayTimestamp);
  VTStatus (* VTCompressionSessionCopyProperty)
      (VTCompressionSessionRef session, CFTypeRef key, void* unk,
      CFTypeRef * value);
  VTStatus (* VTCompressionSessionCopySupportedPropertyDictionary)
      (VTCompressionSessionRef session, CFDictionaryRef * dict);
  VTStatus (* VTCompressionSessionCreate)
      (CFAllocatorRef allocator, int width, int height, VTFormatId formatId,
      size_t unk1, CFDictionaryRef sourcePixelBufferAttributes, size_t unk2,
      VTCompressionOutputCallback outputCallback,
      VTCompressionSessionRef * session);
  VTStatus (* VTCompressionSessionEncodeFrame)
      (VTCompressionSessionRef session, CVPixelBufferRef pixelBuffer,
      CMTime displayTimestamp, CMTime displayDuration,
      CFDictionaryRef frameOptions, void * sourceTrackingCallback,
      void * sourceFrameRefCon);
  void (* VTCompressionSessionInvalidate)
      (VTCompressionSessionRef session);
  void (* VTCompressionSessionRelease)
      (VTCompressionSessionRef session);
  VTCompressionSessionRef (* VTCompressionSessionRetain)
      (VTCompressionSessionRef session);
  VTStatus (* VTCompressionSessionSetProperty)
      (VTCompressionSessionRef session, CFStringRef propName,
      CFTypeRef propValue);

  VTStatus (* VTDecompressionSessionCreate)
      (CFAllocatorRef allocator,
      CMFormatDescriptionRef videoFormatDescription,
      CFTypeRef sessionOptions,
      CFDictionaryRef destinationPixelBufferAttributes,
      VTDecompressionOutputCallback * outputCallback,
      VTDecompressionSessionRef * session);
  VTStatus (* VTDecompressionSessionDecodeFrame)
      (VTDecompressionSessionRef session, CMSampleBufferRef sbuf, size_t unk1,
      size_t unk2, size_t unk3);
  void (* VTDecompressionSessionInvalidate)
      (VTDecompressionSessionRef session);
  void (* VTDecompressionSessionRelease)
      (VTDecompressionSessionRef session);
  VTDecompressionSessionRef (* VTDecompressionSessionRetain)
      (VTDecompressionSessionRef session);
  VTStatus (* VTDecompressionSessionWaitForAsynchronousFrames)
      (VTDecompressionSessionRef session);
    
  OSStatus (* FigVideoFormatDescriptionCreateWithSampleDescriptionExtensionAtom)(CFAllocatorRef allocator, UInt32 formatId, UInt32 width, UInt32 height, UInt32 atomId, const UInt8 *data, CFIndex len, void *unk1, CMFormatDescriptionRef *formatDesc);

  CFStringRef * kVTCompressionPropertyKey_AllowTemporalCompression;
  CFStringRef * kVTCompressionPropertyKey_AverageDataRate;
  CFStringRef * kVTCompressionPropertyKey_ExpectedFrameRate;
  CFStringRef * kVTCompressionPropertyKey_ExpectedDuration;
  CFStringRef * kVTCompressionPropertyKey_MaxKeyFrameInterval;
  CFStringRef * kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration;
  CFStringRef * kVTCompressionPropertyKey_ProfileLevel;
  CFStringRef * kVTCompressionPropertyKey_Usage;
  CFStringRef * kVTEncodeFrameOptionKey_ForceKeyFrame;
  CFStringRef * kVTProfileLevel_H264_Baseline_1_3;
  CFStringRef * kVTProfileLevel_H264_Baseline_3_0;
  CFStringRef * kVTProfileLevel_H264_Baseline_3_1;
  CFStringRef * kVTProfileLevel_H264_Extended_5_0;
  CFStringRef * kVTProfileLevel_H264_High_5_0;
  CFStringRef * kVTProfileLevel_H264_Main_3_0;
  CFStringRef * kVTProfileLevel_H264_Main_3_1;
  CFStringRef * kVTProfileLevel_H264_Main_4_0;
  CFStringRef * kVTProfileLevel_H264_Main_4_1;
  CFStringRef * kVTProfileLevel_H264_Main_5_0;
};

typedef struct _GstVTApi GstVTApi;


#endif

具体如何利用VideoToolBox动态库中的这些函数实现IOS硬件编解码,暂时不公开

若需要实现源代码,可联系我。QQ:349260360   Email:manshilingkai@163.com


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值