[FFmpeg-cvslog] avcodec/cbs_av1: split film grain param fields into their own struct

James Almer git at videolan.org
Tue Dec 1 00:30:36 EET 2020


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Wed Nov 25 16:56:51 2020 -0300| [aea80e227327da2f275e9fb14821eac2b57df930] | committer: James Almer

avcodec/cbs_av1: split film grain param fields into their own struct

Cosmetic change in preparation for the following patches.

Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=aea80e227327da2f275e9fb14821eac2b57df930
---

 libavcodec/cbs_av1.h                 | 62 +++++++++++++++++++-----------------
 libavcodec/cbs_av1_syntax_template.c |  9 +++---
 libavcodec/nvdec_av1.c               | 59 +++++++++++++++++-----------------
 libavcodec/vaapi_av1.c               | 17 +++++-----
 4 files changed, 77 insertions(+), 70 deletions(-)

diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h
index 386774750a..799470015c 100644
--- a/libavcodec/cbs_av1.h
+++ b/libavcodec/cbs_av1.h
@@ -130,6 +130,38 @@ typedef struct AV1RawSequenceHeader {
     uint8_t film_grain_params_present;
 } AV1RawSequenceHeader;
 
+typedef struct AV1RawFilmGrainParams {
+    uint8_t  apply_grain;
+    uint16_t grain_seed;
+    uint8_t  update_grain;
+    uint8_t  film_grain_params_ref_idx;
+    uint8_t  num_y_points;
+    uint8_t  point_y_value[14];
+    uint8_t  point_y_scaling[14];
+    uint8_t  chroma_scaling_from_luma;
+    uint8_t  num_cb_points;
+    uint8_t  point_cb_value[10];
+    uint8_t  point_cb_scaling[10];
+    uint8_t  num_cr_points;
+    uint8_t  point_cr_value[10];
+    uint8_t  point_cr_scaling[10];
+    uint8_t  grain_scaling_minus_8;
+    uint8_t  ar_coeff_lag;
+    uint8_t  ar_coeffs_y_plus_128[24];
+    uint8_t  ar_coeffs_cb_plus_128[25];
+    uint8_t  ar_coeffs_cr_plus_128[25];
+    uint8_t  ar_coeff_shift_minus_6;
+    uint8_t  grain_scale_shift;
+    uint8_t  cb_mult;
+    uint8_t  cb_luma_mult;
+    uint16_t cb_offset;
+    uint8_t  cr_mult;
+    uint8_t  cr_luma_mult;
+    uint16_t cr_offset;
+    uint8_t  overlap_flag;
+    uint8_t  clip_to_restricted_range;
+} AV1RawFilmGrainParams;
+
 typedef struct AV1RawFrameHeader {
     uint8_t  show_existing_frame;
     uint8_t  frame_to_show_map_idx;
@@ -251,35 +283,7 @@ typedef struct AV1RawFrameHeader {
     //AV1RawSubexp gm_params[AV1_TOTAL_REFS_PER_FRAME][6];
     uint32_t gm_params[AV1_TOTAL_REFS_PER_FRAME][6];
 
-    uint8_t  apply_grain;
-    uint16_t grain_seed;
-    uint8_t  update_grain;
-    uint8_t  film_grain_params_ref_idx;
-    uint8_t  num_y_points;
-    uint8_t  point_y_value[14];
-    uint8_t  point_y_scaling[14];
-    uint8_t  chroma_scaling_from_luma;
-    uint8_t  num_cb_points;
-    uint8_t  point_cb_value[10];
-    uint8_t  point_cb_scaling[10];
-    uint8_t  num_cr_points;
-    uint8_t  point_cr_value[10];
-    uint8_t  point_cr_scaling[10];
-    uint8_t  grain_scaling_minus_8;
-    uint8_t  ar_coeff_lag;
-    uint8_t  ar_coeffs_y_plus_128[24];
-    uint8_t  ar_coeffs_cb_plus_128[25];
-    uint8_t  ar_coeffs_cr_plus_128[25];
-    uint8_t  ar_coeff_shift_minus_6;
-    uint8_t  grain_scale_shift;
-    uint8_t  cb_mult;
-    uint8_t  cb_luma_mult;
-    uint16_t cb_offset;
-    uint8_t  cr_mult;
-    uint8_t  cr_luma_mult;
-    uint16_t cr_offset;
-    uint8_t  overlap_flag;
-    uint8_t  clip_to_restricted_range;
+    AV1RawFilmGrainParams film_grain;
 } AV1RawFrameHeader;
 
 typedef struct AV1RawTileData {
diff --git a/libavcodec/cbs_av1_syntax_template.c b/libavcodec/cbs_av1_syntax_template.c
index f866dc7b2e..6fe6e9a4f3 100644
--- a/libavcodec/cbs_av1_syntax_template.c
+++ b/libavcodec/cbs_av1_syntax_template.c
@@ -1194,7 +1194,8 @@ static int FUNC(global_motion_params)(CodedBitstreamContext *ctx, RWContext *rw,
 }
 
 static int FUNC(film_grain_params)(CodedBitstreamContext *ctx, RWContext *rw,
-                                   AV1RawFrameHeader *current)
+                                   AV1RawFilmGrainParams *current,
+                                   AV1RawFrameHeader *frame_header)
 {
     CodedBitstreamAV1Context  *priv = ctx->priv_data;
     const AV1RawSequenceHeader *seq = priv->sequence_header;
@@ -1202,7 +1203,7 @@ static int FUNC(film_grain_params)(CodedBitstreamContext *ctx, RWContext *rw,
     int i, err;
 
     if (!seq->film_grain_params_present ||
-        (!current->show_frame && !current->showable_frame))
+        (!frame_header->show_frame && !frame_header->showable_frame))
         return 0;
 
     flag(apply_grain);
@@ -1212,7 +1213,7 @@ static int FUNC(film_grain_params)(CodedBitstreamContext *ctx, RWContext *rw,
 
     fb(16, grain_seed);
 
-    if (current->frame_type == AV1_FRAME_INTER)
+    if (frame_header->frame_type == AV1_FRAME_INTER)
         flag(update_grain);
     else
         infer(update_grain, 1);
@@ -1635,7 +1636,7 @@ static int FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw,
 
     CHECK(FUNC(global_motion_params)(ctx, rw, current));
 
-    CHECK(FUNC(film_grain_params)(ctx, rw, current));
+    CHECK(FUNC(film_grain_params)(ctx, rw, &current->film_grain, current));
 
     av_log(ctx->log_ctx, AV_LOG_DEBUG, "Frame %d:  size %dx%d  "
            "upscaled %d  render %dx%d  subsample %dx%d  "
diff --git a/libavcodec/nvdec_av1.c b/libavcodec/nvdec_av1.c
index 9da1c840e3..1bac1fe26c 100644
--- a/libavcodec/nvdec_av1.c
+++ b/libavcodec/nvdec_av1.c
@@ -42,6 +42,7 @@ static int nvdec_av1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u
     const AV1DecContext *s = avctx->priv_data;
     const AV1RawSequenceHeader *seq = s->raw_seq;
     const AV1RawFrameHeader *frame_header = s->raw_frame_header;
+    const AV1RawFilmGrainParams *film_grain = &frame_header->film_grain;
 
     NVDECContext      *ctx = avctx->internal->hwaccel_priv_data;
     CUVIDPICPARAMS     *pp = &ctx->pic_params;
@@ -54,7 +55,7 @@ static int nvdec_av1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u
 
     int ret, i, j;
 
-    ret = ff_nvdec_start_frame_sep_ref(avctx, cur_frame, frame_header->apply_grain);
+    ret = ff_nvdec_start_frame_sep_ref(avctx, cur_frame, film_grain->apply_grain);
     if (ret < 0)
         return ret;
 
@@ -181,24 +182,24 @@ static int nvdec_av1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u
             .spatial_layer_id  = s->cur_frame.spatial_id,
 
             /* Film Grain Params */
-            .apply_grain              = frame_header->apply_grain,
-            .overlap_flag             = frame_header->overlap_flag,
-            .scaling_shift_minus8     = frame_header->grain_scaling_minus_8,
-            .chroma_scaling_from_luma = frame_header->chroma_scaling_from_luma,
-            .ar_coeff_lag             = frame_header->ar_coeff_lag,
-            .ar_coeff_shift_minus6    = frame_header->ar_coeff_shift_minus_6,
-            .grain_scale_shift        = frame_header->grain_scale_shift,
-            .clip_to_restricted_range = frame_header->clip_to_restricted_range,
-            .num_y_points             = frame_header->num_y_points,
-            .num_cb_points            = frame_header->num_cb_points,
-            .num_cr_points            = frame_header->num_cr_points,
-            .random_seed              = frame_header->grain_seed,
-            .cb_mult                  = frame_header->cb_mult,
-            .cb_luma_mult             = frame_header->cb_luma_mult,
-            .cb_offset                = frame_header->cb_offset,
-            .cr_mult                  = frame_header->cr_mult,
-            .cr_luma_mult             = frame_header->cr_luma_mult,
-            .cr_offset                = frame_header->cr_offset
+            .apply_grain              = film_grain->apply_grain,
+            .overlap_flag             = film_grain->overlap_flag,
+            .scaling_shift_minus8     = film_grain->grain_scaling_minus_8,
+            .chroma_scaling_from_luma = film_grain->chroma_scaling_from_luma,
+            .ar_coeff_lag             = film_grain->ar_coeff_lag,
+            .ar_coeff_shift_minus6    = film_grain->ar_coeff_shift_minus_6,
+            .grain_scale_shift        = film_grain->grain_scale_shift,
+            .clip_to_restricted_range = film_grain->clip_to_restricted_range,
+            .num_y_points             = film_grain->num_y_points,
+            .num_cb_points            = film_grain->num_cb_points,
+            .num_cr_points            = film_grain->num_cr_points,
+            .random_seed              = film_grain->grain_seed,
+            .cb_mult                  = film_grain->cb_mult,
+            .cb_luma_mult             = film_grain->cb_luma_mult,
+            .cb_offset                = film_grain->cb_offset,
+            .cr_mult                  = film_grain->cr_mult,
+            .cr_luma_mult             = film_grain->cr_luma_mult,
+            .cr_offset                = film_grain->cr_offset
         }
     };
 
@@ -258,23 +259,23 @@ static int nvdec_av1_start_frame(AVCodecContext *avctx, const uint8_t *buffer, u
     }
 
     /* Film Grain Params */
-    if (frame_header->apply_grain) {
+    if (film_grain->apply_grain) {
         for (i = 0; i < 14; ++i) {
-            ppc->scaling_points_y[i][0] = frame_header->point_y_value[i];
-            ppc->scaling_points_y[i][1] = frame_header->point_y_scaling[i];
+            ppc->scaling_points_y[i][0] = film_grain->point_y_value[i];
+            ppc->scaling_points_y[i][1] = film_grain->point_y_scaling[i];
         }
         for (i = 0; i < 10; ++i) {
-            ppc->scaling_points_cb[i][0] = frame_header->point_cb_value[i];
-            ppc->scaling_points_cb[i][1] = frame_header->point_cb_scaling[i];
-            ppc->scaling_points_cr[i][0] = frame_header->point_cr_value[i];
-            ppc->scaling_points_cr[i][1] = frame_header->point_cr_scaling[i];
+            ppc->scaling_points_cb[i][0] = film_grain->point_cb_value[i];
+            ppc->scaling_points_cb[i][1] = film_grain->point_cb_scaling[i];
+            ppc->scaling_points_cr[i][0] = film_grain->point_cr_value[i];
+            ppc->scaling_points_cr[i][1] = film_grain->point_cr_scaling[i];
         }
         for (i = 0; i < 24; ++i) {
-            ppc->ar_coeffs_y[i] = (short)frame_header->ar_coeffs_y_plus_128[i] - 128;
+            ppc->ar_coeffs_y[i] = (short)film_grain->ar_coeffs_y_plus_128[i] - 128;
         }
         for (i = 0; i < 25; ++i) {
-            ppc->ar_coeffs_cb[i] = (short)frame_header->ar_coeffs_cb_plus_128[i] - 128;
-            ppc->ar_coeffs_cr[i] = (short)frame_header->ar_coeffs_cr_plus_128[i] - 128;
+            ppc->ar_coeffs_cb[i] = (short)film_grain->ar_coeffs_cb_plus_128[i] - 128;
+            ppc->ar_coeffs_cr[i] = (short)film_grain->ar_coeffs_cr_plus_128[i] - 128;
         }
     }
 
diff --git a/libavcodec/vaapi_av1.c b/libavcodec/vaapi_av1.c
index fcce86b7e5..21b3eceb91 100644
--- a/libavcodec/vaapi_av1.c
+++ b/libavcodec/vaapi_av1.c
@@ -56,6 +56,7 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx,
     AV1DecContext *s = avctx->priv_data;
     const AV1RawSequenceHeader *seq = s->raw_seq;
     const AV1RawFrameHeader *frame_header = s->raw_frame_header;
+    const AV1RawFilmGrainParams *film_grain = &frame_header->film_grain;
     VAAPIDecodePicture *pic = s->cur_frame.hwaccel_picture_private;
     VADecPictureParameterBufferAV1 pic_param;
     int8_t bit_depth_idx;
@@ -115,14 +116,14 @@ static int vaapi_av1_start_frame(AVCodecContext *avctx,
             .update_data     = frame_header->segmentation_update_data,
         },
         .film_grain_info.film_grain_info_fields.bits = {
-            .apply_grain              = frame_header->apply_grain,
-            .chroma_scaling_from_luma = frame_header->chroma_scaling_from_luma,
-            .grain_scaling_minus_8    = frame_header->grain_scaling_minus_8,
-            .ar_coeff_lag             = frame_header->ar_coeff_lag,
-            .ar_coeff_shift_minus_6   = frame_header->ar_coeff_shift_minus_6,
-            .grain_scale_shift        = frame_header->grain_scale_shift,
-            .overlap_flag             = frame_header->overlap_flag,
-            .clip_to_restricted_range = frame_header->clip_to_restricted_range,
+            .apply_grain              = film_grain->apply_grain,
+            .chroma_scaling_from_luma = film_grain->chroma_scaling_from_luma,
+            .grain_scaling_minus_8    = film_grain->grain_scaling_minus_8,
+            .ar_coeff_lag             = film_grain->ar_coeff_lag,
+            .ar_coeff_shift_minus_6   = film_grain->ar_coeff_shift_minus_6,
+            .grain_scale_shift        = film_grain->grain_scale_shift,
+            .overlap_flag             = film_grain->overlap_flag,
+            .clip_to_restricted_range = film_grain->clip_to_restricted_range,
         },
         .pic_info_fields.bits = {
             .frame_type                   = frame_header->frame_type,



More information about the ffmpeg-cvslog mailing list