Skip to main content

gstreamer_mpegts/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![allow(clippy::missing_safety_doc)]
3#![allow(clippy::manual_c_str_literals)]
4
5use std::sync::Once;
6
7pub use glib;
8#[cfg(feature = "v1_20")]
9use glib::translate::ToGlibPtr;
10pub use gst;
11pub use gstreamer_mpegts_sys as ffi;
12
13static MPEGTS_INIT: Once = Once::new();
14
15macro_rules! assert_initialized_main_thread {
16    () => {
17        if !gst::INITIALIZED.load(std::sync::atomic::Ordering::SeqCst) {
18            gst::assert_initialized();
19        }
20        crate::MPEGTS_INIT.call_once(|| unsafe { crate::ffi::gst_mpegts_initialize() });
21    };
22}
23
24pub fn init() {
25    assert_initialized_main_thread!();
26}
27
28#[allow(unused_imports)]
29mod auto;
30#[allow(unused_imports)]
31pub use crate::auto::*;
32
33#[cfg(feature = "v1_20")]
34#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
35#[doc(alias = "gst_event_new_mpegts_section")]
36pub fn event_new_mpegts_section(section: &Section) -> gst::Event {
37    assert_initialized_main_thread!();
38
39    unsafe {
40        let event = ffi::gst_event_new_mpegts_section(section.to_glib_none().0);
41        glib::translate::from_glib_full(event)
42    }
43}
44
45#[cfg(feature = "v1_20")]
46#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
47#[doc(alias = "gst_message_new_mpegts_section")]
48pub fn message_new_mpegts_section(parent: &gst::Object, section: &Section) -> gst::Message {
49    assert_initialized_main_thread!();
50
51    unsafe {
52        let message =
53            ffi::gst_message_new_mpegts_section(parent.to_glib_none().0, section.to_glib_none().0);
54        glib::translate::from_glib_full(message)
55    }
56}
57
58// rustdoc-stripper-ignore-next
59/// Parses a #Section from a #Event.
60///
61/// # Arguments
62///
63/// * `event` - The #Event to parse
64///
65/// # Returns
66///
67/// A `Section` if the event contains MPEG-TS section data, else `None`
68#[cfg(feature = "v1_20")]
69#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
70#[doc(alias = "gst_event_parse_mpegts_section")]
71pub fn event_parse_mpegts_section(event: &gst::Event) -> Option<Section> {
72    assert_initialized_main_thread!();
73
74    unsafe {
75        let section = ffi::gst_event_parse_mpegts_section(event.to_glib_none().0);
76        glib::translate::from_glib_full(section)
77    }
78}
79
80// rustdoc-stripper-ignore-next
81/// Parses a #Section from a #Message.
82///
83/// Returns a `Section` if the message contains MPEG-TS section data, else
84/// `None`
85#[cfg(feature = "v1_20")]
86#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
87#[doc(alias = "gst_message_parse_mpegts_section")]
88pub fn message_parse_mpegts_section(message: &gst::Message) -> Option<Section> {
89    assert_initialized_main_thread!();
90
91    unsafe {
92        let section = ffi::gst_message_parse_mpegts_section(message.to_glib_none().0);
93        glib::translate::from_glib_full(section)
94    }
95}
96
97#[cfg(feature = "v1_20")]
98impl Section {
99    // rustdoc-stripper-ignore-next
100    /// Creates a new #Section from the provided data.
101    ///
102    /// # Arguments
103    ///
104    /// * `pid` - The PID to which this section belongs
105    /// * `data` - A slice containing the section data (must start with table_id)
106    ///
107    /// # Returns
108    ///
109    /// A new `Section` if the data was valid, else `None`
110    #[doc(alias = "gst_mpegts_section_new")]
111    pub fn new(pid: u16, data: &[u8]) -> Option<Section> {
112        assert_initialized_main_thread!();
113        unsafe {
114            let len = data.len();
115            let ptr = data.to_glib_full();
116            let section = ffi::gst_mpegts_section_new(pid, ptr, len);
117            glib::translate::from_glib_full(section)
118        }
119    }
120}