mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-10-31 22:59:14 +00:00
Add GstContext bindings
This commit is contained in:
parent
b08a101cc6
commit
3fdc4cf5fc
2 changed files with 90 additions and 0 deletions
88
gstreamer/src/context.rs
Normal file
88
gstreamer/src/context.rs
Normal file
|
@ -0,0 +1,88 @@
|
|||
// 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.
|
||||
|
||||
use std::ffi::CStr;
|
||||
|
||||
use ffi;
|
||||
|
||||
use glib;
|
||||
use glib::StaticType;
|
||||
use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib, ToGlibPtr};
|
||||
|
||||
use miniobject::*;
|
||||
use StructureRef;
|
||||
|
||||
pub type Context = GstRc<ContextRef>;
|
||||
pub struct ContextRef(ffi::GstContext);
|
||||
|
||||
unsafe impl MiniObject for ContextRef {
|
||||
type GstType = ffi::GstContext;
|
||||
}
|
||||
|
||||
impl GstRc<ContextRef> {
|
||||
pub fn new(context_type: &str, persistent: bool) -> Self {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_context_new(
|
||||
context_type.to_glib_none().0,
|
||||
persistent.to_glib(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ContextRef {
|
||||
pub fn get_context_type(&self) -> &str {
|
||||
unsafe {
|
||||
let raw = ffi::gst_context_get_context_type(self.as_mut_ptr());
|
||||
CStr::from_ptr(raw).to_str().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_context_type(&self, context_type: &str) -> bool {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_context_has_context_type(
|
||||
self.as_mut_ptr(),
|
||||
context_type.to_glib_none().0,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_persistent(&self) -> bool {
|
||||
unsafe { from_glib(ffi::gst_context_is_persistent(self.as_mut_ptr())) }
|
||||
}
|
||||
|
||||
pub fn get_structure(&self) -> &StructureRef {
|
||||
unsafe { StructureRef::from_glib_borrow(ffi::gst_context_get_structure(self.as_mut_ptr())) }
|
||||
}
|
||||
|
||||
pub fn get_mut_structure(&mut self) -> &mut StructureRef {
|
||||
unsafe {
|
||||
StructureRef::from_glib_borrow_mut(
|
||||
ffi::gst_context_writable_structure(self.as_mut_ptr()),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StaticType for ContextRef {
|
||||
fn static_type() -> glib::Type {
|
||||
unsafe { from_glib(ffi::gst_context_get_type()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl ToOwned for ContextRef {
|
||||
type Owned = GstRc<ContextRef>;
|
||||
|
||||
fn to_owned(&self) -> GstRc<ContextRef> {
|
||||
unsafe { from_glib_none(self.as_ptr()) }
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Sync for ContextRef {}
|
||||
unsafe impl Send for ContextRef {}
|
|
@ -69,6 +69,8 @@ pub mod query;
|
|||
pub use query::{Query, QueryRef, QueryView};
|
||||
pub mod event;
|
||||
pub use event::{Event, EventRef, EventView};
|
||||
pub mod context;
|
||||
pub use context::{Context, ContextRef};
|
||||
|
||||
mod object;
|
||||
mod element;
|
||||
|
|
Loading…
Reference in a new issue