lib.rs 8.78 KB
Newer Older
Sebastian Dröge's avatar
Sebastian Dröge committed
1 2 3 4 5 6 7 8
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

9
#![recursion_limit = "256"]
Sebastian Dröge's avatar
Sebastian Dröge committed
10 11
#[macro_use]
extern crate bitflags;
12 13 14
#[cfg(any(feature = "v1_14", feature = "dox"))]
#[macro_use]
extern crate cfg_if;
15 16
#[macro_use]
extern crate lazy_static;
17
extern crate libc;
Sebastian Dröge's avatar
Sebastian Dröge committed
18

19 20 21 22 23 24 25
// Re-exported for the subclass gst_plugin_define! macro
#[doc(hidden)]
pub extern crate glib_sys as glib_ffi;
#[doc(hidden)]
pub extern crate gobject_sys as gobject_ffi;
#[doc(hidden)]
pub extern crate gstreamer_sys as ffi;
Sebastian Dröge's avatar
Sebastian Dröge committed
26 27

#[macro_use]
28 29
#[doc(hidden)]
pub extern crate glib;
Sebastian Dröge's avatar
Sebastian Dröge committed
30

Sebastian Dröge's avatar
Sebastian Dröge committed
31 32
extern crate num_rational;

33
#[cfg(any(feature = "futures", feature = "dox"))]
34
extern crate futures_core;
35

36 37
extern crate muldiv;

François Laignel's avatar
François Laignel committed
38 39 40
#[cfg(feature = "ser_de")]
extern crate serde;
#[cfg(feature = "ser_de")]
François Laignel's avatar
François Laignel committed
41 42
extern crate serde_bytes;
#[cfg(feature = "ser_de")]
François Laignel's avatar
François Laignel committed
43 44 45
#[macro_use]
extern crate serde_derive;

46 47
use glib::translate::{from_glib, from_glib_full};

48
macro_rules! assert_initialized_main_thread {
49 50
    () => {
        if unsafe { ::ffi::gst_is_initialized() } != ::glib_ffi::GTRUE {
51 52
            panic!("GStreamer has not been initialized. Call `gst::init` first.");
        }
53
    };
54 55 56
}

macro_rules! skip_assert_initialized {
57
    () => {};
58 59
}

60
pub use glib::{Cast, Continue, Error, IsA, StaticType, ToValue, Type, TypedValue, Value};
Sebastian Dröge's avatar
Sebastian Dröge committed
61

62 63 64 65
#[cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
#[cfg_attr(feature = "cargo-clippy", allow(too_many_arguments))]
#[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))]
66
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
67
#[rustfmt::skip]
Sebastian Dröge's avatar
Sebastian Dröge committed
68
mod auto;
Sebastian Dröge's avatar
Sebastian Dröge committed
69
pub use auto::functions::*;
70
pub use auto::*;
Sebastian Dröge's avatar
Sebastian Dröge committed
71

72 73 74 75
#[macro_use]
mod log;
pub use log::*;

Sebastian Dröge's avatar
Sebastian Dröge committed
76 77 78 79
#[macro_use]
mod error;
pub use error::*;

80
#[macro_use]
81
pub mod miniobject;
82
pub use miniobject::{GstRc, MiniObject};
83
pub mod message;
84
pub use message::{Message, MessageErrorDomain, MessageRef, MessageView};
85

François Laignel's avatar
François Laignel committed
86 87
mod value;
pub use value::*;
88 89
#[cfg(feature = "ser_de")]
#[macro_use]
90
mod value_serde;
91

92
pub mod structure;
Sebastian Dröge's avatar
Sebastian Dröge committed
93
pub use structure::{Structure, StructureRef};
94
#[cfg(feature = "ser_de")]
95
mod structure_serde;
96

Sebastian Dröge's avatar
Sebastian Dröge committed
97
pub mod caps;
Sebastian Dröge's avatar
Sebastian Dröge committed
98
pub use caps::{Caps, CapsRef};
99
mod caps_features;
100
#[cfg(feature = "ser_de")]
101
mod caps_serde;
102 103 104 105
pub use caps_features::{
    CapsFeatures, CapsFeaturesRef, CAPS_FEATURES_MEMORY_SYSTEM_MEMORY,
    CAPS_FEATURE_MEMORY_SYSTEM_MEMORY,
};
106 107
#[cfg(feature = "ser_de")]
mod caps_features_serde;
108

Sebastian Dröge's avatar
Sebastian Dröge committed
109
pub mod tags;
110
pub use tags::{Tag, TagList, TagListRef};
111
#[cfg(feature = "ser_de")]
112
mod tags_serde;
113

114 115
pub mod meta;
pub use meta::{Meta, MetaAPI, MetaRef, MetaRefMut, ParentBufferMeta};
116
pub mod buffer;
117 118 119
pub use buffer::{
    Buffer, BufferMap, BufferRef, MappedBuffer, BUFFER_COPY_ALL, BUFFER_COPY_METADATA,
};
120
#[cfg(feature = "ser_de")]
121
mod buffer_serde;
122

Sebastian Dröge's avatar
Sebastian Dröge committed
123 124
pub mod sample;
pub use sample::{Sample, SampleRef};
125
#[cfg(feature = "ser_de")]
126
mod sample_serde;
127

Sebastian Dröge's avatar
Sebastian Dröge committed
128 129
pub mod bufferlist;
pub use bufferlist::{BufferList, BufferListRef};
130
#[cfg(feature = "ser_de")]
131
mod bufferlist_serde;
132

Sebastian Dröge's avatar
Sebastian Dröge committed
133 134
pub mod query;
pub use query::{Query, QueryRef, QueryView};
Sebastian Dröge's avatar
Sebastian Dröge committed
135
pub mod event;
136
pub use event::{Event, EventRef, EventView, GroupId, Seqnum, GROUP_ID_INVALID, SEQNUM_INVALID};
Sebastian Dröge's avatar
Sebastian Dröge committed
137 138
pub mod context;
pub use context::{Context, ContextRef};
139 140 141 142
mod static_caps;
pub use static_caps::*;
mod static_pad_template;
pub use static_pad_template::*;
143

Sebastian Dröge's avatar
Sebastian Dröge committed
144 145 146 147 148
#[cfg(any(feature = "v1_14", feature = "dox"))]
mod promise;
#[cfg(any(feature = "v1_14", feature = "dox"))]
pub use promise::*;

149
mod bus;
150
mod element;
151

Sebastian Dröge's avatar
Sebastian Dröge committed
152
mod bin;
Sebastian Dröge's avatar
Sebastian Dröge committed
153

154 155 156 157 158 159 160 161 162 163 164 165 166 167
// OS dependent Bus extensions (also import the other plateform mod for doc)
#[cfg(any(feature = "v1_14", feature = "dox"))]
cfg_if! {
    if #[cfg(unix)] {
        mod bus_unix;
        #[cfg(feature = "dox")]
        mod bus_windows;
    } else {
        mod bus_windows;
        #[cfg(feature = "dox")]
        mod bus_unix;
    }
}

Sebastian Dröge's avatar
Sebastian Dröge committed
168
mod child_proxy;
169
mod clock_time;
170
#[cfg(feature = "ser_de")]
171
mod clock_time_serde;
172
mod date_time;
173 174
#[cfg(feature = "ser_de")]
mod date_time_serde;
175
mod device_monitor;
176 177 178 179 180 181 182 183 184 185
mod device_provider;
mod enums;
mod ghost_pad;
mod gobject;
mod iterator;
mod object;
mod pad;
mod parse_context;
mod proxy_pad;
mod tag_setter;
186
pub use bin::GstBinExtManual;
187
pub use element::{ElementExtManual, ElementMessageType, NotifyWatchId};
188 189 190 191
pub use element::{
    ELEMENT_METADATA_AUTHOR, ELEMENT_METADATA_DESCRIPTION, ELEMENT_METADATA_DOC_URI,
    ELEMENT_METADATA_ICON_NAME, ELEMENT_METADATA_KLASS, ELEMENT_METADATA_LONGNAME,
};
192
pub use object::GstObjectExtManual;
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207

// OS dependent Bus extensions (also import the other plateform trait for doc)
#[cfg(any(feature = "v1_14", feature = "dox"))]
cfg_if! {
    if #[cfg(unix)] {
        pub use bus_unix::UnixBusExtManual;
        #[cfg(feature = "dox")]
        pub use bus_windows::WindowsBusExtManual;
    } else {
        pub use bus_windows::WindowsBusExtManual;
        #[cfg(feature = "dox")]
        pub use bus_unix::UnixBusExtManual;
    }
}

208
pub use self::iterator::{Iterator, IteratorError, IteratorImpl};
209
#[cfg(any(feature = "futures", feature = "dox"))]
210
pub use bus::BusStream;
211 212 213
pub use child_proxy::ChildProxyExtManual;
pub use clock_time::ClockTime;
pub use device_provider::DeviceProviderExtManual;
214 215 216 217
pub use enums::{
    ClockError, ClockSuccess, FlowError, FlowSuccess, PadLinkError, PadLinkSuccess,
    StateChangeError, StateChangeSuccess, TagError,
};
218 219 220 221
pub use gobject::GObjectExtManualGst;
pub use pad::{PadExtManual, PadProbeData, PadProbeId, PadProbeInfo};
pub use parse_context::ParseContext;
pub use tag_setter::TagSetterExtManual;
222

223
mod plugin;
224
#[cfg(any(feature = "v1_10", feature = "dox"))]
225
mod stream;
226 227
#[cfg(any(feature = "v1_10", feature = "dox"))]
pub mod stream_collection;
228

229 230 231
mod typefind;
pub use typefind::*;

232 233
pub mod format;
pub use format::{FormattedValue, GenericFormattedValue, SpecificFormattedValue};
234
#[cfg(feature = "ser_de")]
235
mod format_serde;
236

237 238
mod segment;
pub use segment::*;
239
#[cfg(feature = "ser_de")]
240
mod segment_serde;
241

242 243
pub mod toc;
pub use toc::{Toc, TocEntry, TocEntryRef, TocRef};
244
#[cfg(feature = "ser_de")]
245
mod toc_serde;
246

247
mod clock;
248
pub use clock::{ClockExtManual, ClockId};
249

250 251 252
mod buffer_pool;
pub use buffer_pool::*;

Sebastian Dröge's avatar
Sebastian Dröge committed
253 254
mod pad_template;

255 256 257
mod param_spec;
pub use param_spec::*;

258 259 260
pub mod functions;
pub use functions::*;

Sebastian Dröge's avatar
Sebastian Dröge committed
261 262
use std::ptr;

263
pub fn init() -> Result<(), glib::Error> {
Sebastian Dröge's avatar
Sebastian Dröge committed
264
    unsafe {
265
        let mut error = ptr::null_mut();
266 267 268 269 270
        if from_glib(ffi::gst_init_check(
            ptr::null_mut(),
            ptr::null_mut(),
            &mut error,
        )) {
271 272 273 274
            Ok(())
        } else {
            Err(from_glib_full(error))
        }
Sebastian Dröge's avatar
Sebastian Dröge committed
275 276
    }
}
277

278 279 280 281
pub unsafe fn deinit() {
    ffi::gst_deinit();
}

282
pub const BUFFER_OFFSET_NONE: u64 = ffi::GST_BUFFER_OFFSET_NONE;
283 284 285 286 287 288
pub const CLOCK_TIME_NONE: ClockTime = ClockTime(None);

pub const SECOND: ClockTime = ClockTime(Some(1_000_000_000));
pub const MSECOND: ClockTime = ClockTime(Some(1_000_000));
pub const USECOND: ClockTime = ClockTime(Some(1_000));
pub const NSECOND: ClockTime = ClockTime(Some(1));
289

290 291 292 293 294
pub const SECOND_VAL: u64 = 1_000_000_000;
pub const MSECOND_VAL: u64 = 1_000_000;
pub const USECOND_VAL: u64 = 1_000;
pub const NSECOND_VAL: u64 = 1;

295 296
pub const FORMAT_PERCENT_MAX: u32 = ffi::GST_FORMAT_PERCENT_MAX as u32;
pub const FORMAT_PERCENT_SCALE: u32 = ffi::GST_FORMAT_PERCENT_SCALE as u32;
297 298 299 300 301 302 303 304

// Re-export all the traits in a prelude module, so that applications
// can always "use gst::prelude::*" without getting conflicts
pub mod prelude {
    pub use glib::prelude::*;

    pub use auto::traits::*;

305 306
    pub use meta::MetaAPI;

307
    pub use bin::GstBinExtManual;
308
    pub use element::ElementExtManual;
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323

    // OS dependent Bus extensions (also import the other plateform trait for doc)
    #[cfg(any(feature = "v1_14", feature = "dox"))]
    cfg_if! {
        if #[cfg(unix)] {
            pub use bus_unix::UnixBusExtManual;
            #[cfg(feature = "dox")]
            pub use bus_windows::WindowsBusExtManual;
        } else {
            pub use bus_windows::WindowsBusExtManual;
            #[cfg(feature = "dox")]
            pub use bus_unix::UnixBusExtManual;
        }
    }

324
    pub use buffer_pool::BufferPoolExtManual;
325 326
    pub use child_proxy::ChildProxyExtManual;
    pub use clock::ClockExtManual;
327 328 329 330
    pub use device_provider::DeviceProviderExtManual;
    pub use gobject::GObjectExtManualGst;
    pub use object::GstObjectExtManual;
    pub use pad::PadExtManual;
331
    pub use param_spec::GstParamSpecExt;
332
    pub use tag_setter::TagSetterExtManual;
333 334 335
    pub use value::GstValueExt;

    pub use miniobject::MiniObject;
336
    pub use tags::Tag;
337 338

    pub use muldiv::MulDiv;
339 340

    pub use format::{FormattedValue, SpecificFormattedValue};
341
}
342 343

mod utils;
344 345 346 347

#[macro_use]
#[cfg(feature = "subclassing")]
pub mod subclass;