ffvidenc: Allocate output buffers with the base class functions

This commit is contained in:
Sebastian Dröge 2012-07-23 10:40:14 +02:00
parent 941f4c331b
commit 899fd3d76e

View file

@ -716,7 +716,13 @@ gst_ffmpegvidenc_handle_frame (GstVideoEncoder * encoder,
frame = gst_video_encoder_get_oldest_frame (encoder); frame = gst_video_encoder_get_oldest_frame (encoder);
/* Allocate output buffer */ /* 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); gst_buffer_fill (outbuf, 0, ffmpegenc->working_buf, ret_size);
/* buggy codec may not set coded_frame */ /* buggy codec may not set coded_frame */
@ -743,6 +749,16 @@ encode_fail:
#endif /* GST_DISABLE_GST_DEBUG */ #endif /* GST_DISABLE_GST_DEBUG */
return GST_FLOW_OK; 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 static void
@ -773,6 +789,7 @@ gst_ffmpegvidenc_flush_buffers (GstFFMpegVidEnc * ffmpegenc, gboolean send)
GST_WARNING_OBJECT (ffmpegenc, GST_WARNING_OBJECT (ffmpegenc,
"avenc_%s: failed to flush buffer", oclass->in_plugin->name); "avenc_%s: failed to flush buffer", oclass->in_plugin->name);
#endif /* GST_DISABLE_GST_DEBUG */ #endif /* GST_DISABLE_GST_DEBUG */
gst_video_codec_frame_unref (frame);
break; break;
} }
@ -783,7 +800,18 @@ gst_ffmpegvidenc_flush_buffers (GstFFMpegVidEnc * ffmpegenc, gboolean send)
(("Could not write to file \"%s\"."), ffmpegenc->filename), (("Could not write to file \"%s\"."), ffmpegenc->filename),
GST_ERROR_SYSTEM); 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); gst_buffer_fill (outbuf, 0, ffmpegenc->working_buf, ret_size);
if (ffmpegenc->context->coded_frame->key_frame) if (ffmpegenc->context->coded_frame->key_frame)