Skip to main content

core_media_sys/
format_description.rs

1use crate::libc::{c_void, size_t};
2use crate::core_foundation_sys::base::{OSStatus, Boolean, CFAllocatorRef, CFTypeID, CFTypeRef};
3use crate::core_foundation_sys::dictionary::CFDictionaryRef;
4use crate::core_foundation_sys::string::CFStringRef;
5
6use crate::sync::CMClockRef;
7
8
9pub const kCMFormatDescriptionError_InvalidParameter: OSStatus      = -12710;
10pub const kCMFormatDescriptionError_AllocationFailed: OSStatus      = -12711;
11pub const kCMFormatDescriptionError_ValueNotAvailable: OSStatus     = -12718;
12
13pub type CMFormatDescriptionRef = *mut c_void;
14pub type CMAudioFormatDescriptionRef = CMFormatDescriptionRef;
15pub type CMVideoFormatDescriptionRef = CMFormatDescriptionRef;
16
17
18// https://developer.apple.com/documentation/kernel/fourcharcode?language=objc
19pub type FourCharCode = u32;
20
21pub type CMMediaType       = FourCharCode;
22pub type CMAudioCodecType  = FourCharCode;
23pub type CMVideoCodecType  = FourCharCode;
24pub type CMPixelFormatType = FourCharCode;
25
26
27const fn as_u32_be(array: &[u8; 4]) -> u32 {
28    ((array[0] as u32) << 24) +
29    ((array[1] as u32) << 16) +
30    ((array[2] as u32) <<  8) +
31    ((array[3] as u32) <<  0)
32}
33
34
35pub const kCMMediaType_Video: CMMediaType              = as_u32_be(b"vide");
36pub const kCMMediaType_Audio: CMMediaType              = as_u32_be(b"soun");
37pub const kCMMediaType_Muxed: CMMediaType              = as_u32_be(b"muxx");
38pub const kCMMediaType_Text: CMMediaType               = as_u32_be(b"text");
39pub const kCMMediaType_ClosedCaption: CMMediaType      = as_u32_be(b"clcp");
40pub const kCMMediaType_Subtitle: CMMediaType           = as_u32_be(b"sbtl");
41pub const kCMMediaType_TimeCode: CMMediaType           = as_u32_be(b"tmcd");
42pub const kCMMediaType_Metadata: CMMediaType           = as_u32_be(b"meta");
43
44pub const kCMAudioCodecType_AAC_LCProtected: CMAudioCodecType      = as_u32_be(b"paac");
45pub const kCMAudioCodecType_AAC_AudibleProtected: CMAudioCodecType = as_u32_be(b"aaac");
46
47pub type CMAudioFormatDescriptionMask = u32;
48pub const kCMAudioFormatDescriptionMask_StreamBasicDescription: CMAudioFormatDescriptionMask    = 1<<0;
49pub const kCMAudioFormatDescriptionMask_MagicCookie: CMAudioFormatDescriptionMask               = 1<<1;
50pub const kCMAudioFormatDescriptionMask_ChannelLayout: CMAudioFormatDescriptionMask             = 1<<2;
51pub const kCMAudioFormatDescriptionMask_Extensions: CMAudioFormatDescriptionMask                = 1<<3;
52pub const kCMAudioFormatDescriptionMask_All: CMAudioFormatDescriptionMask                       = kCMAudioFormatDescriptionMask_StreamBasicDescription
53                                                                                                | kCMAudioFormatDescriptionMask_MagicCookie
54                                                                                                | kCMAudioFormatDescriptionMask_ChannelLayout
55                                                                                                | kCMAudioFormatDescriptionMask_Extensions;
56
57
58pub const kCMPixelFormat_32ARGB: CMPixelFormatType                   = 32;
59pub const kCMPixelFormat_32BGRA: CMPixelFormatType                   = as_u32_be(b"BGRA");
60pub const kCMPixelFormat_24RGB: CMPixelFormatType                    = 24;
61pub const kCMPixelFormat_16BE555: CMPixelFormatType                  = 16;
62pub const kCMPixelFormat_16BE565: CMPixelFormatType                  = as_u32_be(b"B565");
63pub const kCMPixelFormat_16LE555: CMPixelFormatType                  = as_u32_be(b"L555");
64pub const kCMPixelFormat_16LE565: CMPixelFormatType                  = as_u32_be(b"L565");
65pub const kCMPixelFormat_16LE5551: CMPixelFormatType                 = as_u32_be(b"5551");
66pub const kCMPixelFormat_422YpCbCr8: CMPixelFormatType               = as_u32_be(b"2vuy");
67pub const kCMPixelFormat_422YpCbCr8_yuvs: CMPixelFormatType          = as_u32_be(b"yuvs");
68pub const kCMPixelFormat_444YpCbCr8: CMPixelFormatType               = as_u32_be(b"v308");
69pub const kCMPixelFormat_4444YpCbCrA8: CMPixelFormatType             = as_u32_be(b"v408");
70pub const kCMPixelFormat_422YpCbCr16: CMPixelFormatType              = as_u32_be(b"v216");
71pub const kCMPixelFormat_422YpCbCr10: CMPixelFormatType              = as_u32_be(b"v210");
72pub const kCMPixelFormat_444YpCbCr10: CMPixelFormatType              = as_u32_be(b"v410");
73pub const kCMPixelFormat_8IndexedGray_WhiteIsZero: CMPixelFormatType = 0x00000028;
74
75
76
77pub const kCMVideoCodecType_422YpCbCr8: CMVideoCodecType       = kCMPixelFormat_422YpCbCr8;
78pub const kCMVideoCodecType_Animation: CMVideoCodecType        = as_u32_be(b"rle ");
79pub const kCMVideoCodecType_Cinepak: CMVideoCodecType          = as_u32_be(b"cvid");
80pub const kCMVideoCodecType_JPEG: CMVideoCodecType             = as_u32_be(b"jpeg");
81pub const kCMVideoCodecType_JPEG_OpenDML: CMVideoCodecType     = as_u32_be(b"dmb1");
82pub const kCMVideoCodecType_SorensonVideo: CMVideoCodecType    = as_u32_be(b"SVQ1");
83pub const kCMVideoCodecType_SorensonVideo3: CMVideoCodecType   = as_u32_be(b"SVQ3");
84pub const kCMVideoCodecType_H263: CMVideoCodecType             = as_u32_be(b"h263");
85pub const kCMVideoCodecType_H264: CMVideoCodecType             = as_u32_be(b"avc1");
86pub const kCMVideoCodecType_HEVC: CMVideoCodecType             = as_u32_be(b"hvc1");
87pub const kCMVideoCodecType_MPEG4Video: CMVideoCodecType       = as_u32_be(b"mp4v");
88pub const kCMVideoCodecType_MPEG2Video: CMVideoCodecType       = as_u32_be(b"mp2v");
89pub const kCMVideoCodecType_MPEG1Video: CMVideoCodecType       = as_u32_be(b"mp1v");
90
91pub const kCMVideoCodecType_DVCNTSC: CMVideoCodecType          = as_u32_be(b"dvc ");
92pub const kCMVideoCodecType_DVCPAL: CMVideoCodecType           = as_u32_be(b"dvcp");
93pub const kCMVideoCodecType_DVCProPAL: CMVideoCodecType        = as_u32_be(b"dvpp");
94pub const kCMVideoCodecType_DVCPro50NTSC: CMVideoCodecType     = as_u32_be(b"dv5n");
95pub const kCMVideoCodecType_DVCPro50PAL: CMVideoCodecType      = as_u32_be(b"dv5p");
96pub const kCMVideoCodecType_DVCPROHD720p60: CMVideoCodecType   = as_u32_be(b"dvhp");
97pub const kCMVideoCodecType_DVCPROHD720p50: CMVideoCodecType   = as_u32_be(b"dvhq");
98pub const kCMVideoCodecType_DVCPROHD1080i60: CMVideoCodecType  = as_u32_be(b"dvh6");
99pub const kCMVideoCodecType_DVCPROHD1080i50: CMVideoCodecType  = as_u32_be(b"dvh5");
100pub const kCMVideoCodecType_DVCPROHD1080p30: CMVideoCodecType  = as_u32_be(b"dvh3");
101pub const kCMVideoCodecType_DVCPROHD1080p25: CMVideoCodecType  = as_u32_be(b"dvh2");
102
103pub const kCMVideoCodecType_AppleProRes4444: CMVideoCodecType  = as_u32_be(b"ap4h");
104pub const kCMVideoCodecType_AppleProRes422HQ: CMVideoCodecType = as_u32_be(b"apch");
105pub const kCMVideoCodecType_AppleProRes422: CMVideoCodecType   = as_u32_be(b"apcn");
106pub const kCMVideoCodecType_AppleProRes422LT: CMVideoCodecType = as_u32_be(b"apcs");
107pub const kCMVideoCodecType_AppleProRes422Proxy: CMVideoCodecType = as_u32_be(b"apco");
108
109
110#[repr(C)]
111#[derive(Debug, Copy, Clone)]
112pub struct CMVideoDimensions {
113    pub width: i32,
114    pub height: i32,
115}
116
117
118extern "C" {
119    pub static kCMFormatDescriptionExtension_OriginalCompressionSettings: CFStringRef;
120    pub static kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms: CFStringRef;
121    pub static kCMFormatDescriptionExtension_VerbatimSampleDescription: CFStringRef;
122    pub static kCMFormatDescriptionExtension_VerbatimISOSampleEntry: CFStringRef;
123
124    pub static kCMFormatDescriptionExtension_FormatName: CFStringRef;
125    pub static kCMFormatDescriptionExtension_Depth: CFStringRef;
126
127    pub static kCMFormatDescriptionExtension_CleanAperture: CFStringRef;
128    pub static kCMFormatDescriptionKey_CleanApertureWidth: CFStringRef;
129    pub static kCMFormatDescriptionKey_CleanApertureHeight: CFStringRef;
130    pub static kCMFormatDescriptionKey_CleanApertureHorizontalOffset: CFStringRef;
131    pub static kCMFormatDescriptionKey_CleanApertureVerticalOffset: CFStringRef;
132
133    pub static kCMFormatDescriptionKey_CleanApertureWidthRational: CFStringRef;
134    pub static kCMFormatDescriptionKey_CleanApertureHeightRational: CFStringRef;
135    pub static kCMFormatDescriptionKey_CleanApertureHorizontalOffsetRational: CFStringRef;
136    pub static kCMFormatDescriptionKey_CleanApertureVerticalOffsetRational: CFStringRef;
137    pub static kCMFormatDescriptionExtension_FieldCount: CFStringRef;
138
139    pub static kCMFormatDescriptionExtension_FieldDetail: CFStringRef;
140    pub static kCMFormatDescriptionFieldDetail_TemporalTopFirst: CFStringRef;
141    pub static kCMFormatDescriptionFieldDetail_TemporalBottomFirst: CFStringRef;
142    pub static kCMFormatDescriptionFieldDetail_SpatialFirstLineEarly: CFStringRef;
143    pub static kCMFormatDescriptionFieldDetail_SpatialFirstLineLate: CFStringRef;
144
145
146
147    pub fn CMFormatDescriptionCreate(allocator: CFAllocatorRef,
148                                     mediaType: CMMediaType,
149                                     mediaSubtype: FourCharCode,
150                                     extensions: CFDictionaryRef,
151                                     descOut: *mut CMFormatDescriptionRef) -> OSStatus;
152
153    pub fn CMFormatDescriptionGetTypeID() -> CFTypeID;
154    pub fn CMFormatDescriptionEqual(desc1: CMFormatDescriptionRef,
155                                    desc2: CMFormatDescriptionRef) -> Boolean;
156
157    pub fn CMFormatDescriptionGetMediaType(desc: CMFormatDescriptionRef) -> CMMediaType;
158    pub fn CMFormatDescriptionGetMediaSubType(desc: CMFormatDescriptionRef) -> FourCharCode;
159
160
161    // /System/Library/Frameworks/CoreAudio.framework/Versions/A/Headers/CoreAudioTypes.h
162    // pub fn CMAudioFormatDescriptionCreate(allocator: CFAllocatorRef,
163    //                                       asbd: *const AudioStreamBasicDescription,
164    //                                       layoutSize: size_t,
165    //                                       layout: *const AudioChannelLayout,
166    //                                       magicCookieSize: size_t,
167    //                                       magicCookie: *const c_void,
168    //                                       extensions: CFDictionaryRef,
169    //                                       outDesc: *mut CMAudioFormatDescriptionRef) -> OSStatus;
170
171    pub fn CMVideoFormatDescriptionCreate(allocator: CFAllocatorRef,
172                                          codecType: CMVideoCodecType,
173                                          width: i32,
174                                          height: i32,
175                                          extensions: CFDictionaryRef,
176                                          outDesc: *mut CMVideoFormatDescriptionRef) -> OSStatus;
177}