From 6e5fa03b6b75d84dca375746a837a8676e8f9254 Mon Sep 17 00:00:00 2001 From: Luca Ognibene Date: Wed, 11 May 2005 15:18:23 +0000 Subject: [PATCH] ext/ffmpeg/: Makes ffmpegdec and ffmpegenc use these functions and remove a comment from a previuos patch Original commit message from CVS: * ext/ffmpeg/gstffmpegenc.c (gst_ffmpegenc_chain_video): * ext/ffmpeg/gstffmpegdec.c (gst_ffmpegdec_chain): Makes ffmpegdec and ffmpegenc use these functions and remove a comment from a previuos patch * ext/ffmpeg/gstffmpegcodecmap.h: Add two utility functions to convert the pts from/to the ffmpeg format --- ChangeLog | 11 +++++++++++ ext/ffmpeg/gstffmpegcodecmap.h | 29 +++++++++++++++++++++++++++++ ext/ffmpeg/gstffmpegdec.c | 13 ++++--------- ext/ffmpeg/gstffmpegenc.c | 2 +- 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 37785b8..4b31fa7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2005-05-11 Luca Ognibene + + * ext/ffmpeg/gstffmpegenc.c (gst_ffmpegenc_chain_video): + * ext/ffmpeg/gstffmpegdec.c (gst_ffmpegdec_chain): + Makes ffmpegdec and ffmpegenc use these functions + and remove a comment from a previuos patch + + * ext/ffmpeg/gstffmpegcodecmap.h: + Add two utility functions to convert the pts from/to + the ffmpeg format + 2005-05-06 Luca Ognibene Reviewed by: Ronald S. Bultje diff --git a/ext/ffmpeg/gstffmpegcodecmap.h b/ext/ffmpeg/gstffmpegcodecmap.h index 4ba8287..c4bd1d6 100644 --- a/ext/ffmpeg/gstffmpegcodecmap.h +++ b/ext/ffmpeg/gstffmpegcodecmap.h @@ -132,5 +132,34 @@ gst_ffmpeg_img_convert (AVPicture * dst, int dst_pix_fmt, const AVPicture * src, int src_pix_fmt, int src_width, int src_height); + + +static inline int64_t +gst_ffmpeg_pts_gst_to_ffmpeg (GstClockTime inpts) { + + int64_t outpts; + + if (GST_CLOCK_TIME_IS_VALID (inpts)) + outpts = (inpts / (GST_SECOND / AV_TIME_BASE)); + else + outpts = AV_NOPTS_VALUE; + + return outpts; +} + +static inline GstClockTime +gst_ffmpeg_pts_ffmpeg_to_gst (int64_t inpts) { + + GstClockTime outpts; + + if (inpts != AV_NOPTS_VALUE) + outpts = (inpts * (GST_SECOND / AV_TIME_BASE)); + else + outpts = GST_CLOCK_TIME_NONE; + + return outpts; +} + + #endif /* __GST_FFMPEG_CODECMAP_H__ */ diff --git a/ext/ffmpeg/gstffmpegdec.c b/ext/ffmpeg/gstffmpegdec.c index c59284f..437cc63 100644 --- a/ext/ffmpeg/gstffmpegdec.c +++ b/ext/ffmpeg/gstffmpegdec.c @@ -944,11 +944,10 @@ gst_ffmpegdec_chain (GstPad * pad, GstData * _data) /* parse, if at all possible */ if (ffmpegdec->pctx) { gint res; - gint64 ffpts = AV_NOPTS_VALUE; + gint64 ffpts; + + ffpts = gst_ffmpeg_pts_gst_to_ffmpeg (in_ts); - if (GST_CLOCK_TIME_IS_VALID (in_ts)) - ffpts = in_ts / (GST_SECOND / AV_TIME_BASE); - res = av_parser_parse (ffmpegdec->pctx, ffmpegdec->context, &data, &size, bdata, bsize, ffpts, ffpts); @@ -956,8 +955,7 @@ gst_ffmpegdec_chain (GstPad * pad, GstData * _data) GST_DEBUG_OBJECT (ffmpegdec, "Parsed video frame, res=%d, size=%d", res, size); - if (ffmpegdec->pctx->pts != AV_NOPTS_VALUE) - in_ts = ffmpegdec->pctx->pts * (GST_SECOND / AV_TIME_BASE); + in_ts = gst_ffmpeg_pts_ffmpeg_to_gst (ffmpegdec->pctx->pts); if (res == 0 || size == 0) break; @@ -1005,9 +1003,6 @@ gst_ffmpegdec_change_state (GstElement * element) if (ffmpegdec->last_buffer != NULL) { gst_buffer_unref (ffmpegdec->last_buffer); } - - /* closing context.. unref buffers? */ - gst_ffmpegdec_close (ffmpegdec); break; } diff --git a/ext/ffmpeg/gstffmpegenc.c b/ext/ffmpeg/gstffmpegenc.c index cc815f1..ca11423 100644 --- a/ext/ffmpeg/gstffmpegenc.c +++ b/ext/ffmpeg/gstffmpegenc.c @@ -468,7 +468,7 @@ gst_ffmpegenc_chain_video (GstPad * pad, GstData * _data) ffmpegenc->context->width, ffmpegenc->context->height); g_return_if_fail (frame_size == GST_BUFFER_SIZE (inbuf)); - ffmpegenc->picture->pts = GST_BUFFER_TIMESTAMP (inbuf) / 1000; + ffmpegenc->picture->pts = gst_ffmpeg_pts_gst_to_ffmpeg (GST_BUFFER_TIMESTAMP (inbuf)); outbuf = gst_buffer_new_and_alloc (ffmpegenc->buffer_size); ret_size = avcodec_encode_video (ffmpegenc->context, -- 2.7.4