diff mbox series

[FFmpeg-devel,v3,4/6] lavc/vaapi_encode: Extract set output pkt timestamp function

Message ID 20230803060132.501741-4-fei.w.wang@intel.com
State New
Headers show
Series [FFmpeg-devel,v3,1/6] avcodec/cbs_av1: Add tx mode enum values | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Wang, Fei W Aug. 3, 2023, 6:01 a.m. UTC
From: Fei Wang <fei.w.wang@intel.com>

Signed-off-by: Fei Wang <fei.w.wang@intel.com>
---
 libavcodec/vaapi_encode.c | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

Comments

Mark Thompson Aug. 7, 2023, 8:22 p.m. UTC | #1
On 03/08/2023 07:01, fei.w.wang-at-intel.com@ffmpeg.org wrote:
> From: Fei Wang <fei.w.wang@intel.com>
> 
> Signed-off-by: Fei Wang <fei.w.wang@intel.com>
> ---
>   libavcodec/vaapi_encode.c | 37 ++++++++++++++++++++++++-------------
>   1 file changed, 24 insertions(+), 13 deletions(-)
> 
> diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
> index 8c9f14df66..c8545cd8db 100644
> --- a/libavcodec/vaapi_encode.c
> +++ b/libavcodec/vaapi_encode.c
> @@ -650,6 +650,27 @@ fail_at_end:
>       return err;
>   }
>   
> +static int vaapi_encode_set_output_timestamp(AVCodecContext *avctx,
> +                                             VAAPIEncodePicture *pic,
> +                                             AVPacket *pkt)
> +{
> +    VAAPIEncodeContext *ctx = avctx->priv_data;
> +
> +    if (ctx->output_delay == 0) {
> +        pkt->dts = pkt->pts;
> +    } else if (pic->encode_order < ctx->decode_delay) {
> +        if (ctx->ts_ring[pic->encode_order] < INT64_MIN + ctx->dts_pts_diff)
> +            pkt->dts = INT64_MIN;
> +        else
> +            pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
> +    } else {
> +        pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
> +                                (3 * ctx->output_delay + ctx->async_depth)];
> +    }
> +
> +    return 0;
> +}
> +
>   static int vaapi_encode_output(AVCodecContext *avctx,
>                                  VAAPIEncodePicture *pic, AVPacket *pkt)
>   {
> @@ -1273,19 +1294,9 @@ int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
>           return err;
>       }
>   
> -    if (ctx->output_delay == 0) {
> -        pkt->dts = pkt->pts;
> -    } else if (pic->encode_order < ctx->decode_delay) {
> -        if (ctx->ts_ring[pic->encode_order] < INT64_MIN + ctx->dts_pts_diff)
> -            pkt->dts = INT64_MIN;
> -        else
> -            pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
> -    } else {
> -        pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
> -                                (3 * ctx->output_delay + ctx->async_depth)];
> -    }
> -    av_log(avctx, AV_LOG_DEBUG, "Output packet: pts %"PRId64" dts %"PRId64".\n",
> -           pkt->pts, pkt->dts);
> +    vaapi_encode_set_output_timestamp(avctx, pic, pkt);
> +    av_log(avctx, AV_LOG_DEBUG, "Output packet: pts %"PRId64", dts %"PRId64", "
> +           "size %u bytes.\n", pkt->pts, pkt->dts, pkt->size);

Packet size is not unsigned.

>   
>       ctx->output_order = pic->encode_order;
>       vaapi_encode_clear_old(avctx);

Seems fair to extract this to its own function, LGTM.

Thanks,

- Mark
diff mbox series

Patch

diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c
index 8c9f14df66..c8545cd8db 100644
--- a/libavcodec/vaapi_encode.c
+++ b/libavcodec/vaapi_encode.c
@@ -650,6 +650,27 @@  fail_at_end:
     return err;
 }
 
+static int vaapi_encode_set_output_timestamp(AVCodecContext *avctx,
+                                             VAAPIEncodePicture *pic,
+                                             AVPacket *pkt)
+{
+    VAAPIEncodeContext *ctx = avctx->priv_data;
+
+    if (ctx->output_delay == 0) {
+        pkt->dts = pkt->pts;
+    } else if (pic->encode_order < ctx->decode_delay) {
+        if (ctx->ts_ring[pic->encode_order] < INT64_MIN + ctx->dts_pts_diff)
+            pkt->dts = INT64_MIN;
+        else
+            pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
+    } else {
+        pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
+                                (3 * ctx->output_delay + ctx->async_depth)];
+    }
+
+    return 0;
+}
+
 static int vaapi_encode_output(AVCodecContext *avctx,
                                VAAPIEncodePicture *pic, AVPacket *pkt)
 {
@@ -1273,19 +1294,9 @@  int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
         return err;
     }
 
-    if (ctx->output_delay == 0) {
-        pkt->dts = pkt->pts;
-    } else if (pic->encode_order < ctx->decode_delay) {
-        if (ctx->ts_ring[pic->encode_order] < INT64_MIN + ctx->dts_pts_diff)
-            pkt->dts = INT64_MIN;
-        else
-            pkt->dts = ctx->ts_ring[pic->encode_order] - ctx->dts_pts_diff;
-    } else {
-        pkt->dts = ctx->ts_ring[(pic->encode_order - ctx->decode_delay) %
-                                (3 * ctx->output_delay + ctx->async_depth)];
-    }
-    av_log(avctx, AV_LOG_DEBUG, "Output packet: pts %"PRId64" dts %"PRId64".\n",
-           pkt->pts, pkt->dts);
+    vaapi_encode_set_output_timestamp(avctx, pic, pkt);
+    av_log(avctx, AV_LOG_DEBUG, "Output packet: pts %"PRId64", dts %"PRId64", "
+           "size %u bytes.\n", pkt->pts, pkt->dts, pkt->size);
 
     ctx->output_order = pic->encode_order;
     vaapi_encode_clear_old(avctx);