gst-plugin-ndi 0.15.2

GStreamer NewTek NDI Plugin
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
// SPDX-License-Identifier: MPL-2.0

#![allow(
    non_camel_case_types,
    non_upper_case_globals,
    non_snake_case,
    clippy::upper_case_acronyms,
    clippy::missing_safety_doc
)]

use std::sync::{LazyLock, OnceLock};

#[cfg(unix)]
use libloading::os::unix::{Library, Symbol};
#[cfg(windows)]
use libloading::os::windows::{Library, Symbol};

#[cfg(all(target_arch = "x86_64", target_os = "windows"))]
const LIBRARY_NAMES: &[&str] = &["Processing.NDI.Lib.x64.dll"];
#[cfg(all(target_arch = "x86", target_os = "windows"))]
const LIBRARY_NAMES: &[&str] = &["Processing.NDI.Lib.x86.dll"];
#[cfg(target_os = "linux")]
const LIBRARY_NAMES: &[&str] = &["libndi.so.6", "libndi.so.5"];
#[cfg(target_os = "macos")]
const LIBRARY_NAMES: &[&str] = &["libndi.dylib"];
#[cfg(all(unix, not(any(target_os = "linux", target_os = "macos"))))]
const LIBRARY_NAMES: &[&str] = &["libndi.so"];

#[allow(clippy::type_complexity)]
struct FFI {
    _library: Library,
    initialize: Symbol<fn() -> bool>,
    destroy: Symbol<fn()>,
    find_create_v2:
        Symbol<fn(p_create_settings: *const NDIlib_find_create_t) -> NDIlib_find_instance_t>,
    find_destroy: Symbol<fn(p_instance: NDIlib_find_instance_t)>,
    find_wait_for_sources:
        Symbol<fn(p_instance: NDIlib_find_instance_t, timeout_in_ms: u32) -> bool>,
    find_get_current_sources: Symbol<
        fn(p_instance: NDIlib_find_instance_t, p_no_sources: *mut u32) -> *const NDIlib_source_t,
    >,
    recv_create_v3:
        Symbol<fn(p_create_settings: *const NDIlib_recv_create_v3_t) -> NDIlib_recv_instance_t>,
    recv_destroy: Symbol<fn(p_instance: NDIlib_recv_instance_t)>,
    recv_set_tally:
        Symbol<fn(p_instance: NDIlib_recv_instance_t, p_tally: *const NDIlib_tally_t) -> bool>,
    recv_send_metadata: Symbol<
        fn(p_instance: NDIlib_recv_instance_t, p_metadata: *const NDIlib_metadata_frame_t) -> bool,
    >,
    recv_capture_v3: Symbol<
        fn(
            p_instance: NDIlib_recv_instance_t,
            p_video_data: *mut NDIlib_video_frame_v2_t,
            p_audio_data: *mut NDIlib_audio_frame_v3_t,
            p_metadata: *mut NDIlib_metadata_frame_t,
            timeout_in_ms: u32,
        ) -> NDIlib_frame_type_e,
    >,
    recv_free_video_v2:
        Symbol<fn(p_instance: NDIlib_recv_instance_t, p_video_data: *mut NDIlib_video_frame_v2_t)>,
    recv_free_audio_v3:
        Symbol<fn(p_instance: NDIlib_recv_instance_t, p_audio_data: *mut NDIlib_audio_frame_v3_t)>,
    recv_free_metadata:
        Symbol<fn(p_instance: NDIlib_recv_instance_t, p_metadata: *mut NDIlib_metadata_frame_t)>,
    recv_get_queue:
        Symbol<fn(p_instance: NDIlib_recv_instance_t, p_total: *mut NDIlib_recv_queue_t)>,
    send_create:
        Symbol<fn(p_create_settings: *const NDIlib_send_create_t) -> NDIlib_send_instance_t>,
    send_destroy: Symbol<fn(p_instance: NDIlib_send_instance_t)>,
    send_send_video_v2: Symbol<
        fn(p_instance: NDIlib_send_instance_t, p_video_data: *const NDIlib_video_frame_v2_t),
    >,
    send_send_audio_v3: Symbol<
        fn(p_instance: NDIlib_send_instance_t, p_audio_data: *const NDIlib_audio_frame_v3_t),
    >,
    send_send_metadata:
        Symbol<fn(p_instance: NDIlib_send_instance_t, p_metadata: *const NDIlib_metadata_frame_t)>,
}

pub type NDIlib_find_instance_t = *mut ::std::ffi::c_void;

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct NDIlib_find_create_t {
    pub show_local_sources: bool,
    pub p_groups: *const ::std::ffi::c_char,
    pub p_extra_ips: *const ::std::ffi::c_char,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct NDIlib_source_t {
    pub p_ndi_name: *const ::std::ffi::c_char,
    pub p_url_address: *const ::std::ffi::c_char,
}

#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum NDIlib_frame_type_e {
    NDIlib_frame_type_none = 0,
    NDIlib_frame_type_video = 1,
    NDIlib_frame_type_audio = 2,
    NDIlib_frame_type_metadata = 3,
    NDIlib_frame_type_error = 4,
    NDIlib_frame_type_status_change = 100,
}

pub type NDIlib_recv_bandwidth_e = i32;

pub const NDIlib_recv_bandwidth_metadata_only: NDIlib_recv_bandwidth_e = -10;
pub const NDIlib_recv_bandwidth_audio_only: NDIlib_recv_bandwidth_e = 10;
pub const NDIlib_recv_bandwidth_lowest: NDIlib_recv_bandwidth_e = 0;
pub const NDIlib_recv_bandwidth_highest: NDIlib_recv_bandwidth_e = 100;

pub type NDIlib_recv_color_format_e = u32;
pub const NDIlib_recv_color_format_BGRX_BGRA: NDIlib_recv_color_format_e = 0;
pub const NDIlib_recv_color_format_UYVY_BGRA: NDIlib_recv_color_format_e = 1;
pub const NDIlib_recv_color_format_RGBX_RGBA: NDIlib_recv_color_format_e = 2;
pub const NDIlib_recv_color_format_UYVY_RGBA: NDIlib_recv_color_format_e = 3;
pub const NDIlib_recv_color_format_fastest: NDIlib_recv_color_format_e = 100;
pub const NDIlib_recv_color_format_best: NDIlib_recv_color_format_e = 101;
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_recv_color_format_ex_compressed: NDIlib_recv_color_format_e = 300;
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_recv_color_format_ex_compressed_v2: NDIlib_recv_color_format_e = 301;
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_recv_color_format_ex_compressed_v3: NDIlib_recv_color_format_e = 302;
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_recv_color_format_ex_compressed_v3_with_audio: NDIlib_recv_color_format_e = 304;
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_recv_color_format_ex_compressed_v4: NDIlib_recv_color_format_e = 303;
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_recv_color_format_ex_compressed_v4_with_audio: NDIlib_recv_color_format_e = 305;
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_recv_color_format_ex_compressed_v5: NDIlib_recv_color_format_e = 307;
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_recv_color_format_ex_compressed_v5_with_audio: NDIlib_recv_color_format_e = 308;

const fn make_fourcc(fourcc: &[u8; 4]) -> u32 {
    (fourcc[0] as u32)
        | ((fourcc[1] as u32) << 8)
        | ((fourcc[2] as u32) << 16)
        | ((fourcc[3] as u32) << 24)
}

pub type NDIlib_FourCC_video_type_e = u32;
pub const NDIlib_FourCC_video_type_UYVY: NDIlib_FourCC_video_type_e = make_fourcc(b"UYVY");
pub const NDIlib_FourCC_video_type_UYVA: NDIlib_FourCC_video_type_e = make_fourcc(b"UYVA");
pub const NDIlib_FourCC_video_type_P216: NDIlib_FourCC_video_type_e = make_fourcc(b"P216");
pub const NDIlib_FourCC_video_type_PA16: NDIlib_FourCC_video_type_e = make_fourcc(b"PA16");
pub const NDIlib_FourCC_video_type_YV12: NDIlib_FourCC_video_type_e = make_fourcc(b"YV12");
pub const NDIlib_FourCC_video_type_I420: NDIlib_FourCC_video_type_e = make_fourcc(b"I420");
pub const NDIlib_FourCC_video_type_NV12: NDIlib_FourCC_video_type_e = make_fourcc(b"NV12");
pub const NDIlib_FourCC_video_type_BGRA: NDIlib_FourCC_video_type_e = make_fourcc(b"BGRA");
pub const NDIlib_FourCC_video_type_BGRX: NDIlib_FourCC_video_type_e = make_fourcc(b"BGRX");
pub const NDIlib_FourCC_video_type_RGBA: NDIlib_FourCC_video_type_e = make_fourcc(b"RGBA");
pub const NDIlib_FourCC_video_type_RGBX: NDIlib_FourCC_video_type_e = make_fourcc(b"RGBX");

#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_video_type_ex_SHQ0_highest_bandwidth: NDIlib_FourCC_video_type_e =
    make_fourcc(b"SHQ0");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_video_type_ex_SHQ2_highest_bandwidth: NDIlib_FourCC_video_type_e =
    make_fourcc(b"SHQ2");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_video_type_ex_SHQ7_highest_bandwidth: NDIlib_FourCC_video_type_e =
    make_fourcc(b"SHQ7");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_video_type_ex_SHQ0_lowest_bandwidth: NDIlib_FourCC_video_type_e =
    make_fourcc(b"shq0");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_video_type_ex_SHQ2_lowest_bandwidth: NDIlib_FourCC_video_type_e =
    make_fourcc(b"shq2");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_video_type_ex_SHQ7_lowest_bandwidth: NDIlib_FourCC_video_type_e =
    make_fourcc(b"shq7");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_video_type_ex_H264_highest_bandwidth: NDIlib_FourCC_video_type_e =
    make_fourcc(b"H264");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_video_type_ex_H264_lowest_bandwidth: NDIlib_FourCC_video_type_e =
    make_fourcc(b"h264");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_video_type_ex_HEVC_highest_bandwidth: NDIlib_FourCC_video_type_e =
    make_fourcc(b"HEVC");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_video_type_ex_HEVC_lowest_bandwidth: NDIlib_FourCC_video_type_e =
    make_fourcc(b"hevc");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_video_type_ex_H264_alpha_highest_bandwidth: NDIlib_FourCC_video_type_e =
    make_fourcc(b"A264");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_video_type_ex_H264_alpha_lowest_bandwidth: NDIlib_FourCC_video_type_e =
    make_fourcc(b"a264");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_video_type_ex_HEVC_alpha_highest_bandwidth: NDIlib_FourCC_video_type_e =
    make_fourcc(b"AEVC");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_video_type_ex_HEVC_alpha_lowest_bandwidth: NDIlib_FourCC_video_type_e =
    make_fourcc(b"aevc");

pub type NDIlib_FourCC_audio_type_e = u32;
pub const NDIlib_FourCC_audio_type_FLTp: NDIlib_FourCC_video_type_e = make_fourcc(b"FLTp");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_audio_type_AAC: NDIlib_FourCC_audio_type_e = 0x000000ff;
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_FourCC_audio_type_Opus: NDIlib_FourCC_audio_type_e = make_fourcc(b"Opus");

#[cfg(feature = "advanced-sdk")]
pub type NDIlib_compressed_FourCC_type_e = u32;
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_compressed_FourCC_type_H264: NDIlib_compressed_FourCC_type_e =
    make_fourcc(b"H264");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_compressed_FourCC_type_HEVC: NDIlib_compressed_FourCC_type_e =
    make_fourcc(b"HEVC");
#[cfg(feature = "advanced-sdk")]
pub const NDIlib_compressed_FourCC_type_AAC: NDIlib_compressed_FourCC_type_e = 0x000000ff;

#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum NDIlib_frame_format_type_e {
    NDIlib_frame_format_type_progressive = 1,
    NDIlib_frame_format_type_interleaved = 0,
    NDIlib_frame_format_type_field_0 = 2,
    NDIlib_frame_format_type_field_1 = 3,
}

pub const NDIlib_send_timecode_synthesize: i64 = i64::MAX;
pub const NDIlib_recv_timestamp_undefined: i64 = i64::MAX;

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct NDIlib_recv_create_v3_t {
    pub source_to_connect_to: NDIlib_source_t,
    pub color_format: NDIlib_recv_color_format_e,
    pub bandwidth: NDIlib_recv_bandwidth_e,
    pub allow_video_fields: bool,
    pub p_ndi_recv_name: *const ::std::ffi::c_char,
}

pub type NDIlib_recv_instance_t = *mut ::std::ffi::c_void;

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct NDIlib_send_create_t {
    pub p_ndi_name: *const ::std::ffi::c_char,
    pub p_groups: *const ::std::ffi::c_char,
    pub clock_video: bool,
    pub clock_audio: bool,
}

pub type NDIlib_send_instance_t = *mut ::std::ffi::c_void;

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct NDIlib_tally_t {
    pub on_program: bool,
    pub on_preview: bool,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct NDIlib_recv_queue_t {
    pub video_frames: i32,
    pub audio_frames: i32,
    pub metadata_frames: i32,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct NDIlib_metadata_frame_t {
    pub length: ::std::ffi::c_int,
    pub timecode: i64,
    pub p_data: *const ::std::ffi::c_char,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct NDIlib_video_frame_v2_t {
    pub xres: ::std::ffi::c_int,
    pub yres: ::std::ffi::c_int,
    pub FourCC: NDIlib_FourCC_video_type_e,
    pub frame_rate_N: ::std::ffi::c_int,
    pub frame_rate_D: ::std::ffi::c_int,
    pub picture_aspect_ratio: ::std::ffi::c_float,
    pub frame_format_type: NDIlib_frame_format_type_e,
    pub timecode: i64,
    pub p_data: *const ::std::ffi::c_char,
    pub line_stride_or_data_size_in_bytes: ::std::ffi::c_int,
    pub p_metadata: *const ::std::ffi::c_char,
    pub timestamp: i64,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct NDIlib_audio_frame_v3_t {
    pub sample_rate: ::std::ffi::c_int,
    pub no_channels: ::std::ffi::c_int,
    pub no_samples: ::std::ffi::c_int,
    pub timecode: i64,
    pub FourCC: NDIlib_FourCC_audio_type_e,
    pub p_data: *const ::std::ffi::c_float,
    pub channel_stride_or_data_size_in_bytes: ::std::ffi::c_int,
    pub p_metadata: *const ::std::ffi::c_char,
    pub timestamp: i64,
}

#[cfg(feature = "advanced-sdk")]
#[repr(C, packed)]
#[derive(Debug, Copy, Clone)]
pub struct NDIlib_compressed_packet_t {
    pub version: u32,
    pub fourcc: NDIlib_compressed_FourCC_type_e,
    pub pts: i64,
    pub dts: i64,
    pub reserved: u64,
    pub flags: u32,
    pub data_size: u32,
    pub extra_data_size: u32,
}

#[cfg(feature = "advanced-sdk")]
pub const NDIlib_compressed_packet_flags_keyframe: u32 = 1;

#[cfg(feature = "advanced-sdk")]
pub const NDIlib_compressed_packet_version_0: u32 = 44;

static CAT: LazyLock<gst::DebugCategory> = LazyLock::new(|| {
    gst::DebugCategory::new("ndi", gst::DebugColorFlags::empty(), Some("NewTek NDI"))
});

static FFI: OnceLock<FFI> = OnceLock::new();

pub fn load() -> Result<(), glib::BoolError> {
    static ERR: OnceLock<Result<(), glib::BoolError>> = OnceLock::new();

    ERR.get_or_init(|| unsafe {
        use std::env;
        use std::path;

        const ENV_VARS: &[&str] = &["NDI_RUNTIME_DIR_V6", "NDI_RUNTIME_DIR_V5", ""];

        let mut library = None;
        'outer_loop: for env_var in ENV_VARS {
            let library_directory = if !env_var.is_empty() {
                let Some(library_directory) = env::var_os(env_var) else {
                    continue;
                };
                Some(library_directory)
            } else {
                None
            };

            for library_name in LIBRARY_NAMES {
                let library_path = if let Some(ref library_directory) = library_directory {
                    let mut path = path::PathBuf::from(library_directory);
                    path.push(library_name);
                    path
                } else {
                    path::PathBuf::from(library_name)
                };

                match Library::new(&library_path) {
                    Ok(lib) => {
                        gst::log!(CAT, "Loaded NDI SDK from {}", library_path.display());
                        library = Some(lib);
                        break 'outer_loop;
                    }
                    Err(err) => {
                        gst::log!(
                            CAT,
                            "Failed loading NDI SDK from {}: {err}",
                            library_path.display()
                        );
                        continue;
                    }
                }
            }
        }

        let library = library.ok_or_else(|| glib::bool_error!("Failed loading NDI SDK"))?;

        macro_rules! load_symbol {
            ($name:ident) => {{
                #[cfg(unix)]
                {
                    library
                        .get_singlethreaded(stringify!($name).as_bytes())
                        .map_err(|err| {
                            glib::bool_error!(
                                concat!(
                                    "Failed to load function '",
                                    stringify!($name),
                                    "' from NDI SDK: {}"
                                ),
                                err
                            )
                        })?
                }
                #[cfg(windows)]
                {
                    library.get(stringify!($name).as_bytes()).map_err(|err| {
                        glib::bool_error!(
                            concat!(
                                "Failed to load function '",
                                stringify!($name),
                                "' from NDI SDK: {}"
                            ),
                            err
                        )
                    })?
                }
            }};
        }

        let ffi = FFI {
            initialize: load_symbol!(NDIlib_initialize),
            destroy: load_symbol!(NDIlib_destroy),
            find_create_v2: load_symbol!(NDIlib_find_create_v2),
            find_destroy: load_symbol!(NDIlib_find_destroy),
            find_wait_for_sources: load_symbol!(NDIlib_find_wait_for_sources),
            find_get_current_sources: load_symbol!(NDIlib_find_get_current_sources),
            recv_create_v3: load_symbol!(NDIlib_recv_create_v3),
            recv_destroy: load_symbol!(NDIlib_recv_destroy),
            recv_set_tally: load_symbol!(NDIlib_recv_set_tally),
            recv_send_metadata: load_symbol!(NDIlib_recv_send_metadata),
            recv_capture_v3: load_symbol!(NDIlib_recv_capture_v3),
            recv_free_video_v2: load_symbol!(NDIlib_recv_free_video_v2),
            recv_free_audio_v3: load_symbol!(NDIlib_recv_free_audio_v3),
            recv_free_metadata: load_symbol!(NDIlib_recv_free_metadata),
            recv_get_queue: load_symbol!(NDIlib_recv_get_queue),
            send_create: load_symbol!(NDIlib_send_create),
            send_destroy: load_symbol!(NDIlib_send_destroy),
            send_send_video_v2: load_symbol!(NDIlib_send_send_video_v2),
            send_send_audio_v3: load_symbol!(NDIlib_send_send_audio_v3),
            send_send_metadata: load_symbol!(NDIlib_send_send_metadata),
            _library: library,
        };

        if FFI.set(ffi).is_err() {
            unreachable!("NDI SDK loaded twice");
        }

        Ok(())
    })
    .to_owned()
}

pub unsafe fn NDIlib_initialize() -> bool {
    unsafe { (FFI.get().unwrap_unchecked().initialize)() }
}

pub unsafe fn NDIlib_destroy() {
    unsafe { (FFI.get().unwrap_unchecked().destroy)() }
}

pub unsafe fn NDIlib_find_create_v2(
    p_create_settings: *const NDIlib_find_create_t,
) -> NDIlib_find_instance_t {
    unsafe { (FFI.get().unwrap_unchecked().find_create_v2)(p_create_settings) }
}
pub unsafe fn NDIlib_find_destroy(p_instance: NDIlib_find_instance_t) {
    unsafe { (FFI.get().unwrap_unchecked().find_destroy)(p_instance) }
}

pub unsafe fn NDIlib_find_wait_for_sources(
    p_instance: NDIlib_find_instance_t,
    timeout_in_ms: u32,
) -> bool {
    unsafe { (FFI.get().unwrap_unchecked().find_wait_for_sources)(p_instance, timeout_in_ms) }
}

pub unsafe fn NDIlib_find_get_current_sources(
    p_instance: NDIlib_find_instance_t,
    p_no_sources: *mut u32,
) -> *const NDIlib_source_t {
    unsafe { (FFI.get().unwrap_unchecked().find_get_current_sources)(p_instance, p_no_sources) }
}

pub unsafe fn NDIlib_recv_create_v3(
    p_create_settings: *const NDIlib_recv_create_v3_t,
) -> NDIlib_recv_instance_t {
    unsafe { (FFI.get().unwrap_unchecked().recv_create_v3)(p_create_settings) }
}

pub unsafe fn NDIlib_recv_destroy(p_instance: NDIlib_recv_instance_t) {
    unsafe { (FFI.get().unwrap_unchecked().recv_destroy)(p_instance) }
}

pub unsafe fn NDIlib_recv_set_tally(
    p_instance: NDIlib_recv_instance_t,
    p_tally: *const NDIlib_tally_t,
) -> bool {
    unsafe { (FFI.get().unwrap_unchecked().recv_set_tally)(p_instance, p_tally) }
}

pub unsafe fn NDIlib_recv_send_metadata(
    p_instance: NDIlib_recv_instance_t,
    p_metadata: *const NDIlib_metadata_frame_t,
) -> bool {
    unsafe { (FFI.get().unwrap_unchecked().recv_send_metadata)(p_instance, p_metadata) }
}

pub unsafe fn NDIlib_recv_capture_v3(
    p_instance: NDIlib_recv_instance_t,
    p_video_data: *mut NDIlib_video_frame_v2_t,
    p_audio_data: *mut NDIlib_audio_frame_v3_t,
    p_metadata: *mut NDIlib_metadata_frame_t,
    timeout_in_ms: u32,
) -> NDIlib_frame_type_e {
    unsafe {
        (FFI.get().unwrap_unchecked().recv_capture_v3)(
            p_instance,
            p_video_data,
            p_audio_data,
            p_metadata,
            timeout_in_ms,
        )
    }
}

pub unsafe fn NDIlib_recv_free_video_v2(
    p_instance: NDIlib_recv_instance_t,
    p_video_data: *mut NDIlib_video_frame_v2_t,
) {
    unsafe { (FFI.get().unwrap_unchecked().recv_free_video_v2)(p_instance, p_video_data) }
}

pub unsafe fn NDIlib_recv_free_audio_v3(
    p_instance: NDIlib_recv_instance_t,
    p_audio_data: *mut NDIlib_audio_frame_v3_t,
) {
    unsafe { (FFI.get().unwrap_unchecked().recv_free_audio_v3)(p_instance, p_audio_data) }
}

pub unsafe fn NDIlib_recv_free_metadata(
    p_instance: NDIlib_recv_instance_t,
    p_metadata: *mut NDIlib_metadata_frame_t,
) {
    unsafe { (FFI.get().unwrap_unchecked().recv_free_metadata)(p_instance, p_metadata) }
}

pub unsafe fn NDIlib_recv_get_queue(
    p_instance: NDIlib_recv_instance_t,
    p_total: *mut NDIlib_recv_queue_t,
) {
    unsafe { (FFI.get().unwrap_unchecked().recv_get_queue)(p_instance, p_total) }
}

pub unsafe fn NDIlib_send_create(
    p_create_settings: *const NDIlib_send_create_t,
) -> NDIlib_send_instance_t {
    unsafe { (FFI.get().unwrap_unchecked().send_create)(p_create_settings) }
}

pub unsafe fn NDIlib_send_destroy(p_instance: NDIlib_send_instance_t) {
    unsafe { (FFI.get().unwrap_unchecked().send_destroy)(p_instance) }
}

pub unsafe fn NDIlib_send_send_video_v2(
    p_instance: NDIlib_send_instance_t,
    p_video_data: *const NDIlib_video_frame_v2_t,
) {
    unsafe { (FFI.get().unwrap_unchecked().send_send_video_v2)(p_instance, p_video_data) }
}

pub unsafe fn NDIlib_send_send_audio_v3(
    p_instance: NDIlib_send_instance_t,
    p_audio_data: *const NDIlib_audio_frame_v3_t,
) {
    unsafe { (FFI.get().unwrap_unchecked().send_send_audio_v3)(p_instance, p_audio_data) }
}

pub unsafe fn NDIlib_send_send_metadata(
    p_instance: NDIlib_send_instance_t,
    p_metadata: *const NDIlib_metadata_frame_t,
) {
    unsafe { (FFI.get().unwrap_unchecked().send_send_metadata)(p_instance, p_metadata) }
}