FFmpeg coverage


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