From 4a8e860a9eb69110fac01a434334389866c2f334 Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Sun, 12 May 2019 18:17:33 +0300 Subject: [PATCH] gstreamer-video: Expose VideoBufferPool Closes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/12 --- Gir_GstVideo.toml | 2 + gstreamer-video/src/auto/mod.rs | 3 + gstreamer-video/src/auto/video_buffer_pool.rs | 36 +++++++++ gstreamer-video/src/lib.rs | 6 +- gstreamer-video/src/video_buffer_pool.rs | 81 +++++++++++++++++++ 5 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 gstreamer-video/src/auto/video_buffer_pool.rs diff --git a/Gir_GstVideo.toml b/Gir_GstVideo.toml index a0778138d..c3bf8920a 100644 --- a/Gir_GstVideo.toml +++ b/Gir_GstVideo.toml @@ -37,11 +37,13 @@ generate = [ "GstVideo.VideoOverlayFormatFlags", "GstVideo.VideoTimeCodeFlags", "GstVideo.VideoCaptionType", + "GstVideo.VideoBufferPool", ] manual = [ "GLib.DateTime", "GObject.Object", + "Gst.BufferPool", "Gst.Object", "Gst.Element", "Gst.Buffer", diff --git a/gstreamer-video/src/auto/mod.rs b/gstreamer-video/src/auto/mod.rs index ed91f8fa6..613e3726d 100644 --- a/gstreamer-video/src/auto/mod.rs +++ b/gstreamer-video/src/auto/mod.rs @@ -6,6 +6,9 @@ mod video_decoder; pub use self::video_decoder::{VideoDecoder, VideoDecoderClass, NONE_VIDEO_DECODER}; pub use self::video_decoder::VideoDecoderExt; +mod video_buffer_pool; +pub use self::video_buffer_pool::{VideoBufferPool, VideoBufferPoolClass, NONE_VIDEO_BUFFER_POOL}; + mod video_filter; pub use self::video_filter::{VideoFilter, VideoFilterClass, NONE_VIDEO_FILTER}; diff --git a/gstreamer-video/src/auto/video_buffer_pool.rs b/gstreamer-video/src/auto/video_buffer_pool.rs new file mode 100644 index 000000000..866c79ff3 --- /dev/null +++ b/gstreamer-video/src/auto/video_buffer_pool.rs @@ -0,0 +1,36 @@ +// This file was generated by gir (https://github.com/gtk-rs/gir) +// from gir-files (https://github.com/gtk-rs/gir-files) +// DO NOT EDIT + +use glib::object::Cast; +use glib::translate::*; +use gst; +use gst_video_sys; + +glib_wrapper! { + pub struct VideoBufferPool(Object) @extends gst::BufferPool, gst::Object; + + match fn { + get_type => || gst_video_sys::gst_video_buffer_pool_get_type(), + } +} + +impl VideoBufferPool { + pub fn new() -> VideoBufferPool { + assert_initialized_main_thread!(); + unsafe { + gst::BufferPool::from_glib_full(gst_video_sys::gst_video_buffer_pool_new()).unsafe_cast() + } + } +} + +impl Default for VideoBufferPool { + fn default() -> Self { + Self::new() + } +} + +unsafe impl Send for VideoBufferPool {} +unsafe impl Sync for VideoBufferPool {} + +pub const NONE_VIDEO_BUFFER_POOL: Option<&VideoBufferPool> = None; diff --git a/gstreamer-video/src/lib.rs b/gstreamer-video/src/lib.rs index 0feada17a..f450e8437 100644 --- a/gstreamer-video/src/lib.rs +++ b/gstreamer-video/src/lib.rs @@ -74,8 +74,9 @@ mod video_time_code_interval; pub use video_time_code_interval::VideoTimeCodeInterval; mod video_buffer_pool; pub use video_buffer_pool::{ - BUFFER_POOL_OPTION_VIDEO_AFFINE_TRANSFORMATION_META, BUFFER_POOL_OPTION_VIDEO_ALIGNMENT, - BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META, BUFFER_POOL_OPTION_VIDEO_META, + VideoAlignment, BUFFER_POOL_OPTION_VIDEO_AFFINE_TRANSFORMATION_META, + BUFFER_POOL_OPTION_VIDEO_ALIGNMENT, BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META, + BUFFER_POOL_OPTION_VIDEO_META, }; mod video_codec_frame; @@ -92,6 +93,7 @@ pub mod prelude { pub use gst::prelude::*; pub use auto::traits::*; + pub use video_buffer_pool::VideoBufferPoolConfig; pub use video_decoder::VideoDecoderExtManual; pub use video_overlay::VideoOverlayExtManual; } diff --git a/gstreamer-video/src/video_buffer_pool.rs b/gstreamer-video/src/video_buffer_pool.rs index 6f67e59de..39709074c 100644 --- a/gstreamer-video/src/video_buffer_pool.rs +++ b/gstreamer-video/src/video_buffer_pool.rs @@ -1,4 +1,5 @@ // Copyright (C) 2019 Guillaume Desmottes +// Copyright (C) 2019 Vivia Nikolaidou // // Licensed under the Apache License, Version 2.0 or the MIT license @@ -7,6 +8,9 @@ // except according to those terms. use std::ffi::CStr; +use std::mem; + +use glib::translate::*; lazy_static! { pub static ref BUFFER_POOL_OPTION_VIDEO_AFFINE_TRANSFORMATION_META: &'static str = unsafe { @@ -30,3 +34,80 @@ lazy_static! { .unwrap() }; } + +#[derive(Debug, Clone)] +pub struct VideoAlignment(gst_video_sys::GstVideoAlignment); + +impl VideoAlignment { + pub fn get_padding_top(&self) -> u32 { + self.0.padding_top + } + pub fn get_padding_bottom(&self) -> u32 { + self.0.padding_bottom + } + pub fn get_padding_left(&self) -> u32 { + self.0.padding_left + } + pub fn get_padding_right(&self) -> u32 { + self.0.padding_right + } + pub fn get_stride_align(&self) -> &[u32; gst_video_sys::GST_VIDEO_MAX_PLANES as usize] { + &self.0.stride_align + } + + pub fn new( + padding_top: u32, + padding_bottom: u32, + padding_left: u32, + padding_right: u32, + stride_align: &[u32; gst_video_sys::GST_VIDEO_MAX_PLANES as usize], + ) -> Self { + assert_initialized_main_thread!(); + + let videoalignment = unsafe { + let mut videoalignment: gst_video_sys::GstVideoAlignment = mem::zeroed(); + + videoalignment.padding_top = padding_top; + videoalignment.padding_bottom = padding_bottom; + videoalignment.padding_left = padding_left; + videoalignment.padding_right = padding_right; + videoalignment.stride_align = *stride_align; + + videoalignment + }; + + VideoAlignment(videoalignment) + } +} + +pub trait VideoBufferPoolConfig { + fn get_video_alignment(&self) -> Option; + + fn set_video_alignment(&mut self, align: &VideoAlignment); +} + +impl VideoBufferPoolConfig for gst::BufferPoolConfig { + fn get_video_alignment(&self) -> Option { + unsafe { + let mut alignment: VideoAlignment = mem::zeroed(); + let ret = from_glib(gst_video_sys::gst_buffer_pool_config_get_video_alignment( + self.as_ref().as_mut_ptr(), + &mut alignment.0, + )); + if ret { + Some(alignment) + } else { + None + } + } + } + + fn set_video_alignment(&mut self, align: &VideoAlignment) { + unsafe { + gst_video_sys::gst_buffer_pool_config_set_video_alignment( + self.as_mut().as_mut_ptr(), + &align.0 as *const _ as *mut _, + ) + } + } +}