summaryrefslogtreecommitdiff
path: root/ext/ffmpeg/gstffmpegenc.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/ffmpeg/gstffmpegenc.c')
-rw-r--r--ext/ffmpeg/gstffmpegenc.c60
1 files changed, 21 insertions, 39 deletions
diff --git a/ext/ffmpeg/gstffmpegenc.c b/ext/ffmpeg/gstffmpegenc.c
index b827c93..0cf2a1d 100644
--- a/ext/ffmpeg/gstffmpegenc.c
+++ b/ext/ffmpeg/gstffmpegenc.c
@@ -248,10 +248,8 @@ gst_ffmpegenc_init (GstFFMpegEnc * ffmpegenc)
GST_CODEC_LOG("\n")
ffmpegenc->context = avcodec_alloc_context ();
ffmpegenc->picture = avcodec_alloc_frame ();
- if (oclass->in_plugin->type == CODEC_TYPE_VIDEO) {
- emul_avcodec_alloc_context();
- emul_avcodec_alloc_frame();
- }
+ emul_avcodec_alloc_context(&ffmpegenc->codecInfo);
+ emul_avcodec_alloc_frame(&ffmpegenc->codecInfo);
ffmpegenc->opened = FALSE;
ffmpegenc->file = NULL;
@@ -290,23 +288,20 @@ static void
gst_ffmpegenc_finalize (GObject * object)
{
GstFFMpegEnc *ffmpegenc = (GstFFMpegEnc *) object;
- enum AVMediaType codec_type;
gst_ffmpeg_cfg_finalize (ffmpegenc);
/* close old session */
if (ffmpegenc->opened) {
- gst_ffmpeg_avcodec_close (ffmpegenc->context);
+ gst_ffmpeg_avcodec_close (ffmpegenc->context, &ffmpegenc->codecInfo);
ffmpegenc->opened = FALSE;
}
/* clean up remaining allocated data */
GST_CODEC_LOG("before free AVCodecContext and AVFrame\n")
- codec_type = ffmpegenc->context->codec_type;
- if (codec_type == AVMEDIA_TYPE_VIDEO) {
- emul_av_free_context();
- emul_av_free_picture();
- }
+ emul_av_free_context(&ffmpegenc->codecInfo);
+ emul_av_free_picture(&ffmpegenc->codecInfo);
+ emul_close_codecdev(&ffmpegenc->codecInfo);
av_free(ffmpegenc->context);
av_free(ffmpegenc->picture);
@@ -477,7 +472,7 @@ gst_ffmpegenc_getcaps (GstPad * pad)
GST_DEBUG ("Attempting to open codec");
GST_CODEC_LOG("before gst_ffmpeg_avcodec_open, codec_id:%d\n", oclass->in_plugin->id)
- if (gst_ffmpeg_avcodec_open (ctx, oclass->in_plugin) >= 0 &&
+ if (gst_ffmpeg_avcodec_open (ctx, oclass->in_plugin, &ffmpegenc->codecInfo) >= 0 &&
ctx->pix_fmt == pixfmt) {
ctx->width = -1;
if (!caps)
@@ -490,13 +485,13 @@ gst_ffmpegenc_getcaps (GstPad * pad)
GST_LOG_OBJECT (ffmpegenc,
"Couldn't get caps for oclass->in_plugin->name:%s",
oclass->in_plugin->name);
- gst_ffmpeg_avcodec_close (ctx);
+ gst_ffmpeg_avcodec_close (ctx, &ffmpegenc->codecInfo);
} else {
GST_DEBUG_OBJECT (ffmpegenc, "Opening codec failed with pixfmt : %d",
pixfmt);
}
if (ctx->priv_data)
- gst_ffmpeg_avcodec_close (ctx);
+ gst_ffmpeg_avcodec_close (ctx, &ffmpegenc->codecInfo);
av_free (ctx);
}
#ifndef GST_DISABLE_GST_DEBUG
@@ -534,7 +529,7 @@ gst_ffmpegenc_setcaps (GstPad * pad, GstCaps * caps)
/* close old session */
if (ffmpegenc->opened) {
- gst_ffmpeg_avcodec_close (ffmpegenc->context);
+ gst_ffmpeg_avcodec_close (ffmpegenc->context, &ffmpegenc->codecInfo);
ffmpegenc->opened = FALSE;
}
@@ -658,9 +653,9 @@ gst_ffmpegenc_setcaps (GstPad * pad, GstCaps * caps)
/* open codec */
GST_CODEC_LOG("before gst_ffmpeg_avcodec_open\n")
- if (gst_ffmpeg_avcodec_open (ffmpegenc->context, oclass->in_plugin) < 0) {
+ if (gst_ffmpeg_avcodec_open (ffmpegenc->context, oclass->in_plugin, &ffmpegenc->codecInfo) < 0) {
if (ffmpegenc->context->priv_data)
- gst_ffmpeg_avcodec_close (ffmpegenc->context);
+ gst_ffmpeg_avcodec_close (ffmpegenc->context, &ffmpegenc->codecInfo);
if (ffmpegenc->context->stats_in)
g_free (ffmpegenc->context->stats_in);
GST_DEBUG_OBJECT (ffmpegenc, "ffenc_%s: Failed to open FFMPEG codec",
@@ -674,7 +669,7 @@ gst_ffmpegenc_setcaps (GstPad * pad, GstCaps * caps)
/* is the colourspace correct? */
if (pix_fmt != ffmpegenc->context->pix_fmt) {
- gst_ffmpeg_avcodec_close (ffmpegenc->context);
+ gst_ffmpeg_avcodec_close (ffmpegenc->context, &ffmpegenc->codecInfo);
GST_DEBUG_OBJECT (ffmpegenc,
"ffenc_%s: AV wants different colourspace (%d given, %d wanted)",
oclass->in_plugin->name, pix_fmt, ffmpegenc->context->pix_fmt);
@@ -708,7 +703,7 @@ gst_ffmpegenc_setcaps (GstPad * pad, GstCaps * caps)
ffmpegenc->context, TRUE);
if (!other_caps) {
- gst_ffmpeg_avcodec_close (ffmpegenc->context);
+ gst_ffmpeg_avcodec_close (ffmpegenc->context, &ffmpegenc->codecInfo);
GST_DEBUG ("Unsupported codec - no caps found");
return FALSE;
}
@@ -732,7 +727,7 @@ gst_ffmpegenc_setcaps (GstPad * pad, GstCaps * caps)
}
if (!gst_pad_set_caps (ffmpegenc->srcpad, icaps)) {
- gst_ffmpeg_avcodec_close (ffmpegenc->context);
+ gst_ffmpeg_avcodec_close (ffmpegenc->context, &ffmpegenc->codecInfo);
gst_caps_unref (icaps);
return FALSE;
}
@@ -795,21 +790,13 @@ gst_ffmpegenc_chain_video (GstPad * pad, GstBuffer * inbuf)
gst_ffmpeg_time_gst_to_ff (GST_BUFFER_TIMESTAMP (inbuf) /
ffmpegenc->context->ticks_per_frame, ffmpegenc->context->time_base);
- GST_CODEC_LOG("picture->pts:%d\n", ffmpegenc->picture->pts)
-
ffmpegenc_setup_working_buf (ffmpegenc);
GST_CODEC_LOG("before avcodec_encode_video, codec_id:%d\n",
ffmpegenc->context->codec_id)
- if (ffmpegenc->context->codec_type == AVMEDIA_TYPE_VIDEO) {
- GST_CODEC_LOG("\n")
- ret_size = emul_avcodec_encode_video (ffmpegenc->context, ffmpegenc->working_buf,
- ffmpegenc->working_buf_size, ffmpegenc->picture, GST_BUFFER_DATA(inbuf));
- } else {
- GST_CODEC_LOG("\n")
- ret_size = avcodec_encode_video (ffmpegenc->context,
- ffmpegenc->working_buf, ffmpegenc->working_buf_size, ffmpegenc->picture);
- }
+ GST_CODEC_LOG("\n")
+ ret_size = emul_avcodec_encode_video (ffmpegenc->context, ffmpegenc->working_buf,
+ ffmpegenc->working_buf_size, ffmpegenc->picture, GST_BUFFER_DATA(inbuf), &ffmpegenc->codecInfo);
GST_CODEC_LOG("after encode video, ret:%d\n", ret_size)
if (ret_size < 0) {
@@ -1101,13 +1088,8 @@ gst_ffmpegenc_flush_buffers (GstFFMpegEnc * ffmpegenc, gboolean send)
GST_CODEC_LOG("before avcodec_encode_video, codec_id:%d\n",
ffmpegenc->context->codec_id)
- if (ffmpegenc->context->codec_type == AVMEDIA_TYPE_VIDEO) {
- ret_size = emul_avcodec_encode_video (ffmpegenc->context,
- ffmpegenc->working_buf, ffmpegenc->working_buf_size, NULL, NULL);
- } else {
- ret_size = avcodec_encode_video (ffmpegenc->context,
- ffmpegenc->working_buf, ffmpegenc->working_buf_size, NULL);
- }
+ ret_size = emul_avcodec_encode_video (ffmpegenc->context,
+ ffmpegenc->working_buf, ffmpegenc->working_buf_size, NULL, NULL, &ffmpegenc->codecInfo);
GST_CODEC_LOG("after encode vidoe : ret(%d)\n", ret_size)
if (ret_size < 0) { /* there should be something, notify and give up */
#ifndef GST_DISABLE_GST_DEBUG
@@ -1299,7 +1281,7 @@ gst_ffmpegenc_change_state (GstElement * element, GstStateChange transition)
case GST_STATE_CHANGE_PAUSED_TO_READY:
gst_ffmpegenc_flush_buffers (ffmpegenc, FALSE);
if (ffmpegenc->opened) {
- gst_ffmpeg_avcodec_close (ffmpegenc->context);
+ gst_ffmpeg_avcodec_close (ffmpegenc->context, &ffmpegenc->codecInfo);
ffmpegenc->opened = FALSE;
}
gst_adapter_clear (ffmpegenc->adapter);