FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ituh263dec.c
Date: 2022-01-28 07:56:06
Exec Total Coverage
Lines: 558 804 69.4%
Branches: 283 538 52.6%

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