FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/ituh263dec.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 562 805 69.8%
Functions: 15 18 83.3%
Branches: 286 536 53.4%

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