From 7207bbed69e0e975c762b0b1f74b3868df8c1f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 28 Oct 2018 12:39:27 +0000 Subject: [PATCH] Add various global functions to the pbutils library --- Gir_GstPbutils.toml | 52 ++++++++++++++++++ gstreamer-pbutils/src/auto/functions.rs | 65 ++++++++++++++++++++++ gstreamer-pbutils/src/auto/mod.rs | 2 + gstreamer-pbutils/src/functions.rs | 72 +++++++++++++++++++++++++ gstreamer-pbutils/src/lib.rs | 6 +++ 5 files changed, 197 insertions(+) create mode 100644 gstreamer-pbutils/src/auto/functions.rs create mode 100644 gstreamer-pbutils/src/functions.rs diff --git a/Gir_GstPbutils.toml b/Gir_GstPbutils.toml index 87a55a7d8..4289fd138 100644 --- a/Gir_GstPbutils.toml +++ b/Gir_GstPbutils.toml @@ -234,3 +234,55 @@ trait = false pattern = "set_.*" ignore = true +[[object]] +name = "GstPbutils.*" +status = "generate" + # We'll opt-in for constants at a later time + [[object.constant]] + pattern = ".+" + ignore = true + + # Codec utils need some special care + [[object.function]] + pattern = "codec_utils.*" + ignore = true + + # Plugin installer API needs some manual impls + [[object.function]] + pattern = "install_plugins.*" + ignore = true + + # Plugin installer API needs some manual impls + [[object.function]] + pattern = "missing_.*" + ignore = true + + # Plugin installer API needs some manual impls + [[object.function]] + name = "is_missing_plugin_message" + ignore = true + + # Initialization is handled implicitely + [[object.function]] + name = "pb_utils_init" + ignore = true + + # Needs special handling for mutable taglists + [[object.function]] + name = "pb_utils_add_codec_description_to_tag_list" + ignore = true + + # Needs special handling for caps refs + [[object.function]] + name = "pb_utils_get_codec_description" + ignore = true + + # Needs special handling for caps refs + [[object.function]] + name = "pb_utils_get_decoder_description" + ignore = true + + # Needs special handling for caps refs + [[object.function]] + name = "pb_utils_get_encoder_description" + ignore = true diff --git a/gstreamer-pbutils/src/auto/functions.rs b/gstreamer-pbutils/src/auto/functions.rs new file mode 100644 index 000000000..5040036fb --- /dev/null +++ b/gstreamer-pbutils/src/auto/functions.rs @@ -0,0 +1,65 @@ +// 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 EncodingTarget; +use ffi; +use glib::translate::*; +use std::mem; + + +pub fn encoding_list_all_targets<'a, P: Into>>(categoryname: P) -> Vec { + assert_initialized_main_thread!(); + let categoryname = categoryname.into(); + let categoryname = categoryname.to_glib_none(); + unsafe { + FromGlibPtrContainer::from_glib_full(ffi::gst_encoding_list_all_targets(categoryname.0)) + } +} + +pub fn encoding_list_available_categories() -> Vec { + assert_initialized_main_thread!(); + unsafe { + FromGlibPtrContainer::from_glib_full(ffi::gst_encoding_list_available_categories()) + } +} + +pub fn pb_utils_get_element_description(factory_name: &str) -> Option { + assert_initialized_main_thread!(); + unsafe { + from_glib_full(ffi::gst_pb_utils_get_element_description(factory_name.to_glib_none().0)) + } +} + +pub fn pb_utils_get_sink_description(protocol: &str) -> Option { + assert_initialized_main_thread!(); + unsafe { + from_glib_full(ffi::gst_pb_utils_get_sink_description(protocol.to_glib_none().0)) + } +} + +pub fn pb_utils_get_source_description(protocol: &str) -> Option { + assert_initialized_main_thread!(); + unsafe { + from_glib_full(ffi::gst_pb_utils_get_source_description(protocol.to_glib_none().0)) + } +} + +pub fn plugins_base_version() -> (u32, u32, u32, u32) { + assert_initialized_main_thread!(); + unsafe { + let mut major = mem::uninitialized(); + let mut minor = mem::uninitialized(); + let mut micro = mem::uninitialized(); + let mut nano = mem::uninitialized(); + ffi::gst_plugins_base_version(&mut major, &mut minor, &mut micro, &mut nano); + (major, minor, micro, nano) + } +} + +pub fn plugins_base_version_string() -> Option { + assert_initialized_main_thread!(); + unsafe { + from_glib_full(ffi::gst_plugins_base_version_string()) + } +} diff --git a/gstreamer-pbutils/src/auto/mod.rs b/gstreamer-pbutils/src/auto/mod.rs index 804394d90..aa33410ef 100644 --- a/gstreamer-pbutils/src/auto/mod.rs +++ b/gstreamer-pbutils/src/auto/mod.rs @@ -49,6 +49,8 @@ pub use self::enums::DiscovererResult; mod flags; pub use self::flags::DiscovererSerializeFlags; +pub mod functions; + #[doc(hidden)] pub mod traits { pub use super::DiscovererInfoExt; diff --git a/gstreamer-pbutils/src/functions.rs b/gstreamer-pbutils/src/functions.rs new file mode 100644 index 000000000..f0575addc --- /dev/null +++ b/gstreamer-pbutils/src/functions.rs @@ -0,0 +1,72 @@ +// Copyright (C) 2018 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 ffi; +use glib; +use glib::translate::*; +use gst; +use gst::MiniObject; +use std::ptr; + +pub unsafe trait CodecTag<'a>: gst::Tag<'a, TagType = &'a str> {} + +unsafe impl<'a> CodecTag<'a> for gst::tags::ContainerFormat {} +unsafe impl<'a> CodecTag<'a> for gst::tags::AudioCodec {} +unsafe impl<'a> CodecTag<'a> for gst::tags::VideoCodec {} +unsafe impl<'a> CodecTag<'a> for gst::tags::SubtitleCodec {} +unsafe impl<'a> CodecTag<'a> for gst::tags::Codec {} + +pub fn pb_utils_add_codec_description_to_tag_list_for_tag<'a, T: CodecTag<'a>>( + taglist: &mut gst::TagListRef, + caps: &gst::CapsRef, +) -> Result<(), glib::BoolError> { + assert_initialized_main_thread!(); + let codec_tag = T::tag_name(); + unsafe { + glib::BoolError::from_glib( + ffi::gst_pb_utils_add_codec_description_to_tag_list( + taglist.as_mut_ptr(), + codec_tag.to_glib_none().0, + caps.as_ptr(), + ), + "Failed to find codec description", + ) + } +} + +pub fn pb_utils_add_codec_description_to_tag_list( + taglist: &mut gst::TagListRef, + caps: &gst::CapsRef, +) -> Result<(), glib::BoolError> { + assert_initialized_main_thread!(); + unsafe { + glib::BoolError::from_glib( + ffi::gst_pb_utils_add_codec_description_to_tag_list( + taglist.as_mut_ptr(), + ptr::null_mut(), + caps.as_ptr(), + ), + "Failed to find codec description", + ) + } +} + +pub fn pb_utils_get_encoder_description(caps: &gst::CapsRef) -> Option { + assert_initialized_main_thread!(); + unsafe { from_glib_full(ffi::gst_pb_utils_get_encoder_description(caps.as_ptr())) } +} + +pub fn pb_utils_get_decoder_description(caps: &gst::CapsRef) -> Option { + assert_initialized_main_thread!(); + unsafe { from_glib_full(ffi::gst_pb_utils_get_decoder_description(caps.as_ptr())) } +} + +pub fn pb_utils_get_codec_description(caps: &gst::CapsRef) -> Option { + assert_initialized_main_thread!(); + unsafe { from_glib_full(ffi::gst_pb_utils_get_codec_description(caps.as_ptr())) } +} diff --git a/gstreamer-pbutils/src/lib.rs b/gstreamer-pbutils/src/lib.rs index f65adf16c..1bafdf23c 100644 --- a/gstreamer-pbutils/src/lib.rs +++ b/gstreamer-pbutils/src/lib.rs @@ -45,6 +45,7 @@ pub use glib::{Cast, Continue, Error, IsA, StaticType, ToValue, Type, TypedValue #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))] #[cfg_attr(feature = "cargo-clippy", allow(type_complexity))] mod auto; +pub use auto::functions::*; pub use auto::*; mod discoverer; @@ -58,6 +59,9 @@ pub use discoverer_video_info::*; mod encoding_profile; pub use encoding_profile::*; +pub mod functions; +pub use functions::*; + // Re-export all the traits in a prelude module, so that applications // can always "use gst::prelude::*" without getting conflicts pub mod prelude { @@ -66,4 +70,6 @@ pub mod prelude { pub use auto::traits::*; pub use encoding_profile::EncodingProfileBuilder; + + pub use functions::CodecTag; }