diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2009-05-13 17:59:01 +0200 |
---|---|---|
committer | Wim Taymans <wim.taymans@collabora.co.uk> | 2009-05-13 17:59:01 +0200 |
commit | 42797bbdc284e93138e7d6ae5203c5ebe042260c (patch) | |
tree | 3b6ee65753b2b394585ddfbd220ee6ddcd366916 | |
parent | 63a4d4f33204fdffbe870636f2fec015e84c0a6f (diff) |
ffmpegenc: use new adapter timestamp handlingwork
-rw-r--r-- | ext/ffmpeg/gstffmpegenc.c | 50 | ||||
-rw-r--r-- | ext/ffmpeg/gstffmpegenc.h | 2 |
2 files changed, 23 insertions, 29 deletions
diff --git a/ext/ffmpeg/gstffmpegenc.c b/ext/ffmpeg/gstffmpegenc.c index 9a0bf4e..e3a9bd6 100644 --- a/ext/ffmpeg/gstffmpegenc.c +++ b/ext/ffmpeg/gstffmpegenc.c @@ -781,7 +781,8 @@ gst_ffmpegenc_chain_audio (GstPad * pad, GstBuffer * inbuf) if (frame_size > 1) { /* we have a frame_size, feed the encoder multiples of this frame size */ - guint avail, frame_bytes; + guint avail, frame_bytes, bps; + guint64 dist; if (discont) { GST_LOG_OBJECT (ffmpegenc, "DISCONT, clear adapter"); @@ -789,52 +790,47 @@ gst_ffmpegenc_chain_audio (GstPad * pad, GstBuffer * inbuf) ffmpegenc->discont = TRUE; } - if (gst_adapter_available (ffmpegenc->adapter) == 0) { - /* lock on to new timestamp */ - GST_LOG_OBJECT (ffmpegenc, "taking buffer timestamp %" GST_TIME_FORMAT, - GST_TIME_ARGS (timestamp)); - ffmpegenc->adapter_ts = timestamp; - ffmpegenc->adapter_consumed = 0; - } else { - /* use timestamp at head of the adapter */ - GST_LOG_OBJECT (ffmpegenc, "taking adapter timestamp %" GST_TIME_FORMAT, - GST_TIME_ARGS (ffmpegenc->adapter_ts)); - timestamp = ffmpegenc->adapter_ts; - timestamp += - gst_util_uint64_scale (ffmpegenc->adapter_consumed, GST_SECOND, - ctx->sample_rate); - } - GST_LOG_OBJECT (ffmpegenc, "pushing buffer in adapter"); gst_adapter_push (ffmpegenc->adapter, inbuf); /* first see how many bytes we need to feed to the decoder. */ - frame_bytes = frame_size * osize * ctx->channels; + bps = osize * ctx->channels; + frame_bytes = frame_size * bps; avail = gst_adapter_available (ffmpegenc->adapter); GST_LOG_OBJECT (ffmpegenc, "frame_bytes %u, avail %u", frame_bytes, avail); + /* next timestamp of data in the adapter */ + timestamp = gst_adapter_prev_timestamp (ffmpegenc->adapter, &dist); + GST_LOG_OBJECT (ffmpegenc, + "timestamp %" GST_TIME_FORMAT " dist: %" G_GUINT64_FORMAT, + GST_TIME_ARGS (timestamp), dist); + dist /= bps; + timestamp += gst_util_uint64_scale (dist, GST_SECOND, ctx->sample_rate); + /* while there is more than a frame size in the adapter, consume it */ while (avail >= frame_bytes) { + guint64 next_ts; + GST_LOG_OBJECT (ffmpegenc, "taking %u bytes from the adapter", frame_bytes); /* take an audio buffer out of the adapter */ inbuf = gst_adapter_take_buffer (ffmpegenc->adapter, frame_bytes); - ffmpegenc->adapter_consumed += frame_size; - /* calculate timestamp and duration relative to start of adapter and to - * the amount of samples we consumed */ - duration = - gst_util_uint64_scale (ffmpegenc->adapter_consumed, GST_SECOND, - ctx->sample_rate); - duration -= (timestamp - ffmpegenc->adapter_ts); + /* get next timestamp */ + next_ts = gst_adapter_prev_timestamp (ffmpegenc->adapter, &dist); + GST_LOG_OBJECT (ffmpegenc, + "next_ts %" GST_TIME_FORMAT " dist: %" G_GUINT64_FORMAT, + GST_TIME_ARGS (next_ts), dist); + dist /= bps; + next_ts += gst_util_uint64_scale (dist, GST_SECOND, ctx->sample_rate); GST_BUFFER_TIMESTAMP (inbuf) = timestamp; - GST_BUFFER_DURATION (inbuf) = duration; + GST_BUFFER_DURATION (inbuf) = next_ts - timestamp; /* advance the adapter timestamp with the duration */ - timestamp += duration; + timestamp = next_ts; /* 4 times the input size should be big enough... */ out_size = MAX (frame_bytes * 4, FF_MIN_BUFFER_SIZE); diff --git a/ext/ffmpeg/gstffmpegenc.h b/ext/ffmpeg/gstffmpegenc.h index ee8468c..bd4b1f1 100644 --- a/ext/ffmpeg/gstffmpegenc.h +++ b/ext/ffmpeg/gstffmpegenc.h @@ -41,8 +41,6 @@ struct _GstFFMpegEnc AVCodecContext *context; AVFrame *picture; gboolean opened; - GstClockTime adapter_ts; - guint64 adapter_consumed; GstAdapter *adapter; gboolean discont; |