1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_BASE_MAC_VIDEOTOOLBOX_GLUE_H_
6 #define MEDIA_BASE_MAC_VIDEOTOOLBOX_GLUE_H_
8 #include "base/basictypes.h"
9 #include "media/base/mac/coremedia_glue.h"
10 #include "media/base/media_export.h"
12 // VideoToolbox API is available in OS X 10.9 and iOS 8 (10.8 has support for
13 // software encoding, but this class exposes the 10.9 API level). Chromium
14 // requires OS X 10.6 or iOS 6. Linking with VideoToolbox therefore has to
15 // happen at runtime. This class is defined to try and load the VideoToolbox
16 // library. If it succeeds, clients can use VideoToolbox via this class.
17 class MEDIA_EXPORT VideoToolboxGlue
{
21 // Returns a glue object if VideoToolbox is supported or null otherwise.
22 // Using a glue object allows to avoid expensive atomic operations on every
23 // function call. The object has process life duration and must not be
25 static const VideoToolboxGlue
* Get();
27 // Originally from VTErrors.h
28 typedef UInt32 VTEncodeInfoFlags
;
30 kVTEncodeInfo_Asynchronous
= 1UL << 0,
31 kVTEncodeInfo_FrameDropped
= 1UL << 1,
34 // Originally from VTCompressionSession.h
35 typedef struct OpaqueVTCompressionSession
* VTCompressionSessionRef
;
36 typedef void (*VTCompressionOutputCallback
)(
37 void* outputCallbackRefCon
,
38 void* sourceFrameRefCon
,
40 VTEncodeInfoFlags infoFlags
,
41 CoreMediaGlue::CMSampleBufferRef sampleBuffer
);
43 // Originally from VTSession.h
44 typedef CFTypeRef VTSessionRef
;
46 // Originally from VTCompressionProperties.h
47 CFStringRef
kVTCompressionPropertyKey_AllowFrameReordering() const;
48 CFStringRef
kVTCompressionPropertyKey_AverageBitRate() const;
49 CFStringRef
kVTCompressionPropertyKey_ColorPrimaries() const;
50 CFStringRef
kVTCompressionPropertyKey_ExpectedFrameRate() const;
51 CFStringRef
kVTCompressionPropertyKey_MaxFrameDelayCount() const;
52 CFStringRef
kVTCompressionPropertyKey_MaxKeyFrameInterval() const;
53 CFStringRef
kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration() const;
54 CFStringRef
kVTCompressionPropertyKey_ProfileLevel() const;
55 CFStringRef
kVTCompressionPropertyKey_RealTime() const;
56 CFStringRef
kVTCompressionPropertyKey_TransferFunction() const;
57 CFStringRef
kVTCompressionPropertyKey_YCbCrMatrix() const;
59 CFStringRef
kVTEncodeFrameOptionKey_ForceKeyFrame() const;
61 CFStringRef
kVTProfileLevel_H264_Baseline_AutoLevel() const;
62 CFStringRef
kVTProfileLevel_H264_Main_AutoLevel() const;
63 CFStringRef
kVTProfileLevel_H264_Extended_AutoLevel() const;
64 CFStringRef
kVTProfileLevel_H264_High_AutoLevel() const;
67 kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder()
70 // Originally from VTCompressionSession.h
71 OSStatus
VTCompressionSessionCreate(
72 CFAllocatorRef allocator
,
75 CoreMediaGlue::CMVideoCodecType codecType
,
76 CFDictionaryRef encoderSpecification
,
77 CFDictionaryRef sourceImageBufferAttributes
,
78 CFAllocatorRef compressedDataAllocator
,
79 VTCompressionOutputCallback outputCallback
,
80 void* outputCallbackRefCon
,
81 VTCompressionSessionRef
* compressionSessionOut
) const;
82 OSStatus
VTCompressionSessionEncodeFrame(
83 VTCompressionSessionRef session
,
84 CVImageBufferRef imageBuffer
,
85 CoreMediaGlue::CMTime presentationTimeStamp
,
86 CoreMediaGlue::CMTime duration
,
87 CFDictionaryRef frameProperties
,
88 void* sourceFrameRefCon
,
89 VTEncodeInfoFlags
* infoFlagsOut
) const;
90 CVPixelBufferPoolRef
VTCompressionSessionGetPixelBufferPool(
91 VTCompressionSessionRef session
) const;
92 void VTCompressionSessionInvalidate(VTCompressionSessionRef session
) const;
93 OSStatus
VTCompressionSessionCompleteFrames(
94 VTCompressionSessionRef session
,
95 CoreMediaGlue::CMTime completeUntilPresentationTimeStamp
) const;
97 // Originally from VTSession.h
98 OSStatus
VTSessionSetProperty(VTSessionRef session
,
99 CFStringRef propertyKey
,
100 CFTypeRef propertyValue
) const;
106 DISALLOW_COPY_AND_ASSIGN(VideoToolboxGlue
);
109 #endif // MEDIA_BASE_MAC_VIDEOTOOLBOX_GLUE_H_