screencapturekit 1.5.4

Safe Rust bindings for Apple's ScreenCaptureKit framework - screen and audio capture on macOS
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
//! Swift FFI bridge to `ScreenCaptureKit`
use std::ffi::c_void;

// MARK: - FFI Packed Data Structures

/// Packed `CGRect` for efficient FFI transfer (32 bytes)
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
pub struct FFIRect {
    pub x: f64,
    pub y: f64,
    pub width: f64,
    pub height: f64,
}

/// Packed display data for batch retrieval (48 bytes)
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct FFIDisplayData {
    pub display_id: u32,
    pub width: i32,
    pub height: i32,
    pub frame: FFIRect,
}

/// Packed window data for batch retrieval
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct FFIWindowData {
    pub window_id: u32,
    pub window_layer: i32,
    pub is_on_screen: bool,
    pub is_active: bool,
    pub frame: FFIRect,
    pub title_offset: u32,
    pub title_length: u32,
    pub owning_app_index: i32,
    #[doc(hidden)]
    pub _padding: i32,
}

/// Packed application data for batch retrieval
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct FFIApplicationData {
    pub process_id: i32,
    #[doc(hidden)]
    pub _padding: i32,
    pub bundle_id_offset: u32,
    pub bundle_id_length: u32,
    pub app_name_offset: u32,
    pub app_name_length: u32,
}

// MARK: - CoreGraphics Initialization
extern "C" {
    /// Force CoreGraphics initialization by calling `CGMainDisplayID`
    /// This prevents `CGS_REQUIRE_INIT` crashes on headless systems
    pub fn sc_initialize_core_graphics();
}

// MARK: - SCShareableContent
extern "C" {
    /// Synchronous blocking call to get shareable content
    /// Returns content pointer on success, or writes error to `error_buffer`
    pub fn sc_shareable_content_get_sync(
        exclude_desktop_windows: bool,
        on_screen_windows_only: bool,
        error_buffer: *mut i8,
        error_buffer_size: isize,
    ) -> *const c_void;

    /// Async callback-based shareable content retrieval with options
    pub fn sc_shareable_content_get_with_options(
        exclude_desktop_windows: bool,
        on_screen_windows_only: bool,
        callback: extern "C" fn(*const c_void, *const i8, *mut c_void),
        user_data: *mut c_void,
    );

    pub fn sc_shareable_content_get(
        callback: extern "C" fn(*const c_void, *const i8, *mut c_void),
        user_data: *mut c_void,
    );
    pub fn sc_shareable_content_get_current_process_displays(
        callback: extern "C" fn(*const c_void, *const i8, *mut c_void),
        user_data: *mut c_void,
    );
    pub fn sc_shareable_content_get_below_window(
        exclude_desktop_windows: bool,
        reference_window: *const c_void,
        callback: extern "C" fn(*const c_void, *const i8, *mut c_void),
        user_data: *mut c_void,
    );
    pub fn sc_shareable_content_get_above_window(
        exclude_desktop_windows: bool,
        reference_window: *const c_void,
        callback: extern "C" fn(*const c_void, *const i8, *mut c_void),
        user_data: *mut c_void,
    );
    pub fn sc_shareable_content_retain(content: *const c_void) -> *const c_void;
    pub fn sc_shareable_content_release(content: *const c_void);
    pub fn sc_shareable_content_get_displays_count(content: *const c_void) -> isize;
    pub fn sc_shareable_content_get_display_at(
        content: *const c_void,
        index: isize,
    ) -> *const c_void;
    pub fn sc_shareable_content_get_windows_count(content: *const c_void) -> isize;
    pub fn sc_shareable_content_get_window_at(
        content: *const c_void,
        index: isize,
    ) -> *const c_void;
    pub fn sc_shareable_content_get_applications_count(content: *const c_void) -> isize;
    pub fn sc_shareable_content_get_application_at(
        content: *const c_void,
        index: isize,
    ) -> *const c_void;

    // Batch retrieval functions (optimized FFI)
    pub fn sc_shareable_content_get_displays_batch(
        content: *const c_void,
        buffer: *mut c_void, // Actually *mut FFIDisplayData
        max_displays: isize,
    ) -> isize;

    pub fn sc_shareable_content_get_applications_batch(
        content: *const c_void,
        buffer: *mut c_void, // Actually *mut FFIApplicationData
        max_apps: isize,
        string_buffer: *mut i8,
        string_buffer_size: isize,
        string_buffer_used: *mut isize,
    ) -> isize;

    pub fn sc_shareable_content_get_windows_batch(
        content: *const c_void,
        buffer: *mut c_void, // Actually *mut FFIWindowData
        max_windows: isize,
        string_buffer: *mut i8,
        string_buffer_size: isize,
        string_buffer_used: *mut isize,
        app_pointers: *mut *const c_void,
        max_apps: isize,
        app_count: *mut isize,
    ) -> isize;
}

// MARK: - SCDisplay
extern "C" {
    pub fn sc_display_retain(display: *const c_void) -> *const c_void;
    pub fn sc_display_release(display: *const c_void);
    pub fn sc_display_get_display_id(display: *const c_void) -> u32;
    pub fn sc_display_get_width(display: *const c_void) -> isize;
    pub fn sc_display_get_height(display: *const c_void) -> isize;
    pub fn sc_display_get_frame(
        display: *const c_void,
        x: *mut f64,
        y: *mut f64,
        width: *mut f64,
        height: *mut f64,
    );
    /// Get display frame (same as `sc_display_get_frame`, kept for API compatibility)
    pub fn sc_display_get_frame_packed(
        display: *const c_void,
        x: *mut f64,
        y: *mut f64,
        width: *mut f64,
        height: *mut f64,
    );
}

// MARK: - SCWindow
extern "C" {
    pub fn sc_window_retain(window: *const c_void) -> *const c_void;
    pub fn sc_window_release(window: *const c_void);
    pub fn sc_window_get_window_id(window: *const c_void) -> u32;
    pub fn sc_window_get_frame(
        window: *const c_void,
        x: *mut f64,
        y: *mut f64,
        width: *mut f64,
        height: *mut f64,
    );
    /// Get window frame (same as `sc_window_get_frame`, kept for API compatibility)
    pub fn sc_window_get_frame_packed(
        window: *const c_void,
        x: *mut f64,
        y: *mut f64,
        width: *mut f64,
        height: *mut f64,
    );
    pub fn sc_window_get_title(window: *const c_void, buffer: *mut i8, buffer_size: isize) -> bool;
    /// Get window title as owned string (caller must free with `sc_free_string`)
    pub fn sc_window_get_title_owned(window: *const c_void) -> *mut i8;
    pub fn sc_window_get_window_layer(window: *const c_void) -> isize;
    pub fn sc_window_is_on_screen(window: *const c_void) -> bool;
    pub fn sc_window_get_owning_application(window: *const c_void) -> *const c_void;
    pub fn sc_window_is_active(window: *const c_void) -> bool;
}

// MARK: - SCRunningApplication
extern "C" {
    pub fn sc_running_application_retain(app: *const c_void) -> *const c_void;
    pub fn sc_running_application_release(app: *const c_void);
    pub fn sc_running_application_get_bundle_identifier(
        app: *const c_void,
        buffer: *mut i8,
        buffer_size: isize,
    ) -> bool;
    /// Get bundle identifier as owned string (caller must free with `sc_free_string`)
    pub fn sc_running_application_get_bundle_identifier_owned(app: *const c_void) -> *mut i8;
    pub fn sc_running_application_get_application_name(
        app: *const c_void,
        buffer: *mut i8,
        buffer_size: isize,
    ) -> bool;
    /// Get application name as owned string (caller must free with `sc_free_string`)
    pub fn sc_running_application_get_application_name_owned(app: *const c_void) -> *mut i8;
    pub fn sc_running_application_get_process_id(app: *const c_void) -> i32;
}

// MARK: - String memory management
extern "C" {
    /// Free a string allocated by Swift (strdup)
    pub fn sc_free_string(str: *mut i8);
}

// MARK: - SCStreamConfiguration
extern "C" {
    pub fn sc_stream_configuration_create() -> *const c_void;
    pub fn sc_stream_configuration_retain(config: *const c_void) -> *const c_void;
    pub fn sc_stream_configuration_release(config: *const c_void);

    pub fn sc_stream_configuration_set_width(config: *const c_void, width: isize);
    pub fn sc_stream_configuration_get_width(config: *const c_void) -> isize;

    pub fn sc_stream_configuration_set_height(config: *const c_void, height: isize);
    pub fn sc_stream_configuration_get_height(config: *const c_void) -> isize;

    pub fn sc_stream_configuration_set_shows_cursor(config: *const c_void, shows_cursor: bool);
    pub fn sc_stream_configuration_get_shows_cursor(config: *const c_void) -> bool;

    pub fn sc_stream_configuration_set_scales_to_fit(config: *const c_void, scales_to_fit: bool);
    pub fn sc_stream_configuration_get_scales_to_fit(config: *const c_void) -> bool;

    pub fn sc_stream_configuration_set_captures_audio(config: *const c_void, captures_audio: bool);
    pub fn sc_stream_configuration_get_captures_audio(config: *const c_void) -> bool;

    pub fn sc_stream_configuration_set_sample_rate(config: *const c_void, sample_rate: isize);
    pub fn sc_stream_configuration_get_sample_rate(config: *const c_void) -> isize;

    pub fn sc_stream_configuration_set_channel_count(config: *const c_void, channel_count: isize);
    pub fn sc_stream_configuration_get_channel_count(config: *const c_void) -> isize;

    pub fn sc_stream_configuration_set_queue_depth(config: *const c_void, queue_depth: isize);
    pub fn sc_stream_configuration_get_queue_depth(config: *const c_void) -> isize;

    pub fn sc_stream_configuration_set_pixel_format(config: *const c_void, pixel_format: u32);
    pub fn sc_stream_configuration_get_pixel_format(config: *const c_void) -> u32;

    pub fn sc_stream_configuration_set_minimum_frame_interval(
        config: *const c_void,
        value: i64,
        timescale: i32,
        flags: u32,
        epoch: i64,
    );
    pub fn sc_stream_configuration_get_minimum_frame_interval(
        config: *const c_void,
        value: *mut i64,
        timescale: *mut i32,
        flags: *mut u32,
        epoch: *mut i64,
    );

    pub fn sc_stream_configuration_set_source_rect(
        config: *const c_void,
        x: f64,
        y: f64,
        width: f64,
        height: f64,
    );
    pub fn sc_stream_configuration_get_source_rect(
        config: *const c_void,
        x: *mut f64,
        y: *mut f64,
        width: *mut f64,
        height: *mut f64,
    );

    pub fn sc_stream_configuration_set_destination_rect(
        config: *const c_void,
        x: f64,
        y: f64,
        width: f64,
        height: f64,
    );
    pub fn sc_stream_configuration_get_destination_rect(
        config: *const c_void,
        x: *mut f64,
        y: *mut f64,
        width: *mut f64,
        height: *mut f64,
    );

    pub fn sc_stream_configuration_set_preserves_aspect_ratio(
        config: *const c_void,
        preserves_aspect_ratio: bool,
    );
    pub fn sc_stream_configuration_get_preserves_aspect_ratio(config: *const c_void) -> bool;

    pub fn sc_stream_configuration_set_ignores_shadows_single_window(
        config: *const c_void,
        ignores_shadows: bool,
    );
    pub fn sc_stream_configuration_get_ignores_shadows_single_window(config: *const c_void)
        -> bool;

    pub fn sc_stream_configuration_set_should_be_opaque(
        config: *const c_void,
        should_be_opaque: bool,
    );
    pub fn sc_stream_configuration_get_should_be_opaque(config: *const c_void) -> bool;

    pub fn sc_stream_configuration_set_includes_child_windows(
        config: *const c_void,
        includes_child_windows: bool,
    );
    pub fn sc_stream_configuration_get_includes_child_windows(config: *const c_void) -> bool;

    pub fn sc_stream_configuration_set_presenter_overlay_privacy_alert_setting(
        config: *const c_void,
        setting: i32,
    );
    pub fn sc_stream_configuration_get_presenter_overlay_privacy_alert_setting(
        config: *const c_void,
    ) -> i32;

    pub fn sc_stream_configuration_set_background_color(
        config: *const c_void,
        r: f32,
        g: f32,
        b: f32,
    );
    pub fn sc_stream_configuration_set_color_space_name(config: *const c_void, name: *const i8);
    pub fn sc_stream_configuration_set_color_matrix(config: *const c_void, matrix: *const i8);
    pub fn sc_stream_configuration_get_color_matrix(
        config: *const c_void,
        buffer: *mut i8,
        buffer_size: usize,
    ) -> bool;

    // macOS 14.0+ - capture resolution type
    pub fn sc_stream_configuration_set_capture_resolution_type(config: *const c_void, value: i32);
    pub fn sc_stream_configuration_get_capture_resolution_type(config: *const c_void) -> i32;

    pub fn sc_stream_configuration_set_ignores_shadow_display_configuration(
        config: *const c_void,
        ignores_shadow: bool,
    );
    pub fn sc_stream_configuration_get_ignores_shadow_display_configuration(
        config: *const c_void,
    ) -> bool;

    pub fn sc_stream_configuration_set_preserve_aspect_ratio(config: *const c_void, preserve: bool);
    pub fn sc_stream_configuration_get_preserve_aspect_ratio(config: *const c_void) -> bool;

    pub fn sc_stream_configuration_set_captures_shadows_only(
        config: *const c_void,
        captures_shadows_only: bool,
    );
    pub fn sc_stream_configuration_get_captures_shadows_only(config: *const c_void) -> bool;

    pub fn sc_stream_configuration_set_captures_microphone(
        config: *const c_void,
        captures_microphone: bool,
    );
    pub fn sc_stream_configuration_get_captures_microphone(config: *const c_void) -> bool;

    pub fn sc_stream_configuration_set_excludes_current_process_audio(
        config: *const c_void,
        excludes: bool,
    );
    pub fn sc_stream_configuration_get_excludes_current_process_audio(
        config: *const c_void,
    ) -> bool;

    pub fn sc_stream_configuration_set_microphone_capture_device_id(
        config: *const c_void,
        device_id: *const i8,
    );
    pub fn sc_stream_configuration_get_microphone_capture_device_id(
        config: *const c_void,
        buffer: *mut i8,
        buffer_size: isize,
    ) -> bool;

    pub fn sc_stream_configuration_set_stream_name(config: *const c_void, name: *const i8);
    pub fn sc_stream_configuration_get_stream_name(
        config: *const c_void,
        buffer: *mut i8,
        buffer_size: isize,
    ) -> bool;

    pub fn sc_stream_configuration_set_capture_dynamic_range(config: *const c_void, value: i32);
    pub fn sc_stream_configuration_get_capture_dynamic_range(config: *const c_void) -> i32;
}

// MARK: - SCContentFilter
extern "C" {
    pub fn sc_content_filter_create_with_desktop_independent_window(
        window: *const c_void,
    ) -> *const c_void;
    pub fn sc_content_filter_create_with_display_excluding_windows(
        display: *const c_void,
        windows: *const *const c_void,
        windows_count: isize,
    ) -> *const c_void;
    pub fn sc_content_filter_create_with_display_including_windows(
        display: *const c_void,
        windows: *const *const c_void,
        windows_count: isize,
    ) -> *const c_void;
    pub fn sc_content_filter_create_with_display_including_applications_excepting_windows(
        display: *const c_void,
        apps: *const *const c_void,
        apps_count: isize,
        windows: *const *const c_void,
        windows_count: isize,
    ) -> *const c_void;
    pub fn sc_content_filter_create_with_display_excluding_applications_excepting_windows(
        display: *const c_void,
        apps: *const *const c_void,
        apps_count: isize,
        windows: *const *const c_void,
        windows_count: isize,
    ) -> *const c_void;
    pub fn sc_content_filter_retain(filter: *const c_void) -> *const c_void;
    pub fn sc_content_filter_release(filter: *const c_void);
    pub fn sc_content_filter_set_content_rect(
        filter: *const c_void,
        x: f64,
        y: f64,
        width: f64,
        height: f64,
    );
    pub fn sc_content_filter_get_content_rect(
        filter: *const c_void,
        x: *mut f64,
        y: *mut f64,
        width: *mut f64,
        height: *mut f64,
    );
    /// Get content filter content rect (same as `sc_content_filter_get_content_rect`)
    pub fn sc_content_filter_get_content_rect_packed(
        filter: *const c_void,
        x: *mut f64,
        y: *mut f64,
        width: *mut f64,
        height: *mut f64,
    );
}

// MARK: - SCStream
extern "C" {
    pub fn sc_stream_create(
        filter: *const c_void,
        config: *const c_void,
        context: *mut c_void,
        error_callback: extern "C" fn(*mut c_void, i32, *const i8),
        sample_callback: extern "C" fn(*mut c_void, *const c_void, i32),
    ) -> *const c_void;
    pub fn sc_stream_add_stream_output(stream: *const c_void, output_type: i32) -> bool;
    pub fn sc_stream_add_stream_output_with_queue(
        stream: *const c_void,
        output_type: i32,
        dispatch_queue: *const c_void,
    ) -> bool;
    pub fn sc_stream_remove_stream_output(stream: *const c_void, output_type: i32) -> bool;
    pub fn sc_stream_start_capture(
        stream: *const c_void,
        context: *mut c_void,
        callback: extern "C" fn(*mut c_void, bool, *const i8),
    );
    pub fn sc_stream_stop_capture(
        stream: *const c_void,
        context: *mut c_void,
        callback: extern "C" fn(*mut c_void, bool, *const i8),
    );
    pub fn sc_stream_update_configuration(
        stream: *const c_void,
        config: *const c_void,
        context: *mut c_void,
        callback: extern "C" fn(*mut c_void, bool, *const i8),
    );
    pub fn sc_stream_update_content_filter(
        stream: *const c_void,
        filter: *const c_void,
        context: *mut c_void,
        callback: extern "C" fn(*mut c_void, bool, *const i8),
    );
    pub fn sc_stream_add_recording_output(
        stream: *const c_void,
        recording_output: *const c_void,
        callback: extern "C" fn(*mut c_void, bool, *const i8),
        context: *mut c_void,
    );
    pub fn sc_stream_remove_recording_output(
        stream: *const c_void,
        recording_output: *const c_void,
        callback: extern "C" fn(*mut c_void, bool, *const i8),
        context: *mut c_void,
    );
    pub fn sc_stream_retain(stream: *const c_void) -> *const c_void;
    pub fn sc_stream_release(stream: *const c_void);

    // macOS 13.0+ - synchronizationClock
    pub fn sc_stream_get_synchronization_clock(stream: *const c_void) -> *const c_void;
}

// MARK: - Dispatch Queue
extern "C" {
    pub fn dispatch_queue_create(label: *const i8, qos: i32) -> *const c_void;
    pub fn dispatch_queue_release(queue: *const c_void);
    pub fn dispatch_queue_retain(queue: *const c_void) -> *const c_void;
}

// MARK: - IOSurface
extern "C" {
    pub fn cv_pixel_buffer_get_iosurface(pixel_buffer: *const c_void) -> *const c_void;
    pub fn cv_pixel_buffer_is_backed_by_iosurface(pixel_buffer: *const c_void) -> bool;
    pub fn iosurface_get_width(iosurface: *const c_void) -> isize;
    pub fn iosurface_get_height(iosurface: *const c_void) -> isize;
    pub fn iosurface_get_bytes_per_row(iosurface: *const c_void) -> isize;
    pub fn iosurface_get_pixel_format(iosurface: *const c_void) -> u32;
    pub fn iosurface_get_base_address(iosurface: *const c_void) -> *mut u8;
    pub fn iosurface_lock(iosurface: *const c_void, options: u32) -> i32;
    pub fn iosurface_unlock(iosurface: *const c_void, options: u32) -> i32;
    pub fn iosurface_is_in_use(iosurface: *const c_void) -> bool;
    pub fn iosurface_release(iosurface: *const c_void);

    // Plane functions (for multi-planar formats like YCbCr 420)
    pub fn iosurface_get_plane_count(iosurface: *const c_void) -> isize;
    pub fn iosurface_get_width_of_plane(iosurface: *const c_void, plane: isize) -> isize;
    pub fn iosurface_get_height_of_plane(iosurface: *const c_void, plane: isize) -> isize;
    pub fn iosurface_get_bytes_per_row_of_plane(iosurface: *const c_void, plane: isize) -> isize;

    // IOSurface creation (for testing)
    pub fn io_surface_create(
        width: usize,
        height: usize,
        pixel_format: u32,
        bytes_per_element: usize,
        surface_out: *mut *mut c_void,
    ) -> i32;

    // IOSurface creation with full properties (for multi-planar formats)
    pub fn io_surface_create_with_properties(
        width: usize,
        height: usize,
        pixel_format: u32,
        bytes_per_element: usize,
        bytes_per_row: usize,
        alloc_size: usize,
        plane_count: usize,
        plane_widths: *const usize,
        plane_heights: *const usize,
        plane_bytes_per_row: *const usize,
        plane_bytes_per_element: *const usize,
        plane_offsets: *const usize,
        plane_sizes: *const usize,
        surface_out: *mut *mut c_void,
    ) -> i32;
}

// MARK: - SCContentSharingPicker (macOS 14.0+)
extern "C" {
    pub fn sc_content_sharing_picker_configuration_create() -> *const c_void;
    pub fn sc_content_sharing_picker_configuration_set_allowed_picker_modes(
        config: *const c_void,
        modes: *const i32,
        count: usize,
    );
    pub fn sc_content_sharing_picker_configuration_set_allows_changing_selected_content(
        config: *const c_void,
        allows: bool,
    );
    pub fn sc_content_sharing_picker_configuration_get_allows_changing_selected_content(
        config: *const c_void,
    ) -> bool;
    pub fn sc_content_sharing_picker_configuration_set_excluded_bundle_ids(
        config: *const c_void,
        bundle_ids: *const *const i8,
        count: usize,
    );
    pub fn sc_content_sharing_picker_configuration_get_excluded_bundle_ids_count(
        config: *const c_void,
    ) -> usize;
    pub fn sc_content_sharing_picker_configuration_get_excluded_bundle_id_at(
        config: *const c_void,
        index: usize,
        buffer: *mut i8,
        buffer_size: usize,
    ) -> bool;
    pub fn sc_content_sharing_picker_configuration_set_excluded_window_ids(
        config: *const c_void,
        window_ids: *const u32,
        count: usize,
    );
    pub fn sc_content_sharing_picker_configuration_get_excluded_window_ids_count(
        config: *const c_void,
    ) -> usize;
    pub fn sc_content_sharing_picker_configuration_get_excluded_window_id_at(
        config: *const c_void,
        index: usize,
    ) -> u32;
    pub fn sc_content_sharing_picker_configuration_retain(config: *const c_void) -> *const c_void;
    pub fn sc_content_sharing_picker_configuration_release(config: *const c_void);

    // Picker maximum stream count
    pub fn sc_content_sharing_picker_set_maximum_stream_count(count: usize);
    pub fn sc_content_sharing_picker_get_maximum_stream_count() -> usize;

    pub fn sc_content_sharing_picker_show(
        config: *const c_void,
        callback: extern "C" fn(i32, *const c_void, *mut c_void),
        user_data: *mut c_void,
    );
    pub fn sc_content_sharing_picker_show_with_result(
        config: *const c_void,
        callback: extern "C" fn(i32, *const c_void, *mut c_void),
        user_data: *mut c_void,
    );
    pub fn sc_content_sharing_picker_show_for_stream(
        config: *const c_void,
        stream: *const c_void,
        callback: extern "C" fn(i32, *const c_void, *mut c_void),
        user_data: *mut c_void,
    );
    pub fn sc_content_sharing_picker_show_using_style(
        config: *const c_void,
        style: i32,
        callback: extern "C" fn(i32, *const c_void, *mut c_void),
        user_data: *mut c_void,
    );
    pub fn sc_content_sharing_picker_show_for_stream_using_style(
        config: *const c_void,
        stream: *const c_void,
        style: i32,
        callback: extern "C" fn(i32, *const c_void, *mut c_void),
        user_data: *mut c_void,
    );
    pub fn sc_picker_result_get_filter(result: *const c_void) -> *const c_void;
    pub fn sc_picker_result_get_content_rect(
        result: *const c_void,
        x: *mut f64,
        y: *mut f64,
        width: *mut f64,
        height: *mut f64,
    );
    pub fn sc_picker_result_get_scale(result: *const c_void) -> f64;
    pub fn sc_picker_result_get_windows_count(result: *const c_void) -> usize;
    pub fn sc_picker_result_get_window_at(result: *const c_void, index: usize) -> *const c_void;
    pub fn sc_picker_result_get_displays_count(result: *const c_void) -> usize;
    pub fn sc_picker_result_get_display_at(result: *const c_void, index: usize) -> *const c_void;
    pub fn sc_picker_result_get_applications_count(result: *const c_void) -> usize;
    pub fn sc_picker_result_get_application_at(
        result: *const c_void,
        index: usize,
    ) -> *const c_void;
    pub fn sc_picker_result_release(result: *const c_void);
}

// MARK: - SCRecordingOutput (macOS 15.0+)
extern "C" {
    pub fn sc_recording_output_configuration_create() -> *const c_void;
    pub fn sc_recording_output_configuration_set_output_url(config: *const c_void, path: *const i8);
    pub fn sc_recording_output_configuration_set_video_codec(config: *const c_void, codec: i32);
    pub fn sc_recording_output_configuration_retain(config: *const c_void) -> *const c_void;
    pub fn sc_recording_output_configuration_release(config: *const c_void);
    pub fn sc_recording_output_create(config: *const c_void) -> *const c_void;
    pub fn sc_recording_output_retain(output: *const c_void) -> *const c_void;
    pub fn sc_recording_output_release(output: *const c_void);
}

// MARK: - SCScreenshotManager (macOS 14.0+)
extern "C" {
    pub fn sc_screenshot_manager_capture_image(
        content_filter: *const c_void,
        config: *const c_void,
        callback: extern "C" fn(*const c_void, *const i8, *mut c_void),
        user_data: *mut c_void,
    );
    pub fn sc_screenshot_manager_capture_sample_buffer(
        content_filter: *const c_void,
        config: *const c_void,
        callback: extern "C" fn(*const c_void, *const i8, *mut c_void),
        user_data: *mut c_void,
    );
    pub fn sc_screenshot_manager_capture_image_in_rect(
        x: f64,
        y: f64,
        width: f64,
        height: f64,
        callback: extern "C" fn(*const c_void, *const i8, *mut c_void),
        user_data: *mut c_void,
    );
    pub fn cgimage_get_width(image: *const c_void) -> usize;
    pub fn cgimage_get_height(image: *const c_void) -> usize;
    pub fn cgimage_get_data(
        image: *const c_void,
        out_ptr: *mut *const u8,
        out_length: *mut usize,
    ) -> bool;
    pub fn cgimage_free_data(ptr: *mut u8);
    pub fn cgimage_release(image: *const c_void);
    pub fn cgimage_save_png(image: *const c_void, path: *const i8) -> bool;
    pub fn cgimage_save_to_file(
        image: *const c_void,
        path: *const i8,
        format: i32,
        quality: f32,
    ) -> bool;
}

// MARK: - SCScreenshotConfiguration (macOS 26.0+)
extern "C" {
    pub fn sc_screenshot_configuration_create() -> *const c_void;
    pub fn sc_screenshot_configuration_set_width(config: *const c_void, width: isize);
    pub fn sc_screenshot_configuration_set_height(config: *const c_void, height: isize);
    pub fn sc_screenshot_configuration_set_shows_cursor(config: *const c_void, shows_cursor: bool);
    pub fn sc_screenshot_configuration_set_source_rect(
        config: *const c_void,
        x: f64,
        y: f64,
        width: f64,
        height: f64,
    );
    pub fn sc_screenshot_configuration_set_destination_rect(
        config: *const c_void,
        x: f64,
        y: f64,
        width: f64,
        height: f64,
    );
    pub fn sc_screenshot_configuration_set_ignore_shadows(
        config: *const c_void,
        ignore_shadows: bool,
    );
    pub fn sc_screenshot_configuration_set_ignore_clipping(
        config: *const c_void,
        ignore_clipping: bool,
    );
    pub fn sc_screenshot_configuration_set_include_child_windows(
        config: *const c_void,
        include_child_windows: bool,
    );
    pub fn sc_screenshot_configuration_set_display_intent(
        config: *const c_void,
        display_intent: i32,
    );
    pub fn sc_screenshot_configuration_set_dynamic_range(config: *const c_void, dynamic_range: i32);
    pub fn sc_screenshot_configuration_set_file_url(config: *const c_void, path: *const i8);
    pub fn sc_screenshot_configuration_release(config: *const c_void);

    // Content type support (macOS 26.0+)
    pub fn sc_screenshot_configuration_set_content_type(
        config: *const c_void,
        identifier: *const i8,
    );
    pub fn sc_screenshot_configuration_get_content_type(
        config: *const c_void,
        buffer: *mut i8,
        buffer_size: usize,
    ) -> bool;
    pub fn sc_screenshot_configuration_get_supported_content_types_count() -> usize;
    pub fn sc_screenshot_configuration_get_supported_content_type_at(
        index: usize,
        buffer: *mut i8,
        buffer_size: usize,
    ) -> bool;
}

// MARK: - SCScreenshotOutput (macOS 26.0+)
extern "C" {
    pub fn sc_screenshot_output_get_sdr_image(output: *const c_void) -> *const c_void;
    pub fn sc_screenshot_output_get_hdr_image(output: *const c_void) -> *const c_void;
    pub fn sc_screenshot_output_get_file_url(
        output: *const c_void,
        buffer: *mut i8,
        buffer_size: isize,
    ) -> bool;
    pub fn sc_screenshot_output_release(output: *const c_void);

    pub fn sc_screenshot_manager_capture_screenshot(
        content_filter: *const c_void,
        config: *const c_void,
        callback: extern "C" fn(*const c_void, *const i8, *mut c_void),
        user_data: *mut c_void,
    );
    pub fn sc_screenshot_manager_capture_screenshot_in_rect(
        x: f64,
        y: f64,
        width: f64,
        height: f64,
        config: *const c_void,
        callback: extern "C" fn(*const c_void, *const i8, *mut c_void),
        user_data: *mut c_void,
    );
}

// MARK: - SCStreamConfiguration additional properties
extern "C" {
    // macOS 15.0+ - showMouseClicks
    pub fn sc_stream_configuration_set_shows_mouse_clicks(config: *const c_void, value: bool);
    pub fn sc_stream_configuration_get_shows_mouse_clicks(config: *const c_void) -> bool;

    // macOS 14.0+ - ignoreShadowsDisplay
    pub fn sc_stream_configuration_set_ignores_shadows_display(config: *const c_void, value: bool);
    pub fn sc_stream_configuration_get_ignores_shadows_display(config: *const c_void) -> bool;

    // macOS 14.0+ - ignoreGlobalClipDisplay
    pub fn sc_stream_configuration_set_ignore_global_clip_display(
        config: *const c_void,
        value: bool,
    );
    pub fn sc_stream_configuration_get_ignore_global_clip_display(config: *const c_void) -> bool;

    // macOS 14.0+ - ignoreGlobalClipSingleWindow
    pub fn sc_stream_configuration_set_ignore_global_clip_single_window(
        config: *const c_void,
        value: bool,
    );
    pub fn sc_stream_configuration_get_ignore_global_clip_single_window(
        config: *const c_void,
    ) -> bool;

    // macOS 15.0+ - preset-based configuration
    pub fn sc_stream_configuration_create_with_preset(preset: i32) -> *const c_void;
}

// MARK: - SCContentFilter additional properties
extern "C" {
    // macOS 14.0+ - style and pointPixelScale
    pub fn sc_content_filter_get_style(filter: *const c_void) -> i32;
    pub fn sc_content_filter_get_point_pixel_scale(filter: *const c_void) -> f32;
    pub fn sc_content_filter_get_stream_type(filter: *const c_void) -> i32;

    // macOS 14.2+ - includeMenuBar
    pub fn sc_content_filter_set_include_menu_bar(filter: *const c_void, include: bool);
    pub fn sc_content_filter_get_include_menu_bar(filter: *const c_void) -> bool;

    // macOS 15.2+ - included content arrays
    pub fn sc_content_filter_get_included_displays_count(filter: *const c_void) -> isize;
    pub fn sc_content_filter_get_included_display_at(
        filter: *const c_void,
        index: isize,
    ) -> *const c_void;
    pub fn sc_content_filter_get_included_windows_count(filter: *const c_void) -> isize;
    pub fn sc_content_filter_get_included_window_at(
        filter: *const c_void,
        index: isize,
    ) -> *const c_void;
    pub fn sc_content_filter_get_included_applications_count(filter: *const c_void) -> isize;
    pub fn sc_content_filter_get_included_application_at(
        filter: *const c_void,
        index: isize,
    ) -> *const c_void;
}

// MARK: - SCShareableContentInfo (macOS 14.0+)
extern "C" {
    pub fn sc_shareable_content_info_for_filter(filter: *const c_void) -> *const c_void;
    pub fn sc_shareable_content_info_get_style(info: *const c_void) -> i32;
    pub fn sc_shareable_content_info_get_point_pixel_scale(info: *const c_void) -> f32;
    pub fn sc_shareable_content_info_get_content_rect(
        info: *const c_void,
        x: *mut f64,
        y: *mut f64,
        width: *mut f64,
        height: *mut f64,
    );
    /// Get shareable content info rect (same as `sc_shareable_content_info_get_content_rect`)
    pub fn sc_shareable_content_info_get_content_rect_packed(
        info: *const c_void,
        x: *mut f64,
        y: *mut f64,
        width: *mut f64,
        height: *mut f64,
    );
    pub fn sc_shareable_content_info_retain(info: *const c_void) -> *const c_void;
    pub fn sc_shareable_content_info_release(info: *const c_void);
}

// MARK: - SCRecordingOutput additional (macOS 15.0+)
extern "C" {
    pub fn sc_recording_output_configuration_set_output_file_type(
        config: *const c_void,
        file_type: i32,
    );
    pub fn sc_recording_output_configuration_get_output_file_type(config: *const c_void) -> i32;
    pub fn sc_recording_output_configuration_get_video_codec(config: *const c_void) -> i32;
    pub fn sc_recording_output_configuration_get_available_video_codecs_count(
        config: *const c_void,
    ) -> isize;
    pub fn sc_recording_output_configuration_get_available_video_codec_at(
        config: *const c_void,
        index: isize,
    ) -> i32;
    pub fn sc_recording_output_configuration_get_available_output_file_types_count(
        config: *const c_void,
    ) -> isize;
    pub fn sc_recording_output_configuration_get_available_output_file_type_at(
        config: *const c_void,
        index: isize,
    ) -> i32;
    pub fn sc_recording_output_create_with_delegate(
        config: *const c_void,
        started_callback: Option<extern "C" fn(*mut c_void)>,
        failed_callback: Option<extern "C" fn(*mut c_void, i32, *const i8)>,
        finished_callback: Option<extern "C" fn(*mut c_void)>,
        context: *mut c_void,
    ) -> *const c_void;
    pub fn sc_recording_output_get_recorded_duration(
        output: *const c_void,
        value: *mut i64,
        timescale: *mut i32,
    );
    pub fn sc_recording_output_get_recorded_file_size(output: *const c_void) -> i64;
}

// MARK: - Audio Input Devices (AVFoundation)
extern "C" {
    /// Get the count of available audio input devices
    pub fn sc_audio_get_input_device_count() -> isize;

    /// Get audio input device ID at index into buffer
    pub fn sc_audio_get_input_device_id(index: isize, buffer: *mut i8, buffer_size: isize) -> bool;

    /// Get audio input device name at index into buffer
    pub fn sc_audio_get_input_device_name(
        index: isize,
        buffer: *mut i8,
        buffer_size: isize,
    ) -> bool;

    /// Check if the device at index is the default audio input device
    pub fn sc_audio_is_default_input_device(index: isize) -> bool;

    /// Get the default audio input device ID into buffer
    pub fn sc_audio_get_default_input_device_id(buffer: *mut i8, buffer_size: isize) -> bool;

    /// Get the default audio input device name into buffer
    pub fn sc_audio_get_default_input_device_name(buffer: *mut i8, buffer_size: isize) -> bool;
}