gstreamer: Add some API for add new items to a gst::Array and gst::List

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1157>
This commit is contained in:
Sebastian Dröge 2022-11-27 00:52:32 +02:00
parent ae4dd88f3d
commit 0bc16c65f0

View file

@ -724,6 +724,31 @@ impl Array {
}
}
}
pub fn append_value(&mut self, value: glib::SendValue) {
unsafe {
ffi::gst_value_array_append_and_take_value(
self.0.to_glib_none_mut().0,
&mut value.into_raw(),
);
}
}
pub fn append(&mut self, value: impl Into<glib::Value> + Send) {
self.append_value(glib::SendValue::from_owned(value));
}
}
impl Default for Array {
fn default() -> Self {
assert_initialized_main_thread!();
unsafe {
let value = glib::Value::for_value_type::<Array>();
Self(glib::SendValue::unsafe_from(value.into_raw()))
}
}
}
impl ops::Deref for Array {
@ -747,6 +772,14 @@ impl std::iter::FromIterator<glib::SendValue> for Array {
}
}
impl std::iter::Extend<glib::SendValue> for Array {
fn extend<T: IntoIterator<Item = glib::SendValue>>(&mut self, iter: T) {
for v in iter.into_iter() {
self.append_value(v);
}
}
}
impl glib::value::ValueType for Array {
type Type = Self;
}
@ -906,6 +939,31 @@ impl List {
}
}
}
pub fn append_value(&mut self, value: glib::SendValue) {
unsafe {
ffi::gst_value_list_append_and_take_value(
self.0.to_glib_none_mut().0,
&mut value.into_raw(),
);
}
}
pub fn append(&mut self, value: impl Into<glib::Value> + Send) {
self.append_value(glib::SendValue::from_owned(value));
}
}
impl Default for List {
fn default() -> Self {
assert_initialized_main_thread!();
unsafe {
let value = glib::Value::for_value_type::<List>();
Self(glib::SendValue::unsafe_from(value.into_raw()))
}
}
}
impl ops::Deref for List {
@ -929,6 +987,14 @@ impl std::iter::FromIterator<glib::SendValue> for List {
}
}
impl std::iter::Extend<glib::SendValue> for List {
fn extend<T: IntoIterator<Item = glib::SendValue>>(&mut self, iter: T) {
for v in iter.into_iter() {
self.append_value(v);
}
}
}
impl glib::value::ValueType for List {
type Type = Self;
}