1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::translate::*;
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::result_from_gboolean!(
            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",
        )
    }
}

/// Adds a codec tag describing the format specified by `caps` to `taglist`.
/// ## `taglist`
/// a [`gst::TagList`][crate::gst::TagList]
/// ## `codec_tag`
/// a GStreamer codec tag such as `GST_TAG_AUDIO_CODEC`,
///  `GST_TAG_VIDEO_CODEC` or `GST_TAG_CODEC`. If none is specified,
///  the function will attempt to detect the appropriate category.
/// ## `caps`
/// the (fixed) [`gst::Caps`][crate::gst::Caps] for which a codec tag should be added.
///
/// # Returns
///
/// TRUE if a codec tag was added, FALSE otherwise.
#[doc(alias = "gst_pb_utils_add_codec_description_to_tag_list")]
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::result_from_gboolean!(
            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",
        )
    }
}

/// Returns a localised string describing an encoder for the format specified
/// in `caps`, for use in error dialogs or other messages to be seen by the user.
/// Should never return NULL unless `factory_name` or `caps` are invalid.
///
/// This function is mainly for internal use, applications would typically
/// use `gst_missing_plugin_message_get_description()` to get a description of
/// a missing feature from a missing-plugin message.
/// ## `caps`
/// the (fixed) [`gst::Caps`][crate::gst::Caps] for which an encoder description is needed
///
/// # Returns
///
/// a newly-allocated description string, or NULL on error. Free
///  string with `g_free()` when not needed any longer.
#[doc(alias = "gst_pb_utils_get_encoder_description")]
pub fn pb_utils_get_encoder_description(
    caps: &gst::CapsRef,
) -> Result<glib::GString, glib::error::BoolError> {
    assert_initialized_main_thread!();
    unsafe {
        match from_glib_full(ffi::gst_pb_utils_get_encoder_description(caps.as_ptr())) {
            Some(s) => Ok(s),
            None => Err(glib::bool_error!("Failed to get encoder description")),
        }
    }
}

/// Returns a localised string describing an decoder for the format specified
/// in `caps`, for use in error dialogs or other messages to be seen by the user.
/// Should never return NULL unless `factory_name` or `caps` are invalid.
///
/// This function is mainly for internal use, applications would typically
/// use `gst_missing_plugin_message_get_description()` to get a description of
/// a missing feature from a missing-plugin message.
/// ## `caps`
/// the (fixed) [`gst::Caps`][crate::gst::Caps] for which an decoder description is needed
///
/// # Returns
///
/// a newly-allocated description string, or NULL on error. Free
///  string with `g_free()` when not needed any longer.
#[doc(alias = "gst_pb_utils_get_decoder_description")]
pub fn pb_utils_get_decoder_description(
    caps: &gst::CapsRef,
) -> Result<glib::GString, glib::error::BoolError> {
    assert_initialized_main_thread!();
    unsafe {
        match from_glib_full(ffi::gst_pb_utils_get_decoder_description(caps.as_ptr())) {
            Some(s) => Ok(s),
            None => Err(glib::bool_error!("Failed to get decoder description")),
        }
    }
}

/// Returns a localised (as far as this is possible) string describing the
/// media format specified in `caps`, for use in error dialogs or other messages
/// to be seen by the user. Should never return NULL unless `caps` is invalid.
///
/// Also see the convenience function
/// `gst_pb_utils_add_codec_description_to_tag_list()`.
/// ## `caps`
/// the (fixed) [`gst::Caps`][crate::gst::Caps] for which an format description is needed
///
/// # Returns
///
/// a newly-allocated description string, or NULL on error. Free
///  string with `g_free()` when not needed any longer.
#[doc(alias = "gst_pb_utils_get_codec_description")]
pub fn pb_utils_get_codec_description(
    caps: &gst::CapsRef,
) -> Result<glib::GString, glib::error::BoolError> {
    assert_initialized_main_thread!();
    unsafe {
        match from_glib_full(ffi::gst_pb_utils_get_codec_description(caps.as_ptr())) {
            Some(s) => Ok(s),
            None => Err(glib::bool_error!("Failed to get codec description")),
        }
    }
}