audio-info: Allow from_caps() with encoded audio format

Similar to gst_video_info_from_caps() which allows encoded video format,
don't error gst_audio_info_from_caps() with encoded audio format.
Because gst_audio_info_set_format() supports encoded format, current
behavior does not seem to be consistent.
This commit is contained in:
Seungha Yang 2019-10-25 12:05:54 +09:00
parent 2bc1b38825
commit 2f89c3aff1

View file

@ -193,13 +193,14 @@ gst_audio_info_from_caps (GstAudioInfo * info, const GstCaps * caps)
{
GstStructure *str;
const gchar *s;
GstAudioFormat format;
gint rate, channels;
guint64 channel_mask;
GstAudioFormat format = GST_AUDIO_FORMAT_UNKNOWN;
gint rate = 0;
gint channels = 0;
guint64 channel_mask = 0;
gint i;
GstAudioChannelPosition position[64];
GstAudioFlags flags;
GstAudioLayout layout;
GstAudioLayout layout = GST_AUDIO_LAYOUT_INTERLEAVED;
g_return_val_if_fail (info != NULL, FALSE);
g_return_val_if_fail (caps != NULL, FALSE);
@ -211,16 +212,20 @@ gst_audio_info_from_caps (GstAudioInfo * info, const GstCaps * caps)
str = gst_caps_get_structure (caps, 0);
if (!gst_structure_has_name (str, "audio/x-raw"))
goto wrong_name;
if (gst_structure_has_name (str, "audio/x-raw")) {
if (!(s = gst_structure_get_string (str, "format")))
goto no_format;
format = gst_audio_format_from_string (s);
if (format == GST_AUDIO_FORMAT_UNKNOWN)
goto unknown_format;
} else if (g_str_has_prefix (gst_structure_get_name (str), "audio/")) {
format = GST_AUDIO_FORMAT_ENCODED;
} else {
goto wrong_name;
}
if (format != GST_AUDIO_FORMAT_ENCODED) {
if (!(s = gst_structure_get_string (str, "layout")))
goto no_layout;
if (g_str_equal (s, "interleaved"))
@ -229,10 +234,13 @@ gst_audio_info_from_caps (GstAudioInfo * info, const GstCaps * caps)
layout = GST_AUDIO_LAYOUT_NON_INTERLEAVED;
else
goto unknown_layout;
}
if (!gst_structure_get_int (str, "rate", &rate))
if (!gst_structure_get_int (str, "rate", &rate) &&
format != GST_AUDIO_FORMAT_ENCODED)
goto no_rate;
if (!gst_structure_get_int (str, "channels", &channels))
if (!gst_structure_get_int (str, "channels", &channels) &&
format != GST_AUDIO_FORMAT_ENCODED)
goto no_channels;
if (!gst_structure_get (str, "channel-mask", GST_TYPE_BITMASK, &channel_mask,
@ -242,7 +250,7 @@ gst_audio_info_from_caps (GstAudioInfo * info, const GstCaps * caps)
} else if (channels == 2) {
position[0] = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
position[1] = GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT;
} else {
} else if (format != GST_AUDIO_FORMAT_ENCODED) {
goto no_channel_mask;
}
} else if (channel_mask == 0) {