FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ituh263dec.c
Date: 2025-10-11 17:33:36
Exec Total Coverage
Lines: 557 796 70.0%
Functions: 15 18 83.3%
Branches: 285 538 53.0%

Line Branch Exec Source
1 /*
2 * ITU H.263 bitstream decoder
3 * Copyright (c) 2000,2001 Fabrice Bellard
4 * H.263+ support.
5 * Copyright (c) 2001 Juan J. Sierralta P
6 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 /**
26 * @file
27 * H.263 decoder.
28 */
29
30 #define UNCHECKED_BITSTREAM_READER 1
31
32 #include "config_components.h"
33
34 #include "libavutil/attributes.h"
35 #include "libavutil/imgutils.h"
36 #include "libavutil/internal.h"
37 #include "libavutil/mathematics.h"
38 #include "libavutil/mem_internal.h"
39 #include "libavutil/thread.h"
40 #include "avcodec.h"
41 #include "mpegvideo.h"
42 #include "h263.h"
43 #include "h263data.h"
44 #include "h263dec.h"
45 #include "mathops.h"
46 #include "mpegutils.h"
47 #include "unary.h"
48 #include "rv10dec.h"
49 #include "mpeg4video.h"
50 #include "mpegvideodata.h"
51 #include "mpegvideodec.h"
52 #include "mpeg4videodec.h"
53 #include "mpeg4videodefs.h"
54
55 // The defines below define the number of bits that are read at once for
56 // reading vlc values. Changing these may improve speed and data cache needs
57 // be aware though that decreasing them may need the number of stages that is
58 // passed to get_vlc* to be increased.
59 #define H263_MBTYPE_B_VLC_BITS 6
60 #define CBPC_B_VLC_BITS 3
61
62 static const int16_t h263_mb_type_b_map[15]= {
63 MB_TYPE_DIRECT2 | MB_TYPE_BIDIR_MV,
64 MB_TYPE_DIRECT2 | MB_TYPE_BIDIR_MV | MB_TYPE_CBP,
65 MB_TYPE_DIRECT2 | MB_TYPE_BIDIR_MV | MB_TYPE_CBP | MB_TYPE_QUANT,
66 MB_TYPE_FORWARD_MV | MB_TYPE_16x16,
67 MB_TYPE_FORWARD_MV | MB_TYPE_CBP | MB_TYPE_16x16,
68 MB_TYPE_FORWARD_MV | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
69 MB_TYPE_BACKWARD_MV | MB_TYPE_16x16,
70 MB_TYPE_BACKWARD_MV | MB_TYPE_CBP | MB_TYPE_16x16,
71 MB_TYPE_BACKWARD_MV | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
72 MB_TYPE_BIDIR_MV | MB_TYPE_16x16,
73 MB_TYPE_BIDIR_MV | MB_TYPE_CBP | MB_TYPE_16x16,
74 MB_TYPE_BIDIR_MV | MB_TYPE_CBP | MB_TYPE_QUANT | MB_TYPE_16x16,
75 0, //stuffing
76 MB_TYPE_INTRA4x4 | MB_TYPE_CBP,
77 MB_TYPE_INTRA4x4 | MB_TYPE_CBP | MB_TYPE_QUANT,
78 };
79
80 461 void ff_h263_show_pict_info(H263DecContext *const h, int h263_plus)
81 {
82
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if (h->c.avctx->debug&FF_DEBUG_PICT_INFO) {
83 av_log(h->c.avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n",
84 h->c.qscale, av_get_picture_type_char(h->c.pict_type),
85 h->gb.size_in_bits, 1-h->c.no_rounding,
86 h->c.obmc ? " AP" : "",
87 h->umvplus ? " UMV" : "",
88 h->h263_long_vectors ? " LONG" : "",
89 h263_plus ? " +" : "",
90 h->c.h263_aic ? " AIC" : "",
91 h->alt_inter_vlc ? " AIV" : "",
92 h->modified_quant ? " MQ" : "",
93 h->loop_filter ? " LOOP" : "",
94 h->h263_slice_structured ? " SS" : "",
95 h->c.avctx->framerate.num, h->c.avctx->framerate.den);
96 }
97 461 }
98
99 /***********************************************/
100 /* decoding */
101
102 VLCElem ff_h263_intra_MCBPC_vlc[72];
103 VLCElem ff_h263_inter_MCBPC_vlc[198];
104 VLCElem ff_h263_cbpy_vlc[64];
105 VLCElem ff_h263_mv_vlc[538];
106 static VLCElem h263_mbtype_b_vlc[80];
107 static VLCElem cbpc_b_vlc[8];
108
109 /* init vlcs */
110
111 164 static av_cold void h263_decode_init_vlc(void)
112 {
113 164 VLC_INIT_STATIC_TABLE(ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9,
114 ff_h263_intra_MCBPC_bits, 1, 1,
115 ff_h263_intra_MCBPC_code, 1, 1, 0);
116 164 VLC_INIT_STATIC_TABLE(ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28,
117 ff_h263_inter_MCBPC_bits, 1, 1,
118 ff_h263_inter_MCBPC_code, 1, 1, 0);
119 164 VLC_INIT_STATIC_TABLE(ff_h263_cbpy_vlc, CBPY_VLC_BITS, 16,
120 &ff_h263_cbpy_tab[0][1], 2, 1,
121 &ff_h263_cbpy_tab[0][0], 2, 1, 0);
122 164 VLC_INIT_STATIC_TABLE(ff_h263_mv_vlc, H263_MV_VLC_BITS, 33,
123 &ff_mvtab[0][1], 2, 1,
124 &ff_mvtab[0][0], 2, 1, 0);
125
2/2
✓ Branch 0 taken 5248 times.
✓ Branch 1 taken 164 times.
5412 VLC_INIT_RL(ff_h263_rl_inter, 554);
126 164 INIT_FIRST_VLC_RL(ff_rl_intra_aic, 554);
127 164 VLC_INIT_STATIC_SPARSE_TABLE(h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15,
128 &ff_h263_mbtype_b_tab[0][1], 2, 1,
129 &ff_h263_mbtype_b_tab[0][0], 2, 1,
130 h263_mb_type_b_map, 2, 2, 0);
131 164 VLC_INIT_STATIC_TABLE(cbpc_b_vlc, CBPC_B_VLC_BITS, 4,
132 &ff_cbpc_b_tab[0][1], 2, 1,
133 &ff_cbpc_b_tab[0][0], 2, 1, 0);
134 164 }
135
136 290 av_cold void ff_h263_decode_init_vlc(void)
137 {
138 static AVOnce init_static_once = AV_ONCE_INIT;
139 290 ff_thread_once(&init_static_once, h263_decode_init_vlc);
140 290 }
141
142 742 int ff_h263_decode_mba(H263DecContext *const h)
143 {
144 int i, mb_pos;
145
146
1/2
✓ Branch 0 taken 2226 times.
✗ Branch 1 not taken.
2226 for (i = 0; i < 6; i++)
147
2/2
✓ Branch 0 taken 742 times.
✓ Branch 1 taken 1484 times.
2226 if (h->c.mb_num - 1 <= ff_mba_max[i])
148 742 break;
149 742 mb_pos = get_bits(&h->gb, ff_mba_length[i]);
150 742 h->c.mb_x = mb_pos % h->c.mb_width;
151 742 h->c.mb_y = mb_pos / h->c.mb_width;
152
153 742 return mb_pos;
154 }
155
156 /**
157 * Decode the group of blocks header or slice header.
158 * @return <0 if an error occurred
159 */
160 2544 static int h263_decode_gob_header(H263DecContext *const h)
161 {
162 unsigned int val, gob_number;
163 int left;
164
165 /* Check for GOB Start Code */
166 2544 val = show_bits(&h->gb, 16);
167
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2544 times.
2544 if(val)
168 return -1;
169
170 /* We have a GBSC probably with GSTUFF */
171 2544 skip_bits(&h->gb, 16); /* Drop the zeros */
172 2544 left = get_bits_left(&h->gb);
173 2544 left = FFMIN(left, 32);
174 //MN: we must check the bits left or we might end in an infinite loop (or segfault)
175
1/2
✓ Branch 0 taken 11538 times.
✗ Branch 1 not taken.
11538 for(;left>13; left--){
176
2/2
✓ Branch 1 taken 2544 times.
✓ Branch 2 taken 8994 times.
11538 if (get_bits1(&h->gb))
177 2544 break; /* Seek the '1' bit */
178 }
179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2544 times.
2544 if(left<=13)
180 return -1;
181
182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2544 times.
2544 if (h->h263_slice_structured) {
183 if (check_marker(h->c.avctx, &h->gb, "before MBA")==0)
184 return -1;
185
186 ff_h263_decode_mba(h);
187
188 if (h->c.mb_num > 1583)
189 if (check_marker(h->c.avctx, &h->gb, "after MBA")==0)
190 return -1;
191
192 h->c.qscale = get_bits(&h->gb, 5); /* SQUANT */
193 if (check_marker(h->c.avctx, &h->gb, "after SQUANT")==0)
194 return -1;
195 skip_bits(&h->gb, 2); /* GFID */
196 }else{
197 2544 gob_number = get_bits(&h->gb, 5); /* GN */
198 2544 h->c.mb_x = 0;
199 2544 h->c.mb_y = h->gob_index* gob_number;
200 2544 skip_bits(&h->gb, 2); /* GFID */
201 2544 h->c.qscale = get_bits(&h->gb, 5); /* GQUANT */
202 }
203
204
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2544 times.
2544 if (h->c.mb_y >= h->c.mb_height)
205 return -1;
206
207
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2544 times.
2544 if (h->c.qscale==0)
208 return -1;
209
210 2544 return 0;
211 }
212
213 /**
214 * Decode the group of blocks / video packet header / slice header (MPEG-4 Studio).
215 * @return bit position of the resync_marker, or <0 if none was found
216 */
217 6480 int ff_h263_resync(H263DecContext *const h)
218 {
219 int left, pos, ret;
220
221 /* In MPEG-4 studio mode look for a new slice startcode
222 * and decode slice header */
223
4/4
✓ Branch 0 taken 3936 times.
✓ Branch 1 taken 2544 times.
✓ Branch 2 taken 29 times.
✓ Branch 3 taken 3907 times.
6480 if (h->c.codec_id==AV_CODEC_ID_MPEG4 && h->c.studio_profile) {
224 29 align_get_bits(&h->gb);
225
226
2/4
✓ Branch 1 taken 29 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 29 times.
29 while (get_bits_left(&h->gb) >= 32 && show_bits_long(&h->gb, 32) != SLICE_STARTCODE) {
227 get_bits(&h->gb, 8);
228 }
229
230
2/4
✓ Branch 1 taken 29 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 29 times.
✗ Branch 5 not taken.
29 if (get_bits_left(&h->gb) >= 32 && show_bits_long(&h->gb, 32) == SLICE_STARTCODE)
231 29 return get_bits_count(&h->gb);
232 else
233 return -1;
234 }
235
236
2/2
✓ Branch 0 taken 3907 times.
✓ Branch 1 taken 2544 times.
6451 if (h->c.codec_id==AV_CODEC_ID_MPEG4){
237 3907 skip_bits1(&h->gb);
238 3907 align_get_bits(&h->gb);
239 }
240
241
1/2
✓ Branch 1 taken 6451 times.
✗ Branch 2 not taken.
6451 if (show_bits(&h->gb, 16) ==0) {
242 6451 pos = get_bits_count(&h->gb);
243 #if CONFIG_MPEG4_DECODER
244
2/2
✓ Branch 0 taken 3907 times.
✓ Branch 1 taken 2544 times.
6451 if (h->c.codec_id == AV_CODEC_ID_MPEG4)
245 3907 ret = ff_mpeg4_decode_video_packet_header(h);
246 else
247 #endif
248 2544 ret = h263_decode_gob_header(h);
249
1/2
✓ Branch 0 taken 6451 times.
✗ Branch 1 not taken.
6451 if(ret>=0)
250 6451 return pos;
251 }
252 //OK, it's not where it is supposed to be ...
253 h->gb = h->last_resync_gb;
254 align_get_bits(&h->gb);
255 left = get_bits_left(&h->gb);
256
257 for(;left>16+1+5+5; left-=8){
258 if (show_bits(&h->gb, 16) == 0){
259 GetBitContext bak = h->gb;
260
261 pos = get_bits_count(&h->gb);
262 #if CONFIG_MPEG4_DECODER
263 if (h->c.codec_id == AV_CODEC_ID_MPEG4)
264 ret = ff_mpeg4_decode_video_packet_header(h);
265 else
266 #endif
267 ret = h263_decode_gob_header(h);
268 if(ret>=0)
269 return pos;
270
271 h->gb = bak;
272 }
273 skip_bits(&h->gb, 8);
274 }
275
276 return -1;
277 }
278
279 3776878 int ff_h263_decode_motion(H263DecContext *const h, int pred, int f_code)
280 {
281 int code, val, sign, shift;
282 3776878 code = get_vlc2(&h->gb, ff_h263_mv_vlc, H263_MV_VLC_BITS, 2);
283
284
2/2
✓ Branch 0 taken 1854435 times.
✓ Branch 1 taken 1922443 times.
3776878 if (code == 0)
285 1854435 return pred;
286
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1922443 times.
1922443 if (code < 0)
287 return 0xffff;
288
289 1922443 sign = get_bits1(&h->gb);
290 1922443 shift = f_code - 1;
291 1922443 val = code;
292
2/2
✓ Branch 0 taken 210536 times.
✓ Branch 1 taken 1711907 times.
1922443 if (shift) {
293 210536 val = (val - 1) << shift;
294 210536 val |= get_bits(&h->gb, shift);
295 210536 val++;
296 }
297
2/2
✓ Branch 0 taken 804810 times.
✓ Branch 1 taken 1117633 times.
1922443 if (sign)
298 804810 val = -val;
299 1922443 val += pred;
300
301 /* modulo decoding */
302
1/2
✓ Branch 0 taken 1922443 times.
✗ Branch 1 not taken.
1922443 if (!h->h263_long_vectors) {
303 1922443 val = sign_extend(val, 5 + f_code);
304 } else {
305 /* horrible H.263 long vector mode */
306 if (pred < -31 && val < -63)
307 val += 64;
308 if (pred > 32 && val > 63)
309 val -= 64;
310
311 }
312 1922443 return val;
313 }
314
315
316 /* Decode RVLC of H.263+ UMV */
317 103298 static int h263p_decode_umotion(H263DecContext *const h, int pred)
318 {
319 103298 int code = 0, sign;
320
321
2/2
✓ Branch 1 taken 51255 times.
✓ Branch 2 taken 52043 times.
103298 if (get_bits1(&h->gb)) /* Motion difference = 0 */
322 51255 return pred;
323
324 52043 code = 2 + get_bits1(&h->gb);
325
326
2/2
✓ Branch 1 taken 28759 times.
✓ Branch 2 taken 52043 times.
80802 while (get_bits1(&h->gb))
327 {
328 28759 code <<= 1;
329 28759 code += get_bits1(&h->gb);
330
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28759 times.
28759 if (code >= 32768) {
331 avpriv_request_sample(h->c.avctx, "Huge DMV");
332 return 0xffff;
333 }
334 }
335 52043 sign = code & 1;
336 52043 code >>= 1;
337
338
2/2
✓ Branch 0 taken 30417 times.
✓ Branch 1 taken 21626 times.
52043 code = (sign) ? (pred - code) : (pred + code);
339 ff_tlog(h->c.avctx,"H.263+ UMV Motion = %d\n", code);
340 52043 return code;
341
342 }
343
344 /**
345 * read the next MVs for OBMC. yes this is an ugly hack, feel free to send a patch :)
346 */
347 48550 static void preview_obmc(H263DecContext *const h)
348 {
349 48550 GetBitContext gb = h->gb;
350
351 int cbpc, i, pred_x, pred_y, mx, my;
352 int16_t *mot_val;
353 48550 const int xy = h->c.mb_x + 1 + h->c.mb_y * h->c.mb_stride;
354 48550 const int stride = h->c.b8_stride * 2;
355
356
2/2
✓ Branch 0 taken 194200 times.
✓ Branch 1 taken 48550 times.
242750 for(i=0; i<4; i++)
357 194200 h->c.block_index[i] += 2;
358
2/2
✓ Branch 0 taken 97100 times.
✓ Branch 1 taken 48550 times.
145650 for(i=4; i<6; i++)
359 97100 h->c.block_index[i] += 1;
360 48550 h->c.mb_x++;
361
362 av_assert2(h->c.pict_type == AV_PICTURE_TYPE_P);
363
364 do{
365
2/2
✓ Branch 1 taken 654 times.
✓ Branch 2 taken 47896 times.
48550 if (get_bits1(&h->gb)) {
366 /* skip mb */
367 654 mot_val = h->c.cur_pic.motion_val[0][h->c.block_index[0]];
368 654 mot_val[0 ]= mot_val[2 ]=
369 654 mot_val[0+stride]= mot_val[2+stride]= 0;
370 654 mot_val[1 ]= mot_val[3 ]=
371 654 mot_val[1+stride]= mot_val[3+stride]= 0;
372
373 654 h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
374 654 goto end;
375 }
376 47896 cbpc = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 47896 times.
47896 }while(cbpc == 20);
378
379
2/2
✓ Branch 0 taken 957 times.
✓ Branch 1 taken 46939 times.
47896 if(cbpc & 4){
380 957 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
381 }else{
382 46939 get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
383
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46939 times.
46939 if (cbpc & 8) {
384 skip_bits(&h->gb, h->modified_quant ? (get_bits1(&h->gb) ? 1 : 5) : 2);
385 }
386
387
1/2
✓ Branch 0 taken 46939 times.
✗ Branch 1 not taken.
46939 if ((cbpc & 16) == 0) {
388 46939 h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
389 /* 16x16 motion prediction */
390 46939 mot_val= ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
391
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46939 times.
46939 if (h->umvplus)
392 mx = h263p_decode_umotion(h, pred_x);
393 else
394 46939 mx = ff_h263_decode_motion(h, pred_x, 1);
395
396
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46939 times.
46939 if (h->umvplus)
397 my = h263p_decode_umotion(h, pred_y);
398 else
399 46939 my = ff_h263_decode_motion(h, pred_y, 1);
400
401 46939 mot_val[0 ]= mot_val[2 ]=
402 46939 mot_val[0+stride]= mot_val[2+stride]= mx;
403 46939 mot_val[1 ]= mot_val[3 ]=
404 46939 mot_val[1+stride]= mot_val[3+stride]= my;
405 } else {
406 h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
407 for(i=0;i<4;i++) {
408 mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
409 if (h->umvplus)
410 mx = h263p_decode_umotion(h, pred_x);
411 else
412 mx = ff_h263_decode_motion(h, pred_x, 1);
413
414 if (h->umvplus)
415 my = h263p_decode_umotion(h, pred_y);
416 else
417 my = ff_h263_decode_motion(h, pred_y, 1);
418 if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
419 skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
420 mot_val[0] = mx;
421 mot_val[1] = my;
422 }
423 }
424 }
425 end:
426
427
2/2
✓ Branch 0 taken 194200 times.
✓ Branch 1 taken 48550 times.
242750 for(i=0; i<4; i++)
428 194200 h->c.block_index[i] -= 2;
429
2/2
✓ Branch 0 taken 97100 times.
✓ Branch 1 taken 48550 times.
145650 for(i=4; i<6; i++)
430 97100 h->c.block_index[i] -= 1;
431 48550 h->c.mb_x--;
432
433 48550 h->gb = gb;
434 48550 }
435
436 static void h263_decode_dquant(H263DecContext *const h)
437 {
438 static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
439 int qscale;
440
441 if (h->modified_quant) {
442 if (get_bits1(&h->gb))
443 qscale = ff_modified_quant_tab[get_bits1(&h->gb)][h->c.qscale];
444 else
445 qscale = get_bits(&h->gb, 5);
446 }else
447 qscale = h->c.qscale + quant_tab[get_bits(&h->gb, 2)];
448 ff_set_qscale(&h->c, qscale);
449 }
450
451 91098 static void h263_pred_acdc(MpegEncContext * s, int16_t *block, int n)
452 {
453 int wrap, a, c, pred_dc, scale;
454 91098 const int xy = s->block_index[n];
455 91098 int16_t *const dc_val = s->dc_val + xy;
456 91098 int16_t *const ac_val = (s->ac_val + xy)[0];
457
458 /* find prediction */
459
2/2
✓ Branch 0 taken 60732 times.
✓ Branch 1 taken 30366 times.
91098 if (n < 4) {
460 60732 wrap = s->b8_stride;
461 60732 scale = s->y_dc_scale;
462 } else {
463 30366 wrap = s->mb_stride;
464 30366 scale = s->c_dc_scale;
465 }
466
467 /* B C
468 * A X
469 */
470 91098 a = dc_val[-1];
471 91098 c = dc_val[-wrap];
472
473 /* No prediction outside GOB boundary */
474
4/4
✓ Branch 0 taken 54174 times.
✓ Branch 1 taken 36924 times.
✓ Branch 2 taken 45145 times.
✓ Branch 3 taken 9029 times.
91098 if (s->first_slice_line && n != 3) {
475
2/2
✓ Branch 0 taken 36116 times.
✓ Branch 1 taken 9029 times.
45145 if (n != 2) c= 1024;
476
4/4
✓ Branch 0 taken 36116 times.
✓ Branch 1 taken 9029 times.
✓ Branch 2 taken 1348 times.
✓ Branch 3 taken 34768 times.
45145 if (n != 1 && s->mb_x == s->resync_mb_x) a= 1024;
477 }
478
479
2/2
✓ Branch 0 taken 4434 times.
✓ Branch 1 taken 86664 times.
91098 if (s->ac_pred) {
480 4434 pred_dc = 1024;
481
2/2
✓ Branch 0 taken 1596 times.
✓ Branch 1 taken 2838 times.
4434 if (s->h263_aic_dir) {
482 /* left prediction */
483
2/2
✓ Branch 0 taken 1576 times.
✓ Branch 1 taken 20 times.
1596 if (a != 1024) {
484 1576 int16_t *const ac_val2 = ac_val - 16;
485
2/2
✓ Branch 0 taken 11032 times.
✓ Branch 1 taken 1576 times.
12608 for (int i = 1; i < 8; i++) {
486 11032 block[s->idsp.idct_permutation[i << 3]] += ac_val2[i];
487 }
488 1576 pred_dc = a;
489 }
490 } else {
491 /* top prediction */
492
2/2
✓ Branch 0 taken 1910 times.
✓ Branch 1 taken 928 times.
2838 if (c != 1024) {
493 1910 int16_t *const ac_val2 = ac_val - 16 * wrap;
494
2/2
✓ Branch 0 taken 13370 times.
✓ Branch 1 taken 1910 times.
15280 for (int i = 1; i < 8; i++) {
495 13370 block[s->idsp.idct_permutation[i]] += ac_val2[i + 8];
496 }
497 1910 pred_dc = c;
498 }
499 }
500 } else {
501 /* just DC prediction */
502
4/4
✓ Branch 0 taken 81140 times.
✓ Branch 1 taken 5524 times.
✓ Branch 2 taken 50003 times.
✓ Branch 3 taken 31137 times.
86664 if (a != 1024 && c != 1024)
503 50003 pred_dc = (a + c) >> 1;
504
2/2
✓ Branch 0 taken 31137 times.
✓ Branch 1 taken 5524 times.
36661 else if (a != 1024)
505 31137 pred_dc = a;
506 else
507 5524 pred_dc = c;
508 }
509
510 /* we assume pred is positive */
511 91098 block[0] = block[0] * scale + pred_dc;
512
513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 91098 times.
91098 if (block[0] < 0)
514 block[0] = 0;
515 else
516 91098 block[0] |= 1;
517
518 /* Update AC/DC tables */
519 91098 *dc_val = block[0];
520
521 /* left copy */
522
2/2
✓ Branch 0 taken 637686 times.
✓ Branch 1 taken 91098 times.
728784 for (int i = 1; i < 8; i++)
523 637686 ac_val[i] = block[s->idsp.idct_permutation[i << 3]];
524 /* top copy */
525
2/2
✓ Branch 0 taken 637686 times.
✓ Branch 1 taken 91098 times.
728784 for (int i = 1; i < 8; i++)
526 637686 ac_val[8 + i] = block[s->idsp.idct_permutation[i]];
527 91098 }
528
529 2590998 static int h263_decode_block(H263DecContext *const h, int16_t block[64],
530 int n, int coded)
531 {
532 int level, i, j, run;
533 2590998 const RLTable *rl = &ff_h263_rl_inter;
534 const uint8_t *scan_table;
535 2590998 GetBitContext gb = h->gb;
536
537 2590998 scan_table = h->c.intra_scantable.permutated;
538
4/4
✓ Branch 0 taken 400992 times.
✓ Branch 1 taken 2190006 times.
✓ Branch 2 taken 91098 times.
✓ Branch 3 taken 309894 times.
2590998 if (h->c.h263_aic && h->c.mb_intra) {
539 91098 i = 0;
540
2/2
✓ Branch 0 taken 3823 times.
✓ Branch 1 taken 87275 times.
91098 if (!coded)
541 3823 goto not_coded;
542 87275 rl = &ff_rl_intra_aic;
543
2/2
✓ Branch 0 taken 3073 times.
✓ Branch 1 taken 84202 times.
87275 if (h->c.ac_pred) {
544
2/2
✓ Branch 0 taken 1148 times.
✓ Branch 1 taken 1925 times.
3073 if (h->c.h263_aic_dir)
545 1148 scan_table = h->c.permutated_intra_v_scantable; /* left */
546 else
547 1925 scan_table = h->c.permutated_intra_h_scantable; /* top */
548 }
549
2/2
✓ Branch 0 taken 300744 times.
✓ Branch 1 taken 2199156 times.
2499900 } else if (h->c.mb_intra) {
550 /* DC coef */
551
2/2
✓ Branch 0 taken 46710 times.
✓ Branch 1 taken 254034 times.
300744 if (CONFIG_RV10_DECODER && h->c.codec_id == AV_CODEC_ID_RV10) {
552
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46710 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46710 if (h->rv10_version == 3 && h->c.pict_type == AV_PICTURE_TYPE_I) {
553 int component = (n <= 3 ? 0 : n - 4 + 1);
554 level = h->c.last_dc[component];
555 if (h->rv10_first_dc_coded[component]) {
556 int diff = ff_rv_decode_dc(h, n);
557 if (diff < 0)
558 return -1;
559 level += diff;
560 level = level & 0xff; /* handle wrap round */
561 h->c.last_dc[component] = level;
562 } else {
563 h->rv10_first_dc_coded[component] = 1;
564 }
565 } else {
566 46710 level = get_bits(&h->gb, 8);
567
2/2
✓ Branch 0 taken 542 times.
✓ Branch 1 taken 46168 times.
46710 if (level == 255)
568 542 level = 128;
569 }
570 }else{
571 254034 level = get_bits(&h->gb, 8);
572
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 254034 times.
254034 if((level&0x7F) == 0){
573 av_log(h->c.avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
574 level, h->c.mb_x, h->c.mb_y);
575 if (h->c.avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
576 return -1;
577 }
578
2/2
✓ Branch 0 taken 3049 times.
✓ Branch 1 taken 250985 times.
254034 if (level == 255)
579 3049 level = 128;
580 }
581 300744 block[0] = level;
582 300744 i = 1;
583 } else {
584 2199156 i = 0;
585 }
586
2/2
✓ Branch 0 taken 1345756 times.
✓ Branch 1 taken 1241419 times.
2587175 if (!coded) {
587 1241419 h->c.block_last_index[n] = i - 1;
588 1241419 return 0;
589 }
590 1345756 retry:
591 {
592 1412215 OPEN_READER(re, &h->gb);
593 1412215 i--; // offset by -1 to allow direct indexing of scan_table
594 for(;;) {
595 26689671 UPDATE_CACHE(re, &h->gb);
596
2/2
✓ Branch 1 taken 893282 times.
✓ Branch 2 taken 13157661 times.
14050943 GET_RL_VLC(level, run, re, &h->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
597
2/2
✓ Branch 0 taken 587695 times.
✓ Branch 1 taken 13463248 times.
14050943 if (run == 66) {
598
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 587695 times.
587695 if (level){
599 CLOSE_READER(re, &h->gb);
600 av_log(h->c.avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
601 h->c.mb_x, h->c.mb_y);
602 return -1;
603 }
604 /* escape */
605
2/2
✓ Branch 0 taken 117640 times.
✓ Branch 1 taken 470055 times.
587695 if (CONFIG_FLV_DECODER && h->flv) {
606 117640 int is11 = SHOW_UBITS(re, &h->gb, 1);
607 117640 SKIP_CACHE(re, &h->gb, 1);
608 117640 run = SHOW_UBITS(re, &h->gb, 7) + 1;
609
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 117640 times.
117640 if (is11) {
610 SKIP_COUNTER(re, &h->gb, 1 + 7);
611 UPDATE_CACHE(re, &h->gb);
612 level = SHOW_SBITS(re, &h->gb, 11);
613 SKIP_COUNTER(re, &h->gb, 11);
614 } else {
615 117640 SKIP_CACHE(re, &h->gb, 7);
616 117640 level = SHOW_SBITS(re, &h->gb, 7);
617 117640 SKIP_COUNTER(re, &h->gb, 1 + 7 + 7);
618 }
619 } else {
620 470055 run = SHOW_UBITS(re, &h->gb, 7) + 1;
621 470055 SKIP_CACHE(re, &h->gb, 7);
622 470055 level = (int8_t)SHOW_UBITS(re, &h->gb, 8);
623 470055 SKIP_COUNTER(re, &h->gb, 7 + 8);
624
2/2
✓ Branch 0 taken 3157 times.
✓ Branch 1 taken 466898 times.
470055 if(level == -128){
625 3157 UPDATE_CACHE(re, &h->gb);
626
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3157 times.
3157 if (h->c.codec_id == AV_CODEC_ID_RV10) {
627 /* XXX: should patch encoder too */
628 level = SHOW_SBITS(re, &h->gb, 12);
629 SKIP_COUNTER(re, &h->gb, 12);
630 }else{
631 3157 level = SHOW_UBITS(re, &h->gb, 5);
632 3157 SKIP_CACHE(re, &h->gb, 5);
633 3157 level |= SHOW_SBITS(re, &h->gb, 6) * (1<<5);
634 3157 SKIP_COUNTER(re, &h->gb, 5 + 6);
635 }
636 }
637 }
638 } else {
639
2/2
✓ Branch 1 taken 6708475 times.
✓ Branch 2 taken 6754773 times.
13463248 if (SHOW_UBITS(re, &h->gb, 1))
640 6708475 level = -level;
641 13463248 SKIP_COUNTER(re, &h->gb, 1);
642 }
643 14050943 i += run;
644
2/2
✓ Branch 0 taken 1412215 times.
✓ Branch 1 taken 12638728 times.
14050943 if (i >= 64){
645 1412215 CLOSE_READER(re, &h->gb);
646 // redo update without last flag, revert -1 offset
647 1412215 i = i - run + ((run-1)&63) + 1;
648
2/2
✓ Branch 0 taken 1345756 times.
✓ Branch 1 taken 66459 times.
1412215 if (i < 64) {
649 // only last marker, no overrun
650 1345756 block[scan_table[i]] = level;
651 1345756 break;
652 }
653
3/6
✓ Branch 0 taken 66459 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66459 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 66459 times.
✗ Branch 5 not taken.
66459 if(h->alt_inter_vlc && rl == &ff_h263_rl_inter && !h->c.mb_intra){
654 //Looks like a hack but no, it's the way it is supposed to work ...
655 66459 rl = &ff_rl_intra_aic;
656 66459 i = 0;
657 66459 h->gb = gb;
658 66459 h->c.bdsp.clear_block(block);
659 66459 goto retry;
660 }
661 av_log(h->c.avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n",
662 h->c.mb_x, h->c.mb_y, h->c.mb_intra);
663 return -1;
664 }
665 12638728 j = scan_table[i];
666 12638728 block[j] = level;
667 }
668 }
669
4/4
✓ Branch 0 taken 350482 times.
✓ Branch 1 taken 995274 times.
✓ Branch 2 taken 87275 times.
✓ Branch 3 taken 263207 times.
1345756 if (h->c.mb_intra && h->c.h263_aic) {
670 87275 not_coded:
671 91098 h263_pred_acdc(&h->c, block, n);
672 }
673 1349579 h->c.block_last_index[n] = i;
674 1349579 return 0;
675 }
676
677 static int h263_skip_b_part(H263DecContext *const h, int cbp)
678 {
679 LOCAL_ALIGNED_32(int16_t, dblock, [64]);
680 int i, mbi;
681 int bli[6];
682
683 /* we have to set h->c.mb_intra to zero to decode B-part of PB-frame correctly
684 * but real value should be restored in order to be used later (in OBMC condition)
685 */
686 mbi = h->c.mb_intra;
687 memcpy(bli, h->c.block_last_index, sizeof(bli));
688 h->c.mb_intra = 0;
689 for (i = 0; i < 6; i++) {
690 if (h263_decode_block(h, dblock, i, cbp&32) < 0)
691 return -1;
692 cbp+=cbp;
693 }
694 h->c.mb_intra = mbi;
695 memcpy(h->c.block_last_index, bli, sizeof(bli));
696 return 0;
697 }
698
699 static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb)
700 {
701 int c, mv = 1;
702
703 if (pb_frame < 3) { // h.263 Annex G and i263 PB-frame
704 c = get_bits1(gb);
705 if (pb_frame == 2 && c)
706 mv = !get_bits1(gb);
707 } else { // h.263 Annex M improved PB-frame
708 mv = get_unary(gb, 0, 4) + 1;
709 c = mv & 1;
710 mv = !!(mv & 2);
711 }
712 if(c)
713 *cbpb = get_bits(gb, 6);
714 return mv;
715 }
716
717 #define tab_size ((signed)FF_ARRAY_ELEMS(s->direct_scale_mv[0]))
718 #define tab_bias (tab_size / 2)
719 15407 static inline void set_one_direct_mv(MpegEncContext *s, const MPVPicture *p, int i)
720 {
721 15407 int xy = s->block_index[i];
722 15407 uint16_t time_pp = s->pp_time;
723 15407 uint16_t time_pb = s->pb_time;
724 int p_mx, p_my;
725
726 15407 p_mx = p->motion_val[0][xy][0];
727
1/2
✓ Branch 0 taken 15407 times.
✗ Branch 1 not taken.
15407 if ((unsigned)(p_mx + tab_bias) < tab_size) {
728 15407 s->mv[0][i][0] = s->direct_scale_mv[0][p_mx + tab_bias];
729 15407 s->mv[1][i][0] = s->direct_scale_mv[1][p_mx + tab_bias];
730 } else {
731 s->mv[0][i][0] = p_mx * time_pb / time_pp;
732 s->mv[1][i][0] = p_mx * (time_pb - time_pp) / time_pp;
733 }
734 15407 p_my = p->motion_val[0][xy][1];
735
1/2
✓ Branch 0 taken 15407 times.
✗ Branch 1 not taken.
15407 if ((unsigned)(p_my + tab_bias) < tab_size) {
736 15407 s->mv[0][i][1] = s->direct_scale_mv[0][p_my + tab_bias];
737 15407 s->mv[1][i][1] = s->direct_scale_mv[1][p_my + tab_bias];
738 } else {
739 s->mv[0][i][1] = p_my * time_pb / time_pp;
740 s->mv[1][i][1] = p_my * (time_pb - time_pp) / time_pp;
741 }
742 15407 }
743
744 /**
745 * @return the mb_type
746 */
747 15266 static int set_direct_mv(MpegEncContext *s)
748 {
749 15266 const int mb_index = s->mb_x + s->mb_y * s->mb_stride;
750 15266 const MPVPicture *p = s->next_pic.ptr;
751 15266 int colocated_mb_type = p->mb_type[mb_index];
752 int i;
753
754
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 15266 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
15266 if (s->codec_tag == AV_RL32("U263") && p->f->pict_type == AV_PICTURE_TYPE_I) {
755 p = s->last_pic.ptr;
756 colocated_mb_type = p->mb_type[mb_index];
757 }
758
759
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 15219 times.
15266 if (IS_8X8(colocated_mb_type)) {
760 47 s->mv_type = MV_TYPE_8X8;
761
2/2
✓ Branch 0 taken 188 times.
✓ Branch 1 taken 47 times.
235 for (i = 0; i < 4; i++)
762 188 set_one_direct_mv(s, p, i);
763 47 return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_BIDIR_MV;
764 } else {
765 15219 set_one_direct_mv(s, p, 0);
766 15219 s->mv[0][1][0] =
767 15219 s->mv[0][2][0] =
768 15219 s->mv[0][3][0] = s->mv[0][0][0];
769 15219 s->mv[0][1][1] =
770 15219 s->mv[0][2][1] =
771 15219 s->mv[0][3][1] = s->mv[0][0][1];
772 15219 s->mv[1][1][0] =
773 15219 s->mv[1][2][0] =
774 15219 s->mv[1][3][0] = s->mv[1][0][0];
775 15219 s->mv[1][1][1] =
776 15219 s->mv[1][2][1] =
777 15219 s->mv[1][3][1] = s->mv[1][0][1];
778 15219 s->mv_type = MV_TYPE_8X8;
779 // Note see prev line
780 15219 return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_BIDIR_MV;
781 }
782 }
783
784 441138 int ff_h263_decode_mb(H263DecContext *const h)
785 {
786 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
787 int16_t *mot_val;
788 441138 const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
789 441138 int cbpb = 0, pb_mv_count = 0;
790
791 av_assert2(!h->c.h263_pred);
792
793
2/2
✓ Branch 0 taken 367701 times.
✓ Branch 1 taken 73437 times.
441138 if (h->c.pict_type == AV_PICTURE_TYPE_P) {
794 do{
795
2/2
✓ Branch 1 taken 9305 times.
✓ Branch 2 taken 358396 times.
367701 if (get_bits1(&h->gb)) {
796 /* skip mb */
797 9305 h->c.mb_intra = 0;
798
2/2
✓ Branch 0 taken 55830 times.
✓ Branch 1 taken 9305 times.
65135 for(i=0;i<6;i++)
799 55830 h->c.block_last_index[i] = -1;
800 9305 h->c.mv_dir = MV_DIR_FORWARD;
801 9305 h->c.mv_type = MV_TYPE_16X16;
802 9305 h->c.cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
803 9305 h->c.mv[0][0][0] = 0;
804 9305 h->c.mv[0][0][1] = 0;
805 9305 h->c.mb_skipped = !(h->c.obmc | h->loop_filter);
806 9305 goto end;
807 }
808 358396 cbpc = get_vlc2(&h->gb, ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 2);
809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 358396 times.
358396 if (cbpc < 0){
810 av_log(h->c.avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n",
811 h->c.mb_x, h->c.mb_y);
812 return SLICE_ERROR;
813 }
814
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 358396 times.
358396 }while(cbpc == 20);
815
816 358396 h->c.bdsp.clear_blocks(h->block[0]);
817
818 358396 dquant = cbpc & 8;
819 358396 h->c.mb_intra = ((cbpc & 4) != 0);
820
2/2
✓ Branch 0 taken 13424 times.
✓ Branch 1 taken 344972 times.
358396 if (h->c.mb_intra)
821 13424 goto intra;
822
823
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 344972 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
344972 if (h->pb_frame && get_bits1(&h->gb))
824 pb_mv_count = h263_get_modb(&h->gb, h->pb_frame, &cbpb);
825 344972 cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
826
827
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 344972 times.
344972 if (cbpy < 0) {
828 av_log(h->c.avctx, AV_LOG_ERROR, "cbpy damaged at %d %d\n",
829 h->c.mb_x, h->c.mb_y);
830 return SLICE_ERROR;
831 }
832
833
4/4
✓ Branch 0 taken 51649 times.
✓ Branch 1 taken 293323 times.
✓ Branch 2 taken 13805 times.
✓ Branch 3 taken 37844 times.
344972 if (!h->alt_inter_vlc|| (cbpc & 3)!=3)
834 307128 cbpy ^= 0xF;
835
836 344972 cbp = (cbpc & 3) | (cbpy << 2);
837
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 344972 times.
344972 if (dquant) {
838 h263_decode_dquant(h);
839 }
840
841 344972 h->c.mv_dir = MV_DIR_FORWARD;
842
2/2
✓ Branch 0 taken 343929 times.
✓ Branch 1 taken 1043 times.
344972 if ((cbpc & 16) == 0) {
843 343929 h->c.cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
844 /* 16x16 motion prediction */
845 343929 h->c.mv_type = MV_TYPE_16X16;
846 343929 ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
847
2/2
✓ Branch 0 taken 51649 times.
✓ Branch 1 taken 292280 times.
343929 if (h->umvplus)
848 51649 mx = h263p_decode_umotion(h, pred_x);
849 else
850 292280 mx = ff_h263_decode_motion(h, pred_x, 1);
851
852
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 343929 times.
343929 if (mx >= 0xffff)
853 return SLICE_ERROR;
854
855
2/2
✓ Branch 0 taken 51649 times.
✓ Branch 1 taken 292280 times.
343929 if (h->umvplus)
856 51649 my = h263p_decode_umotion(h, pred_y);
857 else
858 292280 my = ff_h263_decode_motion(h, pred_y, 1);
859
860
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 343929 times.
343929 if (my >= 0xffff)
861 return SLICE_ERROR;
862 343929 h->c.mv[0][0][0] = mx;
863 343929 h->c.mv[0][0][1] = my;
864
865
6/6
✓ Branch 0 taken 51649 times.
✓ Branch 1 taken 292280 times.
✓ Branch 2 taken 10131 times.
✓ Branch 3 taken 41518 times.
✓ Branch 4 taken 340 times.
✓ Branch 5 taken 9791 times.
343929 if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
866 340 skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
867 } else {
868 1043 h->c.cur_pic.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_FORWARD_MV;
869 1043 h->c.mv_type = MV_TYPE_8X8;
870
2/2
✓ Branch 0 taken 4172 times.
✓ Branch 1 taken 1043 times.
5215 for(i=0;i<4;i++) {
871 4172 mot_val = ff_h263_pred_motion(&h->c, i, 0, &pred_x, &pred_y);
872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4172 times.
4172 if (h->umvplus)
873 mx = h263p_decode_umotion(h, pred_x);
874 else
875 4172 mx = ff_h263_decode_motion(h, pred_x, 1);
876
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4172 times.
4172 if (mx >= 0xffff)
877 return SLICE_ERROR;
878
879
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4172 times.
4172 if (h->umvplus)
880 my = h263p_decode_umotion(h, pred_y);
881 else
882 4172 my = ff_h263_decode_motion(h, pred_y, 1);
883
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4172 times.
4172 if (my >= 0xffff)
884 return SLICE_ERROR;
885 4172 h->c.mv[0][i][0] = mx;
886 4172 h->c.mv[0][i][1] = my;
887
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4172 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
4172 if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
888 skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
889 4172 mot_val[0] = mx;
890 4172 mot_val[1] = my;
891 }
892 }
893
2/2
✓ Branch 0 taken 21600 times.
✓ Branch 1 taken 51837 times.
73437 } else if (h->c.pict_type==AV_PICTURE_TYPE_B) {
894 int mb_type;
895 21600 const int stride = h->c.b8_stride;
896 21600 int16_t *mot_val0 = h->c.cur_pic.motion_val[0][2 * (h->c.mb_x + h->c.mb_y * stride)];
897 21600 int16_t *mot_val1 = h->c.cur_pic.motion_val[1][2 * (h->c.mb_x + h->c.mb_y * stride)];
898 // const int mv_xy = h->c.mb_x + 1 + h->c.mb_y * h->c.mb_stride;
899
900 //FIXME ugly
901 21600 mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]=
902 21600 mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]=
903 21600 mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]=
904 21600 mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0;
905
906 do{
907 21600 mb_type = get_vlc2(&h->gb, h263_mbtype_b_vlc,
908 H263_MBTYPE_B_VLC_BITS, 2);
909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21600 times.
21600 if (mb_type < 0){
910 av_log(h->c.avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n",
911 h->c.mb_x, h->c.mb_y);
912 return SLICE_ERROR;
913 }
914
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21600 times.
21600 }while(!mb_type);
915
916 21600 h->c.mb_intra = IS_INTRA(mb_type);
917
2/2
✓ Branch 0 taken 11402 times.
✓ Branch 1 taken 10198 times.
21600 if(HAS_CBP(mb_type)){
918 11402 h->c.bdsp.clear_blocks(h->block[0]);
919 11402 cbpc = get_vlc2(&h->gb, cbpc_b_vlc, CBPC_B_VLC_BITS, 1);
920
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 11356 times.
11402 if (h->c.mb_intra) {
921 46 dquant = IS_QUANT(mb_type);
922 46 goto intra;
923 }
924
925 11356 cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
926
927
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11356 times.
11356 if (cbpy < 0){
928 av_log(h->c.avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n",
929 h->c.mb_x, h->c.mb_y);
930 return SLICE_ERROR;
931 }
932
933
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11356 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11356 if (!h->alt_inter_vlc || (cbpc & 3)!=3)
934 11356 cbpy ^= 0xF;
935
936 11356 cbp = (cbpc & 3) | (cbpy << 2);
937 }else
938 10198 cbp=0;
939
940 av_assert2(!h->c.mb_intra);
941
942
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21554 times.
21554 if(IS_QUANT(mb_type)){
943 h263_decode_dquant(h);
944 }
945
946
2/2
✓ Branch 0 taken 15266 times.
✓ Branch 1 taken 6288 times.
21554 if(IS_DIRECT(mb_type)){
947 15266 h->c.mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
948 15266 mb_type |= set_direct_mv(&h->c);
949 }else{
950 6288 h->c.mv_dir = 0;
951 6288 h->c.mv_type = MV_TYPE_16X16;
952 //FIXME UMV
953
954
2/2
✓ Branch 0 taken 2594 times.
✓ Branch 1 taken 3694 times.
6288 if (HAS_FORWARD_MV(mb_type)) {
955 2594 int16_t *mot_val = ff_h263_pred_motion(&h->c, 0, 0, &pred_x, &pred_y);
956 2594 h->c.mv_dir = MV_DIR_FORWARD;
957
958
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2594 times.
2594 if (h->umvplus)
959 mx = h263p_decode_umotion(h, pred_x);
960 else
961 2594 mx = ff_h263_decode_motion(h, pred_x, 1);
962
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2594 times.
2594 if (mx >= 0xffff)
963 return SLICE_ERROR;
964
965
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2594 times.
2594 if (h->umvplus)
966 my = h263p_decode_umotion(h, pred_y);
967 else
968 2594 my = ff_h263_decode_motion(h, pred_y, 1);
969
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2594 times.
2594 if (my >= 0xffff)
970 return SLICE_ERROR;
971
972
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2594 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
2594 if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
973 skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
974
975 2594 h->c.mv[0][0][0] = mx;
976 2594 h->c.mv[0][0][1] = my;
977 2594 mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
978 2594 mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
979 }
980
981
2/2
✓ Branch 0 taken 3694 times.
✓ Branch 1 taken 2594 times.
6288 if (HAS_BACKWARD_MV(mb_type)) {
982 3694 int16_t *mot_val = ff_h263_pred_motion(&h->c, 0, 1, &pred_x, &pred_y);
983 3694 h->c.mv_dir |= MV_DIR_BACKWARD;
984
985
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3694 times.
3694 if (h->umvplus)
986 mx = h263p_decode_umotion(h, pred_x);
987 else
988 3694 mx = ff_h263_decode_motion(h, pred_x, 1);
989
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3694 times.
3694 if (mx >= 0xffff)
990 return SLICE_ERROR;
991
992
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3694 times.
3694 if (h->umvplus)
993 my = h263p_decode_umotion(h, pred_y);
994 else
995 3694 my = ff_h263_decode_motion(h, pred_y, 1);
996
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3694 times.
3694 if (my >= 0xffff)
997 return SLICE_ERROR;
998
999
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 3694 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3694 if (h->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
1000 skip_bits1(&h->gb); /* Bit stuffing to prevent PSC */
1001
1002 3694 h->c.mv[1][0][0] = mx;
1003 3694 h->c.mv[1][0][1] = my;
1004 3694 mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
1005 3694 mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
1006 }
1007 }
1008
1009 21554 h->c.cur_pic.mb_type[xy] = mb_type;
1010 } else { /* I-Frame */
1011 do{
1012 51837 cbpc = get_vlc2(&h->gb, ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 2);
1013
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51837 times.
51837 if (cbpc < 0){
1014 av_log(h->c.avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n",
1015 h->c.mb_x, h->c.mb_y);
1016 return SLICE_ERROR;
1017 }
1018
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51837 times.
51837 }while(cbpc == 8);
1019
1020 51837 h->c.bdsp.clear_blocks(h->block[0]);
1021
1022 51837 dquant = cbpc & 4;
1023 51837 h->c.mb_intra = 1;
1024 65307 intra:
1025 65307 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA;
1026
2/2
✓ Branch 0 taken 15183 times.
✓ Branch 1 taken 50124 times.
65307 if (h->c.h263_aic) {
1027 15183 h->c.ac_pred = get_bits1(&h->gb);
1028
2/2
✓ Branch 0 taken 739 times.
✓ Branch 1 taken 14444 times.
15183 if (h->c.ac_pred) {
1029 739 h->c.cur_pic.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
1030
1031 739 h->c.h263_aic_dir = get_bits1(&h->gb);
1032 }
1033 }else
1034 50124 h->c.ac_pred = 0;
1035
1036
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 65307 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
65307 if (h->pb_frame && get_bits1(&h->gb))
1037 pb_mv_count = h263_get_modb(&h->gb, h->pb_frame, &cbpb);
1038 65307 cbpy = get_vlc2(&h->gb, ff_h263_cbpy_vlc, CBPY_VLC_BITS, 1);
1039
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 65307 times.
65307 if(cbpy<0){
1040 av_log(h->c.avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n",
1041 h->c.mb_x, h->c.mb_y);
1042 return SLICE_ERROR;
1043 }
1044 65307 cbp = (cbpc & 3) | (cbpy << 2);
1045
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 65307 times.
65307 if (dquant) {
1046 h263_decode_dquant(h);
1047 }
1048
1049 65307 pb_mv_count += !!h->pb_frame;
1050 }
1051
1052
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 431833 times.
431833 while(pb_mv_count--){
1053 ff_h263_decode_motion(h, 0, 1);
1054 ff_h263_decode_motion(h, 0, 1);
1055 }
1056
1057 /* decode each block */
1058
2/2
✓ Branch 0 taken 2590998 times.
✓ Branch 1 taken 431833 times.
3022831 for (i = 0; i < 6; i++) {
1059
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2590998 times.
2590998 if (h263_decode_block(h, h->block[i], i, cbp&32) < 0)
1060 return -1;
1061 2590998 cbp+=cbp;
1062 }
1063
1064
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 431833 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
431833 if (h->pb_frame && h263_skip_b_part(h, cbpb) < 0)
1065 return -1;
1066
4/4
✓ Branch 0 taken 373249 times.
✓ Branch 1 taken 58584 times.
✓ Branch 2 taken 7779 times.
✓ Branch 3 taken 50805 times.
431833 if (h->c.obmc && !h->c.mb_intra) {
1067
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50805 times.
50805 if (h->c.pict_type == AV_PICTURE_TYPE_P &&
1068
3/4
✓ Branch 0 taken 2255 times.
✓ Branch 1 taken 48550 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 48550 times.
50805 h->c.mb_x + 1 < h->c.mb_width && h->mb_num_left != 1)
1069 48550 preview_obmc(h);
1070 }
1071 383283 end:
1072
1073
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 441138 times.
441138 if (get_bits_left(&h->gb) < 0)
1074 return AVERROR_INVALIDDATA;
1075
1076 /* per-MB end of slice check */
1077 {
1078 441138 int v = show_bits(&h->gb, 16);
1079
1080
2/2
✓ Branch 1 taken 1616 times.
✓ Branch 2 taken 439522 times.
441138 if (get_bits_left(&h->gb) < 16) {
1081 1616 v >>= 16 - get_bits_left(&h->gb);
1082 }
1083
1084
2/2
✓ Branch 0 taken 3742 times.
✓ Branch 1 taken 437396 times.
441138 if(v==0)
1085 3742 return SLICE_END;
1086 }
1087
1088 437396 return SLICE_OK;
1089 }
1090
1091 /* Most is hardcoded; should extend to handle all H.263 streams. */
1092 461 int ff_h263_decode_picture_header(H263DecContext *const h)
1093 {
1094 int width, height, i, ret;
1095 int h263_plus;
1096
1097 461 align_get_bits(&h->gb);
1098
1099
1/4
✗ Branch 1 not taken.
✓ Branch 2 taken 461 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
461 if (show_bits(&h->gb, 2) == 2 && h->c.avctx->frame_num == 0) {
1100 av_log(h->c.avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");
1101 }
1102
1103 461 uint32_t startcode = get_bits(&h->gb, 22-8);
1104
1105
1/2
✓ Branch 1 taken 461 times.
✗ Branch 2 not taken.
461 for (i = get_bits_left(&h->gb); i>24; i -= 8) {
1106 461 startcode = ((startcode << 8) | get_bits(&h->gb, 8)) & 0x003FFFFF;
1107
1108
1/2
✓ Branch 0 taken 461 times.
✗ Branch 1 not taken.
461 if(startcode == 0x20)
1109 461 break;
1110 }
1111
1112
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if (startcode != 0x20) {
1113 av_log(h->c.avctx, AV_LOG_ERROR, "Bad picture start code\n");
1114 return -1;
1115 }
1116 /* temporal reference */
1117 461 i = get_bits(&h->gb, 8); /* picture timestamp */
1118
1119 461 i -= (i - (h->picture_number & 0xFF) + 128) & ~0xFF;
1120
1121 461 h->picture_number = (h->picture_number&~0xFF) + i;
1122
1123 /* PTYPE starts here */
1124
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 461 times.
461 if (check_marker(h->c.avctx, &h->gb, "in PTYPE") != 1) {
1125 return -1;
1126 }
1127
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 461 times.
461 if (get_bits1(&h->gb) != 0) {
1128 av_log(h->c.avctx, AV_LOG_ERROR, "Bad H.263 id\n");
1129 return -1; /* H.263 id */
1130 }
1131 461 skip_bits1(&h->gb); /* split screen off */
1132 461 skip_bits1(&h->gb); /* camera off */
1133 461 skip_bits1(&h->gb); /* freeze picture release off */
1134
1135 461 int format = get_bits(&h->gb, 3);
1136 /*
1137 0 forbidden
1138 1 sub-QCIF
1139 10 QCIF
1140 7 extended PTYPE (PLUSPTYPE)
1141 */
1142
1143
3/4
✓ Branch 0 taken 307 times.
✓ Branch 1 taken 154 times.
✓ Branch 2 taken 307 times.
✗ Branch 3 not taken.
461 if (format != 7 && format != 6) {
1144 307 h263_plus = 0;
1145 /* H.263v1 */
1146 307 width = ff_h263_format[format][0];
1147 307 height = ff_h263_format[format][1];
1148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 307 times.
307 if (!width)
1149 return -1;
1150
1151 307 h->c.pict_type = AV_PICTURE_TYPE_I + get_bits1(&h->gb);
1152
1153 307 h->h263_long_vectors = get_bits1(&h->gb);
1154
1155
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 307 times.
307 if (get_bits1(&h->gb) != 0) {
1156 av_log(h->c.avctx, AV_LOG_ERROR, "H.263 SAC not supported\n");
1157 return -1; /* SAC: off */
1158 }
1159 307 h->c.obmc = get_bits1(&h->gb); /* Advanced prediction mode */
1160
1161 307 h->pb_frame = get_bits1(&h->gb);
1162 307 h->c.chroma_qscale = h->c.qscale = get_bits(&h->gb, 5);
1163 307 skip_bits1(&h->gb); /* Continuous Presence Multipoint mode: off */
1164
1165 307 h->c.width = width;
1166 307 h->c.height = height;
1167 307 h->c.avctx->sample_aspect_ratio= (AVRational){12,11};
1168 307 h->c.avctx->framerate = (AVRational){ 30000, 1001 };
1169 } else {
1170 int ufep;
1171
1172 /* H.263v2 */
1173 154 h263_plus = 1;
1174 154 ufep = get_bits(&h->gb, 3); /* Update Full Extended PTYPE */
1175
1176 /* ufep other than 0 and 1 are reserved */
1177
1/2
✓ Branch 0 taken 154 times.
✗ Branch 1 not taken.
154 if (ufep == 1) {
1178 /* OPPTYPE */
1179 154 format = get_bits(&h->gb, 3);
1180 ff_dlog(h->c.avctx, "ufep=1, format: %d\n", format);
1181 154 h->custom_pcf = get_bits1(&h->gb);
1182 154 h->umvplus = get_bits1(&h->gb); /* Unrestricted Motion Vector */
1183
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 154 times.
154 if (get_bits1(&h->gb) != 0) {
1184 av_log(h->c.avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
1185 }
1186 154 h->c.obmc = get_bits1(&h->gb); /* Advanced prediction mode */
1187 154 h->c.h263_aic = get_bits1(&h->gb); /* Advanced Intra Coding (AIC) */
1188 154 h->loop_filter = get_bits1(&h->gb);
1189
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 154 times.
154 if (h->c.avctx->lowres)
1190 h->loop_filter = 0;
1191
1192 154 h->h263_slice_structured = get_bits1(&h->gb);
1193
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 154 times.
154 if (get_bits1(&h->gb) != 0) {
1194 av_log(h->c.avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
1195 }
1196
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 154 times.
154 if (get_bits1(&h->gb) != 0) {
1197 av_log(h->c.avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
1198 }
1199 154 h->alt_inter_vlc = get_bits1(&h->gb);
1200 154 h->modified_quant = get_bits1(&h->gb);
1201
1/2
✓ Branch 0 taken 154 times.
✗ Branch 1 not taken.
154 if (h->modified_quant)
1202 154 h->c.chroma_qscale_table= ff_h263_chroma_qscale_table;
1203
1204 154 skip_bits(&h->gb, 1); /* Prevent start code emulation */
1205
1206 154 skip_bits(&h->gb, 3); /* Reserved */
1207 } else if (ufep != 0) {
1208 av_log(h->c.avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);
1209 return -1;
1210 }
1211
1212 /* MPPTYPE */
1213 154 h->c.pict_type = get_bits(&h->gb, 3);
1214
2/6
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 135 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
154 switch (h->c.pict_type) {
1215 19 case 0: h->c.pict_type = AV_PICTURE_TYPE_I; break;
1216 135 case 1: h->c.pict_type = AV_PICTURE_TYPE_P; break;
1217 case 2: h->c.pict_type = AV_PICTURE_TYPE_P; h->pb_frame = 3; break;
1218 case 3: h->c.pict_type = AV_PICTURE_TYPE_B; break;
1219 case 7: h->c.pict_type = AV_PICTURE_TYPE_I; break; //ZYGO
1220 default:
1221 return -1;
1222 }
1223 154 skip_bits(&h->gb, 2);
1224 154 h->c.no_rounding = get_bits1(&h->gb);
1225 154 skip_bits(&h->gb, 4);
1226
1227 /* Get the picture dimensions */
1228
1/2
✓ Branch 0 taken 154 times.
✗ Branch 1 not taken.
154 if (ufep) {
1229
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 154 times.
154 if (format == 6) {
1230 /* Custom Picture Format (CPFMT) */
1231 int aspect_ratio_info = get_bits(&h->gb, 4);
1232 ff_dlog(h->c.avctx, "aspect: %d\n", aspect_ratio_info);
1233 /* aspect ratios:
1234 0 - forbidden
1235 1 - 1:1
1236 2 - 12:11 (CIF 4:3)
1237 3 - 10:11 (525-type 4:3)
1238 4 - 16:11 (CIF 16:9)
1239 5 - 40:33 (525-type 16:9)
1240 6-14 - reserved
1241 */
1242 width = (get_bits(&h->gb, 9) + 1) * 4;
1243 check_marker(h->c.avctx, &h->gb, "in dimensions");
1244 height = get_bits(&h->gb, 9) * 4;
1245 ff_dlog(h->c.avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
1246 if (aspect_ratio_info == FF_ASPECT_EXTENDED) {
1247 /* expected dimensions */
1248 h->c.avctx->sample_aspect_ratio.num = get_bits(&h->gb, 8);
1249 h->c.avctx->sample_aspect_ratio.den = get_bits(&h->gb, 8);
1250 }else{
1251 h->c.avctx->sample_aspect_ratio= ff_h263_pixel_aspect[aspect_ratio_info];
1252 }
1253 } else {
1254 154 width = ff_h263_format[format][0];
1255 154 height = ff_h263_format[format][1];
1256 154 h->c.avctx->sample_aspect_ratio = (AVRational){12,11};
1257 }
1258 154 h->c.avctx->sample_aspect_ratio.den <<= h->ehc_mode;
1259
2/4
✓ Branch 0 taken 154 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 154 times.
154 if ((width == 0) || (height == 0))
1260 return -1;
1261 154 h->c.width = width;
1262 154 h->c.height = height;
1263
1264
1/2
✓ Branch 0 taken 154 times.
✗ Branch 1 not taken.
154 if (h->custom_pcf) {
1265 154 h->c.avctx->framerate.num = 1800000;
1266 154 h->c.avctx->framerate.den = 1000 + get_bits1(&h->gb);
1267 154 h->c.avctx->framerate.den *= get_bits(&h->gb, 7);
1268
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 154 times.
154 if (h->c.avctx->framerate.den == 0) {
1269 av_log(h->c.avctx, AV_LOG_ERROR, "zero framerate\n");
1270 return -1;
1271 }
1272 154 int gcd = av_gcd(h->c.avctx->framerate.den, h->c.avctx->framerate.num);
1273 154 h->c.avctx->framerate.den /= gcd;
1274 154 h->c.avctx->framerate.num /= gcd;
1275 }else{
1276 h->c.avctx->framerate = (AVRational){ 30000, 1001 };
1277 }
1278 }
1279
1280
1/2
✓ Branch 0 taken 154 times.
✗ Branch 1 not taken.
154 if (h->custom_pcf)
1281 154 skip_bits(&h->gb, 2); //extended Temporal reference
1282
1283
1/2
✓ Branch 0 taken 154 times.
✗ Branch 1 not taken.
154 if (ufep) {
1284
1/2
✓ Branch 0 taken 154 times.
✗ Branch 1 not taken.
154 if (h->umvplus) {
1285
1/2
✓ Branch 1 taken 154 times.
✗ Branch 2 not taken.
154 if (get_bits1(&h->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
1286 154 skip_bits1(&h->gb);
1287 }
1288
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 154 times.
154 if (h->h263_slice_structured) {
1289 if (get_bits1(&h->gb) != 0) {
1290 av_log(h->c.avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
1291 }
1292 if (get_bits1(&h->gb) != 0) {
1293 av_log(h->c.avctx, AV_LOG_ERROR, "unordered slices not supported\n");
1294 }
1295 }
1296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 154 times.
154 if (h->c.pict_type == AV_PICTURE_TYPE_B) {
1297 skip_bits(&h->gb, 4); //ELNUM
1298 if (ufep == 1) {
1299 skip_bits(&h->gb, 4); // RLNUM
1300 }
1301 }
1302 }
1303
1304 154 h->c.qscale = get_bits(&h->gb, 5);
1305 }
1306
1307 461 ret = av_image_check_size(h->c.width, h->c.height, 0, h->c.avctx);
1308
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if (ret < 0)
1309 return ret;
1310
1311
1/2
✓ Branch 0 taken 461 times.
✗ Branch 1 not taken.
461 if (!(h->c.avctx->flags2 & AV_CODEC_FLAG2_CHUNKS)) {
1312
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 461 times.
461 if ((h->c.width * h->c.height / 256 / 8) > get_bits_left(&h->gb))
1313 return AVERROR_INVALIDDATA;
1314 }
1315
1316 461 h->c.mb_width = (h->c.width + 15U) / 16;
1317 461 h->c.mb_height = (h->c.height + 15U) / 16;
1318 461 h->c.mb_num = h->c.mb_width * h->c.mb_height;
1319
1320
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
461 h->gob_index = H263_GOB_HEIGHT(h->c.height);
1321
1322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if (h->pb_frame) {
1323 skip_bits(&h->gb, 3); /* Temporal reference for B-pictures */
1324 if (h->custom_pcf)
1325 skip_bits(&h->gb, 2); //extended Temporal reference
1326 skip_bits(&h->gb, 2); /* Quantization information for B-pictures */
1327 }
1328
1329
1/2
✓ Branch 0 taken 461 times.
✗ Branch 1 not taken.
461 if (h->c.pict_type!=AV_PICTURE_TYPE_B) {
1330 461 h->c.time = h->picture_number;
1331 461 h->c.pp_time = h->c.time - h->c.last_non_b_time;
1332 461 h->c.last_non_b_time = h->c.time;
1333 }else{
1334 h->c.time = h->picture_number;
1335 h->c.pb_time = h->c.pp_time - (h->c.last_non_b_time - h->c.time);
1336 if (h->c.pp_time <= h->c.pb_time ||
1337 h->c.pp_time <= h->c.pp_time - h->c.pb_time ||
1338 h->c.pp_time <= 0) {
1339 h->c.pp_time = 2;
1340 h->c.pb_time = 1;
1341 }
1342 ff_mpeg4_init_direct_mv(&h->c);
1343 }
1344
1345 /* PEI */
1346
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 461 times.
461 if (skip_1stop_8data_bits(&h->gb) < 0)
1347 return AVERROR_INVALIDDATA;
1348
1349
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if (h->h263_slice_structured) {
1350 if (check_marker(h->c.avctx, &h->gb, "SEPB1") != 1) {
1351 return -1;
1352 }
1353
1354 ff_h263_decode_mba(h);
1355
1356 if (check_marker(h->c.avctx, &h->gb, "SEPB2") != 1) {
1357 return -1;
1358 }
1359 }
1360
1361
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 461 times.
461 if (h->c.pict_type == AV_PICTURE_TYPE_B)
1362 h->c.low_delay = 0;
1363
1364
2/2
✓ Branch 0 taken 154 times.
✓ Branch 1 taken 307 times.
461 if (h->c.h263_aic) {
1365 154 h->c.y_dc_scale_table =
1366 154 h->c.c_dc_scale_table = ff_aic_dc_scale_table;
1367 }else{
1368 307 h->c.y_dc_scale_table =
1369 307 h->c.c_dc_scale_table = ff_mpeg1_dc_scale_table;
1370 }
1371
1372 461 ff_h263_show_pict_info(h, h263_plus);
1373
1374
3/6
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 405 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 56 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
461 if (h->c.pict_type == AV_PICTURE_TYPE_I && h->c.codec_tag == AV_RL32("ZYGO") && get_bits_left(&h->gb) >= 85 + 13*3*16 + 50){
1375 int i,j;
1376 for(i=0; i<85; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->gb));
1377 av_log(h->c.avctx, AV_LOG_DEBUG, "\n");
1378 for(i=0; i<13; i++){
1379 for(j=0; j<3; j++){
1380 int v= get_bits(&h->gb, 8);
1381 v |= get_sbits(&h->gb, 8) * (1 << 8);
1382 av_log(h->c.avctx, AV_LOG_DEBUG, " %5d", v);
1383 }
1384 av_log(h->c.avctx, AV_LOG_DEBUG, "\n");
1385 }
1386 for(i=0; i<50; i++) av_log(h->c.avctx, AV_LOG_DEBUG, "%d", get_bits1(&h->gb));
1387 }
1388
1389 461 return 0;
1390 }
1391