FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ituh263dec.c
Date: 2022-07-05 19:52:29
Exec Total Coverage
Lines: 563 805 69.9%
Branches: 286 536 53.4%

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