audio/video-info: Properly initialize the info structures in set_format()

And don't assume in other code that set_format() preserves any fields at
all. These assumptions were already made here for fields that were changed
by set_format().
This commit is contained in:
Sebastian Dröge 2013-12-30 10:53:24 +01:00
parent 65732d9c97
commit 58592a2af3
2 changed files with 18 additions and 8 deletions

View file

@ -107,6 +107,8 @@ gst_audio_info_init (GstAudioInfo * info)
* @position: the channel positions
*
* Set the default info for the audio info of @format and @rate and @channels.
*
* Note: This initializes @info first, no values are preserved.
*/
void
gst_audio_info_set_format (GstAudioInfo * info, GstAudioFormat format,
@ -119,7 +121,7 @@ gst_audio_info_set_format (GstAudioInfo * info, GstAudioFormat format,
g_return_if_fail (format != GST_AUDIO_FORMAT_UNKNOWN);
g_return_if_fail (channels <= 64 || position == NULL);
memset (info, 0, sizeof (GstAudioInfo));
gst_audio_info_init (info);
finfo = gst_audio_format_get_info (format);
@ -179,6 +181,8 @@ gst_audio_info_from_caps (GstAudioInfo * info, const GstCaps * caps)
guint64 channel_mask;
gint i;
GstAudioChannelPosition position[64];
GstAudioFlags flags;
GstAudioLayout layout;
g_return_val_if_fail (info != NULL, FALSE);
g_return_val_if_fail (caps != NULL, FALSE);
@ -186,7 +190,7 @@ gst_audio_info_from_caps (GstAudioInfo * info, const GstCaps * caps)
GST_DEBUG ("parsing caps %" GST_PTR_FORMAT, caps);
info->flags = 0;
flags = 0;
str = gst_caps_get_structure (caps, 0);
@ -203,9 +207,9 @@ gst_audio_info_from_caps (GstAudioInfo * info, const GstCaps * caps)
if (!(s = gst_structure_get_string (str, "layout")))
goto no_layout;
if (g_str_equal (s, "interleaved"))
info->layout = GST_AUDIO_LAYOUT_INTERLEAVED;
layout = GST_AUDIO_LAYOUT_INTERLEAVED;
else if (g_str_equal (s, "non-interleaved"))
info->layout = GST_AUDIO_LAYOUT_NON_INTERLEAVED;
layout = GST_AUDIO_LAYOUT_NON_INTERLEAVED;
else
goto unknown_layout;
@ -225,7 +229,7 @@ gst_audio_info_from_caps (GstAudioInfo * info, const GstCaps * caps)
goto no_channel_mask;
}
} else if (channel_mask == 0) {
info->flags |= GST_AUDIO_FLAG_UNPOSITIONED;
flags |= GST_AUDIO_FLAG_UNPOSITIONED;
for (i = 0; i < MIN (64, channels); i++)
position[i] = GST_AUDIO_CHANNEL_POSITION_NONE;
} else {
@ -237,6 +241,9 @@ gst_audio_info_from_caps (GstAudioInfo * info, const GstCaps * caps)
gst_audio_info_set_format (info, format, rate, channels,
(channels > 64) ? NULL : position);
info->flags = flags;
info->layout = layout;
return TRUE;
/* ERROR */

View file

@ -79,6 +79,8 @@ static const GstVideoColorimetry default_color[] = {
* @height: a height
*
* Set the default info for a video frame of @format and @width and @height.
*
* Note: This initializes @info first, no values are preserved.
*/
void
gst_video_info_set_format (GstVideoInfo * info, GstVideoFormat format,
@ -89,7 +91,7 @@ gst_video_info_set_format (GstVideoInfo * info, GstVideoFormat format,
g_return_if_fail (info != NULL);
g_return_if_fail (format != GST_VIDEO_FORMAT_UNKNOWN);
memset (info, 0, sizeof (GstVideoInfo));
gst_video_info_init (info);
finfo = gst_video_format_get_info (format);
@ -767,8 +769,9 @@ gst_video_info_align (GstVideoInfo * info, GstVideoAlignment * align)
do {
GST_LOG ("padded dimension %u-%u", padded_width, padded_height);
gst_video_info_set_format (info, GST_VIDEO_INFO_FORMAT (info),
padded_width, padded_height);
info->width = padded_width;
info->height = padded_height;
fill_planes (info);
/* check alignment */
aligned = TRUE;