Skip to main content

apple_cf/ffi/
mod.rs

1//! Raw FFI declarations for the Swift bridge.
2//!
3//! These are intentionally low-level (`*mut c_void` + scalar arguments) and
4//! `unsafe`; safe wrappers live in [`crate::iosurface`], [`crate::dispatch_queue`],
5//! etc.
6//!
7//! Currently exposes:
8//! * `acf_free_string` — heap-string deallocator used by every bridge fn that
9//!   returns an owned C string back to Rust.
10//! * `dispatch_queue_*` — Grand Central Dispatch queue lifetime + creation.
11//! * `io_surface_*` — `IOSurface` accessors and lifetime control.
12//!
13//! Future framework additions (`CoreMedia`, `CoreVideo`, Metal, ...) extend this
14//! module and gain matching `@_cdecl` exports under
15//! `swift-bridge/Sources/<Framework>Bridge/`.
16
17#![allow(missing_docs)]
18
19mod core_foundation;
20mod core_video_extras;
21mod dispatch_extras;
22
23pub use core_foundation::*;
24pub use core_video_extras::*;
25pub use dispatch_extras::*;
26
27use core::ffi::{c_char, c_void};
28
29extern "C" {
30    /// Free a heap-allocated C string previously returned by any bridge fn.
31    /// Centralised in `AppleCFBridge.swift`.
32    pub fn acf_free_string(s: *mut c_char);
33
34    // ---- dispatch ----
35    /// Swift bridge function `acf_dispatch_queue_create` for the corresponding Apple API.
36    pub fn acf_dispatch_queue_create(label: *const c_char, qos: i32) -> *const c_void;
37    pub fn acf_dispatch_queue_create_concurrent(label: *const c_char, qos: i32) -> *const c_void;
38    pub fn acf_dispatch_queue_main() -> *const c_void;
39    pub fn acf_dispatch_queue_global(qos: i32) -> *const c_void;
40    /// Swift bridge function `dispatch_queue_release` for the corresponding Apple API.
41    pub fn dispatch_queue_release(queue: *const c_void);
42    /// Swift bridge function `dispatch_queue_retain` for the corresponding Apple API.
43    pub fn dispatch_queue_retain(queue: *const c_void) -> *const c_void;
44
45    // ---- CoreGraphics bridge helpers ----
46    /// Swift bridge function `cgimage_save_png` for the corresponding Apple API.
47    pub fn cgimage_save_png(image: *mut c_void, path: *const c_char) -> bool;
48
49    // ---- IOSurface ----
50    /// Swift bridge function `io_surface_create` for the corresponding Apple API.
51    pub fn io_surface_create(
52        width: usize,
53        height: usize,
54        pixel_format: u32,
55        bytes_per_element: usize,
56        out_surface: *mut *mut c_void,
57    ) -> i32;
58    /// Swift bridge function `io_surface_create_with_properties` for the corresponding Apple API.
59    pub fn io_surface_create_with_properties(
60        width: usize,
61        height: usize,
62        pixel_format: u32,
63        bytes_per_element: usize,
64        bytes_per_row: usize,
65        alloc_size: usize,
66        plane_count: usize,
67        plane_widths: *const usize,
68        plane_heights: *const usize,
69        plane_bytes_per_row: *const usize,
70        plane_bytes_per_element: *const usize,
71        plane_offsets: *const usize,
72        plane_sizes: *const usize,
73        surface_out: *mut *mut c_void,
74    ) -> i32;
75    /// Swift bridge function `io_surface_release` for the corresponding Apple API.
76    pub fn io_surface_release(surface: *mut c_void);
77    /// Swift bridge function `io_surface_retain` for the corresponding Apple API.
78    pub fn io_surface_retain(surface: *mut c_void) -> *mut c_void;
79    /// Swift bridge function `io_surface_hash` for the corresponding Apple API.
80    pub fn io_surface_hash(surface: *mut c_void) -> usize;
81    /// Swift bridge function `io_surface_get_width` for the corresponding Apple API.
82    pub fn io_surface_get_width(surface: *mut c_void) -> usize;
83    /// Swift bridge function `io_surface_get_height` for the corresponding Apple API.
84    pub fn io_surface_get_height(surface: *mut c_void) -> usize;
85    /// Swift bridge function `io_surface_get_bytes_per_row` for the corresponding Apple API.
86    pub fn io_surface_get_bytes_per_row(surface: *mut c_void) -> usize;
87    /// Swift bridge function `io_surface_get_alloc_size` for the corresponding Apple API.
88    pub fn io_surface_get_alloc_size(surface: *mut c_void) -> usize;
89    /// Swift bridge function `io_surface_get_pixel_format` for the corresponding Apple API.
90    pub fn io_surface_get_pixel_format(surface: *mut c_void) -> u32;
91    /// Swift bridge function `io_surface_get_id` for the corresponding Apple API.
92    pub fn io_surface_get_id(surface: *mut c_void) -> u32;
93    /// Swift bridge function `io_surface_get_seed` for the corresponding Apple API.
94    pub fn io_surface_get_seed(surface: *mut c_void) -> u32;
95    /// Swift bridge function `io_surface_get_plane_count` for the corresponding Apple API.
96    pub fn io_surface_get_plane_count(surface: *mut c_void) -> usize;
97    /// Swift bridge function `io_surface_get_width_of_plane` for the corresponding Apple API.
98    pub fn io_surface_get_width_of_plane(surface: *mut c_void, plane_index: usize) -> usize;
99    /// Swift bridge function `io_surface_get_height_of_plane` for the corresponding Apple API.
100    pub fn io_surface_get_height_of_plane(surface: *mut c_void, plane_index: usize) -> usize;
101    /// Swift bridge function `io_surface_get_bytes_per_row_of_plane` for the corresponding Apple API.
102    pub fn io_surface_get_bytes_per_row_of_plane(surface: *mut c_void, plane_index: usize)
103        -> usize;
104    /// Swift bridge function `io_surface_get_base_address_of_plane` for the corresponding Apple API.
105    pub fn io_surface_get_base_address_of_plane(
106        surface: *mut c_void,
107        plane_index: usize,
108    ) -> *mut c_void;
109    /// Swift bridge function `io_surface_get_base_address` for the corresponding Apple API.
110    pub fn io_surface_get_base_address(surface: *mut c_void) -> *mut c_void;
111    /// Swift bridge function `io_surface_get_bytes_per_element` for the corresponding Apple API.
112    pub fn io_surface_get_bytes_per_element(surface: *mut c_void) -> usize;
113    /// Swift bridge function `io_surface_get_element_width` for the corresponding Apple API.
114    pub fn io_surface_get_element_width(surface: *mut c_void) -> usize;
115    /// Swift bridge function `io_surface_get_element_height` for the corresponding Apple API.
116    pub fn io_surface_get_element_height(surface: *mut c_void) -> usize;
117    /// Swift bridge function `io_surface_is_in_use` for the corresponding Apple API.
118    pub fn io_surface_is_in_use(surface: *mut c_void) -> bool;
119    /// Swift bridge function `io_surface_increment_use_count` for the corresponding Apple API.
120    pub fn io_surface_increment_use_count(surface: *mut c_void);
121    /// Swift bridge function `io_surface_decrement_use_count` for the corresponding Apple API.
122    pub fn io_surface_decrement_use_count(surface: *mut c_void);
123    /// Swift bridge function `io_surface_lock` for the corresponding Apple API.
124    pub fn io_surface_lock(surface: *mut c_void, options: u32, seed: *mut u32) -> i32;
125    /// Swift bridge function `io_surface_unlock` for the corresponding Apple API.
126    pub fn io_surface_unlock(surface: *mut c_void, options: u32, seed: *mut u32) -> i32;
127
128    // ---- CMSampleBuffer ----
129    /// Swift bridge function `cm_sample_buffer_release` for the corresponding Apple API.
130    pub fn cm_sample_buffer_release(sample_buffer: *mut c_void);
131    /// Swift bridge function `cm_sample_buffer_retain` for the corresponding Apple API.
132    pub fn cm_sample_buffer_retain(sample_buffer: *mut c_void) -> *mut c_void;
133    /// Swift bridge function `cm_sample_buffer_hash` for the corresponding Apple API.
134    pub fn cm_sample_buffer_hash(sample_buffer: *mut c_void) -> usize;
135    /// Swift bridge function `cm_sample_buffer_get_data_buffer` for the corresponding Apple API.
136    pub fn cm_sample_buffer_get_data_buffer(sample_buffer: *mut c_void) -> *mut c_void;
137    /// Swift bridge function `cm_sample_buffer_get_format_description` for the corresponding Apple API.
138    pub fn cm_sample_buffer_get_format_description(sample_buffer: *mut c_void) -> *mut c_void;
139    /// Swift bridge function that returns a +1 retained image buffer.
140    pub fn cm_sample_buffer_copy_image_buffer(sample_buffer: *mut c_void) -> *mut c_void;
141    /// Swift bridge function `cm_sample_buffer_get_presentation_timestamp` for the corresponding Apple API.
142    pub fn cm_sample_buffer_get_presentation_timestamp(
143        sample_buffer: *mut c_void,
144        out_value: *mut i64,
145        out_timescale: *mut i32,
146        out_flags: *mut u32,
147        out_epoch: *mut i64,
148    );
149    /// Swift bridge function `cm_sample_buffer_get_decode_timestamp` for the corresponding Apple API.
150    pub fn cm_sample_buffer_get_decode_timestamp(
151        sample_buffer: *mut c_void,
152        out_value: *mut i64,
153        out_timescale: *mut i32,
154        out_flags: *mut u32,
155        out_epoch: *mut i64,
156    );
157    /// Swift bridge function `cm_sample_buffer_get_duration` for the corresponding Apple API.
158    pub fn cm_sample_buffer_get_duration(
159        sample_buffer: *mut c_void,
160        out_value: *mut i64,
161        out_timescale: *mut i32,
162        out_flags: *mut u32,
163        out_epoch: *mut i64,
164    );
165    /// Swift bridge function `cm_sample_buffer_get_num_samples` for the corresponding Apple API.
166    pub fn cm_sample_buffer_get_num_samples(sample_buffer: *mut c_void) -> i64;
167    /// Swift bridge function `cm_sample_buffer_is_valid` for the corresponding Apple API.
168    pub fn cm_sample_buffer_is_valid(sample_buffer: *mut c_void) -> bool;
169    /// Swift bridge function `cm_sample_buffer_data_is_ready` for the corresponding Apple API.
170    pub fn cm_sample_buffer_data_is_ready(sample_buffer: *mut c_void) -> bool;
171    pub fn acf_cm_sample_buffer_copy_audio_buffer_list(
172        sample_buffer: *mut c_void,
173        out_num_buffers: *mut u32,
174        out_buffers: *mut *mut c_void,
175        out_buffers_len: *mut usize,
176        out_block_buffer: *mut *mut c_void,
177    ) -> i32;
178    pub fn acf_cm_audio_buffer_array_free(buffers: *mut c_void);
179    pub fn acf_cm_sample_buffer_copy_sample_attachments(sample_buffer: *mut c_void) -> *mut c_void;
180    pub fn acf_cm_sample_buffer_is_sync_sample(sample_buffer: *mut c_void) -> bool;
181    pub fn acf_cm_video_format_description_get_dimensions(
182        format_description: *mut c_void,
183        out_width: *mut i32,
184        out_height: *mut i32,
185    ) -> bool;
186    pub fn acf_cm_video_format_description_copy_parameter_set(
187        format_description: *mut c_void,
188        hevc: bool,
189        index: usize,
190        out_count: *mut usize,
191        out_nal_unit_header_length: *mut i32,
192        out_status: *mut i32,
193    ) -> *mut c_void;
194
195    // ---- CMBlockBuffer ----
196    /// Swift bridge function `cm_block_buffer_release` for the corresponding Apple API.
197    pub fn cm_block_buffer_release(block_buffer: *mut c_void);
198    /// Swift bridge function `cm_block_buffer_retain` for the corresponding Apple API.
199    pub fn cm_block_buffer_retain(block_buffer: *mut c_void) -> *mut c_void;
200    /// Swift bridge function `cm_block_buffer_hash` for the corresponding Apple API.
201    pub fn cm_block_buffer_hash(block_buffer: *mut c_void) -> usize;
202    /// Swift bridge function `cm_block_buffer_get_data_length` for the corresponding Apple API.
203    pub fn cm_block_buffer_get_data_length(block_buffer: *mut c_void) -> usize;
204    /// Swift bridge function `cm_block_buffer_is_empty` for the corresponding Apple API.
205    pub fn cm_block_buffer_is_empty(block_buffer: *mut c_void) -> bool;
206    /// Swift bridge function `cm_block_buffer_is_range_contiguous` for the corresponding Apple API.
207    pub fn cm_block_buffer_is_range_contiguous(
208        block_buffer: *mut c_void,
209        offset: usize,
210        length: usize,
211    ) -> bool;
212    /// Swift bridge function `cm_block_buffer_get_data_pointer` for the corresponding Apple API.
213    pub fn cm_block_buffer_get_data_pointer(
214        block_buffer: *mut c_void,
215        offset: usize,
216        out_length_at_offset: *mut usize,
217        out_total_length: *mut usize,
218        out_data_pointer: *mut *mut c_void,
219    ) -> i32;
220    /// Swift bridge function `cm_block_buffer_copy_data_bytes` for the corresponding Apple API.
221    pub fn cm_block_buffer_copy_data_bytes(
222        block_buffer: *mut c_void,
223        offset_to_data: usize,
224        data_length: usize,
225        destination: *mut c_void,
226    ) -> i32;
227    /// Swift bridge function `cm_block_buffer_create_with_data` for the corresponding Apple API.
228    pub fn cm_block_buffer_create_with_data(
229        data: *const c_void,
230        data_length: usize,
231        block_buffer_out: *mut *mut c_void,
232    ) -> i32;
233    /// Swift bridge function `cm_block_buffer_create_empty` for the corresponding Apple API.
234    pub fn cm_block_buffer_create_empty(block_buffer_out: *mut *mut c_void) -> i32;
235
236    // ---- CMFormatDescription ----
237    /// Swift bridge function `cm_format_description_release` for the corresponding Apple API.
238    pub fn cm_format_description_release(format_description: *mut c_void);
239    /// Swift bridge function `cm_format_description_retain` for the corresponding Apple API.
240    pub fn cm_format_description_retain(format_description: *mut c_void) -> *mut c_void;
241    /// Swift bridge function `cm_format_description_hash` for the corresponding Apple API.
242    pub fn cm_format_description_hash(format_description: *mut c_void) -> usize;
243    /// Swift bridge function `cm_format_description_get_media_type` for the corresponding Apple API.
244    pub fn cm_format_description_get_media_type(format_description: *mut c_void) -> u32;
245    /// Swift bridge function `cm_format_description_get_media_subtype` for the corresponding Apple API.
246    pub fn cm_format_description_get_media_subtype(format_description: *mut c_void) -> u32;
247    /// Swift bridge function `cm_format_description_get_extensions` for the corresponding Apple API.
248    pub fn cm_format_description_get_extensions(format_description: *mut c_void) -> *const c_void;
249    /// Swift bridge function `cm_format_description_get_audio_sample_rate` for the corresponding Apple API.
250    pub fn cm_format_description_get_audio_sample_rate(format_description: *mut c_void) -> f64;
251    /// Swift bridge function `cm_format_description_get_audio_channel_count` for the corresponding Apple API.
252    pub fn cm_format_description_get_audio_channel_count(format_description: *mut c_void) -> u32;
253    /// Swift bridge function `cm_format_description_get_audio_bits_per_channel` for the corresponding Apple API.
254    pub fn cm_format_description_get_audio_bits_per_channel(format_description: *mut c_void)
255        -> u32;
256    /// Swift bridge function `cm_format_description_get_audio_bytes_per_frame` for the corresponding Apple API.
257    pub fn cm_format_description_get_audio_bytes_per_frame(format_description: *mut c_void) -> u32;
258    /// Swift bridge function `cm_format_description_get_audio_format_flags` for the corresponding Apple API.
259    pub fn cm_format_description_get_audio_format_flags(format_description: *mut c_void) -> u32;
260    /// Swift bridge function `cm_metadata_format_description_create_with_keys` for the corresponding Apple API.
261    pub fn cm_metadata_format_description_create_with_keys(
262        metadata_type: u32,
263        keys: *mut c_void,
264        format_description_out: *mut *mut c_void,
265    ) -> i32;
266    /// Swift bridge function `cm_metadata_format_description_create_with_metadata_specifications` for the corresponding Apple API.
267    pub fn cm_metadata_format_description_create_with_metadata_specifications(
268        metadata_type: u32,
269        metadata_specifications: *mut c_void,
270        format_description_out: *mut *mut c_void,
271    ) -> i32;
272    /// Swift bridge function `cm_metadata_format_description_create_with_description_and_metadata_specifications` for the corresponding Apple API.
273    pub fn cm_metadata_format_description_create_with_description_and_metadata_specifications(
274        source_description: *mut c_void,
275        metadata_specifications: *mut c_void,
276        format_description_out: *mut *mut c_void,
277    ) -> i32;
278    /// Swift bridge function `cm_metadata_format_description_create_by_merging_descriptions` for the corresponding Apple API.
279    pub fn cm_metadata_format_description_create_by_merging_descriptions(
280        source_description: *mut c_void,
281        other_source_description: *mut c_void,
282        format_description_out: *mut *mut c_void,
283    ) -> i32;
284    /// Swift bridge function `cm_metadata_format_description_get_identifiers` for the corresponding Apple API.
285    pub fn cm_metadata_format_description_get_identifiers(
286        format_description: *mut c_void,
287    ) -> *mut c_void;
288    /// Swift bridge function `cm_metadata_format_description_get_key_with_local_id` for the corresponding Apple API.
289    pub fn cm_metadata_format_description_get_key_with_local_id(
290        format_description: *mut c_void,
291        local_id: u32,
292    ) -> *mut c_void;
293    /// Swift bridge function `cm_metadata_format_description_extension_key_metadata_key_table` for the corresponding Apple API.
294    pub fn cm_metadata_format_description_extension_key_metadata_key_table() -> *mut c_void;
295    /// Swift bridge function `cm_metadata_format_description_key_conforming_data_types` for the corresponding Apple API.
296    pub fn cm_metadata_format_description_key_conforming_data_types() -> *mut c_void;
297    /// Swift bridge function `cm_metadata_format_description_key_data_type` for the corresponding Apple API.
298    pub fn cm_metadata_format_description_key_data_type() -> *mut c_void;
299    /// Swift bridge function `cm_metadata_format_description_key_data_type_namespace` for the corresponding Apple API.
300    pub fn cm_metadata_format_description_key_data_type_namespace() -> *mut c_void;
301    /// Swift bridge function `cm_metadata_format_description_key_language_tag` for the corresponding Apple API.
302    pub fn cm_metadata_format_description_key_language_tag() -> *mut c_void;
303    /// Swift bridge function `cm_metadata_format_description_key_local_id` for the corresponding Apple API.
304    pub fn cm_metadata_format_description_key_local_id() -> *mut c_void;
305    /// Swift bridge function `cm_metadata_format_description_key_namespace` for the corresponding Apple API.
306    pub fn cm_metadata_format_description_key_namespace() -> *mut c_void;
307    /// Swift bridge function `cm_metadata_format_description_key_setup_data` for the corresponding Apple API.
308    pub fn cm_metadata_format_description_key_setup_data() -> *mut c_void;
309    /// Swift bridge function `cm_metadata_format_description_key_structural_dependency` for the corresponding Apple API.
310    pub fn cm_metadata_format_description_key_structural_dependency() -> *mut c_void;
311    /// Swift bridge function `cm_metadata_format_description_key_value` for the corresponding Apple API.
312    pub fn cm_metadata_format_description_key_value() -> *mut c_void;
313    /// Swift bridge function `cm_metadata_format_description_metadata_specification_key_data_type` for the corresponding Apple API.
314    pub fn cm_metadata_format_description_metadata_specification_key_data_type() -> *mut c_void;
315    /// Swift bridge function `cm_metadata_format_description_metadata_specification_key_extended_language_tag` for the corresponding Apple API.
316    pub fn cm_metadata_format_description_metadata_specification_key_extended_language_tag(
317    ) -> *mut c_void;
318    /// Swift bridge function `cm_metadata_format_description_metadata_specification_key_identifier` for the corresponding Apple API.
319    pub fn cm_metadata_format_description_metadata_specification_key_identifier() -> *mut c_void;
320    /// Swift bridge function `cm_metadata_format_description_metadata_specification_key_setup_data` for the corresponding Apple API.
321    pub fn cm_metadata_format_description_metadata_specification_key_setup_data() -> *mut c_void;
322    /// Swift bridge function `cm_metadata_format_description_metadata_specification_key_structural_dependency` for the corresponding Apple API.
323    pub fn cm_metadata_format_description_metadata_specification_key_structural_dependency(
324    ) -> *mut c_void;
325    /// Swift bridge function `cm_metadata_format_description_structural_dependency_key_dependency_is_invalid_flag` for the corresponding Apple API.
326    pub fn cm_metadata_format_description_structural_dependency_key_dependency_is_invalid_flag(
327    ) -> *mut c_void;
328
329    // ---- CVPixelBuffer ----
330    /// Swift bridge function `cv_pixel_buffer_release` for the corresponding Apple API.
331    pub fn cv_pixel_buffer_release(pixel_buffer: *mut c_void);
332    /// Swift bridge function `cv_pixel_buffer_retain` for the corresponding Apple API.
333    pub fn cv_pixel_buffer_retain(pixel_buffer: *mut c_void) -> *mut c_void;
334    /// Swift bridge function `cv_pixel_buffer_hash` for the corresponding Apple API.
335    pub fn cv_pixel_buffer_hash(pixel_buffer: *mut c_void) -> usize;
336    /// Swift bridge function `cv_pixel_buffer_get_type_id` for the corresponding Apple API.
337    pub fn cv_pixel_buffer_get_type_id() -> usize;
338    /// Swift bridge function `cv_pixel_buffer_get_width` for the corresponding Apple API.
339    pub fn cv_pixel_buffer_get_width(pixel_buffer: *mut c_void) -> usize;
340    /// Swift bridge function `cv_pixel_buffer_get_height` for the corresponding Apple API.
341    pub fn cv_pixel_buffer_get_height(pixel_buffer: *mut c_void) -> usize;
342    /// Swift bridge function `cv_pixel_buffer_get_pixel_format_type` for the corresponding Apple API.
343    pub fn cv_pixel_buffer_get_pixel_format_type(pixel_buffer: *mut c_void) -> u32;
344    /// Swift bridge function `cv_pixel_buffer_get_bytes_per_row` for the corresponding Apple API.
345    pub fn cv_pixel_buffer_get_bytes_per_row(pixel_buffer: *mut c_void) -> usize;
346    /// Swift bridge function `cv_pixel_buffer_get_data_size` for the corresponding Apple API.
347    pub fn cv_pixel_buffer_get_data_size(pixel_buffer: *mut c_void) -> usize;
348    /// Swift bridge function `cv_pixel_buffer_is_planar` for the corresponding Apple API.
349    pub fn cv_pixel_buffer_is_planar(pixel_buffer: *mut c_void) -> bool;
350    /// Swift bridge function `cv_pixel_buffer_get_plane_count` for the corresponding Apple API.
351    pub fn cv_pixel_buffer_get_plane_count(pixel_buffer: *mut c_void) -> usize;
352    /// Swift bridge function `cv_pixel_buffer_get_width_of_plane` for the corresponding Apple API.
353    pub fn cv_pixel_buffer_get_width_of_plane(
354        pixel_buffer: *mut c_void,
355        plane_index: usize,
356    ) -> usize;
357    /// Swift bridge function `cv_pixel_buffer_get_height_of_plane` for the corresponding Apple API.
358    pub fn cv_pixel_buffer_get_height_of_plane(
359        pixel_buffer: *mut c_void,
360        plane_index: usize,
361    ) -> usize;
362    /// Swift bridge function `cv_pixel_buffer_get_bytes_per_row_of_plane` for the corresponding Apple API.
363    pub fn cv_pixel_buffer_get_bytes_per_row_of_plane(
364        pixel_buffer: *mut c_void,
365        plane_index: usize,
366    ) -> usize;
367    /// Swift bridge function `cv_pixel_buffer_get_base_address_of_plane` for the corresponding Apple API.
368    pub fn cv_pixel_buffer_get_base_address_of_plane(
369        pixel_buffer: *mut c_void,
370        plane_index: usize,
371    ) -> *mut c_void;
372    /// Swift bridge function `cv_pixel_buffer_get_base_address` for the corresponding Apple API.
373    pub fn cv_pixel_buffer_get_base_address(pixel_buffer: *mut c_void) -> *mut c_void;
374    /// Swift bridge function `cv_pixel_buffer_lock_base_address` for the corresponding Apple API.
375    pub fn cv_pixel_buffer_lock_base_address(pixel_buffer: *mut c_void, flags: u64) -> i32;
376    /// Swift bridge function `cv_pixel_buffer_unlock_base_address` for the corresponding Apple API.
377    pub fn cv_pixel_buffer_unlock_base_address(pixel_buffer: *mut c_void, flags: u64) -> i32;
378    /// Swift bridge function `cv_pixel_buffer_get_io_surface` for the corresponding Apple API.
379    pub fn cv_pixel_buffer_get_io_surface(pixel_buffer: *mut c_void) -> *mut c_void;
380    /// Swift bridge function `cv_pixel_buffer_get_extended_pixels` for the corresponding Apple API.
381    pub fn cv_pixel_buffer_get_extended_pixels(
382        pixel_buffer: *mut c_void,
383        extra_columns_on_left: *mut usize,
384        extra_columns_on_right: *mut usize,
385        extra_rows_on_top: *mut usize,
386        extra_rows_on_bottom: *mut usize,
387    );
388    /// Swift bridge function `cv_pixel_buffer_fill_extended_pixels` for the corresponding Apple API.
389    pub fn cv_pixel_buffer_fill_extended_pixels(pixel_buffer: *mut c_void) -> i32;
390    /// Swift bridge function `cv_pixel_buffer_create` for the corresponding Apple API.
391    pub fn cv_pixel_buffer_create(
392        width: usize,
393        height: usize,
394        pixel_format_type: u32,
395        pixel_buffer_out: *mut *mut c_void,
396    ) -> i32;
397    /// Swift bridge function `cv_pixel_buffer_create_with_bytes` for the corresponding Apple API.
398    pub fn cv_pixel_buffer_create_with_bytes(
399        width: usize,
400        height: usize,
401        pixel_format_type: u32,
402        base_address: *mut c_void,
403        bytes_per_row: usize,
404        pixel_buffer_out: *mut *mut c_void,
405    ) -> i32;
406    /// Swift bridge function `cv_pixel_buffer_create_with_planar_bytes` for the corresponding Apple API.
407    pub fn cv_pixel_buffer_create_with_planar_bytes(
408        width: usize,
409        height: usize,
410        pixel_format_type: u32,
411        num_planes: usize,
412        plane_base_addresses: *const *mut c_void,
413        plane_widths: *const usize,
414        plane_heights: *const usize,
415        plane_bytes_per_row: *const usize,
416        pixel_buffer_out: *mut *mut c_void,
417    ) -> i32;
418    /// Swift bridge function `cv_pixel_buffer_create_with_io_surface` for the corresponding Apple API.
419    pub fn cv_pixel_buffer_create_with_io_surface(
420        io_surface: *mut c_void,
421        pixel_buffer_out: *mut *mut c_void,
422    ) -> i32;
423
424}
425
426// MARK: - ABI Layout Assertions
427//
428// The hand-written `#[repr(C)]` value types below are passed across the FFI
429// boundary by value (e.g. `CMTimeRangeGetEnd(range: CMTimeRange) -> CMTime`,
430// `CVImageBufferGetCleanRect(...) -> CVImageRect`) or read out of buffers that
431// Apple's frameworks / the Swift bridge populate (`AudioBuffer`,
432// `AudioBufferListRaw`). Their layout must match the matching C / Swift struct
433// exactly: any change to a field type, field order, or padding silently
434// corrupts marshalled data at runtime.
435//
436// These compile-time assertions pin the size and alignment of every such
437// struct so accidental field reordering / type changes fail the build
438// immediately. Field offsets are pinned indirectly via size + alignment
439// rather than per-field `offset_of!`. The runtime `verify_ffi_layout` check in
440// `tests/ffi_layout_tests.rs` guards the same invariants.
441
442#[cfg(any(feature = "cg", feature = "cm", feature = "cv"))]
443use core::mem::{align_of, size_of};
444
445#[cfg(feature = "cg")]
446const _: () = {
447    use crate::cg::{CGAffineTransform, CGPoint, CGRect, CGSize, CGVector};
448    assert!(size_of::<CGPoint>() == 16);
449    assert!(align_of::<CGPoint>() == 8);
450    assert!(size_of::<CGSize>() == 16);
451    assert!(align_of::<CGSize>() == 8);
452    assert!(size_of::<CGRect>() == 32);
453    assert!(align_of::<CGRect>() == 8);
454    assert!(size_of::<CGVector>() == 16);
455    assert!(align_of::<CGVector>() == 8);
456    assert!(size_of::<CGAffineTransform>() == 48);
457    assert!(align_of::<CGAffineTransform>() == 8);
458};
459
460#[cfg(feature = "cv")]
461const _: () = {
462    use crate::cv::{CVImageRect, CVImageSize, CVPixelBufferLockFlags};
463    assert!(size_of::<CVImageSize>() == 16);
464    assert!(align_of::<CVImageSize>() == 8);
465    assert!(size_of::<CVImageRect>() == 32);
466    assert!(align_of::<CVImageRect>() == 8);
467    assert!(size_of::<CVPixelBufferLockFlags>() == 8);
468    assert!(align_of::<CVPixelBufferLockFlags>() == 8);
469};
470
471#[cfg(feature = "cm")]
472const _: () = {
473    use crate::cm::{AudioBuffer, AudioBufferListRaw, CMSampleTimingInfo, CMTime, CMTimeRange};
474    assert!(size_of::<CMTime>() == 24);
475    assert!(align_of::<CMTime>() == 8);
476    assert!(size_of::<CMSampleTimingInfo>() == 72);
477    assert!(align_of::<CMSampleTimingInfo>() == 8);
478    assert!(size_of::<CMTimeRange>() == 48);
479    assert!(align_of::<CMTimeRange>() == 8);
480    assert!(size_of::<AudioBuffer>() == 16);
481    assert!(align_of::<AudioBuffer>() == 8);
482    assert!(size_of::<AudioBufferListRaw>() == 24);
483    assert!(align_of::<AudioBufferListRaw>() == 8);
484};
485
486/// Verify the ABI layout (size + alignment) of every by-value `#[repr(C)]`
487/// FFI value type at runtime.
488///
489/// Returns `true` only if all enabled-framework structs still match the layout
490/// pinned by the compile-time assertions above. This mirrors those `const`
491/// assertions in a form the integration tests in `tests/ffi_layout_tests.rs`
492/// can exercise, so a layout regression is caught as a test failure as well as
493/// a build failure.
494#[must_use]
495pub const fn verify_ffi_layout() -> bool {
496    #[allow(unused_mut)]
497    let mut ok = true;
498
499    #[cfg(feature = "cg")]
500    {
501        use crate::cg::{CGAffineTransform, CGPoint, CGRect, CGSize, CGVector};
502        ok = ok && size_of::<CGPoint>() == 16 && align_of::<CGPoint>() == 8;
503        ok = ok && size_of::<CGSize>() == 16 && align_of::<CGSize>() == 8;
504        ok = ok && size_of::<CGRect>() == 32 && align_of::<CGRect>() == 8;
505        ok = ok && size_of::<CGVector>() == 16 && align_of::<CGVector>() == 8;
506        ok = ok && size_of::<CGAffineTransform>() == 48 && align_of::<CGAffineTransform>() == 8;
507    }
508
509    #[cfg(feature = "cv")]
510    {
511        use crate::cv::{CVImageRect, CVImageSize, CVPixelBufferLockFlags};
512        ok = ok && size_of::<CVImageSize>() == 16 && align_of::<CVImageSize>() == 8;
513        ok = ok && size_of::<CVImageRect>() == 32 && align_of::<CVImageRect>() == 8;
514        ok = ok
515            && size_of::<CVPixelBufferLockFlags>() == 8
516            && align_of::<CVPixelBufferLockFlags>() == 8;
517    }
518
519    #[cfg(feature = "cm")]
520    {
521        use crate::cm::{AudioBuffer, AudioBufferListRaw, CMSampleTimingInfo, CMTime, CMTimeRange};
522        ok = ok && size_of::<CMTime>() == 24 && align_of::<CMTime>() == 8;
523        ok = ok && size_of::<CMSampleTimingInfo>() == 72 && align_of::<CMSampleTimingInfo>() == 8;
524        ok = ok && size_of::<CMTimeRange>() == 48 && align_of::<CMTimeRange>() == 8;
525        ok = ok && size_of::<AudioBuffer>() == 16 && align_of::<AudioBuffer>() == 8;
526        ok = ok && size_of::<AudioBufferListRaw>() == 24 && align_of::<AudioBufferListRaw>() == 8;
527    }
528
529    ok
530}