1use std::{
2 mem::{forget, size_of_val},
3 ptr::{null, null_mut},
4 slice::from_raw_parts,
5};
6
7use core_audio_types::{AudioChannelLayout, AudioFormatListItem, AudioStreamBasicDescription};
8use core_foundation::{
9 array::{CFArray, CFArrayRef},
10 base::{kCFAllocatorDefault, Boolean, CFAllocatorRef, CFType, CFTypeID, CFTypeRef, OSStatus, TCFType, TCFTypeRef},
11 declare_TCFType,
12 dictionary::{CFDictionary, CFDictionaryRef},
13 impl_CFTypeDescription, impl_TCFType,
14 propertylist::{CFPropertyList, CFPropertyListRef},
15 string::{CFString, CFStringRef},
16};
17use core_graphics::{
18 base::CGFloat,
19 geometry::{CGRect, CGSize},
20};
21use core_video::image_buffer::{CVImageBuffer, CVImageBufferRef};
22use libc::{c_int, c_void, size_t};
23#[cfg(feature = "objc")]
24use objc2::encode::{Encoding, RefEncode};
25
26use crate::{base::status_to_result, time::CMTime, OSType};
27
28pub const kCMFormatDescriptionError_InvalidParameter: OSStatus = -12710;
29pub const kCMFormatDescriptionError_AllocationFailed: OSStatus = -12711;
30pub const kCMFormatDescriptionError_ValueNotAvailable: OSStatus = -12718;
31
32type FourCharCode = u32;
33
34pub type CMMediaType = FourCharCode;
35
36#[inline]
37const fn fourcc(code: &[u8; 4]) -> u32 {
38 ((code[0] as u32) << 24) | ((code[1] as u32) << 16) | ((code[2] as u32) << 8) | (code[3] as u32)
39}
40
41pub const kCMMediaType_Video: CMMediaType = fourcc(b"vide");
42pub const kCMMediaType_Audio: CMMediaType = fourcc(b"soun");
43pub const kCMMediaType_Muxed: CMMediaType = fourcc(b"muxx");
44pub const kCMMediaType_Text: CMMediaType = fourcc(b"text");
45pub const kCMMediaType_ClosedCaption: CMMediaType = fourcc(b"clcp");
46pub const kCMMediaType_Subtitle: CMMediaType = fourcc(b"sbtl");
47pub const kCMMediaType_TimeCode: CMMediaType = fourcc(b"tmcd");
48pub const kCMMediaType_Metadata: CMMediaType = fourcc(b"meta");
49pub const kCMMediaType_TaggedBufferGroup: CMMediaType = fourcc(b"tbgr");
50
51#[repr(C)]
52pub struct opaqueCMFormatDescription(c_void);
53
54pub type CMFormatDescriptionRef = *mut opaqueCMFormatDescription;
55
56extern "C" {
57 pub fn CMFormatDescriptionCreate(
58 allocator: CFAllocatorRef,
59 mediaType: CMMediaType,
60 mediaSubType: FourCharCode,
61 extensions: CFDictionaryRef,
62 formatDescriptionOut: *mut CMFormatDescriptionRef,
63 ) -> OSStatus;
64 pub fn CMFormatDescriptionGetTypeID() -> CFTypeID;
65 pub fn CMFormatDescriptionEqual(formatDescription: CMFormatDescriptionRef, otherFormatDescription: CMFormatDescriptionRef) -> Boolean;
66 pub fn CMFormatDescriptionEqualIgnoringExtensionKeys(
67 formatDescription: CMFormatDescriptionRef,
68 otherFormatDescription: CMFormatDescriptionRef,
69 formatDescriptionExtensionKeysToIgnore: CFTypeRef,
70 sampleDescriptionExtensionAtomKeysToIgnore: CFTypeRef,
71 ) -> Boolean;
72 pub fn CMFormatDescriptionGetMediaType(desc: CMFormatDescriptionRef) -> CMMediaType;
73 pub fn CMFormatDescriptionGetMediaSubType(desc: CMFormatDescriptionRef) -> FourCharCode;
74 pub fn CMFormatDescriptionGetExtensions(desc: CMFormatDescriptionRef) -> CFDictionaryRef;
75
76 pub static kCMFormatDescriptionExtension_OriginalCompressionSettings: CFStringRef;
77 pub static kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms: CFStringRef;
78 pub static kCMFormatDescriptionExtension_VerbatimSampleDescription: CFStringRef;
79 pub static kCMFormatDescriptionExtension_VerbatimISOSampleEntry: CFStringRef;
80
81 pub fn CMFormatDescriptionGetExtension(desc: CMFormatDescriptionRef, extensionKey: CFStringRef) -> CFPropertyListRef;
82}
83
84pub type CMAudioCodecType = FourCharCode;
85
86pub const kCMAudioCodecType_AAC_LCProtected: CMAudioCodecType = fourcc(b"paac");
87pub const kCMAudioCodecType_AAC_AudibleProtected: CMAudioCodecType = fourcc(b"aaac");
88
89pub type CMAudioFormatDescriptionRef = CMFormatDescriptionRef;
90
91extern "C" {
92 pub fn CMAudioFormatDescriptionCreate(
93 allocator: CFAllocatorRef,
94 asbd: *const AudioStreamBasicDescription,
95 layoutSize: size_t,
96 layout: *const AudioChannelLayout,
97 magicCookieSize: size_t,
98 magicCookie: *const c_void,
99 extensions: CFDictionaryRef,
100 formatDescriptionOut: *mut CMAudioFormatDescriptionRef,
101 ) -> OSStatus;
102 pub fn CMAudioFormatDescriptionGetStreamBasicDescription(desc: CMAudioFormatDescriptionRef) -> *const AudioStreamBasicDescription;
103 pub fn CMAudioFormatDescriptionGetMagicCookie(desc: CMAudioFormatDescriptionRef, sizeOut: *mut size_t) -> *const c_void;
104 pub fn CMAudioFormatDescriptionGetChannelLayout(desc: CMAudioFormatDescriptionRef, sizeOut: *mut size_t) -> *const AudioChannelLayout;
105 pub fn CMAudioFormatDescriptionGetFormatList(desc: CMAudioFormatDescriptionRef, sizeOut: *mut size_t) -> *const AudioFormatListItem;
106 pub fn CMAudioFormatDescriptionGetRichestDecodableFormat(desc: CMAudioFormatDescriptionRef) -> *const AudioFormatListItem;
107 pub fn CMAudioFormatDescriptionGetMostCompatibleFormat(desc: CMAudioFormatDescriptionRef) -> *const AudioFormatListItem;
108 pub fn CMAudioFormatDescriptionCreateSummary(
109 allocator: CFAllocatorRef,
110 formatDescriptionArray: CFArrayRef,
111 flags: u32,
112 formatDescriptionOut: *mut CMAudioFormatDescriptionRef,
113 ) -> OSStatus;
114}
115
116pub type CMAudioFormatDescriptionMask = u32;
117
118pub const kCMAudioFormatDescriptionMask_StreamBasicDescription: CMAudioFormatDescriptionMask = 1 << 0;
119pub const kCMAudioFormatDescriptionMask_MagicCookie: CMAudioFormatDescriptionMask = 1 << 1;
120pub const kCMAudioFormatDescriptionMask_ChannelLayout: CMAudioFormatDescriptionMask = 1 << 2;
121pub const kCMAudioFormatDescriptionMask_Extensions: CMAudioFormatDescriptionMask = 1 << 3;
122pub const kCMAudioFormatDescriptionMask_All: CMAudioFormatDescriptionMask = kCMAudioFormatDescriptionMask_StreamBasicDescription |
123 kCMAudioFormatDescriptionMask_MagicCookie |
124 kCMAudioFormatDescriptionMask_ChannelLayout |
125 kCMAudioFormatDescriptionMask_Extensions;
126
127extern "C" {
128 pub fn CMAudioFormatDescriptionEqual(
129 formatDescription: CMAudioFormatDescriptionRef,
130 otherFormatDescription: CMAudioFormatDescriptionRef,
131 equalityMask: CMAudioFormatDescriptionMask,
132 equalityMaskOut: *mut CMAudioFormatDescriptionMask,
133 ) -> Boolean;
134}
135
136pub type CMVideoFormatDescriptionRef = CMFormatDescriptionRef;
137
138pub type CMPixelFormatType = FourCharCode;
139
140pub const kCMPixelFormat_32ARGB: CMPixelFormatType = 32;
141pub const kCMPixelFormat_32BGRA: CMPixelFormatType = fourcc(b"BGRA");
142pub const kCMPixelFormat_24RGB: CMPixelFormatType = 24;
143pub const kCMPixelFormat_16BE555: CMPixelFormatType = 16;
144pub const kCMPixelFormat_16BE565: CMPixelFormatType = fourcc(b"B565");
145pub const kCMPixelFormat_16LE555: CMPixelFormatType = fourcc(b"L555");
146pub const kCMPixelFormat_16LE565: CMPixelFormatType = fourcc(b"L565");
147pub const kCMPixelFormat_16LE5551: CMPixelFormatType = fourcc(b"5551");
148pub const kCMPixelFormat_422YpCbCr8: CMPixelFormatType = fourcc(b"2vuy");
149pub const kCMPixelFormat_422YpCbCr8_yuvs: CMPixelFormatType = fourcc(b"yuvs");
150pub const kCMPixelFormat_444YpCbCr8: CMPixelFormatType = fourcc(b"v308");
151pub const kCMPixelFormat_4444YpCbCrA8: CMPixelFormatType = fourcc(b"v408");
152pub const kCMPixelFormat_422YpCbCr16: CMPixelFormatType = fourcc(b"v216");
153pub const kCMPixelFormat_422YpCbCr10: CMPixelFormatType = fourcc(b"v210");
154pub const kCMPixelFormat_444YpCbCr10: CMPixelFormatType = fourcc(b"v410");
155pub const kCMPixelFormat_8IndexedGray_WhiteIsZero: CMPixelFormatType = 0x00000028;
156
157pub type CMVideoCodecType = FourCharCode;
158
159pub const kCMVideoCodecType_422YpCbCr8: CMVideoCodecType = kCMPixelFormat_422YpCbCr8;
160pub const kCMVideoCodecType_Animation: CMVideoCodecType = fourcc(b"rle ");
161pub const kCMVideoCodecType_Cinepak: CMVideoCodecType = fourcc(b"cvid");
162pub const kCMVideoCodecType_JPEG: CMVideoCodecType = fourcc(b"jpeg");
163pub const kCMVideoCodecType_JPEG_OpenDML: CMVideoCodecType = fourcc(b"dmb1");
164pub const kCMVideoCodecType_SorensonVideo: CMVideoCodecType = fourcc(b"SVQ1");
165pub const kCMVideoCodecType_SorensonVideo3: CMVideoCodecType = fourcc(b"SVQ3");
166pub const kCMVideoCodecType_H263: CMVideoCodecType = fourcc(b"h263");
167pub const kCMVideoCodecType_H264: CMVideoCodecType = fourcc(b"avc1");
168pub const kCMVideoCodecType_HEVC: CMVideoCodecType = fourcc(b"hvc1");
169pub const kCMVideoCodecType_HEVCWithAlpha: CMVideoCodecType = fourcc(b"muxa");
170pub const kCMVideoCodecType_DolbyVisionHEVC: CMVideoCodecType = fourcc(b"dvh1");
171pub const kCMVideoCodecType_MPEG4Video: CMVideoCodecType = fourcc(b"mp4v");
172pub const kCMVideoCodecType_MPEG2Video: CMVideoCodecType = fourcc(b"mp2v");
173pub const kCMVideoCodecType_MPEG1Video: CMVideoCodecType = fourcc(b"mp1v");
174pub const kCMVideoCodecType_VP9: CMVideoCodecType = fourcc(b"vp09");
175pub const kCMVideoCodecType_DVCNTSC: CMVideoCodecType = fourcc(b"dvc ");
176pub const kCMVideoCodecType_DVCPAL: CMVideoCodecType = fourcc(b"dvcp");
177pub const kCMVideoCodecType_DVCProPAL: CMVideoCodecType = fourcc(b"dvpp");
178pub const kCMVideoCodecType_DVCPro50NTSC: CMVideoCodecType = fourcc(b"dv5n");
179pub const kCMVideoCodecType_DVCPro50PAL: CMVideoCodecType = fourcc(b"dv5p");
180pub const kCMVideoCodecType_DVCPROHD720p60: CMVideoCodecType = fourcc(b"dvhp");
181pub const kCMVideoCodecType_DVCPROHD720p50: CMVideoCodecType = fourcc(b"dvhq");
182pub const kCMVideoCodecType_DVCPROHD1080i60: CMVideoCodecType = fourcc(b"dvh6");
183pub const kCMVideoCodecType_DVCPROHD1080i50: CMVideoCodecType = fourcc(b"dvh5");
184pub const kCMVideoCodecType_DVCPROHD1080p30: CMVideoCodecType = fourcc(b"dvh3");
185pub const kCMVideoCodecType_DVCPROHD1080p25: CMVideoCodecType = fourcc(b"dvh2");
186pub const kCMVideoCodecType_AppleProRes4444XQ: CMVideoCodecType = fourcc(b"ap4x");
187pub const kCMVideoCodecType_AppleProRes4444: CMVideoCodecType = fourcc(b"ap4h");
188pub const kCMVideoCodecType_AppleProRes422HQ: CMVideoCodecType = fourcc(b"apch");
189pub const kCMVideoCodecType_AppleProRes422: CMVideoCodecType = fourcc(b"apcn");
190pub const kCMVideoCodecType_AppleProRes422LT: CMVideoCodecType = fourcc(b"apcs");
191pub const kCMVideoCodecType_AppleProRes422Proxy: CMVideoCodecType = fourcc(b"apco");
192pub const kCMVideoCodecType_AppleProResRAW: CMVideoCodecType = fourcc(b"aprn");
193pub const kCMVideoCodecType_AppleProResRAWHQ: CMVideoCodecType = fourcc(b"aprh");
194pub const kCMVideoCodecType_DisparityHEVC: CMVideoCodecType = fourcc(b"dish");
195pub const kCMVideoCodecType_DepthHEVC: CMVideoCodecType = fourcc(b"deph");
196pub const kCMVideoCodecType_AV1: CMVideoCodecType = fourcc(b"av01");
197
198#[repr(C, packed(4))]
199#[derive(Clone, Copy, Debug, Default, PartialEq)]
200pub struct CMVideoDimensions {
201 pub width: i32,
202 pub height: i32,
203}
204
205extern "C" {
206 pub static kCMFormatDescriptionExtension_FormatName: CFStringRef;
207 pub static kCMFormatDescriptionExtension_Depth: CFStringRef;
208 pub static kCMFormatDescriptionExtension_CleanAperture: CFStringRef;
209 pub static kCMFormatDescriptionKey_CleanApertureWidth: CFStringRef;
210 pub static kCMFormatDescriptionKey_CleanApertureHeight: CFStringRef;
211 pub static kCMFormatDescriptionKey_CleanApertureHorizontalOffset: CFStringRef;
212 pub static kCMFormatDescriptionKey_CleanApertureVerticalOffset: CFStringRef;
213 pub static kCMFormatDescriptionKey_CleanApertureWidthRational: CFStringRef;
214 pub static kCMFormatDescriptionKey_CleanApertureHeightRational: CFStringRef;
215 pub static kCMFormatDescriptionKey_CleanApertureHorizontalOffsetRational: CFStringRef;
216 pub static kCMFormatDescriptionKey_CleanApertureVerticalOffsetRational: CFStringRef;
217 pub static kCMFormatDescriptionExtension_FieldCount: CFStringRef;
218 pub static kCMFormatDescriptionFieldDetail_TemporalTopFirst: CFStringRef;
219 pub static kCMFormatDescriptionFieldDetail_TemporalBottomFirst: CFStringRef;
220 pub static kCMFormatDescriptionFieldDetail_SpatialFirstLineEarly: CFStringRef;
221 pub static kCMFormatDescriptionFieldDetail_SpatialFirstLineLate: CFStringRef;
222 pub static kCMFormatDescriptionExtension_PixelAspectRatio: CFStringRef;
223 pub static kCMFormatDescriptionKey_PixelAspectRatioHorizontalSpacing: CFStringRef;
224 pub static kCMFormatDescriptionKey_PixelAspectRatioVerticalSpacing: CFStringRef;
225 pub static kCMFormatDescriptionExtension_ColorPrimaries: CFStringRef;
226 pub static kCMFormatDescriptionColorPrimaries_ITU_R_709_2: CFStringRef;
227 pub static kCMFormatDescriptionColorPrimaries_EBU_3213: CFStringRef;
228 pub static kCMFormatDescriptionColorPrimaries_SMPTE_C: CFStringRef;
229 pub static kCMFormatDescriptionColorPrimaries_DCI_P3: CFStringRef;
230 pub static kCMFormatDescriptionColorPrimaries_P3_D65: CFStringRef;
231 pub static kCMFormatDescriptionColorPrimaries_ITU_R_2020: CFStringRef;
232 pub static kCMFormatDescriptionColorPrimaries_P22: CFStringRef;
233 pub static kCMFormatDescriptionExtension_TransferFunction: CFStringRef;
234 pub static kCMFormatDescriptionTransferFunction_ITU_R_709_2: CFStringRef;
235 pub static kCMFormatDescriptionTransferFunction_SMPTE_240M_1995: CFStringRef;
236 pub static kCMFormatDescriptionTransferFunction_UseGamma: CFStringRef;
237 pub static kCMFormatDescriptionTransferFunction_ITU_R_2020: CFStringRef;
238 pub static kCMFormatDescriptionTransferFunction_SMPTE_ST_428_1: CFStringRef;
239 pub static kCMFormatDescriptionTransferFunction_SMPTE_ST_2084_PQ: CFStringRef;
240 pub static kCMFormatDescriptionTransferFunction_ITU_R_2100_HLG: CFStringRef;
241 pub static kCMFormatDescriptionTransferFunction_Linear: CFStringRef;
242 pub static kCMFormatDescriptionTransferFunction_sRGB: CFStringRef;
243 pub static kCMFormatDescriptionExtension_GammaLevel: CFStringRef;
244 pub static kCMFormatDescriptionExtension_YCbCrMatrix: CFStringRef;
245 pub static kCMFormatDescriptionYCbCrMatrix_ITU_R_709_2: CFStringRef;
246 pub static kCMFormatDescriptionYCbCrMatrix_ITU_R_601_4: CFStringRef;
247 pub static kCMFormatDescriptionYCbCrMatrix_SMPTE_240M_1995: CFStringRef;
248 pub static kCMFormatDescriptionYCbCrMatrix_ITU_R_2020: CFStringRef;
249 pub static kCMFormatDescriptionExtension_FullRangeVideo: CFStringRef;
250 pub static kCMFormatDescriptionExtension_ICCProfile: CFStringRef;
251 pub static kCMFormatDescriptionExtension_BytesPerRow: CFStringRef;
252 pub static kCMFormatDescriptionExtension_ChromaLocationTopField: CFStringRef;
253 pub static kCMFormatDescriptionExtension_ChromaLocationBottomField: CFStringRef;
254 pub static kCMFormatDescriptionChromaLocation_Left: CFStringRef;
255 pub static kCMFormatDescriptionChromaLocation_Center: CFStringRef;
256 pub static kCMFormatDescriptionChromaLocation_TopLeft: CFStringRef;
257 pub static kCMFormatDescriptionChromaLocation_Top: CFStringRef;
258 pub static kCMFormatDescriptionChromaLocation_BottomLeft: CFStringRef;
259 pub static kCMFormatDescriptionChromaLocation_Bottom: CFStringRef;
260 pub static kCMFormatDescriptionChromaLocation_DV420: CFStringRef;
261 pub static kCMFormatDescriptionConformsToMPEG2VideoProfile: CFStringRef;
262 pub static kCMFormatDescriptionExtension_ProtectedContentOriginalFormat: CFStringRef;
263}
264
265pub const kCMMPEG2VideoProfile_HDV_720p30: i32 = fourcc(b"hdv1") as i32;
266pub const kCMMPEG2VideoProfile_HDV_1080i60: i32 = fourcc(b"hdv2") as i32;
267pub const kCMMPEG2VideoProfile_HDV_1080i50: i32 = fourcc(b"hdv3") as i32;
268pub const kCMMPEG2VideoProfile_HDV_720p24: i32 = fourcc(b"hdv4") as i32;
269pub const kCMMPEG2VideoProfile_HDV_720p25: i32 = fourcc(b"hdv5") as i32;
270pub const kCMMPEG2VideoProfile_HDV_1080p24: i32 = fourcc(b"hdv6") as i32;
271pub const kCMMPEG2VideoProfile_HDV_1080p25: i32 = fourcc(b"hdv7") as i32;
272pub const kCMMPEG2VideoProfile_HDV_1080p30: i32 = fourcc(b"hdv8") as i32;
273pub const kCMMPEG2VideoProfile_HDV_720p60: i32 = fourcc(b"hdv9") as i32;
274pub const kCMMPEG2VideoProfile_HDV_720p50: i32 = fourcc(b"hdva") as i32;
275pub const kCMMPEG2VideoProfile_XDCAM_HD_1080i60_VBR35: i32 = fourcc(b"xdv2") as i32;
276pub const kCMMPEG2VideoProfile_XDCAM_HD_1080i50_VBR35: i32 = fourcc(b"xdv3") as i32;
277pub const kCMMPEG2VideoProfile_XDCAM_HD_1080p24_VBR35: i32 = fourcc(b"xdv6") as i32;
278pub const kCMMPEG2VideoProfile_XDCAM_HD_1080p25_VBR35: i32 = fourcc(b"xdv7") as i32;
279pub const kCMMPEG2VideoProfile_XDCAM_HD_1080p30_VBR35: i32 = fourcc(b"xdv8") as i32;
280pub const kCMMPEG2VideoProfile_XDCAM_EX_720p24_VBR35: i32 = fourcc(b"xdv4") as i32;
281pub const kCMMPEG2VideoProfile_XDCAM_EX_720p25_VBR35: i32 = fourcc(b"xdv5") as i32;
282pub const kCMMPEG2VideoProfile_XDCAM_EX_720p30_VBR35: i32 = fourcc(b"xdv1") as i32;
283pub const kCMMPEG2VideoProfile_XDCAM_EX_720p50_VBR35: i32 = fourcc(b"xdva") as i32;
284pub const kCMMPEG2VideoProfile_XDCAM_EX_720p60_VBR35: i32 = fourcc(b"xdv9") as i32;
285pub const kCMMPEG2VideoProfile_XDCAM_EX_1080i60_VBR35: i32 = fourcc(b"xdvb") as i32;
286pub const kCMMPEG2VideoProfile_XDCAM_EX_1080i50_VBR35: i32 = fourcc(b"xdvc") as i32;
287pub const kCMMPEG2VideoProfile_XDCAM_EX_1080p24_VBR35: i32 = fourcc(b"xdvd") as i32;
288pub const kCMMPEG2VideoProfile_XDCAM_EX_1080p25_VBR35: i32 = fourcc(b"xdve") as i32;
289pub const kCMMPEG2VideoProfile_XDCAM_EX_1080p30_VBR35: i32 = fourcc(b"xdvf") as i32;
290pub const kCMMPEG2VideoProfile_XDCAM_HD422_720p50_CBR50: i32 = fourcc(b"xd5a") as i32;
291pub const kCMMPEG2VideoProfile_XDCAM_HD422_720p60_CBR50: i32 = fourcc(b"xd59") as i32;
292pub const kCMMPEG2VideoProfile_XDCAM_HD422_1080i60_CBR50: i32 = fourcc(b"xd5b") as i32;
293pub const kCMMPEG2VideoProfile_XDCAM_HD422_1080i50_CBR50: i32 = fourcc(b"xd5c") as i32;
294pub const kCMMPEG2VideoProfile_XDCAM_HD422_1080p24_CBR50: i32 = fourcc(b"xd5d") as i32;
295pub const kCMMPEG2VideoProfile_XDCAM_HD422_1080p25_CBR50: i32 = fourcc(b"xd5e") as i32;
296pub const kCMMPEG2VideoProfile_XDCAM_HD422_1080p30_CBR50: i32 = fourcc(b"xd5f") as i32;
297pub const kCMMPEG2VideoProfile_XDCAM_HD_540p: i32 = fourcc(b"xdhd") as i32;
298pub const kCMMPEG2VideoProfile_XDCAM_HD422_540p: i32 = fourcc(b"xdh2") as i32;
299pub const kCMMPEG2VideoProfile_XDCAM_HD422_720p24_CBR50: i32 = fourcc(b"xd54") as i32;
300pub const kCMMPEG2VideoProfile_XDCAM_HD422_720p25_CBR50: i32 = fourcc(b"xd55") as i32;
301pub const kCMMPEG2VideoProfile_XDCAM_HD422_720p30_CBR50: i32 = fourcc(b"xd51") as i32;
302pub const kCMMPEG2VideoProfile_XF: i32 = fourcc(b"xfz1") as i32;
303
304extern "C" {
305 pub static kCMFormatDescriptionExtension_TemporalQuality: CFStringRef;
306 pub static kCMFormatDescriptionExtension_SpatialQuality: CFStringRef;
307 pub static kCMFormatDescriptionExtension_VerbatimImageDescription: CFStringRef;
308 pub static kCMFormatDescriptionExtension_Version: CFStringRef;
309 pub static kCMFormatDescriptionExtension_RevisionLevel: CFStringRef;
310 pub static kCMFormatDescriptionExtension_Vendor: CFStringRef;
311 pub static kCMFormatDescriptionVendor_Apple: CFStringRef;
312 pub static kCMFormatDescriptionExtension_MasteringDisplayColorVolume: CFStringRef;
313 pub static kCMFormatDescriptionExtension_ContentLightLevelInfo: CFStringRef;
314 pub static kCMFormatDescriptionExtension_ContentColorVolume: CFStringRef;
315 pub static kCMFormatDescriptionExtension_AlternativeTransferCharacteristics: CFStringRef;
316 pub static kCMFormatDescriptionExtension_AuxiliaryTypeInfo: CFStringRef;
317 pub static kCMFormatDescriptionExtension_AlphaChannelMode: CFStringRef;
318 pub static kCMFormatDescriptionAlphaChannelMode_StraightAlpha: CFStringRef;
319 pub static kCMFormatDescriptionAlphaChannelMode_PremultipliedAlpha: CFStringRef;
320 pub static kCMFormatDescriptionExtension_ContainsAlphaChannel: CFStringRef;
321 pub static kCMFormatDescriptionExtension_BitsPerComponent: CFStringRef;
322 pub static kCMFormatDescriptionExtension_HorizontalFieldOfView: CFStringRef;
323 pub static kCMFormatDescriptionExtension_HeroEye: CFStringRef;
324 pub static kCMFormatDescriptionHeroEye_Left: CFStringRef;
325 pub static kCMFormatDescriptionHeroEye_Right: CFStringRef;
326 pub static kCMFormatDescriptionExtension_StereoCameraBaseline: CFStringRef;
327 pub static kCMFormatDescriptionExtension_HorizontalDisparityAdjustment: CFStringRef;
328
329 pub fn CMVideoFormatDescriptionCreate(
330 allocator: CFAllocatorRef,
331 codecType: CMVideoCodecType,
332 width: i32,
333 height: i32,
334 extensions: CFDictionaryRef,
335 formatDescriptionOut: *mut CMVideoFormatDescriptionRef,
336 ) -> OSStatus;
337 pub fn CMVideoFormatDescriptionCreateForImageBuffer(
338 allocator: CFAllocatorRef,
339 imageBuffer: CVImageBufferRef,
340 formatDescriptionOut: *mut CMVideoFormatDescriptionRef,
341 ) -> OSStatus;
342 pub fn CMVideoFormatDescriptionCreateFromH264ParameterSets(
343 allocator: CFAllocatorRef,
344 parameterSetCount: size_t,
345 parameterSetPointers: *const *const u8,
346 parameterSetSizes: *const size_t,
347 NALUnitHeaderLength: c_int,
348 formatDescriptionOut: *mut CMFormatDescriptionRef,
349 ) -> OSStatus;
350 pub fn CMVideoFormatDescriptionCreateFromHEVCParameterSets(
351 allocator: CFAllocatorRef,
352 parameterSetCount: size_t,
353 parameterSetPointers: *const *const u8,
354 parameterSetSizes: *const size_t,
355 NALUnitHeaderLength: c_int,
356 extensions: CFDictionaryRef,
357 formatDescriptionOut: *mut CMFormatDescriptionRef,
358 ) -> OSStatus;
359 pub fn CMVideoFormatDescriptionGetH264ParameterSetAtIndex(
360 videoDesc: CMFormatDescriptionRef,
361 parameterSetIndex: size_t,
362 parameterSetPointerOut: *mut *const u8,
363 parameterSetSizeOut: *mut size_t,
364 parameterSetCountOut: *mut size_t,
365 NALUnitHeaderLengthOut: *mut c_int,
366 ) -> OSStatus;
367 pub fn CMVideoFormatDescriptionGetHEVCParameterSetAtIndex(
368 videoDesc: CMFormatDescriptionRef,
369 parameterSetIndex: size_t,
370 parameterSetPointerOut: *mut *const u8,
371 parameterSetSizeOut: *mut size_t,
372 parameterSetCountOut: *mut size_t,
373 NALUnitHeaderLengthOut: *mut c_int,
374 ) -> OSStatus;
375 pub fn CMVideoFormatDescriptionGetDimensions(videoDesc: CMVideoFormatDescriptionRef) -> CMVideoDimensions;
376 pub fn CMVideoFormatDescriptionGetPresentationDimensions(
377 videoDesc: CMVideoFormatDescriptionRef,
378 usePixelAspectRatio: Boolean,
379 useCleanAperture: Boolean,
380 ) -> CGSize;
381 pub fn CMVideoFormatDescriptionGetCleanAperture(videoDesc: CMVideoFormatDescriptionRef, originIsAtTopLeft: Boolean) -> CGRect;
382 pub fn CMVideoFormatDescriptionGetExtensionKeysCommonWithImageBuffers() -> CFArrayRef;
383 pub fn CMVideoFormatDescriptionMatchesImageBuffer(videoDesc: CMVideoFormatDescriptionRef, imageBuffer: CVImageBufferRef) -> Boolean;
384 pub fn CMVideoFormatDescriptionCopyTagCollectionArray(
385 formatDescription: CMVideoFormatDescriptionRef,
386 tagCollectionsOut: *mut CFArrayRef,
387 ) -> OSStatus;
388}
389
390pub type CMTaggedBufferGroupFormatDescriptionRef = CMFormatDescriptionRef;
391
392pub type CMTaggedBufferGroupFormatType = FourCharCode;
393
394pub const kCMTaggedBufferGroupFormatType_TaggedBufferGroup: CMTaggedBufferGroupFormatType = fourcc(b"tbgr");
395
396pub type CMMuxedFormatDescriptionRef = CMFormatDescriptionRef;
397
398pub type CMMuxedStreamType = FourCharCode;
399
400pub const kCMMuxedStreamType_MPEG1System: CMMuxedStreamType = fourcc(b"mp1s");
401pub const kCMMuxedStreamType_MPEG2Transport: CMMuxedStreamType = fourcc(b"mp2t");
402pub const kCMMuxedStreamType_MPEG2Program: CMMuxedStreamType = fourcc(b"mp2p");
403pub const kCMMuxedStreamType_DV: CMMuxedStreamType = fourcc(b"dv ");
404pub const kCMMuxedStreamType_EmbeddedDeviceScreenRecording: CMMuxedStreamType = fourcc(b"isr ");
405
406extern "C" {
407 pub fn CMMuxedFormatDescriptionCreate(
408 allocator: CFAllocatorRef,
409 muxType: CMMuxedStreamType,
410 extensions: CFDictionaryRef,
411 formatDescriptionOut: *mut CMMuxedFormatDescriptionRef,
412 ) -> OSStatus;
413}
414
415pub type CMClosedCaptionFormatDescriptionRef = CMFormatDescriptionRef;
416
417pub type CMClosedCaptionFormatType = FourCharCode;
418
419pub const kCMClosedCaptionFormatType_CEA608: CMClosedCaptionFormatType = fourcc(b"c608");
420pub const kCMClosedCaptionFormatType_CEA708: CMClosedCaptionFormatType = fourcc(b"c708");
421pub const kCMClosedCaptionFormatType_ATSC: CMClosedCaptionFormatType = fourcc(b"atcc");
422
423pub type CMTextFormatDescriptionRef = CMFormatDescriptionRef;
424
425pub type CMTextFormatType = FourCharCode;
426
427pub const kCMTextFormatType_QTText: CMTextFormatType = fourcc(b"text");
428pub const kCMTextFormatType_3GText: CMTextFormatType = fourcc(b"tx3g");
429
430pub type CMTextDisplayFlags = u32;
431
432pub const kCMTextDisplayFlag_scrollIn: CMTextDisplayFlags = 0x00000020;
433pub const kCMTextDisplayFlag_scrollOut: CMTextDisplayFlags = 0x00000040;
434pub const kCMTextDisplayFlag_scrollDirectionMask: CMTextDisplayFlags = 0x00000180;
435pub const kCMTextDisplayFlag_scrollDirection_bottomToTop: CMTextDisplayFlags = 0x00000000;
436pub const kCMTextDisplayFlag_scrollDirection_rightToLeft: CMTextDisplayFlags = 0x00000080;
437pub const kCMTextDisplayFlag_scrollDirection_topToBottom: CMTextDisplayFlags = 0x00000100;
438pub const kCMTextDisplayFlag_scrollDirection_leftToRight: CMTextDisplayFlags = 0x00000180;
439pub const kCMTextDisplayFlag_continuousKaraoke: CMTextDisplayFlags = 0x00000800;
440pub const kCMTextDisplayFlag_writeTextVertically: CMTextDisplayFlags = 0x00020000;
441pub const kCMTextDisplayFlag_fillTextRegion: CMTextDisplayFlags = 0x00040000;
442pub const kCMTextDisplayFlag_obeySubtitleFormatting: CMTextDisplayFlags = 0x20000000;
443pub const kCMTextDisplayFlag_forcedSubtitlesPresent: CMTextDisplayFlags = 0x40000000;
444pub const kCMTextDisplayFlag_allSubtitlesForced: CMTextDisplayFlags = 0x80000000;
445
446pub type CMTextJustificationValue = i8;
447
448pub const kCMTextJustification_left_top: CMTextJustificationValue = 0;
449pub const kCMTextJustification_centered: CMTextJustificationValue = 1;
450pub const kCMTextJustification_bottom_right: CMTextJustificationValue = -1;
451
452extern "C" {
453 pub static kCMTextFormatDescriptionExtension_DisplayFlags: CFStringRef;
454 pub static kCMTextFormatDescriptionExtension_BackgroundColor: CFStringRef;
455 pub static kCMTextFormatDescriptionColor_Red: CFStringRef;
456 pub static kCMTextFormatDescriptionColor_Green: CFStringRef;
457 pub static kCMTextFormatDescriptionColor_Blue: CFStringRef;
458 pub static kCMTextFormatDescriptionColor_Alpha: CFStringRef;
459 pub static kCMTextFormatDescriptionExtension_DefaultTextBox: CFStringRef;
460 pub static kCMTextFormatDescriptionRect_Top: CFStringRef;
461 pub static kCMTextFormatDescriptionRect_Left: CFStringRef;
462 pub static kCMTextFormatDescriptionRect_Bottom: CFStringRef;
463 pub static kCMTextFormatDescriptionRect_Right: CFStringRef;
464 pub static kCMTextFormatDescriptionExtension_DefaultStyle: CFStringRef;
465 pub static kCMTextFormatDescriptionStyle_StartChar: CFStringRef;
466 pub static kCMTextFormatDescriptionStyle_Font: CFStringRef;
467 pub static kCMTextFormatDescriptionStyle_FontFace: CFStringRef;
468 pub static kCMTextFormatDescriptionStyle_ForegroundColor: CFStringRef;
469 pub static kCMTextFormatDescriptionStyle_FontSize: CFStringRef;
470 pub static kCMTextFormatDescriptionExtension_HorizontalJustification: CFStringRef;
471 pub static kCMTextFormatDescriptionExtension_VerticalJustification: CFStringRef;
472 pub static kCMTextFormatDescriptionStyle_EndChar: CFStringRef;
473 pub static kCMTextFormatDescriptionExtension_FontTable: CFStringRef;
474 pub static kCMTextFormatDescriptionExtension_TextJustification: CFStringRef;
475 pub static kCMTextFormatDescriptionStyle_Height: CFStringRef;
476 pub static kCMTextFormatDescriptionStyle_Ascent: CFStringRef;
477 pub static kCMTextFormatDescriptionExtension_DefaultFontName: CFStringRef;
478 pub static kCMFormatDescriptionExtension_AmbientViewingEnvironment: CFStringRef;
479
480 pub fn CMTextFormatDescriptionGetDisplayFlags(desc: CMFormatDescriptionRef, displayFlagsOut: *mut CMTextDisplayFlags) -> OSStatus;
481 pub fn CMTextFormatDescriptionGetJustification(
482 desc: CMFormatDescriptionRef,
483 horizontaJustificationlOut: *mut CMTextJustificationValue,
484 verticalJustificationOut: *mut CMTextJustificationValue,
485 ) -> OSStatus;
486 pub fn CMTextFormatDescriptionGetDefaultTextBox(
487 desc: CMFormatDescriptionRef,
488 originIsAtTopLeft: Boolean,
489 heightOfTextTrack: CGFloat,
490 defaultTextBoxOut: *mut CGRect,
491 ) -> OSStatus;
492 pub fn CMTextFormatDescriptionGetDefaultStyle(
493 desc: CMFormatDescriptionRef,
494 localFontIDOut: *mut u16,
495 boldOut: *mut Boolean,
496 italicOut: *mut Boolean,
497 underlineOut: *mut Boolean,
498 fontSizeOut: *mut CGFloat,
499 colorComponentsOut: *mut [CGFloat; 4usize],
500 ) -> OSStatus;
501 pub fn CMTextFormatDescriptionGetFontName(desc: CMFormatDescriptionRef, localFontID: u16, fontNameOut: *mut CFStringRef) -> OSStatus;
502}
503
504pub type CMSubtitleFormatType = FourCharCode;
505
506pub const kCMSubtitleFormatType_3GText: CMSubtitleFormatType = fourcc(b"tx3g");
507pub const kCMSubtitleFormatType_WebVTT: CMSubtitleFormatType = fourcc(b"wvtt");
508
509pub type CMTimeCodeFormatDescriptionRef = CMFormatDescriptionRef;
510
511pub type CMTimeCodeFormatType = FourCharCode;
512
513pub const kCMTimeCodeFormatType_TimeCode32: CMTimeCodeFormatType = fourcc(b"tmcd");
514pub const kCMTimeCodeFormatType_TimeCode64: CMTimeCodeFormatType = fourcc(b"tc64");
515pub const kCMTimeCodeFormatType_Counter32: CMTimeCodeFormatType = fourcc(b"cn32");
516pub const kCMTimeCodeFormatType_Counter64: CMTimeCodeFormatType = fourcc(b"cn64");
517
518pub const kCMTimeCodeFlag_DropFrame: u32 = 1 << 0;
519pub const kCMTimeCodeFlag_24HourMax: u32 = 1 << 1;
520pub const kCMTimeCodeFlag_NegTimesOK: u32 = 1 << 2;
521
522extern "C" {
523 pub fn CMTimeCodeFormatDescriptionCreate(
524 allocator: CFAllocatorRef,
525 timeCodeFormatType: CMTimeCodeFormatType,
526 frameDuration: CMTime,
527 frameQuanta: u32,
528 flags: u32,
529 extensions: CFDictionaryRef,
530 formatDescriptionOut: *mut CMTimeCodeFormatDescriptionRef,
531 ) -> OSStatus;
532 pub fn CMTimeCodeFormatDescriptionGetFrameDuration(desc: CMTimeCodeFormatDescriptionRef) -> CMTime;
533 pub fn CMTimeCodeFormatDescriptionGetFrameQuanta(desc: CMTimeCodeFormatDescriptionRef) -> u32;
534 pub fn CMTimeCodeFormatDescriptionGetTimeCodeFlags(desc: CMTimeCodeFormatDescriptionRef) -> u32;
535
536 pub static kCMTimeCodeFormatDescriptionExtension_SourceReferenceName: CFStringRef;
537 pub static kCMTimeCodeFormatDescriptionKey_Value: CFStringRef;
538 pub static kCMTimeCodeFormatDescriptionKey_LangCode: CFStringRef;
539}
540
541pub type CMMetadataFormatDescriptionRef = CMFormatDescriptionRef;
542
543pub type CMMetadataFormatType = FourCharCode;
544
545pub const kCMMetadataFormatType_ICY: CMMetadataFormatType = fourcc(b"icy ");
546pub const kCMMetadataFormatType_ID3: CMMetadataFormatType = fourcc(b"id3 ");
547pub const kCMMetadataFormatType_Boxed: CMMetadataFormatType = fourcc(b"mebx");
548pub const kCMMetadataFormatType_EMSG: CMMetadataFormatType = fourcc(b"emsg");
549
550extern "C" {
551 pub static kCMFormatDescriptionExtensionKey_MetadataKeyTable: CFStringRef;
552 pub static kCMMetadataFormatDescriptionKey_Namespace: CFStringRef;
553 pub static kCMMetadataFormatDescriptionKey_Value: CFStringRef;
554 pub static kCMMetadataFormatDescriptionKey_LocalID: CFStringRef;
555 pub static kCMMetadataFormatDescriptionKey_DataType: CFStringRef;
556 pub static kCMMetadataFormatDescriptionKey_DataTypeNamespace: CFStringRef;
557 pub static kCMMetadataFormatDescriptionKey_ConformingDataTypes: CFStringRef;
558 pub static kCMMetadataFormatDescriptionKey_LanguageTag: CFStringRef;
559 pub static kCMMetadataFormatDescriptionKey_StructuralDependency: CFStringRef;
560 pub static kCMMetadataFormatDescriptionKey_SetupData: CFStringRef;
561 pub static kCMMetadataFormatDescription_StructuralDependencyKey_DependencyIsInvalidFlag: CFStringRef;
562 pub static kCMMetadataFormatDescriptionMetadataSpecificationKey_Identifier: CFStringRef;
563 pub static kCMMetadataFormatDescriptionMetadataSpecificationKey_DataType: CFStringRef;
564 pub static kCMMetadataFormatDescriptionMetadataSpecificationKey_ExtendedLanguageTag: CFStringRef;
565 pub static kCMMetadataFormatDescriptionMetadataSpecificationKey_StructuralDependency: CFStringRef;
566 pub static kCMMetadataFormatDescriptionMetadataSpecificationKey_SetupData: CFStringRef;
567
568 pub fn CMMetadataFormatDescriptionCreateWithKeys(
569 allocator: CFAllocatorRef,
570 metadataType: CMMetadataFormatType,
571 keys: CFArrayRef,
572 formatDescriptionOut: *mut CMMetadataFormatDescriptionRef,
573 ) -> OSStatus;
574 pub fn CMMetadataFormatDescriptionCreateWithMetadataSpecifications(
575 allocator: CFAllocatorRef,
576 metadataType: CMMetadataFormatType,
577 metadataSpecifications: CFArrayRef,
578 formatDescriptionOut: *mut CMMetadataFormatDescriptionRef,
579 ) -> OSStatus;
580 pub fn CMMetadataFormatDescriptionCreateWithMetadataFormatDescriptionAndMetadataSpecifications(
581 allocator: CFAllocatorRef,
582 sourceDescription: CMMetadataFormatDescriptionRef,
583 metadataSpecifications: CFArrayRef,
584 formatDescriptionOut: *mut CMMetadataFormatDescriptionRef,
585 ) -> OSStatus;
586 pub fn CMMetadataFormatDescriptionCreateByMergingMetadataFormatDescriptions(
587 allocator: CFAllocatorRef,
588 sourceDescription: CMMetadataFormatDescriptionRef,
589 otherSourceDescription: CMMetadataFormatDescriptionRef,
590 formatDescriptionOut: *mut CMMetadataFormatDescriptionRef,
591 ) -> OSStatus;
592 pub fn CMMetadataFormatDescriptionGetKeyWithLocalID(desc: CMMetadataFormatDescriptionRef, localKeyID: OSType) -> CFDictionaryRef;
593 pub fn CMMetadataFormatDescriptionGetIdentifiers(desc: CMMetadataFormatDescriptionRef) -> CFArrayRef;
594}
595
596#[cfg(feature = "objc")]
597unsafe impl RefEncode for opaqueCMFormatDescription {
598 const ENCODING_REF: Encoding = Encoding::Pointer(&Encoding::Struct("opaqueCMFormatDescription", &[]));
599}
600
601pub trait TCMFormatDescription: TCFType {
602 #[inline]
603 fn as_format_description(&self) -> CMFormatDescription {
604 unsafe { CMFormatDescription::wrap_under_get_rule(self.as_concrete_TypeRef().as_void_ptr() as CMFormatDescriptionRef) }
605 }
606
607 #[inline]
608 fn into_format_description(self) -> CMFormatDescription
609 where
610 Self: Sized,
611 {
612 let reference = self.as_concrete_TypeRef().as_void_ptr() as CMFormatDescriptionRef;
613 forget(self);
614 unsafe { CMFormatDescription::wrap_under_create_rule(reference) }
615 }
616}
617
618impl CMFormatDescription {
619 #[inline]
620 pub fn downcast<T: TCMFormatDescription>(&self) -> Option<T> {
621 if self.instance_of::<T>() {
622 unsafe { Some(T::wrap_under_get_rule(T::Ref::from_void_ptr(self.as_concrete_TypeRef() as *const c_void))) }
623 } else {
624 None
625 }
626 }
627
628 #[inline]
629 pub fn downcast_into<T: TCMFormatDescription>(self) -> Option<T> {
630 if self.instance_of::<T>() {
631 unsafe {
632 let reference = T::Ref::from_void_ptr(self.as_concrete_TypeRef() as *const c_void);
633 forget(self);
634 Some(T::wrap_under_create_rule(reference))
635 }
636 } else {
637 None
638 }
639 }
640}
641
642declare_TCFType!(CMFormatDescription, CMFormatDescriptionRef);
643impl_TCFType!(CMFormatDescription, CMFormatDescriptionRef, CMFormatDescriptionGetTypeID);
644impl_CFTypeDescription!(CMFormatDescription);
645
646impl CMFormatDescription {
647 #[inline]
648 pub fn new(media_type: CMMediaType, media_subtype: FourCharCode, extensions: Option<&CFDictionary<CFString, CFType>>) -> Result<Self, OSStatus> {
649 let mut format_description: CMFormatDescriptionRef = null_mut();
650 let status = unsafe {
651 CMFormatDescriptionCreate(
652 kCFAllocatorDefault,
653 media_type,
654 media_subtype,
655 extensions.map_or(null(), |exts| exts.as_concrete_TypeRef()),
656 &mut format_description,
657 )
658 };
659 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
660 }
661
662 #[inline]
663 pub fn equal(&self, other: &Self) -> bool {
664 unsafe { CMFormatDescriptionEqual(self.as_concrete_TypeRef(), other.as_concrete_TypeRef()) != 0 }
665 }
666
667 #[inline]
668 pub fn equal_ignoring_extension_keys(
669 &self,
670 other: &Self,
671 extension_keys_to_ignore: &CFType,
672 sample_description_extension_atom_keys_to_ignore: &CFType,
673 ) -> bool {
674 unsafe {
675 CMFormatDescriptionEqualIgnoringExtensionKeys(
676 self.as_concrete_TypeRef(),
677 other.as_concrete_TypeRef(),
678 extension_keys_to_ignore.as_concrete_TypeRef(),
679 sample_description_extension_atom_keys_to_ignore.as_concrete_TypeRef(),
680 ) != 0
681 }
682 }
683
684 #[inline]
685 pub fn get_media_type(&self) -> CMMediaType {
686 unsafe { CMFormatDescriptionGetMediaType(self.as_concrete_TypeRef()) }
687 }
688
689 #[inline]
690 pub fn get_media_subtype(&self) -> FourCharCode {
691 unsafe { CMFormatDescriptionGetMediaSubType(self.as_concrete_TypeRef()) }
692 }
693
694 #[inline]
695 pub fn get_extensions(&self) -> Option<CFDictionary<CFString, CFType>> {
696 unsafe {
697 let extensions = CMFormatDescriptionGetExtensions(self.as_concrete_TypeRef());
698 if extensions.is_null() {
699 None
700 } else {
701 Some(TCFType::wrap_under_get_rule(extensions))
702 }
703 }
704 }
705
706 #[inline]
707 pub fn get_extension(&self, extension_key: &CFString) -> Option<CFPropertyList> {
708 unsafe {
709 let extension = CMFormatDescriptionGetExtension(self.as_concrete_TypeRef(), extension_key.as_concrete_TypeRef());
710 if extension.is_null() {
711 None
712 } else {
713 Some(CFPropertyList::wrap_under_get_rule(extension))
714 }
715 }
716 }
717}
718
719impl TCMFormatDescription for CMAudioFormatDescription {}
720
721declare_TCFType!(CMAudioFormatDescription, CMAudioFormatDescriptionRef);
722impl_TCFType!(CMAudioFormatDescription, CMAudioFormatDescriptionRef, CMFormatDescriptionGetTypeID);
723impl_CFTypeDescription!(CMAudioFormatDescription);
724
725impl CMAudioFormatDescription {
726 #[inline]
727 pub fn new(
728 asbd: &AudioStreamBasicDescription,
729 layout: &AudioChannelLayout,
730 magic_cookie: &[u8],
731 extensions: Option<&CFDictionary<CFString, CFType>>,
732 ) -> Result<Self, OSStatus> {
733 let mut format_description: CMAudioFormatDescriptionRef = null_mut();
734 let status = unsafe {
735 CMAudioFormatDescriptionCreate(
736 kCFAllocatorDefault,
737 asbd,
738 size_of_val(layout),
739 layout,
740 magic_cookie.len(),
741 magic_cookie.as_ptr() as *const _,
742 extensions.map_or(null(), |exts| exts.as_concrete_TypeRef()),
743 &mut format_description,
744 )
745 };
746 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
747 }
748
749 #[inline]
750 pub fn get_codec_type(&self) -> CMAudioCodecType {
751 unsafe { CMFormatDescriptionGetMediaSubType(self.as_concrete_TypeRef()) }
752 }
753
754 #[inline]
755 pub fn get_stream_basic_description(&self) -> Option<&AudioStreamBasicDescription> {
756 unsafe {
757 let asbd = CMAudioFormatDescriptionGetStreamBasicDescription(self.as_concrete_TypeRef());
758 if asbd.is_null() {
759 None
760 } else {
761 Some(&*asbd)
762 }
763 }
764 }
765
766 #[inline]
767 pub fn get_magic_cookie(&self) -> Option<&[u8]> {
768 unsafe {
769 let mut size = 0;
770 let cookie = CMAudioFormatDescriptionGetMagicCookie(self.as_concrete_TypeRef(), &mut size);
771 if cookie.is_null() {
772 None
773 } else {
774 Some(from_raw_parts(cookie as *const u8, size))
775 }
776 }
777 }
778
779 #[inline]
780 pub fn get_channel_layout(&self) -> Option<(&AudioChannelLayout, usize)> {
781 unsafe {
782 let mut size = 0;
783 let layout = CMAudioFormatDescriptionGetChannelLayout(self.as_concrete_TypeRef(), &mut size);
784 if layout.is_null() {
785 None
786 } else {
787 Some((&*layout, size))
788 }
789 }
790 }
791
792 #[inline]
793 pub fn get_format_list(&self) -> Option<&[AudioFormatListItem]> {
794 unsafe {
795 let mut size = 0;
796 let list = CMAudioFormatDescriptionGetFormatList(self.as_concrete_TypeRef(), &mut size);
797 if list.is_null() {
798 None
799 } else {
800 Some(from_raw_parts(list, size))
801 }
802 }
803 }
804
805 #[inline]
806 pub fn get_richest_decodable_format(&self) -> Option<&AudioFormatListItem> {
807 unsafe {
808 let format = CMAudioFormatDescriptionGetRichestDecodableFormat(self.as_concrete_TypeRef());
809 if format.is_null() {
810 None
811 } else {
812 Some(&*format)
813 }
814 }
815 }
816
817 #[inline]
818 pub fn get_most_compatible_format(&self) -> Option<&AudioFormatListItem> {
819 unsafe {
820 let format = CMAudioFormatDescriptionGetMostCompatibleFormat(self.as_concrete_TypeRef());
821 if format.is_null() {
822 None
823 } else {
824 Some(&*format)
825 }
826 }
827 }
828
829 #[inline]
830 pub fn new_summary(format_description_array: &CFArray<CMAudioFormatDescription>, flags: u32) -> Result<Self, OSStatus> {
831 let mut format_description: CMAudioFormatDescriptionRef = null_mut();
832 let status = unsafe {
833 CMAudioFormatDescriptionCreateSummary(kCFAllocatorDefault, format_description_array.as_concrete_TypeRef(), flags, &mut format_description)
834 };
835 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
836 }
837
838 #[inline]
839 pub fn equal(&self, other: &Self, eequality_mask: CMAudioFormatDescriptionMask) -> (bool, CMAudioFormatDescriptionMask) {
840 let mut mask = 0;
841 let equal = unsafe { CMAudioFormatDescriptionEqual(self.as_concrete_TypeRef(), other.as_concrete_TypeRef(), eequality_mask, &mut mask) != 0 };
842 (equal, mask)
843 }
844}
845
846impl TCMFormatDescription for CMVideoFormatDescription {}
847
848declare_TCFType!(CMVideoFormatDescription, CMVideoFormatDescriptionRef);
849impl_TCFType!(CMVideoFormatDescription, CMVideoFormatDescriptionRef, CMFormatDescriptionGetTypeID);
850impl_CFTypeDescription!(CMVideoFormatDescription);
851
852impl CMVideoFormatDescription {
853 #[inline]
854 pub fn new(codec_type: CMVideoCodecType, width: i32, height: i32, extensions: Option<&CFDictionary<CFString, CFType>>) -> Result<Self, OSStatus> {
855 let mut format_description: CMVideoFormatDescriptionRef = null_mut();
856 let status = unsafe {
857 CMVideoFormatDescriptionCreate(
858 kCFAllocatorDefault,
859 codec_type,
860 width,
861 height,
862 extensions.map_or(null(), |exts| exts.as_concrete_TypeRef()),
863 &mut format_description,
864 )
865 };
866 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
867 }
868
869 #[inline]
870 pub fn from_image_buffer(image_buffer: &CVImageBuffer) -> Result<Self, OSStatus> {
871 let mut format_description: CMVideoFormatDescriptionRef = null_mut();
872 let status =
873 unsafe { CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, image_buffer.as_concrete_TypeRef(), &mut format_description) };
874 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
875 }
876
877 #[inline]
878 pub fn from_h264_parameter_sets(parameter_sets: &[&[u8]], nal_unit_header_length: i32) -> Result<Self, OSStatus> {
879 let mut format_description: CMVideoFormatDescriptionRef = null_mut();
880 let status = unsafe {
881 CMVideoFormatDescriptionCreateFromH264ParameterSets(
882 kCFAllocatorDefault,
883 parameter_sets.len(),
884 parameter_sets.iter().map(|data| data.as_ptr()).collect::<Vec<_>>().as_ptr(),
885 parameter_sets.iter().map(|data| data.len()).collect::<Vec<_>>().as_ptr(),
886 nal_unit_header_length,
887 &mut format_description,
888 )
889 };
890 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
891 }
892
893 #[inline]
894 pub fn from_hevc_parameter_sets(
895 parameter_sets: &[&[u8]],
896 nal_unit_header_length: i32,
897 extensions: Option<&CFDictionary<CFString, CFType>>,
898 ) -> Result<Self, OSStatus> {
899 let mut format_description: CMVideoFormatDescriptionRef = null_mut();
900 let status = unsafe {
901 CMVideoFormatDescriptionCreateFromHEVCParameterSets(
902 kCFAllocatorDefault,
903 parameter_sets.len(),
904 parameter_sets.iter().map(|data| data.as_ptr()).collect::<Vec<_>>().as_ptr(),
905 parameter_sets.iter().map(|data| data.len()).collect::<Vec<_>>().as_ptr(),
906 nal_unit_header_length,
907 extensions.map_or(null(), |exts| exts.as_concrete_TypeRef()),
908 &mut format_description,
909 )
910 };
911 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
912 }
913
914 #[inline]
915 pub fn get_h264_parameter_set_at_index(&self, parameter_set_index: usize) -> Result<(&[u8], usize, i32), OSStatus> {
916 let mut parameter_set_pointer = null();
917 let mut parameter_set_size = 0;
918 let mut parameter_set_count = 0;
919 let mut nal_unit_header_length = 0;
920 let status = unsafe {
921 CMVideoFormatDescriptionGetH264ParameterSetAtIndex(
922 self.as_concrete_TypeRef(),
923 parameter_set_index,
924 &mut parameter_set_pointer,
925 &mut parameter_set_size,
926 &mut parameter_set_count,
927 &mut nal_unit_header_length,
928 )
929 };
930 status_to_result(status)
931 .map(|_| (unsafe { from_raw_parts(parameter_set_pointer, parameter_set_size) }, parameter_set_count, nal_unit_header_length))
932 }
933
934 #[inline]
935 pub fn get_hevc_parameter_set_at_index(&self, parameter_set_index: usize) -> Result<(&[u8], usize, i32), OSStatus> {
936 let mut parameter_set_pointer = null();
937 let mut parameter_set_size = 0;
938 let mut parameter_set_count = 0;
939 let mut nal_unit_header_length = 0;
940 let status = unsafe {
941 CMVideoFormatDescriptionGetHEVCParameterSetAtIndex(
942 self.as_concrete_TypeRef(),
943 parameter_set_index,
944 &mut parameter_set_pointer,
945 &mut parameter_set_size,
946 &mut parameter_set_count,
947 &mut nal_unit_header_length,
948 )
949 };
950 status_to_result(status)
951 .map(|_| (unsafe { from_raw_parts(parameter_set_pointer, parameter_set_size) }, parameter_set_count, nal_unit_header_length))
952 }
953
954 #[inline]
955 pub fn get_codec_type(&self) -> CMVideoCodecType {
956 unsafe { CMFormatDescriptionGetMediaSubType(self.as_concrete_TypeRef()) }
957 }
958
959 #[inline]
960 pub fn get_dimensions(&self) -> CMVideoDimensions {
961 unsafe { CMVideoFormatDescriptionGetDimensions(self.as_concrete_TypeRef()) }
962 }
963
964 #[inline]
965 pub fn get_presentation_dimensions(&self, use_pixel_aspect_ratio: bool, use_clean_aperture: bool) -> CGSize {
966 unsafe { CMVideoFormatDescriptionGetPresentationDimensions(self.as_concrete_TypeRef(), use_pixel_aspect_ratio as _, use_clean_aperture as _) }
967 }
968
969 #[inline]
970 pub fn get_clean_aperture(&self, origin_is_at_top_left: bool) -> CGRect {
971 unsafe { CMVideoFormatDescriptionGetCleanAperture(self.as_concrete_TypeRef(), origin_is_at_top_left as _) }
972 }
973
974 #[inline]
975 pub fn get_extension_keys_common_with_image_buffers() -> CFArray<CFString> {
976 unsafe { TCFType::wrap_under_create_rule(CMVideoFormatDescriptionGetExtensionKeysCommonWithImageBuffers()) }
977 }
978
979 #[inline]
980 pub fn matches_image_buffer(&self, image_buffer: &CVImageBuffer) -> bool {
981 unsafe { CMVideoFormatDescriptionMatchesImageBuffer(self.as_concrete_TypeRef(), image_buffer.as_concrete_TypeRef()) != 0 }
982 }
983}
984
985impl TCMFormatDescription for CMMuxedFormatDescription {}
986
987declare_TCFType!(CMMuxedFormatDescription, CMMuxedFormatDescriptionRef);
988impl_TCFType!(CMMuxedFormatDescription, CMMuxedFormatDescriptionRef, CMFormatDescriptionGetTypeID);
989impl_CFTypeDescription!(CMMuxedFormatDescription);
990
991impl CMMuxedFormatDescription {
992 #[inline]
993 pub fn new(mux_type: CMMuxedStreamType, extensions: Option<&CFDictionary<CFString, CFType>>) -> Result<Self, OSStatus> {
994 let mut format_description: CMMuxedFormatDescriptionRef = null_mut();
995 let status = unsafe {
996 CMMuxedFormatDescriptionCreate(
997 kCFAllocatorDefault,
998 mux_type,
999 extensions.map_or(null(), |exts| exts.as_concrete_TypeRef()),
1000 &mut format_description,
1001 )
1002 };
1003 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
1004 }
1005
1006 #[inline]
1007 pub fn get_stream_type(&self) -> CMMuxedStreamType {
1008 unsafe { CMFormatDescriptionGetMediaSubType(self.as_concrete_TypeRef()) }
1009 }
1010}
1011
1012impl TCMFormatDescription for CMClosedCaptionFormatDescription {}
1013
1014declare_TCFType!(CMClosedCaptionFormatDescription, CMClosedCaptionFormatDescriptionRef);
1015impl_TCFType!(CMClosedCaptionFormatDescription, CMClosedCaptionFormatDescriptionRef, CMFormatDescriptionGetTypeID);
1016impl_CFTypeDescription!(CMClosedCaptionFormatDescription);
1017
1018impl CMClosedCaptionFormatDescription {
1019 #[inline]
1020 pub fn new(format_type: CMClosedCaptionFormatType, extensions: Option<&CFDictionary<CFString, CFType>>) -> Result<Self, OSStatus> {
1021 let mut format_description: CMClosedCaptionFormatDescriptionRef = null_mut();
1022 let status = unsafe {
1023 CMFormatDescriptionCreate(
1024 kCFAllocatorDefault,
1025 kCMMediaType_ClosedCaption,
1026 format_type,
1027 extensions.map_or(null(), |exts| exts.as_concrete_TypeRef()),
1028 &mut format_description,
1029 )
1030 };
1031 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
1032 }
1033
1034 #[inline]
1035 pub fn get_format_type(&self) -> CMClosedCaptionFormatType {
1036 unsafe { CMFormatDescriptionGetMediaSubType(self.as_concrete_TypeRef()) }
1037 }
1038}
1039
1040impl TCMFormatDescription for CMTextFormatDescription {}
1041
1042declare_TCFType!(CMTextFormatDescription, CMTextFormatDescriptionRef);
1043impl_TCFType!(CMTextFormatDescription, CMTextFormatDescriptionRef, CMFormatDescriptionGetTypeID);
1044impl_CFTypeDescription!(CMTextFormatDescription);
1045
1046impl CMTextFormatDescription {
1047 #[inline]
1048 pub fn new(format_type: CMTextFormatType, extensions: Option<&CFDictionary<CFString, CFType>>) -> Result<Self, OSStatus> {
1049 let mut format_description: CMTextFormatDescriptionRef = null_mut();
1050 let status = unsafe {
1051 CMFormatDescriptionCreate(
1052 kCFAllocatorDefault,
1053 kCMMediaType_Text,
1054 format_type,
1055 extensions.map_or(null(), |exts| exts.as_concrete_TypeRef()),
1056 &mut format_description,
1057 )
1058 };
1059 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
1060 }
1061
1062 #[inline]
1063 pub fn get_format_type(&self) -> CMTextFormatType {
1064 unsafe { CMFormatDescriptionGetMediaSubType(self.as_concrete_TypeRef()) }
1065 }
1066
1067 #[inline]
1068 pub fn get_display_flags(&self) -> Result<CMTextDisplayFlags, OSStatus> {
1069 let mut display_flags = 0;
1070 let status = unsafe { CMTextFormatDescriptionGetDisplayFlags(self.as_concrete_TypeRef(), &mut display_flags) };
1071 status_to_result(status).map(|_| display_flags)
1072 }
1073
1074 #[inline]
1075 pub fn get_justification(&self) -> Result<(CMTextJustificationValue, CMTextJustificationValue), OSStatus> {
1076 let mut horizontal_justification = 0;
1077 let mut vertical_justification = 0;
1078 let status = unsafe {
1079 CMTextFormatDescriptionGetJustification(self.as_concrete_TypeRef(), &mut horizontal_justification, &mut vertical_justification)
1080 };
1081 status_to_result(status).map(|_| (horizontal_justification, vertical_justification))
1082 }
1083
1084 #[inline]
1085 pub fn get_default_text_box(&self, origin_is_at_top_left: bool, height_of_text_track: CGFloat) -> Result<CGRect, OSStatus> {
1086 let mut default_text_box = CGRect::default();
1087 let status = unsafe {
1088 CMTextFormatDescriptionGetDefaultTextBox(
1089 self.as_concrete_TypeRef(),
1090 origin_is_at_top_left as _,
1091 height_of_text_track,
1092 &mut default_text_box,
1093 )
1094 };
1095 status_to_result(status).map(|_| default_text_box)
1096 }
1097
1098 #[inline]
1099 pub fn get_default_style(&self) -> Result<(u16, bool, bool, bool, CGFloat, [CGFloat; 4]), OSStatus> {
1100 let mut local_font_id = 0;
1101 let mut bold: Boolean = 0;
1102 let mut italic: Boolean = 0;
1103 let mut underline: Boolean = 0;
1104 let mut font_size = 0.0;
1105 let mut color_components = [0.0; 4];
1106 let status = unsafe {
1107 CMTextFormatDescriptionGetDefaultStyle(
1108 self.as_concrete_TypeRef(),
1109 &mut local_font_id,
1110 &mut bold,
1111 &mut italic,
1112 &mut underline,
1113 &mut font_size,
1114 &mut color_components,
1115 )
1116 };
1117 status_to_result(status).map(|_| (local_font_id, bold != 0, italic != 0, underline != 0, font_size, color_components))
1118 }
1119
1120 #[inline]
1121 pub fn get_font_name(&self, local_font_id: u16) -> Result<CFString, OSStatus> {
1122 let mut font_name = null();
1123 let status = unsafe { CMTextFormatDescriptionGetFontName(self.as_concrete_TypeRef(), local_font_id, &mut font_name) };
1124 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(font_name) })
1125 }
1126}
1127
1128impl TCMFormatDescription for CMTimeCodeFormatDescription {}
1129
1130declare_TCFType!(CMTimeCodeFormatDescription, CMTimeCodeFormatDescriptionRef);
1131impl_TCFType!(CMTimeCodeFormatDescription, CMTimeCodeFormatDescriptionRef, CMFormatDescriptionGetTypeID);
1132impl_CFTypeDescription!(CMTimeCodeFormatDescription);
1133
1134impl CMTimeCodeFormatDescription {
1135 #[inline]
1136 pub fn new(
1137 time_code_format_type: CMTimeCodeFormatType,
1138 frame_duration: CMTime,
1139 frame_quanta: u32,
1140 flags: u32,
1141 extensions: Option<&CFDictionary<CFString, CFType>>,
1142 ) -> Result<Self, OSStatus> {
1143 let mut format_description: CMTimeCodeFormatDescriptionRef = null_mut();
1144 let status = unsafe {
1145 CMTimeCodeFormatDescriptionCreate(
1146 kCFAllocatorDefault,
1147 time_code_format_type,
1148 frame_duration,
1149 frame_quanta,
1150 flags,
1151 extensions.map_or(null(), |exts| exts.as_concrete_TypeRef()),
1152 &mut format_description,
1153 )
1154 };
1155 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
1156 }
1157
1158 #[inline]
1159 pub fn get_format_type(&self) -> CMTimeCodeFormatType {
1160 unsafe { CMFormatDescriptionGetMediaSubType(self.as_concrete_TypeRef()) }
1161 }
1162
1163 #[inline]
1164 pub fn get_frame_duration(&self) -> CMTime {
1165 unsafe { CMTimeCodeFormatDescriptionGetFrameDuration(self.as_concrete_TypeRef()) }
1166 }
1167
1168 #[inline]
1169 pub fn get_frame_quanta(&self) -> u32 {
1170 unsafe { CMTimeCodeFormatDescriptionGetFrameQuanta(self.as_concrete_TypeRef()) }
1171 }
1172
1173 #[inline]
1174 pub fn get_time_code_flags(&self) -> u32 {
1175 unsafe { CMTimeCodeFormatDescriptionGetTimeCodeFlags(self.as_concrete_TypeRef()) }
1176 }
1177}
1178
1179impl TCMFormatDescription for CMMetadataFormatDescription {}
1180
1181declare_TCFType!(CMMetadataFormatDescription, CMMetadataFormatDescriptionRef);
1182impl_TCFType!(CMMetadataFormatDescription, CMMetadataFormatDescriptionRef, CMFormatDescriptionGetTypeID);
1183impl_CFTypeDescription!(CMMetadataFormatDescription);
1184
1185impl CMMetadataFormatDescription {
1186 #[inline]
1187 pub fn new_with_keys(metadata_type: CMMetadataFormatType, keys: Option<&CFArray<CFString>>) -> Result<Self, OSStatus> {
1188 let mut format_description: CMMetadataFormatDescriptionRef = null_mut();
1189 let status = unsafe {
1190 CMMetadataFormatDescriptionCreateWithKeys(
1191 kCFAllocatorDefault,
1192 metadata_type,
1193 keys.map_or(null(), |keys| keys.as_concrete_TypeRef()),
1194 &mut format_description,
1195 )
1196 };
1197 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
1198 }
1199
1200 #[inline]
1201 pub fn new_with_metadata_specifications(
1202 metadata_type: CMMetadataFormatType,
1203 metadata_specifications: &CFArray<CFDictionary<CFString, CFType>>,
1204 ) -> Result<Self, OSStatus> {
1205 let mut format_description: CMMetadataFormatDescriptionRef = null_mut();
1206 let status = unsafe {
1207 CMMetadataFormatDescriptionCreateWithMetadataSpecifications(
1208 kCFAllocatorDefault,
1209 metadata_type,
1210 metadata_specifications.as_concrete_TypeRef(),
1211 &mut format_description,
1212 )
1213 };
1214 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
1215 }
1216
1217 #[inline]
1218 pub fn new_with_metadata_format_description_and_metadata_specifications(
1219 source_description: &CMMetadataFormatDescription,
1220 metadata_specifications: &CFArray<CFDictionary<CFString, CFType>>,
1221 ) -> Result<Self, OSStatus> {
1222 let mut format_description: CMMetadataFormatDescriptionRef = null_mut();
1223 let status = unsafe {
1224 CMMetadataFormatDescriptionCreateWithMetadataFormatDescriptionAndMetadataSpecifications(
1225 kCFAllocatorDefault,
1226 source_description.as_concrete_TypeRef(),
1227 metadata_specifications.as_concrete_TypeRef(),
1228 &mut format_description,
1229 )
1230 };
1231 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
1232 }
1233
1234 #[inline]
1235 pub fn new_by_merging_metadata_format_descriptions(
1236 source_description: &CMMetadataFormatDescription,
1237 other_source_description: &CMMetadataFormatDescription,
1238 ) -> Result<Self, OSStatus> {
1239 let mut format_description: CMMetadataFormatDescriptionRef = null_mut();
1240 let status = unsafe {
1241 CMMetadataFormatDescriptionCreateByMergingMetadataFormatDescriptions(
1242 kCFAllocatorDefault,
1243 source_description.as_concrete_TypeRef(),
1244 other_source_description.as_concrete_TypeRef(),
1245 &mut format_description,
1246 )
1247 };
1248 status_to_result(status).map(|_| unsafe { TCFType::wrap_under_create_rule(format_description) })
1249 }
1250
1251 #[inline]
1252 pub fn get_key_with_local_id(&self, local_key_id: OSType) -> Option<CFDictionary<CFString, CFType>> {
1253 unsafe {
1254 let key = CMMetadataFormatDescriptionGetKeyWithLocalID(self.as_concrete_TypeRef(), local_key_id);
1255 if key.is_null() {
1256 None
1257 } else {
1258 Some(TCFType::wrap_under_get_rule(key))
1259 }
1260 }
1261 }
1262
1263 #[inline]
1264 pub fn get_identifiers(&self) -> Option<CFArray<CFString>> {
1265 unsafe {
1266 let identifiers = CMMetadataFormatDescriptionGetIdentifiers(self.as_concrete_TypeRef());
1267 if identifiers.is_null() {
1268 None
1269 } else {
1270 Some(TCFType::wrap_under_get_rule(identifiers))
1271 }
1272 }
1273 }
1274}