1 // Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
2 //
3 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6 // option. This file may not be copied, modified, or distributed
7 // except according to those terms.
8
9 #![recursion_limit = "256"]
10 #[macro_use]
11 extern crate bitflags;
12 #[cfg(any(feature = "v1_14", feature = "dox"))]
13 #[macro_use]
14 extern crate cfg_if;
15 #[macro_use]
16 extern crate lazy_static;
17 extern crate libc;
18
19 // Re-exported for the subclass gst_plugin_define! macro
20 #[doc(hidden)]
21 pub extern crate glib_sys;
22 #[doc(hidden)]
23 pub extern crate gobject_sys;
24 #[doc(hidden)]
25 pub extern crate gstreamer_sys as gst_sys;
26 #[doc(hidden)]
27 pub extern crate paste;
28
29 #[macro_use]
30 #[doc(hidden)]
31 pub extern crate glib;
32
33 extern crate num_rational;
34
35 extern crate futures_channel;
36 extern crate futures_core;
37 extern crate futures_util;
38
39 extern crate muldiv;
40
41 #[cfg(feature = "ser_de")]
42 extern crate serde;
43 #[cfg(feature = "ser_de")]
44 extern crate serde_bytes;
45 #[cfg(feature = "ser_de")]
46 #[macro_use]
47 extern crate serde_derive;
48
49 #[cfg(test)]
50 extern crate futures_executor;
51
52 use glib::translate::{from_glib, from_glib_full};
53
54 macro_rules! assert_initialized_main_thread {
55 () => {
56 if unsafe { ::gst_sys::gst_is_initialized() } != ::glib_sys::GTRUE {
57 panic!("GStreamer has not been initialized. Call `gst::init` first.");
58 }
59 };
60 }
61
62 macro_rules! skip_assert_initialized {
63 () => {};
64 }
65
66 #[allow(clippy::unreadable_literal)]
67 #[allow(clippy::too_many_arguments)]
68 #[allow(clippy::match_same_arms)]
69 #[allow(clippy::type_complexity)]
70 mod auto;
71 pub use auto::functions::*;
72 pub use auto::*;
73
74 #[macro_use]
75 mod log;
76 pub use log::*;
77
78 #[macro_use]
79 mod error;
80 pub use error::*;
81
82 #[macro_use]
83 pub mod miniobject;
84 pub use miniobject::{GstRc, MiniObject};
85 pub mod message;
86 pub use message::{Message, MessageErrorDomain, MessageRef, MessageView};
87
88 mod value;
89 pub use value::*;
90 #[cfg(feature = "ser_de")]
91 #[macro_use]
92 mod value_serde;
93
94 pub mod structure;
95 pub use structure::{Structure, StructureRef};
96 #[cfg(feature = "ser_de")]
97 mod structure_serde;
98
99 pub mod caps;
100 pub use caps::{Caps, CapsRef};
101 mod caps_features;
102 #[cfg(feature = "ser_de")]
103 mod caps_serde;
104 pub use caps_features::{
105 CapsFeatures, CapsFeaturesRef, CAPS_FEATURES_MEMORY_SYSTEM_MEMORY,
106 CAPS_FEATURE_MEMORY_SYSTEM_MEMORY,
107 };
108 #[cfg(feature = "ser_de")]
109 mod caps_features_serde;
110
111 pub mod tags;
112 pub use tags::{
113 tag_exists, tag_get_description, tag_get_flag, tag_get_nick, tag_get_type, Tag, TagList,
114 TagListRef,
115 };
116 #[cfg(feature = "ser_de")]
117 mod tags_serde;
118
119 pub mod meta;
120 #[cfg(any(feature = "v1_14", feature = "dox"))]
121 pub use meta::ReferenceTimestampMeta;
122 pub use meta::{Meta, MetaAPI, MetaRef, MetaRefMut, ParentBufferMeta, ProtectionMeta};
123 pub mod buffer;
124 pub use buffer::{
125 Buffer, BufferMap, BufferRef, MappedBuffer, BUFFER_COPY_ALL, BUFFER_COPY_METADATA,
126 };
127 pub mod memory;
128 pub use memory::{MappedMemory, Memory, MemoryMap, MemoryRef};
129 #[cfg(feature = "ser_de")]
130 mod buffer_serde;
131
132 pub mod sample;
133 pub use sample::{Sample, SampleRef};
134 #[cfg(feature = "ser_de")]
135 mod sample_serde;
136
137 pub mod bufferlist;
138 pub use bufferlist::{BufferList, BufferListRef};
139 #[cfg(feature = "ser_de")]
140 mod bufferlist_serde;
141
142 pub mod query;
143 pub use query::{Query, QueryRef, QueryView};
144 pub mod event;
145 pub use event::{Event, EventRef, EventView, GroupId, Seqnum, GROUP_ID_INVALID, SEQNUM_INVALID};
146 pub mod context;
147 pub use context::{Context, ContextRef};
148 mod static_caps;
149 pub use static_caps::*;
150 mod static_pad_template;
151 pub use static_pad_template::*;
152
153 #[cfg(any(feature = "v1_14", feature = "dox"))]
154 pub mod promise;
155 #[cfg(any(feature = "v1_14", feature = "dox"))]
156 pub use promise::{Promise, PromiseError};
157
158 pub mod bus;
159 mod element;
160
161 mod bin;
162
163 mod allocator;
164 pub use allocator::AllocatorExtManual;
165 mod pipeline;
166 pub use pipeline::GstPipelineExtManual;
167
168 mod allocation_params;
169 pub use self::allocation_params::AllocationParams;
170
171 // OS dependent Bus extensions (also import the other plateform mod for doc)
172 #[cfg(any(feature = "v1_14", feature = "dox"))]
173 cfg_if! {
174 if #[cfg(unix)] {
175 mod bus_unix;
176 #[cfg(feature = "dox")]
177 mod bus_windows;
178 } else {
179 mod bus_windows;
180 #[cfg(feature = "dox")]
181 mod bus_unix;
182 }
183 }
184
185 mod child_proxy;
186 mod clock_time;
187 #[cfg(feature = "ser_de")]
188 mod clock_time_serde;
189 mod date_time;
190 #[cfg(feature = "ser_de")]
191 mod date_time_serde;
192 mod device_monitor;
193 mod device_provider;
194 mod enums;
195 pub use enums::MessageType;
196 mod ghost_pad;
197 mod gobject;
198 mod iterator;
199 mod object;
200 mod pad;
201 mod parse_context;
202 mod proxy_pad;
203 pub use proxy_pad::ProxyPadExtManual;
204 mod tag_setter;
205 pub use bin::GstBinExtManual;
206 pub use element::{ElementExtManual, ElementMessageType, NotifyWatchId};
207 pub use element::{
208 ELEMENT_METADATA_AUTHOR, ELEMENT_METADATA_DESCRIPTION, ELEMENT_METADATA_DOC_URI,
209 ELEMENT_METADATA_ICON_NAME, ELEMENT_METADATA_KLASS, ELEMENT_METADATA_LONGNAME,
210 };
211 pub use object::GstObjectExtManual;
212
213 // OS dependent Bus extensions (also import the other plateform trait for doc)
214 #[cfg(any(feature = "v1_14", feature = "dox"))]
215 cfg_if! {
216 if #[cfg(unix)] {
217 pub use bus_unix::UnixBusExtManual;
218 #[cfg(feature = "dox")]
219 pub use bus_windows::WindowsBusExtManual;
220 } else {
221 pub use bus_windows::WindowsBusExtManual;
222 #[cfg(feature = "dox")]
223 pub use bus_unix::UnixBusExtManual;
224 }
225 }
226
227 pub use self::iterator::{Iterator, IteratorError, IteratorImpl, StdIterator};
228 pub use bus::BusStream;
229 pub use child_proxy::ChildProxyExtManual;
230 pub use clock_time::ClockTime;
231 pub use device_monitor::{DeviceMonitorExtManual, DeviceMonitorFilterId};
232 pub use device_provider::DeviceProviderExtManual;
233 pub use enums::{
234 ClockError, ClockSuccess, FlowError, FlowSuccess, PadLinkError, PadLinkSuccess,
235 StateChangeError, StateChangeSuccess, TagError,
236 };
237 pub use gobject::GObjectExtManualGst;
238 pub use pad::{PadExtManual, PadProbeData, PadProbeId, PadProbeInfo};
239 pub use parse_context::ParseContext;
240 mod plugin_feature;
241 pub use plugin_feature::PluginFeatureExtManual;
242 pub use tag_setter::TagSetterExtManual;
243
244 mod plugin;
245 pub use plugin::GstPluginExtManual;
246 #[cfg(any(feature = "v1_10", feature = "dox"))]
247 pub mod stream;
248 #[cfg(any(feature = "v1_10", feature = "dox"))]
249 pub mod stream_collection;
250
251 mod typefind;
252 pub use typefind::*;
253
254 pub mod format;
255 pub use format::{FormattedValue, GenericFormattedValue, SpecificFormattedValue};
256 #[cfg(feature = "ser_de")]
257 mod format_serde;
258
259 mod segment;
260 pub use segment::*;
261 #[cfg(feature = "ser_de")]
262 mod segment_serde;
263
264 pub mod toc;
265 pub use toc::{Toc, TocEntry, TocEntryRef, TocRef};
266 #[cfg(feature = "ser_de")]
267 mod toc_serde;
268
269 mod clock;
270 pub use clock::{AtomicClockReturn, ClockExtManual, ClockId};
271
272 mod buffer_pool;
273 pub use buffer_pool::*;
274
275 mod pad_template;
276
277 mod param_spec;
278 pub use param_spec::*;
279
280 pub mod functions;
281 pub use functions::*;
282
283 use std::ptr;
284
init() -> Result<(), glib::Error>285 pub fn init() -> Result<(), glib::Error> {
286 unsafe {
287 let mut error = ptr::null_mut();
288 if from_glib(gst_sys::gst_init_check(
289 ptr::null_mut(),
290 ptr::null_mut(),
291 &mut error,
292 )) {
293 Ok(())
294 } else {
295 Err(from_glib_full(error))
296 }
297 }
298 }
299
300 /// Deinitialize GStreamer
301 ///
302 /// # Safety
303 ///
304 /// This must only be called once during the lifetime of the process, once no GStreamer threads
305 /// are running anymore and all GStreamer resources are released.
deinit()306 pub unsafe fn deinit() {
307 gst_sys::gst_deinit();
308 }
309
310 pub const BUFFER_OFFSET_NONE: u64 = gst_sys::GST_BUFFER_OFFSET_NONE;
311 pub const CLOCK_TIME_NONE: ClockTime = ClockTime(None);
312
313 pub const SECOND: ClockTime = ClockTime(Some(1_000_000_000));
314 pub const MSECOND: ClockTime = ClockTime(Some(1_000_000));
315 pub const USECOND: ClockTime = ClockTime(Some(1_000));
316 pub const NSECOND: ClockTime = ClockTime(Some(1));
317
318 pub const SECOND_VAL: u64 = 1_000_000_000;
319 pub const MSECOND_VAL: u64 = 1_000_000;
320 pub const USECOND_VAL: u64 = 1_000;
321 pub const NSECOND_VAL: u64 = 1;
322
323 pub const FORMAT_PERCENT_MAX: u32 = gst_sys::GST_FORMAT_PERCENT_MAX as u32;
324 pub const FORMAT_PERCENT_SCALE: u32 = gst_sys::GST_FORMAT_PERCENT_SCALE as u32;
325
326 // Re-export all the traits in a prelude module, so that applications
327 // can always "use gst::prelude::*" without getting conflicts
328 pub mod prelude {
329 pub use glib::prelude::*;
330
331 pub use auto::traits::*;
332
333 pub use meta::MetaAPI;
334
335 pub use allocator::AllocatorExtManual;
336 pub use bin::GstBinExtManual;
337 pub use element::ElementExtManual;
338
339 // OS dependent Bus extensions (also import the other plateform trait for doc)
340 #[cfg(any(feature = "v1_14", feature = "dox"))]
341 cfg_if! {
342 if #[cfg(unix)] {
343 pub use bus_unix::UnixBusExtManual;
344 #[cfg(feature = "dox")]
345 pub use bus_windows::WindowsBusExtManual;
346 } else {
347 pub use bus_windows::WindowsBusExtManual;
348 #[cfg(feature = "dox")]
349 pub use bus_unix::UnixBusExtManual;
350 }
351 }
352
353 pub use buffer_pool::BufferPoolExtManual;
354 pub use child_proxy::ChildProxyExtManual;
355 pub use clock::ClockExtManual;
356 pub use device_monitor::DeviceMonitorExtManual;
357 pub use device_provider::DeviceProviderExtManual;
358 pub use gobject::GObjectExtManualGst;
359 pub use message::MessageErrorDomain;
360 pub use object::GstObjectExtManual;
361 pub use pad::PadExtManual;
362 pub use param_spec::GstParamSpecExt;
363 pub use pipeline::GstPipelineExtManual;
364 pub use plugin::GstPluginExtManual;
365 pub use plugin_feature::PluginFeatureExtManual;
366 pub use proxy_pad::ProxyPadExtManual;
367 pub use tag_setter::TagSetterExtManual;
368 pub use typefind::TypeFindImpl;
369 pub use value::GstValueExt;
370
371 pub use miniobject::MiniObject;
372 pub use tags::{CustomTag, Tag};
373
374 pub use muldiv::MulDiv;
375
376 pub use format::{FormattedValue, SpecificFormattedValue};
377 }
378
379 mod utils;
380
381 #[macro_use]
382 pub mod subclass;
383