Skip to content

Commit eb26de3

Browse files
committed
generate the module declaration macro with a version number
1 parent e27c310 commit eb26de3

File tree

5 files changed

+66
-49
lines changed

5 files changed

+66
-49
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ src/ffi/demux.rs
66
src/ffi/es.rs
77
src/ffi/plugin.rs
88
src/ffi/stream.rs
9+
src/ffi/es_out.rs
10+
src/macros.rs

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ This work was extracted from https://github.com/Geal/rust-vlc-demux to provide g
55
It provides some of the struct definitions, some of the functions exported by libVLCCore, and macros to declare a module and call `vlc_Log`.
66

77
it currently requires the content of the `vlc/include` directory available at `include/`
8+
environment variable requirements:
9+
10+
- INCLUDE_DIR points to the VLC include directory
11+
- VLC_VERSION is the version number used for entry points. Set VLC_VERSION=3_0_0a for a vlc_entry__3_0_0a

build.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
extern crate libbindgen;
2+
use std::fs::File;
3+
use std::io::Write;
4+
use std::path::Path;
25

36
fn main() {
47
//look for libvlccore in the current directory while in development
@@ -88,4 +91,58 @@ fn main() {
8891
.use_core()
8992
.generate().unwrap()
9093
.write_to_file("src/ffi/es_out.rs");
94+
95+
let dest_path = Path::new("src/macros.rs");
96+
let mut f = File::create(&dest_path).unwrap();
97+
98+
let macros = concat!("#[macro_export]
99+
macro_rules! vlc_module {
100+
(set_name($name:expr) set_description($desc:expr) set_capability($cap:expr, $score:expr) set_callbacks($open:expr, $close:expr)) => (
101+
#[allow(non_snake_case)]
102+
#[no_mangle]
103+
pub unsafe extern fn vlc_entry__", env!("VLC_VERSION"), "(vlc_set: unsafe extern fn(*mut c_void, *mut c_void, c_int, ...)
104+
-> c_int,
105+
opaque: *mut c_void) -> c_int {
106+
let module: *mut c_void = 0 as *mut c_void;
107+
108+
if vlc_set(opaque, 0 as *mut c_void, $crate::vlc::vlc_module_properties::VLC_MODULE_CREATE as i32,
109+
&module) != 0 {
110+
return -1;
111+
}
112+
113+
if vlc_set(opaque, module, $crate::vlc::vlc_module_properties::VLC_MODULE_NAME as i32,
114+
concat!($name, \"\\0\").as_ptr()) != 0 {
115+
return -1;
116+
}
117+
118+
if vlc_set(opaque, module, $crate::vlc::vlc_module_properties::VLC_MODULE_DESCRIPTION as i32,
119+
concat!($desc, \"\\0\").as_ptr()) != 0 {
120+
return -1;
121+
}
122+
123+
if vlc_set(opaque, module, $crate::vlc::vlc_module_properties::VLC_MODULE_CAPABILITY as i32,
124+
concat!($cap, \"\\0\").as_ptr()) != 0 {
125+
return -1;
126+
}
127+
128+
if vlc_set(opaque, module, $crate::vlc::vlc_module_properties::VLC_MODULE_SCORE as i32, $score) != 0 {
129+
return -1;
130+
}
131+
132+
let p_open: extern \"C\" fn(*mut demux_t<demux_sys_t>) -> c_int =
133+
transmute($open as extern \"C\" fn(_) -> c_int);
134+
if vlc_set(opaque, module, $crate::vlc::vlc_module_properties::VLC_MODULE_CB_OPEN as i32, p_open) != 0 {
135+
return -1;
136+
}
137+
138+
let p_close: extern \"C\" fn(*mut demux_t<demux_sys_t>) = transmute($close as extern \"C\" fn(_));
139+
if vlc_set(opaque, module, $crate::vlc::vlc_module_properties::VLC_MODULE_CB_CLOSE as i32, p_close) != 0 {
140+
return -1;
141+
}
142+
0
143+
}
144+
);
145+
}
146+
");
147+
f.write_all(macros.as_bytes()).unwrap();
91148
}

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
extern crate libc;
44
extern crate core;
55

6+
#[macro_use]
7+
pub mod macros;
8+
69
#[macro_use]
710
pub mod vlc;
811

src/vlc.rs

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,55 +10,6 @@ use ffi::{self, stream_t, es_format_category_e};
1010

1111
pub const VLC_TS_0: mtime_t = 1;
1212

13-
#[macro_export]
14-
macro_rules! vlc_module {
15-
($fn_name:ident, set_name($name:expr) set_description($desc:expr) set_capability($cap:expr, $score:expr) set_callbacks($open:expr, $close:expr)) => (
16-
#[allow(non_snake_case)]
17-
#[no_mangle]
18-
pub unsafe extern fn $fn_name(vlc_set: unsafe extern fn(*mut c_void, *mut c_void, c_int, ...)
19-
-> c_int,
20-
opaque: *mut c_void) -> c_int {
21-
let module: *mut c_void = 0 as *mut c_void;
22-
23-
if vlc_set(opaque, 0 as *mut c_void, $crate::vlc::vlc_module_properties::VLC_MODULE_CREATE as i32,
24-
&module) != 0 {
25-
return -1;
26-
}
27-
28-
if vlc_set(opaque, module, $crate::vlc::vlc_module_properties::VLC_MODULE_NAME as i32,
29-
concat!($name, "\0").as_ptr()) != 0 {
30-
return -1;
31-
}
32-
33-
if vlc_set(opaque, module, $crate::vlc::vlc_module_properties::VLC_MODULE_DESCRIPTION as i32,
34-
concat!($desc, "\0").as_ptr()) != 0 {
35-
return -1;
36-
}
37-
38-
if vlc_set(opaque, module, $crate::vlc::vlc_module_properties::VLC_MODULE_CAPABILITY as i32,
39-
concat!($cap, "\0").as_ptr()) != 0 {
40-
return -1;
41-
}
42-
43-
if vlc_set(opaque, module, $crate::vlc::vlc_module_properties::VLC_MODULE_SCORE as i32, $score) != 0 {
44-
return -1;
45-
}
46-
47-
let p_open: extern "C" fn(*mut demux_t<demux_sys_t>) -> c_int =
48-
transmute($open as extern "C" fn(_) -> c_int);
49-
if vlc_set(opaque, module, $crate::vlc::vlc_module_properties::VLC_MODULE_CB_OPEN as i32, p_open) != 0 {
50-
return -1;
51-
}
52-
53-
let p_close: extern "C" fn(*mut demux_t<demux_sys_t>) = transmute($close as extern "C" fn(_));
54-
if vlc_set(opaque, module, $crate::vlc::vlc_module_properties::VLC_MODULE_CB_CLOSE as i32, p_close) != 0 {
55-
return -1;
56-
}
57-
0
58-
}
59-
);
60-
}
61-
6213
#[macro_export]
6314
macro_rules! vlc_fourcc (
6415
($a: expr, $b: expr, $c: expr, $d: expr) => {

0 commit comments

Comments
 (0)