1 // Copyright 2013 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_COREMEDIA_GLUE_H_ 6 #define MEDIA_BASE_MAC_COREMEDIA_GLUE_H_ 7 8 #include <CoreVideo/CoreVideo.h> 9 10 #include "base/basictypes.h" 11 #include "media/base/media_export.h" 12 13 // CoreMedia API is only introduced in Mac OS X > 10.6, the (potential) linking 14 // with it has to happen in runtime. If it succeeds, subsequent clients can use 15 // CoreMedia via the class declared in this file, where the original naming has 16 // been kept as much as possible. 17 class MEDIA_EXPORT CoreMediaGlue { 18 public: 19 // Originally from CMTime.h 20 typedef int64_t CMTimeValue; 21 typedef int32_t CMTimeScale; 22 typedef int64_t CMTimeEpoch; 23 typedef uint32_t CMTimeFlags; 24 typedef struct { 25 CMTimeValue value; 26 CMTimeScale timescale; 27 CMTimeFlags flags; 28 CMTimeEpoch epoch; 29 } CMTime; 30 31 // Originally from CMBlockBuffer.h 32 typedef uint32_t CMBlockBufferFlags; 33 typedef struct OpaqueCMBlockBuffer* CMBlockBufferRef; 34 typedef struct { 35 uint32_t version; 36 void* (*AllocateBlock)(void*, size_t); 37 void (*FreeBlock)(void*, void*, size_t); 38 void* refCon; 39 } CMBlockBufferCustomBlockSource; 40 41 // Originally from CMFormatDescription.h. 42 typedef const struct opaqueCMFormatDescription* CMFormatDescriptionRef; 43 typedef CMFormatDescriptionRef CMVideoFormatDescriptionRef; 44 typedef FourCharCode CMVideoCodecType; 45 typedef struct { 46 int32_t width; 47 int32_t height; 48 } CMVideoDimensions; 49 enum { 50 kCMPixelFormat_422YpCbCr8_yuvs = 'yuvs', 51 }; 52 enum { 53 kCMVideoCodecType_JPEG_OpenDML = 'dmb1', 54 kCMVideoCodecType_H264 = 'avc1', 55 }; 56 57 // Originally from CMFormatDescriptionBridge.h 58 enum { 59 kCMFormatDescriptionBridgeError_InvalidParameter = -12712, 60 }; 61 62 // Originally from CMSampleBuffer.h. 63 typedef struct OpaqueCMSampleBuffer* CMSampleBufferRef; 64 65 // Originally from CMTime.h. 66 static CMTime CMTimeMake(int64_t value, int32_t timescale); 67 68 // Originally from CMBlockBuffer.h 69 static OSStatus CMBlockBufferCreateContiguous( 70 CFAllocatorRef structureAllocator, 71 CMBlockBufferRef sourceBuffer, 72 CFAllocatorRef blockAllocator, 73 const CMBlockBufferCustomBlockSource* customBlockSource, 74 size_t offsetToData, 75 size_t dataLength, 76 CMBlockBufferFlags flags, 77 CMBlockBufferRef* newBBufOut); 78 static size_t CMBlockBufferGetDataLength(CMBlockBufferRef theBuffer); 79 static OSStatus CMBlockBufferGetDataPointer(CMBlockBufferRef theBuffer, 80 size_t offset, 81 size_t* lengthAtOffset, 82 size_t* totalLength, 83 char** dataPointer); 84 static Boolean CMBlockBufferIsRangeContiguous(CMBlockBufferRef theBuffer, 85 size_t offset, 86 size_t length); 87 88 // Originally from CMSampleBuffer.h. 89 static CMBlockBufferRef CMSampleBufferGetDataBuffer(CMSampleBufferRef sbuf); 90 static CMFormatDescriptionRef CMSampleBufferGetFormatDescription( 91 CMSampleBufferRef sbuf); 92 static CVImageBufferRef CMSampleBufferGetImageBuffer( 93 CMSampleBufferRef buffer); 94 static CFArrayRef CMSampleBufferGetSampleAttachmentsArray( 95 CMSampleBufferRef sbuf, 96 Boolean createIfNecessary); 97 static CFStringRef kCMSampleAttachmentKey_NotSync(); 98 99 // Originally from CMFormatDescription.h. 100 static FourCharCode CMFormatDescriptionGetMediaSubType( 101 CMFormatDescriptionRef desc); 102 static CMVideoDimensions CMVideoFormatDescriptionGetDimensions( 103 CMVideoFormatDescriptionRef videoDesc); 104 static OSStatus CMVideoFormatDescriptionGetH264ParameterSetAtIndex( 105 CMFormatDescriptionRef videoDesc, 106 size_t parameterSetIndex, 107 const uint8_t** parameterSetPointerOut, 108 size_t* parameterSetSizeOut, 109 size_t* parameterSetCountOut, 110 int* NALUnitHeaderLengthOut) 111 /*__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0)*/; 112 113 private: 114 DISALLOW_IMPLICIT_CONSTRUCTORS(CoreMediaGlue); 115 }; 116 117 #endif // MEDIA_BASE_MAC_COREMEDIA_GLUE_H_ 118