[FFmpeg-cvslog] h264: factor out pred weight table parsing into a separate file

Anton Khirnov git at videolan.org
Tue Apr 26 16:04:55 CEST 2016


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Mon Mar 21 16:14:31 2016 +0100| [e481458bc308ee838deaeacac51929514762e7a7] | committer: Anton Khirnov

h264: factor out pred weight table parsing into a separate file

This will allow decoupling the parser from the decoder.

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

 libavcodec/Makefile           |    4 +-
 libavcodec/dxva2_h264.c       |   20 +++++-----
 libavcodec/h264.c             |   62 -----------------------------
 libavcodec/h264.h             |   14 +------
 libavcodec/h264_mb.c          |   54 +++++++++++++-------------
 libavcodec/h264_mc_template.c |    6 +--
 libavcodec/h264_parse.c       |   86 +++++++++++++++++++++++++++++++++++++++++
 libavcodec/h264_parse.h       |   48 +++++++++++++++++++++++
 libavcodec/h264_parser.c      |    3 +-
 libavcodec/h264_refs.c        |    8 ++--
 libavcodec/h264_slice.c       |   35 +++++++++--------
 libavcodec/vaapi_h264.c       |   24 ++++++------
 12 files changed, 214 insertions(+), 150 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index e253e7e..54b12d3 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -252,7 +252,7 @@ OBJS-$(CONFIG_H264_DECODER)            += h264.o h264_cabac.o h264_cavlc.o \
                                           h264_direct.o h264_loopfilter.o  \
                                           h264_mb.o h264_picture.o h264_ps.o \
                                           h264_refs.o h264_sei.o \
-                                          h264_slice.o h264data.o
+                                          h264_slice.o h264data.o h264_parse.o
 OBJS-$(CONFIG_H264_MMAL_DECODER)       += mmaldec.o
 OBJS-$(CONFIG_H264_NVENC_ENCODER)      += nvenc_h264.o
 OBJS-$(CONFIG_H264_QSV_DECODER)        += qsvdec_h2645.o
@@ -718,7 +718,7 @@ OBJS-$(CONFIG_FLAC_PARSER)             += flac_parser.o flacdata.o flac.o
 OBJS-$(CONFIG_GSM_PARSER)              += gsm_parser.o
 OBJS-$(CONFIG_H261_PARSER)             += h261_parser.o
 OBJS-$(CONFIG_H263_PARSER)             += h263_parser.o
-OBJS-$(CONFIG_H264_PARSER)             += h264_parser.o
+OBJS-$(CONFIG_H264_PARSER)             += h264_parser.o h264_parse.o
 OBJS-$(CONFIG_HEVC_PARSER)             += hevc_parser.o h2645_parse.o hevc_ps.o hevc_data.o
 OBJS-$(CONFIG_MJPEG_PARSER)            += mjpeg_parser.o
 OBJS-$(CONFIG_MLP_PARSER)              += mlp_parser.o mlp.o
diff --git a/libavcodec/dxva2_h264.c b/libavcodec/dxva2_h264.c
index eceb956..2d6fa79 100644
--- a/libavcodec/dxva2_h264.c
+++ b/libavcodec/dxva2_h264.c
@@ -230,8 +230,8 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice,
     slice->slice_type            = ff_h264_get_slice_type(sl);
     if (sl->slice_type_fixed)
         slice->slice_type += 5;
-    slice->luma_log2_weight_denom       = sl->luma_log2_weight_denom;
-    slice->chroma_log2_weight_denom     = sl->chroma_log2_weight_denom;
+    slice->luma_log2_weight_denom       = sl->pwt.luma_log2_weight_denom;
+    slice->chroma_log2_weight_denom     = sl->pwt.chroma_log2_weight_denom;
     if (sl->list_count > 0)
         slice->num_ref_idx_l0_active_minus1 = sl->ref_count[0] - 1;
     if (sl->list_count > 1)
@@ -255,15 +255,15 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice,
                                    r->reference == PICT_BOTTOM_FIELD);
                 for (plane = 0; plane < 3; plane++) {
                     int w, o;
-                    if (plane == 0 && sl->luma_weight_flag[list]) {
-                        w = sl->luma_weight[i][list][0];
-                        o = sl->luma_weight[i][list][1];
-                    } else if (plane >= 1 && sl->chroma_weight_flag[list]) {
-                        w = sl->chroma_weight[i][list][plane-1][0];
-                        o = sl->chroma_weight[i][list][plane-1][1];
+                    if (plane == 0 && sl->pwt.luma_weight_flag[list]) {
+                        w = sl->pwt.luma_weight[i][list][0];
+                        o = sl->pwt.luma_weight[i][list][1];
+                    } else if (plane >= 1 && sl->pwt.chroma_weight_flag[list]) {
+                        w = sl->pwt.chroma_weight[i][list][plane-1][0];
+                        o = sl->pwt.chroma_weight[i][list][plane-1][1];
                     } else {
-                        w = 1 << (plane == 0 ? sl->luma_log2_weight_denom :
-                                               sl->chroma_log2_weight_denom);
+                        w = 1 << (plane == 0 ? sl->pwt.luma_log2_weight_denom :
+                                               sl->pwt.chroma_log2_weight_denom);
                         o = 0;
                     }
                     slice->Weights[list][i][plane][0] = w;
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 0b5b6c2..5332203 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -978,68 +978,6 @@ static void decode_postinit(H264Context *h, int setup_finished)
     }
 }
 
-int ff_pred_weight_table(H264Context *h, H264SliceContext *sl)
-{
-    int list, i;
-    int luma_def, chroma_def;
-
-    sl->use_weight             = 0;
-    sl->use_weight_chroma      = 0;
-    sl->luma_log2_weight_denom = get_ue_golomb(&sl->gb);
-    if (h->sps.chroma_format_idc)
-        sl->chroma_log2_weight_denom = get_ue_golomb(&sl->gb);
-    luma_def   = 1 << sl->luma_log2_weight_denom;
-    chroma_def = 1 << sl->chroma_log2_weight_denom;
-
-    for (list = 0; list < 2; list++) {
-        sl->luma_weight_flag[list]   = 0;
-        sl->chroma_weight_flag[list] = 0;
-        for (i = 0; i < sl->ref_count[list]; i++) {
-            int luma_weight_flag, chroma_weight_flag;
-
-            luma_weight_flag = get_bits1(&sl->gb);
-            if (luma_weight_flag) {
-                sl->luma_weight[i][list][0] = get_se_golomb(&sl->gb);
-                sl->luma_weight[i][list][1] = get_se_golomb(&sl->gb);
-                if (sl->luma_weight[i][list][0] != luma_def ||
-                    sl->luma_weight[i][list][1] != 0) {
-                    sl->use_weight             = 1;
-                    sl->luma_weight_flag[list] = 1;
-                }
-            } else {
-                sl->luma_weight[i][list][0] = luma_def;
-                sl->luma_weight[i][list][1] = 0;
-            }
-
-            if (h->sps.chroma_format_idc) {
-                chroma_weight_flag = get_bits1(&sl->gb);
-                if (chroma_weight_flag) {
-                    int j;
-                    for (j = 0; j < 2; j++) {
-                        sl->chroma_weight[i][list][j][0] = get_se_golomb(&sl->gb);
-                        sl->chroma_weight[i][list][j][1] = get_se_golomb(&sl->gb);
-                        if (sl->chroma_weight[i][list][j][0] != chroma_def ||
-                            sl->chroma_weight[i][list][j][1] != 0) {
-                            sl->use_weight_chroma        = 1;
-                            sl->chroma_weight_flag[list] = 1;
-                        }
-                    }
-                } else {
-                    int j;
-                    for (j = 0; j < 2; j++) {
-                        sl->chroma_weight[i][list][j][0] = chroma_def;
-                        sl->chroma_weight[i][list][j][1] = 0;
-                    }
-                }
-            }
-        }
-        if (sl->slice_type_nos != AV_PICTURE_TYPE_B)
-            break;
-    }
-    sl->use_weight = sl->use_weight || sl->use_weight_chroma;
-    return 0;
-}
-
 /**
  * instantaneous decoder refresh.
  */
diff --git a/libavcodec/h264.h b/libavcodec/h264.h
index 72ad352..3fe5b9c 100644
--- a/libavcodec/h264.h
+++ b/libavcodec/h264.h
@@ -33,6 +33,7 @@
 #include "cabac.h"
 #include "error_resilience.h"
 #include "get_bits.h"
+#include "h264_parse.h"
 #include "h264chroma.h"
 #include "h264dsp.h"
 #include "h264pred.h"
@@ -329,17 +330,7 @@ typedef struct H264SliceContext {
     int slice_alpha_c0_offset;
     int slice_beta_offset;
 
-    // Weighted pred stuff
-    int use_weight;
-    int use_weight_chroma;
-    int luma_log2_weight_denom;
-    int chroma_log2_weight_denom;
-    int luma_weight_flag[2];    ///< 7.4.3.2 luma_weight_lX_flag
-    int chroma_weight_flag[2];  ///< 7.4.3.2 chroma_weight_lX_flag
-    // The following 2 can be changed to int8_t but that causes 10cpu cycles speedloss
-    int luma_weight[48][2][2];
-    int chroma_weight[48][2][2][2];
-    int implicit_weight[48][48][2];
+    H264PredWeightTable pwt;
 
     int prev_mb_skipped;
     int next_mb_skipped;
@@ -1085,7 +1076,6 @@ int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl);
 
 void ff_h264_draw_horiz_band(const H264Context *h, H264SliceContext *sl, int y, int height);
 int ff_init_poc(H264Context *h, int pic_field_poc[2], int *pic_poc);
-int ff_pred_weight_table(H264Context *h, H264SliceContext *sl);
 int ff_set_ref_count(H264Context *h, H264SliceContext *sl);
 
 int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl);
diff --git a/libavcodec/h264_mb.c b/libavcodec/h264_mb.c
index 2487b96..f94333b 100644
--- a/libavcodec/h264_mb.c
+++ b/libavcodec/h264_mb.c
@@ -419,8 +419,8 @@ static av_always_inline void mc_part_weighted(const H264Context *h, H264SliceCon
                     x_offset, y_offset, qpix_put, chroma_put,
                     pixel_shift, chroma_idc);
 
-        if (sl->use_weight == 2) {
-            int weight0 = sl->implicit_weight[refn0][refn1][sl->mb_y & 1];
+        if (sl->pwt.use_weight == 2) {
+            int weight0 = sl->pwt.implicit_weight[refn0][refn1][sl->mb_y & 1];
             int weight1 = 64 - weight0;
             luma_weight_avg(dest_y, tmp_y, sl->mb_linesize,
                             height, 5, weight0, weight1, 0);
@@ -430,23 +430,23 @@ static av_always_inline void mc_part_weighted(const H264Context *h, H264SliceCon
                               chroma_height, 5, weight0, weight1, 0);
         } else {
             luma_weight_avg(dest_y, tmp_y, sl->mb_linesize, height,
-                            sl->luma_log2_weight_denom,
-                            sl->luma_weight[refn0][0][0],
-                            sl->luma_weight[refn1][1][0],
-                            sl->luma_weight[refn0][0][1] +
-                            sl->luma_weight[refn1][1][1]);
+                            sl->pwt.luma_log2_weight_denom,
+                            sl->pwt.luma_weight[refn0][0][0],
+                            sl->pwt.luma_weight[refn1][1][0],
+                            sl->pwt.luma_weight[refn0][0][1] +
+                            sl->pwt.luma_weight[refn1][1][1]);
             chroma_weight_avg(dest_cb, tmp_cb, sl->mb_uvlinesize, chroma_height,
-                              sl->chroma_log2_weight_denom,
-                              sl->chroma_weight[refn0][0][0][0],
-                              sl->chroma_weight[refn1][1][0][0],
-                              sl->chroma_weight[refn0][0][0][1] +
-                              sl->chroma_weight[refn1][1][0][1]);
+                              sl->pwt.chroma_log2_weight_denom,
+                              sl->pwt.chroma_weight[refn0][0][0][0],
+                              sl->pwt.chroma_weight[refn1][1][0][0],
+                              sl->pwt.chroma_weight[refn0][0][0][1] +
+                              sl->pwt.chroma_weight[refn1][1][0][1]);
             chroma_weight_avg(dest_cr, tmp_cr, sl->mb_uvlinesize, chroma_height,
-                              sl->chroma_log2_weight_denom,
-                              sl->chroma_weight[refn0][0][1][0],
-                              sl->chroma_weight[refn1][1][1][0],
-                              sl->chroma_weight[refn0][0][1][1] +
-                              sl->chroma_weight[refn1][1][1][1]);
+                              sl->pwt.chroma_log2_weight_denom,
+                              sl->pwt.chroma_weight[refn0][0][1][0],
+                              sl->pwt.chroma_weight[refn1][1][1][0],
+                              sl->pwt.chroma_weight[refn0][0][1][1] +
+                              sl->pwt.chroma_weight[refn1][1][1][1]);
         }
     } else {
         int list     = list1 ? 1 : 0;
@@ -457,18 +457,18 @@ static av_always_inline void mc_part_weighted(const H264Context *h, H264SliceCon
                     qpix_put, chroma_put, pixel_shift, chroma_idc);
 
         luma_weight_op(dest_y, sl->mb_linesize, height,
-                       sl->luma_log2_weight_denom,
-                       sl->luma_weight[refn][list][0],
-                       sl->luma_weight[refn][list][1]);
-        if (sl->use_weight_chroma) {
+                       sl->pwt.luma_log2_weight_denom,
+                       sl->pwt.luma_weight[refn][list][0],
+                       sl->pwt.luma_weight[refn][list][1]);
+        if (sl->pwt.use_weight_chroma) {
             chroma_weight_op(dest_cb, sl->mb_uvlinesize, chroma_height,
-                             sl->chroma_log2_weight_denom,
-                             sl->chroma_weight[refn][list][0][0],
-                             sl->chroma_weight[refn][list][0][1]);
+                             sl->pwt.chroma_log2_weight_denom,
+                             sl->pwt.chroma_weight[refn][list][0][0],
+                             sl->pwt.chroma_weight[refn][list][0][1]);
             chroma_weight_op(dest_cr, sl->mb_uvlinesize, chroma_height,
-                             sl->chroma_log2_weight_denom,
-                             sl->chroma_weight[refn][list][1][0],
-                             sl->chroma_weight[refn][list][1][1]);
+                             sl->pwt.chroma_log2_weight_denom,
+                             sl->pwt.chroma_weight[refn][list][1][0],
+                             sl->pwt.chroma_weight[refn][list][1][1]);
         }
     }
 }
diff --git a/libavcodec/h264_mc_template.c b/libavcodec/h264_mc_template.c
index a295859..8ae1eef 100644
--- a/libavcodec/h264_mc_template.c
+++ b/libavcodec/h264_mc_template.c
@@ -48,9 +48,9 @@ static void mc_part(const H264Context *h, H264SliceContext *sl,
                     const h264_biweight_func *weight_avg,
                     int list0, int list1)
 {
-    if ((sl->use_weight == 2 && list0 && list1 &&
-         (sl->implicit_weight[sl->ref_cache[0][scan8[n]]][sl->ref_cache[1][scan8[n]]][sl->mb_y & 1] != 32)) ||
-        sl->use_weight == 1)
+    if ((sl->pwt.use_weight == 2 && list0 && list1 &&
+         (sl->pwt.implicit_weight[sl->ref_cache[0][scan8[n]]][sl->ref_cache[1][scan8[n]]][sl->mb_y & 1] != 32)) ||
+        sl->pwt.use_weight == 1)
         mc_part_weighted(h, sl, n, square, height, delta, dest_y, dest_cb, dest_cr,
                          x_offset, y_offset, qpix_put, chroma_put,
                          weight_op[0], weight_op[1], weight_avg[0],
diff --git a/libavcodec/h264_parse.c b/libavcodec/h264_parse.c
new file mode 100644
index 0000000..88caa48
--- /dev/null
+++ b/libavcodec/h264_parse.c
@@ -0,0 +1,86 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "get_bits.h"
+#include "golomb.h"
+#include "h264.h"
+#include "h264_parse.h"
+
+int ff_h264_pred_weight_table(GetBitContext *gb, const SPS *sps,
+                              const int *ref_count, int slice_type_nos,
+                              H264PredWeightTable *pwt)
+{
+    int list, i;
+    int luma_def, chroma_def;
+
+    pwt->use_weight             = 0;
+    pwt->use_weight_chroma      = 0;
+    pwt->luma_log2_weight_denom = get_ue_golomb(gb);
+    if (sps->chroma_format_idc)
+        pwt->chroma_log2_weight_denom = get_ue_golomb(gb);
+    luma_def   = 1 << pwt->luma_log2_weight_denom;
+    chroma_def = 1 << pwt->chroma_log2_weight_denom;
+
+    for (list = 0; list < 2; list++) {
+        pwt->luma_weight_flag[list]   = 0;
+        pwt->chroma_weight_flag[list] = 0;
+        for (i = 0; i < ref_count[list]; i++) {
+            int luma_weight_flag, chroma_weight_flag;
+
+            luma_weight_flag = get_bits1(gb);
+            if (luma_weight_flag) {
+                pwt->luma_weight[i][list][0] = get_se_golomb(gb);
+                pwt->luma_weight[i][list][1] = get_se_golomb(gb);
+                if (pwt->luma_weight[i][list][0] != luma_def ||
+                    pwt->luma_weight[i][list][1] != 0) {
+                    pwt->use_weight             = 1;
+                    pwt->luma_weight_flag[list] = 1;
+                }
+            } else {
+                pwt->luma_weight[i][list][0] = luma_def;
+                pwt->luma_weight[i][list][1] = 0;
+            }
+
+            if (sps->chroma_format_idc) {
+                chroma_weight_flag = get_bits1(gb);
+                if (chroma_weight_flag) {
+                    int j;
+                    for (j = 0; j < 2; j++) {
+                        pwt->chroma_weight[i][list][j][0] = get_se_golomb(gb);
+                        pwt->chroma_weight[i][list][j][1] = get_se_golomb(gb);
+                        if (pwt->chroma_weight[i][list][j][0] != chroma_def ||
+                            pwt->chroma_weight[i][list][j][1] != 0) {
+                            pwt->use_weight_chroma        = 1;
+                            pwt->chroma_weight_flag[list] = 1;
+                        }
+                    }
+                } else {
+                    int j;
+                    for (j = 0; j < 2; j++) {
+                        pwt->chroma_weight[i][list][j][0] = chroma_def;
+                        pwt->chroma_weight[i][list][j][1] = 0;
+                    }
+                }
+            }
+        }
+        if (slice_type_nos != AV_PICTURE_TYPE_B)
+            break;
+    }
+    pwt->use_weight = pwt->use_weight || pwt->use_weight_chroma;
+    return 0;
+}
diff --git a/libavcodec/h264_parse.h b/libavcodec/h264_parse.h
new file mode 100644
index 0000000..7bdce04
--- /dev/null
+++ b/libavcodec/h264_parse.h
@@ -0,0 +1,48 @@
+/*
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * H.264 decoder/parser shared code
+ */
+
+#ifndef AVCODEC_H264_PARSE_H
+#define AVCODEC_H264_PARSE_H
+
+#include "get_bits.h"
+
+typedef struct H264PredWeightTable {
+    int use_weight;
+    int use_weight_chroma;
+    int luma_log2_weight_denom;
+    int chroma_log2_weight_denom;
+    int luma_weight_flag[2];    ///< 7.4.3.2 luma_weight_lX_flag
+    int chroma_weight_flag[2];  ///< 7.4.3.2 chroma_weight_lX_flag
+    // The following 2 can be changed to int8_t but that causes 10cpu cycles speedloss
+    int luma_weight[48][2][2];
+    int chroma_weight[48][2][2][2];
+    int implicit_weight[48][48][2];
+} H264PredWeightTable;
+
+struct SPS;
+
+int ff_h264_pred_weight_table(GetBitContext *gb, const struct SPS *sps,
+                              const int *ref_count, int slice_type_nos,
+                              H264PredWeightTable *pwt);
+
+#endif /* AVCODEC_H264_PARSE_H */
diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c
index 0f970ae..b5ccce3 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -150,7 +150,8 @@ static int scan_mmco_reset(AVCodecParserContext *s)
 
     if ((h->pps.weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||
         (h->pps.weighted_bipred_idc == 1 && sl->slice_type_nos == AV_PICTURE_TYPE_B))
-        ff_pred_weight_table(h, sl);
+        ff_h264_pred_weight_table(&sl->gb, &h->sps, sl->ref_count, sl->slice_type_nos,
+                                  &sl->pwt);
 
     if (get_bits1(&sl->gb)) { // adaptive_ref_pic_marking_mode_flag
         int i;
diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c
index 089efcc..2102f88 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -342,11 +342,11 @@ void ff_h264_fill_mbaff_ref_list(H264Context *h, H264SliceContext *sl)
             field[1].reference = PICT_BOTTOM_FIELD;
             field[1].poc       = field[1].parent->field_poc[1];
 
-            sl->luma_weight[16 + 2 * i][list][0] = sl->luma_weight[16 + 2 * i + 1][list][0] = sl->luma_weight[i][list][0];
-            sl->luma_weight[16 + 2 * i][list][1] = sl->luma_weight[16 + 2 * i + 1][list][1] = sl->luma_weight[i][list][1];
+            sl->pwt.luma_weight[16 + 2 * i][list][0] = sl->pwt.luma_weight[16 + 2 * i + 1][list][0] = sl->pwt.luma_weight[i][list][0];
+            sl->pwt.luma_weight[16 + 2 * i][list][1] = sl->pwt.luma_weight[16 + 2 * i + 1][list][1] = sl->pwt.luma_weight[i][list][1];
             for (j = 0; j < 2; j++) {
-                sl->chroma_weight[16 + 2 * i][list][j][0] = sl->chroma_weight[16 + 2 * i + 1][list][j][0] = sl->chroma_weight[i][list][j][0];
-                sl->chroma_weight[16 + 2 * i][list][j][1] = sl->chroma_weight[16 + 2 * i + 1][list][j][1] = sl->chroma_weight[i][list][j][1];
+                sl->pwt.chroma_weight[16 + 2 * i][list][j][0] = sl->pwt.chroma_weight[16 + 2 * i + 1][list][j][0] = sl->pwt.chroma_weight[i][list][j][0];
+                sl->pwt.chroma_weight[16 + 2 * i][list][j][1] = sl->pwt.chroma_weight[16 + 2 * i + 1][list][j][1] = sl->pwt.chroma_weight[i][list][j][1];
             }
         }
     }
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 408cc48..49d7e6c 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -726,8 +726,8 @@ static void implicit_weight_table(const H264Context *h, H264SliceContext *sl, in
     int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;
 
     for (i = 0; i < 2; i++) {
-        sl->luma_weight_flag[i]   = 0;
-        sl->chroma_weight_flag[i] = 0;
+        sl->pwt.luma_weight_flag[i]   = 0;
+        sl->pwt.chroma_weight_flag[i] = 0;
     }
 
     if (field < 0) {
@@ -738,8 +738,8 @@ static void implicit_weight_table(const H264Context *h, H264SliceContext *sl, in
         }
         if (sl->ref_count[0] == 1 && sl->ref_count[1] == 1 && !FRAME_MBAFF(h) &&
             sl->ref_list[0][0].poc + sl->ref_list[1][0].poc == 2 * cur_poc) {
-            sl->use_weight        = 0;
-            sl->use_weight_chroma = 0;
+            sl->pwt.use_weight        = 0;
+            sl->pwt.use_weight_chroma = 0;
             return;
         }
         ref_start  = 0;
@@ -752,10 +752,10 @@ static void implicit_weight_table(const H264Context *h, H264SliceContext *sl, in
         ref_count1 = 16 + 2 * sl->ref_count[1];
     }
 
-    sl->use_weight               = 2;
-    sl->use_weight_chroma        = 2;
-    sl->luma_log2_weight_denom   = 5;
-    sl->chroma_log2_weight_denom = 5;
+    sl->pwt.use_weight               = 2;
+    sl->pwt.use_weight_chroma        = 2;
+    sl->pwt.luma_log2_weight_denom   = 5;
+    sl->pwt.chroma_log2_weight_denom = 5;
 
     for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
         int poc0 = sl->ref_list[0][ref0].poc;
@@ -773,10 +773,10 @@ static void implicit_weight_table(const H264Context *h, H264SliceContext *sl, in
                 }
             }
             if (field < 0) {
-                sl->implicit_weight[ref0][ref1][0] =
-                sl->implicit_weight[ref0][ref1][1] = w;
+                sl->pwt.implicit_weight[ref0][ref1][0] =
+                sl->pwt.implicit_weight[ref0][ref1][1] = w;
             } else {
-                sl->implicit_weight[ref0][ref1][field] = w;
+                sl->pwt.implicit_weight[ref0][ref1][field] = w;
             }
         }
     }
@@ -1505,15 +1505,16 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
     if ((h->pps.weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||
         (h->pps.weighted_bipred_idc == 1 &&
          sl->slice_type_nos == AV_PICTURE_TYPE_B))
-        ff_pred_weight_table(h, sl);
+        ff_h264_pred_weight_table(&sl->gb, &h->sps, sl->ref_count,
+                                  sl->slice_type_nos, &sl->pwt);
     else if (h->pps.weighted_bipred_idc == 2 &&
              sl->slice_type_nos == AV_PICTURE_TYPE_B) {
         implicit_weight_table(h, sl, -1);
     } else {
-        sl->use_weight = 0;
+        sl->pwt.use_weight = 0;
         for (i = 0; i < 2; i++) {
-            sl->luma_weight_flag[i]   = 0;
-            sl->chroma_weight_flag[i] = 0;
+            sl->pwt.luma_weight_flag[i]   = 0;
+            sl->pwt.chroma_weight_flag[i] = 0;
         }
     }
 
@@ -1687,8 +1688,8 @@ int ff_h264_decode_slice_header(H264Context *h, H264SliceContext *sl)
                sl->qscale,
                sl->deblocking_filter,
                sl->slice_alpha_c0_offset, sl->slice_beta_offset,
-               sl->use_weight,
-               sl->use_weight == 1 && sl->use_weight_chroma ? "c" : "",
+               sl->pwt.use_weight,
+               sl->pwt.use_weight == 1 && sl->pwt.use_weight_chroma ? "c" : "",
                sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "");
     }
 
diff --git a/libavcodec/vaapi_h264.c b/libavcodec/vaapi_h264.c
index 7f7de56..431a428 100644
--- a/libavcodec/vaapi_h264.c
+++ b/libavcodec/vaapi_h264.c
@@ -195,25 +195,25 @@ static void fill_vaapi_plain_pred_weight_table(H264Context   *h,
     H264SliceContext *sl = &h->slice_ctx[0];
     unsigned int i, j;
 
-    *luma_weight_flag    = sl->luma_weight_flag[list];
-    *chroma_weight_flag  = sl->chroma_weight_flag[list];
+    *luma_weight_flag    = sl->pwt.luma_weight_flag[list];
+    *chroma_weight_flag  = sl->pwt.chroma_weight_flag[list];
 
     for (i = 0; i < sl->ref_count[list]; i++) {
         /* VA API also wants the inferred (default) values, not
            only what is available in the bitstream (7.4.3.2). */
-        if (sl->luma_weight_flag[list]) {
-            luma_weight[i] = sl->luma_weight[i][list][0];
-            luma_offset[i] = sl->luma_weight[i][list][1];
+        if (sl->pwt.luma_weight_flag[list]) {
+            luma_weight[i] = sl->pwt.luma_weight[i][list][0];
+            luma_offset[i] = sl->pwt.luma_weight[i][list][1];
         } else {
-            luma_weight[i] = 1 << sl->luma_log2_weight_denom;
+            luma_weight[i] = 1 << sl->pwt.luma_log2_weight_denom;
             luma_offset[i] = 0;
         }
         for (j = 0; j < 2; j++) {
-            if (sl->chroma_weight_flag[list]) {
-                chroma_weight[i][j] = sl->chroma_weight[i][list][j][0];
-                chroma_offset[i][j] = sl->chroma_weight[i][list][j][1];
+            if (sl->pwt.chroma_weight_flag[list]) {
+                chroma_weight[i][j] = sl->pwt.chroma_weight[i][list][j][0];
+                chroma_offset[i][j] = sl->pwt.chroma_weight[i][list][j][1];
             } else {
-                chroma_weight[i][j] = 1 << sl->chroma_log2_weight_denom;
+                chroma_weight[i][j] = 1 << sl->pwt.chroma_log2_weight_denom;
                 chroma_offset[i][j] = 0;
             }
         }
@@ -339,8 +339,8 @@ static int vaapi_h264_decode_slice(AVCodecContext *avctx,
     slice_param->disable_deblocking_filter_idc  = sl->deblocking_filter < 2 ? !sl->deblocking_filter : sl->deblocking_filter;
     slice_param->slice_alpha_c0_offset_div2     = sl->slice_alpha_c0_offset / 2;
     slice_param->slice_beta_offset_div2         = sl->slice_beta_offset     / 2;
-    slice_param->luma_log2_weight_denom         = sl->luma_log2_weight_denom;
-    slice_param->chroma_log2_weight_denom       = sl->chroma_log2_weight_denom;
+    slice_param->luma_log2_weight_denom         = sl->pwt.luma_log2_weight_denom;
+    slice_param->chroma_log2_weight_denom       = sl->pwt.chroma_log2_weight_denom;
 
     fill_vaapi_RefPicList(slice_param->RefPicList0, sl->ref_list[0], sl->list_count > 0 ? sl->ref_count[0] : 0);
     fill_vaapi_RefPicList(slice_param->RefPicList1, sl->ref_list[1], sl->list_count > 1 ? sl->ref_count[1] : 0);



More information about the ffmpeg-cvslog mailing list