From 210d64109195a830d97350f2eee668098b2a9050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 28 Jul 2017 18:04:15 +0100 Subject: [PATCH] Implement Sample bindings --- gstreamer/src/lib.rs | 2 + gstreamer/src/sample.rs | 92 ++++++++++++++++++++++++++++++++++++++++ gstreamer/src/segment.rs | 2 + gstreamer/src/tags.rs | 9 ++++ 4 files changed, 105 insertions(+) create mode 100644 gstreamer/src/sample.rs diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 28097af8a..30f17ab4c 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -58,6 +58,8 @@ pub mod tags; pub use tags::*; pub mod buffer; pub use buffer::{Buffer, BufferRef, ReadBufferMap, ReadWriteBufferMap, ReadMappedBuffer, ReadWriteMappedBuffer}; +pub mod sample; +pub use sample::{Sample, SampleRef}; mod element; mod bin; diff --git a/gstreamer/src/sample.rs b/gstreamer/src/sample.rs new file mode 100644 index 000000000..185c5993e --- /dev/null +++ b/gstreamer/src/sample.rs @@ -0,0 +1,92 @@ +// Copyright (C) 2017 Sebastian Dröge +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::ptr; + +use ffi; + +use glib; +use glib::StaticType; +use glib::translate::{mut_override, from_glib, from_glib_none, from_glib_full, ToGlibPtr}; + +use miniobject::*; +use Buffer; +use Caps; +use Segment; +use StructureRef; + +pub type Sample = GstRc; +pub struct SampleRef(ffi::GstSample); + +unsafe impl MiniObject for SampleRef { + type GstType = ffi::GstSample; +} + +impl GstRc { + pub fn new(buffer: Option, caps: Option, segment: Option<&Segment>, info: Option<&StructureRef>) -> Self { + assert_initialized_main_thread!(); + unsafe { + let info = info.map(|i| i.as_ptr()).unwrap_or(ptr::null()); + + from_glib_full(ffi::gst_sample_new(buffer.to_glib_none().0, caps.to_glib_none().0, mut_override(segment.to_glib_none().0), mut_override(info))) + } + } +} + +impl SampleRef { + pub fn get_buffer(&self) -> Option { + unsafe { + from_glib_none(ffi::gst_sample_get_buffer(self.as_mut_ptr())) + } + } + + // TODO: bufferlist + + pub fn get_caps(&self) -> Option { + unsafe { + from_glib_none(ffi::gst_sample_get_caps(self.as_mut_ptr())) + } + } + + pub fn get_segment(&self) -> Option { + unsafe { + from_glib_none(ffi::gst_sample_get_segment(self.as_mut_ptr())) + } + } + + pub fn get_structure(&self) -> Option<&StructureRef> { + unsafe { + let ptr = ffi::gst_sample_get_info(self.as_mut_ptr()); + if ptr.is_null() { + None + } else { + Some(StructureRef::from_glib_borrow(ptr)) + } + } + } +} + +impl StaticType for SampleRef { + fn static_type() -> glib::Type { + unsafe { + from_glib(ffi::gst_sample_get_type()) + } + } +} + +impl ToOwned for SampleRef { + type Owned = GstRc; + + fn to_owned(&self) -> GstRc { + unsafe { from_glib_none(self.as_ptr()) } + } +} + +unsafe impl Sync for SampleRef {} +unsafe impl Send for SampleRef {} + diff --git a/gstreamer/src/segment.rs b/gstreamer/src/segment.rs index a4785c96d..fb157f1a1 100644 --- a/gstreamer/src/segment.rs +++ b/gstreamer/src/segment.rs @@ -12,6 +12,8 @@ use Format; use glib::translate::{from_glib, ToGlib, ToGlibPtr, ToGlibPtrMut}; +// TODO: Plain struct implementation without heap allocation + impl Segment { pub fn set_flags(&mut self, flags: SegmentFlags) { unsafe { diff --git a/gstreamer/src/tags.rs b/gstreamer/src/tags.rs index e8106b6a5..8809f178d 100644 --- a/gstreamer/src/tags.rs +++ b/gstreamer/src/tags.rs @@ -11,6 +11,7 @@ use std::mem; use std::marker::PhantomData; use ffi; +use glib; use glib::StaticType; use glib::value::{Value, TypedValue, FromValueOptional, SetValue, ToValue}; use glib::translate::{from_glib, from_glib_none, from_glib_full, ToGlib, ToGlibPtr, ToGlibPtrMut}; @@ -149,6 +150,14 @@ impl ToOwned for TagListRef { } } +impl StaticType for TagListRef { + fn static_type() -> glib::Type { + unsafe { + from_glib(ffi::gst_tag_list_get_type()) + } + } +} + unsafe impl Sync for TagListRef {} unsafe impl Send for TagListRef {}