tag: Add bindings for language code API

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1714>
This commit is contained in:
Sebastian Dröge 2025-04-14 13:48:16 +03:00
parent 8e475a9011
commit a91f5bceb5
2 changed files with 91 additions and 0 deletions

View file

@ -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())
}))
}
}

View file

@ -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 {