mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-31 20:38:44 +00:00
Tags: more and better getters/adder factorizations
This commit is contained in:
parent
7ca54cf1c5
commit
02a8e9faa0
1 changed files with 7 additions and 35 deletions
|
@ -14,7 +14,7 @@ use std::mem;
|
||||||
use ffi;
|
use ffi;
|
||||||
use glib;
|
use glib;
|
||||||
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr, ToGlibPtrMut};
|
use glib::translate::{from_glib, from_glib_full, ToGlib, ToGlibPtr, ToGlibPtrMut};
|
||||||
use glib::value::{FromValueOptional, SendValue, SetValue, ToSendValue, TypedValue, Value};
|
use glib::value::{FromValueOptional, SendValue, SetValue, ToSendValue, TypedValue};
|
||||||
use glib::StaticType;
|
use glib::StaticType;
|
||||||
|
|
||||||
use miniobject::*;
|
use miniobject::*;
|
||||||
|
@ -177,16 +177,8 @@ impl TagListRef {
|
||||||
where
|
where
|
||||||
T::TagType: ToSendValue,
|
T::TagType: ToSendValue,
|
||||||
{
|
{
|
||||||
unsafe {
|
// result can be safely ignored here as `value`'s type is tied to `T::tag_name()`
|
||||||
let v = value.to_send_value();
|
let _res = self.add_generic(T::tag_name(), value, mode);
|
||||||
|
|
||||||
ffi::gst_tag_list_add_value(
|
|
||||||
self.as_mut_ptr(),
|
|
||||||
mode.to_glib(),
|
|
||||||
T::tag_name().to_glib_none().0,
|
|
||||||
v.to_glib_none().0,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_generic<T>(
|
pub fn add_generic<T>(
|
||||||
|
@ -220,21 +212,8 @@ impl TagListRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get<'a, T: Tag<'a>>(&self) -> Option<TypedValue<T::TagType>> {
|
pub fn get<'a, T: Tag<'a>>(&self) -> Option<TypedValue<T::TagType>> {
|
||||||
unsafe {
|
self.get_generic(T::tag_name())
|
||||||
let mut value: Value = mem::zeroed();
|
.and_then(|value| value.downcast().ok())
|
||||||
|
|
||||||
let found: bool = from_glib(ffi::gst_tag_list_copy_value(
|
|
||||||
value.to_glib_none_mut().0,
|
|
||||||
self.as_ptr(),
|
|
||||||
T::tag_name().to_glib_none().0,
|
|
||||||
));
|
|
||||||
|
|
||||||
if !found {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
value.downcast().ok()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_generic(&self, tag_name: &str) -> Option<SendValue> {
|
pub fn get_generic(&self, tag_name: &str) -> Option<SendValue> {
|
||||||
|
@ -265,14 +244,7 @@ impl TagListRef {
|
||||||
|
|
||||||
pub fn get_index<'a, T: Tag<'a>>(&'a self, idx: u32) -> Option<&'a TypedValue<T::TagType>> {
|
pub fn get_index<'a, T: Tag<'a>>(&'a self, idx: u32) -> Option<&'a TypedValue<T::TagType>> {
|
||||||
self.get_index_generic(T::tag_name(), idx)
|
self.get_index_generic(T::tag_name(), idx)
|
||||||
.and_then(|value| unsafe {
|
.and_then(|value| value.downcast_ref())
|
||||||
let value = value.to_glib_none().0;
|
|
||||||
if (*value).g_type != T::TagType::static_type().to_glib() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(&*(value as *const TypedValue<T::TagType>))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_index_generic<'a>(&'a self, tag_name: &str, idx: u32) -> Option<&'a SendValue> {
|
pub fn get_index_generic<'a>(&'a self, tag_name: &str, idx: u32) -> Option<&'a SendValue> {
|
||||||
|
@ -292,7 +264,7 @@ impl TagListRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_size<'a, T: Tag<'a>>(&self) -> u32 {
|
pub fn get_size<'a, T: Tag<'a>>(&self) -> u32 {
|
||||||
unsafe { ffi::gst_tag_list_get_tag_size(self.as_ptr(), T::tag_name().to_glib_none().0) }
|
self.get_size_by_name(T::tag_name())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_size_by_name(&self, tag_name: &str) -> u32 {
|
pub fn get_size_by_name(&self, tag_name: &str) -> u32 {
|
||||||
|
|
Loading…
Reference in a new issue