lib.rs 2.23 KB
Newer Older
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
extern crate array_init;
10 11 12
#[macro_use]
extern crate bitflags;

13 14
#[macro_use]
extern crate glib;
15 16 17
extern crate glib_sys as glib_ffi;
extern crate gobject_sys as gobject_ffi;
extern crate gstreamer as gst;
18 19
extern crate gstreamer_audio_sys as ffi;
extern crate gstreamer_sys as gst_ffi;
20

21
macro_rules! assert_initialized_main_thread {
22 23
    () => {
        if unsafe { ::gst_ffi::gst_is_initialized() } != ::glib_ffi::GTRUE {
24 25
            panic!("GStreamer has not been initialized. Call `gst::init` first.");
        }
26
    };
27 28
}

29
macro_rules! skip_assert_initialized {
30
    () => {};
31 32 33 34 35 36 37 38
}

pub use glib::{Cast, Continue, Error, IsA, StaticType, ToValue, Type, TypedValue, Value};

#[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))]
39
#[rustfmt::skip]
40 41 42
mod auto;
pub use auto::*;

43 44
mod audio_format;
pub use audio_format::*;
45 46 47 48
mod audio_format_info;
pub use audio_format_info::*;
mod audio_info;
pub use audio_info::*;
49 50
mod audio_channel_position;
pub use audio_channel_position::*;
Sebastian Dröge's avatar
Sebastian Dröge committed
51
#[cfg(any(feature = "v1_14", feature = "dox"))]
Sebastian Dröge's avatar
Sebastian Dröge committed
52
mod audio_stream_align;
53 54 55 56 57 58 59

use glib::translate::{from_glib_full, ToGlibPtr};
pub fn audio_buffer_clip(
    buffer: gst::Buffer,
    segment: &gst::Segment,
    rate: u32,
    channels: u32,
60
) -> Option<gst::Buffer> {
61 62
    skip_assert_initialized!();

63 64 65 66 67 68 69 70 71
    unsafe {
        from_glib_full(ffi::gst_audio_buffer_clip(
            buffer.into_ptr(),
            segment.to_glib_none().0,
            rate as i32,
            channels as i32,
        ))
    }
}
72 73 74 75 76 77 78 79 80

// 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 gst::prelude::*;

    pub use auto::traits::*;
}