use std::mem::MaybeUninit;
use std::os::raw::{c_long, c_void};
include!(concat!(env!("OUT_DIR"), "/tsduck_version.rs"));
pub type UChar = u16;
pub type LogCallbackUtf16 =
unsafe extern "C" fn(severity: i32, message: *const UChar, message_bytes: usize) -> *mut c_void;
pub type PluginCallbackUtf16 = unsafe extern "C" fn(
event_code: u32,
plugin_name: *const UChar,
plugin_name_bytes: usize,
plugin_index: usize,
plugin_count: usize,
bitrate: usize,
plugin_packets: usize,
total_packets: usize,
data: *const u8,
data_size: usize,
data_max_size: usize,
data_read_only: bool,
event_data: *mut c_void,
) -> bool;
#[deprecated(
since = "1.1.0",
note = "incompatible with TSDuck's callback ABI and can cause undefined behavior; use LogCallbackUtf16"
)]
pub type LogCallback = unsafe extern "C" fn(severity: i32, message: *const u8, size: usize);
#[deprecated(
since = "1.1.0",
note = "incompatible with TSDuck's plugin-name ABI; use PluginCallbackUtf16"
)]
pub type PluginCallback = unsafe extern "C" fn(
event_code: u32,
plugin_name: *const u8,
plugin_name_size: usize,
plugin_index: usize,
plugin_count: usize,
bitrate: usize,
plugin_packets: usize,
total_packets: usize,
data: *const u8,
data_size: usize,
data_max_size: usize,
data_read_only: bool,
event_data: *mut c_void,
) -> bool;
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TspyAbiLayout {
pub tsduck_header_version_major: u32,
pub tsduck_header_version_minor: u32,
pub ts_processor_args_size: usize,
pub ts_processor_args_align: usize,
pub ts_processor_args_offsets: [usize; 16],
pub input_switcher_args_size: usize,
pub input_switcher_args_align: usize,
pub input_switcher_args_offsets: [usize; 23],
pub uint32_size: usize,
pub uint32_align: usize,
pub size_t_size: usize,
pub size_t_align: usize,
pub bool_size: usize,
pub bool_align: usize,
pub long_size: usize,
pub long_align: usize,
}
#[must_use]
pub fn tspy_abi_layout() -> TspyAbiLayout {
let mut layout = MaybeUninit::<TspyAbiLayout>::uninit();
unsafe {
rustduck_tspy_query_abi_layout(layout.as_mut_ptr());
layout.assume_init()
}
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct TSProcessorArgs {
pub ignore_joint_termination: c_long,
pub buffer_size: c_long,
pub max_flushed_packets: c_long,
pub max_input_packets: c_long,
pub max_output_packets: c_long,
pub initial_input_packets: c_long,
pub add_input_stuffing_0: c_long,
pub add_input_stuffing_1: c_long,
pub add_start_stuffing: c_long,
pub add_stop_stuffing: c_long,
pub bitrate: c_long,
pub bitrate_adjust_interval: c_long,
pub receive_timeout: c_long,
pub log_plugin_index: c_long,
pub plugins: *mut u8,
pub plugins_size: usize,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub struct InputSwitcherArgs {
pub fast_switch: c_long,
pub delayed_switch: c_long,
pub terminate: c_long,
pub reuse_port: c_long,
pub first_input: c_long,
pub primary_input: c_long,
pub cycle_count: c_long,
pub buffered_packets: c_long,
pub max_input_packets: c_long,
pub max_output_packets: c_long,
pub sock_buffer: c_long,
pub remote_server_port: c_long,
pub receive_timeout: c_long,
pub plugins: *mut u8,
pub plugins_size: usize,
pub event_command: *mut u8,
pub event_command_size: usize,
pub event_udp_addr: *mut u8,
pub event_udp_addr_size: usize,
pub event_udp_port: c_long,
pub local_addr: *mut u8,
pub local_addr_size: usize,
pub event_ttl: c_long,
}
struct RedactedPointer<T>(*const T);
impl<T> RedactedPointer<T> {
fn new(pointer: *mut T) -> Self {
Self(pointer)
}
}
impl<T> std::fmt::Debug for RedactedPointer<T> {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(if self.0.is_null() { "null" } else { "non-null" })
}
}
impl std::fmt::Debug for TSProcessorArgs {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("TSProcessorArgs")
.field("ignore_joint_termination", &self.ignore_joint_termination)
.field("buffer_size", &self.buffer_size)
.field("max_flushed_packets", &self.max_flushed_packets)
.field("max_input_packets", &self.max_input_packets)
.field("max_output_packets", &self.max_output_packets)
.field("initial_input_packets", &self.initial_input_packets)
.field("add_input_stuffing_0", &self.add_input_stuffing_0)
.field("add_input_stuffing_1", &self.add_input_stuffing_1)
.field("add_start_stuffing", &self.add_start_stuffing)
.field("add_stop_stuffing", &self.add_stop_stuffing)
.field("bitrate", &self.bitrate)
.field("bitrate_adjust_interval", &self.bitrate_adjust_interval)
.field("receive_timeout", &self.receive_timeout)
.field("log_plugin_index", &self.log_plugin_index)
.field("plugins", &RedactedPointer::new(self.plugins))
.field("plugins_size", &self.plugins_size)
.finish()
}
}
impl std::fmt::Debug for InputSwitcherArgs {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("InputSwitcherArgs")
.field("fast_switch", &self.fast_switch)
.field("delayed_switch", &self.delayed_switch)
.field("terminate", &self.terminate)
.field("reuse_port", &self.reuse_port)
.field("first_input", &self.first_input)
.field("primary_input", &self.primary_input)
.field("cycle_count", &self.cycle_count)
.field("buffered_packets", &self.buffered_packets)
.field("max_input_packets", &self.max_input_packets)
.field("max_output_packets", &self.max_output_packets)
.field("sock_buffer", &self.sock_buffer)
.field("remote_server_port", &self.remote_server_port)
.field("receive_timeout", &self.receive_timeout)
.field("plugins", &RedactedPointer::new(self.plugins))
.field("plugins_size", &self.plugins_size)
.field("event_command", &RedactedPointer::new(self.event_command))
.field("event_command_size", &self.event_command_size)
.field("event_udp_addr", &RedactedPointer::new(self.event_udp_addr))
.field("event_udp_addr_size", &self.event_udp_addr_size)
.field("event_udp_port", &self.event_udp_port)
.field("local_addr", &RedactedPointer::new(self.local_addr))
.field("local_addr_size", &self.local_addr_size)
.field("event_ttl", &self.event_ttl)
.finish()
}
}
unsafe extern "C" {
fn rustduck_tspy_query_abi_layout(layout: *mut TspyAbiLayout);
pub fn tspyVersionInteger() -> u32;
pub fn tspyVersionString(buffer: *mut u8, size: *mut usize);
pub fn tspyNullReport() -> *mut c_void;
pub fn tspyStdErrReport() -> *mut c_void;
pub fn tspyNewAsyncReport(
severity: i32,
sync_log: bool,
timed_log: bool,
log_msg_count: usize,
) -> *mut c_void;
#[allow(deprecated)]
#[deprecated(
since = "1.1.0",
note = "uses an incompatible callback ABI; use tspyNewPySyncReportUtf16"
)]
pub fn tspyNewPySyncReport(callback: LogCallback, severity: i32) -> *mut c_void;
#[allow(clashing_extern_declarations)]
#[link_name = "tspyNewPySyncReport"]
pub fn tspyNewPySyncReportUtf16(callback: LogCallbackUtf16, severity: i32) -> *mut c_void;
#[allow(deprecated)]
#[deprecated(
since = "1.1.0",
note = "uses an incompatible callback ABI; use tspyNewPyAsyncReportUtf16"
)]
pub fn tspyNewPyAsyncReport(
callback: LogCallback,
severity: i32,
sync_log: bool,
log_msg_count: usize,
) -> *mut c_void;
#[allow(clashing_extern_declarations)]
#[link_name = "tspyNewPyAsyncReport"]
pub fn tspyNewPyAsyncReportUtf16(
callback: LogCallbackUtf16,
severity: i32,
sync_log: bool,
log_msg_count: usize,
) -> *mut c_void;
pub fn tspyDeleteReport(report: *mut c_void);
pub fn tspyTerminateAsyncReport(report: *mut c_void);
pub fn tspySetMaxSeverity(report: *mut c_void, severity: i32);
pub fn tspyLogReport(report: *mut c_void, severity: i32, message: *const u8, size: usize);
pub fn tspyReportHeader(severity: i32, buffer: *mut u8, size: *mut usize);
pub fn tspyNewDuckContext(report: *mut c_void) -> *mut c_void;
pub fn tspyDeleteDuckContext(duck: *mut c_void);
pub fn tspyDuckContextSetDefaultCharset(
duck: *mut c_void,
name: *const u8,
size: usize,
) -> bool;
pub fn tspyDuckContextSetDefaultCASId(duck: *mut c_void, cas: u16);
pub fn tspyDuckContextSetDefaultPDS(duck: *mut c_void, pds: u32);
pub fn tspyDuckContextAddStandards(duck: *mut c_void, mask: u32);
pub fn tspyDuckContextStandards(duck: *mut c_void) -> u32;
pub fn tspyDuckContextResetStandards(duck: *mut c_void, mask: u32);
pub fn tspyDuckContextSetTimeReferenceOffset(duck: *mut c_void, offset: i64);
pub fn tspyDuckContextSetTimeReference(duck: *mut c_void, name: *const u8, size: usize)
-> bool;
#[allow(deprecated)]
#[deprecated(
since = "1.1.0",
note = "uses an incompatible plugin-name ABI; use tspyNewPyPluginEventHandlerUtf16"
)]
pub fn tspyNewPyPluginEventHandler(callback: PluginCallback) -> *mut c_void;
#[allow(clashing_extern_declarations)]
#[link_name = "tspyNewPyPluginEventHandler"]
pub fn tspyNewPyPluginEventHandlerUtf16(callback: PluginCallbackUtf16) -> *mut c_void;
pub fn tspyDeletePyPluginEventHandler(handler: *mut c_void);
pub fn tspyPyPluginEventHandlerUpdateData(
event_data: *mut c_void,
data: *mut c_void,
size: usize,
);
pub fn tspyNewSectionFile(duck: *mut c_void) -> *mut c_void;
pub fn tspyDeleteSectionFile(section_file: *mut c_void);
pub fn tspySectionFileClear(section_file: *mut c_void);
pub fn tspySectionFileBinarySize(section_file: *mut c_void) -> usize;
pub fn tspySectionFileSectionsCount(section_file: *mut c_void) -> usize;
pub fn tspySectionFileTablesCount(section_file: *mut c_void) -> usize;
pub fn tspySectionFileSetCRCValidation(section_file: *mut c_void, mode: i32);
pub fn tspySectionLoadBuffer(section_file: *mut c_void, buffer: *const u8, size: usize)
-> bool;
pub fn tspySectionSaveBuffer(section_file: *mut c_void, buffer: *mut u8, size: *mut usize);
pub fn tspySectionFileLoadBinary(
section_file: *mut c_void,
name: *const u8,
size: usize,
) -> bool;
pub fn tspySectionFileSaveBinary(
section_file: *mut c_void,
name: *const u8,
size: usize,
) -> bool;
pub fn tspySectionFileLoadXML(section_file: *mut c_void, name: *const u8, size: usize) -> bool;
pub fn tspySectionFileSaveXML(section_file: *mut c_void, name: *const u8, size: usize) -> bool;
pub fn tspySectionFileSaveJSON(section_file: *mut c_void, name: *const u8, size: usize)
-> bool;
pub fn tspySectionFileToXML(
section_file: *mut c_void,
buffer: *mut u8,
size: *mut usize,
) -> usize;
pub fn tspySectionFileToJSON(
section_file: *mut c_void,
buffer: *mut u8,
size: *mut usize,
) -> usize;
pub fn tspySectionFileReorganizeEITs(
section_file: *mut c_void,
year: i32,
month: i32,
day: i32,
);
pub fn tspyNewSystemMonitor(
report: *mut c_void,
config: *const u8,
config_size: usize,
) -> *mut c_void;
pub fn tspyDeleteSystemMonitor(monitor: *mut c_void);
pub fn tspyStartSystemMonitor(monitor: *mut c_void);
pub fn tspyStopSystemMonitor(monitor: *mut c_void);
pub fn tspyWaitSystemMonitor(monitor: *mut c_void);
pub fn tspyPluginEventHandlerRegister(
registry: *mut c_void,
handler: *mut c_void,
event_code: u32,
);
pub fn tspyPluginEventHandlerRegisterInput(registry: *mut c_void, handler: *mut c_void);
pub fn tspyPluginEventHandlerRegisterOutput(registry: *mut c_void, handler: *mut c_void);
pub fn tspyNewTSProcessor(report: *mut c_void) -> *mut c_void;
pub fn tspyDeleteTSProcessor(processor: *mut c_void);
pub fn tspyStartTSProcessor(processor: *mut c_void, args: *const TSProcessorArgs) -> bool;
pub fn tspyAbortTSProcessor(processor: *mut c_void);
pub fn tspyWaitTSProcessor(processor: *mut c_void);
pub fn tspyNewInputSwitcher(report: *mut c_void) -> *mut c_void;
pub fn tspyDeleteInputSwitcher(switcher: *mut c_void);
pub fn tspyStartInputSwitcher(switcher: *mut c_void, args: *const InputSwitcherArgs) -> bool;
pub fn tspyInputSwitcherSetInput(switcher: *mut c_void, index: usize);
pub fn tspyInputSwitcherNextInput(switcher: *mut c_void);
pub fn tspyInputSwitcherPreviousInput(switcher: *mut c_void);
pub fn tspyInputSwitcherCurrentInput(switcher: *mut c_void) -> usize;
pub fn tspyStopInputSwitcher(switcher: *mut c_void);
pub fn tspyWaitInputSwitcher(switcher: *mut c_void);
}