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