From a51339de797476fc584bb1f31ac68224b68ece66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 14 Apr 2025 13:48:16 +0300 Subject: [PATCH] tag: Add bindings for language code API Part-of: --- gstreamer-tag/src/language_codes.rs | 89 +++++++++++++++++++++++++++++ gstreamer-tag/src/lib.rs | 2 + 2 files changed, 91 insertions(+) create mode 100644 gstreamer-tag/src/language_codes.rs diff --git a/gstreamer-tag/src/language_codes.rs b/gstreamer-tag/src/language_codes.rs new file mode 100644 index 000000000..882060b81 --- /dev/null +++ b/gstreamer-tag/src/language_codes.rs @@ -0,0 +1,89 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use crate::ffi; +use glib::translate::*; + +#[doc(alias = "gst_tag_get_language_codes")] +pub fn language_codes() -> glib::collections::StrV { + skip_assert_initialized!(); + + unsafe { glib::collections::StrV::from_glib_full(ffi::gst_tag_get_language_codes()) } +} + +#[doc(alias = "gst_tag_get_language_name")] +pub fn language_name<'a>(language_code: &str) -> Option<&'a glib::GStr> { + skip_assert_initialized!(); + + unsafe { + let ptr = language_code + .run_with_gstr(|language_code| ffi::gst_tag_get_language_name(language_code.as_ptr())); + + if ptr.is_null() { + None + } else { + Some(glib::GStr::from_ptr(ptr)) + } + } +} + +#[doc(alias = "gst_tag_get_language_code_iso_639_1")] +pub fn language_code_iso_639_1<'a>(language_code: &str) -> Option<&'a glib::GStr> { + skip_assert_initialized!(); + + unsafe { + let ptr = language_code.run_with_gstr(|language_code| { + ffi::gst_tag_get_language_code_iso_639_1(language_code.as_ptr()) + }); + + if ptr.is_null() { + None + } else { + Some(glib::GStr::from_ptr(ptr)) + } + } +} + +#[doc(alias = "gst_tag_get_language_code_iso_639_2T")] +pub fn language_code_iso_639_2t<'a>(language_code: &str) -> Option<&'a glib::GStr> { + skip_assert_initialized!(); + + unsafe { + let ptr = language_code.run_with_gstr(|language_code| { + ffi::gst_tag_get_language_code_iso_639_2T(language_code.as_ptr()) + }); + + if ptr.is_null() { + None + } else { + Some(glib::GStr::from_ptr(ptr)) + } + } +} + +#[doc(alias = "gst_tag_get_language_code_iso_639_2B")] +pub fn language_code_iso_639_2b<'a>(language_code: &str) -> Option<&'a glib::GStr> { + skip_assert_initialized!(); + + unsafe { + let ptr = language_code.run_with_gstr(|language_code| { + ffi::gst_tag_get_language_code_iso_639_2B(language_code.as_ptr()) + }); + + if ptr.is_null() { + None + } else { + Some(glib::GStr::from_ptr(ptr)) + } + } +} + +#[doc(alias = "gst_tag_check_language_code")] +pub fn check_language_code(language_code: &str) -> bool { + skip_assert_initialized!(); + + unsafe { + from_glib(language_code.run_with_gstr(|language_code| { + ffi::gst_tag_check_language_code(language_code.as_ptr()) + })) + } +} diff --git a/gstreamer-tag/src/lib.rs b/gstreamer-tag/src/lib.rs index bc4f1b452..a8e784a6c 100644 --- a/gstreamer-tag/src/lib.rs +++ b/gstreamer-tag/src/lib.rs @@ -16,6 +16,8 @@ macro_rules! skip_assert_initialized { mod tags; pub use crate::tags::*; +pub mod language_codes; + // Re-export all the traits in a prelude module, so that applications // can always "use gst_tag::prelude::*" without getting conflicts pub mod prelude {