LCOV - code coverage report
Current view: top level - libavcodec - h264_mvpred.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 413 417 99.0 %
Date: 2017-12-12 11:08:38 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /*
       2             :  * H.26L/H.264/AVC/JVT/14496-10/... motion vector prediction
       3             :  * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
       4             :  *
       5             :  * This file is part of FFmpeg.
       6             :  *
       7             :  * FFmpeg is free software; you can redistribute it and/or
       8             :  * modify it under the terms of the GNU Lesser General Public
       9             :  * License as published by the Free Software Foundation; either
      10             :  * version 2.1 of the License, or (at your option) any later version.
      11             :  *
      12             :  * FFmpeg is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :  * Lesser General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU Lesser General Public
      18             :  * License along with FFmpeg; if not, write to the Free Software
      19             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      20             :  */
      21             : 
      22             : /**
      23             :  * @file
      24             :  * H.264 / AVC / MPEG-4 part10 motion vector prediction.
      25             :  * @author Michael Niedermayer <michaelni@gmx.at>
      26             :  */
      27             : 
      28             : #ifndef AVCODEC_H264_MVPRED_H
      29             : #define AVCODEC_H264_MVPRED_H
      30             : 
      31             : #include "internal.h"
      32             : #include "avcodec.h"
      33             : #include "h264dec.h"
      34             : #include "mpegutils.h"
      35             : #include "libavutil/avassert.h"
      36             : 
      37             : 
      38    17343032 : static av_always_inline int fetch_diagonal_mv(const H264Context *h, H264SliceContext *sl,
      39             :                                               const int16_t **C,
      40             :                                               int i, int list, int part_width)
      41             : {
      42    17343032 :     const int topright_ref = sl->ref_cache[list][i - 8 + part_width];
      43             : 
      44             :     /* there is no consistent mapping of mvs to neighboring locations that will
      45             :      * make mbaff happy, so we can't move all this logic to fill_caches */
      46    17343032 :     if (FRAME_MBAFF(h)) {
      47             : #define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4)                              \
      48             :         const int xy = XY, y4 = Y4;                                     \
      49             :         const int mb_type = mb_types[xy + (y4 >> 2) * h->mb_stride];    \
      50             :         if (!USES_LIST(mb_type, list))                                  \
      51             :             return LIST_NOT_USED;                                       \
      52             :         mv = h->cur_pic_ptr->motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \
      53             :         sl->mv_cache[list][scan8[0] - 2][0] = mv[0];                     \
      54             :         sl->mv_cache[list][scan8[0] - 2][1] = mv[1] MV_OP;               \
      55             :         return h->cur_pic_ptr->ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP;
      56             : 
      57     2607483 :         if (topright_ref == PART_NOT_AVAILABLE
      58     1080915 :             && i >= scan8[0] + 8 && (i & 7) == 4
      59      190008 :             && sl->ref_cache[list][scan8[0] - 1] != PART_NOT_AVAILABLE) {
      60      182797 :             const uint32_t *mb_types = h->cur_pic_ptr->mb_type;
      61             :             const int16_t *mv;
      62      182797 :             AV_ZERO32(sl->mv_cache[list][scan8[0] - 2]);
      63      182797 :             *C = sl->mv_cache[list][scan8[0] - 2];
      64             : 
      65      182797 :             if (!MB_FIELD(sl) && IS_INTERLACED(sl->left_type[0])) {
      66       26640 :                 SET_DIAG_MV(* 2, >> 1, sl->left_mb_xy[0] + h->mb_stride,
      67             :                             (sl->mb_y & 1) * 2 + (i >> 5));
      68             :             }
      69      156157 :             if (MB_FIELD(sl) && !IS_INTERLACED(sl->left_type[0])) {
      70             :                 // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK.
      71       35582 :                 SET_DIAG_MV(/ 2, *2, sl->left_mb_xy[i >= 36], ((i >> 2)) & 3);
      72             :             }
      73             :         }
      74             : #undef SET_DIAG_MV
      75             :     }
      76             : 
      77    17280810 :     if (topright_ref != PART_NOT_AVAILABLE) {
      78    10939466 :         *C = sl->mv_cache[list][i - 8 + part_width];
      79    10939466 :         return topright_ref;
      80             :     } else {
      81             :         ff_tlog(h->avctx, "topright MV not available\n");
      82             : 
      83     6341344 :         *C = sl->mv_cache[list][i - 8 - 1];
      84     6341344 :         return sl->ref_cache[list][i - 8 - 1];
      85             :     }
      86             : }
      87             : 
      88             : /**
      89             :  * Get the predicted MV.
      90             :  * @param n the block index
      91             :  * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4)
      92             :  * @param mx the x component of the predicted motion vector
      93             :  * @param my the y component of the predicted motion vector
      94             :  */
      95    16788702 : static av_always_inline void pred_motion(const H264Context *const h,
      96             :                                          H264SliceContext *sl,
      97             :                                          int n,
      98             :                                          int part_width, int list, int ref,
      99             :                                          int *const mx, int *const my)
     100             : {
     101    16788702 :     const int index8       = scan8[n];
     102    16788702 :     const int top_ref      = sl->ref_cache[list][index8 - 8];
     103    16788702 :     const int left_ref     = sl->ref_cache[list][index8 - 1];
     104    16788702 :     const int16_t *const A = sl->mv_cache[list][index8 - 1];
     105    16788702 :     const int16_t *const B = sl->mv_cache[list][index8 - 8];
     106             :     const int16_t *C;
     107             :     int diagonal_ref, match_count;
     108             : 
     109             :     av_assert2(part_width == 1 || part_width == 2 || part_width == 4);
     110             : 
     111             : /* mv_cache
     112             :  * B . . A T T T T
     113             :  * U . . L . . , .
     114             :  * U . . L . . . .
     115             :  * U . . L . . , .
     116             :  * . . . L . . . .
     117             :  */
     118             : 
     119    16788702 :     diagonal_ref = fetch_diagonal_mv(h, sl, &C, index8, list, part_width);
     120    16788702 :     match_count  = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
     121             :     ff_tlog(h->avctx, "pred_motion match_count=%d\n", match_count);
     122    16788702 :     if (match_count > 1) { //most common
     123    12438793 :         *mx = mid_pred(A[0], B[0], C[0]);
     124    12438793 :         *my = mid_pred(A[1], B[1], C[1]);
     125     4349909 :     } else if (match_count == 1) {
     126     2961825 :         if (left_ref == ref) {
     127     1861581 :             *mx = A[0];
     128     1861581 :             *my = A[1];
     129     1100244 :         } else if (top_ref == ref) {
     130      790631 :             *mx = B[0];
     131      790631 :             *my = B[1];
     132             :         } else {
     133      309613 :             *mx = C[0];
     134      309613 :             *my = C[1];
     135             :         }
     136             :     } else {
     137     1388084 :         if (top_ref      == PART_NOT_AVAILABLE &&
     138      215136 :             diagonal_ref == PART_NOT_AVAILABLE &&
     139             :             left_ref     != PART_NOT_AVAILABLE) {
     140      192229 :             *mx = A[0];
     141      192229 :             *my = A[1];
     142             :         } else {
     143     1195855 :             *mx = mid_pred(A[0], B[0], C[0]);
     144     1195855 :             *my = mid_pred(A[1], B[1], C[1]);
     145             :         }
     146             :     }
     147             : 
     148             :     ff_tlog(h->avctx,
     149             :             "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n",
     150             :             top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref,
     151             :             A[0], A[1], ref, *mx, *my, sl->mb_x, sl->mb_y, n, list);
     152    16788702 : }
     153             : 
     154             : /**
     155             :  * Get the directionally predicted 16x8 MV.
     156             :  * @param n the block index
     157             :  * @param mx the x component of the predicted motion vector
     158             :  * @param my the y component of the predicted motion vector
     159             :  */
     160     1290659 : static av_always_inline void pred_16x8_motion(const H264Context *const h,
     161             :                                               H264SliceContext *sl,
     162             :                                               int n, int list, int ref,
     163             :                                               int *const mx, int *const my)
     164             : {
     165     1290659 :     if (n == 0) {
     166      644537 :         const int top_ref      = sl->ref_cache[list][scan8[0] - 8];
     167      644537 :         const int16_t *const B = sl->mv_cache[list][scan8[0] - 8];
     168             : 
     169             :         ff_tlog(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
     170             :                 top_ref, B[0], B[1], sl->mb_x, sl->mb_y, n, list);
     171             : 
     172      644537 :         if (top_ref == ref) {
     173      363121 :             *mx = B[0];
     174      363121 :             *my = B[1];
     175      363121 :             return;
     176             :         }
     177             :     } else {
     178      646122 :         const int left_ref     = sl->ref_cache[list][scan8[8] - 1];
     179      646122 :         const int16_t *const A = sl->mv_cache[list][scan8[8] - 1];
     180             : 
     181             :         ff_tlog(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
     182             :                 left_ref, A[0], A[1], sl->mb_x, sl->mb_y, n, list);
     183             : 
     184      646122 :         if (left_ref == ref) {
     185      431790 :             *mx = A[0];
     186      431790 :             *my = A[1];
     187      431790 :             return;
     188             :         }
     189             :     }
     190             : 
     191             :     //RARE
     192      495748 :     pred_motion(h, sl, n, 4, list, ref, mx, my);
     193             : }
     194             : 
     195             : /**
     196             :  * Get the directionally predicted 8x16 MV.
     197             :  * @param n the block index
     198             :  * @param mx the x component of the predicted motion vector
     199             :  * @param my the y component of the predicted motion vector
     200             :  */
     201     1109955 : static av_always_inline void pred_8x16_motion(const H264Context *const h,
     202             :                                               H264SliceContext *sl,
     203             :                                               int n, int list, int ref,
     204             :                                               int *const mx, int *const my)
     205             : {
     206     1109955 :     if (n == 0) {
     207      555625 :         const int left_ref     = sl->ref_cache[list][scan8[0] - 1];
     208      555625 :         const int16_t *const A = sl->mv_cache[list][scan8[0] - 1];
     209             : 
     210             :         ff_tlog(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
     211             :                 left_ref, A[0], A[1], sl->mb_x, sl->mb_y, n, list);
     212             : 
     213      555625 :         if (left_ref == ref) {
     214      342172 :             *mx = A[0];
     215      342172 :             *my = A[1];
     216      342172 :             return;
     217             :         }
     218             :     } else {
     219             :         const int16_t *C;
     220             :         int diagonal_ref;
     221             : 
     222      554330 :         diagonal_ref = fetch_diagonal_mv(h, sl, &C, scan8[4], list, 2);
     223             : 
     224             :         ff_tlog(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
     225             :                 diagonal_ref, C[0], C[1], sl->mb_x, sl->mb_y, n, list);
     226             : 
     227      554330 :         if (diagonal_ref == ref) {
     228      315564 :             *mx = C[0];
     229      315564 :             *my = C[1];
     230      315564 :             return;
     231             :         }
     232             :     }
     233             : 
     234             :     //RARE
     235      452219 :     pred_motion(h, sl, n, 2, list, ref, mx, my);
     236             : }
     237             : 
     238             : #define FIX_MV_MBAFF(type, refn, mvn, idx)      \
     239             :     if (FRAME_MBAFF(h)) {                       \
     240             :         if (MB_FIELD(sl)) {                     \
     241             :             if (!IS_INTERLACED(type)) {         \
     242             :                 refn <<= 1;                     \
     243             :                 AV_COPY32(mvbuf[idx], mvn);     \
     244             :                 mvbuf[idx][1] /= 2;             \
     245             :                 mvn = mvbuf[idx];               \
     246             :             }                                   \
     247             :         } else {                                \
     248             :             if (IS_INTERLACED(type)) {          \
     249             :                 refn >>= 1;                     \
     250             :                 AV_COPY32(mvbuf[idx], mvn);     \
     251             :                 mvbuf[idx][1] *= 2;             \
     252             :                 mvn = mvbuf[idx];               \
     253             :             }                                   \
     254             :         }                                       \
     255             :     }
     256             : 
     257     1252391 : static av_always_inline void pred_pskip_motion(const H264Context *const h,
     258             :                                                H264SliceContext *sl)
     259             : {
     260             :     DECLARE_ALIGNED(4, static const int16_t, zeromv)[2] = { 0 };
     261             :     DECLARE_ALIGNED(4, int16_t, mvbuf)[3][2];
     262     1252391 :     int8_t *ref     = h->cur_pic.ref_index[0];
     263     1252391 :     int16_t(*mv)[2] = h->cur_pic.motion_val[0];
     264             :     int top_ref, left_ref, diagonal_ref, match_count, mx, my;
     265             :     const int16_t *A, *B, *C;
     266     1252391 :     int b_stride = h->b_stride;
     267             : 
     268     1252391 :     fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1);
     269             : 
     270             :     /* To avoid doing an entire fill_decode_caches, we inline the relevant
     271             :      * parts here.
     272             :      * FIXME: this is a partial duplicate of the logic in fill_decode_caches,
     273             :      * but it's faster this way.  Is there a way to avoid this duplication?
     274             :      */
     275     1252391 :     if (USES_LIST(sl->left_type[LTOP], 0)) {
     276     1181850 :         left_ref = ref[4 * sl->left_mb_xy[LTOP] + 1 + (sl->left_block[0] & ~1)];
     277     1181850 :         A = mv[h->mb2b_xy[sl->left_mb_xy[LTOP]] + 3 + b_stride * sl->left_block[0]];
     278     1181850 :         FIX_MV_MBAFF(sl->left_type[LTOP], left_ref, A, 0);
     279     1181850 :         if (!(left_ref | AV_RN32A(A)))
     280      928782 :             goto zeromv;
     281       70541 :     } else if (sl->left_type[LTOP]) {
     282       27576 :         left_ref = LIST_NOT_USED;
     283       27576 :         A        = zeromv;
     284             :     } else {
     285       42965 :         goto zeromv;
     286             :     }
     287             : 
     288      280644 :     if (USES_LIST(sl->top_type, 0)) {
     289      253935 :         top_ref = ref[4 * sl->top_mb_xy + 2];
     290      253935 :         B       = mv[h->mb2b_xy[sl->top_mb_xy] + 3 * b_stride];
     291      253935 :         FIX_MV_MBAFF(sl->top_type, top_ref, B, 1);
     292      253935 :         if (!(top_ref | AV_RN32A(B)))
     293       41140 :             goto zeromv;
     294       26709 :     } else if (sl->top_type) {
     295       17308 :         top_ref = LIST_NOT_USED;
     296       17308 :         B       = zeromv;
     297             :     } else {
     298        9401 :         goto zeromv;
     299             :     }
     300             : 
     301             :     ff_tlog(h->avctx, "pred_pskip: (%d) (%d) at %2d %2d\n",
     302             :             top_ref, left_ref, sl->mb_x, sl->mb_y);
     303             : 
     304      230103 :     if (USES_LIST(sl->topright_type, 0)) {
     305      198836 :         diagonal_ref = ref[4 * sl->topright_mb_xy + 2];
     306      198836 :         C = mv[h->mb2b_xy[sl->topright_mb_xy] + 3 * b_stride];
     307      198836 :         FIX_MV_MBAFF(sl->topright_type, diagonal_ref, C, 2);
     308       31267 :     } else if (sl->topright_type) {
     309       17144 :         diagonal_ref = LIST_NOT_USED;
     310       17144 :         C = zeromv;
     311             :     } else {
     312       14123 :         if (USES_LIST(sl->topleft_type, 0)) {
     313       26656 :             diagonal_ref = ref[4 * sl->topleft_mb_xy + 1 +
     314       13328 :                                (sl->topleft_partition & 2)];
     315       26656 :             C = mv[h->mb2b_xy[sl->topleft_mb_xy] + 3 + b_stride +
     316       13328 :                    (sl->topleft_partition & 2 * b_stride)];
     317       13328 :             FIX_MV_MBAFF(sl->topleft_type, diagonal_ref, C, 2);
     318         795 :         } else if (sl->topleft_type) {
     319         795 :             diagonal_ref = LIST_NOT_USED;
     320         795 :             C            = zeromv;
     321             :         } else {
     322           0 :             diagonal_ref = PART_NOT_AVAILABLE;
     323           0 :             C            = zeromv;
     324             :         }
     325             :     }
     326             : 
     327      230103 :     match_count = !diagonal_ref + !top_ref + !left_ref;
     328             :     ff_tlog(h->avctx, "pred_pskip_motion match_count=%d\n", match_count);
     329      230103 :     if (match_count > 1) {
     330      189515 :         mx = mid_pred(A[0], B[0], C[0]);
     331      189515 :         my = mid_pred(A[1], B[1], C[1]);
     332       40588 :     } else if (match_count == 1) {
     333       34709 :         if (!left_ref) {
     334       17042 :             mx = A[0];
     335       17042 :             my = A[1];
     336       17667 :         } else if (!top_ref) {
     337        7667 :             mx = B[0];
     338        7667 :             my = B[1];
     339             :         } else {
     340       10000 :             mx = C[0];
     341       10000 :             my = C[1];
     342             :         }
     343             :     } else {
     344        5879 :         mx = mid_pred(A[0], B[0], C[0]);
     345        5879 :         my = mid_pred(A[1], B[1], C[1]);
     346             :     }
     347             : 
     348      230103 :     fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx, my), 4);
     349      230103 :     return;
     350             : 
     351     1022288 : zeromv:
     352     1022288 :     fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
     353     1022288 :     return;
     354             : }
     355             : 
     356    12276922 : static void fill_decode_neighbors(const H264Context *h, H264SliceContext *sl, int mb_type)
     357             : {
     358    12276922 :     const int mb_xy = sl->mb_xy;
     359             :     int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
     360             :     static const uint8_t left_block_options[4][32] = {
     361             :         { 0, 1, 2, 3, 7, 10, 8, 11, 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 5 * 4, 1 + 9 * 4 },
     362             :         { 2, 2, 3, 3, 8, 11, 8, 11, 3 + 2 * 4, 3 + 2 * 4, 3 + 3 * 4, 3 + 3 * 4, 1 + 5 * 4, 1 + 9 * 4, 1 + 5 * 4, 1 + 9 * 4 },
     363             :         { 0, 0, 1, 1, 7, 10, 7, 10, 3 + 0 * 4, 3 + 0 * 4, 3 + 1 * 4, 3 + 1 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 },
     364             :         { 0, 2, 0, 2, 7, 10, 7, 10, 3 + 0 * 4, 3 + 2 * 4, 3 + 0 * 4, 3 + 2 * 4, 1 + 4 * 4, 1 + 8 * 4, 1 + 4 * 4, 1 + 8 * 4 }
     365             :     };
     366             : 
     367    12276922 :     sl->topleft_partition = -1;
     368             : 
     369    12276922 :     top_xy = mb_xy - (h->mb_stride << MB_FIELD(sl));
     370             : 
     371             :     /* Wow, what a mess, why didn't they simplify the interlacing & intra
     372             :      * stuff, I can't imagine that these complex rules are worth it. */
     373             : 
     374    12276922 :     topleft_xy    = top_xy - 1;
     375    12276922 :     topright_xy   = top_xy + 1;
     376    12276922 :     left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1;
     377    12276922 :     sl->left_block = left_block_options[0];
     378    12276922 :     if (FRAME_MBAFF(h)) {
     379     1857412 :         const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]);
     380     1857412 :         const int curr_mb_field_flag = IS_INTERLACED(mb_type);
     381     1857412 :         if (sl->mb_y & 1) {
     382      928594 :             if (left_mb_field_flag != curr_mb_field_flag) {
     383      247902 :                 left_xy[LBOT] = left_xy[LTOP] = mb_xy - h->mb_stride - 1;
     384      247902 :                 if (curr_mb_field_flag) {
     385      127965 :                     left_xy[LBOT] += h->mb_stride;
     386      127965 :                     sl->left_block  = left_block_options[3];
     387             :                 } else {
     388      119937 :                     topleft_xy += h->mb_stride;
     389             :                     /* take top left mv from the middle of the mb, as opposed
     390             :                      * to all other modes which use the bottom right partition */
     391      119937 :                     sl->topleft_partition = 0;
     392      119937 :                     sl->left_block        = left_block_options[1];
     393             :                 }
     394             :             }
     395             :         } else {
     396      928818 :             if (curr_mb_field_flag) {
     397      305129 :                 topleft_xy  += h->mb_stride & (((h->cur_pic.mb_type[top_xy - 1] >> 7) & 1) - 1);
     398      305129 :                 topright_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy + 1] >> 7) & 1) - 1);
     399      305129 :                 top_xy      += h->mb_stride & (((h->cur_pic.mb_type[top_xy]     >> 7) & 1) - 1);
     400             :             }
     401      928818 :             if (left_mb_field_flag != curr_mb_field_flag) {
     402      248076 :                 if (curr_mb_field_flag) {
     403      127938 :                     left_xy[LBOT] += h->mb_stride;
     404      127938 :                     sl->left_block  = left_block_options[3];
     405             :                 } else {
     406      120138 :                     sl->left_block = left_block_options[2];
     407             :                 }
     408             :             }
     409             :         }
     410             :     }
     411             : 
     412    12276922 :     sl->topleft_mb_xy    = topleft_xy;
     413    12276922 :     sl->top_mb_xy        = top_xy;
     414    12276922 :     sl->topright_mb_xy   = topright_xy;
     415    12276922 :     sl->left_mb_xy[LTOP] = left_xy[LTOP];
     416    12276922 :     sl->left_mb_xy[LBOT] = left_xy[LBOT];
     417             :     //FIXME do we need all in the context?
     418             : 
     419    12276922 :     sl->topleft_type    = h->cur_pic.mb_type[topleft_xy];
     420    12276922 :     sl->top_type        = h->cur_pic.mb_type[top_xy];
     421    12276922 :     sl->topright_type   = h->cur_pic.mb_type[topright_xy];
     422    12276922 :     sl->left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]];
     423    12276922 :     sl->left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]];
     424             : 
     425             :     if (FMO) {
     426             :         if (h->slice_table[topleft_xy] != sl->slice_num)
     427             :             sl->topleft_type = 0;
     428             :         if (h->slice_table[top_xy] != sl->slice_num)
     429             :             sl->top_type = 0;
     430             :         if (h->slice_table[left_xy[LTOP]] != sl->slice_num)
     431             :             sl->left_type[LTOP] = sl->left_type[LBOT] = 0;
     432             :     } else {
     433    12276922 :         if (h->slice_table[topleft_xy] != sl->slice_num) {
     434     1247666 :             sl->topleft_type = 0;
     435     1247666 :             if (h->slice_table[top_xy] != sl->slice_num)
     436      920500 :                 sl->top_type = 0;
     437     1247666 :             if (h->slice_table[left_xy[LTOP]] != sl->slice_num)
     438      358307 :                 sl->left_type[LTOP] = sl->left_type[LBOT] = 0;
     439             :         }
     440             :     }
     441    12276922 :     if (h->slice_table[topright_xy] != sl->slice_num)
     442     1855733 :         sl->topright_type = 0;
     443    12276922 : }
     444             : 
     445    11018872 : static void fill_decode_caches(const H264Context *h, H264SliceContext *sl, int mb_type)
     446             : {
     447             :     int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
     448             :     int topleft_type, top_type, topright_type, left_type[LEFT_MBS];
     449    11018872 :     const uint8_t *left_block = sl->left_block;
     450             :     int i;
     451             :     uint8_t *nnz;
     452             :     uint8_t *nnz_cache;
     453             : 
     454    11018872 :     topleft_xy      = sl->topleft_mb_xy;
     455    11018872 :     top_xy          = sl->top_mb_xy;
     456    11018872 :     topright_xy     = sl->topright_mb_xy;
     457    11018872 :     left_xy[LTOP]   = sl->left_mb_xy[LTOP];
     458    11018872 :     left_xy[LBOT]   = sl->left_mb_xy[LBOT];
     459    11018872 :     topleft_type    = sl->topleft_type;
     460    11018872 :     top_type        = sl->top_type;
     461    11018872 :     topright_type   = sl->topright_type;
     462    11018872 :     left_type[LTOP] = sl->left_type[LTOP];
     463    11018872 :     left_type[LBOT] = sl->left_type[LBOT];
     464             : 
     465    11018872 :     if (!IS_SKIP(mb_type)) {
     466     9603535 :         if (IS_INTRA(mb_type)) {
     467     3688913 :             int type_mask = h->ps.pps->constrained_intra_pred ? IS_INTRA(-1) : -1;
     468     3688913 :             sl->topleft_samples_available     =
     469     3688913 :                 sl->top_samples_available     =
     470     3688913 :                     sl->left_samples_available = 0xFFFF;
     471     3688913 :             sl->topright_samples_available     = 0xEEEA;
     472             : 
     473     3688913 :             if (!(top_type & type_mask)) {
     474      264018 :                 sl->topleft_samples_available  = 0xB3FF;
     475      264018 :                 sl->top_samples_available      = 0x33FF;
     476      264018 :                 sl->topright_samples_available = 0x26EA;
     477             :             }
     478     3688913 :             if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) {
     479      211987 :                 if (IS_INTERLACED(mb_type)) {
     480      110440 :                     if (!(left_type[LTOP] & type_mask)) {
     481       15628 :                         sl->topleft_samples_available &= 0xDFFF;
     482       15628 :                         sl->left_samples_available    &= 0x5FFF;
     483             :                     }
     484      110440 :                     if (!(left_type[LBOT] & type_mask)) {
     485       15633 :                         sl->topleft_samples_available &= 0xFF5F;
     486       15633 :                         sl->left_samples_available    &= 0xFF5F;
     487             :                     }
     488             :                 } else {
     489      101547 :                     int left_typei = h->cur_pic.mb_type[left_xy[LTOP] + h->mb_stride];
     490             : 
     491             :                     av_assert2(left_xy[LTOP] == left_xy[LBOT]);
     492      101547 :                     if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {
     493          53 :                         sl->topleft_samples_available &= 0xDF5F;
     494          53 :                         sl->left_samples_available    &= 0x5F5F;
     495             :                     }
     496             :                 }
     497             :             } else {
     498     3476926 :                 if (!(left_type[LTOP] & type_mask)) {
     499       62638 :                     sl->topleft_samples_available &= 0xDF5F;
     500       62638 :                     sl->left_samples_available    &= 0x5F5F;
     501             :                 }
     502             :             }
     503             : 
     504     3688913 :             if (!(topleft_type & type_mask))
     505      333803 :                 sl->topleft_samples_available &= 0x7FFF;
     506             : 
     507     3688913 :             if (!(topright_type & type_mask))
     508      686713 :                 sl->topright_samples_available &= 0xFBFF;
     509             : 
     510     3688913 :             if (IS_INTRA4x4(mb_type)) {
     511     2857332 :                 if (IS_INTRA4x4(top_type)) {
     512     2143458 :                     AV_COPY32(sl->intra4x4_pred_mode_cache + 4 + 8 * 0, sl->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
     513             :                 } else {
     514      713874 :                     sl->intra4x4_pred_mode_cache[4 + 8 * 0] =
     515      713874 :                     sl->intra4x4_pred_mode_cache[5 + 8 * 0] =
     516      713874 :                     sl->intra4x4_pred_mode_cache[6 + 8 * 0] =
     517      713874 :                     sl->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask);
     518             :                 }
     519     8571996 :                 for (i = 0; i < 2; i++) {
     520     5714664 :                     if (IS_INTRA4x4(left_type[LEFT(i)])) {
     521     4594984 :                         int8_t *mode = sl->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];
     522     4594984 :                         sl->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]];
     523     4594984 :                         sl->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]];
     524             :                     } else {
     525     2239360 :                         sl->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] =
     526     2239360 :                         sl->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask);
     527             :                     }
     528             :                 }
     529             :             }
     530             :         }
     531             : 
     532             :         /*
     533             :          * 0 . T T. T T T T
     534             :          * 1 L . .L . . . .
     535             :          * 2 L . .L . . . .
     536             :          * 3 . T TL . . . .
     537             :          * 4 L . .L . . . .
     538             :          * 5 L . .. . . . .
     539             :          */
     540             :         /* FIXME: constraint_intra_pred & partitioning & nnz
     541             :          * (let us hope this is just a typo in the spec) */
     542     9603535 :         nnz_cache = sl->non_zero_count_cache;
     543     9603535 :         if (top_type) {
     544     8847222 :             nnz = h->non_zero_count[top_xy];
     545     8847222 :             AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);
     546     8847222 :             if (!h->chroma_y_shift) {
     547      851463 :                 AV_COPY32(&nnz_cache[4 + 8 *  5], &nnz[4 *  7]);
     548      851463 :                 AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);
     549             :             } else {
     550     7995759 :                 AV_COPY32(&nnz_cache[4 + 8 *  5], &nnz[4 * 5]);
     551     7995759 :                 AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);
     552             :             }
     553             :         } else {
     554      756313 :             uint32_t top_empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 : 0x40404040;
     555      756313 :             AV_WN32A(&nnz_cache[4 + 8 *  0], top_empty);
     556      756313 :             AV_WN32A(&nnz_cache[4 + 8 *  5], top_empty);
     557      756313 :             AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty);
     558             :         }
     559             : 
     560    28810605 :         for (i = 0; i < 2; i++) {
     561    19207070 :             if (left_type[LEFT(i)]) {
     562    18639738 :                 nnz = h->non_zero_count[left_xy[LEFT(i)]];
     563    18639738 :                 nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]];
     564    18639738 :                 nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]];
     565    18639738 :                 if (CHROMA444(h)) {
     566      183572 :                     nnz_cache[3 + 8 *  6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];
     567      183572 :                     nnz_cache[3 + 8 *  7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];
     568      183572 :                     nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];
     569      183572 :                     nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];
     570    18456166 :                 } else if (CHROMA422(h)) {
     571     1619188 :                     nnz_cache[3 + 8 *  6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];
     572     1619188 :                     nnz_cache[3 + 8 *  7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];
     573     1619188 :                     nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];
     574     1619188 :                     nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];
     575             :                 } else {
     576    16836978 :                     nnz_cache[3 + 8 *  6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];
     577    16836978 :                     nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];
     578             :                 }
     579             :             } else {
     580     1134664 :                 nnz_cache[3 + 8 *  1 + 2 * 8 * i] =
     581     1701996 :                 nnz_cache[3 + 8 *  2 + 2 * 8 * i] =
     582     1701996 :                 nnz_cache[3 + 8 *  6 + 2 * 8 * i] =
     583     1701996 :                 nnz_cache[3 + 8 *  7 + 2 * 8 * i] =
     584     1701996 :                 nnz_cache[3 + 8 * 11 + 2 * 8 * i] =
     585     1134664 :                 nnz_cache[3 + 8 * 12 + 2 * 8 * i] = CABAC(h) && !IS_INTRA(mb_type) ? 0 : 64;
     586             :             }
     587             :         }
     588             : 
     589           0 :         if (CABAC(h)) {
     590             :             // top_cbp
     591     6132798 :             if (top_type)
     592     5719314 :                 sl->top_cbp = h->cbp_table[top_xy];
     593             :             else
     594      413484 :                 sl->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
     595             :             // left_cbp
     596     6132798 :             if (left_type[LTOP]) {
     597    17927691 :                 sl->left_cbp =   (h->cbp_table[left_xy[LTOP]] & 0x7F0) |
     598    11951794 :                                ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |
     599     5975897 :                               (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2);
     600             :             } else {
     601      156901 :                 sl->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
     602             :             }
     603             :         }
     604             :     }
     605             : 
     606    11018872 :     if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && sl->direct_spatial_mv_pred)) {
     607             :         int list;
     608     7265999 :         int b_stride = h->b_stride;
     609    18737836 :         for (list = 0; list < sl->list_count; list++) {
     610    11471837 :             int8_t *ref_cache = &sl->ref_cache[list][scan8[0]];
     611    11471837 :             int8_t *ref       = h->cur_pic.ref_index[list];
     612    11471837 :             int16_t(*mv_cache)[2] = &sl->mv_cache[list][scan8[0]];
     613    11471837 :             int16_t(*mv)[2]       = h->cur_pic.motion_val[list];
     614    11471837 :             if (!USES_LIST(mb_type, list))
     615     1195385 :                 continue;
     616             :             av_assert2(!(IS_DIRECT(mb_type) && !sl->direct_spatial_mv_pred));
     617             : 
     618    10276452 :             if (USES_LIST(top_type, list)) {
     619     8199160 :                 const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride;
     620     8199160 :                 AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]);
     621    16398320 :                 ref_cache[0 - 1 * 8] =
     622    16398320 :                 ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];
     623    16398320 :                 ref_cache[2 - 1 * 8] =
     624    16398320 :                 ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];
     625             :             } else {
     626     2077292 :                 AV_ZERO128(mv_cache[0 - 1 * 8]);
     627     2077292 :                 AV_WN32A(&ref_cache[0 - 1 * 8],
     628             :                          ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u);
     629             :             }
     630             : 
     631    10276452 :             if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) {
     632     7964550 :                 for (i = 0; i < 2; i++) {
     633     5309700 :                     int cache_idx = -1 + i * 2 * 8;
     634     5309700 :                     if (USES_LIST(left_type[LEFT(i)], list)) {
     635     4543112 :                         const int b_xy  = h->mb2b_xy[left_xy[LEFT(i)]] + 3;
     636     4543112 :                         const int b8_xy = 4 * left_xy[LEFT(i)] + 1;
     637     4543112 :                         AV_COPY32(mv_cache[cache_idx],
     638             :                                   mv[b_xy + b_stride * left_block[0 + i * 2]]);
     639     4543112 :                         AV_COPY32(mv_cache[cache_idx + 8],
     640             :                                   mv[b_xy + b_stride * left_block[1 + i * 2]]);
     641     4543112 :                         ref_cache[cache_idx]     = ref[b8_xy + (left_block[0 + i * 2] & ~1)];
     642     4543112 :                         ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];
     643             :                     } else {
     644      766588 :                         AV_ZERO32(mv_cache[cache_idx]);
     645      766588 :                         AV_ZERO32(mv_cache[cache_idx + 8]);
     646     1533176 :                         ref_cache[cache_idx]     =
     647     1533176 :                         ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED
     648             :                                                                         : PART_NOT_AVAILABLE;
     649             :                     }
     650             :                 }
     651             :             } else {
     652     7621602 :                 if (USES_LIST(left_type[LTOP], list)) {
     653     6438349 :                     const int b_xy  = h->mb2b_xy[left_xy[LTOP]] + 3;
     654     6438349 :                     const int b8_xy = 4 * left_xy[LTOP] + 1;
     655     6438349 :                     AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]);
     656     6438349 :                     ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];
     657             :                 } else {
     658     1183253 :                     AV_ZERO32(mv_cache[-1]);
     659     1183253 :                     ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED
     660             :                                                     : PART_NOT_AVAILABLE;
     661             :                 }
     662             :             }
     663             : 
     664    10276452 :             if (USES_LIST(topright_type, list)) {
     665     7557983 :                 const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride;
     666     7557983 :                 AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]);
     667     7557983 :                 ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];
     668             :             } else {
     669     2718469 :                 AV_ZERO32(mv_cache[4 - 1 * 8]);
     670     2718469 :                 ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED
     671             :                                                      : PART_NOT_AVAILABLE;
     672             :             }
     673    10276452 :             if(ref_cache[2 - 1*8] < 0 || ref_cache[4 - 1 * 8] < 0) {
     674     3359489 :                 if (USES_LIST(topleft_type, list)) {
     675     3049504 :                     const int b_xy  = h->mb2b_xy[topleft_xy] + 3 + b_stride +
     676     1524752 :                                       (sl->topleft_partition & 2 * b_stride);
     677     1524752 :                     const int b8_xy = 4 * topleft_xy + 1 + (sl->topleft_partition & 2);
     678     1524752 :                     AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]);
     679     1524752 :                     ref_cache[-1 - 1 * 8] = ref[b8_xy];
     680             :                 } else {
     681     1834737 :                     AV_ZERO32(mv_cache[-1 - 1 * 8]);
     682     1834737 :                     ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED
     683             :                                                          : PART_NOT_AVAILABLE;
     684             :                 }
     685             :             }
     686             : 
     687    10276452 :             if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF(h))
     688     3372640 :                 continue;
     689             : 
     690     6903812 :             if (!(mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2))) {
     691     6437854 :                 uint8_t(*mvd_cache)[2]   = &sl->mvd_cache[list][scan8[0]];
     692     6437854 :                 uint8_t(*mvd)[2]         = sl->mvd_table[list];
     693    12875708 :                 ref_cache[2 + 8 * 0] =
     694    12875708 :                 ref_cache[2 + 8 * 2] = PART_NOT_AVAILABLE;
     695     6437854 :                 AV_ZERO32(mv_cache[2 + 8 * 0]);
     696     6437854 :                 AV_ZERO32(mv_cache[2 + 8 * 2]);
     697             : 
     698           0 :                 if (CABAC(h)) {
     699     4126270 :                     if (USES_LIST(top_type, list)) {
     700     3293751 :                         const int b_xy = h->mb2br_xy[top_xy];
     701     3293751 :                         AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);
     702             :                     } else {
     703      832519 :                         AV_ZERO64(mvd_cache[0 - 1 * 8]);
     704             :                     }
     705     4126270 :                     if (USES_LIST(left_type[LTOP], list)) {
     706     3476188 :                         const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6;
     707     3476188 :                         AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);
     708     3476188 :                         AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);
     709             :                     } else {
     710      650082 :                         AV_ZERO16(mvd_cache[-1 + 0 * 8]);
     711      650082 :                         AV_ZERO16(mvd_cache[-1 + 1 * 8]);
     712             :                     }
     713     4126270 :                     if (USES_LIST(left_type[LBOT], list)) {
     714     3475988 :                         const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6;
     715     3475988 :                         AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);
     716     3475988 :                         AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);
     717             :                     } else {
     718      650282 :                         AV_ZERO16(mvd_cache[-1 + 2 * 8]);
     719      650282 :                         AV_ZERO16(mvd_cache[-1 + 3 * 8]);
     720             :                     }
     721     4126270 :                     AV_ZERO16(mvd_cache[2 + 8 * 0]);
     722     4126270 :                     AV_ZERO16(mvd_cache[2 + 8 * 2]);
     723     4126270 :                     if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
     724     2433140 :                         uint8_t *direct_cache = &sl->direct_cache[scan8[0]];
     725     2433140 :                         uint8_t *direct_table = h->direct_table;
     726     2433140 :                         fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1);
     727             : 
     728     2433140 :                         if (IS_DIRECT(top_type)) {
     729      370079 :                             AV_WN32A(&direct_cache[-1 * 8],
     730             :                                      0x01010101u * (MB_TYPE_DIRECT2 >> 1));
     731     2063061 :                         } else if (IS_8X8(top_type)) {
     732      603526 :                             int b8_xy = 4 * top_xy;
     733      603526 :                             direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];
     734      603526 :                             direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];
     735             :                         } else {
     736     1459535 :                             AV_WN32A(&direct_cache[-1 * 8],
     737             :                                      0x01010101 * (MB_TYPE_16x16 >> 1));
     738             :                         }
     739             : 
     740     2433140 :                         if (IS_DIRECT(left_type[LTOP]))
     741      362487 :                             direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1;
     742     2070653 :                         else if (IS_8X8(left_type[LTOP]))
     743      636876 :                             direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)];
     744             :                         else
     745     1433777 :                             direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1;
     746             : 
     747     2433140 :                         if (IS_DIRECT(left_type[LBOT]))
     748      361602 :                             direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1;
     749     2071538 :                         else if (IS_8X8(left_type[LBOT]))
     750      638965 :                             direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];
     751             :                         else
     752     1432573 :                             direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1;
     753             :                     }
     754             :                 }
     755             :             }
     756             : 
     757             : #define MAP_MVS                                                         \
     758             :     MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type)                         \
     759             :     MAP_F2F(scan8[0] + 0 - 1 * 8, top_type)                             \
     760             :     MAP_F2F(scan8[0] + 1 - 1 * 8, top_type)                             \
     761             :     MAP_F2F(scan8[0] + 2 - 1 * 8, top_type)                             \
     762             :     MAP_F2F(scan8[0] + 3 - 1 * 8, top_type)                             \
     763             :     MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type)                        \
     764             :     MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP])                      \
     765             :     MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP])                      \
     766             :     MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT])                      \
     767             :     MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])
     768             : 
     769     6903812 :             if (FRAME_MBAFF(h)) {
     770     1337913 :                 if (MB_FIELD(sl)) {
     771             : 
     772             : #define MAP_F2F(idx, mb_type)                                           \
     773             :     if (!IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) {     \
     774             :         sl->ref_cache[list][idx]     *= 2;                              \
     775             :         sl->mv_cache[list][idx][1]   /= 2;                              \
     776             :         sl->mvd_cache[list][idx][1] >>= 1;                              \
     777             :     }
     778             : 
     779      543998 :                     MAP_MVS
     780             :                 } else {
     781             : 
     782             : #undef MAP_F2F
     783             : #define MAP_F2F(idx, mb_type)                                           \
     784             :     if (IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) {      \
     785             :         sl->ref_cache[list][idx]    >>= 1;                              \
     786             :         sl->mv_cache[list][idx][1]   *= 2;                              \
     787             :         sl->mvd_cache[list][idx][1] <<= 1;                              \
     788             :     }
     789             : 
     790      793915 :                     MAP_MVS
     791             : #undef MAP_F2F
     792             :                 }
     793             :             }
     794             :         }
     795             :     }
     796             : 
     797    11018872 :     sl->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);
     798    11018872 : }
     799             : 
     800             : /**
     801             :  * decodes a P_SKIP or B_SKIP macroblock
     802             :  */
     803     2803794 : static void av_unused decode_mb_skip(const H264Context *h, H264SliceContext *sl)
     804             : {
     805     2803794 :     const int mb_xy = sl->mb_xy;
     806     2803794 :     int mb_type     = 0;
     807             : 
     808     2803794 :     memset(h->non_zero_count[mb_xy], 0, 48);
     809             : 
     810     2803794 :     if (MB_FIELD(sl))
     811      887692 :         mb_type |= MB_TYPE_INTERLACED;
     812             : 
     813     2803794 :     if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
     814             :         // just for fill_caches. pred_direct_motion will set the real mb_type
     815     1551403 :         mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 | MB_TYPE_SKIP;
     816     1551403 :         if (sl->direct_spatial_mv_pred) {
     817     1415337 :             fill_decode_neighbors(h, sl, mb_type);
     818     1415337 :             fill_decode_caches(h, sl, mb_type); //FIXME check what is needed and what not ...
     819             :         }
     820     1551403 :         ff_h264_pred_direct_motion(h, sl, &mb_type);
     821     1551403 :         mb_type |= MB_TYPE_SKIP;
     822             :     } else {
     823     1252391 :         mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P1L0 | MB_TYPE_SKIP;
     824             : 
     825     1252391 :         fill_decode_neighbors(h, sl, mb_type);
     826     1252391 :         pred_pskip_motion(h, sl);
     827             :     }
     828             : 
     829     2803794 :     write_back_motion(h, sl, mb_type);
     830     2803794 :     h->cur_pic.mb_type[mb_xy]      = mb_type;
     831     2803794 :     h->cur_pic.qscale_table[mb_xy] = sl->qscale;
     832     2803794 :     h->slice_table[mb_xy]          = sl->slice_num;
     833     2803794 :     sl->prev_mb_skipped            = 1;
     834     2803794 : }
     835             : 
     836             : #endif /* AVCODEC_H264_MVPRED_H */

Generated by: LCOV version 1.13