gstreamer/
lib.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3#![cfg_attr(docsrs, feature(doc_cfg))]
4#![allow(clippy::missing_safety_doc)]
5#![allow(clippy::manual_range_contains)]
6#![allow(clippy::manual_c_str_literals)]
7#![doc = include_str!("../README.md")]
8
9// Re-exported for the subclass gst_plugin_define! macro
10pub use glib;
11pub use gstreamer_sys as ffi;
12#[deprecated = "Use `gst::pastey` instead"]
13pub use pastey as paste;
14pub use pastey;
15
16#[doc(hidden)]
17pub static INITIALIZED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
18
19#[cold]
20#[inline(never)]
21#[track_caller]
22pub fn assert_initialized() {
23    #[allow(unused_unsafe)]
24    if unsafe { ffi::gst_is_initialized() } != glib::ffi::GTRUE {
25        panic!("GStreamer has not been initialized. Call `gst::init` first.");
26    } else {
27        crate::INITIALIZED.store(true, std::sync::atomic::Ordering::SeqCst);
28    }
29}
30
31macro_rules! assert_initialized_main_thread {
32    () => {
33        if !crate::INITIALIZED.load(std::sync::atomic::Ordering::SeqCst) {
34            $crate::assert_initialized();
35        }
36    };
37}
38
39macro_rules! skip_assert_initialized {
40    () => {};
41}
42
43#[allow(clippy::needless_borrow)]
44#[allow(clippy::let_unit_value)]
45#[allow(unused_imports)]
46mod auto;
47pub use crate::auto::*;
48
49#[macro_use]
50#[cfg(feature = "serde")]
51mod serde_macros;
52
53#[macro_use]
54pub mod log;
55#[cfg(feature = "v1_28")]
56#[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
57pub mod log_context;
58#[cfg(feature = "log")]
59pub use crate::log::DebugCategoryLogger;
60pub use crate::log::{
61    DebugCategory, DebugLogFunction, DebugLogger, DebugMessage, LoggedObject, CAT_BUFFER,
62    CAT_BUFFER_LIST, CAT_BUS, CAT_CALL_TRACE, CAT_CAPS, CAT_CLOCK, CAT_CONTEXT, CAT_DEFAULT,
63    CAT_ELEMENT_PADS, CAT_ERROR_SYSTEM, CAT_EVENT, CAT_GST_INIT, CAT_LOCKING, CAT_MEMORY,
64    CAT_MESSAGE, CAT_META, CAT_NEGOTIATION, CAT_PADS, CAT_PARAMS, CAT_PARENTAGE, CAT_PERFORMANCE,
65    CAT_PIPELINE, CAT_PLUGIN_INFO, CAT_PLUGIN_LOADING, CAT_PROBE, CAT_PROPERTIES, CAT_QOS,
66    CAT_REFCOUNTING, CAT_REGISTRY, CAT_RUST, CAT_SCHEDULING, CAT_SIGNAL, CAT_STATES,
67};
68
69#[cfg(feature = "v1_28")]
70#[cfg_attr(docsrs, doc(cfg(feature = "v1_28")))]
71pub use crate::log_context::{LogContext, LogContextBuilder};
72
73#[cfg(target_os = "macos")]
74mod macos;
75#[cfg(all(target_os = "macos", feature = "v1_22"))]
76pub use crate::macos::*;
77
78#[macro_use]
79mod error;
80pub use crate::error::*;
81
82#[macro_use]
83pub mod miniobject;
84pub use miniobject::{MiniObject, MiniObjectRef};
85
86#[macro_use]
87mod value;
88pub use crate::value::{
89    Array, ArrayRef, Bitmask, Fraction, FractionRange, IntRange, List, ListRef,
90};
91#[cfg(feature = "serde")]
92#[macro_use]
93mod value_serde;
94
95#[macro_use]
96mod id_str;
97pub use crate::id_str::IdStr;
98
99#[cfg(feature = "serde")]
100mod flag_serde;
101
102pub mod message;
103pub use crate::message::{Message, MessageErrorDomain, MessageRef, MessageView, MessageViewMut};
104
105pub mod structure;
106pub use crate::structure::{Structure, StructureRef};
107#[cfg(feature = "serde")]
108mod structure_serde;
109
110pub mod caps;
111pub use crate::caps::{Caps, CapsFilterMapAction, CapsRef};
112mod caps_features;
113#[cfg(feature = "serde")]
114mod caps_serde;
115pub use crate::caps_features::{
116    CapsFeatures, CapsFeaturesRef, CAPS_FEATURES_MEMORY_SYSTEM_MEMORY,
117    CAPS_FEATURE_MEMORY_SYSTEM_MEMORY,
118};
119#[cfg(feature = "serde")]
120mod caps_features_serde;
121
122pub mod tags;
123pub use crate::tags::{
124    tag_exists, tag_get_description, tag_get_flag, tag_get_nick, tag_get_type, Tag, TagList,
125    TagListRef,
126};
127#[cfg(feature = "serde")]
128mod tags_serde;
129
130#[macro_use]
131pub mod meta;
132#[cfg(feature = "v1_16")]
133#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
134pub use crate::meta::MetaSeqnum;
135pub use crate::meta::{
136    Meta, MetaAPI, MetaAPIExt, MetaRef, MetaRefMut, ParentBufferMeta, ProtectionMeta,
137    ReferenceTimestampMeta,
138};
139pub mod buffer;
140pub use crate::buffer::{
141    Buffer, BufferMap, BufferRef, MappedBuffer, BUFFER_COPY_ALL, BUFFER_COPY_METADATA,
142};
143mod buffer_cursor;
144pub use crate::buffer_cursor::{BufferCursor, BufferRefCursor};
145pub mod memory;
146mod memory_wrapped;
147#[cfg(feature = "v1_26")]
148#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
149pub use crate::memory::MemoryRefTrace;
150pub use crate::memory::{MappedMemory, Memory, MemoryMap, MemoryRef};
151pub use crate::memory_wrapped::MemoryIntoInnerError;
152#[cfg(feature = "serde")]
153mod buffer_serde;
154pub mod slice;
155
156pub mod sample;
157pub use crate::sample::{Sample, SampleRef};
158#[cfg(feature = "serde")]
159mod sample_serde;
160
161pub mod bufferlist;
162pub use crate::bufferlist::{BufferList, BufferListRef};
163#[cfg(feature = "serde")]
164mod bufferlist_serde;
165
166pub mod query;
167pub use crate::query::{Query, QueryRef, QueryView, QueryViewMut};
168pub mod event;
169pub use crate::event::{Event, EventRef, EventView, EventViewMut, GroupId, Seqnum};
170pub mod context;
171pub use crate::context::{Context, ContextRef};
172mod rank;
173pub use crate::rank::Rank;
174mod static_caps;
175pub use crate::static_caps::*;
176mod static_pad_template;
177pub use crate::static_pad_template::*;
178
179pub mod promise;
180pub use promise::{Promise, PromiseError};
181
182pub mod bus;
183mod element;
184pub mod element_factory;
185
186mod bin;
187pub use bin::BinBuilder;
188
189mod pipeline;
190pub use pipeline::PipelineBuilder;
191
192mod allocation_params;
193pub use self::allocation_params::AllocationParams;
194mod allocator;
195
196mod element_factory_type;
197pub use element_factory_type::*;
198
199mod tracer;
200mod tracer_factory;
201
202// OS dependent Bus extensions (also import the other platform mod for doc)
203#[cfg(any(unix, docsrs))]
204mod bus_unix;
205#[cfg(any(windows, docsrs))]
206mod bus_windows;
207
208mod child_proxy;
209mod date_time;
210#[cfg(feature = "serde")]
211mod date_time_serde;
212mod device_monitor;
213mod device_provider;
214mod device_provider_factory;
215mod enums;
216mod ghost_pad;
217pub mod gobject;
218mod iterator;
219mod object;
220mod pad;
221pub use pad::{
222    EventForeachAction, PadBuilder, PadGetRangeSuccess, PadProbeData, PadProbeId, PadProbeInfo,
223    StreamLock,
224};
225mod control_binding;
226mod control_source;
227mod parse_context;
228mod proxy_pad;
229mod registry;
230mod tag_setter;
231pub mod task;
232pub use task::{TaskLock, TaskLockGuard};
233mod task_pool;
234pub use self::iterator::{Iterator, IteratorError, IteratorImpl, StdIterator};
235pub use crate::{
236    device_monitor::DeviceMonitorFilterId,
237    element::{
238        ElementMessageType, NotifyWatchId, ELEMENT_METADATA_AUTHOR, ELEMENT_METADATA_DESCRIPTION,
239        ELEMENT_METADATA_DOC_URI, ELEMENT_METADATA_ICON_NAME, ELEMENT_METADATA_KLASS,
240        ELEMENT_METADATA_LONGNAME,
241    },
242    enums::{
243        ClockError, ClockSuccess, FlowError, FlowReturn, FlowSuccess, MessageType, PadLinkError,
244        PadLinkReturn, PadLinkSuccess, StateChangeError, StateChangeSuccess, TagError,
245    },
246    parse_context::ParseContext,
247    task_pool::{TaskHandle, TaskPoolTaskHandle},
248};
249mod plugin_feature;
250
251mod plugin;
252pub mod stream;
253pub mod stream_collection;
254
255mod typefind;
256pub use crate::typefind::*;
257mod typefind_factory;
258
259pub mod format;
260pub use crate::format::{ClockTime, GenericFormattedValue, GenericSignedFormattedValue, Signed};
261
262mod segment;
263pub use crate::segment::*;
264#[cfg(feature = "serde")]
265mod segment_serde;
266
267mod timed_value;
268pub use crate::timed_value::TimedValue;
269
270pub mod toc;
271pub use crate::toc::{Toc, TocEntry, TocEntryRef, TocRef};
272#[cfg(feature = "serde")]
273mod toc_serde;
274
275mod clock;
276pub use crate::clock::{AtomicClockReturn, ClockId, PeriodicClockId, SingleShotClockId};
277
278mod buffer_pool;
279pub use crate::buffer_pool::{BufferPoolAcquireParams, BufferPoolConfig, BufferPoolConfigRef};
280
281mod pad_template;
282pub use pad_template::PadTemplateBuilder;
283
284pub mod param_spec;
285pub use crate::param_spec::{ParamSpecArray, ParamSpecFraction};
286
287mod functions;
288pub use crate::functions::*;
289
290mod utils;
291pub use crate::utils::ObjectLockGuard;
292
293pub mod parse;
294
295#[cfg(feature = "v1_18")]
296mod gtype;
297
298use std::ptr;
299
300#[doc(alias = "gst_init_check")]
301pub fn init() -> Result<(), glib::Error> {
302    unsafe {
303        use glib::translate::*;
304
305        let mut error = ptr::null_mut();
306        if from_glib(ffi::gst_init_check(
307            ptr::null_mut(),
308            ptr::null_mut(),
309            &mut error,
310        )) {
311            crate::INITIALIZED.store(true, std::sync::atomic::Ordering::SeqCst);
312            Ok(())
313        } else {
314            Err(from_glib_full(error))
315        }
316    }
317}
318
319// rustdoc-stripper-ignore-next
320/// Deinitialize GStreamer
321///
322/// # Safety
323///
324/// This must only be called once during the lifetime of the process, once no GStreamer threads
325/// are running anymore and all GStreamer resources are released.
326pub unsafe fn deinit() {
327    crate::INITIALIZED.store(false, std::sync::atomic::Ordering::SeqCst);
328    ffi::gst_deinit();
329}
330
331pub const PARAM_FLAG_CONTROLLABLE: glib::ParamFlags = glib::ParamFlags::USER_1;
332pub const PARAM_FLAG_MUTABLE_READY: glib::ParamFlags = glib::ParamFlags::USER_2;
333pub const PARAM_FLAG_MUTABLE_PAUSED: glib::ParamFlags = glib::ParamFlags::USER_3;
334pub const PARAM_FLAG_MUTABLE_PLAYING: glib::ParamFlags = glib::ParamFlags::USER_4;
335#[cfg(feature = "v1_18")]
336pub const PARAM_FLAG_DOC_SHOW_DEFAULT: glib::ParamFlags = glib::ParamFlags::USER_5;
337#[cfg(feature = "v1_18")]
338pub const PARAM_FLAG_CONDITIONALLY_AVAILABLE: glib::ParamFlags = glib::ParamFlags::USER_6;
339
340// Re-export all the traits in a prelude module, so that applications
341// can always "use gst::prelude::*" without getting conflicts
342pub mod prelude {
343    #[doc(hidden)]
344    pub use glib::prelude::*;
345    pub use muldiv::MulDiv;
346    pub use opt_ops::prelude::*;
347
348    // OS dependent Bus extensions (also import the other platform trait for doc)
349    #[cfg(any(unix, docsrs))]
350    pub use crate::bus_unix::UnixBusExtManual;
351    #[cfg(any(windows, docsrs))]
352    pub use crate::bus_windows::WindowsBusExtManual;
353    #[cfg(feature = "v1_18")]
354    pub use crate::gtype::PluginApiExt;
355    pub use crate::{
356        auto::traits::*,
357        bin::GstBinExtManual,
358        buffer_pool::BufferPoolExtManual,
359        child_proxy::ChildProxyExtManual,
360        clock::ClockExtManual,
361        control_binding::ControlBindingExtManual,
362        control_source::ControlSourceExtManual,
363        device_monitor::DeviceMonitorExtManual,
364        device_provider::{DeviceProviderClassExt, DeviceProviderExtManual},
365        element::{ElementClassExt, ElementExtManual},
366        format::prelude::*,
367        gobject::GObjectExtManualGst,
368        log::DebugLogger,
369        memory::MemoryType,
370        message::MessageErrorDomain,
371        meta::{MetaAPI, MetaAPIExt, MetaTag},
372        miniobject::IsMiniObject,
373        object::GstObjectExtManual,
374        pad::PadExtManual,
375        param_spec::GstParamSpecBuilderExt,
376        pipeline::GstPipelineExtManual,
377        plugin_feature::PluginFeatureExtManual,
378        slice::ByteSliceExt,
379        tag_setter::TagSetterExtManual,
380        tags::{CustomTag, Tag},
381        task_pool::{TaskHandle, TaskPoolExtManual},
382        typefind::TypeFindImpl,
383        utils::Displayable,
384        value::GstValueExt,
385    };
386}
387
388#[macro_use]
389pub mod subclass;