diff mbox series

[FFmpeg-devel,2/4] avcodec/av1dec: expose coded_lossless

Message ID 20201109163057.18005-3-timo@rothenpieler.org
State Accepted
Headers show
Series Add NVDEC AV1 hwaccel | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Timo Rothenpieler Nov. 9, 2020, 4:30 p.m. UTC
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
Co-authored-by: James Almer <jamrial@gmail.com>
---
 libavcodec/av1dec.c | 32 +++++++++++++++++++++++++++++++-
 libavcodec/av1dec.h |  2 ++
 2 files changed, 33 insertions(+), 1 deletion(-)

Comments

Mark Thompson Nov. 9, 2020, 10:38 p.m. UTC | #1
On 09/11/2020 16:30, Timo Rothenpieler wrote:
> Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
> Co-authored-by: James Almer <jamrial@gmail.com>
> ---
>   libavcodec/av1dec.c | 32 +++++++++++++++++++++++++++++++-
>   libavcodec/av1dec.h |  2 ++
>   2 files changed, 33 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
> index 83295699e1..bde1124434 100644
> --- a/libavcodec/av1dec.c
> +++ b/libavcodec/av1dec.c
> @@ -226,6 +226,34 @@ static void skip_mode_params(AV1DecContext *s)
>           AV1_REF_FRAME_LAST + FFMAX(forward_idx, second_forward_idx);
>   }
>   
> +static void coded_lossless_param(AV1DecContext *s)
> +{
> +    const AV1RawFrameHeader *header = s->raw_frame_header;
> +    int i;
> +
> +    if (header->delta_q_y_dc || header->delta_q_u_ac ||
> +        header->delta_q_u_dc || header->delta_q_v_ac ||
> +        header->delta_q_v_dc)
> +        return;

Just write the field here.  Relying on the reset to zero by the previous unref is nonobvious enough that it looked like an error.

> +
> +    s->cur_frame.coded_lossless = 1;
> +    for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
> +        int qindex;
> +        if (header->feature_enabled[i][AV1_SEG_LVL_ALT_Q]) {
> +            qindex = (header->base_q_idx +
> +                      header->feature_value[i][AV1_SEG_LVL_ALT_Q]);
> +        } else {
> +            qindex = header->base_q_idx;
> +        }
> +        qindex = av_clip_uintp2(qindex, 8);
> +
> +        if (qindex) {
> +            s->cur_frame.coded_lossless = 0;
> +            return;
> +        }
> +    } > +}
> +
>   static int init_tile_data(AV1DecContext *s)
>   
>   {
> @@ -398,7 +426,7 @@ static void av1_frame_unref(AVCodecContext *avctx, AV1Frame *f)
>       ff_thread_release_buffer(avctx, &f->tf);
>       av_buffer_unref(&f->hwaccel_priv_buf);
>       f->hwaccel_picture_private = NULL;
> -    f->spatial_id = f->temporal_id = 0;
> +    f->spatial_id = f->temporal_id = f->coded_lossless = 0;

Mild dislike for combining with an unrelated assignment which happens to have the same value.

>       f->order_hint = 0;
>   }
>   
> @@ -419,6 +447,7 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *s
>   
>       dst->spatial_id = src->spatial_id;
>       dst->temporal_id = src->temporal_id;
> +    dst->coded_lossless = src->coded_lossless;
>       memcpy(dst->skip_mode_frame_idx,
>              src->skip_mode_frame_idx,
>              2 * sizeof(uint8_t));
> @@ -700,6 +729,7 @@ static int get_current_frame(AVCodecContext *avctx)
>   
>       global_motion_params(s);
>       skip_mode_params(s);
> +    coded_lossless_param(s);
>   
>       return ret;
>   }
> diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h
> index 8cf50f0d59..32a77425cd 100644
> --- a/libavcodec/av1dec.h
> +++ b/libavcodec/av1dec.h
> @@ -44,6 +44,8 @@ typedef struct AV1Frame {
>   
>       uint8_t order_hint;
>       uint8_t skip_mode_frame_idx[2];
> +
> +    int coded_lossless;

uint8_t - it's a single bit.

>   } AV1Frame;
>   
>   typedef struct TileGroupInfo {
> 

- Mark
diff mbox series

Patch

diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 83295699e1..bde1124434 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -226,6 +226,34 @@  static void skip_mode_params(AV1DecContext *s)
         AV1_REF_FRAME_LAST + FFMAX(forward_idx, second_forward_idx);
 }
 
+static void coded_lossless_param(AV1DecContext *s)
+{
+    const AV1RawFrameHeader *header = s->raw_frame_header;
+    int i;
+
+    if (header->delta_q_y_dc || header->delta_q_u_ac ||
+        header->delta_q_u_dc || header->delta_q_v_ac ||
+        header->delta_q_v_dc)
+        return;
+
+    s->cur_frame.coded_lossless = 1;
+    for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
+        int qindex;
+        if (header->feature_enabled[i][AV1_SEG_LVL_ALT_Q]) {
+            qindex = (header->base_q_idx +
+                      header->feature_value[i][AV1_SEG_LVL_ALT_Q]);
+        } else {
+            qindex = header->base_q_idx;
+        }
+        qindex = av_clip_uintp2(qindex, 8);
+
+        if (qindex) {
+            s->cur_frame.coded_lossless = 0;
+            return;
+        }
+    }
+}
+
 static int init_tile_data(AV1DecContext *s)
 
 {
@@ -398,7 +426,7 @@  static void av1_frame_unref(AVCodecContext *avctx, AV1Frame *f)
     ff_thread_release_buffer(avctx, &f->tf);
     av_buffer_unref(&f->hwaccel_priv_buf);
     f->hwaccel_picture_private = NULL;
-    f->spatial_id = f->temporal_id = 0;
+    f->spatial_id = f->temporal_id = f->coded_lossless = 0;
     f->order_hint = 0;
 }
 
@@ -419,6 +447,7 @@  static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *s
 
     dst->spatial_id = src->spatial_id;
     dst->temporal_id = src->temporal_id;
+    dst->coded_lossless = src->coded_lossless;
     memcpy(dst->skip_mode_frame_idx,
            src->skip_mode_frame_idx,
            2 * sizeof(uint8_t));
@@ -700,6 +729,7 @@  static int get_current_frame(AVCodecContext *avctx)
 
     global_motion_params(s);
     skip_mode_params(s);
+    coded_lossless_param(s);
 
     return ret;
 }
diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h
index 8cf50f0d59..32a77425cd 100644
--- a/libavcodec/av1dec.h
+++ b/libavcodec/av1dec.h
@@ -44,6 +44,8 @@  typedef struct AV1Frame {
 
     uint8_t order_hint;
     uint8_t skip_mode_frame_idx[2];
+
+    int coded_lossless;
 } AV1Frame;
 
 typedef struct TileGroupInfo {