coremedia_sys/
lib.rs

1#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals, improper_ctypes)]
2#![cfg(any(target_os = "macos", target_os = "ios"))]
3
4extern crate libc;
5extern crate core_foundation_sys;
6
7
8use libc::{c_void, size_t, c_long};
9use core_foundation_sys::base::{OSStatus, Boolean, CFAllocatorRef, CFTypeID, CFTypeRef};
10use core_foundation_sys::dictionary::CFDictionaryRef;
11use core_foundation_sys::string::CFStringRef;
12
13
14pub type OSType = u32;
15
16pub type CMItemCount = c_long;
17pub type CMItemIndex = c_long;
18
19pub type CMTimeValue = i64;
20pub type CMTimeScale = i32;
21pub type CMTimeFlags = u32;
22pub type CMTimeEpoch = i64;
23
24pub type CMVideoCodecType = u32;
25
26
27
28
29
30
31
32
33pub type CMBlockBufferFlags = u32;
34// #[repr(C)]
35// #[derive(Debug, Copy, Clone)]
36// pub struct OpaqueCMBlockBuffer;
37// pub type CMBlockBufferRef = *mut OpaqueCMBlockBuffer;
38pub type CMBlockBufferRef = CFTypeRef;
39
40// #[repr(C)]
41// #[derive(Debug, Copy, Clone)]
42// pub struct OpaqueCMFormatDescription;
43// pub type CMFormatDescriptionRef = *mut OpaqueCMFormatDescription;
44pub type CMFormatDescriptionRef = CFTypeRef;
45pub type CMVideoFormatDescriptionRef = CMFormatDescriptionRef;
46
47// #[repr(C)]
48// #[derive(Debug, Copy, Clone)]
49// pub struct OpaqueCMSampleBuffer;
50// pub type CMSampleBufferRef = *mut OpaqueCMSampleBuffer;
51pub type CMSampleBufferRef = CFTypeRef;
52
53pub type CMSampleBufferMakeDataReadyCallback =
54    extern "C" fn(sbuf: CMSampleBufferRef, makeDataReadyRefcon: *mut c_void)
55                  -> OSStatus;
56
57
58pub const kCMTimeFlags_Valid: CMTimeFlags = 1 << 0;
59#[allow(non_upper_case_globals)]
60pub const kCMVideoCodecType_H264: CMVideoCodecType =
61    ((b'a' as u32) << 24) | ((b'v' as u32) << 16) | ((b'c' as u32) << 8) | (b'1' as u32);
62
63
64#[repr(C)]
65#[derive(Debug, Copy, Clone)]
66pub struct CMTime {
67    pub value: CMTimeValue,
68    pub timescale: CMTimeScale,
69    pub flags: CMTimeFlags,
70    pub epoch: CMTimeEpoch,
71}
72
73#[repr(C)]
74#[derive(Debug, Copy, Clone)]
75pub struct CMSampleTimingInfo {
76    pub duration: CMTime,
77    pub presentation_time_stamp: CMTime,
78    pub decode_time_stamp: CMTime,
79}
80
81#[repr(C)]
82#[derive(Debug, Copy, Clone)]
83pub struct CMTimeRange {
84    pub start: CMTime,
85    pub duration: CMTime,
86}
87
88
89
90
91#[repr(C)]
92#[allow(missing_copy_implementations)]
93#[derive(Debug, Copy, Clone)]
94pub struct CMBlockBufferCustomBlockSource {
95    version: u32,
96    AllocateBlock: extern "C" fn(refCon: *mut c_void, sizeInBytes: size_t) -> *mut c_void,
97    FreeBlock: extern "C" fn(refCon: *mut c_void, doomedMemoryBlock: *mut c_void, sizeInBytes: size_t),
98    refCon: *mut c_void,
99}
100
101
102#[link(name="CoreMedia", kind="framework")]
103extern {
104    pub static kCMFormatDescriptionExtension_SampleDescriptionExtensionAtoms: CFStringRef;
105
106    pub fn CMFormatDescriptionGetTypeID() -> CFTypeID;
107    pub fn CMVideoFormatDescriptionCreate(allocator: CFAllocatorRef,
108                                          codecType: CMVideoCodecType,
109                                          width: i32,
110                                          height: i32,
111                                          extensions: CFDictionaryRef,
112                                          outDesc: *mut CMVideoFormatDescriptionRef)
113                                          -> OSStatus;
114    pub fn CMBlockBufferGetTypeID() -> CFTypeID;
115    pub fn CMBlockBufferCreateWithMemoryBlock(structureAllocator: CFAllocatorRef,
116                                              memoryBlock: *mut c_void,
117                                              blockLength: size_t,
118                                              blockAllocator: CFAllocatorRef,
119                                              customBlockSource: *const
120                                                CMBlockBufferCustomBlockSource,
121                                              offsetToData: size_t,
122                                              dataLength: size_t,
123                                              flags: CMBlockBufferFlags,
124                                              newBBufOut: *mut CMBlockBufferRef)
125                                              -> OSStatus;
126    pub fn CMBlockBufferReplaceDataBytes(sourceBytes: *const c_void,
127                                         destinationBuffer: CMBlockBufferRef,
128                                         offsetIntoDestination: size_t,
129                                         dataLength: size_t)
130                                         -> OSStatus;
131    pub fn CMSampleBufferGetTypeID() -> CFTypeID;
132    pub fn CMSampleBufferCreate(allocator: CFAllocatorRef,
133                                dataBuffer: CMBlockBufferRef,
134                                dataReady: Boolean,
135                                makeDataReadyCallback: CMSampleBufferMakeDataReadyCallback,
136                                makeDataReadyRefcon: *mut c_void,
137                                formatDescription: CMFormatDescriptionRef,
138                                numSamples: CMItemCount,
139                                numSampleTimingEntries: CMItemCount,
140                                sampleTimingArray: *const CMSampleTimingInfo,
141                                numSampleSizeEntries: CMItemCount,
142                                sampleSizeArray: *const size_t,
143                                sBufOut: *mut CMSampleBufferRef)
144                                -> OSStatus;
145    pub fn CMSampleBufferGetSampleTimingInfo(sbuf: CMSampleBufferRef,
146                                             sampleIndex: CMItemIndex,
147                                             timingInfoOut: *mut CMSampleTimingInfo)
148                                             -> OSStatus;
149}
150
151
152#[cfg(test)]
153mod test {
154    use super::*;
155
156    #[test]
157    fn test(){
158        unsafe {
159            assert_eq!(CMFormatDescriptionGetTypeID(), 269);
160        }
161    }
162}