forked from mirrors/gstreamer-rs
Implement all caps/structure operations
Except for anything related to caps features
This commit is contained in:
parent
aadf2e3b30
commit
28f665502b
5 changed files with 289 additions and 10 deletions
|
@ -51,6 +51,7 @@ generate = [
|
|||
"Gst.TagMergeMode",
|
||||
"Gst.PadProbeType",
|
||||
"Gst.PadProbeReturn",
|
||||
"Gst.CapsIntersectMode",
|
||||
]
|
||||
|
||||
manual = [
|
||||
|
|
|
@ -134,6 +134,63 @@ impl SetValue for BusSyncReply {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum CapsIntersectMode {
|
||||
ZigZag,
|
||||
First,
|
||||
#[doc(hidden)]
|
||||
__Unknown(i32),
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl ToGlib for CapsIntersectMode {
|
||||
type GlibType = ffi::GstCapsIntersectMode;
|
||||
|
||||
fn to_glib(&self) -> ffi::GstCapsIntersectMode {
|
||||
match *self {
|
||||
CapsIntersectMode::ZigZag => ffi::GST_CAPS_INTERSECT_ZIG_ZAG,
|
||||
CapsIntersectMode::First => ffi::GST_CAPS_INTERSECT_FIRST,
|
||||
CapsIntersectMode::__Unknown(value) => unsafe{std::mem::transmute(value)}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl FromGlib<ffi::GstCapsIntersectMode> for CapsIntersectMode {
|
||||
fn from_glib(value: ffi::GstCapsIntersectMode) -> Self {
|
||||
skip_assert_initialized!();
|
||||
match value as i32 {
|
||||
0 => CapsIntersectMode::ZigZag,
|
||||
1 => CapsIntersectMode::First,
|
||||
value => CapsIntersectMode::__Unknown(value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StaticType for CapsIntersectMode {
|
||||
fn static_type() -> Type {
|
||||
unsafe { from_glib(ffi::gst_caps_intersect_mode_get_type()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> FromValueOptional<'a> for CapsIntersectMode {
|
||||
unsafe fn from_value_optional(value: &Value) -> Option<Self> {
|
||||
Some(FromValue::from_value(value))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> FromValue<'a> for CapsIntersectMode {
|
||||
unsafe fn from_value(value: &Value) -> Self {
|
||||
from_glib(std::mem::transmute::<i32, ffi::GstCapsIntersectMode>(gobject_ffi::g_value_get_enum(value.to_glib_none().0)))
|
||||
}
|
||||
}
|
||||
|
||||
impl SetValue for CapsIntersectMode {
|
||||
unsafe fn set_value(value: &mut Value, this: &Self) {
|
||||
gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib() as i32)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
|
||||
pub enum CoreError {
|
||||
Failed,
|
||||
|
|
|
@ -75,6 +75,7 @@ pub use self::u_r_i_handler::URIHandlerExt;
|
|||
mod enums;
|
||||
pub use self::enums::BufferingMode;
|
||||
pub use self::enums::BusSyncReply;
|
||||
pub use self::enums::CapsIntersectMode;
|
||||
pub use self::enums::CoreError;
|
||||
pub use self::enums::FlowReturn;
|
||||
pub use self::enums::Format;
|
||||
|
|
|
@ -11,9 +11,11 @@ use std::str;
|
|||
use miniobject::*;
|
||||
use structure::*;
|
||||
|
||||
use CapsIntersectMode;
|
||||
|
||||
use glib;
|
||||
use ffi;
|
||||
use glib::translate::{from_glib, from_glib_none, from_glib_full, ToGlibPtr};
|
||||
use glib::translate::{from_glib, from_glib_none, from_glib_full, ToGlibPtr, ToGlib};
|
||||
|
||||
#[repr(C)]
|
||||
pub struct CapsRef(ffi::GstCaps);
|
||||
|
@ -57,6 +59,39 @@ impl GstRc<CapsRef> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fixate(caps: Self) -> Self {
|
||||
unsafe { from_glib_full(ffi::gst_caps_fixate(caps.into_ptr())) }
|
||||
}
|
||||
|
||||
pub fn merge(caps: Self, other: Self) -> Self {
|
||||
unsafe { from_glib_full(ffi::gst_caps_merge(caps.into_ptr(), other.into_ptr())) }
|
||||
}
|
||||
|
||||
pub fn merge_structure(caps: Self, other: Structure) -> Self {
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_caps_merge_structure(
|
||||
caps.into_ptr(),
|
||||
other.into_ptr(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn normalize(caps: Self) -> Self {
|
||||
unsafe { from_glib_full(ffi::gst_caps_normalize(caps.into_ptr())) }
|
||||
}
|
||||
|
||||
pub fn simplify(caps: Self) -> Self {
|
||||
unsafe { from_glib_full(ffi::gst_caps_simplify(caps.into_ptr())) }
|
||||
}
|
||||
|
||||
pub fn subtract(caps: Self, other: Self) -> Self {
|
||||
unsafe { from_glib_full(ffi::gst_caps_subtract(caps.into_ptr(), other.into_ptr())) }
|
||||
}
|
||||
|
||||
pub fn truncate(caps: Self) -> Self {
|
||||
unsafe { from_glib_full(ffi::gst_caps_truncate(caps.into_ptr())) }
|
||||
}
|
||||
}
|
||||
|
||||
impl str::FromStr for Caps {
|
||||
|
@ -110,10 +145,6 @@ impl CapsRef {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn append_structure(&mut self, structure: Structure) {
|
||||
unsafe { ffi::gst_caps_append_structure(self.as_mut_ptr(), structure.into_ptr()) }
|
||||
}
|
||||
|
||||
pub fn get_size(&self) -> u32 {
|
||||
unsafe { ffi::gst_caps_get_size(self.as_ptr()) }
|
||||
}
|
||||
|
@ -126,7 +157,87 @@ impl CapsRef {
|
|||
IterMut::new(self)
|
||||
}
|
||||
|
||||
// TODO: All kinds of caps operations
|
||||
pub fn append_structure(&mut self, structure: Structure) {
|
||||
unsafe { ffi::gst_caps_append_structure(self.as_mut_ptr(), structure.into_ptr()) }
|
||||
}
|
||||
|
||||
pub fn remove_structure(&mut self, idx: u32) {
|
||||
unsafe { ffi::gst_caps_remove_structure(self.as_mut_ptr(), idx) }
|
||||
}
|
||||
|
||||
pub fn append(&mut self, other: Caps) {
|
||||
unsafe { ffi::gst_caps_append(self.as_mut_ptr(), other.into_ptr()) }
|
||||
}
|
||||
|
||||
pub fn can_intersect(&self, other: &Caps) -> bool {
|
||||
unsafe { from_glib(ffi::gst_caps_can_intersect(self.as_ptr(), other.as_ptr())) }
|
||||
}
|
||||
|
||||
pub fn intersect(&self, other: &Caps) -> Caps {
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_caps_intersect(
|
||||
self.as_mut_ptr(),
|
||||
other.as_mut_ptr(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn intersect_with_mode(&self, other: &Caps, mode: CapsIntersectMode) -> Caps {
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_caps_intersect_full(
|
||||
self.as_mut_ptr(),
|
||||
other.as_mut_ptr(),
|
||||
mode.to_glib(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_always_compatible(&self, other: &Caps) -> bool {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_caps_is_always_compatible(
|
||||
self.as_ptr(),
|
||||
other.as_ptr(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_any(&self) -> bool {
|
||||
unsafe { from_glib(ffi::gst_caps_is_any(self.as_ptr())) }
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
unsafe { from_glib(ffi::gst_caps_is_empty(self.as_ptr())) }
|
||||
}
|
||||
|
||||
pub fn is_fixed(&self) -> bool {
|
||||
unsafe { from_glib(ffi::gst_caps_is_fixed(self.as_ptr())) }
|
||||
}
|
||||
|
||||
pub fn is_equal_fixed(&self, other: &Caps) -> bool {
|
||||
unsafe { from_glib(ffi::gst_caps_is_equal_fixed(self.as_ptr(), other.as_ptr())) }
|
||||
}
|
||||
|
||||
pub fn is_strictly_equal(&self, other: &Caps) -> bool {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_caps_is_strictly_equal(
|
||||
self.as_ptr(),
|
||||
other.as_ptr(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_subset(&self, superset: &Caps) -> bool {
|
||||
unsafe { from_glib(ffi::gst_caps_is_subset(self.as_ptr(), superset.as_ptr())) }
|
||||
}
|
||||
|
||||
pub fn is_subset_structure(&self, structure: &StructureRef) -> bool {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_caps_is_subset_structure(
|
||||
self.as_ptr(),
|
||||
structure.as_ptr(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl glib::types::StaticType for GstRc<CapsRef> {
|
||||
|
|
|
@ -15,8 +15,10 @@ use std::ops::{Deref, DerefMut};
|
|||
use std::borrow::{Borrow, ToOwned, BorrowMut};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use Fraction;
|
||||
|
||||
use glib;
|
||||
use glib::translate::{from_glib, from_glib_full, Stash, StashMut, ToGlibPtr, ToGlibPtrMut,
|
||||
use glib::translate::{from_glib, from_glib_full, Stash, StashMut, ToGlib, ToGlibPtr, ToGlibPtrMut,
|
||||
FromGlibPtrNone, FromGlibPtrFull};
|
||||
use glib::value::{Value, ToValue, FromValueOptional};
|
||||
use ffi;
|
||||
|
@ -239,6 +241,14 @@ impl StructureRef {
|
|||
&mut *(ptr as *mut StructureRef)
|
||||
}
|
||||
|
||||
pub unsafe fn as_ptr(&self) -> *const ffi::GstStructure {
|
||||
self as *const Self as *const ffi::GstStructure
|
||||
}
|
||||
|
||||
pub unsafe fn as_mut_ptr(&self) -> *mut ffi::GstStructure {
|
||||
self as *const Self as *mut ffi::GstStructure
|
||||
}
|
||||
|
||||
pub fn to_string(&self) -> String {
|
||||
unsafe { from_glib_full(ffi::gst_structure_to_string(&self.0)) }
|
||||
}
|
||||
|
@ -283,6 +293,10 @@ impl StructureRef {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn set_name(&mut self, name: &str) {
|
||||
unsafe { ffi::gst_structure_set_name(&mut self.0, name.to_glib_none().0) }
|
||||
}
|
||||
|
||||
pub fn has_field(&self, field: &str) -> bool {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_structure_has_field(
|
||||
|
@ -292,12 +306,28 @@ impl StructureRef {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn has_field_with_type(&self, field: &str, type_: glib::Type) -> bool {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_structure_has_field_typed(
|
||||
&self.0,
|
||||
field.to_glib_none().0,
|
||||
type_.to_glib(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_field(&mut self, field: &str) {
|
||||
unsafe {
|
||||
ffi::gst_structure_remove_field(&mut self.0, field.to_glib_none().0);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_fields(&mut self, fields: &[&str]) {
|
||||
for f in fields {
|
||||
self.remove_field(f)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remove_all_fields(&mut self) {
|
||||
unsafe {
|
||||
ffi::gst_structure_remove_all_fields(&mut self.0);
|
||||
|
@ -312,7 +342,7 @@ impl StructureRef {
|
|||
Iter::new(self)
|
||||
}
|
||||
|
||||
fn get_nth_field_name(&self, idx: u32) -> Option<&str> {
|
||||
pub fn get_nth_field_name(&self, idx: u32) -> Option<&str> {
|
||||
unsafe {
|
||||
let field_name = ffi::gst_structure_nth_field_name(&self.0, idx);
|
||||
if field_name.is_null() {
|
||||
|
@ -323,11 +353,90 @@ impl StructureRef {
|
|||
}
|
||||
}
|
||||
|
||||
fn n_fields(&self) -> u32 {
|
||||
pub fn n_fields(&self) -> u32 {
|
||||
unsafe { ffi::gst_structure_n_fields(&self.0) as u32 }
|
||||
}
|
||||
|
||||
// TODO: Various operations
|
||||
pub fn can_intersect(&self, other: &StructureRef) -> bool {
|
||||
unsafe { from_glib(ffi::gst_structure_can_intersect(&self.0, &other.0)) }
|
||||
}
|
||||
|
||||
pub fn intersect(&self, other: &StructureRef) -> Structure {
|
||||
unsafe { from_glib_full(ffi::gst_structure_intersect(&self.0, &other.0)) }
|
||||
}
|
||||
|
||||
pub fn is_subset(&self, superset: &StructureRef) -> bool {
|
||||
unsafe { from_glib(ffi::gst_structure_is_subset(&self.0, &superset.0)) }
|
||||
}
|
||||
|
||||
pub fn fixate(&mut self) {
|
||||
unsafe { ffi::gst_structure_fixate(&mut self.0) }
|
||||
}
|
||||
|
||||
pub fn fixate_field(&mut self, name: &str) -> bool {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_structure_fixate_field(
|
||||
&mut self.0,
|
||||
name.to_glib_none().0,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fixate_field_bool(&mut self, name: &str, target: bool) -> bool {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_structure_fixate_field_boolean(
|
||||
&mut self.0,
|
||||
name.to_glib_none().0,
|
||||
target.to_glib(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fixate_field_str(&mut self, name: &str, target: &str) -> bool {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_structure_fixate_field_string(
|
||||
&mut self.0,
|
||||
name.to_glib_none().0,
|
||||
target.to_glib_none().0,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fixate_field_nearest_double(&mut self, name: &str, target: f64) -> bool {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_structure_fixate_field_nearest_double(
|
||||
&mut self.0,
|
||||
name.to_glib_none().0,
|
||||
target,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fixate_field_nearest_fraction<T: Into<Fraction>>(
|
||||
&mut self,
|
||||
name: &str,
|
||||
target: T,
|
||||
) -> bool {
|
||||
let target = target.into();
|
||||
unsafe {
|
||||
from_glib(ffi::gst_structure_fixate_field_nearest_fraction(
|
||||
&mut self.0,
|
||||
name.to_glib_none().0,
|
||||
*target.numer(),
|
||||
*target.denom(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fixate_field_nearest_int(&mut self, name: &str, target: i32) -> bool {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_structure_fixate_field_nearest_int(
|
||||
&mut self.0,
|
||||
name.to_glib_none().0,
|
||||
target,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for StructureRef {
|
||||
|
|
Loading…
Reference in a new issue