[FFmpeg-cvslog] Merge commit 'e481458bc308ee838deaeacac51929514762e7a7'

Derek Buitenhuis git at videolan.org
Tue Apr 26 16:04:55 CEST 2016


ffmpeg | branch: master | Derek Buitenhuis <derek.buitenhuis at gmail.com> | Tue Apr 26 15:04:29 2016 +0100| [ee38234c43b6b3280304be7a43dc569cef683c43] | committer: Derek Buitenhuis

Merge commit 'e481458bc308ee838deaeacac51929514762e7a7'

* commit 'e481458bc308ee838deaeacac51929514762e7a7':
  h264: factor out pred weight table parsing into a separate file

Merged-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>

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

 libavcodec/Makefile           |    4 +-
 libavcodec/dxva2_h264.c       |   20 ++++-----
 libavcodec/h264.c             |   72 -------------------------------
 libavcodec/h264.h             |   14 +-----
 libavcodec/h264_mb.c          |   54 +++++++++++------------
 libavcodec/h264_mc_template.c |    6 +--
 libavcodec/h264_parse.c       |   96 +++++++++++++++++++++++++++++++++++++++++
 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, 224 insertions(+), 160 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 36b65f7..4cda4dc 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -308,7 +308,7 @@ OBJS-$(CONFIG_H263_ENCODER)            += mpeg4videoenc.o mpeg4video.o  \
 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_refs.o h264_sei.o h264_slice.o h264data.o h264_parse.o
 OBJS-$(CONFIG_H264_MEDIACODEC_DECODER) += mediacodecdec_h264.o
 OBJS-$(CONFIG_H264_MMAL_DECODER)       += mmaldec.o
 OBJS-$(CONFIG_H264_VDA_DECODER)        += vda_h264_dec.o
@@ -900,7 +900,7 @@ OBJS-$(CONFIG_G729_PARSER)             += g729_parser.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 b1abb9a..7048c4a 100644
--- a/libavcodec/dxva2_h264.c
+++ b/libavcodec/dxva2_h264.c
@@ -232,8 +232,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)
@@ -257,15 +257,15 @@ static void fill_slice_long(AVCodecContext *avctx, DXVA_Slice_H264_Long *slice,
                                    sl->ref_list[list][i].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 88768af..22375aa 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -999,78 +999,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);
-
-    if (sl->luma_log2_weight_denom > 7U) {
-        av_log(h->avctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is out of range\n", sl->luma_log2_weight_denom);
-        sl->luma_log2_weight_denom = 0;
-    }
-    if (sl->chroma_log2_weight_denom > 7U) {
-        av_log(h->avctx, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out of range\n", sl->chroma_log2_weight_denom);
-        sl->chroma_log2_weight_denom = 0;
-    }
-
-    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 6d6629b..e655995 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"
@@ -384,17 +385,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;
@@ -1213,7 +1204,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 8302de0..8791e2e 100644
--- a/libavcodec/h264_mb.c
+++ b/libavcodec/h264_mb.c
@@ -420,8 +420,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);
@@ -433,24 +433,24 @@ static av_always_inline void mc_part_weighted(const H264Context *h, H264SliceCon
             }
         } 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]);
             if (!CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {
                 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 {
@@ -462,19 +462,19 @@ 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]);
+                       sl->pwt.luma_log2_weight_denom,
+                       sl->pwt.luma_weight[refn][list][0],
+                       sl->pwt.luma_weight[refn][list][1]);
         if (!CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {
-            if (sl->use_weight_chroma) {
+            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 e4333a7..bf8f0ad 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..ebd87b0
--- /dev/null
+++ b/libavcodec/h264_parse.c
@@ -0,0 +1,96 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; 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);
+
+    if (pwt->luma_log2_weight_denom > 7U) {
+        av_log(NULL, AV_LOG_ERROR, "luma_log2_weight_denom %d is out of range\n", pwt->luma_log2_weight_denom);
+        pwt->luma_log2_weight_denom = 0;
+    }
+    if (pwt->chroma_log2_weight_denom > 7U) {
+        av_log(NULL, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out of range\n", pwt->chroma_log2_weight_denom);
+        pwt->chroma_log2_weight_denom = 0;
+    }
+
+    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..d1a7af0
--- /dev/null
+++ b/libavcodec/h264_parse.h
@@ -0,0 +1,48 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; 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 9a06d61..c86f032 100644
--- a/libavcodec/h264_parser.c
+++ b/libavcodec/h264_parser.c
@@ -183,7 +183,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 35e254e..1b1526a 100644
--- a/libavcodec/h264_refs.c
+++ b/libavcodec/h264_refs.c
@@ -391,11 +391,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 f0f0a50..880b696 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -770,8 +770,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) {
@@ -782,8 +782,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 + (int64_t)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;
@@ -796,10 +796,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++) {
         int64_t poc0 = sl->ref_list[0][ref0].poc;
@@ -817,10 +817,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;
             }
         }
     }
@@ -1744,15 +1744,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;
         }
     }
 
@@ -1941,8 +1942,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 ded2cb3..b024738 100644
--- a/libavcodec/vaapi_h264.c
+++ b/libavcodec/vaapi_h264.c
@@ -196,25 +196,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;
             }
         }
@@ -341,8 +341,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);


======================================================================

diff --cc libavcodec/Makefile
index 36b65f7,54b12d3..4cda4dc
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@@ -308,10 -251,10 +308,10 @@@ OBJS-$(CONFIG_H263_ENCODER)            
  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_refs.o h264_sei.o \
 -                                          h264_slice.o h264data.o h264_parse.o
++                                          h264_refs.o h264_sei.o h264_slice.o h264data.o h264_parse.o
 +OBJS-$(CONFIG_H264_MEDIACODEC_DECODER) += mediacodecdec_h264.o
  OBJS-$(CONFIG_H264_MMAL_DECODER)       += mmaldec.o
 -OBJS-$(CONFIG_H264_NVENC_ENCODER)      += nvenc_h264.o
 +OBJS-$(CONFIG_H264_VDA_DECODER)        += vda_h264_dec.o
  OBJS-$(CONFIG_H264_QSV_DECODER)        += qsvdec_h2645.o
  OBJS-$(CONFIG_H264_QSV_ENCODER)        += qsvenc_h264.o
  OBJS-$(CONFIG_HAP_DECODER)             += hapdec.o hap.o
diff --cc libavcodec/dxva2_h264.c
index b1abb9a,2d6fa79..7048c4a
--- a/libavcodec/dxva2_h264.c
+++ b/libavcodec/dxva2_h264.c
@@@ -254,18 -252,18 +254,18 @@@ static void fill_slice_long(AVCodecCont
                  else
                      index = get_refpic_index(pp, ff_dxva2_get_surface_index(avctx, ctx, r->f));
                  fill_picture_entry(&slice->RefPicList[list][i], index,
 -                                   r->reference == PICT_BOTTOM_FIELD);
 +                                   sl->ref_list[list][i].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 --cc libavcodec/h264_mb.c
index 8302de0,f94333b..8791e2e
--- a/libavcodec/h264_mb.c
+++ b/libavcodec/h264_mb.c
@@@ -425,33 -424,29 +425,33 @@@ static av_always_inline void mc_part_we
              int weight1 = 64 - weight0;
              luma_weight_avg(dest_y, tmp_y, sl->mb_linesize,
                              height, 5, weight0, weight1, 0);
 -            chroma_weight_avg(dest_cb, tmp_cb, sl->mb_uvlinesize,
 -                              chroma_height, 5, weight0, weight1, 0);
 -            chroma_weight_avg(dest_cr, tmp_cr, sl->mb_uvlinesize,
 -                              chroma_height, 5, weight0, weight1, 0);
 +            if (!CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {
 +                chroma_weight_avg(dest_cb, tmp_cb, sl->mb_uvlinesize,
 +                                  chroma_height, 5, weight0, weight1, 0);
 +                chroma_weight_avg(dest_cr, tmp_cr, sl->mb_uvlinesize,
 +                                  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->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->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]);
 +            if (!CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {
 +                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;
@@@ -462,20 -457,18 +462,20 @@@
                      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]);
+                        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->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->pwt.chroma_log2_weight_denom,
 -                             sl->pwt.chroma_weight[refn][list][1][0],
 -                             sl->pwt.chroma_weight[refn][list][1][1]);
 +        if (!CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {
-             if (sl->use_weight_chroma) {
++            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 --cc libavcodec/h264_parse.c
index 0000000,88caa48..ebd87b0
mode 000000,100644..100644
--- a/libavcodec/h264_parse.c
+++ b/libavcodec/h264_parse.c
@@@ -1,0 -1,86 +1,96 @@@
+ /*
 - * This file is part of Libav.
++ * This file is part of FFmpeg.
+  *
 - * Libav is free software; you can redistribute it and/or
++ * FFmpeg 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,
++ * FFmpeg 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
++ * License along with FFmpeg; 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);
++
++    if (pwt->luma_log2_weight_denom > 7U) {
++        av_log(NULL, AV_LOG_ERROR, "luma_log2_weight_denom %d is out of range\n", pwt->luma_log2_weight_denom);
++        pwt->luma_log2_weight_denom = 0;
++    }
++    if (pwt->chroma_log2_weight_denom > 7U) {
++        av_log(NULL, AV_LOG_ERROR, "chroma_log2_weight_denom %d is out of range\n", pwt->chroma_log2_weight_denom);
++        pwt->chroma_log2_weight_denom = 0;
++    }
++
+     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 --cc libavcodec/h264_parse.h
index 0000000,7bdce04..d1a7af0
mode 000000,100644..100644
--- a/libavcodec/h264_parse.h
+++ b/libavcodec/h264_parse.h
@@@ -1,0 -1,48 +1,48 @@@
+ /*
 - * This file is part of Libav.
++ * This file is part of FFmpeg.
+  *
 - * Libav is free software; you can redistribute it and/or
++ * FFmpeg 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,
++ * FFmpeg 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
++ * License along with FFmpeg; 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 --cc libavcodec/h264_slice.c
index f0f0a50,49d7e6c..880b696
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@@ -781,9 -737,9 +781,9 @@@ static void implicit_weight_table(cons
              cur_poc = h->cur_pic_ptr->field_poc[h->picture_structure - 1];
          }
          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->ref_list[0][0].poc + (int64_t)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;
@@@ -796,13 -752,13 +796,13 @@@
          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;
 +        int64_t poc0 = sl->ref_list[0][ref0].poc;
          for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
              int w = 32;
              if (!sl->ref_list[0][ref0].parent->long_ref && !sl->ref_list[1][ref1].parent->long_ref) {




More information about the ffmpeg-cvslog mailing list