2017-08-02 17:34:37 +00:00
|
|
|
// 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;
|
2018-04-01 08:30:03 +00:00
|
|
|
use std::fmt;
|
2017-08-02 17:34:37 +00:00
|
|
|
|
2019-03-19 07:58:20 +00:00
|
|
|
use gst_sys;
|
2017-08-02 17:34:37 +00:00
|
|
|
|
|
|
|
use glib;
|
2018-12-08 11:06:44 +00:00
|
|
|
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr};
|
2017-08-02 17:34:37 +00:00
|
|
|
|
2018-04-25 08:10:06 +00:00
|
|
|
use StructureRef;
|
2017-08-02 17:34:37 +00:00
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
gst_define_mini_object_wrapper!(Context, ContextRef, gst_sys::GstContext, || {
|
2019-03-19 07:58:20 +00:00
|
|
|
gst_sys::gst_context_get_type()
|
2018-09-28 15:11:46 +00:00
|
|
|
});
|
2017-08-02 17:34:37 +00:00
|
|
|
|
2018-09-28 15:11:46 +00:00
|
|
|
impl Context {
|
2017-08-02 17:34:37 +00:00
|
|
|
pub fn new(context_type: &str, persistent: bool) -> Self {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
2019-03-19 07:58:20 +00:00
|
|
|
from_glib_full(gst_sys::gst_context_new(
|
2017-08-02 17:34:37 +00:00
|
|
|
context_type.to_glib_none().0,
|
|
|
|
persistent.to_glib(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ContextRef {
|
|
|
|
pub fn get_context_type(&self) -> &str {
|
|
|
|
unsafe {
|
2019-03-19 07:58:20 +00:00
|
|
|
let raw = gst_sys::gst_context_get_context_type(self.as_mut_ptr());
|
2017-08-02 17:34:37 +00:00
|
|
|
CStr::from_ptr(raw).to_str().unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn has_context_type(&self, context_type: &str) -> bool {
|
|
|
|
unsafe {
|
2019-03-19 07:58:20 +00:00
|
|
|
from_glib(gst_sys::gst_context_has_context_type(
|
2017-08-02 17:34:37 +00:00
|
|
|
self.as_mut_ptr(),
|
|
|
|
context_type.to_glib_none().0,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_persistent(&self) -> bool {
|
2019-03-19 07:58:20 +00:00
|
|
|
unsafe { from_glib(gst_sys::gst_context_is_persistent(self.as_mut_ptr())) }
|
2017-08-02 17:34:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_structure(&self) -> &StructureRef {
|
2019-03-19 07:58:20 +00:00
|
|
|
unsafe {
|
|
|
|
StructureRef::from_glib_borrow(gst_sys::gst_context_get_structure(self.as_mut_ptr()))
|
|
|
|
}
|
2017-08-02 17:34:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_mut_structure(&mut self) -> &mut StructureRef {
|
|
|
|
unsafe {
|
2019-03-19 07:58:20 +00:00
|
|
|
StructureRef::from_glib_borrow_mut(gst_sys::gst_context_writable_structure(
|
2017-12-20 17:30:14 +00:00
|
|
|
self.as_mut_ptr(),
|
|
|
|
))
|
2017-08-02 17:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 21:12:46 +00:00
|
|
|
impl fmt::Debug for Context {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
ContextRef::fmt(self, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 09:21:20 +00:00
|
|
|
impl fmt::Debug for ContextRef {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.debug_struct("Context")
|
|
|
|
.field("type", &self.get_context_type())
|
|
|
|
.field("structure", &self.get_structure())
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|