From 899fd3d76e3353d2ed7dc5aea1d8dbbc9c0aeb10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 23 Jul 2012 10:40:14 +0200 Subject: [PATCH] ffvidenc: Allocate output buffers with the base class functions --- ext/ffmpeg/gstffmpegvidenc.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/ext/ffmpeg/gstffmpegvidenc.c b/ext/ffmpeg/gstffmpegvidenc.c index e636eda563..4204e08a9b 100644 --- a/ext/ffmpeg/gstffmpegvidenc.c +++ b/ext/ffmpeg/gstffmpegvidenc.c @@ -716,7 +716,13 @@ gst_ffmpegvidenc_handle_frame (GstVideoEncoder * encoder, frame = gst_video_encoder_get_oldest_frame (encoder); /* Allocate output buffer */ - frame->output_buffer = outbuf = gst_buffer_new_and_alloc (ret_size); + if (gst_video_encoder_allocate_output_frame (encoder, frame, + ret_size) != GST_FLOW_OK) { + gst_video_codec_frame_unref (frame); + goto alloc_fail; + } + + outbuf = frame->output_buffer; gst_buffer_fill (outbuf, 0, ffmpegenc->working_buf, ret_size); /* buggy codec may not set coded_frame */ @@ -743,6 +749,16 @@ encode_fail: #endif /* GST_DISABLE_GST_DEBUG */ return GST_FLOW_OK; } +alloc_fail: + { +#ifndef GST_DISABLE_GST_DEBUG + GstFFMpegVidEncClass *oclass = + (GstFFMpegVidEncClass *) (G_OBJECT_GET_CLASS (ffmpegenc)); + GST_ERROR_OBJECT (ffmpegenc, + "avenc_%s: failed to allocate buffer", oclass->in_plugin->name); +#endif /* GST_DISABLE_GST_DEBUG */ + return GST_FLOW_ERROR; + } } static void @@ -773,6 +789,7 @@ gst_ffmpegvidenc_flush_buffers (GstFFMpegVidEnc * ffmpegenc, gboolean send) GST_WARNING_OBJECT (ffmpegenc, "avenc_%s: failed to flush buffer", oclass->in_plugin->name); #endif /* GST_DISABLE_GST_DEBUG */ + gst_video_codec_frame_unref (frame); break; } @@ -783,7 +800,18 @@ gst_ffmpegvidenc_flush_buffers (GstFFMpegVidEnc * ffmpegenc, gboolean send) (("Could not write to file \"%s\"."), ffmpegenc->filename), GST_ERROR_SYSTEM); - frame->output_buffer = outbuf = gst_buffer_new_and_alloc (ret_size); + if (gst_video_encoder_allocate_output_frame (GST_VIDEO_ENCODER (ffmpegenc), + frame, ret_size) != GST_FLOW_OK) { +#ifndef GST_DISABLE_GST_DEBUG + GstFFMpegVidEncClass *oclass = + (GstFFMpegVidEncClass *) (G_OBJECT_GET_CLASS (ffmpegenc)); + GST_WARNING_OBJECT (ffmpegenc, + "avenc_%s: failed to allocate buffer", oclass->in_plugin->name); +#endif /* GST_DISABLE_GST_DEBUG */ + gst_video_codec_frame_unref (frame); + break; + } + outbuf = frame->output_buffer; gst_buffer_fill (outbuf, 0, ffmpegenc->working_buf, ret_size); if (ffmpegenc->context->coded_frame->key_frame)