FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/cavsdec.c
Date: 2024-07-26 21:54:09
Exec Total Coverage
Lines: 475 569 83.5%
Functions: 18 19 94.7%
Branches: 277 368 75.3%

Line Branch Exec Source
1 /*
2 * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
3 * Copyright (c) 2006 Stefan Gehrer <stefan.gehrer@gmx.de>
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 * Chinese AVS video (AVS1-P2, JiZhun profile) decoder
25 * @author Stefan Gehrer <stefan.gehrer@gmx.de>
26 */
27
28 #include "libavutil/avassert.h"
29 #include "libavutil/emms.h"
30 #include "libavutil/mem.h"
31 #include "avcodec.h"
32 #include "get_bits.h"
33 #include "golomb.h"
34 #include "cavs.h"
35 #include "codec_internal.h"
36 #include "decode.h"
37 #include "mathops.h"
38 #include "mpeg12data.h"
39 #include "startcode.h"
40
41 static const uint8_t mv_scan[4] = {
42 MV_FWD_X0, MV_FWD_X1,
43 MV_FWD_X2, MV_FWD_X3
44 };
45
46 static const uint8_t cbp_tab[64][2] = {
47 { 63, 0 }, { 15, 15 }, { 31, 63 }, { 47, 31 }, { 0, 16 }, { 14, 32 }, { 13, 47 }, { 11, 13 },
48 { 7, 14 }, { 5, 11 }, { 10, 12 }, { 8, 5 }, { 12, 10 }, { 61, 7 }, { 4, 48 }, { 55, 3 },
49 { 1, 2 }, { 2, 8 }, { 59, 4 }, { 3, 1 }, { 62, 61 }, { 9, 55 }, { 6, 59 }, { 29, 62 },
50 { 45, 29 }, { 51, 27 }, { 23, 23 }, { 39, 19 }, { 27, 30 }, { 46, 28 }, { 53, 9 }, { 30, 6 },
51 { 43, 60 }, { 37, 21 }, { 60, 44 }, { 16, 26 }, { 21, 51 }, { 28, 35 }, { 19, 18 }, { 35, 20 },
52 { 42, 24 }, { 26, 53 }, { 44, 17 }, { 32, 37 }, { 58, 39 }, { 24, 45 }, { 20, 58 }, { 17, 43 },
53 { 18, 42 }, { 48, 46 }, { 22, 36 }, { 33, 33 }, { 25, 34 }, { 49, 40 }, { 40, 52 }, { 36, 49 },
54 { 34, 50 }, { 50, 56 }, { 52, 25 }, { 54, 22 }, { 41, 54 }, { 56, 57 }, { 38, 41 }, { 57, 38 }
55 };
56
57 static const uint8_t scan3x3[4] = { 4, 5, 7, 8 };
58
59 static const uint8_t dequant_shift[64] = {
60 14, 14, 14, 14, 14, 14, 14, 14,
61 13, 13, 13, 13, 13, 13, 13, 13,
62 13, 12, 12, 12, 12, 12, 12, 12,
63 11, 11, 11, 11, 11, 11, 11, 11,
64 11, 10, 10, 10, 10, 10, 10, 10,
65 10, 9, 9, 9, 9, 9, 9, 9,
66 9, 8, 8, 8, 8, 8, 8, 8,
67 7, 7, 7, 7, 7, 7, 7, 7
68 };
69
70 static const uint16_t dequant_mul[64] = {
71 32768, 36061, 38968, 42495, 46341, 50535, 55437, 60424,
72 32932, 35734, 38968, 42495, 46177, 50535, 55109, 59933,
73 65535, 35734, 38968, 42577, 46341, 50617, 55027, 60097,
74 32809, 35734, 38968, 42454, 46382, 50576, 55109, 60056,
75 65535, 35734, 38968, 42495, 46320, 50515, 55109, 60076,
76 65535, 35744, 38968, 42495, 46341, 50535, 55099, 60087,
77 65535, 35734, 38973, 42500, 46341, 50535, 55109, 60097,
78 32771, 35734, 38965, 42497, 46341, 50535, 55109, 60099
79 };
80
81 #define EOB 0, 0, 0
82
83 static const struct dec_2dvlc intra_dec[7] = {
84 {
85 { //level / run / table_inc
86 { 1, 1, 1 }, { -1, 1, 1 }, { 1, 2, 1 }, { -1, 2, 1 }, { 1, 3, 1 }, { -1, 3, 1 },
87 { 1, 4, 1 }, { -1, 4, 1 }, { 1, 5, 1 }, { -1, 5, 1 }, { 1, 6, 1 }, { -1, 6, 1 },
88 { 1, 7, 1 }, { -1, 7, 1 }, { 1, 8, 1 }, { -1, 8, 1 }, { 1, 9, 1 }, { -1, 9, 1 },
89 { 1, 10, 1 }, { -1, 10, 1 }, { 1, 11, 1 }, { -1, 11, 1 }, { 2, 1, 2 }, { -2, 1, 2 },
90 { 1, 12, 1 }, { -1, 12, 1 }, { 1, 13, 1 }, { -1, 13, 1 }, { 1, 14, 1 }, { -1, 14, 1 },
91 { 1, 15, 1 }, { -1, 15, 1 }, { 2, 2, 2 }, { -2, 2, 2 }, { 1, 16, 1 }, { -1, 16, 1 },
92 { 1, 17, 1 }, { -1, 17, 1 }, { 3, 1, 3 }, { -3, 1, 3 }, { 1, 18, 1 }, { -1, 18, 1 },
93 { 1, 19, 1 }, { -1, 19, 1 }, { 2, 3, 2 }, { -2, 3, 2 }, { 1, 20, 1 }, { -1, 20, 1 },
94 { 1, 21, 1 }, { -1, 21, 1 }, { 2, 4, 2 }, { -2, 4, 2 }, { 1, 22, 1 }, { -1, 22, 1 },
95 { 2, 5, 2 }, { -2, 5, 2 }, { 1, 23, 1 }, { -1, 23, 1 }, { EOB }
96 },
97 //level_add
98 { 0, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1 },
99 2, //golomb_order
100 0, //inc_limit
101 23, //max_run
102 },
103 {
104 { //level / run
105 { 1, 1, 0 }, { -1, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 2, 1, 1 }, { -2, 1, 1 },
106 { 1, 3, 0 }, { -1, 3, 0 }, { EOB }, { 1, 4, 0 }, { -1, 4, 0 }, { 1, 5, 0 },
107 { -1, 5, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 3, 1, 2 }, { -3, 1, 2 }, { 2, 2, 1 },
108 { -2, 2, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 1, 8, 0 }, { -1, 8, 0 }, { 1, 9, 0 },
109 { -1, 9, 0 }, { 2, 3, 1 }, { -2, 3, 1 }, { 4, 1, 2 }, { -4, 1, 2 }, { 1, 10, 0 },
110 { -1, 10, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 2, 4, 1 }, { -2, 4, 1 }, { 3, 2, 2 },
111 { -3, 2, 2 }, { 1, 12, 0 }, { -1, 12, 0 }, { 2, 5, 1 }, { -2, 5, 1 }, { 5, 1, 3 },
112 { -5, 1, 3 }, { 1, 13, 0 }, { -1, 13, 0 }, { 2, 6, 1 }, { -2, 6, 1 }, { 1, 14, 0 },
113 { -1, 14, 0 }, { 2, 7, 1 }, { -2, 7, 1 }, { 2, 8, 1 }, { -2, 8, 1 }, { 3, 3, 2 },
114 { -3, 3, 2 }, { 6, 1, 3 }, { -6, 1, 3 }, { 1, 15, 0 }, { -1, 15, 0 }
115 },
116 //level_add
117 { 0, 7, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
118 2, //golomb_order
119 1, //inc_limit
120 15, //max_run
121 },
122 {
123 { //level / run
124 { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 },
125 { 3, 1, 1 }, { -3, 1, 1 }, { EOB }, { 1, 3, 0 }, { -1, 3, 0 }, { 2, 2, 0 },
126 { -2, 2, 0 }, { 4, 1, 1 }, { -4, 1, 1 }, { 1, 4, 0 }, { -1, 4, 0 }, { 5, 1, 2 },
127 { -5, 1, 2 }, { 1, 5, 0 }, { -1, 5, 0 }, { 3, 2, 1 }, { -3, 2, 1 }, { 2, 3, 0 },
128 { -2, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 6, 1, 2 }, { -6, 1, 2 }, { 2, 4, 0 },
129 { -2, 4, 0 }, { 1, 7, 0 }, { -1, 7, 0 }, { 4, 2, 1 }, { -4, 2, 1 }, { 7, 1, 2 },
130 { -7, 1, 2 }, { 3, 3, 1 }, { -3, 3, 1 }, { 2, 5, 0 }, { -2, 5, 0 }, { 1, 8, 0 },
131 { -1, 8, 0 }, { 2, 6, 0 }, { -2, 6, 0 }, { 8, 1, 3 }, { -8, 1, 3 }, { 1, 9, 0 },
132 { -1, 9, 0 }, { 5, 2, 2 }, { -5, 2, 2 }, { 3, 4, 1 }, { -3, 4, 1 }, { 2, 7, 0 },
133 { -2, 7, 0 }, { 9, 1, 3 }, { -9, 1, 3 }, { 1, 10, 0 }, { -1, 10, 0 }
134 },
135 //level_add
136 { 0, 10, 6, 4, 4, 3, 3, 3, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
137 2, //golomb_order
138 2, //inc_limit
139 10, //max_run
140 },
141 {
142 { //level / run
143 { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 }, { -3, 1, 0 },
144 { 1, 2, 0 }, { -1, 2, 0 }, { EOB }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 1 },
145 { -5, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 6, 1, 1 },
146 { -6, 1, 1 }, { 3, 2, 0 }, { -3, 2, 0 }, { 7, 1, 1 }, { -7, 1, 1 }, { 1, 4, 0 },
147 { -1, 4, 0 }, { 8, 1, 2 }, { -8, 1, 2 }, { 2, 3, 0 }, { -2, 3, 0 }, { 4, 2, 0 },
148 { -4, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 9, 1, 2 }, { -9, 1, 2 }, { 5, 2, 1 },
149 { -5, 2, 1 }, { 2, 4, 0 }, { -2, 4, 0 }, { 10, 1, 2 }, {-10, 1, 2 }, { 3, 3, 0 },
150 { -3, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 11, 1, 3 }, {-11, 1, 3 }, { 6, 2, 1 },
151 { -6, 2, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 2, 5, 0 }, { -2, 5, 0 }, { 3, 4, 0 },
152 { -3, 4, 0 }, { 12, 1, 3 }, {-12, 1, 3 }, { 4, 3, 0 }, { -4, 3, 0 }
153 },
154 //level_add
155 { 0, 13, 7, 5, 4, 3, 2, 2, -1, -1, -1 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
156 2, //golomb_order
157 4, //inc_limit
158 7, //max_run
159 },
160 {
161 { //level / run
162 { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 }, { -3, 1, 0 },
163 { EOB }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
164 { -6, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 1 },
165 { -8, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 9, 1, 1 }, { -9, 1, 1 }, { 10, 1, 1 },
166 {-10, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 11, 1, 2 },
167 {-11, 1, 2 }, { 4, 2, 0 }, { -4, 2, 0 }, { 12, 1, 2 }, {-12, 1, 2 }, { 13, 1, 2 },
168 {-13, 1, 2 }, { 5, 2, 0 }, { -5, 2, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 2, 3, 0 },
169 { -2, 3, 0 }, { 14, 1, 2 }, {-14, 1, 2 }, { 6, 2, 0 }, { -6, 2, 0 }, { 15, 1, 2 },
170 {-15, 1, 2 }, { 16, 1, 2 }, {-16, 1, 2 }, { 3, 3, 0 }, { -3, 3, 0 }, { 1, 5, 0 },
171 { -1, 5, 0 }, { 7, 2, 0 }, { -7, 2, 0 }, { 17, 1, 2 }, {-17, 1, 2 }
172 },
173 //level_add
174 { 0,18, 8, 4, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
175 2, //golomb_order
176 7, //inc_limit
177 5, //max_run
178 },
179 {
180 { //level / run
181 { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
182 { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
183 { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 }, { -8, 1, 0 }, { 9, 1, 0 },
184 { -9, 1, 0 }, { 10, 1, 0 }, {-10, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 11, 1, 1 },
185 {-11, 1, 1 }, { 12, 1, 1 }, {-12, 1, 1 }, { 13, 1, 1 }, {-13, 1, 1 }, { 2, 2, 0 },
186 { -2, 2, 0 }, { 14, 1, 1 }, {-14, 1, 1 }, { 15, 1, 1 }, {-15, 1, 1 }, { 3, 2, 0 },
187 { -3, 2, 0 }, { 16, 1, 1 }, {-16, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 17, 1, 1 },
188 {-17, 1, 1 }, { 4, 2, 0 }, { -4, 2, 0 }, { 18, 1, 1 }, {-18, 1, 1 }, { 5, 2, 0 },
189 { -5, 2, 0 }, { 19, 1, 1 }, {-19, 1, 1 }, { 20, 1, 1 }, {-20, 1, 1 }, { 6, 2, 0 },
190 { -6, 2, 0 }, { 21, 1, 1 }, {-21, 1, 1 }, { 2, 3, 0 }, { -2, 3, 0 }
191 },
192 //level_add
193 { 0, 22, 7, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
194 2, //golomb_order
195 10, //inc_limit
196 3, //max_run
197 },
198 {
199 { //level / run
200 { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
201 { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
202 { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 }, { -8, 1, 0 }, { 9, 1, 0 },
203 { -9, 1, 0 }, { 10, 1, 0 }, {-10, 1, 0 }, { 11, 1, 0 }, {-11, 1, 0 }, { 12, 1, 0 },
204 {-12, 1, 0 }, { 13, 1, 0 }, {-13, 1, 0 }, { 14, 1, 0 }, {-14, 1, 0 }, { 15, 1, 0 },
205 {-15, 1, 0 }, { 16, 1, 0 }, {-16, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 17, 1, 0 },
206 {-17, 1, 0 }, { 18, 1, 0 }, {-18, 1, 0 }, { 19, 1, 0 }, {-19, 1, 0 }, { 20, 1, 0 },
207 {-20, 1, 0 }, { 21, 1, 0 }, {-21, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 22, 1, 0 },
208 {-22, 1, 0 }, { 23, 1, 0 }, {-23, 1, 0 }, { 24, 1, 0 }, {-24, 1, 0 }, { 25, 1, 0 },
209 {-25, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 26, 1, 0 }, {-26, 1, 0 }
210 },
211 //level_add
212 { 0, 27, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
213 2, //golomb_order
214 INT_MAX, //inc_limit
215 2, //max_run
216 }
217 };
218
219 static const struct dec_2dvlc inter_dec[7] = {
220 {
221 { //level / run
222 { 1, 1, 1 }, { -1, 1, 1 }, { 1, 2, 1 }, { -1, 2, 1 }, { 1, 3, 1 }, { -1, 3, 1 },
223 { 1, 4, 1 }, { -1, 4, 1 }, { 1, 5, 1 }, { -1, 5, 1 }, { 1, 6, 1 }, { -1, 6, 1 },
224 { 1, 7, 1 }, { -1, 7, 1 }, { 1, 8, 1 }, { -1, 8, 1 }, { 1, 9, 1 }, { -1, 9, 1 },
225 { 1, 10, 1 }, { -1, 10, 1 }, { 1, 11, 1 }, { -1, 11, 1 }, { 1, 12, 1 }, { -1, 12, 1 },
226 { 1, 13, 1 }, { -1, 13, 1 }, { 2, 1, 2 }, { -2, 1, 2 }, { 1, 14, 1 }, { -1, 14, 1 },
227 { 1, 15, 1 }, { -1, 15, 1 }, { 1, 16, 1 }, { -1, 16, 1 }, { 1, 17, 1 }, { -1, 17, 1 },
228 { 1, 18, 1 }, { -1, 18, 1 }, { 1, 19, 1 }, { -1, 19, 1 }, { 3, 1, 3 }, { -3, 1, 3 },
229 { 1, 20, 1 }, { -1, 20, 1 }, { 1, 21, 1 }, { -1, 21, 1 }, { 2, 2, 2 }, { -2, 2, 2 },
230 { 1, 22, 1 }, { -1, 22, 1 }, { 1, 23, 1 }, { -1, 23, 1 }, { 1, 24, 1 }, { -1, 24, 1 },
231 { 1, 25, 1 }, { -1, 25, 1 }, { 1, 26, 1 }, { -1, 26, 1 }, { EOB }
232 },
233 //level_add
234 { 0, 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
235 3, //golomb_order
236 0, //inc_limit
237 26 //max_run
238 },
239 {
240 { //level / run
241 { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 1, 2, 0 }, { -1, 2, 0 }, { 1, 3, 0 },
242 { -1, 3, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 1, 6, 0 },
243 { -1, 6, 0 }, { 2, 1, 1 }, { -2, 1, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 1, 8, 0 },
244 { -1, 8, 0 }, { 1, 9, 0 }, { -1, 9, 0 }, { 1, 10, 0 }, { -1, 10, 0 }, { 2, 2, 1 },
245 { -2, 2, 1 }, { 1, 11, 0 }, { -1, 11, 0 }, { 1, 12, 0 }, { -1, 12, 0 }, { 3, 1, 2 },
246 { -3, 1, 2 }, { 1, 13, 0 }, { -1, 13, 0 }, { 1, 14, 0 }, { -1, 14, 0 }, { 2, 3, 1 },
247 { -2, 3, 1 }, { 1, 15, 0 }, { -1, 15, 0 }, { 2, 4, 1 }, { -2, 4, 1 }, { 1, 16, 0 },
248 { -1, 16, 0 }, { 2, 5, 1 }, { -2, 5, 1 }, { 1, 17, 0 }, { -1, 17, 0 }, { 4, 1, 3 },
249 { -4, 1, 3 }, { 2, 6, 1 }, { -2, 6, 1 }, { 1, 18, 0 }, { -1, 18, 0 }, { 1, 19, 0 },
250 { -1, 19, 0 }, { 2, 7, 1 }, { -2, 7, 1 }, { 3, 2, 2 }, { -3, 2, 2 }
251 },
252 //level_add
253 { 0, 5, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1 },
254 2, //golomb_order
255 1, //inc_limit
256 19 //max_run
257 },
258 {
259 { //level / run
260 { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 1, 2, 0 }, { -1, 2, 0 }, { 2, 1, 0 },
261 { -2, 1, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 3, 1, 1 },
262 { -3, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 1, 6, 0 },
263 { -1, 6, 0 }, { 1, 7, 0 }, { -1, 7, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 4, 1, 2 },
264 { -4, 1, 2 }, { 1, 8, 0 }, { -1, 8, 0 }, { 3, 2, 1 }, { -3, 2, 1 }, { 2, 4, 0 },
265 { -2, 4, 0 }, { 1, 9, 0 }, { -1, 9, 0 }, { 1, 10, 0 }, { -1, 10, 0 }, { 5, 1, 2 },
266 { -5, 1, 2 }, { 2, 5, 0 }, { -2, 5, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 2, 6, 0 },
267 { -2, 6, 0 }, { 1, 12, 0 }, { -1, 12, 0 }, { 3, 3, 1 }, { -3, 3, 1 }, { 6, 1, 2 },
268 { -6, 1, 2 }, { 4, 2, 2 }, { -4, 2, 2 }, { 1, 13, 0 }, { -1, 13, 0 }, { 2, 7, 0 },
269 { -2, 7, 0 }, { 3, 4, 1 }, { -3, 4, 1 }, { 1, 14, 0 }, { -1, 14, 0 }
270 },
271 //level_add
272 { 0, 7, 5, 4, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
273 2, //golomb_order
274 2, //inc_limit
275 14 //max_run
276 },
277 {
278 { //level / run
279 { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 2, 1, 0 }, { -2, 1, 0 }, { 1, 2, 0 },
280 { -1, 2, 0 }, { 3, 1, 0 }, { -3, 1, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 2, 2, 0 },
281 { -2, 2, 0 }, { 4, 1, 1 }, { -4, 1, 1 }, { 1, 4, 0 }, { -1, 4, 0 }, { 5, 1, 1 },
282 { -5, 1, 1 }, { 1, 5, 0 }, { -1, 5, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 2, 3, 0 },
283 { -2, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 6, 1, 1 }, { -6, 1, 1 }, { 2, 4, 0 },
284 { -2, 4, 0 }, { 1, 7, 0 }, { -1, 7, 0 }, { 4, 2, 1 }, { -4, 2, 1 }, { 7, 1, 2 },
285 { -7, 1, 2 }, { 3, 3, 0 }, { -3, 3, 0 }, { 1, 8, 0 }, { -1, 8, 0 }, { 2, 5, 0 },
286 { -2, 5, 0 }, { 8, 1, 2 }, { -8, 1, 2 }, { 1, 9, 0 }, { -1, 9, 0 }, { 3, 4, 0 },
287 { -3, 4, 0 }, { 2, 6, 0 }, { -2, 6, 0 }, { 5, 2, 1 }, { -5, 2, 1 }, { 1, 10, 0 },
288 { -1, 10, 0 }, { 9, 1, 2 }, { -9, 1, 2 }, { 4, 3, 1 }, { -4, 3, 1 }
289 },
290 //level_add
291 { 0,10, 6, 5, 4, 3, 3, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
292 2, //golomb_order
293 3, //inc_limit
294 10 //max_run
295 },
296 {
297 { //level / run
298 { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
299 { -3, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 },
300 { -5, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 6, 1, 0 },
301 { -6, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 7, 1, 1 }, { -7, 1, 1 }, { 1, 4, 0 },
302 { -1, 4, 0 }, { 8, 1, 1 }, { -8, 1, 1 }, { 2, 3, 0 }, { -2, 3, 0 }, { 4, 2, 0 },
303 { -4, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 9, 1, 1 }, { -9, 1, 1 }, { 5, 2, 0 },
304 { -5, 2, 0 }, { 2, 4, 0 }, { -2, 4, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 10, 1, 2 },
305 {-10, 1, 2 }, { 3, 3, 0 }, { -3, 3, 0 }, { 11, 1, 2 }, {-11, 1, 2 }, { 1, 7, 0 },
306 { -1, 7, 0 }, { 6, 2, 0 }, { -6, 2, 0 }, { 3, 4, 0 }, { -3, 4, 0 }, { 2, 5, 0 },
307 { -2, 5, 0 }, { 12, 1, 2 }, {-12, 1, 2 }, { 4, 3, 0 }, { -4, 3, 0 }
308 },
309 //level_add
310 { 0, 13, 7, 5, 4, 3, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
311 2, //golomb_order
312 6, //inc_limit
313 7 //max_run
314 },
315 {
316 { //level / run
317 { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
318 { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 1, 2, 0 },
319 { -1, 2, 0 }, { 6, 1, 0 }, { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 },
320 { -8, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 9, 1, 0 }, { -9, 1, 0 }, { 1, 3, 0 },
321 { -1, 3, 0 }, { 10, 1, 1 }, { -10, 1, 1 }, { 3, 2, 0 }, { -3, 2, 0 }, { 11, 1, 1 },
322 { -11, 1, 1 }, { 4, 2, 0 }, { -4, 2, 0 }, { 12, 1, 1 }, { -12, 1, 1 }, { 1, 4, 0 },
323 { -1, 4, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 13, 1, 1 }, { -13, 1, 1 }, { 5, 2, 0 },
324 { -5, 2, 0 }, { 14, 1, 1 }, { -14, 1, 1 }, { 6, 2, 0 }, { -6, 2, 0 }, { 1, 5, 0 },
325 { -1, 5, 0 }, { 15, 1, 1 }, { -15, 1, 1 }, { 3, 3, 0 }, { -3, 3, 0 }, { 16, 1, 1 },
326 { -16, 1, 1 }, { 2, 4, 0 }, { -2, 4, 0 }, { 7, 2, 0 }, { -7, 2, 0 }
327 },
328 //level_add
329 { 0, 17, 8, 4, 3, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
330 2, //golomb_order
331 9, //inc_limit
332 5 //max_run
333 },
334 {
335 { //level / run
336 { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
337 { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
338 { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 8, 1, 0 },
339 { -8, 1, 0 }, { 9, 1, 0 }, { -9, 1, 0 }, { 10, 1, 0 }, { -10, 1, 0 }, { 11, 1, 0 },
340 { -11, 1, 0 }, { 12, 1, 0 }, { -12, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 13, 1, 0 },
341 { -13, 1, 0 }, { 1, 3, 0 }, { -1, 3, 0 }, { 14, 1, 0 }, { -14, 1, 0 }, { 15, 1, 0 },
342 { -15, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 16, 1, 0 }, { -16, 1, 0 }, { 17, 1, 0 },
343 { -17, 1, 0 }, { 18, 1, 0 }, { -18, 1, 0 }, { 4, 2, 0 }, { -4, 2, 0 }, { 19, 1, 0 },
344 { -19, 1, 0 }, { 20, 1, 0 }, { -20, 1, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 1, 4, 0 },
345 { -1, 4, 0 }, { 5, 2, 0 }, { -5, 2, 0 }, { 21, 1, 0 }, { -21, 1, 0 }
346 },
347 //level_add
348 { 0, 22, 6, 3, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
349 2, //golomb_order
350 INT_MAX, //inc_limit
351 4 //max_run
352 }
353 };
354
355 static const struct dec_2dvlc chroma_dec[5] = {
356 {
357 { //level / run
358 { 1, 1, 1 }, { -1, 1, 1 }, { 1, 2, 1 }, { -1, 2, 1 }, { 1, 3, 1 }, { -1, 3, 1 },
359 { 1, 4, 1 }, { -1, 4, 1 }, { 1, 5, 1 }, { -1, 5, 1 }, { 1, 6, 1 }, { -1, 6, 1 },
360 { 1, 7, 1 }, { -1, 7, 1 }, { 2, 1, 2 }, { -2, 1, 2 }, { 1, 8, 1 }, { -1, 8, 1 },
361 { 1, 9, 1 }, { -1, 9, 1 }, { 1, 10, 1 }, { -1, 10, 1 }, { 1, 11, 1 }, { -1, 11, 1 },
362 { 1, 12, 1 }, { -1, 12, 1 }, { 1, 13, 1 }, { -1, 13, 1 }, { 1, 14, 1 }, { -1, 14, 1 },
363 { 1, 15, 1 }, { -1, 15, 1 }, { 3, 1, 3 }, { -3, 1, 3 }, { 1, 16, 1 }, { -1, 16, 1 },
364 { 1, 17, 1 }, { -1, 17, 1 }, { 1, 18, 1 }, { -1, 18, 1 }, { 1, 19, 1 }, { -1, 19, 1 },
365 { 1, 20, 1 }, { -1, 20, 1 }, { 1, 21, 1 }, { -1, 21, 1 }, { 1, 22, 1 }, { -1, 22, 1 },
366 { 2, 2, 2 }, { -2, 2, 2 }, { 1, 23, 1 }, { -1, 23, 1 }, { 1, 24, 1 }, { -1, 24, 1 },
367 { 1, 25, 1 }, { -1, 25, 1 }, { 4, 1, 3 }, { -4, 1, 3 }, { EOB }
368 },
369 //level_add
370 { 0, 5, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1 },
371 2, //golomb_order
372 0, //inc_limit
373 25 //max_run
374 },
375 {
376 { //level / run
377 { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 2, 1, 1 },
378 { -2, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 1, 5, 0 },
379 { -1, 5, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 3, 1, 2 }, { -3, 1, 2 }, { 1, 7, 0 },
380 { -1, 7, 0 }, { 1, 8, 0 }, { -1, 8, 0 }, { 2, 2, 1 }, { -2, 2, 1 }, { 1, 9, 0 },
381 { -1, 9, 0 }, { 1, 10, 0 }, { -1, 10, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 4, 1, 2 },
382 { -4, 1, 2 }, { 1, 12, 0 }, { -1, 12, 0 }, { 1, 13, 0 }, { -1, 13, 0 }, { 1, 14, 0 },
383 { -1, 14, 0 }, { 2, 3, 1 }, { -2, 3, 1 }, { 1, 15, 0 }, { -1, 15, 0 }, { 2, 4, 1 },
384 { -2, 4, 1 }, { 5, 1, 3 }, { -5, 1, 3 }, { 3, 2, 2 }, { -3, 2, 2 }, { 1, 16, 0 },
385 { -1, 16, 0 }, { 1, 17, 0 }, { -1, 17, 0 }, { 1, 18, 0 }, { -1, 18, 0 }, { 2, 5, 1 },
386 { -2, 5, 1 }, { 1, 19, 0 }, { -1, 19, 0 }, { 1, 20, 0 }, { -1, 20, 0 }
387 },
388 //level_add
389 { 0, 6, 4, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1 },
390 0, //golomb_order
391 1, //inc_limit
392 20 //max_run
393 },
394 {
395 { //level / run
396 { 1, 1, 0 }, { -1, 1, 0 }, { EOB }, { 2, 1, 0 }, { -2, 1, 0 }, { 1, 2, 0 },
397 { -1, 2, 0 }, { 3, 1, 1 }, { -3, 1, 1 }, { 1, 3, 0 }, { -1, 3, 0 }, { 4, 1, 1 },
398 { -4, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 1, 4, 0 }, { -1, 4, 0 }, { 5, 1, 2 },
399 { -5, 1, 2 }, { 1, 5, 0 }, { -1, 5, 0 }, { 3, 2, 1 }, { -3, 2, 1 }, { 2, 3, 0 },
400 { -2, 3, 0 }, { 1, 6, 0 }, { -1, 6, 0 }, { 6, 1, 2 }, { -6, 1, 2 }, { 1, 7, 0 },
401 { -1, 7, 0 }, { 2, 4, 0 }, { -2, 4, 0 }, { 7, 1, 2 }, { -7, 1, 2 }, { 1, 8, 0 },
402 { -1, 8, 0 }, { 4, 2, 1 }, { -4, 2, 1 }, { 1, 9, 0 }, { -1, 9, 0 }, { 3, 3, 1 },
403 { -3, 3, 1 }, { 2, 5, 0 }, { -2, 5, 0 }, { 2, 6, 0 }, { -2, 6, 0 }, { 8, 1, 2 },
404 { -8, 1, 2 }, { 1, 10, 0 }, { -1, 10, 0 }, { 1, 11, 0 }, { -1, 11, 0 }, { 9, 1, 2 },
405 { -9, 1, 2 }, { 5, 2, 2 }, { -5, 2, 2 }, { 3, 4, 1 }, { -3, 4, 1 },
406 },
407 //level_add
408 { 0,10, 6, 4, 4, 3, 3, 2, 2, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
409 1, //golomb_order
410 2, //inc_limit
411 11 //max_run
412 },
413 {
414 { //level / run
415 { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
416 { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 1, 2, 0 }, { -1, 2, 0 }, { 5, 1, 1 },
417 { -5, 1, 1 }, { 2, 2, 0 }, { -2, 2, 0 }, { 6, 1, 1 }, { -6, 1, 1 }, { 1, 3, 0 },
418 { -1, 3, 0 }, { 7, 1, 1 }, { -7, 1, 1 }, { 3, 2, 0 }, { -3, 2, 0 }, { 8, 1, 1 },
419 { -8, 1, 1 }, { 1, 4, 0 }, { -1, 4, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 9, 1, 1 },
420 { -9, 1, 1 }, { 4, 2, 0 }, { -4, 2, 0 }, { 1, 5, 0 }, { -1, 5, 0 }, { 10, 1, 1 },
421 {-10, 1, 1 }, { 3, 3, 0 }, { -3, 3, 0 }, { 5, 2, 1 }, { -5, 2, 1 }, { 2, 4, 0 },
422 { -2, 4, 0 }, { 11, 1, 1 }, {-11, 1, 1 }, { 1, 6, 0 }, { -1, 6, 0 }, { 12, 1, 1 },
423 {-12, 1, 1 }, { 1, 7, 0 }, { -1, 7, 0 }, { 6, 2, 1 }, { -6, 2, 1 }, { 13, 1, 1 },
424 {-13, 1, 1 }, { 2, 5, 0 }, { -2, 5, 0 }, { 1, 8, 0 }, { -1, 8, 0 },
425 },
426 //level_add
427 { 0, 14, 7, 4, 3, 3, 2, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
428 1, //golomb_order
429 4, //inc_limit
430 8 //max_run
431 },
432 {
433 { //level / run
434 { EOB }, { 1, 1, 0 }, { -1, 1, 0 }, { 2, 1, 0 }, { -2, 1, 0 }, { 3, 1, 0 },
435 { -3, 1, 0 }, { 4, 1, 0 }, { -4, 1, 0 }, { 5, 1, 0 }, { -5, 1, 0 }, { 6, 1, 0 },
436 { -6, 1, 0 }, { 7, 1, 0 }, { -7, 1, 0 }, { 8, 1, 0 }, { -8, 1, 0 }, { 1, 2, 0 },
437 { -1, 2, 0 }, { 9, 1, 0 }, { -9, 1, 0 }, { 10, 1, 0 }, { -10, 1, 0 }, { 11, 1, 0 },
438 { -11, 1, 0 }, { 2, 2, 0 }, { -2, 2, 0 }, { 12, 1, 0 }, { -12, 1, 0 }, { 13, 1, 0 },
439 { -13, 1, 0 }, { 3, 2, 0 }, { -3, 2, 0 }, { 14, 1, 0 }, { -14, 1, 0 }, { 1, 3, 0 },
440 { -1, 3, 0 }, { 15, 1, 0 }, { -15, 1, 0 }, { 4, 2, 0 }, { -4, 2, 0 }, { 16, 1, 0 },
441 { -16, 1, 0 }, { 17, 1, 0 }, { -17, 1, 0 }, { 5, 2, 0 }, { -5, 2, 0 }, { 1, 4, 0 },
442 { -1, 4, 0 }, { 2, 3, 0 }, { -2, 3, 0 }, { 18, 1, 0 }, { -18, 1, 0 }, { 6, 2, 0 },
443 { -6, 2, 0 }, { 19, 1, 0 }, { -19, 1, 0 }, { 1, 5, 0 }, { -1, 5, 0 },
444 },
445 //level_add
446 { 0, 20, 7, 3, 2, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
447 0, //golomb_order
448 INT_MAX, //inc_limit
449 5, //max_run
450 }
451 };
452
453 #undef EOB
454
455 /*****************************************************************************
456 *
457 * motion vector prediction
458 *
459 ****************************************************************************/
460
461 83018 static inline void store_mvs(AVSContext *h)
462 {
463 83018 h->col_mv[h->mbidx * 4 + 0] = h->mv[MV_FWD_X0];
464 83018 h->col_mv[h->mbidx * 4 + 1] = h->mv[MV_FWD_X1];
465 83018 h->col_mv[h->mbidx * 4 + 2] = h->mv[MV_FWD_X2];
466 83018 h->col_mv[h->mbidx * 4 + 3] = h->mv[MV_FWD_X3];
467 83018 }
468
469 526000 static inline void mv_pred_direct(AVSContext *h, cavs_vector *pmv_fw,
470 cavs_vector *col_mv)
471 {
472 526000 cavs_vector *pmv_bw = pmv_fw + MV_BWD_OFFS;
473 526000 unsigned den = h->direct_den[col_mv->ref];
474 526000 int m = FF_SIGNBIT(col_mv->x);
475
476 526000 pmv_fw->dist = h->dist[1];
477 526000 pmv_bw->dist = h->dist[0];
478 526000 pmv_fw->ref = 1;
479 526000 pmv_bw->ref = 0;
480 /* scale the co-located motion vector according to its temporal span */
481 526000 pmv_fw->x = (((den + (den * col_mv->x * pmv_fw->dist ^ m) - m - 1) >> 14) ^ m) - m;
482 526000 pmv_bw->x = m - (((den + (den * col_mv->x * pmv_bw->dist ^ m) - m - 1) >> 14) ^ m);
483 526000 m = FF_SIGNBIT(col_mv->y);
484 526000 pmv_fw->y = (((den + (den * col_mv->y * pmv_fw->dist ^ m) - m - 1) >> 14) ^ m) - m;
485 526000 pmv_bw->y = m - (((den + (den * col_mv->y * pmv_bw->dist ^ m) - m - 1) >> 14) ^ m);
486 526000 }
487
488 28328 static inline void mv_pred_sym(AVSContext *h, cavs_vector *src,
489 enum cavs_block size)
490 {
491 28328 cavs_vector *dst = src + MV_BWD_OFFS;
492
493 /* backward mv is the scaled and negated forward mv */
494 28328 dst->x = -((src->x * h->sym_factor + 256) >> 9);
495 28328 dst->y = -((src->y * h->sym_factor + 256) >> 9);
496 28328 dst->ref = 0;
497 28328 dst->dist = h->dist[0];
498 28328 set_mvs(dst, size);
499 28328 }
500
501 /*****************************************************************************
502 *
503 * residual data decoding
504 *
505 ****************************************************************************/
506
507 /** kth-order exponential golomb code */
508 2791502 static inline int get_ue_code(GetBitContext *gb, int order)
509 {
510 2791502 unsigned ret = get_ue_golomb(gb);
511
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2791499 times.
2791502 if (ret >= ((1U<<31)>>order)) {
512 3 av_log(NULL, AV_LOG_ERROR, "get_ue_code: value too large\n");
513 3 return AVERROR_INVALIDDATA;
514 }
515
2/2
✓ Branch 0 taken 2402705 times.
✓ Branch 1 taken 388794 times.
2791499 if (order) {
516 2402705 return (ret<<order) + get_bits(gb, order);
517 }
518 388794 return ret;
519 }
520
521 358756 static inline int dequant(AVSContext *h, int16_t *level_buf, uint8_t *run_buf,
522 int16_t *dst, int mul, int shift, int coeff_num)
523 {
524 358756 int round = 1 << (shift - 1);
525 358756 int pos = -1;
526 358756 const uint8_t *scantab = h->permutated_scantable;
527
528 /* inverse scan and dequantization */
529
2/2
✓ Branch 0 taken 2359974 times.
✓ Branch 1 taken 358756 times.
2718730 while (--coeff_num >= 0) {
530 2359974 pos += run_buf[coeff_num];
531
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2359974 times.
2359974 if (pos > 63) {
532 av_log(h->avctx, AV_LOG_ERROR,
533 "position out of block bounds at pic %d MB(%d,%d)\n",
534 h->cur.poc, h->mbx, h->mby);
535 return AVERROR_INVALIDDATA;
536 }
537 2359974 dst[scantab[pos]] = (level_buf[coeff_num] * mul + round) >> shift;
538 }
539 358756 return 0;
540 }
541
542 /**
543 * decode coefficients from one 8x8 block, dequantize, inverse transform
544 * and add them to sample block
545 * @param r pointer to 2D VLC table
546 * @param esc_golomb_order escape codes are k-golomb with this order k
547 * @param qp quantizer
548 * @param dst location of sample block
549 * @param stride line stride in frame buffer
550 */
551 358759 static int decode_residual_block(AVSContext *h, GetBitContext *gb,
552 const struct dec_2dvlc *r, int esc_golomb_order,
553 int qp, uint8_t *dst, ptrdiff_t stride)
554 {
555 int i, esc_code, level, mask, ret;
556 unsigned int level_code, run;
557 int16_t level_buf[65];
558 uint8_t run_buf[65];
559 358759 int16_t *block = h->block;
560
561
1/2
✓ Branch 0 taken 2718736 times.
✗ Branch 1 not taken.
2718736 for (i = 0; i < 65; i++) {
562 2718736 level_code = get_ue_code(gb, r->golomb_order);
563
2/2
✓ Branch 0 taken 72769 times.
✓ Branch 1 taken 2645967 times.
2718736 if (level_code >= ESCAPE_CODE) {
564 72769 run = ((level_code - ESCAPE_CODE) >> 1) + 1;
565
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 72766 times.
72769 if(run > 64) {
566 3 av_log(h->avctx, AV_LOG_ERROR, "run %d is too large\n", run);
567 3 return AVERROR_INVALIDDATA;
568 }
569 72766 esc_code = get_ue_code(gb, esc_golomb_order);
570
2/4
✓ Branch 0 taken 72766 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 72766 times.
72766 if (esc_code < 0 || esc_code > 32767) {
571 av_log(h->avctx, AV_LOG_ERROR, "esc_code invalid\n");
572 return AVERROR_INVALIDDATA;
573 }
574
575
2/2
✓ Branch 0 taken 38482 times.
✓ Branch 1 taken 34284 times.
72766 level = esc_code + (run > r->max_run ? 1 : r->level_add[run]);
576
2/2
✓ Branch 0 taken 68851 times.
✓ Branch 1 taken 72766 times.
141617 while (level > r->inc_limit)
577 68851 r++;
578 72766 mask = -(level_code & 1);
579 72766 level = (level ^ mask) - mask;
580 } else {
581 2645967 level = r->rltab[level_code][0];
582
2/2
✓ Branch 0 taken 358756 times.
✓ Branch 1 taken 2287211 times.
2645967 if (!level) //end of block signal
583 358756 break;
584 2287211 run = r->rltab[level_code][1];
585 2287211 r += r->rltab[level_code][2];
586 }
587 2359977 level_buf[i] = level;
588 2359977 run_buf[i] = run;
589 }
590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 358756 times.
358756 if ((ret = dequant(h, level_buf, run_buf, block, dequant_mul[qp],
591 358756 dequant_shift[qp], i)) < 0)
592 return ret;
593 358756 h->cdsp.cavs_idct8_add(dst, block, stride);
594 358756 h->bdsp.clear_block(block);
595 358756 return 0;
596 }
597
598
599 174001 static inline int decode_residual_chroma(AVSContext *h)
600 {
601
2/2
✓ Branch 0 taken 63485 times.
✓ Branch 1 taken 110516 times.
174001 if (h->cbp & (1 << 4)) {
602 63485 int ret = decode_residual_block(h, &h->gb, chroma_dec, 0,
603 63485 ff_cavs_chroma_qp[h->qp], h->cu, h->c_stride);
604
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 63484 times.
63485 if (ret < 0)
605 1 return ret;
606 }
607
2/2
✓ Branch 0 taken 70783 times.
✓ Branch 1 taken 103217 times.
174000 if (h->cbp & (1 << 5)) {
608 70783 int ret = decode_residual_block(h, &h->gb, chroma_dec, 0,
609 70783 ff_cavs_chroma_qp[h->qp], h->cv, h->c_stride);
610
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 70783 times.
70783 if (ret < 0)
611 return ret;
612 }
613 174000 return 0;
614 }
615
616 144867 static inline int decode_residual_inter(AVSContext *h)
617 {
618 int block;
619
620 /* get coded block pattern */
621 144867 int cbp = get_ue_golomb(&h->gb);
622
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 144867 times.
144867 if (cbp > 63U) {
623 av_log(h->avctx, AV_LOG_ERROR, "illegal inter cbp %d\n", cbp);
624 return AVERROR_INVALIDDATA;
625 }
626 144867 h->cbp = cbp_tab[cbp][1];
627
628 /* get quantizer */
629
3/4
✓ Branch 0 taken 125275 times.
✓ Branch 1 taken 19592 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 125275 times.
144867 if (h->cbp && !h->qp_fixed)
630 h->qp = (h->qp + (unsigned)get_se_golomb(&h->gb)) & 63;
631
2/2
✓ Branch 0 taken 579468 times.
✓ Branch 1 taken 144867 times.
724335 for (block = 0; block < 4; block++)
632
2/2
✓ Branch 0 taken 181616 times.
✓ Branch 1 taken 397852 times.
579468 if (h->cbp & (1 << block))
633 181616 decode_residual_block(h, &h->gb, inter_dec, 0, h->qp,
634 181616 h->cy + h->luma_scan[block], h->l_stride);
635 144867 decode_residual_chroma(h);
636
637 144867 return 0;
638 }
639
640 /*****************************************************************************
641 *
642 * macroblock level
643 *
644 ****************************************************************************/
645
646 29134 static inline void set_mv_intra(AVSContext *h)
647 {
648 29134 h->mv[MV_FWD_X0] = ff_cavs_intra_mv;
649 29134 set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
650 29134 h->mv[MV_BWD_X0] = ff_cavs_intra_mv;
651 29134 set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
652
2/2
✓ Branch 0 taken 25882 times.
✓ Branch 1 taken 3252 times.
29134 if (h->cur.f->pict_type != AV_PICTURE_TYPE_B)
653 25882 h->col_type_base[h->mbidx] = I_8X8;
654 29134 }
655
656 29134 static int decode_mb_i(AVSContext *h, int cbp_code)
657 {
658 29134 GetBitContext *gb = &h->gb;
659 unsigned pred_mode_uv;
660 int block;
661 uint8_t top[18];
662 29134 uint8_t *left = NULL;
663 uint8_t *d;
664 int ret;
665
666 29134 ff_cavs_init_mb(h);
667
668 /* get intra prediction modes from stream */
669
2/2
✓ Branch 0 taken 116536 times.
✓ Branch 1 taken 29134 times.
145670 for (block = 0; block < 4; block++) {
670 int nA, nB, predpred;
671 116536 int pos = scan3x3[block];
672
673 116536 nA = h->pred_mode_Y[pos - 1];
674 116536 nB = h->pred_mode_Y[pos - 3];
675 116536 predpred = FFMIN(nA, nB);
676
2/2
✓ Branch 0 taken 2126 times.
✓ Branch 1 taken 114410 times.
116536 if (predpred == NOT_AVAIL) // if either is not available
677 2126 predpred = INTRA_L_LP;
678
2/2
✓ Branch 1 taken 23170 times.
✓ Branch 2 taken 93366 times.
116536 if (!get_bits1(gb)) {
679 23170 int rem_mode = get_bits(gb, 2);
680 23170 predpred = rem_mode + (rem_mode >= predpred);
681 }
682 116536 h->pred_mode_Y[pos] = predpred;
683 }
684 29134 pred_mode_uv = get_ue_golomb_31(gb);
685
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29134 times.
29134 if (pred_mode_uv > 6) {
686 av_log(h->avctx, AV_LOG_ERROR, "illegal intra chroma pred mode\n");
687 return AVERROR_INVALIDDATA;
688 }
689 29134 ff_cavs_modify_mb_i(h, &pred_mode_uv);
690
691 /* get coded block pattern */
692
2/2
✓ Branch 0 taken 18180 times.
✓ Branch 1 taken 10954 times.
29134 if (h->cur.f->pict_type == AV_PICTURE_TYPE_I)
693 18180 cbp_code = get_ue_golomb(gb);
694
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29134 times.
29134 if (cbp_code > 63U) {
695 av_log(h->avctx, AV_LOG_ERROR, "illegal intra cbp\n");
696 return AVERROR_INVALIDDATA;
697 }
698 29134 h->cbp = cbp_tab[cbp_code][0];
699
4/4
✓ Branch 0 taken 17869 times.
✓ Branch 1 taken 11265 times.
✓ Branch 2 taken 2289 times.
✓ Branch 3 taken 15580 times.
29134 if (h->cbp && !h->qp_fixed)
700 2289 h->qp = (h->qp + (unsigned)get_se_golomb(gb)) & 63; //qp_delta
701
702 /* luma intra prediction interleaved with residual decode/transform/add */
703
2/2
✓ Branch 0 taken 116536 times.
✓ Branch 1 taken 29134 times.
145670 for (block = 0; block < 4; block++) {
704 116536 d = h->cy + h->luma_scan[block];
705 116536 ff_cavs_load_intra_pred_luma(h, top, &left, block);
706 116536 h->intra_pred_l[h->pred_mode_Y[scan3x3[block]]]
707 (d, top, left, h->l_stride);
708
2/2
✓ Branch 0 taken 42875 times.
✓ Branch 1 taken 73661 times.
116536 if (h->cbp & (1<<block)) {
709 42875 ret = decode_residual_block(h, gb, intra_dec, 1, h->qp, d, h->l_stride);
710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42875 times.
42875 if (ret < 0)
711 return ret;
712 }
713 }
714
715 /* chroma intra prediction */
716 29134 ff_cavs_load_intra_pred_chroma(h);
717 29134 h->intra_pred_c[pred_mode_uv](h->cu, &h->top_border_u[h->mbx * 10],
718 29134 h->left_border_u, h->c_stride);
719 29134 h->intra_pred_c[pred_mode_uv](h->cv, &h->top_border_v[h->mbx * 10],
720 29134 h->left_border_v, h->c_stride);
721
722 29134 ret = decode_residual_chroma(h);
723
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 29134 times.
29134 if (ret < 0)
724 return ret;
725 29134 ff_cavs_filter(h, I_8X8);
726 29134 set_mv_intra(h);
727 29134 return 0;
728 }
729
730 273831 static inline void set_intra_mode_default(AVSContext *h)
731 {
732
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 273831 times.
273831 if (h->stream_revision > 0) {
733 h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL;
734 h->top_pred_Y[h->mbx * 2 + 0] = h->top_pred_Y[h->mbx * 2 + 1] = NOT_AVAIL;
735 } else {
736 273831 h->pred_mode_Y[3] = h->pred_mode_Y[6] = INTRA_L_LP;
737 273831 h->top_pred_Y[h->mbx * 2 + 0] = h->top_pred_Y[h->mbx * 2 + 1] = INTRA_L_LP;
738 }
739 273831 }
740
741 83018 static void decode_mb_p(AVSContext *h, enum cavs_mb mb_type)
742 {
743 83018 GetBitContext *gb = &h->gb;
744 int ref[4];
745
746 83018 ff_cavs_init_mb(h);
747
5/6
✓ Branch 0 taken 20801 times.
✓ Branch 1 taken 48877 times.
✓ Branch 2 taken 3399 times.
✓ Branch 3 taken 3154 times.
✓ Branch 4 taken 6787 times.
✗ Branch 5 not taken.
83018 switch (mb_type) {
748 20801 case P_SKIP:
749 20801 ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_PSKIP, BLK_16X16, 0);
750 20801 break;
751 48877 case P_16X16:
752
2/2
✓ Branch 0 taken 45007 times.
✓ Branch 1 taken 3870 times.
48877 ref[0] = h->ref_flag ? 0 : get_bits1(gb);
753 48877 ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, ref[0]);
754 48877 break;
755 3399 case P_16X8:
756
2/2
✓ Branch 0 taken 3234 times.
✓ Branch 1 taken 165 times.
3399 ref[0] = h->ref_flag ? 0 : get_bits1(gb);
757
2/2
✓ Branch 0 taken 3234 times.
✓ Branch 1 taken 165 times.
3399 ref[2] = h->ref_flag ? 0 : get_bits1(gb);
758 3399 ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, ref[0]);
759 3399 ff_cavs_mv(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, ref[2]);
760 3399 break;
761 3154 case P_8X16:
762
2/2
✓ Branch 0 taken 2987 times.
✓ Branch 1 taken 167 times.
3154 ref[0] = h->ref_flag ? 0 : get_bits1(gb);
763
2/2
✓ Branch 0 taken 2987 times.
✓ Branch 1 taken 167 times.
3154 ref[1] = h->ref_flag ? 0 : get_bits1(gb);
764 3154 ff_cavs_mv(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, ref[0]);
765 3154 ff_cavs_mv(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT, BLK_8X16, ref[1]);
766 3154 break;
767 6787 case P_8X8:
768
2/2
✓ Branch 0 taken 6455 times.
✓ Branch 1 taken 332 times.
6787 ref[0] = h->ref_flag ? 0 : get_bits1(gb);
769
2/2
✓ Branch 0 taken 6455 times.
✓ Branch 1 taken 332 times.
6787 ref[1] = h->ref_flag ? 0 : get_bits1(gb);
770
2/2
✓ Branch 0 taken 6455 times.
✓ Branch 1 taken 332 times.
6787 ref[2] = h->ref_flag ? 0 : get_bits1(gb);
771
2/2
✓ Branch 0 taken 6455 times.
✓ Branch 1 taken 332 times.
6787 ref[3] = h->ref_flag ? 0 : get_bits1(gb);
772 6787 ff_cavs_mv(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_MEDIAN, BLK_8X8, ref[0]);
773 6787 ff_cavs_mv(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_MEDIAN, BLK_8X8, ref[1]);
774 6787 ff_cavs_mv(h, MV_FWD_X2, MV_FWD_X1, MV_PRED_MEDIAN, BLK_8X8, ref[2]);
775 6787 ff_cavs_mv(h, MV_FWD_X3, MV_FWD_X0, MV_PRED_MEDIAN, BLK_8X8, ref[3]);
776 }
777 83018 ff_cavs_inter(h, mb_type);
778 83018 set_intra_mode_default(h);
779 83018 store_mvs(h);
780
2/2
✓ Branch 0 taken 62217 times.
✓ Branch 1 taken 20801 times.
83018 if (mb_type != P_SKIP)
781 62217 decode_residual_inter(h);
782 83018 ff_cavs_filter(h, mb_type);
783 83018 h->col_type_base[h->mbidx] = mb_type;
784 83018 }
785
786 190813 static int decode_mb_b(AVSContext *h, enum cavs_mb mb_type)
787 {
788 int block;
789 enum cavs_sub_mb sub_type[4];
790 int flags;
791
792 190813 ff_cavs_init_mb(h);
793
794 /* reset all MVs */
795 190813 h->mv[MV_FWD_X0] = ff_cavs_dir_mv;
796 190813 set_mvs(&h->mv[MV_FWD_X0], BLK_16X16);
797 190813 h->mv[MV_BWD_X0] = ff_cavs_dir_mv;
798 190813 set_mvs(&h->mv[MV_BWD_X0], BLK_16X16);
799
6/6
✓ Branch 0 taken 145959 times.
✓ Branch 1 taken 7352 times.
✓ Branch 2 taken 3131 times.
✓ Branch 3 taken 5777 times.
✓ Branch 4 taken 13841 times.
✓ Branch 5 taken 14753 times.
190813 switch (mb_type) {
800 145959 case B_SKIP:
801 case B_DIRECT:
802
2/2
✓ Branch 0 taken 14459 times.
✓ Branch 1 taken 131500 times.
145959 if (!h->col_type_base[h->mbidx]) {
803 /* intra MB at co-location, do in-plane prediction */
804 14459 ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_BSKIP, BLK_16X16, 1);
805 14459 ff_cavs_mv(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_BSKIP, BLK_16X16, 0);
806 } else
807 /* direct prediction from co-located P MB, block-wise */
808
2/2
✓ Branch 0 taken 526000 times.
✓ Branch 1 taken 131500 times.
657500 for (block = 0; block < 4; block++)
809 526000 mv_pred_direct(h, &h->mv[mv_scan[block]],
810 526000 &h->col_mv[h->mbidx * 4 + block]);
811 145959 break;
812 7352 case B_FWD_16X16:
813 7352 ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);
814 7352 break;
815 3131 case B_SYM_16X16:
816 3131 ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_MEDIAN, BLK_16X16, 1);
817 3131 mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X16);
818 3131 break;
819 5777 case B_BWD_16X16:
820 5777 ff_cavs_mv(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_MEDIAN, BLK_16X16, 0);
821 5777 break;
822 13841 case B_8X8:
823 #define TMP_UNUSED_INX 7
824 13841 flags = 0;
825
2/2
✓ Branch 0 taken 55364 times.
✓ Branch 1 taken 13841 times.
69205 for (block = 0; block < 4; block++)
826 55364 sub_type[block] = get_bits(&h->gb, 2);
827
2/2
✓ Branch 0 taken 55364 times.
✓ Branch 1 taken 13841 times.
69205 for (block = 0; block < 4; block++) {
828
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 20371 times.
✓ Branch 2 taken 16570 times.
✓ Branch 3 taken 18423 times.
55364 switch (sub_type[block]) {
829 case B_SUB_DIRECT:
830 if (!h->col_type_base[h->mbidx]) {
831 /* intra MB at co-location, do in-plane prediction */
832 if(flags==0) {
833 // if col-MB is a Intra MB, current Block size is 16x16.
834 // AVS standard section 9.9.1
835 if(block>0){
836 h->mv[TMP_UNUSED_INX ] = h->mv[MV_FWD_X0 ];
837 h->mv[TMP_UNUSED_INX + MV_BWD_OFFS] = h->mv[MV_FWD_X0 + MV_BWD_OFFS];
838 }
839 ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2,
840 MV_PRED_BSKIP, BLK_8X8, 1);
841 ff_cavs_mv(h, MV_FWD_X0+MV_BWD_OFFS,
842 MV_FWD_C2+MV_BWD_OFFS,
843 MV_PRED_BSKIP, BLK_8X8, 0);
844 if(block>0) {
845 flags = mv_scan[block];
846 h->mv[flags ] = h->mv[MV_FWD_X0 ];
847 h->mv[flags + MV_BWD_OFFS] = h->mv[MV_FWD_X0 + MV_BWD_OFFS];
848 h->mv[MV_FWD_X0 ] = h->mv[TMP_UNUSED_INX ];
849 h->mv[MV_FWD_X0 + MV_BWD_OFFS] = h->mv[TMP_UNUSED_INX + MV_BWD_OFFS];
850 } else
851 flags = MV_FWD_X0;
852 } else {
853 h->mv[mv_scan[block] ] = h->mv[flags ];
854 h->mv[mv_scan[block] + MV_BWD_OFFS] = h->mv[flags + MV_BWD_OFFS];
855 }
856 } else
857 mv_pred_direct(h, &h->mv[mv_scan[block]],
858 &h->col_mv[h->mbidx * 4 + block]);
859 break;
860 20371 case B_SUB_FWD:
861 20371 ff_cavs_mv(h, mv_scan[block], mv_scan[block] - 3,
862 MV_PRED_MEDIAN, BLK_8X8, 1);
863 20371 break;
864 16570 case B_SUB_SYM:
865 16570 ff_cavs_mv(h, mv_scan[block], mv_scan[block] - 3,
866 MV_PRED_MEDIAN, BLK_8X8, 1);
867 16570 mv_pred_sym(h, &h->mv[mv_scan[block]], BLK_8X8);
868 16570 break;
869 }
870 }
871 #undef TMP_UNUSED_INX
872
2/2
✓ Branch 0 taken 55364 times.
✓ Branch 1 taken 13841 times.
69205 for (block = 0; block < 4; block++) {
873
2/2
✓ Branch 0 taken 18423 times.
✓ Branch 1 taken 36941 times.
55364 if (sub_type[block] == B_SUB_BWD)
874 18423 ff_cavs_mv(h, mv_scan[block] + MV_BWD_OFFS,
875 18423 mv_scan[block] + MV_BWD_OFFS - 3,
876 MV_PRED_MEDIAN, BLK_8X8, 0);
877 }
878 13841 break;
879 14753 default:
880
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14753 times.
14753 if (mb_type <= B_SYM_16X16) {
881 av_log(h->avctx, AV_LOG_ERROR, "Invalid mb_type %d in B frame\n", mb_type);
882 return AVERROR_INVALIDDATA;
883 }
884 av_assert2(mb_type < B_8X8);
885 14753 flags = ff_cavs_partition_flags[mb_type];
886
2/2
✓ Branch 0 taken 7898 times.
✓ Branch 1 taken 6855 times.
14753 if (mb_type & 1) { /* 16x8 macroblock types */
887
2/2
✓ Branch 0 taken 5294 times.
✓ Branch 1 taken 2604 times.
7898 if (flags & FWD0)
888 5294 ff_cavs_mv(h, MV_FWD_X0, MV_FWD_C2, MV_PRED_TOP, BLK_16X8, 1);
889
2/2
✓ Branch 0 taken 2140 times.
✓ Branch 1 taken 5758 times.
7898 if (flags & SYM0)
890 2140 mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_16X8);
891
2/2
✓ Branch 0 taken 5400 times.
✓ Branch 1 taken 2498 times.
7898 if (flags & FWD1)
892 5400 ff_cavs_mv(h, MV_FWD_X2, MV_FWD_A1, MV_PRED_LEFT, BLK_16X8, 1);
893
2/2
✓ Branch 0 taken 2495 times.
✓ Branch 1 taken 5403 times.
7898 if (flags & SYM1)
894 2495 mv_pred_sym(h, &h->mv[MV_FWD_X2], BLK_16X8);
895
2/2
✓ Branch 0 taken 2604 times.
✓ Branch 1 taken 5294 times.
7898 if (flags & BWD0)
896 2604 ff_cavs_mv(h, MV_BWD_X0, MV_BWD_C2, MV_PRED_TOP, BLK_16X8, 0);
897
2/2
✓ Branch 0 taken 2498 times.
✓ Branch 1 taken 5400 times.
7898 if (flags & BWD1)
898 2498 ff_cavs_mv(h, MV_BWD_X2, MV_BWD_A1, MV_PRED_LEFT, BLK_16X8, 0);
899 } else { /* 8x16 macroblock types */
900
2/2
✓ Branch 0 taken 4601 times.
✓ Branch 1 taken 2254 times.
6855 if (flags & FWD0)
901 4601 ff_cavs_mv(h, MV_FWD_X0, MV_FWD_B3, MV_PRED_LEFT, BLK_8X16, 1);
902
2/2
✓ Branch 0 taken 1976 times.
✓ Branch 1 taken 4879 times.
6855 if (flags & SYM0)
903 1976 mv_pred_sym(h, &h->mv[MV_FWD_X0], BLK_8X16);
904
2/2
✓ Branch 0 taken 4556 times.
✓ Branch 1 taken 2299 times.
6855 if (flags & FWD1)
905 4556 ff_cavs_mv(h, MV_FWD_X1, MV_FWD_C2, MV_PRED_TOPRIGHT, BLK_8X16, 1);
906
2/2
✓ Branch 0 taken 2016 times.
✓ Branch 1 taken 4839 times.
6855 if (flags & SYM1)
907 2016 mv_pred_sym(h, &h->mv[MV_FWD_X1], BLK_8X16);
908
2/2
✓ Branch 0 taken 2254 times.
✓ Branch 1 taken 4601 times.
6855 if (flags & BWD0)
909 2254 ff_cavs_mv(h, MV_BWD_X0, MV_BWD_B3, MV_PRED_LEFT, BLK_8X16, 0);
910
2/2
✓ Branch 0 taken 2299 times.
✓ Branch 1 taken 4556 times.
6855 if (flags & BWD1)
911 2299 ff_cavs_mv(h, MV_BWD_X1, MV_BWD_C2, MV_PRED_TOPRIGHT, BLK_8X16, 0);
912 }
913 }
914 190813 ff_cavs_inter(h, mb_type);
915 190813 set_intra_mode_default(h);
916
2/2
✓ Branch 0 taken 82650 times.
✓ Branch 1 taken 108163 times.
190813 if (mb_type != B_SKIP)
917 82650 decode_residual_inter(h);
918 190813 ff_cavs_filter(h, mb_type);
919
920 190813 return 0;
921 }
922
923 /*****************************************************************************
924 *
925 * slice level
926 *
927 ****************************************************************************/
928
929 2 static inline int decode_slice_header(AVSContext *h, GetBitContext *gb)
930 {
931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (h->stc > 0xAF)
932 av_log(h->avctx, AV_LOG_ERROR, "unexpected start code 0x%02x\n", h->stc);
933
934
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (h->stc >= h->mb_height) {
935 av_log(h->avctx, AV_LOG_ERROR, "stc 0x%02x is too large\n", h->stc);
936 return AVERROR_INVALIDDATA;
937 }
938
939 2 h->mby = h->stc;
940 2 h->mbidx = h->mby * h->mb_width;
941
942 /* mark top macroblocks as unavailable */
943 2 h->flags &= ~(B_AVAIL | C_AVAIL);
944
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (!h->pic_qp_fixed) {
945 2 h->qp_fixed = get_bits1(gb);
946 2 h->qp = get_bits(gb, 6);
947 }
948 /* inter frame or second slice can have weighting params */
949
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
2 if ((h->cur.f->pict_type != AV_PICTURE_TYPE_I) ||
950
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 (!h->pic_structure && h->mby >= h->mb_width / 2))
951
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 if (get_bits1(gb)) { //slice_weighting_flag
952 1 av_log(h->avctx, AV_LOG_ERROR,
953 "weighted prediction not yet supported\n");
954 }
955 2 return 0;
956 }
957
958 302966 static inline int check_for_slice(AVSContext *h)
959 {
960 302966 GetBitContext *gb = &h->gb;
961 int align;
962
963
2/2
✓ Branch 0 taken 296268 times.
✓ Branch 1 taken 6698 times.
302966 if (h->mbx)
964 296268 return 0;
965 6698 align = (-get_bits_count(gb)) & 7;
966 /* check for stuffing byte */
967
4/4
✓ Branch 0 taken 786 times.
✓ Branch 1 taken 5912 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 783 times.
6698 if (!align && (show_bits(gb, 8) == 0x80))
968 3 align = 8;
969
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 6697 times.
6698 if ((show_bits_long(gb, 24 + align) & 0xFFFFFF) == 0x000001) {
970 1 skip_bits_long(gb, 24 + align);
971 1 h->stc = get_bits(gb, 8);
972
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (h->stc >= h->mb_height)
973 return 0;
974 1 decode_slice_header(h, gb);
975 1 return 1;
976 }
977 6697 return 0;
978 }
979
980 /*****************************************************************************
981 *
982 * frame level
983 *
984 ****************************************************************************/
985
986 186 static int decode_pic(AVSContext *h)
987 {
988 int ret;
989 186 int skip_count = -1;
990 enum cavs_mb mb_type;
991
992
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 186 times.
186 if (!h->top_qp) {
993 av_log(h->avctx, AV_LOG_ERROR, "No sequence header decoded yet\n");
994 return AVERROR_INVALIDDATA;
995 }
996
997 186 av_frame_unref(h->cur.f);
998
999 186 skip_bits(&h->gb, 16);//bbv_dwlay
1000
2/2
✓ Branch 0 taken 176 times.
✓ Branch 1 taken 10 times.
186 if (h->stc == PIC_PB_START_CODE) {
1001 176 h->cur.f->pict_type = get_bits(&h->gb, 2) + AV_PICTURE_TYPE_I;
1002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 176 times.
176 if (h->cur.f->pict_type > AV_PICTURE_TYPE_B) {
1003 av_log(h->avctx, AV_LOG_ERROR, "illegal picture type\n");
1004 return AVERROR_INVALIDDATA;
1005 }
1006 /* make sure we have the reference frames we need */
1007
1/2
✓ Branch 0 taken 176 times.
✗ Branch 1 not taken.
176 if (!h->DPB[0].f->data[0] ||
1008
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 174 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
176 (!h->DPB[1].f->data[0] && h->cur.f->pict_type == AV_PICTURE_TYPE_B))
1009 return AVERROR_INVALIDDATA;
1010 } else {
1011 10 h->cur.f->pict_type = AV_PICTURE_TYPE_I;
1012
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
10 if (get_bits1(&h->gb))
1013 skip_bits(&h->gb, 24);//time_code
1014 /* old sample clips were all progressive and no low_delay,
1015 bump stream revision if detected otherwise */
1016
3/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 9 times.
10 if (h->low_delay || !(show_bits(&h->gb, 9) & 1))
1017 1 h->stream_revision = 1;
1018 /* similarly test top_field_first and repeat_first_field */
1019
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
9 else if (show_bits(&h->gb, 11) & 3)
1020 h->stream_revision = 1;
1021
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 if (h->stream_revision > 0)
1022 1 skip_bits(&h->gb, 1); //marker_bit
1023 }
1024
1025
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 186 times.
186 if (get_bits_left(&h->gb) < 23)
1026 return AVERROR_INVALIDDATA;
1027
1028 186 ret = ff_get_buffer(h->avctx, h->cur.f, h->cur.f->pict_type == AV_PICTURE_TYPE_B ?
1029 0 : AV_GET_BUFFER_FLAG_REF);
1030
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 186 times.
186 if (ret < 0)
1031 return ret;
1032
1033
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 181 times.
186 if (!h->edge_emu_buffer) {
1034 5 int alloc_size = FFALIGN(FFABS(h->cur.f->linesize[0]) + 32, 32);
1035 5 h->edge_emu_buffer = av_mallocz(alloc_size * 2 * 24);
1036
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if (!h->edge_emu_buffer)
1037 return AVERROR(ENOMEM);
1038 }
1039
1040
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 186 times.
186 if ((ret = ff_cavs_init_pic(h)) < 0)
1041 return ret;
1042 186 h->cur.poc = get_bits(&h->gb, 8) * 2;
1043
1044 /* get temporal distances and MV scaling factors */
1045
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 120 times.
186 if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
1046 66 h->dist[0] = (h->cur.poc - h->DPB[0].poc) & 511;
1047 } else {
1048 120 h->dist[0] = (h->DPB[0].poc - h->cur.poc) & 511;
1049 }
1050 186 h->dist[1] = (h->cur.poc - h->DPB[1].poc) & 511;
1051
2/2
✓ Branch 0 taken 181 times.
✓ Branch 1 taken 5 times.
186 h->scale_den[0] = h->dist[0] ? 512/h->dist[0] : 0;
1052
2/2
✓ Branch 0 taken 181 times.
✓ Branch 1 taken 5 times.
186 h->scale_den[1] = h->dist[1] ? 512/h->dist[1] : 0;
1053
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 66 times.
186 if (h->cur.f->pict_type == AV_PICTURE_TYPE_B) {
1054 120 h->sym_factor = h->dist[0] * h->scale_den[1];
1055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
120 if (FFABS(h->sym_factor) > 32768) {
1056 av_log(h->avctx, AV_LOG_ERROR, "sym_factor %d too large\n", h->sym_factor);
1057 return AVERROR_INVALIDDATA;
1058 }
1059 } else {
1060
2/2
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 5 times.
66 h->direct_den[0] = h->dist[0] ? 16384 / h->dist[0] : 0;
1061
2/2
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 5 times.
66 h->direct_den[1] = h->dist[1] ? 16384 / h->dist[1] : 0;
1062 }
1063
1064
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 186 times.
186 if (h->low_delay)
1065 get_ue_golomb(&h->gb); //bbv_check_times
1066 186 h->progressive = get_bits1(&h->gb);
1067 186 h->pic_structure = 1;
1068
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 186 times.
186 if (!h->progressive)
1069 h->pic_structure = get_bits1(&h->gb);
1070
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 186 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
186 if (!h->pic_structure && h->stc == PIC_PB_START_CODE)
1071 skip_bits1(&h->gb); //advanced_pred_mode_disable
1072 186 skip_bits1(&h->gb); //top_field_first
1073 186 skip_bits1(&h->gb); //repeat_first_field
1074 186 h->pic_qp_fixed =
1075 186 h->qp_fixed = get_bits1(&h->gb);
1076 186 h->qp = get_bits(&h->gb, 6);
1077
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 176 times.
186 if (h->cur.f->pict_type == AV_PICTURE_TYPE_I) {
1078
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
10 if (!h->progressive && !h->pic_structure)
1079 skip_bits1(&h->gb);//what is this?
1080 10 skip_bits(&h->gb, 4); //reserved bits
1081 } else {
1082
3/4
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 120 times.
176 if (!(h->cur.f->pict_type == AV_PICTURE_TYPE_B && h->pic_structure == 1))
1083 56 h->ref_flag = get_bits1(&h->gb);
1084 176 skip_bits(&h->gb, 4); //reserved bits
1085 176 h->skip_mode_flag = get_bits1(&h->gb);
1086 }
1087 186 h->loop_filter_disable = get_bits1(&h->gb);
1088
2/4
✓ Branch 0 taken 186 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 186 times.
186 if (!h->loop_filter_disable && get_bits1(&h->gb)) {
1089 h->alpha_offset = get_se_golomb(&h->gb);
1090 h->beta_offset = get_se_golomb(&h->gb);
1091 if ( h->alpha_offset < -64 || h->alpha_offset > 64
1092 || h-> beta_offset < -64 || h-> beta_offset > 64) {
1093 h->alpha_offset = h->beta_offset = 0;
1094 return AVERROR_INVALIDDATA;
1095 }
1096 } else {
1097 186 h->alpha_offset = h->beta_offset = 0;
1098 }
1099
1100 186 ret = 0;
1101
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 176 times.
186 if (h->cur.f->pict_type == AV_PICTURE_TYPE_I) {
1102 do {
1103 18180 check_for_slice(h);
1104 18180 ret = decode_mb_i(h, 0);
1105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18180 times.
18180 if (ret < 0)
1106 break;
1107
2/2
✓ Branch 1 taken 18170 times.
✓ Branch 2 taken 10 times.
18180 } while (ff_cavs_next_mb(h));
1108
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 120 times.
176 } else if (h->cur.f->pict_type == AV_PICTURE_TYPE_P) {
1109 do {
1110
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 90720 times.
90720 if (check_for_slice(h))
1111 skip_count = -1;
1112
3/4
✓ Branch 0 taken 90720 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69924 times.
✓ Branch 3 taken 20796 times.
90720 if (h->skip_mode_flag && (skip_count < 0)) {
1113
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 69924 times.
69924 if (get_bits_left(&h->gb) < 1) {
1114 ret = AVERROR_INVALIDDATA;
1115 break;
1116 }
1117 69924 skip_count = get_ue_golomb(&h->gb);
1118 }
1119
3/4
✓ Branch 0 taken 90720 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 20801 times.
✓ Branch 3 taken 69919 times.
90720 if (h->skip_mode_flag && skip_count--) {
1120 20801 decode_mb_p(h, P_SKIP);
1121 } else {
1122
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 69919 times.
69919 if (get_bits_left(&h->gb) < 1) {
1123 ret = AVERROR_INVALIDDATA;
1124 break;
1125 }
1126 69919 mb_type = get_ue_golomb(&h->gb) + P_SKIP + h->skip_mode_flag;
1127
2/2
✓ Branch 0 taken 7702 times.
✓ Branch 1 taken 62217 times.
69919 if (mb_type > P_8X8)
1128 7702 ret = decode_mb_i(h, mb_type - P_8X8 - 1);
1129 else
1130 62217 decode_mb_p(h, mb_type);
1131 }
1132
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 90720 times.
90720 if (ret < 0)
1133 break;
1134
2/2
✓ Branch 1 taken 90664 times.
✓ Branch 2 taken 56 times.
90720 } while (ff_cavs_next_mb(h));
1135 } else { /* AV_PICTURE_TYPE_B */
1136 do {
1137
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 194066 times.
194066 if (check_for_slice(h))
1138 skip_count = -1;
1139
3/4
✓ Branch 0 taken 194066 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 85940 times.
✓ Branch 3 taken 108126 times.
194066 if (h->skip_mode_flag && (skip_count < 0)) {
1140
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 85939 times.
85940 if (get_bits_left(&h->gb) < 1) {
1141 1 ret = AVERROR_INVALIDDATA;
1142 1 break;
1143 }
1144 85939 skip_count = get_ue_golomb(&h->gb);
1145 }
1146
3/4
✓ Branch 0 taken 194065 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 108163 times.
✓ Branch 3 taken 85902 times.
194065 if (h->skip_mode_flag && skip_count--) {
1147 108163 ret = decode_mb_b(h, B_SKIP);
1148 } else {
1149
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 85902 times.
85902 if (get_bits_left(&h->gb) < 1) {
1150 ret = AVERROR_INVALIDDATA;
1151 break;
1152 }
1153 85902 mb_type = get_ue_golomb(&h->gb) + B_SKIP + h->skip_mode_flag;
1154
2/2
✓ Branch 0 taken 3252 times.
✓ Branch 1 taken 82650 times.
85902 if (mb_type > B_8X8)
1155 3252 ret = decode_mb_i(h, mb_type - B_8X8 - 1);
1156 else
1157 82650 ret = decode_mb_b(h, mb_type);
1158 }
1159
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 194065 times.
194065 if (ret < 0)
1160 break;
1161
2/2
✓ Branch 1 taken 193946 times.
✓ Branch 2 taken 119 times.
194065 } while (ff_cavs_next_mb(h));
1162 }
1163 186 emms_c();
1164
4/4
✓ Branch 0 taken 185 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 66 times.
✓ Branch 3 taken 119 times.
186 if (ret >= 0 && h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
1165 66 av_frame_unref(h->DPB[1].f);
1166 66 FFSWAP(AVSFrame, h->cur, h->DPB[1]);
1167 66 FFSWAP(AVSFrame, h->DPB[0], h->DPB[1]);
1168 }
1169 186 return ret;
1170 }
1171
1172 /*****************************************************************************
1173 *
1174 * headers and interface
1175 *
1176 ****************************************************************************/
1177
1178 10 static int decode_seq_header(AVSContext *h)
1179 {
1180 int frame_rate_code;
1181 int width, height;
1182 int ret;
1183
1184 10 h->profile = get_bits(&h->gb, 8);
1185
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (h->profile != 0x20) {
1186 avpriv_report_missing_feature(h->avctx,
1187 "only supprt JiZhun profile");
1188 return AVERROR_PATCHWELCOME;
1189 }
1190 10 h->level = get_bits(&h->gb, 8);
1191 10 skip_bits1(&h->gb); //progressive sequence
1192
1193 10 width = get_bits(&h->gb, 14);
1194 10 height = get_bits(&h->gb, 14);
1195
5/8
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 5 times.
10 if ((h->width || h->height) && (h->width != width || h->height != height)) {
1196 avpriv_report_missing_feature(h->avctx,
1197 "Width/height changing in CAVS");
1198 return AVERROR_PATCHWELCOME;
1199 }
1200
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
10 if (width <= 0 || height <= 0) {
1201 av_log(h->avctx, AV_LOG_ERROR, "Dimensions invalid\n");
1202 return AVERROR_INVALIDDATA;
1203 }
1204 10 skip_bits(&h->gb, 2); //chroma format
1205 10 skip_bits(&h->gb, 3); //sample_precision
1206 10 h->aspect_ratio = get_bits(&h->gb, 4);
1207 10 frame_rate_code = get_bits(&h->gb, 4);
1208
2/4
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
10 if (frame_rate_code == 0 || frame_rate_code > 13) {
1209 av_log(h->avctx, AV_LOG_WARNING,
1210 "frame_rate_code %d is invalid\n", frame_rate_code);
1211 frame_rate_code = 1;
1212 }
1213
1214 10 skip_bits(&h->gb, 18); //bit_rate_lower
1215 10 skip_bits1(&h->gb); //marker_bit
1216 10 skip_bits(&h->gb, 12); //bit_rate_upper
1217 10 h->low_delay = get_bits1(&h->gb);
1218
1219 10 ret = ff_set_dimensions(h->avctx, width, height);
1220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (ret < 0)
1221 return ret;
1222
1223 10 h->width = width;
1224 10 h->height = height;
1225 10 h->mb_width = (h->width + 15) >> 4;
1226 10 h->mb_height = (h->height + 15) >> 4;
1227 10 h->avctx->framerate = ff_mpeg12_frame_rate_tab[frame_rate_code];
1228
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (!h->top_qp)
1229 5 return ff_cavs_init_top_lines(h);
1230 5 return 0;
1231 }
1232
1233 static void cavs_flush(AVCodecContext * avctx)
1234 {
1235 AVSContext *h = avctx->priv_data;
1236 h->got_keyframe = 0;
1237 }
1238
1239 188 static int cavs_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
1240 int *got_frame, AVPacket *avpkt)
1241 {
1242 188 AVSContext *h = avctx->priv_data;
1243 188 const uint8_t *buf = avpkt->data;
1244 188 int buf_size = avpkt->size;
1245 188 uint32_t stc = -1;
1246 int input_size, ret;
1247 const uint8_t *buf_end;
1248 const uint8_t *buf_ptr;
1249 188 int frame_start = 0;
1250
1251
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 186 times.
188 if (buf_size == 0) {
1252
3/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
2 if (!h->low_delay && h->DPB[0].f->data[0]) {
1253 1 *got_frame = 1;
1254 1 av_frame_move_ref(rframe, h->DPB[0].f);
1255 }
1256 2 return 0;
1257 }
1258
1259 186 h->stc = 0;
1260
1261 186 buf_ptr = buf;
1262 186 buf_end = buf + buf_size;
1263 for(;;) {
1264 391 buf_ptr = avpriv_find_start_code(buf_ptr, buf_end, &stc);
1265
3/4
✓ Branch 0 taken 205 times.
✓ Branch 1 taken 186 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 205 times.
391 if ((stc & 0xFFFFFE00) || buf_ptr == buf_end) {
1266
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 185 times.
186 if (!h->stc)
1267 1 av_log(h->avctx, AV_LOG_WARNING, "no frame decoded\n");
1268 186 return FFMAX(0, buf_ptr - buf);
1269 }
1270 205 input_size = (buf_end - buf_ptr) * 8;
1271
6/6
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 176 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 1 times.
205 switch (stc) {
1272 10 case CAVS_START_CODE:
1273 10 init_get_bits(&h->gb, buf_ptr, input_size);
1274 10 decode_seq_header(h);
1275 10 break;
1276 10 case PIC_I_START_CODE:
1277
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
10 if (!h->got_keyframe) {
1278 5 av_frame_unref(h->DPB[0].f);
1279 5 av_frame_unref(h->DPB[1].f);
1280 5 h->got_keyframe = 1;
1281 }
1282 case PIC_PB_START_CODE:
1283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 186 times.
186 if (frame_start > 1)
1284 return AVERROR_INVALIDDATA;
1285 186 frame_start ++;
1286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 186 times.
186 if (*got_frame)
1287 av_frame_unref(rframe);
1288 186 *got_frame = 0;
1289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 186 times.
186 if (!h->got_keyframe)
1290 break;
1291 186 init_get_bits(&h->gb, buf_ptr, input_size);
1292 186 h->stc = stc;
1293
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 185 times.
186 if (decode_pic(h))
1294 1 break;
1295 185 *got_frame = 1;
1296
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 119 times.
185 if (h->cur.f->pict_type != AV_PICTURE_TYPE_B) {
1297
2/2
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 5 times.
66 if (h->DPB[!h->low_delay].f->data[0]) {
1298
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 61 times.
61 if ((ret = av_frame_ref(rframe, h->DPB[!h->low_delay].f)) < 0)
1299 return ret;
1300 } else {
1301 5 *got_frame = 0;
1302 }
1303 } else {
1304 119 av_frame_move_ref(rframe, h->cur.f);
1305 }
1306 185 break;
1307 4 case EXT_START_CODE:
1308 //mpeg_decode_extension(avctx, buf_ptr, input_size);
1309 4 break;
1310 4 case USER_START_CODE:
1311 //mpeg_decode_user_data(avctx, buf_ptr, input_size);
1312 4 break;
1313 1 default:
1314
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (stc <= SLICE_MAX_START_CODE) {
1315 1 init_get_bits(&h->gb, buf_ptr, input_size);
1316 1 decode_slice_header(h, &h->gb);
1317 }
1318 1 break;
1319 }
1320 }
1321 }
1322
1323 const FFCodec ff_cavs_decoder = {
1324 .p.name = "cavs",
1325 CODEC_LONG_NAME("Chinese AVS (Audio Video Standard) (AVS1-P2, JiZhun profile)"),
1326 .p.type = AVMEDIA_TYPE_VIDEO,
1327 .p.id = AV_CODEC_ID_CAVS,
1328 .priv_data_size = sizeof(AVSContext),
1329 .init = ff_cavs_init,
1330 .close = ff_cavs_end,
1331 FF_CODEC_DECODE_CB(cavs_decode_frame),
1332 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
1333 .flush = cavs_flush,
1334 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1335 };
1336