video: Handle errors in gst_video_info_set_format() / gst_video_info_align()

https://bugzilla.gnome.org/show_bug.cgi?id=774588
This commit is contained in:
Sebastian Dröge 2016-11-23 20:10:34 +02:00
parent 17cdd369e6
commit 681d97aed7
6 changed files with 38 additions and 11 deletions

View file

@ -640,7 +640,10 @@ _new_output_state (GstVideoFormat fmt, guint width, guint height,
state = g_slice_new0 (GstVideoCodecState); state = g_slice_new0 (GstVideoCodecState);
state->ref_count = 1; state->ref_count = 1;
gst_video_info_init (&state->info); gst_video_info_init (&state->info);
gst_video_info_set_format (&state->info, fmt, width, height); if (!gst_video_info_set_format (&state->info, fmt, width, height)) {
g_slice_free (GstVideoCodecState, state);
return NULL;
}
if (reference) { if (reference) {
GstVideoInfo *tgt, *ref; GstVideoInfo *tgt, *ref;
@ -3466,6 +3469,8 @@ gst_video_decoder_set_output_state (GstVideoDecoder * decoder,
/* Create the new output state */ /* Create the new output state */
state = _new_output_state (fmt, width, height, reference); state = _new_output_state (fmt, width, height, reference);
if (!state)
return NULL;
GST_VIDEO_DECODER_STREAM_LOCK (decoder); GST_VIDEO_DECODER_STREAM_LOCK (decoder);

View file

@ -517,7 +517,11 @@ _new_output_state (GstCaps * caps, GstVideoCodecState * reference)
state = g_slice_new0 (GstVideoCodecState); state = g_slice_new0 (GstVideoCodecState);
state->ref_count = 1; state->ref_count = 1;
gst_video_info_init (&state->info); gst_video_info_init (&state->info);
gst_video_info_set_format (&state->info, GST_VIDEO_FORMAT_ENCODED, 0, 0);
if (!gst_video_info_set_format (&state->info, GST_VIDEO_FORMAT_ENCODED, 0, 0)) {
g_slice_free (GstVideoCodecState, state);
return NULL;
}
state->caps = caps; state->caps = caps;
@ -2275,6 +2279,8 @@ gst_video_encoder_set_output_state (GstVideoEncoder * encoder, GstCaps * caps,
g_return_val_if_fail (caps != NULL, NULL); g_return_val_if_fail (caps != NULL, NULL);
state = _new_output_state (caps, reference); state = _new_output_state (caps, reference);
if (!state)
return NULL;
GST_VIDEO_ENCODER_STREAM_LOCK (encoder); GST_VIDEO_ENCODER_STREAM_LOCK (encoder);
if (priv->output_state) if (priv->output_state)

View file

@ -270,7 +270,8 @@ gst_buffer_add_video_meta (GstBuffer * buffer,
GstVideoMeta *meta; GstVideoMeta *meta;
GstVideoInfo info; GstVideoInfo info;
gst_video_info_set_format (&info, format, width, height); if (!gst_video_info_set_format (&info, format, width, height))
return NULL;
meta = meta =
gst_buffer_add_video_meta_full (buffer, flags, format, width, gst_buffer_add_video_meta_full (buffer, flags, format, width,

View file

@ -186,7 +186,9 @@ video_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
priv->video_align.stride_align[n] = max_align; priv->video_align.stride_align[n] = max_align;
/* apply the alignment to the info */ /* apply the alignment to the info */
gst_video_info_align (&info, &priv->video_align); if (!gst_video_info_align (&info, &priv->video_align))
goto failed_to_align;
gst_buffer_pool_config_set_video_alignment (config, &priv->video_align); gst_buffer_pool_config_set_video_alignment (config, &priv->video_align);
if (priv->params.align < max_align) { if (priv->params.align < max_align) {
@ -227,7 +229,11 @@ wrong_size:
GST_WARNING_OBJECT (pool, GST_WARNING_OBJECT (pool,
"Provided size is to small for the caps: %u", size); "Provided size is to small for the caps: %u", size);
return FALSE; return FALSE;
}
failed_to_align:
{
GST_WARNING_OBJECT (pool, "Failed to align");
return FALSE;
} }
} }

View file

@ -175,11 +175,14 @@ gst_video_blend_scale_linear_RGBA (GstVideoInfo * src, GstBuffer * src_buffer,
g_return_if_fail (dest_buffer != NULL); g_return_if_fail (dest_buffer != NULL);
tmpbuf = g_malloc (dest_width * 8 * 4);
gst_video_info_init (dest); gst_video_info_init (dest);
gst_video_info_set_format (dest, GST_VIDEO_INFO_FORMAT (src), if (!gst_video_info_set_format (dest, GST_VIDEO_INFO_FORMAT (src),
dest_width, dest_height); dest_width, dest_height)) {
g_warn_if_reached ();
return;
}
tmpbuf = g_malloc (dest_width * 8 * 4);
*dest_buffer = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (dest)); *dest_buffer = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (dest));

View file

@ -739,7 +739,10 @@ gst_video_overlay_rectangle_new_raw (GstBuffer * pixels,
rect->scaled_rectangles = NULL; rect->scaled_rectangles = NULL;
gst_video_info_init (&rect->info); gst_video_info_init (&rect->info);
gst_video_info_set_format (&rect->info, format, width, height); if (!gst_video_info_set_format (&rect->info, format, width, height)) {
gst_mini_object_unref (GST_MINI_OBJECT_CAST (rect));
return NULL;
}
if (flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA) if (flags & GST_VIDEO_OVERLAY_FORMAT_FLAG_PREMULTIPLIED_ALPHA)
rect->info.flags |= GST_VIDEO_FLAG_PREMULTIPLIED_ALPHA; rect->info.flags |= GST_VIDEO_FLAG_PREMULTIPLIED_ALPHA;
@ -1059,7 +1062,10 @@ gst_video_overlay_rectangle_convert (GstVideoInfo * src, GstBuffer * src_buffer,
height = GST_VIDEO_INFO_HEIGHT (src); height = GST_VIDEO_INFO_HEIGHT (src);
gst_video_info_init (dest); gst_video_info_init (dest);
gst_video_info_set_format (dest, dest_format, width, height); if (!gst_video_info_set_format (dest, dest_format, width, height)) {
g_warn_if_reached ();
return;
}
*dest_buffer = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (dest)); *dest_buffer = gst_buffer_new_and_alloc (GST_VIDEO_INFO_SIZE (dest));