Skip to main content

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