Coverage Report

Created: 2026-09-14 08:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavcodec/h264_mvpred.h
Line
Count
Source
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 "h264dec.h"
32
#include "mpegutils.h"
33
#include "rectangle.h"
34
35
#include "libavutil/avassert.h"
36
#include "libavutil/mem_internal.h"
37
38
39
/**
40
 * Get the predicted intra4x4 prediction mode.
41
 */
42
static av_always_inline int pred_intra_mode(const H264Context *h,
43
                                            H264SliceContext *sl, int n)
44
19.2M
{
45
19.2M
    const int index8 = scan8[n];
46
19.2M
    const int left   = sl->intra4x4_pred_mode_cache[index8 - 1];
47
19.2M
    const int top    = sl->intra4x4_pred_mode_cache[index8 - 8];
48
19.2M
    const int min    = FFMIN(left, top);
49
50
19.2M
    ff_tlog(h->avctx, "mode:%d %d min:%d\n", left, top, min);
51
52
19.2M
    if (min < 0)
53
5.57M
        return DC_PRED;
54
13.6M
    else
55
13.6M
        return min;
56
19.2M
}
h264_cavlc.c:pred_intra_mode
Line
Count
Source
44
2.94M
{
45
2.94M
    const int index8 = scan8[n];
46
2.94M
    const int left   = sl->intra4x4_pred_mode_cache[index8 - 1];
47
2.94M
    const int top    = sl->intra4x4_pred_mode_cache[index8 - 8];
48
2.94M
    const int min    = FFMIN(left, top);
49
50
2.94M
    ff_tlog(h->avctx, "mode:%d %d min:%d\n", left, top, min);
51
52
2.94M
    if (min < 0)
53
1.07M
        return DC_PRED;
54
1.86M
    else
55
1.86M
        return min;
56
2.94M
}
h264_cabac.c:pred_intra_mode
Line
Count
Source
44
16.3M
{
45
16.3M
    const int index8 = scan8[n];
46
16.3M
    const int left   = sl->intra4x4_pred_mode_cache[index8 - 1];
47
16.3M
    const int top    = sl->intra4x4_pred_mode_cache[index8 - 8];
48
16.3M
    const int min    = FFMIN(left, top);
49
50
16.3M
    ff_tlog(h->avctx, "mode:%d %d min:%d\n", left, top, min);
51
52
16.3M
    if (min < 0)
53
4.49M
        return DC_PRED;
54
11.8M
    else
55
11.8M
        return min;
56
16.3M
}
57
58
static av_always_inline void write_back_intra_pred_mode(const H264Context *h,
59
                                                        H264SliceContext *sl)
60
2.59M
{
61
2.59M
    int8_t *i4x4       = sl->intra4x4_pred_mode + h->mb2br_xy[sl->mb_xy];
62
2.59M
    int8_t *i4x4_cache = sl->intra4x4_pred_mode_cache;
63
64
2.59M
    AV_COPY32(i4x4, i4x4_cache + 4 + 8 * 4);
65
2.59M
    i4x4[4] = i4x4_cache[7 + 8 * 3];
66
2.59M
    i4x4[5] = i4x4_cache[7 + 8 * 2];
67
2.59M
    i4x4[6] = i4x4_cache[7 + 8 * 1];
68
2.59M
}
h264_cavlc.c:write_back_intra_pred_mode
Line
Count
Source
60
255k
{
61
255k
    int8_t *i4x4       = sl->intra4x4_pred_mode + h->mb2br_xy[sl->mb_xy];
62
255k
    int8_t *i4x4_cache = sl->intra4x4_pred_mode_cache;
63
64
255k
    AV_COPY32(i4x4, i4x4_cache + 4 + 8 * 4);
65
255k
    i4x4[4] = i4x4_cache[7 + 8 * 3];
66
255k
    i4x4[5] = i4x4_cache[7 + 8 * 2];
67
255k
    i4x4[6] = i4x4_cache[7 + 8 * 1];
68
255k
}
h264_cabac.c:write_back_intra_pred_mode
Line
Count
Source
60
2.33M
{
61
2.33M
    int8_t *i4x4       = sl->intra4x4_pred_mode + h->mb2br_xy[sl->mb_xy];
62
2.33M
    int8_t *i4x4_cache = sl->intra4x4_pred_mode_cache;
63
64
2.33M
    AV_COPY32(i4x4, i4x4_cache + 4 + 8 * 4);
65
2.33M
    i4x4[4] = i4x4_cache[7 + 8 * 3];
66
2.33M
    i4x4[5] = i4x4_cache[7 + 8 * 2];
67
2.33M
    i4x4[6] = i4x4_cache[7 + 8 * 1];
68
2.33M
}
69
70
static av_always_inline void write_back_non_zero_count(const H264Context *h,
71
                                                       H264SliceContext *sl)
72
15.9M
{
73
15.9M
    const int mb_xy    = sl->mb_xy;
74
15.9M
    uint8_t *nnz       = h->non_zero_count[mb_xy];
75
15.9M
    uint8_t *nnz_cache = sl->non_zero_count_cache;
76
77
15.9M
    AV_COPY32(&nnz[ 0], &nnz_cache[4 + 8 * 1]);
78
15.9M
    AV_COPY32(&nnz[ 4], &nnz_cache[4 + 8 * 2]);
79
15.9M
    AV_COPY32(&nnz[ 8], &nnz_cache[4 + 8 * 3]);
80
15.9M
    AV_COPY32(&nnz[12], &nnz_cache[4 + 8 * 4]);
81
15.9M
    AV_COPY32(&nnz[16], &nnz_cache[4 + 8 * 6]);
82
15.9M
    AV_COPY32(&nnz[20], &nnz_cache[4 + 8 * 7]);
83
15.9M
    AV_COPY32(&nnz[32], &nnz_cache[4 + 8 * 11]);
84
15.9M
    AV_COPY32(&nnz[36], &nnz_cache[4 + 8 * 12]);
85
86
15.9M
    if (!h->chroma_y_shift) {
87
7.13M
        AV_COPY32(&nnz[24], &nnz_cache[4 + 8 * 8]);
88
7.13M
        AV_COPY32(&nnz[28], &nnz_cache[4 + 8 * 9]);
89
7.13M
        AV_COPY32(&nnz[40], &nnz_cache[4 + 8 * 13]);
90
7.13M
        AV_COPY32(&nnz[44], &nnz_cache[4 + 8 * 14]);
91
7.13M
    }
92
15.9M
}
h264_cavlc.c:write_back_non_zero_count
Line
Count
Source
72
2.16M
{
73
2.16M
    const int mb_xy    = sl->mb_xy;
74
2.16M
    uint8_t *nnz       = h->non_zero_count[mb_xy];
75
2.16M
    uint8_t *nnz_cache = sl->non_zero_count_cache;
76
77
2.16M
    AV_COPY32(&nnz[ 0], &nnz_cache[4 + 8 * 1]);
78
2.16M
    AV_COPY32(&nnz[ 4], &nnz_cache[4 + 8 * 2]);
79
2.16M
    AV_COPY32(&nnz[ 8], &nnz_cache[4 + 8 * 3]);
80
2.16M
    AV_COPY32(&nnz[12], &nnz_cache[4 + 8 * 4]);
81
2.16M
    AV_COPY32(&nnz[16], &nnz_cache[4 + 8 * 6]);
82
2.16M
    AV_COPY32(&nnz[20], &nnz_cache[4 + 8 * 7]);
83
2.16M
    AV_COPY32(&nnz[32], &nnz_cache[4 + 8 * 11]);
84
2.16M
    AV_COPY32(&nnz[36], &nnz_cache[4 + 8 * 12]);
85
86
2.16M
    if (!h->chroma_y_shift) {
87
502k
        AV_COPY32(&nnz[24], &nnz_cache[4 + 8 * 8]);
88
502k
        AV_COPY32(&nnz[28], &nnz_cache[4 + 8 * 9]);
89
502k
        AV_COPY32(&nnz[40], &nnz_cache[4 + 8 * 13]);
90
502k
        AV_COPY32(&nnz[44], &nnz_cache[4 + 8 * 14]);
91
502k
    }
92
2.16M
}
h264_cabac.c:write_back_non_zero_count
Line
Count
Source
72
13.7M
{
73
13.7M
    const int mb_xy    = sl->mb_xy;
74
13.7M
    uint8_t *nnz       = h->non_zero_count[mb_xy];
75
13.7M
    uint8_t *nnz_cache = sl->non_zero_count_cache;
76
77
13.7M
    AV_COPY32(&nnz[ 0], &nnz_cache[4 + 8 * 1]);
78
13.7M
    AV_COPY32(&nnz[ 4], &nnz_cache[4 + 8 * 2]);
79
13.7M
    AV_COPY32(&nnz[ 8], &nnz_cache[4 + 8 * 3]);
80
13.7M
    AV_COPY32(&nnz[12], &nnz_cache[4 + 8 * 4]);
81
13.7M
    AV_COPY32(&nnz[16], &nnz_cache[4 + 8 * 6]);
82
13.7M
    AV_COPY32(&nnz[20], &nnz_cache[4 + 8 * 7]);
83
13.7M
    AV_COPY32(&nnz[32], &nnz_cache[4 + 8 * 11]);
84
13.7M
    AV_COPY32(&nnz[36], &nnz_cache[4 + 8 * 12]);
85
86
13.7M
    if (!h->chroma_y_shift) {
87
6.63M
        AV_COPY32(&nnz[24], &nnz_cache[4 + 8 * 8]);
88
6.63M
        AV_COPY32(&nnz[28], &nnz_cache[4 + 8 * 9]);
89
6.63M
        AV_COPY32(&nnz[40], &nnz_cache[4 + 8 * 13]);
90
6.63M
        AV_COPY32(&nnz[44], &nnz_cache[4 + 8 * 14]);
91
6.63M
    }
92
13.7M
}
93
94
static av_always_inline void write_back_motion_list(const H264Context *h,
95
                                                    H264SliceContext *sl,
96
                                                    int b_stride,
97
                                                    int b_xy, int b8_xy,
98
                                                    int mb_type, int list)
99
49.9M
{
100
49.9M
    int16_t(*mv_dst)[2] = &h->cur_pic.motion_val[list][b_xy];
101
49.9M
    int16_t(*mv_src)[2] = &sl->mv_cache[list][scan8[0]];
102
49.9M
    AV_COPY128(mv_dst + 0 * b_stride, mv_src + 8 * 0);
103
49.9M
    AV_COPY128(mv_dst + 1 * b_stride, mv_src + 8 * 1);
104
49.9M
    AV_COPY128(mv_dst + 2 * b_stride, mv_src + 8 * 2);
105
49.9M
    AV_COPY128(mv_dst + 3 * b_stride, mv_src + 8 * 3);
106
49.9M
    if (CABAC(h)) {
107
41.4M
        uint8_t (*mvd_dst)[2] = &sl->mvd_table[list][FMO ? 8 * sl->mb_xy
108
41.4M
                                                        : h->mb2br_xy[sl->mb_xy]];
109
41.4M
        uint8_t(*mvd_src)[2]  = &sl->mvd_cache[list][scan8[0]];
110
41.4M
        if (IS_SKIP(mb_type)) {
111
28.7M
            AV_ZERO128(mvd_dst);
112
28.7M
        } else {
113
12.6M
            AV_COPY64(mvd_dst, mvd_src + 8 * 3);
114
12.6M
            AV_COPY16(mvd_dst + 3 + 3, mvd_src + 3 + 8 * 0);
115
12.6M
            AV_COPY16(mvd_dst + 3 + 2, mvd_src + 3 + 8 * 1);
116
12.6M
            AV_COPY16(mvd_dst + 3 + 1, mvd_src + 3 + 8 * 2);
117
12.6M
        }
118
41.4M
    }
119
120
49.9M
    {
121
49.9M
        int8_t *ref_index = &h->cur_pic.ref_index[list][b8_xy];
122
49.9M
        int8_t *ref_cache = sl->ref_cache[list];
123
49.9M
        ref_index[0 + 0 * 2] = ref_cache[scan8[0]];
124
49.9M
        ref_index[1 + 0 * 2] = ref_cache[scan8[4]];
125
49.9M
        ref_index[0 + 1 * 2] = ref_cache[scan8[8]];
126
49.9M
        ref_index[1 + 1 * 2] = ref_cache[scan8[12]];
127
49.9M
    }
128
49.9M
}
h264_cavlc.c:write_back_motion_list
Line
Count
Source
99
8.56M
{
100
8.56M
    int16_t(*mv_dst)[2] = &h->cur_pic.motion_val[list][b_xy];
101
8.56M
    int16_t(*mv_src)[2] = &sl->mv_cache[list][scan8[0]];
102
8.56M
    AV_COPY128(mv_dst + 0 * b_stride, mv_src + 8 * 0);
103
8.56M
    AV_COPY128(mv_dst + 1 * b_stride, mv_src + 8 * 1);
104
8.56M
    AV_COPY128(mv_dst + 2 * b_stride, mv_src + 8 * 2);
105
8.56M
    AV_COPY128(mv_dst + 3 * b_stride, mv_src + 8 * 3);
106
8.56M
    if (CABAC(h)) {
107
0
        uint8_t (*mvd_dst)[2] = &sl->mvd_table[list][FMO ? 8 * sl->mb_xy
108
0
                                                        : h->mb2br_xy[sl->mb_xy]];
109
0
        uint8_t(*mvd_src)[2]  = &sl->mvd_cache[list][scan8[0]];
110
0
        if (IS_SKIP(mb_type)) {
111
0
            AV_ZERO128(mvd_dst);
112
0
        } else {
113
0
            AV_COPY64(mvd_dst, mvd_src + 8 * 3);
114
0
            AV_COPY16(mvd_dst + 3 + 3, mvd_src + 3 + 8 * 0);
115
0
            AV_COPY16(mvd_dst + 3 + 2, mvd_src + 3 + 8 * 1);
116
0
            AV_COPY16(mvd_dst + 3 + 1, mvd_src + 3 + 8 * 2);
117
0
        }
118
0
    }
119
120
8.56M
    {
121
8.56M
        int8_t *ref_index = &h->cur_pic.ref_index[list][b8_xy];
122
8.56M
        int8_t *ref_cache = sl->ref_cache[list];
123
8.56M
        ref_index[0 + 0 * 2] = ref_cache[scan8[0]];
124
8.56M
        ref_index[1 + 0 * 2] = ref_cache[scan8[4]];
125
8.56M
        ref_index[0 + 1 * 2] = ref_cache[scan8[8]];
126
8.56M
        ref_index[1 + 1 * 2] = ref_cache[scan8[12]];
127
8.56M
    }
128
8.56M
}
h264_cabac.c:write_back_motion_list
Line
Count
Source
99
41.4M
{
100
41.4M
    int16_t(*mv_dst)[2] = &h->cur_pic.motion_val[list][b_xy];
101
41.4M
    int16_t(*mv_src)[2] = &sl->mv_cache[list][scan8[0]];
102
41.4M
    AV_COPY128(mv_dst + 0 * b_stride, mv_src + 8 * 0);
103
41.4M
    AV_COPY128(mv_dst + 1 * b_stride, mv_src + 8 * 1);
104
41.4M
    AV_COPY128(mv_dst + 2 * b_stride, mv_src + 8 * 2);
105
41.4M
    AV_COPY128(mv_dst + 3 * b_stride, mv_src + 8 * 3);
106
41.4M
    if (CABAC(h)) {
107
41.4M
        uint8_t (*mvd_dst)[2] = &sl->mvd_table[list][FMO ? 8 * sl->mb_xy
108
41.4M
                                                        : h->mb2br_xy[sl->mb_xy]];
109
41.4M
        uint8_t(*mvd_src)[2]  = &sl->mvd_cache[list][scan8[0]];
110
41.4M
        if (IS_SKIP(mb_type)) {
111
28.7M
            AV_ZERO128(mvd_dst);
112
28.7M
        } else {
113
12.6M
            AV_COPY64(mvd_dst, mvd_src + 8 * 3);
114
12.6M
            AV_COPY16(mvd_dst + 3 + 3, mvd_src + 3 + 8 * 0);
115
12.6M
            AV_COPY16(mvd_dst + 3 + 2, mvd_src + 3 + 8 * 1);
116
12.6M
            AV_COPY16(mvd_dst + 3 + 1, mvd_src + 3 + 8 * 2);
117
12.6M
        }
118
41.4M
    }
119
120
41.4M
    {
121
41.4M
        int8_t *ref_index = &h->cur_pic.ref_index[list][b8_xy];
122
41.4M
        int8_t *ref_cache = sl->ref_cache[list];
123
41.4M
        ref_index[0 + 0 * 2] = ref_cache[scan8[0]];
124
41.4M
        ref_index[1 + 0 * 2] = ref_cache[scan8[4]];
125
41.4M
        ref_index[0 + 1 * 2] = ref_cache[scan8[8]];
126
41.4M
        ref_index[1 + 1 * 2] = ref_cache[scan8[12]];
127
41.4M
    }
128
41.4M
}
129
130
static av_always_inline void write_back_motion(const H264Context *h,
131
                                               H264SliceContext *sl,
132
                                               int mb_type)
133
35.5M
{
134
35.5M
    const int b_stride      = h->b_stride;
135
35.5M
    const int b_xy  = 4 * sl->mb_x + 4 * sl->mb_y * h->b_stride; // try mb2b(8)_xy
136
35.5M
    const int b8_xy = 4 * sl->mb_xy;
137
138
35.5M
    if (USES_LIST(mb_type, 0)) {
139
31.7M
        write_back_motion_list(h, sl, b_stride, b_xy, b8_xy, mb_type, 0);
140
31.7M
    } else {
141
3.75M
        fill_rectangle(&h->cur_pic.ref_index[0][b8_xy],
142
3.75M
                       2, 2, 2, (uint8_t)LIST_NOT_USED, 1);
143
3.75M
    }
144
35.5M
    if (USES_LIST(mb_type, 1))
145
18.1M
        write_back_motion_list(h, sl, b_stride, b_xy, b8_xy, mb_type, 1);
146
147
35.5M
    if (sl->slice_type_nos == AV_PICTURE_TYPE_B && CABAC(h)) {
148
18.4M
        if (IS_8X8(mb_type)) {
149
3.86M
            uint8_t *direct_table = &h->direct_table[4 * sl->mb_xy];
150
3.86M
            direct_table[1] = sl->sub_mb_type[1] >> 1;
151
3.86M
            direct_table[2] = sl->sub_mb_type[2] >> 1;
152
3.86M
            direct_table[3] = sl->sub_mb_type[3] >> 1;
153
3.86M
        }
154
18.4M
    }
155
35.5M
}
h264_cavlc.c:write_back_motion
Line
Count
Source
133
6.82M
{
134
6.82M
    const int b_stride      = h->b_stride;
135
6.82M
    const int b_xy  = 4 * sl->mb_x + 4 * sl->mb_y * h->b_stride; // try mb2b(8)_xy
136
6.82M
    const int b8_xy = 4 * sl->mb_xy;
137
138
6.82M
    if (USES_LIST(mb_type, 0)) {
139
6.59M
        write_back_motion_list(h, sl, b_stride, b_xy, b8_xy, mb_type, 0);
140
6.59M
    } else {
141
235k
        fill_rectangle(&h->cur_pic.ref_index[0][b8_xy],
142
235k
                       2, 2, 2, (uint8_t)LIST_NOT_USED, 1);
143
235k
    }
144
6.82M
    if (USES_LIST(mb_type, 1))
145
1.97M
        write_back_motion_list(h, sl, b_stride, b_xy, b8_xy, mb_type, 1);
146
147
6.82M
    if (sl->slice_type_nos == AV_PICTURE_TYPE_B && CABAC(h)) {
148
0
        if (IS_8X8(mb_type)) {
149
0
            uint8_t *direct_table = &h->direct_table[4 * sl->mb_xy];
150
0
            direct_table[1] = sl->sub_mb_type[1] >> 1;
151
0
            direct_table[2] = sl->sub_mb_type[2] >> 1;
152
0
            direct_table[3] = sl->sub_mb_type[3] >> 1;
153
0
        }
154
0
    }
155
6.82M
}
h264_cabac.c:write_back_motion
Line
Count
Source
133
28.7M
{
134
28.7M
    const int b_stride      = h->b_stride;
135
28.7M
    const int b_xy  = 4 * sl->mb_x + 4 * sl->mb_y * h->b_stride; // try mb2b(8)_xy
136
28.7M
    const int b8_xy = 4 * sl->mb_xy;
137
138
28.7M
    if (USES_LIST(mb_type, 0)) {
139
25.1M
        write_back_motion_list(h, sl, b_stride, b_xy, b8_xy, mb_type, 0);
140
25.1M
    } else {
141
3.51M
        fill_rectangle(&h->cur_pic.ref_index[0][b8_xy],
142
3.51M
                       2, 2, 2, (uint8_t)LIST_NOT_USED, 1);
143
3.51M
    }
144
28.7M
    if (USES_LIST(mb_type, 1))
145
16.2M
        write_back_motion_list(h, sl, b_stride, b_xy, b8_xy, mb_type, 1);
146
147
28.7M
    if (sl->slice_type_nos == AV_PICTURE_TYPE_B && CABAC(h)) {
148
18.4M
        if (IS_8X8(mb_type)) {
149
3.86M
            uint8_t *direct_table = &h->direct_table[4 * sl->mb_xy];
150
3.86M
            direct_table[1] = sl->sub_mb_type[1] >> 1;
151
3.86M
            direct_table[2] = sl->sub_mb_type[2] >> 1;
152
3.86M
            direct_table[3] = sl->sub_mb_type[3] >> 1;
153
3.86M
        }
154
18.4M
    }
155
28.7M
}
156
157
static av_always_inline int get_dct8x8_allowed(const H264Context *h, H264SliceContext *sl)
158
1.82M
{
159
1.82M
    if (h->ps.sps->direct_8x8_inference_flag)
160
1.16M
        return !(AV_RN64A(sl->sub_mb_type) &
161
1.16M
                 ((MB_TYPE_16x8 | MB_TYPE_8x16 | MB_TYPE_8x8) *
162
1.16M
                  0x0001000100010001ULL));
163
657k
    else
164
657k
        return !(AV_RN64A(sl->sub_mb_type) &
165
657k
                 ((MB_TYPE_16x8 | MB_TYPE_8x16 | MB_TYPE_8x8 | MB_TYPE_DIRECT2) *
166
657k
                  0x0001000100010001ULL));
167
1.82M
}
h264_cavlc.c:get_dct8x8_allowed
Line
Count
Source
158
49.5k
{
159
49.5k
    if (h->ps.sps->direct_8x8_inference_flag)
160
9.25k
        return !(AV_RN64A(sl->sub_mb_type) &
161
9.25k
                 ((MB_TYPE_16x8 | MB_TYPE_8x16 | MB_TYPE_8x8) *
162
9.25k
                  0x0001000100010001ULL));
163
40.3k
    else
164
40.3k
        return !(AV_RN64A(sl->sub_mb_type) &
165
40.3k
                 ((MB_TYPE_16x8 | MB_TYPE_8x16 | MB_TYPE_8x8 | MB_TYPE_DIRECT2) *
166
40.3k
                  0x0001000100010001ULL));
167
49.5k
}
h264_cabac.c:get_dct8x8_allowed
Line
Count
Source
158
1.77M
{
159
1.77M
    if (h->ps.sps->direct_8x8_inference_flag)
160
1.15M
        return !(AV_RN64A(sl->sub_mb_type) &
161
1.15M
                 ((MB_TYPE_16x8 | MB_TYPE_8x16 | MB_TYPE_8x8) *
162
1.15M
                  0x0001000100010001ULL));
163
617k
    else
164
617k
        return !(AV_RN64A(sl->sub_mb_type) &
165
617k
                 ((MB_TYPE_16x8 | MB_TYPE_8x16 | MB_TYPE_8x8 | MB_TYPE_DIRECT2) *
166
617k
                  0x0001000100010001ULL));
167
1.77M
}
168
169
static av_always_inline int fetch_diagonal_mv(const H264Context *h, H264SliceContext *sl,
170
                                              const int16_t **C,
171
                                              int i, int list, int part_width)
172
24.8M
{
173
24.8M
    const int topright_ref = sl->ref_cache[list][i - 8 + part_width];
174
175
    /* there is no consistent mapping of mvs to neighboring locations that will
176
     * make mbaff happy, so we can't move all this logic to fill_caches */
177
24.8M
    if (FRAME_MBAFF(h)) {
178
8.92M
#define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4)                              \
179
8.92M
        const int xy = XY, y4 = Y4;                                     \
180
98.8k
        const int mb_type = mb_types[xy + (y4 >> 2) * h->mb_stride];    \
181
121k
        if (!USES_LIST(mb_type, list))                                  \
182
98.8k
            return LIST_NOT_USED;                                       \
183
98.8k
        mv = h->cur_pic_ptr->motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \
184
98.8k
        sl->mv_cache[list][scan8[0] - 2][0] = mv[0];                     \
185
98.8k
        sl->mv_cache[list][scan8[0] - 2][1] = mv[1] MV_OP;               \
186
98.8k
        return h->cur_pic_ptr->ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP;
187
188
8.92M
        if (topright_ref == PART_NOT_AVAILABLE
189
4.96M
            && i >= scan8[0] + 8 && (i & 7) == 4
190
726k
            && sl->ref_cache[list][scan8[0] - 1] != PART_NOT_AVAILABLE) {
191
595k
            const uint32_t *mb_types = h->cur_pic_ptr->mb_type;
192
595k
            const int16_t *mv;
193
595k
            AV_ZERO32(sl->mv_cache[list][scan8[0] - 2]);
194
595k
            *C = sl->mv_cache[list][scan8[0] - 2];
195
196
595k
            if (!MB_FIELD(sl) && IS_INTERLACED(sl->left_type[0])) {
197
54.8k
                SET_DIAG_MV(* 2, >> 1, sl->left_mb_xy[0] + h->mb_stride,
198
54.8k
                            (sl->mb_y & 1) * 2 + (i >> 5));
199
0
            }
200
540k
            if (MB_FIELD(sl) && !IS_INTERLACED(sl->left_type[0])) {
201
                // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK.
202
66.1k
                SET_DIAG_MV(/ 2, *2, sl->left_mb_xy[i >= 36], ((i >> 2)) & 3);
203
0
            }
204
540k
        }
205
8.92M
#undef SET_DIAG_MV
206
8.92M
    }
207
208
24.7M
    if (topright_ref != PART_NOT_AVAILABLE) {
209
12.5M
        *C = sl->mv_cache[list][i - 8 + part_width];
210
12.5M
        return topright_ref;
211
12.5M
    } else {
212
12.1M
        ff_tlog(h->avctx, "topright MV not available\n");
213
214
12.1M
        *C = sl->mv_cache[list][i - 8 - 1];
215
12.1M
        return sl->ref_cache[list][i - 8 - 1];
216
12.1M
    }
217
24.7M
}
h264_cavlc.c:fetch_diagonal_mv
Line
Count
Source
172
2.58M
{
173
2.58M
    const int topright_ref = sl->ref_cache[list][i - 8 + part_width];
174
175
    /* there is no consistent mapping of mvs to neighboring locations that will
176
     * make mbaff happy, so we can't move all this logic to fill_caches */
177
2.58M
    if (FRAME_MBAFF(h)) {
178
1.02M
#define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4)                              \
179
1.02M
        const int xy = XY, y4 = Y4;                                     \
180
1.02M
        const int mb_type = mb_types[xy + (y4 >> 2) * h->mb_stride];    \
181
1.02M
        if (!USES_LIST(mb_type, list))                                  \
182
1.02M
            return LIST_NOT_USED;                                       \
183
1.02M
        mv = h->cur_pic_ptr->motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \
184
1.02M
        sl->mv_cache[list][scan8[0] - 2][0] = mv[0];                     \
185
1.02M
        sl->mv_cache[list][scan8[0] - 2][1] = mv[1] MV_OP;               \
186
1.02M
        return h->cur_pic_ptr->ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP;
187
188
1.02M
        if (topright_ref == PART_NOT_AVAILABLE
189
613k
            && i >= scan8[0] + 8 && (i & 7) == 4
190
103k
            && sl->ref_cache[list][scan8[0] - 1] != PART_NOT_AVAILABLE) {
191
93.1k
            const uint32_t *mb_types = h->cur_pic_ptr->mb_type;
192
93.1k
            const int16_t *mv;
193
93.1k
            AV_ZERO32(sl->mv_cache[list][scan8[0] - 2]);
194
93.1k
            *C = sl->mv_cache[list][scan8[0] - 2];
195
196
93.1k
            if (!MB_FIELD(sl) && IS_INTERLACED(sl->left_type[0])) {
197
1.26k
                SET_DIAG_MV(* 2, >> 1, sl->left_mb_xy[0] + h->mb_stride,
198
1.26k
                            (sl->mb_y & 1) * 2 + (i >> 5));
199
0
            }
200
91.8k
            if (MB_FIELD(sl) && !IS_INTERLACED(sl->left_type[0])) {
201
                // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK.
202
7.00k
                SET_DIAG_MV(/ 2, *2, sl->left_mb_xy[i >= 36], ((i >> 2)) & 3);
203
0
            }
204
91.8k
        }
205
1.02M
#undef SET_DIAG_MV
206
1.02M
    }
207
208
2.57M
    if (topright_ref != PART_NOT_AVAILABLE) {
209
1.29M
        *C = sl->mv_cache[list][i - 8 + part_width];
210
1.29M
        return topright_ref;
211
1.29M
    } else {
212
1.28M
        ff_tlog(h->avctx, "topright MV not available\n");
213
214
1.28M
        *C = sl->mv_cache[list][i - 8 - 1];
215
1.28M
        return sl->ref_cache[list][i - 8 - 1];
216
1.28M
    }
217
2.57M
}
h264_cabac.c:fetch_diagonal_mv
Line
Count
Source
172
22.2M
{
173
22.2M
    const int topright_ref = sl->ref_cache[list][i - 8 + part_width];
174
175
    /* there is no consistent mapping of mvs to neighboring locations that will
176
     * make mbaff happy, so we can't move all this logic to fill_caches */
177
22.2M
    if (FRAME_MBAFF(h)) {
178
7.90M
#define SET_DIAG_MV(MV_OP, REF_OP, XY, Y4)                              \
179
7.90M
        const int xy = XY, y4 = Y4;                                     \
180
7.90M
        const int mb_type = mb_types[xy + (y4 >> 2) * h->mb_stride];    \
181
7.90M
        if (!USES_LIST(mb_type, list))                                  \
182
7.90M
            return LIST_NOT_USED;                                       \
183
7.90M
        mv = h->cur_pic_ptr->motion_val[list][h->mb2b_xy[xy] + 3 + y4 * h->b_stride]; \
184
7.90M
        sl->mv_cache[list][scan8[0] - 2][0] = mv[0];                     \
185
7.90M
        sl->mv_cache[list][scan8[0] - 2][1] = mv[1] MV_OP;               \
186
7.90M
        return h->cur_pic_ptr->ref_index[list][4 * xy + 1 + (y4 & ~1)] REF_OP;
187
188
7.90M
        if (topright_ref == PART_NOT_AVAILABLE
189
4.35M
            && i >= scan8[0] + 8 && (i & 7) == 4
190
622k
            && sl->ref_cache[list][scan8[0] - 1] != PART_NOT_AVAILABLE) {
191
502k
            const uint32_t *mb_types = h->cur_pic_ptr->mb_type;
192
502k
            const int16_t *mv;
193
502k
            AV_ZERO32(sl->mv_cache[list][scan8[0] - 2]);
194
502k
            *C = sl->mv_cache[list][scan8[0] - 2];
195
196
502k
            if (!MB_FIELD(sl) && IS_INTERLACED(sl->left_type[0])) {
197
53.6k
                SET_DIAG_MV(* 2, >> 1, sl->left_mb_xy[0] + h->mb_stride,
198
53.6k
                            (sl->mb_y & 1) * 2 + (i >> 5));
199
0
            }
200
448k
            if (MB_FIELD(sl) && !IS_INTERLACED(sl->left_type[0])) {
201
                // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK.
202
59.1k
                SET_DIAG_MV(/ 2, *2, sl->left_mb_xy[i >= 36], ((i >> 2)) & 3);
203
0
            }
204
448k
        }
205
7.90M
#undef SET_DIAG_MV
206
7.90M
    }
207
208
22.1M
    if (topright_ref != PART_NOT_AVAILABLE) {
209
11.2M
        *C = sl->mv_cache[list][i - 8 + part_width];
210
11.2M
        return topright_ref;
211
11.2M
    } else {
212
10.9M
        ff_tlog(h->avctx, "topright MV not available\n");
213
214
10.9M
        *C = sl->mv_cache[list][i - 8 - 1];
215
10.9M
        return sl->ref_cache[list][i - 8 - 1];
216
10.9M
    }
217
22.1M
}
218
219
/**
220
 * Get the predicted MV.
221
 * @param n the block index
222
 * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4)
223
 * @param mx the x component of the predicted motion vector
224
 * @param my the y component of the predicted motion vector
225
 */
226
static av_always_inline void pred_motion(const H264Context *const h,
227
                                         H264SliceContext *sl,
228
                                         int n,
229
                                         int part_width, int list, int ref,
230
                                         int *const mx, int *const my)
231
23.4M
{
232
23.4M
    const int index8       = scan8[n];
233
23.4M
    const int top_ref      = sl->ref_cache[list][index8 - 8];
234
23.4M
    const int left_ref     = sl->ref_cache[list][index8 - 1];
235
23.4M
    const int16_t *const A = sl->mv_cache[list][index8 - 1];
236
23.4M
    const int16_t *const B = sl->mv_cache[list][index8 - 8];
237
23.4M
    const int16_t *C;
238
23.4M
    int diagonal_ref, match_count;
239
240
23.4M
    av_assert2(part_width == 1 || part_width == 2 || part_width == 4);
241
242
/* mv_cache
243
 * B . . A T T T T
244
 * U . . L . . , .
245
 * U . . L . . . .
246
 * U . . L . . , .
247
 * . . . L . . . .
248
 */
249
250
23.4M
    diagonal_ref = fetch_diagonal_mv(h, sl, &C, index8, list, part_width);
251
23.4M
    match_count  = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
252
23.4M
    ff_tlog(h->avctx, "pred_motion match_count=%d\n", match_count);
253
23.4M
    if (match_count > 1) { //most common
254
12.2M
        *mx = mid_pred(A[0], B[0], C[0]);
255
12.2M
        *my = mid_pred(A[1], B[1], C[1]);
256
12.2M
    } else if (match_count == 1) {
257
6.21M
        if (left_ref == ref) {
258
4.07M
            *mx = A[0];
259
4.07M
            *my = A[1];
260
4.07M
        } else if (top_ref == ref) {
261
1.61M
            *mx = B[0];
262
1.61M
            *my = B[1];
263
1.61M
        } else {
264
515k
            *mx = C[0];
265
515k
            *my = C[1];
266
515k
        }
267
6.21M
    } else {
268
4.92M
        if (top_ref      == PART_NOT_AVAILABLE &&
269
1.98M
            diagonal_ref == PART_NOT_AVAILABLE &&
270
1.97M
            left_ref     != PART_NOT_AVAILABLE) {
271
1.49M
            *mx = A[0];
272
1.49M
            *my = A[1];
273
3.42M
        } else {
274
3.42M
            *mx = mid_pred(A[0], B[0], C[0]);
275
3.42M
            *my = mid_pred(A[1], B[1], C[1]);
276
3.42M
        }
277
4.92M
    }
278
279
23.4M
    ff_tlog(h->avctx,
280
23.4M
            "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n",
281
23.4M
            top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref,
282
23.4M
            A[0], A[1], ref, *mx, *my, sl->mb_x, sl->mb_y, n, list);
283
23.4M
}
h264_cavlc.c:pred_motion
Line
Count
Source
231
2.36M
{
232
2.36M
    const int index8       = scan8[n];
233
2.36M
    const int top_ref      = sl->ref_cache[list][index8 - 8];
234
2.36M
    const int left_ref     = sl->ref_cache[list][index8 - 1];
235
2.36M
    const int16_t *const A = sl->mv_cache[list][index8 - 1];
236
2.36M
    const int16_t *const B = sl->mv_cache[list][index8 - 8];
237
2.36M
    const int16_t *C;
238
2.36M
    int diagonal_ref, match_count;
239
240
2.36M
    av_assert2(part_width == 1 || part_width == 2 || part_width == 4);
241
242
/* mv_cache
243
 * B . . A T T T T
244
 * U . . L . . , .
245
 * U . . L . . . .
246
 * U . . L . . , .
247
 * . . . L . . . .
248
 */
249
250
2.36M
    diagonal_ref = fetch_diagonal_mv(h, sl, &C, index8, list, part_width);
251
2.36M
    match_count  = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
252
2.36M
    ff_tlog(h->avctx, "pred_motion match_count=%d\n", match_count);
253
2.36M
    if (match_count > 1) { //most common
254
1.04M
        *mx = mid_pred(A[0], B[0], C[0]);
255
1.04M
        *my = mid_pred(A[1], B[1], C[1]);
256
1.32M
    } else if (match_count == 1) {
257
638k
        if (left_ref == ref) {
258
379k
            *mx = A[0];
259
379k
            *my = A[1];
260
379k
        } else if (top_ref == ref) {
261
213k
            *mx = B[0];
262
213k
            *my = B[1];
263
213k
        } else {
264
45.0k
            *mx = C[0];
265
45.0k
            *my = C[1];
266
45.0k
        }
267
683k
    } else {
268
683k
        if (top_ref      == PART_NOT_AVAILABLE &&
269
346k
            diagonal_ref == PART_NOT_AVAILABLE &&
270
342k
            left_ref     != PART_NOT_AVAILABLE) {
271
126k
            *mx = A[0];
272
126k
            *my = A[1];
273
556k
        } else {
274
556k
            *mx = mid_pred(A[0], B[0], C[0]);
275
556k
            *my = mid_pred(A[1], B[1], C[1]);
276
556k
        }
277
683k
    }
278
279
2.36M
    ff_tlog(h->avctx,
280
2.36M
            "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n",
281
2.36M
            top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref,
282
2.36M
            A[0], A[1], ref, *mx, *my, sl->mb_x, sl->mb_y, n, list);
283
2.36M
}
h264_cabac.c:pred_motion
Line
Count
Source
231
21.0M
{
232
21.0M
    const int index8       = scan8[n];
233
21.0M
    const int top_ref      = sl->ref_cache[list][index8 - 8];
234
21.0M
    const int left_ref     = sl->ref_cache[list][index8 - 1];
235
21.0M
    const int16_t *const A = sl->mv_cache[list][index8 - 1];
236
21.0M
    const int16_t *const B = sl->mv_cache[list][index8 - 8];
237
21.0M
    const int16_t *C;
238
21.0M
    int diagonal_ref, match_count;
239
240
21.0M
    av_assert2(part_width == 1 || part_width == 2 || part_width == 4);
241
242
/* mv_cache
243
 * B . . A T T T T
244
 * U . . L . . , .
245
 * U . . L . . . .
246
 * U . . L . . , .
247
 * . . . L . . . .
248
 */
249
250
21.0M
    diagonal_ref = fetch_diagonal_mv(h, sl, &C, index8, list, part_width);
251
21.0M
    match_count  = (diagonal_ref == ref) + (top_ref == ref) + (left_ref == ref);
252
21.0M
    ff_tlog(h->avctx, "pred_motion match_count=%d\n", match_count);
253
21.0M
    if (match_count > 1) { //most common
254
11.2M
        *mx = mid_pred(A[0], B[0], C[0]);
255
11.2M
        *my = mid_pred(A[1], B[1], C[1]);
256
11.2M
    } else if (match_count == 1) {
257
5.57M
        if (left_ref == ref) {
258
3.70M
            *mx = A[0];
259
3.70M
            *my = A[1];
260
3.70M
        } else if (top_ref == ref) {
261
1.40M
            *mx = B[0];
262
1.40M
            *my = B[1];
263
1.40M
        } else {
264
470k
            *mx = C[0];
265
470k
            *my = C[1];
266
470k
        }
267
5.57M
    } else {
268
4.23M
        if (top_ref      == PART_NOT_AVAILABLE &&
269
1.63M
            diagonal_ref == PART_NOT_AVAILABLE &&
270
1.63M
            left_ref     != PART_NOT_AVAILABLE) {
271
1.36M
            *mx = A[0];
272
1.36M
            *my = A[1];
273
2.87M
        } else {
274
2.87M
            *mx = mid_pred(A[0], B[0], C[0]);
275
2.87M
            *my = mid_pred(A[1], B[1], C[1]);
276
2.87M
        }
277
4.23M
    }
278
279
21.0M
    ff_tlog(h->avctx,
280
21.0M
            "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n",
281
21.0M
            top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref,
282
21.0M
            A[0], A[1], ref, *mx, *my, sl->mb_x, sl->mb_y, n, list);
283
21.0M
}
284
285
/**
286
 * Get the directionally predicted 16x8 MV.
287
 * @param n the block index
288
 * @param mx the x component of the predicted motion vector
289
 * @param my the y component of the predicted motion vector
290
 */
291
static av_always_inline void pred_16x8_motion(const H264Context *const h,
292
                                              H264SliceContext *sl,
293
                                              int n, int list, int ref,
294
                                              int *const mx, int *const my)
295
3.56M
{
296
3.56M
    if (n == 0) {
297
1.64M
        const int top_ref      = sl->ref_cache[list][scan8[0] - 8];
298
1.64M
        const int16_t *const B = sl->mv_cache[list][scan8[0] - 8];
299
300
1.64M
        ff_tlog(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
301
1.64M
                top_ref, B[0], B[1], sl->mb_x, sl->mb_y, n, list);
302
303
1.64M
        if (top_ref == ref) {
304
766k
            *mx = B[0];
305
766k
            *my = B[1];
306
766k
            return;
307
766k
        }
308
1.91M
    } else {
309
1.91M
        const int left_ref     = sl->ref_cache[list][scan8[8] - 1];
310
1.91M
        const int16_t *const A = sl->mv_cache[list][scan8[8] - 1];
311
312
1.91M
        ff_tlog(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
313
1.91M
                left_ref, A[0], A[1], sl->mb_x, sl->mb_y, n, list);
314
315
1.91M
        if (left_ref == ref) {
316
1.14M
            *mx = A[0];
317
1.14M
            *my = A[1];
318
1.14M
            return;
319
1.14M
        }
320
1.91M
    }
321
322
    //RARE
323
1.65M
    pred_motion(h, sl, n, 4, list, ref, mx, my);
324
1.65M
}
h264_cavlc.c:pred_16x8_motion
Line
Count
Source
295
443k
{
296
443k
    if (n == 0) {
297
224k
        const int top_ref      = sl->ref_cache[list][scan8[0] - 8];
298
224k
        const int16_t *const B = sl->mv_cache[list][scan8[0] - 8];
299
300
224k
        ff_tlog(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
301
224k
                top_ref, B[0], B[1], sl->mb_x, sl->mb_y, n, list);
302
303
224k
        if (top_ref == ref) {
304
111k
            *mx = B[0];
305
111k
            *my = B[1];
306
111k
            return;
307
111k
        }
308
224k
    } else {
309
219k
        const int left_ref     = sl->ref_cache[list][scan8[8] - 1];
310
219k
        const int16_t *const A = sl->mv_cache[list][scan8[8] - 1];
311
312
219k
        ff_tlog(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
313
219k
                left_ref, A[0], A[1], sl->mb_x, sl->mb_y, n, list);
314
315
219k
        if (left_ref == ref) {
316
118k
            *mx = A[0];
317
118k
            *my = A[1];
318
118k
            return;
319
118k
        }
320
219k
    }
321
322
    //RARE
323
214k
    pred_motion(h, sl, n, 4, list, ref, mx, my);
324
214k
}
h264_cabac.c:pred_16x8_motion
Line
Count
Source
295
3.11M
{
296
3.11M
    if (n == 0) {
297
1.42M
        const int top_ref      = sl->ref_cache[list][scan8[0] - 8];
298
1.42M
        const int16_t *const B = sl->mv_cache[list][scan8[0] - 8];
299
300
1.42M
        ff_tlog(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
301
1.42M
                top_ref, B[0], B[1], sl->mb_x, sl->mb_y, n, list);
302
303
1.42M
        if (top_ref == ref) {
304
654k
            *mx = B[0];
305
654k
            *my = B[1];
306
654k
            return;
307
654k
        }
308
1.69M
    } else {
309
1.69M
        const int left_ref     = sl->ref_cache[list][scan8[8] - 1];
310
1.69M
        const int16_t *const A = sl->mv_cache[list][scan8[8] - 1];
311
312
1.69M
        ff_tlog(h->avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n",
313
1.69M
                left_ref, A[0], A[1], sl->mb_x, sl->mb_y, n, list);
314
315
1.69M
        if (left_ref == ref) {
316
1.02M
            *mx = A[0];
317
1.02M
            *my = A[1];
318
1.02M
            return;
319
1.02M
        }
320
1.69M
    }
321
322
    //RARE
323
1.43M
    pred_motion(h, sl, n, 4, list, ref, mx, my);
324
1.43M
}
325
326
/**
327
 * Get the directionally predicted 8x16 MV.
328
 * @param n the block index
329
 * @param mx the x component of the predicted motion vector
330
 * @param my the y component of the predicted motion vector
331
 */
332
static av_always_inline void pred_8x16_motion(const H264Context *const h,
333
                                              H264SliceContext *sl,
334
                                              int n, int list, int ref,
335
                                              int *const mx, int *const my)
336
2.90M
{
337
2.90M
    if (n == 0) {
338
1.46M
        const int left_ref     = sl->ref_cache[list][scan8[0] - 1];
339
1.46M
        const int16_t *const A = sl->mv_cache[list][scan8[0] - 1];
340
341
1.46M
        ff_tlog(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
342
1.46M
                left_ref, A[0], A[1], sl->mb_x, sl->mb_y, n, list);
343
344
1.46M
        if (left_ref == ref) {
345
724k
            *mx = A[0];
346
724k
            *my = A[1];
347
724k
            return;
348
724k
        }
349
1.46M
    } else {
350
1.43M
        const int16_t *C;
351
1.43M
        int diagonal_ref;
352
353
1.43M
        diagonal_ref = fetch_diagonal_mv(h, sl, &C, scan8[4], list, 2);
354
355
1.43M
        ff_tlog(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
356
1.43M
                diagonal_ref, C[0], C[1], sl->mb_x, sl->mb_y, n, list);
357
358
1.43M
        if (diagonal_ref == ref) {
359
525k
            *mx = C[0];
360
525k
            *my = C[1];
361
525k
            return;
362
525k
        }
363
1.43M
    }
364
365
    //RARE
366
1.65M
    pred_motion(h, sl, n, 2, list, ref, mx, my);
367
1.65M
}
h264_cavlc.c:pred_8x16_motion
Line
Count
Source
336
442k
{
337
442k
    if (n == 0) {
338
220k
        const int left_ref     = sl->ref_cache[list][scan8[0] - 1];
339
220k
        const int16_t *const A = sl->mv_cache[list][scan8[0] - 1];
340
341
220k
        ff_tlog(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
342
220k
                left_ref, A[0], A[1], sl->mb_x, sl->mb_y, n, list);
343
344
220k
        if (left_ref == ref) {
345
129k
            *mx = A[0];
346
129k
            *my = A[1];
347
129k
            return;
348
129k
        }
349
221k
    } else {
350
221k
        const int16_t *C;
351
221k
        int diagonal_ref;
352
353
221k
        diagonal_ref = fetch_diagonal_mv(h, sl, &C, scan8[4], list, 2);
354
355
221k
        ff_tlog(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
356
221k
                diagonal_ref, C[0], C[1], sl->mb_x, sl->mb_y, n, list);
357
358
221k
        if (diagonal_ref == ref) {
359
119k
            *mx = C[0];
360
119k
            *my = C[1];
361
119k
            return;
362
119k
        }
363
221k
    }
364
365
    //RARE
366
193k
    pred_motion(h, sl, n, 2, list, ref, mx, my);
367
193k
}
h264_cabac.c:pred_8x16_motion
Line
Count
Source
336
2.46M
{
337
2.46M
    if (n == 0) {
338
1.24M
        const int left_ref     = sl->ref_cache[list][scan8[0] - 1];
339
1.24M
        const int16_t *const A = sl->mv_cache[list][scan8[0] - 1];
340
341
1.24M
        ff_tlog(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
342
1.24M
                left_ref, A[0], A[1], sl->mb_x, sl->mb_y, n, list);
343
344
1.24M
        if (left_ref == ref) {
345
594k
            *mx = A[0];
346
594k
            *my = A[1];
347
594k
            return;
348
594k
        }
349
1.24M
    } else {
350
1.21M
        const int16_t *C;
351
1.21M
        int diagonal_ref;
352
353
1.21M
        diagonal_ref = fetch_diagonal_mv(h, sl, &C, scan8[4], list, 2);
354
355
1.21M
        ff_tlog(h->avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n",
356
1.21M
                diagonal_ref, C[0], C[1], sl->mb_x, sl->mb_y, n, list);
357
358
1.21M
        if (diagonal_ref == ref) {
359
405k
            *mx = C[0];
360
405k
            *my = C[1];
361
405k
            return;
362
405k
        }
363
1.21M
    }
364
365
    //RARE
366
1.45M
    pred_motion(h, sl, n, 2, list, ref, mx, my);
367
1.45M
}
368
369
#define FIX_MV_MBAFF(type, refn, mvn, idx)      \
370
9.01M
    if (FRAME_MBAFF(h)) {                       \
371
5.18M
        if (MB_FIELD(sl)) {                     \
372
1.99M
            if (!IS_INTERLACED(type)) {         \
373
193k
                refn <<= 1;                     \
374
193k
                AV_COPY32(mvbuf[idx], mvn);     \
375
193k
                mvbuf[idx][1] /= 2;             \
376
193k
                mvn = mvbuf[idx];               \
377
193k
            }                                   \
378
3.19M
        } else {                                \
379
3.19M
            if (IS_INTERLACED(type)) {          \
380
108k
                refn >>= 1;                     \
381
108k
                AV_COPY32(mvbuf[idx], mvn);     \
382
108k
                mvbuf[idx][1] *= 2;             \
383
108k
                mvn = mvbuf[idx];               \
384
108k
            }                                   \
385
3.19M
        }                                       \
386
5.18M
    }
387
388
static av_always_inline void pred_pskip_motion(const H264Context *const h,
389
                                               H264SliceContext *sl)
390
9.48M
{
391
9.48M
    DECLARE_ALIGNED(4, static const int16_t, zeromv)[2] = { 0 };
392
9.48M
    DECLARE_ALIGNED(4, int16_t, mvbuf)[3][2];
393
9.48M
    int8_t *ref     = h->cur_pic.ref_index[0];
394
9.48M
    int16_t(*mv)[2] = h->cur_pic.motion_val[0];
395
9.48M
    int top_ref, left_ref, diagonal_ref, match_count, mx, my;
396
9.48M
    const int16_t *A, *B, *C;
397
9.48M
    int b_stride = h->b_stride;
398
399
9.48M
    fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1);
400
401
    /* To avoid doing an entire fill_decode_caches, we inline the relevant
402
     * parts here.
403
     * FIXME: this is a partial duplicate of the logic in fill_decode_caches,
404
     * but it's faster this way.  Is there a way to avoid this duplication?
405
     */
406
9.48M
    if (USES_LIST(sl->left_type[LTOP], 0)) {
407
8.09M
        left_ref = ref[4 * sl->left_mb_xy[LTOP] + 1 + (sl->left_block[0] & ~1)];
408
8.09M
        A = mv[h->mb2b_xy[sl->left_mb_xy[LTOP]] + 3 + b_stride * sl->left_block[0]];
409
8.09M
        FIX_MV_MBAFF(sl->left_type[LTOP], left_ref, A, 0);
410
8.09M
        if (!(left_ref | AV_RN32A(A)))
411
7.26M
            goto zeromv;
412
8.09M
    } else if (sl->left_type[LTOP]) {
413
101k
        left_ref = LIST_NOT_USED;
414
101k
        A        = zeromv;
415
1.29M
    } else {
416
1.29M
        goto zeromv;
417
1.29M
    }
418
419
930k
    if (USES_LIST(sl->top_type, 0)) {
420
649k
        top_ref = ref[4 * sl->top_mb_xy + 2];
421
649k
        B       = mv[h->mb2b_xy[sl->top_mb_xy] + 3 * b_stride];
422
649k
        FIX_MV_MBAFF(sl->top_type, top_ref, B, 1);
423
649k
        if (!(top_ref | AV_RN32A(B)))
424
377k
            goto zeromv;
425
649k
    } else if (sl->top_type) {
426
30.2k
        top_ref = LIST_NOT_USED;
427
30.2k
        B       = zeromv;
428
250k
    } else {
429
250k
        goto zeromv;
430
250k
    }
431
432
302k
    ff_tlog(h->avctx, "pred_pskip: (%d) (%d) at %2d %2d\n",
433
302k
            top_ref, left_ref, sl->mb_x, sl->mb_y);
434
435
302k
    if (USES_LIST(sl->topright_type, 0)) {
436
229k
        diagonal_ref = ref[4 * sl->topright_mb_xy + 2];
437
229k
        C = mv[h->mb2b_xy[sl->topright_mb_xy] + 3 * b_stride];
438
229k
        FIX_MV_MBAFF(sl->topright_type, diagonal_ref, C, 2);
439
229k
    } else if (sl->topright_type) {
440
18.9k
        diagonal_ref = LIST_NOT_USED;
441
18.9k
        C = zeromv;
442
53.9k
    } else {
443
53.9k
        if (USES_LIST(sl->topleft_type, 0)) {
444
48.4k
            diagonal_ref = ref[4 * sl->topleft_mb_xy + 1 +
445
48.4k
                               (sl->topleft_partition & 2)];
446
48.4k
            C = mv[h->mb2b_xy[sl->topleft_mb_xy] + 3 + b_stride +
447
48.4k
                   (sl->topleft_partition & 2 * b_stride)];
448
48.4k
            FIX_MV_MBAFF(sl->topleft_type, diagonal_ref, C, 2);
449
48.4k
        } else if (sl->topleft_type) {
450
5.47k
            diagonal_ref = LIST_NOT_USED;
451
5.47k
            C            = zeromv;
452
5.47k
        } else {
453
19
            diagonal_ref = PART_NOT_AVAILABLE;
454
19
            C            = zeromv;
455
19
        }
456
53.9k
    }
457
458
302k
    match_count = !diagonal_ref + !top_ref + !left_ref;
459
302k
    ff_tlog(h->avctx, "pred_pskip_motion match_count=%d\n", match_count);
460
302k
    if (match_count > 1) {
461
230k
        mx = mid_pred(A[0], B[0], C[0]);
462
230k
        my = mid_pred(A[1], B[1], C[1]);
463
230k
    } else if (match_count == 1) {
464
49.8k
        if (!left_ref) {
465
17.1k
            mx = A[0];
466
17.1k
            my = A[1];
467
32.6k
        } else if (!top_ref) {
468
10.1k
            mx = B[0];
469
10.1k
            my = B[1];
470
22.4k
        } else {
471
22.4k
            mx = C[0];
472
22.4k
            my = C[1];
473
22.4k
        }
474
49.8k
    } else {
475
21.8k
        mx = mid_pred(A[0], B[0], C[0]);
476
21.8k
        my = mid_pred(A[1], B[1], C[1]);
477
21.8k
    }
478
479
302k
    fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx, my), 4);
480
302k
    return;
481
482
9.18M
zeromv:
483
9.18M
    fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
484
9.18M
    return;
485
930k
}
h264_cavlc.c:pred_pskip_motion
Line
Count
Source
390
3.80M
{
391
3.80M
    DECLARE_ALIGNED(4, static const int16_t, zeromv)[2] = { 0 };
392
3.80M
    DECLARE_ALIGNED(4, int16_t, mvbuf)[3][2];
393
3.80M
    int8_t *ref     = h->cur_pic.ref_index[0];
394
3.80M
    int16_t(*mv)[2] = h->cur_pic.motion_val[0];
395
3.80M
    int top_ref, left_ref, diagonal_ref, match_count, mx, my;
396
3.80M
    const int16_t *A, *B, *C;
397
3.80M
    int b_stride = h->b_stride;
398
399
3.80M
    fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1);
400
401
    /* To avoid doing an entire fill_decode_caches, we inline the relevant
402
     * parts here.
403
     * FIXME: this is a partial duplicate of the logic in fill_decode_caches,
404
     * but it's faster this way.  Is there a way to avoid this duplication?
405
     */
406
3.80M
    if (USES_LIST(sl->left_type[LTOP], 0)) {
407
3.18M
        left_ref = ref[4 * sl->left_mb_xy[LTOP] + 1 + (sl->left_block[0] & ~1)];
408
3.18M
        A = mv[h->mb2b_xy[sl->left_mb_xy[LTOP]] + 3 + b_stride * sl->left_block[0]];
409
3.18M
        FIX_MV_MBAFF(sl->left_type[LTOP], left_ref, A, 0);
410
3.18M
        if (!(left_ref | AV_RN32A(A)))
411
2.90M
            goto zeromv;
412
3.18M
    } else if (sl->left_type[LTOP]) {
413
36.3k
        left_ref = LIST_NOT_USED;
414
36.3k
        A        = zeromv;
415
581k
    } else {
416
581k
        goto zeromv;
417
581k
    }
418
419
314k
    if (USES_LIST(sl->top_type, 0)) {
420
185k
        top_ref = ref[4 * sl->top_mb_xy + 2];
421
185k
        B       = mv[h->mb2b_xy[sl->top_mb_xy] + 3 * b_stride];
422
185k
        FIX_MV_MBAFF(sl->top_type, top_ref, B, 1);
423
185k
        if (!(top_ref | AV_RN32A(B)))
424
99.8k
            goto zeromv;
425
185k
    } else if (sl->top_type) {
426
6.10k
        top_ref = LIST_NOT_USED;
427
6.10k
        B       = zeromv;
428
122k
    } else {
429
122k
        goto zeromv;
430
122k
    }
431
432
92.1k
    ff_tlog(h->avctx, "pred_pskip: (%d) (%d) at %2d %2d\n",
433
92.1k
            top_ref, left_ref, sl->mb_x, sl->mb_y);
434
435
92.1k
    if (USES_LIST(sl->topright_type, 0)) {
436
77.3k
        diagonal_ref = ref[4 * sl->topright_mb_xy + 2];
437
77.3k
        C = mv[h->mb2b_xy[sl->topright_mb_xy] + 3 * b_stride];
438
77.3k
        FIX_MV_MBAFF(sl->topright_type, diagonal_ref, C, 2);
439
77.3k
    } else if (sl->topright_type) {
440
796
        diagonal_ref = LIST_NOT_USED;
441
796
        C = zeromv;
442
14.0k
    } else {
443
14.0k
        if (USES_LIST(sl->topleft_type, 0)) {
444
12.8k
            diagonal_ref = ref[4 * sl->topleft_mb_xy + 1 +
445
12.8k
                               (sl->topleft_partition & 2)];
446
12.8k
            C = mv[h->mb2b_xy[sl->topleft_mb_xy] + 3 + b_stride +
447
12.8k
                   (sl->topleft_partition & 2 * b_stride)];
448
12.8k
            FIX_MV_MBAFF(sl->topleft_type, diagonal_ref, C, 2);
449
12.8k
        } else if (sl->topleft_type) {
450
1.20k
            diagonal_ref = LIST_NOT_USED;
451
1.20k
            C            = zeromv;
452
1.20k
        } else {
453
3
            diagonal_ref = PART_NOT_AVAILABLE;
454
3
            C            = zeromv;
455
3
        }
456
14.0k
    }
457
458
92.1k
    match_count = !diagonal_ref + !top_ref + !left_ref;
459
92.1k
    ff_tlog(h->avctx, "pred_pskip_motion match_count=%d\n", match_count);
460
92.1k
    if (match_count > 1) {
461
78.4k
        mx = mid_pred(A[0], B[0], C[0]);
462
78.4k
        my = mid_pred(A[1], B[1], C[1]);
463
78.4k
    } else if (match_count == 1) {
464
11.6k
        if (!left_ref) {
465
3.83k
            mx = A[0];
466
3.83k
            my = A[1];
467
7.80k
        } else if (!top_ref) {
468
1.82k
            mx = B[0];
469
1.82k
            my = B[1];
470
5.97k
        } else {
471
5.97k
            mx = C[0];
472
5.97k
            my = C[1];
473
5.97k
        }
474
11.6k
    } else {
475
2.14k
        mx = mid_pred(A[0], B[0], C[0]);
476
2.14k
        my = mid_pred(A[1], B[1], C[1]);
477
2.14k
    }
478
479
92.1k
    fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx, my), 4);
480
92.1k
    return;
481
482
3.71M
zeromv:
483
3.71M
    fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
484
3.71M
    return;
485
314k
}
h264_cabac.c:pred_pskip_motion
Line
Count
Source
390
5.68M
{
391
5.68M
    DECLARE_ALIGNED(4, static const int16_t, zeromv)[2] = { 0 };
392
5.68M
    DECLARE_ALIGNED(4, int16_t, mvbuf)[3][2];
393
5.68M
    int8_t *ref     = h->cur_pic.ref_index[0];
394
5.68M
    int16_t(*mv)[2] = h->cur_pic.motion_val[0];
395
5.68M
    int top_ref, left_ref, diagonal_ref, match_count, mx, my;
396
5.68M
    const int16_t *A, *B, *C;
397
5.68M
    int b_stride = h->b_stride;
398
399
5.68M
    fill_rectangle(&sl->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1);
400
401
    /* To avoid doing an entire fill_decode_caches, we inline the relevant
402
     * parts here.
403
     * FIXME: this is a partial duplicate of the logic in fill_decode_caches,
404
     * but it's faster this way.  Is there a way to avoid this duplication?
405
     */
406
5.68M
    if (USES_LIST(sl->left_type[LTOP], 0)) {
407
4.90M
        left_ref = ref[4 * sl->left_mb_xy[LTOP] + 1 + (sl->left_block[0] & ~1)];
408
4.90M
        A = mv[h->mb2b_xy[sl->left_mb_xy[LTOP]] + 3 + b_stride * sl->left_block[0]];
409
4.90M
        FIX_MV_MBAFF(sl->left_type[LTOP], left_ref, A, 0);
410
4.90M
        if (!(left_ref | AV_RN32A(A)))
411
4.35M
            goto zeromv;
412
4.90M
    } else if (sl->left_type[LTOP]) {
413
65.5k
        left_ref = LIST_NOT_USED;
414
65.5k
        A        = zeromv;
415
709k
    } else {
416
709k
        goto zeromv;
417
709k
    }
418
419
616k
    if (USES_LIST(sl->top_type, 0)) {
420
463k
        top_ref = ref[4 * sl->top_mb_xy + 2];
421
463k
        B       = mv[h->mb2b_xy[sl->top_mb_xy] + 3 * b_stride];
422
463k
        FIX_MV_MBAFF(sl->top_type, top_ref, B, 1);
423
463k
        if (!(top_ref | AV_RN32A(B)))
424
277k
            goto zeromv;
425
463k
    } else if (sl->top_type) {
426
24.1k
        top_ref = LIST_NOT_USED;
427
24.1k
        B       = zeromv;
428
128k
    } else {
429
128k
        goto zeromv;
430
128k
    }
431
432
210k
    ff_tlog(h->avctx, "pred_pskip: (%d) (%d) at %2d %2d\n",
433
210k
            top_ref, left_ref, sl->mb_x, sl->mb_y);
434
435
210k
    if (USES_LIST(sl->topright_type, 0)) {
436
152k
        diagonal_ref = ref[4 * sl->topright_mb_xy + 2];
437
152k
        C = mv[h->mb2b_xy[sl->topright_mb_xy] + 3 * b_stride];
438
152k
        FIX_MV_MBAFF(sl->topright_type, diagonal_ref, C, 2);
439
152k
    } else if (sl->topright_type) {
440
18.2k
        diagonal_ref = LIST_NOT_USED;
441
18.2k
        C = zeromv;
442
39.9k
    } else {
443
39.9k
        if (USES_LIST(sl->topleft_type, 0)) {
444
35.6k
            diagonal_ref = ref[4 * sl->topleft_mb_xy + 1 +
445
35.6k
                               (sl->topleft_partition & 2)];
446
35.6k
            C = mv[h->mb2b_xy[sl->topleft_mb_xy] + 3 + b_stride +
447
35.6k
                   (sl->topleft_partition & 2 * b_stride)];
448
35.6k
            FIX_MV_MBAFF(sl->topleft_type, diagonal_ref, C, 2);
449
35.6k
        } else if (sl->topleft_type) {
450
4.27k
            diagonal_ref = LIST_NOT_USED;
451
4.27k
            C            = zeromv;
452
4.27k
        } else {
453
16
            diagonal_ref = PART_NOT_AVAILABLE;
454
16
            C            = zeromv;
455
16
        }
456
39.9k
    }
457
458
210k
    match_count = !diagonal_ref + !top_ref + !left_ref;
459
210k
    ff_tlog(h->avctx, "pred_pskip_motion match_count=%d\n", match_count);
460
210k
    if (match_count > 1) {
461
152k
        mx = mid_pred(A[0], B[0], C[0]);
462
152k
        my = mid_pred(A[1], B[1], C[1]);
463
152k
    } else if (match_count == 1) {
464
38.1k
        if (!left_ref) {
465
13.3k
            mx = A[0];
466
13.3k
            my = A[1];
467
24.8k
        } else if (!top_ref) {
468
8.34k
            mx = B[0];
469
8.34k
            my = B[1];
470
16.4k
        } else {
471
16.4k
            mx = C[0];
472
16.4k
            my = C[1];
473
16.4k
        }
474
38.1k
    } else {
475
19.7k
        mx = mid_pred(A[0], B[0], C[0]);
476
19.7k
        my = mid_pred(A[1], B[1], C[1]);
477
19.7k
    }
478
479
210k
    fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx, my), 4);
480
210k
    return;
481
482
5.47M
zeromv:
483
5.47M
    fill_rectangle(sl->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4);
484
5.47M
    return;
485
616k
}
486
487
static void fill_decode_neighbors(const H264Context *h, H264SliceContext *sl, int mb_type)
488
35.0M
{
489
35.0M
    const int mb_xy = sl->mb_xy;
490
35.0M
    int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
491
35.0M
    static const uint8_t left_block_options[4][32] = {
492
35.0M
        { 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 },
493
35.0M
        { 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 },
494
35.0M
        { 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 },
495
35.0M
        { 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 }
496
35.0M
    };
497
498
35.0M
    sl->topleft_partition = -1;
499
500
35.0M
    top_xy = mb_xy - (h->mb_stride << MB_FIELD(sl));
501
502
    /* Wow, what a mess, why didn't they simplify the interlacing & intra
503
     * stuff, I can't imagine that these complex rules are worth it. */
504
505
35.0M
    topleft_xy    = top_xy - 1;
506
35.0M
    topright_xy   = top_xy + 1;
507
35.0M
    left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1;
508
35.0M
    sl->left_block = left_block_options[0];
509
35.0M
    if (FRAME_MBAFF(h)) {
510
16.7M
        const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]);
511
16.7M
        const int curr_mb_field_flag = IS_INTERLACED(mb_type);
512
16.7M
        if (sl->mb_y & 1) {
513
8.26M
            if (left_mb_field_flag != curr_mb_field_flag) {
514
1.11M
                left_xy[LBOT] = left_xy[LTOP] = mb_xy - h->mb_stride - 1;
515
1.11M
                if (curr_mb_field_flag) {
516
751k
                    left_xy[LBOT] += h->mb_stride;
517
751k
                    sl->left_block  = left_block_options[3];
518
751k
                } else {
519
361k
                    topleft_xy += h->mb_stride;
520
                    /* take top left mv from the middle of the mb, as opposed
521
                     * to all other modes which use the bottom right partition */
522
361k
                    sl->topleft_partition = 0;
523
361k
                    sl->left_block        = left_block_options[1];
524
361k
                }
525
1.11M
            }
526
8.51M
        } else {
527
8.51M
            if (curr_mb_field_flag) {
528
2.87M
                topleft_xy  += h->mb_stride & (((h->cur_pic.mb_type[top_xy - 1] >> 7) & 1) - 1);
529
2.87M
                topright_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy + 1] >> 7) & 1) - 1);
530
2.87M
                top_xy      += h->mb_stride & (((h->cur_pic.mb_type[top_xy]     >> 7) & 1) - 1);
531
2.87M
            }
532
8.51M
            if (left_mb_field_flag != curr_mb_field_flag) {
533
1.15M
                if (curr_mb_field_flag) {
534
773k
                    left_xy[LBOT] += h->mb_stride;
535
773k
                    sl->left_block  = left_block_options[3];
536
773k
                } else {
537
385k
                    sl->left_block = left_block_options[2];
538
385k
                }
539
1.15M
            }
540
8.51M
        }
541
16.7M
    }
542
543
35.0M
    sl->topleft_mb_xy    = topleft_xy;
544
35.0M
    sl->top_mb_xy        = top_xy;
545
35.0M
    sl->topright_mb_xy   = topright_xy;
546
35.0M
    sl->left_mb_xy[LTOP] = left_xy[LTOP];
547
35.0M
    sl->left_mb_xy[LBOT] = left_xy[LBOT];
548
    //FIXME do we need all in the context?
549
550
35.0M
    sl->topleft_type    = h->cur_pic.mb_type[topleft_xy];
551
35.0M
    sl->top_type        = h->cur_pic.mb_type[top_xy];
552
35.0M
    sl->topright_type   = h->cur_pic.mb_type[topright_xy];
553
35.0M
    sl->left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]];
554
35.0M
    sl->left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]];
555
556
35.0M
    if (FMO) {
557
0
        if (h->slice_table[topleft_xy] != sl->slice_num)
558
0
            sl->topleft_type = 0;
559
0
        if (h->slice_table[top_xy] != sl->slice_num)
560
0
            sl->top_type = 0;
561
0
        if (h->slice_table[left_xy[LTOP]] != sl->slice_num)
562
0
            sl->left_type[LTOP] = sl->left_type[LBOT] = 0;
563
35.0M
    } else {
564
35.0M
        if (h->slice_table[topleft_xy] != sl->slice_num) {
565
14.7M
            sl->topleft_type = 0;
566
14.7M
            if (h->slice_table[top_xy] != sl->slice_num)
567
11.3M
                sl->top_type = 0;
568
14.7M
            if (h->slice_table[left_xy[LTOP]] != sl->slice_num)
569
5.42M
                sl->left_type[LTOP] = sl->left_type[LBOT] = 0;
570
14.7M
        }
571
35.0M
    }
572
35.0M
    if (h->slice_table[topright_xy] != sl->slice_num)
573
18.6M
        sl->topright_type = 0;
574
35.0M
}
h264_cavlc.c:fill_decode_neighbors
Line
Count
Source
488
6.79M
{
489
6.79M
    const int mb_xy = sl->mb_xy;
490
6.79M
    int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
491
6.79M
    static const uint8_t left_block_options[4][32] = {
492
6.79M
        { 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 },
493
6.79M
        { 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 },
494
6.79M
        { 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 },
495
6.79M
        { 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 }
496
6.79M
    };
497
498
6.79M
    sl->topleft_partition = -1;
499
500
6.79M
    top_xy = mb_xy - (h->mb_stride << MB_FIELD(sl));
501
502
    /* Wow, what a mess, why didn't they simplify the interlacing & intra
503
     * stuff, I can't imagine that these complex rules are worth it. */
504
505
6.79M
    topleft_xy    = top_xy - 1;
506
6.79M
    topright_xy   = top_xy + 1;
507
6.79M
    left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1;
508
6.79M
    sl->left_block = left_block_options[0];
509
6.79M
    if (FRAME_MBAFF(h)) {
510
3.20M
        const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]);
511
3.20M
        const int curr_mb_field_flag = IS_INTERLACED(mb_type);
512
3.20M
        if (sl->mb_y & 1) {
513
1.56M
            if (left_mb_field_flag != curr_mb_field_flag) {
514
274k
                left_xy[LBOT] = left_xy[LTOP] = mb_xy - h->mb_stride - 1;
515
274k
                if (curr_mb_field_flag) {
516
202k
                    left_xy[LBOT] += h->mb_stride;
517
202k
                    sl->left_block  = left_block_options[3];
518
202k
                } else {
519
71.6k
                    topleft_xy += h->mb_stride;
520
                    /* take top left mv from the middle of the mb, as opposed
521
                     * to all other modes which use the bottom right partition */
522
71.6k
                    sl->topleft_partition = 0;
523
71.6k
                    sl->left_block        = left_block_options[1];
524
71.6k
                }
525
274k
            }
526
1.64M
        } else {
527
1.64M
            if (curr_mb_field_flag) {
528
1.03M
                topleft_xy  += h->mb_stride & (((h->cur_pic.mb_type[top_xy - 1] >> 7) & 1) - 1);
529
1.03M
                topright_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy + 1] >> 7) & 1) - 1);
530
1.03M
                top_xy      += h->mb_stride & (((h->cur_pic.mb_type[top_xy]     >> 7) & 1) - 1);
531
1.03M
            }
532
1.64M
            if (left_mb_field_flag != curr_mb_field_flag) {
533
310k
                if (curr_mb_field_flag) {
534
216k
                    left_xy[LBOT] += h->mb_stride;
535
216k
                    sl->left_block  = left_block_options[3];
536
216k
                } else {
537
93.8k
                    sl->left_block = left_block_options[2];
538
93.8k
                }
539
310k
            }
540
1.64M
        }
541
3.20M
    }
542
543
6.79M
    sl->topleft_mb_xy    = topleft_xy;
544
6.79M
    sl->top_mb_xy        = top_xy;
545
6.79M
    sl->topright_mb_xy   = topright_xy;
546
6.79M
    sl->left_mb_xy[LTOP] = left_xy[LTOP];
547
6.79M
    sl->left_mb_xy[LBOT] = left_xy[LBOT];
548
    //FIXME do we need all in the context?
549
550
6.79M
    sl->topleft_type    = h->cur_pic.mb_type[topleft_xy];
551
6.79M
    sl->top_type        = h->cur_pic.mb_type[top_xy];
552
6.79M
    sl->topright_type   = h->cur_pic.mb_type[topright_xy];
553
6.79M
    sl->left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]];
554
6.79M
    sl->left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]];
555
556
6.79M
    if (FMO) {
557
0
        if (h->slice_table[topleft_xy] != sl->slice_num)
558
0
            sl->topleft_type = 0;
559
0
        if (h->slice_table[top_xy] != sl->slice_num)
560
0
            sl->top_type = 0;
561
0
        if (h->slice_table[left_xy[LTOP]] != sl->slice_num)
562
0
            sl->left_type[LTOP] = sl->left_type[LBOT] = 0;
563
6.79M
    } else {
564
6.79M
        if (h->slice_table[topleft_xy] != sl->slice_num) {
565
3.69M
            sl->topleft_type = 0;
566
3.69M
            if (h->slice_table[top_xy] != sl->slice_num)
567
3.08M
                sl->top_type = 0;
568
3.69M
            if (h->slice_table[left_xy[LTOP]] != sl->slice_num)
569
1.33M
                sl->left_type[LTOP] = sl->left_type[LBOT] = 0;
570
3.69M
        }
571
6.79M
    }
572
6.79M
    if (h->slice_table[topright_xy] != sl->slice_num)
573
3.92M
        sl->topright_type = 0;
574
6.79M
}
h264_cabac.c:fill_decode_neighbors
Line
Count
Source
488
28.3M
{
489
28.3M
    const int mb_xy = sl->mb_xy;
490
28.3M
    int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
491
28.3M
    static const uint8_t left_block_options[4][32] = {
492
28.3M
        { 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 },
493
28.3M
        { 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 },
494
28.3M
        { 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 },
495
28.3M
        { 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 }
496
28.3M
    };
497
498
28.3M
    sl->topleft_partition = -1;
499
500
28.3M
    top_xy = mb_xy - (h->mb_stride << MB_FIELD(sl));
501
502
    /* Wow, what a mess, why didn't they simplify the interlacing & intra
503
     * stuff, I can't imagine that these complex rules are worth it. */
504
505
28.3M
    topleft_xy    = top_xy - 1;
506
28.3M
    topright_xy   = top_xy + 1;
507
28.3M
    left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1;
508
28.3M
    sl->left_block = left_block_options[0];
509
28.3M
    if (FRAME_MBAFF(h)) {
510
13.5M
        const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]);
511
13.5M
        const int curr_mb_field_flag = IS_INTERLACED(mb_type);
512
13.5M
        if (sl->mb_y & 1) {
513
6.69M
            if (left_mb_field_flag != curr_mb_field_flag) {
514
838k
                left_xy[LBOT] = left_xy[LTOP] = mb_xy - h->mb_stride - 1;
515
838k
                if (curr_mb_field_flag) {
516
548k
                    left_xy[LBOT] += h->mb_stride;
517
548k
                    sl->left_block  = left_block_options[3];
518
548k
                } else {
519
290k
                    topleft_xy += h->mb_stride;
520
                    /* take top left mv from the middle of the mb, as opposed
521
                     * to all other modes which use the bottom right partition */
522
290k
                    sl->topleft_partition = 0;
523
290k
                    sl->left_block        = left_block_options[1];
524
290k
                }
525
838k
            }
526
6.87M
        } else {
527
6.87M
            if (curr_mb_field_flag) {
528
1.83M
                topleft_xy  += h->mb_stride & (((h->cur_pic.mb_type[top_xy - 1] >> 7) & 1) - 1);
529
1.83M
                topright_xy += h->mb_stride & (((h->cur_pic.mb_type[top_xy + 1] >> 7) & 1) - 1);
530
1.83M
                top_xy      += h->mb_stride & (((h->cur_pic.mb_type[top_xy]     >> 7) & 1) - 1);
531
1.83M
            }
532
6.87M
            if (left_mb_field_flag != curr_mb_field_flag) {
533
849k
                if (curr_mb_field_flag) {
534
556k
                    left_xy[LBOT] += h->mb_stride;
535
556k
                    sl->left_block  = left_block_options[3];
536
556k
                } else {
537
292k
                    sl->left_block = left_block_options[2];
538
292k
                }
539
849k
            }
540
6.87M
        }
541
13.5M
    }
542
543
28.3M
    sl->topleft_mb_xy    = topleft_xy;
544
28.3M
    sl->top_mb_xy        = top_xy;
545
28.3M
    sl->topright_mb_xy   = topright_xy;
546
28.3M
    sl->left_mb_xy[LTOP] = left_xy[LTOP];
547
28.3M
    sl->left_mb_xy[LBOT] = left_xy[LBOT];
548
    //FIXME do we need all in the context?
549
550
28.3M
    sl->topleft_type    = h->cur_pic.mb_type[topleft_xy];
551
28.3M
    sl->top_type        = h->cur_pic.mb_type[top_xy];
552
28.3M
    sl->topright_type   = h->cur_pic.mb_type[topright_xy];
553
28.3M
    sl->left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]];
554
28.3M
    sl->left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]];
555
556
28.3M
    if (FMO) {
557
0
        if (h->slice_table[topleft_xy] != sl->slice_num)
558
0
            sl->topleft_type = 0;
559
0
        if (h->slice_table[top_xy] != sl->slice_num)
560
0
            sl->top_type = 0;
561
0
        if (h->slice_table[left_xy[LTOP]] != sl->slice_num)
562
0
            sl->left_type[LTOP] = sl->left_type[LBOT] = 0;
563
28.3M
    } else {
564
28.3M
        if (h->slice_table[topleft_xy] != sl->slice_num) {
565
11.0M
            sl->topleft_type = 0;
566
11.0M
            if (h->slice_table[top_xy] != sl->slice_num)
567
8.26M
                sl->top_type = 0;
568
11.0M
            if (h->slice_table[left_xy[LTOP]] != sl->slice_num)
569
4.09M
                sl->left_type[LTOP] = sl->left_type[LBOT] = 0;
570
11.0M
        }
571
28.3M
    }
572
28.3M
    if (h->slice_table[topright_xy] != sl->slice_num)
573
14.7M
        sl->topright_type = 0;
574
28.3M
}
575
576
static void fill_decode_caches(const H264Context *h, H264SliceContext *sl, int mb_type)
577
25.6M
{
578
25.6M
    int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
579
25.6M
    int topleft_type, top_type, topright_type, left_type[LEFT_MBS];
580
25.6M
    const uint8_t *left_block = sl->left_block;
581
25.6M
    int i;
582
25.6M
    uint8_t *nnz;
583
25.6M
    uint8_t *nnz_cache;
584
585
25.6M
    topleft_xy      = sl->topleft_mb_xy;
586
25.6M
    top_xy          = sl->top_mb_xy;
587
25.6M
    topright_xy     = sl->topright_mb_xy;
588
25.6M
    left_xy[LTOP]   = sl->left_mb_xy[LTOP];
589
25.6M
    left_xy[LBOT]   = sl->left_mb_xy[LBOT];
590
25.6M
    topleft_type    = sl->topleft_type;
591
25.6M
    top_type        = sl->top_type;
592
25.6M
    topright_type   = sl->topright_type;
593
25.6M
    left_type[LTOP] = sl->left_type[LTOP];
594
25.6M
    left_type[LBOT] = sl->left_type[LBOT];
595
596
25.6M
    if (!IS_SKIP(mb_type)) {
597
16.9M
        if (IS_INTRA(mb_type)) {
598
4.66M
            int type_mask = h->ps.pps->constrained_intra_pred ? IS_INTRA(-1) : -1;
599
4.66M
            sl->topleft_samples_available     =
600
4.66M
                sl->top_samples_available     =
601
4.66M
                    sl->left_samples_available = 0xFFFF;
602
4.66M
            sl->topright_samples_available     = 0xEEEA;
603
604
4.66M
            if (!(top_type & type_mask)) {
605
1.78M
                sl->topleft_samples_available  = 0xB3FF;
606
1.78M
                sl->top_samples_available      = 0x33FF;
607
1.78M
                sl->topright_samples_available = 0x26EA;
608
1.78M
            }
609
4.66M
            if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) {
610
348k
                if (IS_INTERLACED(mb_type)) {
611
295k
                    if (!(left_type[LTOP] & type_mask)) {
612
221k
                        sl->topleft_samples_available &= 0xDFFF;
613
221k
                        sl->left_samples_available    &= 0x5FFF;
614
221k
                    }
615
295k
                    if (!(left_type[LBOT] & type_mask)) {
616
225k
                        sl->topleft_samples_available &= 0xFF5F;
617
225k
                        sl->left_samples_available    &= 0xFF5F;
618
225k
                    }
619
295k
                } else {
620
53.2k
                    int left_typei = h->cur_pic.mb_type[left_xy[LTOP] + h->mb_stride];
621
622
53.2k
                    av_assert2(left_xy[LTOP] == left_xy[LBOT]);
623
53.2k
                    if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {
624
1.62k
                        sl->topleft_samples_available &= 0xDF5F;
625
1.62k
                        sl->left_samples_available    &= 0x5F5F;
626
1.62k
                    }
627
53.2k
                }
628
4.31M
            } else {
629
4.31M
                if (!(left_type[LTOP] & type_mask)) {
630
1.08M
                    sl->topleft_samples_available &= 0xDF5F;
631
1.08M
                    sl->left_samples_available    &= 0x5F5F;
632
1.08M
                }
633
4.31M
            }
634
635
4.66M
            if (!(topleft_type & type_mask))
636
2.19M
                sl->topleft_samples_available &= 0x7FFF;
637
638
4.66M
            if (!(topright_type & type_mask))
639
2.43M
                sl->topright_samples_available &= 0xFBFF;
640
641
4.66M
            if (IS_INTRA4x4(mb_type)) {
642
2.59M
                if (IS_INTRA4x4(top_type)) {
643
1.08M
                    AV_COPY32(sl->intra4x4_pred_mode_cache + 4 + 8 * 0, sl->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
644
1.50M
                } else {
645
1.50M
                    sl->intra4x4_pred_mode_cache[4 + 8 * 0] =
646
1.50M
                    sl->intra4x4_pred_mode_cache[5 + 8 * 0] =
647
1.50M
                    sl->intra4x4_pred_mode_cache[6 + 8 * 0] =
648
1.50M
                    sl->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask);
649
1.50M
                }
650
7.77M
                for (i = 0; i < 2; i++) {
651
5.18M
                    if (IS_INTRA4x4(left_type[LEFT(i)])) {
652
2.45M
                        int8_t *mode = sl->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];
653
2.45M
                        sl->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]];
654
2.45M
                        sl->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]];
655
2.72M
                    } else {
656
2.72M
                        sl->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] =
657
2.72M
                        sl->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask);
658
2.72M
                    }
659
5.18M
                }
660
2.59M
            }
661
4.66M
        }
662
663
        /*
664
         * 0 . T T. T T T T
665
         * 1 L . .L . . . .
666
         * 2 L . .L . . . .
667
         * 3 . T TL . . . .
668
         * 4 L . .L . . . .
669
         * 5 L . .. . . . .
670
         */
671
        /* 9.2.1: with data partitioning and constrained intra prediction, an
672
         * inter neighbour must not contribute to nC for an intra macroblock.
673
         * Step 7 would drop it from the (nA + nB + 1) >> 1 average entirely,
674
         * but JM's predict_nnz() counts it as present with zero coefficients.
675
         * FF_BUG_H264_DP_NNZ picks JM, and is autodetected in h264dec.c. */
676
16.9M
        int nnz_mask     = -1;
677
16.9M
        int nnz_excluded = 64;      // 64: unavailable, 0: present but empty
678
679
16.9M
        if (sl->data_partitioning && h->ps.pps->constrained_intra_pred &&
680
170
            IS_INTRA(mb_type)) {
681
133
            nnz_mask = IS_INTRA(-1);
682
133
            if (h->workaround_bugs & FF_BUG_H264_DP_NNZ)
683
133
                nnz_excluded = 0;
684
133
        }
685
686
16.9M
        nnz_cache = sl->non_zero_count_cache;
687
16.9M
        if (top_type & nnz_mask) {
688
11.7M
            nnz = h->non_zero_count[top_xy];
689
11.7M
            AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);
690
11.7M
            if (!h->chroma_y_shift) {
691
5.24M
                AV_COPY32(&nnz_cache[4 + 8 *  5], &nnz[4 *  7]);
692
5.24M
                AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);
693
6.51M
            } else {
694
6.51M
                AV_COPY32(&nnz_cache[4 + 8 *  5], &nnz[4 * 5]);
695
6.51M
                AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);
696
6.51M
            }
697
11.7M
        } else {
698
5.15M
            uint32_t top_empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 :
699
5.15M
                                 top_type ? nnz_excluded * 0x01010101u : 0x40404040;
700
5.15M
            AV_WN32A(&nnz_cache[4 + 8 *  0], top_empty);
701
5.15M
            AV_WN32A(&nnz_cache[4 + 8 *  5], top_empty);
702
5.15M
            AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty);
703
5.15M
        }
704
705
50.7M
        for (i = 0; i < 2; i++) {
706
33.8M
            if (left_type[LEFT(i)] & nnz_mask) {
707
28.5M
                nnz = h->non_zero_count[left_xy[LEFT(i)]];
708
28.5M
                nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]];
709
28.5M
                nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]];
710
28.5M
                if (CHROMA444(h)) {
711
1.97M
                    nnz_cache[3 + 8 *  6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];
712
1.97M
                    nnz_cache[3 + 8 *  7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];
713
1.97M
                    nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];
714
1.97M
                    nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];
715
26.5M
                } else if (CHROMA422(h)) {
716
11.0M
                    nnz_cache[3 + 8 *  6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];
717
11.0M
                    nnz_cache[3 + 8 *  7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];
718
11.0M
                    nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];
719
11.0M
                    nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];
720
15.5M
                } else {
721
15.5M
                    nnz_cache[3 + 8 *  6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];
722
15.5M
                    nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];
723
15.5M
                }
724
28.5M
            } else {
725
5.34M
                int empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 :
726
5.34M
                            left_type[LEFT(i)] ? nnz_excluded : 64;
727
5.34M
                nnz_cache[3 + 8 *  1 + 2 * 8 * i] =
728
5.34M
                nnz_cache[3 + 8 *  2 + 2 * 8 * i] =
729
5.34M
                nnz_cache[3 + 8 *  6 + 2 * 8 * i] =
730
5.34M
                nnz_cache[3 + 8 *  7 + 2 * 8 * i] =
731
5.34M
                nnz_cache[3 + 8 * 11 + 2 * 8 * i] =
732
5.34M
                nnz_cache[3 + 8 * 12 + 2 * 8 * i] = empty;
733
5.34M
            }
734
33.8M
        }
735
736
16.9M
        if (CABAC(h)) {
737
            // top_cbp
738
14.2M
            if (top_type)
739
10.2M
                sl->top_cbp = h->cbp_table[top_xy];
740
4.05M
            else
741
4.05M
                sl->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
742
            // left_cbp
743
14.2M
            if (left_type[LTOP]) {
744
12.3M
                sl->left_cbp =   (h->cbp_table[left_xy[LTOP]] & 0x7F0) |
745
12.3M
                               ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |
746
12.3M
                              (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2);
747
12.3M
            } else {
748
1.94M
                sl->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
749
1.94M
            }
750
14.2M
        }
751
16.9M
    }
752
753
25.6M
    if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && sl->direct_spatial_mv_pred)) {
754
20.5M
        int list;
755
20.5M
        int b_stride = h->b_stride;
756
56.0M
        for (list = 0; list < sl->list_count; list++) {
757
35.4M
            int8_t *ref_cache = &sl->ref_cache[list][scan8[0]];
758
35.4M
            int8_t *ref       = h->cur_pic.ref_index[list];
759
35.4M
            int16_t(*mv_cache)[2] = &sl->mv_cache[list][scan8[0]];
760
35.4M
            int16_t(*mv)[2]       = h->cur_pic.motion_val[list];
761
35.4M
            if (!USES_LIST(mb_type, list))
762
3.66M
                continue;
763
31.8M
            av_assert2(!(IS_DIRECT(mb_type) && !sl->direct_spatial_mv_pred));
764
765
31.8M
            if (USES_LIST(top_type, list)) {
766
18.8M
                const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride;
767
18.8M
                AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]);
768
18.8M
                ref_cache[0 - 1 * 8] =
769
18.8M
                ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];
770
18.8M
                ref_cache[2 - 1 * 8] =
771
18.8M
                ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];
772
18.8M
            } else {
773
12.9M
                AV_ZERO128(mv_cache[0 - 1 * 8]);
774
12.9M
                AV_WN32A(&ref_cache[0 - 1 * 8],
775
12.9M
                         ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u);
776
12.9M
            }
777
778
31.8M
            if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) {
779
15.6M
                for (i = 0; i < 2; i++) {
780
10.4M
                    int cache_idx = -1 + i * 2 * 8;
781
10.4M
                    if (USES_LIST(left_type[LEFT(i)], list)) {
782
8.24M
                        const int b_xy  = h->mb2b_xy[left_xy[LEFT(i)]] + 3;
783
8.24M
                        const int b8_xy = 4 * left_xy[LEFT(i)] + 1;
784
8.24M
                        AV_COPY32(mv_cache[cache_idx],
785
8.24M
                                  mv[b_xy + b_stride * left_block[0 + i * 2]]);
786
8.24M
                        AV_COPY32(mv_cache[cache_idx + 8],
787
8.24M
                                  mv[b_xy + b_stride * left_block[1 + i * 2]]);
788
8.24M
                        ref_cache[cache_idx]     = ref[b8_xy + (left_block[0 + i * 2] & ~1)];
789
8.24M
                        ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];
790
8.24M
                    } else {
791
2.16M
                        AV_ZERO32(mv_cache[cache_idx]);
792
2.16M
                        AV_ZERO32(mv_cache[cache_idx + 8]);
793
2.16M
                        ref_cache[cache_idx]     =
794
2.16M
                        ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED
795
2.16M
                                                                        : PART_NOT_AVAILABLE;
796
2.16M
                    }
797
10.4M
                }
798
26.6M
            } else {
799
26.6M
                if (USES_LIST(left_type[LTOP], list)) {
800
19.3M
                    const int b_xy  = h->mb2b_xy[left_xy[LTOP]] + 3;
801
19.3M
                    const int b8_xy = 4 * left_xy[LTOP] + 1;
802
19.3M
                    AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]);
803
19.3M
                    ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];
804
19.3M
                } else {
805
7.30M
                    AV_ZERO32(mv_cache[-1]);
806
7.30M
                    ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED
807
7.30M
                                                    : PART_NOT_AVAILABLE;
808
7.30M
                }
809
26.6M
            }
810
811
31.8M
            if (USES_LIST(topright_type, list)) {
812
12.5M
                const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride;
813
12.5M
                AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]);
814
12.5M
                ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];
815
19.2M
            } else {
816
19.2M
                AV_ZERO32(mv_cache[4 - 1 * 8]);
817
19.2M
                ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED
818
19.2M
                                                     : PART_NOT_AVAILABLE;
819
19.2M
            }
820
31.8M
            if(ref_cache[2 - 1*8] < 0 || ref_cache[4 - 1 * 8] < 0) {
821
20.5M
                if (USES_LIST(topleft_type, list)) {
822
6.54M
                    const int b_xy  = h->mb2b_xy[topleft_xy] + 3 + b_stride +
823
6.54M
                                      (sl->topleft_partition & 2 * b_stride);
824
6.54M
                    const int b8_xy = 4 * topleft_xy + 1 + (sl->topleft_partition & 2);
825
6.54M
                    AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]);
826
6.54M
                    ref_cache[-1 - 1 * 8] = ref[b8_xy];
827
14.0M
                } else {
828
14.0M
                    AV_ZERO32(mv_cache[-1 - 1 * 8]);
829
14.0M
                    ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED
830
14.0M
                                                         : PART_NOT_AVAILABLE;
831
14.0M
                }
832
20.5M
            }
833
834
31.8M
            if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF(h))
835
7.65M
                continue;
836
837
24.1M
            if (!(mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2))) {
838
13.9M
                uint8_t(*mvd_cache)[2]   = &sl->mvd_cache[list][scan8[0]];
839
13.9M
                uint8_t(*mvd)[2]         = sl->mvd_table[list];
840
13.9M
                ref_cache[2 + 8 * 0] =
841
13.9M
                ref_cache[2 + 8 * 2] = PART_NOT_AVAILABLE;
842
13.9M
                AV_ZERO32(mv_cache[2 + 8 * 0]);
843
13.9M
                AV_ZERO32(mv_cache[2 + 8 * 2]);
844
845
13.9M
                if (CABAC(h)) {
846
12.3M
                    if (USES_LIST(top_type, list)) {
847
7.83M
                        const int b_xy = h->mb2br_xy[top_xy];
848
7.83M
                        AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);
849
7.83M
                    } else {
850
4.47M
                        AV_ZERO64(mvd_cache[0 - 1 * 8]);
851
4.47M
                    }
852
12.3M
                    if (USES_LIST(left_type[LTOP], list)) {
853
9.70M
                        const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6;
854
9.70M
                        AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);
855
9.70M
                        AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);
856
9.70M
                    } else {
857
2.60M
                        AV_ZERO16(mvd_cache[-1 + 0 * 8]);
858
2.60M
                        AV_ZERO16(mvd_cache[-1 + 1 * 8]);
859
2.60M
                    }
860
12.3M
                    if (USES_LIST(left_type[LBOT], list)) {
861
9.71M
                        const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6;
862
9.71M
                        AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);
863
9.71M
                        AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);
864
9.71M
                    } else {
865
2.59M
                        AV_ZERO16(mvd_cache[-1 + 2 * 8]);
866
2.59M
                        AV_ZERO16(mvd_cache[-1 + 3 * 8]);
867
2.59M
                    }
868
12.3M
                    AV_ZERO16(mvd_cache[2 + 8 * 0]);
869
12.3M
                    AV_ZERO16(mvd_cache[2 + 8 * 2]);
870
12.3M
                    if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
871
7.72M
                        uint8_t *direct_cache = &sl->direct_cache[scan8[0]];
872
7.72M
                        uint8_t *direct_table = h->direct_table;
873
7.72M
                        fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1);
874
875
7.72M
                        if (IS_DIRECT(top_type)) {
876
2.13M
                            AV_WN32A(&direct_cache[-1 * 8],
877
2.13M
                                     0x01010101u * (MB_TYPE_DIRECT2 >> 1));
878
5.59M
                        } else if (IS_8X8(top_type)) {
879
487k
                            int b8_xy = 4 * top_xy;
880
487k
                            direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];
881
487k
                            direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];
882
5.10M
                        } else {
883
5.10M
                            AV_WN32A(&direct_cache[-1 * 8],
884
5.10M
                                     0x01010101 * (MB_TYPE_16x16 >> 1));
885
5.10M
                        }
886
887
7.72M
                        if (IS_DIRECT(left_type[LTOP]))
888
2.27M
                            direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1;
889
5.44M
                        else if (IS_8X8(left_type[LTOP]))
890
767k
                            direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)];
891
4.68M
                        else
892
4.68M
                            direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1;
893
894
7.72M
                        if (IS_DIRECT(left_type[LBOT]))
895
2.28M
                            direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1;
896
5.44M
                        else if (IS_8X8(left_type[LBOT]))
897
773k
                            direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];
898
4.67M
                        else
899
4.67M
                            direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1;
900
7.72M
                    }
901
12.3M
                }
902
13.9M
            }
903
904
24.1M
#define MAP_MVS                                                         \
905
24.1M
    MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type)                         \
906
16.0M
    MAP_F2F(scan8[0] + 0 - 1 * 8, top_type)                             \
907
16.0M
    MAP_F2F(scan8[0] + 1 - 1 * 8, top_type)                             \
908
16.0M
    MAP_F2F(scan8[0] + 2 - 1 * 8, top_type)                             \
909
16.0M
    MAP_F2F(scan8[0] + 3 - 1 * 8, top_type)                             \
910
16.0M
    MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type)                        \
911
16.0M
    MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP])                      \
912
16.0M
    MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP])                      \
913
16.0M
    MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT])                      \
914
16.0M
    MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])
915
916
24.1M
            if (FRAME_MBAFF(h)) {
917
16.0M
                if (MB_FIELD(sl)) {
918
919
5.02M
#define MAP_F2F(idx, mb_type)                                           \
920
50.2M
    if (!IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) {     \
921
8.90M
        sl->ref_cache[list][idx]     *= 2;                              \
922
8.90M
        sl->mv_cache[list][idx][1]   /= 2;                              \
923
8.90M
        sl->mvd_cache[list][idx][1] >>= 1;                              \
924
8.90M
    }
925
926
5.02M
                    MAP_MVS
927
11.0M
                } else {
928
929
11.0M
#undef MAP_F2F
930
11.0M
#define MAP_F2F(idx, mb_type)                                           \
931
110M
    if (IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) {      \
932
4.66M
        sl->ref_cache[list][idx]    >>= 1;                              \
933
4.66M
        sl->mv_cache[list][idx][1]   *= 2;                              \
934
4.66M
        sl->mvd_cache[list][idx][1] <<= 1;                              \
935
4.66M
    }
936
937
11.0M
                    MAP_MVS
938
11.0M
#undef MAP_F2F
939
11.0M
                }
940
16.0M
            }
941
24.1M
        }
942
20.5M
    }
943
944
25.6M
    sl->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);
945
25.6M
}
h264_cavlc.c:fill_decode_caches
Line
Count
Source
577
2.99M
{
578
2.99M
    int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
579
2.99M
    int topleft_type, top_type, topright_type, left_type[LEFT_MBS];
580
2.99M
    const uint8_t *left_block = sl->left_block;
581
2.99M
    int i;
582
2.99M
    uint8_t *nnz;
583
2.99M
    uint8_t *nnz_cache;
584
585
2.99M
    topleft_xy      = sl->topleft_mb_xy;
586
2.99M
    top_xy          = sl->top_mb_xy;
587
2.99M
    topright_xy     = sl->topright_mb_xy;
588
2.99M
    left_xy[LTOP]   = sl->left_mb_xy[LTOP];
589
2.99M
    left_xy[LBOT]   = sl->left_mb_xy[LBOT];
590
2.99M
    topleft_type    = sl->topleft_type;
591
2.99M
    top_type        = sl->top_type;
592
2.99M
    topright_type   = sl->topright_type;
593
2.99M
    left_type[LTOP] = sl->left_type[LTOP];
594
2.99M
    left_type[LBOT] = sl->left_type[LBOT];
595
596
2.99M
    if (!IS_SKIP(mb_type)) {
597
2.63M
        if (IS_INTRA(mb_type)) {
598
786k
            int type_mask = h->ps.pps->constrained_intra_pred ? IS_INTRA(-1) : -1;
599
786k
            sl->topleft_samples_available     =
600
786k
                sl->top_samples_available     =
601
786k
                    sl->left_samples_available = 0xFFFF;
602
786k
            sl->topright_samples_available     = 0xEEEA;
603
604
786k
            if (!(top_type & type_mask)) {
605
476k
                sl->topleft_samples_available  = 0xB3FF;
606
476k
                sl->top_samples_available      = 0x33FF;
607
476k
                sl->topright_samples_available = 0x26EA;
608
476k
            }
609
786k
            if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) {
610
110k
                if (IS_INTERLACED(mb_type)) {
611
107k
                    if (!(left_type[LTOP] & type_mask)) {
612
100k
                        sl->topleft_samples_available &= 0xDFFF;
613
100k
                        sl->left_samples_available    &= 0x5FFF;
614
100k
                    }
615
107k
                    if (!(left_type[LBOT] & type_mask)) {
616
100k
                        sl->topleft_samples_available &= 0xFF5F;
617
100k
                        sl->left_samples_available    &= 0xFF5F;
618
100k
                    }
619
107k
                } else {
620
3.70k
                    int left_typei = h->cur_pic.mb_type[left_xy[LTOP] + h->mb_stride];
621
622
3.70k
                    av_assert2(left_xy[LTOP] == left_xy[LBOT]);
623
3.70k
                    if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {
624
943
                        sl->topleft_samples_available &= 0xDF5F;
625
943
                        sl->left_samples_available    &= 0x5F5F;
626
943
                    }
627
3.70k
                }
628
675k
            } else {
629
675k
                if (!(left_type[LTOP] & type_mask)) {
630
237k
                    sl->topleft_samples_available &= 0xDF5F;
631
237k
                    sl->left_samples_available    &= 0x5F5F;
632
237k
                }
633
675k
            }
634
635
786k
            if (!(topleft_type & type_mask))
636
532k
                sl->topleft_samples_available &= 0x7FFF;
637
638
786k
            if (!(topright_type & type_mask))
639
522k
                sl->topright_samples_available &= 0xFBFF;
640
641
786k
            if (IS_INTRA4x4(mb_type)) {
642
255k
                if (IS_INTRA4x4(top_type)) {
643
24.6k
                    AV_COPY32(sl->intra4x4_pred_mode_cache + 4 + 8 * 0, sl->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
644
230k
                } else {
645
230k
                    sl->intra4x4_pred_mode_cache[4 + 8 * 0] =
646
230k
                    sl->intra4x4_pred_mode_cache[5 + 8 * 0] =
647
230k
                    sl->intra4x4_pred_mode_cache[6 + 8 * 0] =
648
230k
                    sl->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask);
649
230k
                }
650
766k
                for (i = 0; i < 2; i++) {
651
511k
                    if (IS_INTRA4x4(left_type[LEFT(i)])) {
652
94.1k
                        int8_t *mode = sl->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];
653
94.1k
                        sl->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]];
654
94.1k
                        sl->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]];
655
416k
                    } else {
656
416k
                        sl->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] =
657
416k
                        sl->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask);
658
416k
                    }
659
511k
                }
660
255k
            }
661
786k
        }
662
663
        /*
664
         * 0 . T T. T T T T
665
         * 1 L . .L . . . .
666
         * 2 L . .L . . . .
667
         * 3 . T TL . . . .
668
         * 4 L . .L . . . .
669
         * 5 L . .. . . . .
670
         */
671
        /* 9.2.1: with data partitioning and constrained intra prediction, an
672
         * inter neighbour must not contribute to nC for an intra macroblock.
673
         * Step 7 would drop it from the (nA + nB + 1) >> 1 average entirely,
674
         * but JM's predict_nnz() counts it as present with zero coefficients.
675
         * FF_BUG_H264_DP_NNZ picks JM, and is autodetected in h264dec.c. */
676
2.63M
        int nnz_mask     = -1;
677
2.63M
        int nnz_excluded = 64;      // 64: unavailable, 0: present but empty
678
679
2.63M
        if (sl->data_partitioning && h->ps.pps->constrained_intra_pred &&
680
170
            IS_INTRA(mb_type)) {
681
133
            nnz_mask = IS_INTRA(-1);
682
133
            if (h->workaround_bugs & FF_BUG_H264_DP_NNZ)
683
133
                nnz_excluded = 0;
684
133
        }
685
686
2.63M
        nnz_cache = sl->non_zero_count_cache;
687
2.63M
        if (top_type & nnz_mask) {
688
1.54M
            nnz = h->non_zero_count[top_xy];
689
1.54M
            AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);
690
1.54M
            if (!h->chroma_y_shift) {
691
259k
                AV_COPY32(&nnz_cache[4 + 8 *  5], &nnz[4 *  7]);
692
259k
                AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);
693
1.28M
            } else {
694
1.28M
                AV_COPY32(&nnz_cache[4 + 8 *  5], &nnz[4 * 5]);
695
1.28M
                AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);
696
1.28M
            }
697
1.54M
        } else {
698
1.09M
            uint32_t top_empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 :
699
1.09M
                                 top_type ? nnz_excluded * 0x01010101u : 0x40404040;
700
1.09M
            AV_WN32A(&nnz_cache[4 + 8 *  0], top_empty);
701
1.09M
            AV_WN32A(&nnz_cache[4 + 8 *  5], top_empty);
702
1.09M
            AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty);
703
1.09M
        }
704
705
7.91M
        for (i = 0; i < 2; i++) {
706
5.27M
            if (left_type[LEFT(i)] & nnz_mask) {
707
3.83M
                nnz = h->non_zero_count[left_xy[LEFT(i)]];
708
3.83M
                nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]];
709
3.83M
                nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]];
710
3.83M
                if (CHROMA444(h)) {
711
351k
                    nnz_cache[3 + 8 *  6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];
712
351k
                    nnz_cache[3 + 8 *  7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];
713
351k
                    nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];
714
351k
                    nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];
715
3.48M
                } else if (CHROMA422(h)) {
716
498k
                    nnz_cache[3 + 8 *  6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];
717
498k
                    nnz_cache[3 + 8 *  7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];
718
498k
                    nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];
719
498k
                    nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];
720
2.98M
                } else {
721
2.98M
                    nnz_cache[3 + 8 *  6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];
722
2.98M
                    nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];
723
2.98M
                }
724
3.83M
            } else {
725
1.44M
                int empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 :
726
1.44M
                            left_type[LEFT(i)] ? nnz_excluded : 64;
727
1.44M
                nnz_cache[3 + 8 *  1 + 2 * 8 * i] =
728
1.44M
                nnz_cache[3 + 8 *  2 + 2 * 8 * i] =
729
1.44M
                nnz_cache[3 + 8 *  6 + 2 * 8 * i] =
730
1.44M
                nnz_cache[3 + 8 *  7 + 2 * 8 * i] =
731
1.44M
                nnz_cache[3 + 8 * 11 + 2 * 8 * i] =
732
1.44M
                nnz_cache[3 + 8 * 12 + 2 * 8 * i] = empty;
733
1.44M
            }
734
5.27M
        }
735
736
2.63M
        if (CABAC(h)) {
737
            // top_cbp
738
0
            if (top_type)
739
0
                sl->top_cbp = h->cbp_table[top_xy];
740
0
            else
741
0
                sl->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
742
            // left_cbp
743
0
            if (left_type[LTOP]) {
744
0
                sl->left_cbp =   (h->cbp_table[left_xy[LTOP]] & 0x7F0) |
745
0
                               ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |
746
0
                              (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2);
747
0
            } else {
748
0
                sl->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
749
0
            }
750
0
        }
751
2.63M
    }
752
753
2.99M
    if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && sl->direct_spatial_mv_pred)) {
754
1.85M
        int list;
755
1.85M
        int b_stride = h->b_stride;
756
4.62M
        for (list = 0; list < sl->list_count; list++) {
757
2.76M
            int8_t *ref_cache = &sl->ref_cache[list][scan8[0]];
758
2.76M
            int8_t *ref       = h->cur_pic.ref_index[list];
759
2.76M
            int16_t(*mv_cache)[2] = &sl->mv_cache[list][scan8[0]];
760
2.76M
            int16_t(*mv)[2]       = h->cur_pic.motion_val[list];
761
2.76M
            if (!USES_LIST(mb_type, list))
762
247k
                continue;
763
2.52M
            av_assert2(!(IS_DIRECT(mb_type) && !sl->direct_spatial_mv_pred));
764
765
2.52M
            if (USES_LIST(top_type, list)) {
766
1.41M
                const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride;
767
1.41M
                AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]);
768
1.41M
                ref_cache[0 - 1 * 8] =
769
1.41M
                ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];
770
1.41M
                ref_cache[2 - 1 * 8] =
771
1.41M
                ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];
772
1.41M
            } else {
773
1.10M
                AV_ZERO128(mv_cache[0 - 1 * 8]);
774
1.10M
                AV_WN32A(&ref_cache[0 - 1 * 8],
775
1.10M
                         ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u);
776
1.10M
            }
777
778
2.52M
            if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) {
779
1.36M
                for (i = 0; i < 2; i++) {
780
910k
                    int cache_idx = -1 + i * 2 * 8;
781
910k
                    if (USES_LIST(left_type[LEFT(i)], list)) {
782
705k
                        const int b_xy  = h->mb2b_xy[left_xy[LEFT(i)]] + 3;
783
705k
                        const int b8_xy = 4 * left_xy[LEFT(i)] + 1;
784
705k
                        AV_COPY32(mv_cache[cache_idx],
785
705k
                                  mv[b_xy + b_stride * left_block[0 + i * 2]]);
786
705k
                        AV_COPY32(mv_cache[cache_idx + 8],
787
705k
                                  mv[b_xy + b_stride * left_block[1 + i * 2]]);
788
705k
                        ref_cache[cache_idx]     = ref[b8_xy + (left_block[0 + i * 2] & ~1)];
789
705k
                        ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];
790
705k
                    } else {
791
204k
                        AV_ZERO32(mv_cache[cache_idx]);
792
204k
                        AV_ZERO32(mv_cache[cache_idx + 8]);
793
204k
                        ref_cache[cache_idx]     =
794
204k
                        ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED
795
204k
                                                                        : PART_NOT_AVAILABLE;
796
204k
                    }
797
910k
                }
798
2.06M
            } else {
799
2.06M
                if (USES_LIST(left_type[LTOP], list)) {
800
1.49M
                    const int b_xy  = h->mb2b_xy[left_xy[LTOP]] + 3;
801
1.49M
                    const int b8_xy = 4 * left_xy[LTOP] + 1;
802
1.49M
                    AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]);
803
1.49M
                    ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];
804
1.49M
                } else {
805
566k
                    AV_ZERO32(mv_cache[-1]);
806
566k
                    ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED
807
566k
                                                    : PART_NOT_AVAILABLE;
808
566k
                }
809
2.06M
            }
810
811
2.52M
            if (USES_LIST(topright_type, list)) {
812
1.09M
                const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride;
813
1.09M
                AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]);
814
1.09M
                ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];
815
1.42M
            } else {
816
1.42M
                AV_ZERO32(mv_cache[4 - 1 * 8]);
817
1.42M
                ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED
818
1.42M
                                                     : PART_NOT_AVAILABLE;
819
1.42M
            }
820
2.52M
            if(ref_cache[2 - 1*8] < 0 || ref_cache[4 - 1 * 8] < 0) {
821
1.56M
                if (USES_LIST(topleft_type, list)) {
822
418k
                    const int b_xy  = h->mb2b_xy[topleft_xy] + 3 + b_stride +
823
418k
                                      (sl->topleft_partition & 2 * b_stride);
824
418k
                    const int b8_xy = 4 * topleft_xy + 1 + (sl->topleft_partition & 2);
825
418k
                    AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]);
826
418k
                    ref_cache[-1 - 1 * 8] = ref[b8_xy];
827
1.14M
                } else {
828
1.14M
                    AV_ZERO32(mv_cache[-1 - 1 * 8]);
829
1.14M
                    ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED
830
1.14M
                                                         : PART_NOT_AVAILABLE;
831
1.14M
                }
832
1.56M
            }
833
834
2.52M
            if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF(h))
835
269k
                continue;
836
837
2.25M
            if (!(mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2))) {
838
1.67M
                uint8_t(*mvd_cache)[2]   = &sl->mvd_cache[list][scan8[0]];
839
1.67M
                uint8_t(*mvd)[2]         = sl->mvd_table[list];
840
1.67M
                ref_cache[2 + 8 * 0] =
841
1.67M
                ref_cache[2 + 8 * 2] = PART_NOT_AVAILABLE;
842
1.67M
                AV_ZERO32(mv_cache[2 + 8 * 0]);
843
1.67M
                AV_ZERO32(mv_cache[2 + 8 * 2]);
844
845
1.67M
                if (CABAC(h)) {
846
0
                    if (USES_LIST(top_type, list)) {
847
0
                        const int b_xy = h->mb2br_xy[top_xy];
848
0
                        AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);
849
0
                    } else {
850
0
                        AV_ZERO64(mvd_cache[0 - 1 * 8]);
851
0
                    }
852
0
                    if (USES_LIST(left_type[LTOP], list)) {
853
0
                        const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6;
854
0
                        AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);
855
0
                        AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);
856
0
                    } else {
857
0
                        AV_ZERO16(mvd_cache[-1 + 0 * 8]);
858
0
                        AV_ZERO16(mvd_cache[-1 + 1 * 8]);
859
0
                    }
860
0
                    if (USES_LIST(left_type[LBOT], list)) {
861
0
                        const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6;
862
0
                        AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);
863
0
                        AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);
864
0
                    } else {
865
0
                        AV_ZERO16(mvd_cache[-1 + 2 * 8]);
866
0
                        AV_ZERO16(mvd_cache[-1 + 3 * 8]);
867
0
                    }
868
0
                    AV_ZERO16(mvd_cache[2 + 8 * 0]);
869
0
                    AV_ZERO16(mvd_cache[2 + 8 * 2]);
870
0
                    if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
871
0
                        uint8_t *direct_cache = &sl->direct_cache[scan8[0]];
872
0
                        uint8_t *direct_table = h->direct_table;
873
0
                        fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1);
874
875
0
                        if (IS_DIRECT(top_type)) {
876
0
                            AV_WN32A(&direct_cache[-1 * 8],
877
0
                                     0x01010101u * (MB_TYPE_DIRECT2 >> 1));
878
0
                        } else if (IS_8X8(top_type)) {
879
0
                            int b8_xy = 4 * top_xy;
880
0
                            direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];
881
0
                            direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];
882
0
                        } else {
883
0
                            AV_WN32A(&direct_cache[-1 * 8],
884
0
                                     0x01010101 * (MB_TYPE_16x16 >> 1));
885
0
                        }
886
887
0
                        if (IS_DIRECT(left_type[LTOP]))
888
0
                            direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1;
889
0
                        else if (IS_8X8(left_type[LTOP]))
890
0
                            direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)];
891
0
                        else
892
0
                            direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1;
893
894
0
                        if (IS_DIRECT(left_type[LBOT]))
895
0
                            direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1;
896
0
                        else if (IS_8X8(left_type[LBOT]))
897
0
                            direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];
898
0
                        else
899
0
                            direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1;
900
0
                    }
901
0
                }
902
1.67M
            }
903
904
2.25M
#define MAP_MVS                                                         \
905
2.25M
    MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type)                         \
906
2.25M
    MAP_F2F(scan8[0] + 0 - 1 * 8, top_type)                             \
907
2.25M
    MAP_F2F(scan8[0] + 1 - 1 * 8, top_type)                             \
908
2.25M
    MAP_F2F(scan8[0] + 2 - 1 * 8, top_type)                             \
909
2.25M
    MAP_F2F(scan8[0] + 3 - 1 * 8, top_type)                             \
910
2.25M
    MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type)                        \
911
2.25M
    MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP])                      \
912
2.25M
    MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP])                      \
913
2.25M
    MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT])                      \
914
2.25M
    MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])
915
916
2.25M
            if (FRAME_MBAFF(h)) {
917
1.13M
                if (MB_FIELD(sl)) {
918
919
750k
#define MAP_F2F(idx, mb_type)                                           \
920
750k
    if (!IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) {     \
921
750k
        sl->ref_cache[list][idx]     *= 2;                              \
922
750k
        sl->mv_cache[list][idx][1]   /= 2;                              \
923
750k
        sl->mvd_cache[list][idx][1] >>= 1;                              \
924
750k
    }
925
926
750k
                    MAP_MVS
927
750k
                } else {
928
929
380k
#undef MAP_F2F
930
380k
#define MAP_F2F(idx, mb_type)                                           \
931
380k
    if (IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) {      \
932
380k
        sl->ref_cache[list][idx]    >>= 1;                              \
933
380k
        sl->mv_cache[list][idx][1]   *= 2;                              \
934
380k
        sl->mvd_cache[list][idx][1] <<= 1;                              \
935
380k
    }
936
937
380k
                    MAP_MVS
938
380k
#undef MAP_F2F
939
380k
                }
940
1.13M
            }
941
2.25M
        }
942
1.85M
    }
943
944
2.99M
    sl->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);
945
2.99M
}
h264_cabac.c:fill_decode_caches
Line
Count
Source
577
22.6M
{
578
22.6M
    int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS];
579
22.6M
    int topleft_type, top_type, topright_type, left_type[LEFT_MBS];
580
22.6M
    const uint8_t *left_block = sl->left_block;
581
22.6M
    int i;
582
22.6M
    uint8_t *nnz;
583
22.6M
    uint8_t *nnz_cache;
584
585
22.6M
    topleft_xy      = sl->topleft_mb_xy;
586
22.6M
    top_xy          = sl->top_mb_xy;
587
22.6M
    topright_xy     = sl->topright_mb_xy;
588
22.6M
    left_xy[LTOP]   = sl->left_mb_xy[LTOP];
589
22.6M
    left_xy[LBOT]   = sl->left_mb_xy[LBOT];
590
22.6M
    topleft_type    = sl->topleft_type;
591
22.6M
    top_type        = sl->top_type;
592
22.6M
    topright_type   = sl->topright_type;
593
22.6M
    left_type[LTOP] = sl->left_type[LTOP];
594
22.6M
    left_type[LBOT] = sl->left_type[LBOT];
595
596
22.6M
    if (!IS_SKIP(mb_type)) {
597
14.2M
        if (IS_INTRA(mb_type)) {
598
3.87M
            int type_mask = h->ps.pps->constrained_intra_pred ? IS_INTRA(-1) : -1;
599
3.87M
            sl->topleft_samples_available     =
600
3.87M
                sl->top_samples_available     =
601
3.87M
                    sl->left_samples_available = 0xFFFF;
602
3.87M
            sl->topright_samples_available     = 0xEEEA;
603
604
3.87M
            if (!(top_type & type_mask)) {
605
1.30M
                sl->topleft_samples_available  = 0xB3FF;
606
1.30M
                sl->top_samples_available      = 0x33FF;
607
1.30M
                sl->topright_samples_available = 0x26EA;
608
1.30M
            }
609
3.87M
            if (IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])) {
610
237k
                if (IS_INTERLACED(mb_type)) {
611
188k
                    if (!(left_type[LTOP] & type_mask)) {
612
121k
                        sl->topleft_samples_available &= 0xDFFF;
613
121k
                        sl->left_samples_available    &= 0x5FFF;
614
121k
                    }
615
188k
                    if (!(left_type[LBOT] & type_mask)) {
616
124k
                        sl->topleft_samples_available &= 0xFF5F;
617
124k
                        sl->left_samples_available    &= 0xFF5F;
618
124k
                    }
619
188k
                } else {
620
49.5k
                    int left_typei = h->cur_pic.mb_type[left_xy[LTOP] + h->mb_stride];
621
622
49.5k
                    av_assert2(left_xy[LTOP] == left_xy[LBOT]);
623
49.5k
                    if (!((left_typei & type_mask) && (left_type[LTOP] & type_mask))) {
624
681
                        sl->topleft_samples_available &= 0xDF5F;
625
681
                        sl->left_samples_available    &= 0x5F5F;
626
681
                    }
627
49.5k
                }
628
3.64M
            } else {
629
3.64M
                if (!(left_type[LTOP] & type_mask)) {
630
846k
                    sl->topleft_samples_available &= 0xDF5F;
631
846k
                    sl->left_samples_available    &= 0x5F5F;
632
846k
                }
633
3.64M
            }
634
635
3.87M
            if (!(topleft_type & type_mask))
636
1.66M
                sl->topleft_samples_available &= 0x7FFF;
637
638
3.87M
            if (!(topright_type & type_mask))
639
1.90M
                sl->topright_samples_available &= 0xFBFF;
640
641
3.87M
            if (IS_INTRA4x4(mb_type)) {
642
2.33M
                if (IS_INTRA4x4(top_type)) {
643
1.06M
                    AV_COPY32(sl->intra4x4_pred_mode_cache + 4 + 8 * 0, sl->intra4x4_pred_mode + h->mb2br_xy[top_xy]);
644
1.27M
                } else {
645
1.27M
                    sl->intra4x4_pred_mode_cache[4 + 8 * 0] =
646
1.27M
                    sl->intra4x4_pred_mode_cache[5 + 8 * 0] =
647
1.27M
                    sl->intra4x4_pred_mode_cache[6 + 8 * 0] =
648
1.27M
                    sl->intra4x4_pred_mode_cache[7 + 8 * 0] = 2 - 3 * !(top_type & type_mask);
649
1.27M
                }
650
7.00M
                for (i = 0; i < 2; i++) {
651
4.66M
                    if (IS_INTRA4x4(left_type[LEFT(i)])) {
652
2.35M
                        int8_t *mode = sl->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]];
653
2.35M
                        sl->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] = mode[6 - left_block[0 + 2 * i]];
654
2.35M
                        sl->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = mode[6 - left_block[1 + 2 * i]];
655
2.35M
                    } else {
656
2.30M
                        sl->intra4x4_pred_mode_cache[3 + 8 * 1 + 2 * 8 * i] =
657
2.30M
                        sl->intra4x4_pred_mode_cache[3 + 8 * 2 + 2 * 8 * i] = 2 - 3 * !(left_type[LEFT(i)] & type_mask);
658
2.30M
                    }
659
4.66M
                }
660
2.33M
            }
661
3.87M
        }
662
663
        /*
664
         * 0 . T T. T T T T
665
         * 1 L . .L . . . .
666
         * 2 L . .L . . . .
667
         * 3 . T TL . . . .
668
         * 4 L . .L . . . .
669
         * 5 L . .. . . . .
670
         */
671
        /* 9.2.1: with data partitioning and constrained intra prediction, an
672
         * inter neighbour must not contribute to nC for an intra macroblock.
673
         * Step 7 would drop it from the (nA + nB + 1) >> 1 average entirely,
674
         * but JM's predict_nnz() counts it as present with zero coefficients.
675
         * FF_BUG_H264_DP_NNZ picks JM, and is autodetected in h264dec.c. */
676
14.2M
        int nnz_mask     = -1;
677
14.2M
        int nnz_excluded = 64;      // 64: unavailable, 0: present but empty
678
679
14.2M
        if (sl->data_partitioning && h->ps.pps->constrained_intra_pred &&
680
0
            IS_INTRA(mb_type)) {
681
0
            nnz_mask = IS_INTRA(-1);
682
0
            if (h->workaround_bugs & FF_BUG_H264_DP_NNZ)
683
0
                nnz_excluded = 0;
684
0
        }
685
686
14.2M
        nnz_cache = sl->non_zero_count_cache;
687
14.2M
        if (top_type & nnz_mask) {
688
10.2M
            nnz = h->non_zero_count[top_xy];
689
10.2M
            AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[4 * 3]);
690
10.2M
            if (!h->chroma_y_shift) {
691
4.98M
                AV_COPY32(&nnz_cache[4 + 8 *  5], &nnz[4 *  7]);
692
4.98M
                AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 11]);
693
5.23M
            } else {
694
5.23M
                AV_COPY32(&nnz_cache[4 + 8 *  5], &nnz[4 * 5]);
695
5.23M
                AV_COPY32(&nnz_cache[4 + 8 * 10], &nnz[4 * 9]);
696
5.23M
            }
697
10.2M
        } else {
698
4.05M
            uint32_t top_empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 :
699
4.05M
                                 top_type ? nnz_excluded * 0x01010101u : 0x40404040;
700
4.05M
            AV_WN32A(&nnz_cache[4 + 8 *  0], top_empty);
701
4.05M
            AV_WN32A(&nnz_cache[4 + 8 *  5], top_empty);
702
4.05M
            AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty);
703
4.05M
        }
704
705
42.8M
        for (i = 0; i < 2; i++) {
706
28.5M
            if (left_type[LEFT(i)] & nnz_mask) {
707
24.6M
                nnz = h->non_zero_count[left_xy[LEFT(i)]];
708
24.6M
                nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i]];
709
24.6M
                nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i]];
710
24.6M
                if (CHROMA444(h)) {
711
1.62M
                    nnz_cache[3 + 8 *  6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 4 * 4];
712
1.62M
                    nnz_cache[3 + 8 *  7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 4 * 4];
713
1.62M
                    nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] + 8 * 4];
714
1.62M
                    nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] + 8 * 4];
715
23.0M
                } else if (CHROMA422(h)) {
716
10.5M
                    nnz_cache[3 + 8 *  6 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 4 * 4];
717
10.5M
                    nnz_cache[3 + 8 *  7 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 4 * 4];
718
10.5M
                    nnz_cache[3 + 8 * 11 + 2 * 8 * i] = nnz[left_block[8 + 0 + 2 * i] - 2 + 8 * 4];
719
10.5M
                    nnz_cache[3 + 8 * 12 + 2 * 8 * i] = nnz[left_block[8 + 1 + 2 * i] - 2 + 8 * 4];
720
12.5M
                } else {
721
12.5M
                    nnz_cache[3 + 8 *  6 + 8 * i] = nnz[left_block[8 + 4 + 2 * i]];
722
12.5M
                    nnz_cache[3 + 8 * 11 + 8 * i] = nnz[left_block[8 + 5 + 2 * i]];
723
12.5M
                }
724
24.6M
            } else {
725
3.89M
                int empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 :
726
3.89M
                            left_type[LEFT(i)] ? nnz_excluded : 64;
727
3.89M
                nnz_cache[3 + 8 *  1 + 2 * 8 * i] =
728
3.89M
                nnz_cache[3 + 8 *  2 + 2 * 8 * i] =
729
3.89M
                nnz_cache[3 + 8 *  6 + 2 * 8 * i] =
730
3.89M
                nnz_cache[3 + 8 *  7 + 2 * 8 * i] =
731
3.89M
                nnz_cache[3 + 8 * 11 + 2 * 8 * i] =
732
3.89M
                nnz_cache[3 + 8 * 12 + 2 * 8 * i] = empty;
733
3.89M
            }
734
28.5M
        }
735
736
14.2M
        if (CABAC(h)) {
737
            // top_cbp
738
14.2M
            if (top_type)
739
10.2M
                sl->top_cbp = h->cbp_table[top_xy];
740
4.05M
            else
741
4.05M
                sl->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
742
            // left_cbp
743
14.2M
            if (left_type[LTOP]) {
744
12.3M
                sl->left_cbp =   (h->cbp_table[left_xy[LTOP]] & 0x7F0) |
745
12.3M
                               ((h->cbp_table[left_xy[LTOP]] >> (left_block[0] & (~1))) & 2) |
746
12.3M
                              (((h->cbp_table[left_xy[LBOT]] >> (left_block[2] & (~1))) & 2) << 2);
747
12.3M
            } else {
748
1.94M
                sl->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F;
749
1.94M
            }
750
14.2M
        }
751
14.2M
    }
752
753
22.6M
    if (IS_INTER(mb_type) || (IS_DIRECT(mb_type) && sl->direct_spatial_mv_pred)) {
754
18.6M
        int list;
755
18.6M
        int b_stride = h->b_stride;
756
51.3M
        for (list = 0; list < sl->list_count; list++) {
757
32.7M
            int8_t *ref_cache = &sl->ref_cache[list][scan8[0]];
758
32.7M
            int8_t *ref       = h->cur_pic.ref_index[list];
759
32.7M
            int16_t(*mv_cache)[2] = &sl->mv_cache[list][scan8[0]];
760
32.7M
            int16_t(*mv)[2]       = h->cur_pic.motion_val[list];
761
32.7M
            if (!USES_LIST(mb_type, list))
762
3.41M
                continue;
763
29.3M
            av_assert2(!(IS_DIRECT(mb_type) && !sl->direct_spatial_mv_pred));
764
765
29.3M
            if (USES_LIST(top_type, list)) {
766
17.4M
                const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride;
767
17.4M
                AV_COPY128(mv_cache[0 - 1 * 8], mv[b_xy + 0]);
768
17.4M
                ref_cache[0 - 1 * 8] =
769
17.4M
                ref_cache[1 - 1 * 8] = ref[4 * top_xy + 2];
770
17.4M
                ref_cache[2 - 1 * 8] =
771
17.4M
                ref_cache[3 - 1 * 8] = ref[4 * top_xy + 3];
772
17.4M
            } else {
773
11.8M
                AV_ZERO128(mv_cache[0 - 1 * 8]);
774
11.8M
                AV_WN32A(&ref_cache[0 - 1 * 8],
775
11.8M
                         ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE) & 0xFF) * 0x01010101u);
776
11.8M
            }
777
778
29.3M
            if (mb_type & (MB_TYPE_16x8 | MB_TYPE_8x8)) {
779
14.2M
                for (i = 0; i < 2; i++) {
780
9.50M
                    int cache_idx = -1 + i * 2 * 8;
781
9.50M
                    if (USES_LIST(left_type[LEFT(i)], list)) {
782
7.54M
                        const int b_xy  = h->mb2b_xy[left_xy[LEFT(i)]] + 3;
783
7.54M
                        const int b8_xy = 4 * left_xy[LEFT(i)] + 1;
784
7.54M
                        AV_COPY32(mv_cache[cache_idx],
785
7.54M
                                  mv[b_xy + b_stride * left_block[0 + i * 2]]);
786
7.54M
                        AV_COPY32(mv_cache[cache_idx + 8],
787
7.54M
                                  mv[b_xy + b_stride * left_block[1 + i * 2]]);
788
7.54M
                        ref_cache[cache_idx]     = ref[b8_xy + (left_block[0 + i * 2] & ~1)];
789
7.54M
                        ref_cache[cache_idx + 8] = ref[b8_xy + (left_block[1 + i * 2] & ~1)];
790
7.54M
                    } else {
791
1.96M
                        AV_ZERO32(mv_cache[cache_idx]);
792
1.96M
                        AV_ZERO32(mv_cache[cache_idx + 8]);
793
1.96M
                        ref_cache[cache_idx]     =
794
1.96M
                        ref_cache[cache_idx + 8] = (left_type[LEFT(i)]) ? LIST_NOT_USED
795
1.96M
                                                                        : PART_NOT_AVAILABLE;
796
1.96M
                    }
797
9.50M
                }
798
24.5M
            } else {
799
24.5M
                if (USES_LIST(left_type[LTOP], list)) {
800
17.8M
                    const int b_xy  = h->mb2b_xy[left_xy[LTOP]] + 3;
801
17.8M
                    const int b8_xy = 4 * left_xy[LTOP] + 1;
802
17.8M
                    AV_COPY32(mv_cache[-1], mv[b_xy + b_stride * left_block[0]]);
803
17.8M
                    ref_cache[-1] = ref[b8_xy + (left_block[0] & ~1)];
804
17.8M
                } else {
805
6.73M
                    AV_ZERO32(mv_cache[-1]);
806
6.73M
                    ref_cache[-1] = left_type[LTOP] ? LIST_NOT_USED
807
6.73M
                                                    : PART_NOT_AVAILABLE;
808
6.73M
                }
809
24.5M
            }
810
811
29.3M
            if (USES_LIST(topright_type, list)) {
812
11.4M
                const int b_xy = h->mb2b_xy[topright_xy] + 3 * b_stride;
813
11.4M
                AV_COPY32(mv_cache[4 - 1 * 8], mv[b_xy]);
814
11.4M
                ref_cache[4 - 1 * 8] = ref[4 * topright_xy + 2];
815
17.8M
            } else {
816
17.8M
                AV_ZERO32(mv_cache[4 - 1 * 8]);
817
17.8M
                ref_cache[4 - 1 * 8] = topright_type ? LIST_NOT_USED
818
17.8M
                                                     : PART_NOT_AVAILABLE;
819
17.8M
            }
820
29.3M
            if(ref_cache[2 - 1*8] < 0 || ref_cache[4 - 1 * 8] < 0) {
821
19.0M
                if (USES_LIST(topleft_type, list)) {
822
6.12M
                    const int b_xy  = h->mb2b_xy[topleft_xy] + 3 + b_stride +
823
6.12M
                                      (sl->topleft_partition & 2 * b_stride);
824
6.12M
                    const int b8_xy = 4 * topleft_xy + 1 + (sl->topleft_partition & 2);
825
6.12M
                    AV_COPY32(mv_cache[-1 - 1 * 8], mv[b_xy]);
826
6.12M
                    ref_cache[-1 - 1 * 8] = ref[b8_xy];
827
12.8M
                } else {
828
12.8M
                    AV_ZERO32(mv_cache[-1 - 1 * 8]);
829
12.8M
                    ref_cache[-1 - 1 * 8] = topleft_type ? LIST_NOT_USED
830
12.8M
                                                         : PART_NOT_AVAILABLE;
831
12.8M
                }
832
19.0M
            }
833
834
29.3M
            if ((mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2)) && !FRAME_MBAFF(h))
835
7.38M
                continue;
836
837
21.9M
            if (!(mb_type & (MB_TYPE_SKIP | MB_TYPE_DIRECT2))) {
838
12.3M
                uint8_t(*mvd_cache)[2]   = &sl->mvd_cache[list][scan8[0]];
839
12.3M
                uint8_t(*mvd)[2]         = sl->mvd_table[list];
840
12.3M
                ref_cache[2 + 8 * 0] =
841
12.3M
                ref_cache[2 + 8 * 2] = PART_NOT_AVAILABLE;
842
12.3M
                AV_ZERO32(mv_cache[2 + 8 * 0]);
843
12.3M
                AV_ZERO32(mv_cache[2 + 8 * 2]);
844
845
12.3M
                if (CABAC(h)) {
846
12.3M
                    if (USES_LIST(top_type, list)) {
847
7.83M
                        const int b_xy = h->mb2br_xy[top_xy];
848
7.83M
                        AV_COPY64(mvd_cache[0 - 1 * 8], mvd[b_xy + 0]);
849
7.83M
                    } else {
850
4.47M
                        AV_ZERO64(mvd_cache[0 - 1 * 8]);
851
4.47M
                    }
852
12.3M
                    if (USES_LIST(left_type[LTOP], list)) {
853
9.70M
                        const int b_xy = h->mb2br_xy[left_xy[LTOP]] + 6;
854
9.70M
                        AV_COPY16(mvd_cache[-1 + 0 * 8], mvd[b_xy - left_block[0]]);
855
9.70M
                        AV_COPY16(mvd_cache[-1 + 1 * 8], mvd[b_xy - left_block[1]]);
856
9.70M
                    } else {
857
2.60M
                        AV_ZERO16(mvd_cache[-1 + 0 * 8]);
858
2.60M
                        AV_ZERO16(mvd_cache[-1 + 1 * 8]);
859
2.60M
                    }
860
12.3M
                    if (USES_LIST(left_type[LBOT], list)) {
861
9.71M
                        const int b_xy = h->mb2br_xy[left_xy[LBOT]] + 6;
862
9.71M
                        AV_COPY16(mvd_cache[-1 + 2 * 8], mvd[b_xy - left_block[2]]);
863
9.71M
                        AV_COPY16(mvd_cache[-1 + 3 * 8], mvd[b_xy - left_block[3]]);
864
9.71M
                    } else {
865
2.59M
                        AV_ZERO16(mvd_cache[-1 + 2 * 8]);
866
2.59M
                        AV_ZERO16(mvd_cache[-1 + 3 * 8]);
867
2.59M
                    }
868
12.3M
                    AV_ZERO16(mvd_cache[2 + 8 * 0]);
869
12.3M
                    AV_ZERO16(mvd_cache[2 + 8 * 2]);
870
12.3M
                    if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
871
7.72M
                        uint8_t *direct_cache = &sl->direct_cache[scan8[0]];
872
7.72M
                        uint8_t *direct_table = h->direct_table;
873
7.72M
                        fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16 >> 1, 1);
874
875
7.72M
                        if (IS_DIRECT(top_type)) {
876
2.13M
                            AV_WN32A(&direct_cache[-1 * 8],
877
2.13M
                                     0x01010101u * (MB_TYPE_DIRECT2 >> 1));
878
5.59M
                        } else if (IS_8X8(top_type)) {
879
487k
                            int b8_xy = 4 * top_xy;
880
487k
                            direct_cache[0 - 1 * 8] = direct_table[b8_xy + 2];
881
487k
                            direct_cache[2 - 1 * 8] = direct_table[b8_xy + 3];
882
5.10M
                        } else {
883
5.10M
                            AV_WN32A(&direct_cache[-1 * 8],
884
5.10M
                                     0x01010101 * (MB_TYPE_16x16 >> 1));
885
5.10M
                        }
886
887
7.72M
                        if (IS_DIRECT(left_type[LTOP]))
888
2.27M
                            direct_cache[-1 + 0 * 8] = MB_TYPE_DIRECT2 >> 1;
889
5.44M
                        else if (IS_8X8(left_type[LTOP]))
890
767k
                            direct_cache[-1 + 0 * 8] = direct_table[4 * left_xy[LTOP] + 1 + (left_block[0] & ~1)];
891
4.68M
                        else
892
4.68M
                            direct_cache[-1 + 0 * 8] = MB_TYPE_16x16 >> 1;
893
894
7.72M
                        if (IS_DIRECT(left_type[LBOT]))
895
2.28M
                            direct_cache[-1 + 2 * 8] = MB_TYPE_DIRECT2 >> 1;
896
5.44M
                        else if (IS_8X8(left_type[LBOT]))
897
773k
                            direct_cache[-1 + 2 * 8] = direct_table[4 * left_xy[LBOT] + 1 + (left_block[2] & ~1)];
898
4.67M
                        else
899
4.67M
                            direct_cache[-1 + 2 * 8] = MB_TYPE_16x16 >> 1;
900
7.72M
                    }
901
12.3M
                }
902
12.3M
            }
903
904
21.9M
#define MAP_MVS                                                         \
905
21.9M
    MAP_F2F(scan8[0] - 1 - 1 * 8, topleft_type)                         \
906
21.9M
    MAP_F2F(scan8[0] + 0 - 1 * 8, top_type)                             \
907
21.9M
    MAP_F2F(scan8[0] + 1 - 1 * 8, top_type)                             \
908
21.9M
    MAP_F2F(scan8[0] + 2 - 1 * 8, top_type)                             \
909
21.9M
    MAP_F2F(scan8[0] + 3 - 1 * 8, top_type)                             \
910
21.9M
    MAP_F2F(scan8[0] + 4 - 1 * 8, topright_type)                        \
911
21.9M
    MAP_F2F(scan8[0] - 1 + 0 * 8, left_type[LTOP])                      \
912
21.9M
    MAP_F2F(scan8[0] - 1 + 1 * 8, left_type[LTOP])                      \
913
21.9M
    MAP_F2F(scan8[0] - 1 + 2 * 8, left_type[LBOT])                      \
914
21.9M
    MAP_F2F(scan8[0] - 1 + 3 * 8, left_type[LBOT])
915
916
21.9M
            if (FRAME_MBAFF(h)) {
917
14.9M
                if (MB_FIELD(sl)) {
918
919
4.27M
#define MAP_F2F(idx, mb_type)                                           \
920
4.27M
    if (!IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) {     \
921
4.27M
        sl->ref_cache[list][idx]     *= 2;                              \
922
4.27M
        sl->mv_cache[list][idx][1]   /= 2;                              \
923
4.27M
        sl->mvd_cache[list][idx][1] >>= 1;                              \
924
4.27M
    }
925
926
4.27M
                    MAP_MVS
927
10.6M
                } else {
928
929
10.6M
#undef MAP_F2F
930
10.6M
#define MAP_F2F(idx, mb_type)                                           \
931
10.6M
    if (IS_INTERLACED(mb_type) && sl->ref_cache[list][idx] >= 0) {      \
932
10.6M
        sl->ref_cache[list][idx]    >>= 1;                              \
933
10.6M
        sl->mv_cache[list][idx][1]   *= 2;                              \
934
10.6M
        sl->mvd_cache[list][idx][1] <<= 1;                              \
935
10.6M
    }
936
937
10.6M
                    MAP_MVS
938
10.6M
#undef MAP_F2F
939
10.6M
                }
940
14.9M
            }
941
21.9M
        }
942
18.6M
    }
943
944
22.6M
    sl->neighbor_transform_size = !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]);
945
22.6M
}
946
947
/**
948
 * decodes a P_SKIP or B_SKIP macroblock
949
 */
950
av_unused static void decode_mb_skip(const H264Context *h, H264SliceContext *sl)
951
23.4M
{
952
23.4M
    const int mb_xy = sl->mb_xy;
953
23.4M
    int mb_type     = 0;
954
955
23.4M
    memset(h->non_zero_count[mb_xy], 0, 48);
956
957
23.4M
    if (MB_FIELD(sl))
958
9.40M
        mb_type |= MB_TYPE_INTERLACED;
959
960
23.4M
    if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
961
        // just for fill_caches. pred_direct_motion will set the real mb_type
962
13.9M
        mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 | MB_TYPE_SKIP;
963
13.9M
        if (sl->direct_spatial_mv_pred) {
964
8.68M
            fill_decode_neighbors(h, sl, mb_type);
965
8.68M
            fill_decode_caches(h, sl, mb_type); //FIXME check what is needed and what not ...
966
8.68M
        }
967
13.9M
        ff_h264_pred_direct_motion(h, sl, &mb_type);
968
13.9M
        mb_type |= MB_TYPE_SKIP;
969
13.9M
    } else {
970
9.48M
        mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P1L0 | MB_TYPE_SKIP;
971
972
9.48M
        fill_decode_neighbors(h, sl, mb_type);
973
9.48M
        pred_pskip_motion(h, sl);
974
9.48M
    }
975
976
23.4M
    write_back_motion(h, sl, mb_type);
977
23.4M
    h->cur_pic.mb_type[mb_xy]      = mb_type;
978
23.4M
    h->cur_pic.qscale_table[mb_xy] = sl->qscale;
979
23.4M
    h->slice_table[mb_xy]          = sl->slice_num;
980
23.4M
    sl->prev_mb_skipped            = 1;
981
23.4M
}
h264_cavlc.c:decode_mb_skip
Line
Count
Source
951
5.02M
{
952
5.02M
    const int mb_xy = sl->mb_xy;
953
5.02M
    int mb_type     = 0;
954
955
5.02M
    memset(h->non_zero_count[mb_xy], 0, 48);
956
957
5.02M
    if (MB_FIELD(sl))
958
2.32M
        mb_type |= MB_TYPE_INTERLACED;
959
960
5.02M
    if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
961
        // just for fill_caches. pred_direct_motion will set the real mb_type
962
1.21M
        mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 | MB_TYPE_SKIP;
963
1.21M
        if (sl->direct_spatial_mv_pred) {
964
356k
            fill_decode_neighbors(h, sl, mb_type);
965
356k
            fill_decode_caches(h, sl, mb_type); //FIXME check what is needed and what not ...
966
356k
        }
967
1.21M
        ff_h264_pred_direct_motion(h, sl, &mb_type);
968
1.21M
        mb_type |= MB_TYPE_SKIP;
969
3.80M
    } else {
970
3.80M
        mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P1L0 | MB_TYPE_SKIP;
971
972
3.80M
        fill_decode_neighbors(h, sl, mb_type);
973
3.80M
        pred_pskip_motion(h, sl);
974
3.80M
    }
975
976
5.02M
    write_back_motion(h, sl, mb_type);
977
5.02M
    h->cur_pic.mb_type[mb_xy]      = mb_type;
978
5.02M
    h->cur_pic.qscale_table[mb_xy] = sl->qscale;
979
5.02M
    h->slice_table[mb_xy]          = sl->slice_num;
980
5.02M
    sl->prev_mb_skipped            = 1;
981
5.02M
}
h264_cabac.c:decode_mb_skip
Line
Count
Source
951
18.3M
{
952
18.3M
    const int mb_xy = sl->mb_xy;
953
18.3M
    int mb_type     = 0;
954
955
18.3M
    memset(h->non_zero_count[mb_xy], 0, 48);
956
957
18.3M
    if (MB_FIELD(sl))
958
7.07M
        mb_type |= MB_TYPE_INTERLACED;
959
960
18.3M
    if (sl->slice_type_nos == AV_PICTURE_TYPE_B) {
961
        // just for fill_caches. pred_direct_motion will set the real mb_type
962
12.7M
        mb_type |= MB_TYPE_L0L1 | MB_TYPE_DIRECT2 | MB_TYPE_SKIP;
963
12.7M
        if (sl->direct_spatial_mv_pred) {
964
8.33M
            fill_decode_neighbors(h, sl, mb_type);
965
8.33M
            fill_decode_caches(h, sl, mb_type); //FIXME check what is needed and what not ...
966
8.33M
        }
967
12.7M
        ff_h264_pred_direct_motion(h, sl, &mb_type);
968
12.7M
        mb_type |= MB_TYPE_SKIP;
969
12.7M
    } else {
970
5.68M
        mb_type |= MB_TYPE_16x16 | MB_TYPE_P0L0 | MB_TYPE_P1L0 | MB_TYPE_SKIP;
971
972
5.68M
        fill_decode_neighbors(h, sl, mb_type);
973
5.68M
        pred_pskip_motion(h, sl);
974
5.68M
    }
975
976
18.3M
    write_back_motion(h, sl, mb_type);
977
18.3M
    h->cur_pic.mb_type[mb_xy]      = mb_type;
978
18.3M
    h->cur_pic.qscale_table[mb_xy] = sl->qscale;
979
18.3M
    h->slice_table[mb_xy]          = sl->slice_num;
980
18.3M
    sl->prev_mb_skipped            = 1;
981
18.3M
}
982
983
#endif /* AVCODEC_H264_MVPRED_H */