1use std::mem::MaybeUninit;
15use std::os::raw::{c_long, c_void};
16
17include!(concat!(env!("OUT_DIR"), "/tsduck_version.rs"));
18
19pub type LogCallback = unsafe extern "C" fn(severity: i32, message: *const u8, size: usize);
21
22pub type PluginCallback = unsafe extern "C" fn(
24 event_code: u32,
25 plugin_name: *const u8,
26 plugin_name_size: usize,
27 plugin_index: usize,
28 plugin_count: usize,
29 bitrate: usize,
30 plugin_packets: usize,
31 total_packets: usize,
32 data: *const u8,
33 data_size: usize,
34 data_max_size: usize,
35 data_read_only: bool,
36 event_data: *mut c_void,
37) -> bool;
38
39#[repr(C)]
44#[derive(Debug, Clone, Copy, PartialEq, Eq)]
45pub struct TspyAbiLayout {
46 pub tsduck_header_version_major: u32,
48 pub tsduck_header_version_minor: u32,
50 pub ts_processor_args_size: usize,
52 pub ts_processor_args_align: usize,
54 pub ts_processor_args_offsets: [usize; 16],
56 pub input_switcher_args_size: usize,
58 pub input_switcher_args_align: usize,
60 pub input_switcher_args_offsets: [usize; 23],
62 pub uint32_size: usize,
64 pub uint32_align: usize,
66 pub size_t_size: usize,
68 pub size_t_align: usize,
70 pub bool_size: usize,
72 pub bool_align: usize,
74 pub long_size: usize,
76 pub long_align: usize,
78}
79
80#[must_use]
82pub fn tspy_abi_layout() -> TspyAbiLayout {
83 let mut layout = MaybeUninit::<TspyAbiLayout>::uninit();
84
85 unsafe {
88 rustduck_tspy_query_abi_layout(layout.as_mut_ptr());
89 layout.assume_init()
90 }
91}
92
93#[repr(C)]
95#[derive(Debug, Clone, Copy)]
96pub struct TSProcessorArgs {
97 pub ignore_joint_termination: c_long,
98 pub buffer_size: c_long,
99 pub max_flushed_packets: c_long,
100 pub max_input_packets: c_long,
101 pub max_output_packets: c_long,
102 pub initial_input_packets: c_long,
103 pub add_input_stuffing_0: c_long,
104 pub add_input_stuffing_1: c_long,
105 pub add_start_stuffing: c_long,
106 pub add_stop_stuffing: c_long,
107 pub bitrate: c_long,
108 pub bitrate_adjust_interval: c_long,
109 pub receive_timeout: c_long,
110 pub log_plugin_index: c_long,
111 pub plugins: *mut u8,
112 pub plugins_size: usize,
113}
114
115#[repr(C)]
117#[derive(Debug, Clone, Copy)]
118pub struct InputSwitcherArgs {
119 pub fast_switch: c_long,
120 pub delayed_switch: c_long,
121 pub terminate: c_long,
122 pub reuse_port: c_long,
123 pub first_input: c_long,
124 pub primary_input: c_long,
125 pub cycle_count: c_long,
126 pub buffered_packets: c_long,
127 pub max_input_packets: c_long,
128 pub max_output_packets: c_long,
129 pub sock_buffer: c_long,
130 pub remote_server_port: c_long,
131 pub receive_timeout: c_long,
132 pub plugins: *mut u8,
133 pub plugins_size: usize,
134 pub event_command: *mut u8,
135 pub event_command_size: usize,
136 pub event_udp_addr: *mut u8,
137 pub event_udp_addr_size: usize,
138 pub event_udp_port: c_long,
139 pub local_addr: *mut u8,
140 pub local_addr_size: usize,
141 pub event_ttl: c_long,
142}
143
144unsafe extern "C" {
145 fn rustduck_tspy_query_abi_layout(layout: *mut TspyAbiLayout);
146
147 pub fn tspyVersionInteger() -> u32;
148 pub fn tspyVersionString(buffer: *mut u8, size: *mut usize);
149
150 pub fn tspyNullReport() -> *mut c_void;
151 pub fn tspyStdErrReport() -> *mut c_void;
152 pub fn tspyNewAsyncReport(
153 severity: i32,
154 sync_log: bool,
155 timed_log: bool,
156 log_msg_count: usize,
157 ) -> *mut c_void;
158 pub fn tspyNewPySyncReport(callback: LogCallback, severity: i32) -> *mut c_void;
159 pub fn tspyNewPyAsyncReport(
160 callback: LogCallback,
161 severity: i32,
162 sync_log: bool,
163 log_msg_count: usize,
164 ) -> *mut c_void;
165 pub fn tspyDeleteReport(report: *mut c_void);
166 pub fn tspyTerminateAsyncReport(report: *mut c_void);
167 pub fn tspySetMaxSeverity(report: *mut c_void, severity: i32);
168 pub fn tspyLogReport(report: *mut c_void, severity: i32, message: *const u8, size: usize);
169 pub fn tspyReportHeader(severity: i32, buffer: *mut u8, size: *mut usize);
170
171 pub fn tspyNewDuckContext(report: *mut c_void) -> *mut c_void;
172 pub fn tspyDeleteDuckContext(duck: *mut c_void);
173 pub fn tspyDuckContextSetDefaultCharset(
174 duck: *mut c_void,
175 name: *const u8,
176 size: usize,
177 ) -> bool;
178 pub fn tspyDuckContextSetDefaultCASId(duck: *mut c_void, cas: u16);
179 pub fn tspyDuckContextSetDefaultPDS(duck: *mut c_void, pds: u32);
180 pub fn tspyDuckContextAddStandards(duck: *mut c_void, mask: u32);
181 pub fn tspyDuckContextStandards(duck: *mut c_void) -> u32;
182 pub fn tspyDuckContextResetStandards(duck: *mut c_void, mask: u32);
183 pub fn tspyDuckContextSetTimeReferenceOffset(duck: *mut c_void, offset: i64);
184 pub fn tspyDuckContextSetTimeReference(duck: *mut c_void, name: *const u8, size: usize)
185 -> bool;
186
187 pub fn tspyNewPyPluginEventHandler(callback: PluginCallback) -> *mut c_void;
188 pub fn tspyDeletePyPluginEventHandler(handler: *mut c_void);
189 pub fn tspyPyPluginEventHandlerUpdateData(
190 event_data: *mut c_void,
191 data: *mut c_void,
192 size: usize,
193 );
194
195 pub fn tspyNewSectionFile(duck: *mut c_void) -> *mut c_void;
196 pub fn tspyDeleteSectionFile(section_file: *mut c_void);
197 pub fn tspySectionFileClear(section_file: *mut c_void);
198 pub fn tspySectionFileBinarySize(section_file: *mut c_void) -> usize;
199 pub fn tspySectionFileSectionsCount(section_file: *mut c_void) -> usize;
200 pub fn tspySectionFileTablesCount(section_file: *mut c_void) -> usize;
201 pub fn tspySectionFileSetCRCValidation(section_file: *mut c_void, mode: i32);
202 pub fn tspySectionLoadBuffer(section_file: *mut c_void, buffer: *const u8, size: usize)
203 -> bool;
204 pub fn tspySectionSaveBuffer(section_file: *mut c_void, buffer: *mut u8, size: *mut usize);
205 pub fn tspySectionFileLoadBinary(
206 section_file: *mut c_void,
207 name: *const u8,
208 size: usize,
209 ) -> bool;
210 pub fn tspySectionFileSaveBinary(
211 section_file: *mut c_void,
212 name: *const u8,
213 size: usize,
214 ) -> bool;
215 pub fn tspySectionFileLoadXML(section_file: *mut c_void, name: *const u8, size: usize) -> bool;
216 pub fn tspySectionFileSaveXML(section_file: *mut c_void, name: *const u8, size: usize) -> bool;
217 pub fn tspySectionFileSaveJSON(section_file: *mut c_void, name: *const u8, size: usize)
218 -> bool;
219 pub fn tspySectionFileToXML(
220 section_file: *mut c_void,
221 buffer: *mut u8,
222 size: *mut usize,
223 ) -> usize;
224 pub fn tspySectionFileToJSON(
225 section_file: *mut c_void,
226 buffer: *mut u8,
227 size: *mut usize,
228 ) -> usize;
229 pub fn tspySectionFileReorganizeEITs(
230 section_file: *mut c_void,
231 year: i32,
232 month: i32,
233 day: i32,
234 );
235
236 pub fn tspyNewSystemMonitor(
237 report: *mut c_void,
238 config: *const u8,
239 config_size: usize,
240 ) -> *mut c_void;
241 pub fn tspyDeleteSystemMonitor(monitor: *mut c_void);
242 pub fn tspyStartSystemMonitor(monitor: *mut c_void);
243 pub fn tspyStopSystemMonitor(monitor: *mut c_void);
244 pub fn tspyWaitSystemMonitor(monitor: *mut c_void);
245
246 pub fn tspyPluginEventHandlerRegister(
247 registry: *mut c_void,
248 handler: *mut c_void,
249 event_code: u32,
250 );
251 pub fn tspyPluginEventHandlerRegisterInput(registry: *mut c_void, handler: *mut c_void);
252 pub fn tspyPluginEventHandlerRegisterOutput(registry: *mut c_void, handler: *mut c_void);
253
254 pub fn tspyNewTSProcessor(report: *mut c_void) -> *mut c_void;
255 pub fn tspyDeleteTSProcessor(processor: *mut c_void);
256 pub fn tspyStartTSProcessor(processor: *mut c_void, args: *const TSProcessorArgs) -> bool;
257 pub fn tspyAbortTSProcessor(processor: *mut c_void);
258 pub fn tspyWaitTSProcessor(processor: *mut c_void);
259
260 pub fn tspyNewInputSwitcher(report: *mut c_void) -> *mut c_void;
261 pub fn tspyDeleteInputSwitcher(switcher: *mut c_void);
262 pub fn tspyStartInputSwitcher(switcher: *mut c_void, args: *const InputSwitcherArgs) -> bool;
263 pub fn tspyInputSwitcherSetInput(switcher: *mut c_void, index: usize);
264 pub fn tspyInputSwitcherNextInput(switcher: *mut c_void);
265 pub fn tspyInputSwitcherPreviousInput(switcher: *mut c_void);
266 pub fn tspyInputSwitcherCurrentInput(switcher: *mut c_void) -> usize;
267 pub fn tspyStopInputSwitcher(switcher: *mut c_void);
268 pub fn tspyWaitInputSwitcher(switcher: *mut c_void);
269
270}