Commit d8e92a89 authored by Aman Gupta's avatar Aman Gupta

avcodec/mediacodecdec: refactor pts handling

Also fixes a bug where EOS buffer was sent with incorrect
pts when not using surface generation.
Signed-off-by: 's avatarMatthieu Bouron <matthieu.bouron@gmail.com>
Signed-off-by: 's avatarAman Gupta <aman@tmm1.net>
parent 7a4639b1
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment