[FFmpeg-devel] [PATCH 3/4] avcodec/mediacodecdec: refactor pts handling
Aman Gupta
ffmpeg at tmm1.net
Tue Apr 24 23:59:25 EEST 2018
From: Aman Gupta <aman at tmm1.net>
Also fixes a bug where EOS buffer was sent with incorrect
pts when not using surface generation.
---
libavcodec/mediacodecdec_common.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/libavcodec/mediacodecdec_common.c b/libavcodec/mediacodecdec_common.c
index 56b3c4fd1e..c0f0a6b983 100644
--- a/libavcodec/mediacodecdec_common.c
+++ b/libavcodec/mediacodecdec_common.c
@@ -571,6 +571,7 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s,
FFAMediaCodec *codec = s->codec;
int status;
int64_t input_dequeue_timeout_us = INPUT_DEQUEUE_TIMEOUT_US;
+ int64_t pts;
if (s->flushing) {
av_log(avctx, AV_LOG_ERROR, "Decoder is flushing and cannot accept new buffer "
@@ -605,14 +606,14 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s,
return AVERROR_EXTERNAL;
}
+ pts = pkt->pts;
+ if (pts != AV_NOPTS_VALUE && avctx->pkt_timebase.num && avctx->pkt_timebase.den) {
+ pts = av_rescale_q(pts, avctx->pkt_timebase, AV_TIME_BASE_Q);
+ }
+
if (need_draining) {
- int64_t pts = pkt->pts;
uint32_t flags = ff_AMediaCodec_getBufferFlagEndOfStream(codec);
- if (s->surface) {
- pts = av_rescale_q(pts, avctx->pkt_timebase, AV_TIME_BASE_Q);
- }
-
av_log(avctx, AV_LOG_DEBUG, "Sending End Of Stream signal\n");
status = ff_AMediaCodec_queueInputBuffer(codec, index, 0, 0, pts, flags);
@@ -627,16 +628,10 @@ int ff_mediacodec_dec_send(AVCodecContext *avctx, MediaCodecDecContext *s,
s->draining = 1;
break;
} else {
- int64_t pts = pkt->pts;
-
size = FFMIN(pkt->size - offset, size);
memcpy(data, pkt->data + offset, size);
offset += size;
- if (avctx->pkt_timebase.num && avctx->pkt_timebase.den) {
- pts = av_rescale_q(pts, avctx->pkt_timebase, AV_TIME_BASE_Q);
- }
-
status = ff_AMediaCodec_queueInputBuffer(codec, index, 0, size, pts, 0);
if (status < 0) {
av_log(avctx, AV_LOG_ERROR, "Failed to queue input buffer (status = %d)\n", status);
--
2.14.2
More information about the ffmpeg-devel
mailing list