Skip to main content

mediasoup_sys/
lib.rs

1use std::os::raw::{c_char, c_int, c_void};
2
3pub use planus_codegen::*;
4
5mod planus_codegen {
6    #![allow(clippy::all)]
7    include!(concat!(env!("OUT_DIR"), "/fbs.rs"));
8}
9
10#[repr(transparent)]
11#[derive(Copy, Clone)]
12pub struct UvAsyncT(pub *const c_void);
13
14unsafe impl Send for UvAsyncT {}
15
16#[repr(transparent)]
17pub struct ChannelReadCtx(pub *const c_void);
18pub type ChannelReadFreeFn = Option<
19    unsafe extern "C" fn(
20        /* message: */ *mut u8,
21        /* message_len: */ u32,
22        /* message_ctx: */ usize,
23    ),
24>;
25pub type ChannelReadFn = unsafe extern "C" fn(
26    /* message: */ *mut *mut u8,
27    /* message_len: */ *mut u32,
28    /* message_ctx: */ *mut usize,
29    // This is `uv_async_t` handle that can be called later with `uv_async_send()` when there is
30    // more data to read
31    /* handle */
32    UvAsyncT,
33    /* ctx: */ ChannelReadCtx,
34) -> ChannelReadFreeFn;
35
36unsafe impl Send for ChannelReadCtx {}
37
38#[repr(transparent)]
39pub struct ChannelWriteCtx(pub *const c_void);
40pub type ChannelWriteFn = unsafe extern "C" fn(
41    /* message: */ *const u8,
42    /* message_len: */ u32,
43    /* ctx: */ ChannelWriteCtx,
44);
45
46unsafe impl Send for ChannelWriteCtx {}
47
48#[link(name = "mediasoup-worker", kind = "static")]
49extern "C" {
50    /// Returns `0` on success, or an error code `< 0` on failure
51    pub fn uv_async_send(handle: UvAsyncT) -> c_int;
52
53    pub fn mediasoup_worker_run(
54        argc: c_int,
55        argv: *const *const c_char,
56        version: *const c_char,
57        consumer_channel_fd: c_int,
58        producer_channel_fd: c_int,
59        channel_read_fn: ChannelReadFn,
60        channel_read_ctx: ChannelReadCtx,
61        channel_write_fn: ChannelWriteFn,
62        channel_write_ctx: ChannelWriteCtx,
63    ) -> c_int;
64}