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.
4
5#ifndef MEDIA_BASE_MAC_VIDEOTOOLBOX_GLUE_H_
6#define MEDIA_BASE_MAC_VIDEOTOOLBOX_GLUE_H_
7
8#include "base/basictypes.h"
9#include "media/base/mac/coremedia_glue.h"
10#include "media/base/media_export.h"
11
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.
17class MEDIA_EXPORT VideoToolboxGlue {
18 public:
19  class Loader;
20
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
24  // deleted.
25  static const VideoToolboxGlue* Get();
26
27  // Originally from VTErrors.h
28  typedef UInt32 VTEncodeInfoFlags;
29  enum {
30    kVTEncodeInfo_Asynchronous = 1UL << 0,
31    kVTEncodeInfo_FrameDropped = 1UL << 1,
32  };
33
34  // Originally from VTCompressionSession.h
35  typedef struct OpaqueVTCompressionSession* VTCompressionSessionRef;
36  typedef void (*VTCompressionOutputCallback)(
37      void* outputCallbackRefCon,
38      void* sourceFrameRefCon,
39      OSStatus status,
40      VTEncodeInfoFlags infoFlags,
41      CoreMediaGlue::CMSampleBufferRef sampleBuffer);
42
43  // Originally from VTSession.h
44  typedef CFTypeRef VTSessionRef;
45
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_MaxKeyFrameInterval() const;
52  CFStringRef kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration() const;
53  CFStringRef kVTCompressionPropertyKey_ProfileLevel() const;
54  CFStringRef kVTCompressionPropertyKey_RealTime() const;
55  CFStringRef kVTCompressionPropertyKey_TransferFunction() const;
56  CFStringRef kVTCompressionPropertyKey_YCbCrMatrix() const;
57
58  CFStringRef kVTEncodeFrameOptionKey_ForceKeyFrame() const;
59
60  CFStringRef kVTProfileLevel_H264_Baseline_AutoLevel() const;
61  CFStringRef kVTProfileLevel_H264_Main_AutoLevel() const;
62  CFStringRef kVTProfileLevel_H264_Extended_AutoLevel() const;
63  CFStringRef kVTProfileLevel_H264_High_AutoLevel() const;
64
65  CFStringRef
66      kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder()
67      const;
68
69  // Originally from VTCompressionSession.h
70  OSStatus VTCompressionSessionCreate(
71      CFAllocatorRef allocator,
72      int32_t width,
73      int32_t height,
74      CoreMediaGlue::CMVideoCodecType codecType,
75      CFDictionaryRef encoderSpecification,
76      CFDictionaryRef sourceImageBufferAttributes,
77      CFAllocatorRef compressedDataAllocator,
78      VTCompressionOutputCallback outputCallback,
79      void* outputCallbackRefCon,
80      VTCompressionSessionRef* compressionSessionOut) const;
81  OSStatus VTCompressionSessionEncodeFrame(
82      VTCompressionSessionRef session,
83      CVImageBufferRef imageBuffer,
84      CoreMediaGlue::CMTime presentationTimeStamp,
85      CoreMediaGlue::CMTime duration,
86      CFDictionaryRef frameProperties,
87      void* sourceFrameRefCon,
88      VTEncodeInfoFlags* infoFlagsOut) const;
89  CVPixelBufferPoolRef VTCompressionSessionGetPixelBufferPool(
90      VTCompressionSessionRef session) const;
91  void VTCompressionSessionInvalidate(VTCompressionSessionRef session) const;
92
93  // Originally from VTSession.h
94  OSStatus VTSessionSetProperty(VTSessionRef session,
95                                CFStringRef propertyKey,
96                                CFTypeRef propertyValue) const;
97
98 private:
99  struct Library;
100  VideoToolboxGlue();
101  Library* library_;
102  DISALLOW_COPY_AND_ASSIGN(VideoToolboxGlue);
103};
104
105#endif  // MEDIA_BASE_MAC_VIDEOTOOLBOX_GLUE_H_
106