diff mbox

[FFmpeg-devel,3/4] avcodec/mediacodecdec: refactor pts handling

Message ID 20180424205926.42027-3-ffmpeg@tmm1.net
State Accepted
Commit d8e92a89edd8e73cdc7f125f078c576df10b66f2
Headers show

Commit Message

Aman Gupta April 24, 2018, 8:59 p.m. UTC
From: Aman Gupta <aman@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(-)

Comments

Matthieu Bouron April 25, 2018, 4:10 p.m. UTC | #1
On Tue, Apr 24, 2018 at 01:59:25PM -0700, Aman Gupta wrote:
> From: Aman Gupta <aman@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
> 

LGTM.
diff mbox

Patch

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);