]> git.sesse.net Git - ffmpeg/blob - libavcodec/ituh263dec.c
avcodec/ituh263dec: Correct indention
[ffmpeg] / libavcodec / ituh263dec.c
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 "avcodec.h"
38 #include "mpegvideo.h"
39 #include "h263.h"
40 #include "h263data.h"
41 #include "internal.h"
42 #include "mathops.h"
43 #include "mpegutils.h"
44 #include "unary.h"
45 #include "flv.h"
46 #include "rv10.h"
47 #include "mpeg4video.h"
48 #include "mpegvideodata.h"
49
50 // The defines below define the number of bits that are read at once for
51 // reading vlc values. Changing these may improve speed and data cache needs
52 // be aware though that decreasing them may need the number of stages that is
53 // passed to get_vlc* to be increased.
54 #define MV_VLC_BITS 9
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 void ff_h263_show_pict_info(MpegEncContext *s){
77     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 }
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 static VLC 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 av_cold void ff_h263_decode_init_vlc(void)
109 {
110     static volatile int done = 0;
111
112     if (!done) {
113         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         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         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         INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 33,
123                  &ff_mvtab[0][1], 2, 1,
124                  &ff_mvtab[0][0], 2, 1, 538);
125         ff_rl_init(&ff_h263_rl_inter, ff_h263_static_rl_table_store[0]);
126         ff_rl_init(&ff_rl_intra_aic, ff_h263_static_rl_table_store[1]);
127         INIT_VLC_RL(ff_h263_rl_inter, 554);
128         INIT_VLC_RL(ff_rl_intra_aic, 554);
129         INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15,
130                  &ff_h263_mbtype_b_tab[0][1], 2, 1,
131                  &ff_h263_mbtype_b_tab[0][0], 2, 1, 80);
132         INIT_VLC_STATIC(&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, 8);
135         done = 1;
136     }
137 }
138
139 int ff_h263_decode_mba(MpegEncContext *s)
140 {
141     int i, mb_pos;
142
143     for (i = 0; i < 6; i++)
144         if (s->mb_num - 1 <= ff_mba_max[i])
145             break;
146     mb_pos  = get_bits(&s->gb, ff_mba_length[i]);
147     s->mb_x = mb_pos % s->mb_width;
148     s->mb_y = mb_pos / s->mb_width;
149
150     return mb_pos;
151 }
152
153 /**
154  * Decode the group of blocks header or slice header.
155  * @return <0 if an error occurred
156  */
157 static int h263_decode_gob_header(MpegEncContext *s)
158 {
159     unsigned int val, gob_number;
160     int left;
161
162     /* Check for GOB Start Code */
163     val = show_bits(&s->gb, 16);
164     if(val)
165         return -1;
166
167         /* We have a GBSC probably with GSTUFF */
168     skip_bits(&s->gb, 16); /* Drop the zeros */
169     left= get_bits_left(&s->gb);
170     left = FFMIN(left, 32);
171     //MN: we must check the bits left or we might end in an infinite loop (or segfault)
172     for(;left>13; left--){
173         if(get_bits1(&s->gb)) break; /* Seek the '1' bit */
174     }
175     if(left<=13)
176         return -1;
177
178     if(s->h263_slice_structured){
179         if(check_marker(s->avctx, &s->gb, "before MBA")==0)
180             return -1;
181
182         ff_h263_decode_mba(s);
183
184         if(s->mb_num > 1583)
185             if(check_marker(s->avctx, &s->gb, "after MBA")==0)
186                 return -1;
187
188         s->qscale = get_bits(&s->gb, 5); /* SQUANT */
189         if(check_marker(s->avctx, &s->gb, "after SQUANT")==0)
190             return -1;
191         skip_bits(&s->gb, 2); /* GFID */
192     }else{
193         gob_number = get_bits(&s->gb, 5); /* GN */
194         s->mb_x= 0;
195         s->mb_y= s->gob_index* gob_number;
196         skip_bits(&s->gb, 2); /* GFID */
197         s->qscale = get_bits(&s->gb, 5); /* GQUANT */
198     }
199
200     if(s->mb_y >= s->mb_height)
201         return -1;
202
203     if(s->qscale==0)
204         return -1;
205
206     return 0;
207 }
208
209 /**
210  * Decode the group of blocks / video packet header.
211  * @return bit position of the resync_marker, or <0 if none was found
212  */
213 int ff_h263_resync(MpegEncContext *s){
214     int left, pos, ret;
215
216     if(s->codec_id==AV_CODEC_ID_MPEG4){
217         skip_bits1(&s->gb);
218         align_get_bits(&s->gb);
219     }
220
221     if(show_bits(&s->gb, 16)==0){
222         pos= get_bits_count(&s->gb);
223         if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
224             ret= ff_mpeg4_decode_video_packet_header(s->avctx->priv_data);
225         else
226             ret= h263_decode_gob_header(s);
227         if(ret>=0)
228             return pos;
229     }
230     //OK, it's not where it is supposed to be ...
231     s->gb= s->last_resync_gb;
232     align_get_bits(&s->gb);
233     left= get_bits_left(&s->gb);
234
235     for(;left>16+1+5+5; left-=8){
236         if(show_bits(&s->gb, 16)==0){
237             GetBitContext bak= s->gb;
238
239             pos= get_bits_count(&s->gb);
240             if(CONFIG_MPEG4_DECODER && s->codec_id==AV_CODEC_ID_MPEG4)
241                 ret= ff_mpeg4_decode_video_packet_header(s->avctx->priv_data);
242             else
243                 ret= h263_decode_gob_header(s);
244             if(ret>=0)
245                 return pos;
246
247             s->gb= bak;
248         }
249         skip_bits(&s->gb, 8);
250     }
251
252     return -1;
253 }
254
255 int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code)
256 {
257     int code, val, sign, shift;
258     code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
259
260     if (code == 0)
261         return pred;
262     if (code < 0)
263         return 0xffff;
264
265     sign = get_bits1(&s->gb);
266     shift = f_code - 1;
267     val = code;
268     if (shift) {
269         val = (val - 1) << shift;
270         val |= get_bits(&s->gb, shift);
271         val++;
272     }
273     if (sign)
274         val = -val;
275     val += pred;
276
277     /* modulo decoding */
278     if (!s->h263_long_vectors) {
279         val = sign_extend(val, 5 + f_code);
280     } else {
281         /* horrible H.263 long vector mode */
282         if (pred < -31 && val < -63)
283             val += 64;
284         if (pred > 32 && val > 63)
285             val -= 64;
286
287     }
288     return val;
289 }
290
291
292 /* Decode RVLC of H.263+ UMV */
293 static int h263p_decode_umotion(MpegEncContext * s, int pred)
294 {
295    int code = 0, sign;
296
297    if (get_bits1(&s->gb)) /* Motion difference = 0 */
298       return pred;
299
300    code = 2 + get_bits1(&s->gb);
301
302    while (get_bits1(&s->gb))
303    {
304       code <<= 1;
305       code += get_bits1(&s->gb);
306    }
307    sign = code & 1;
308    code >>= 1;
309
310    code = (sign) ? (pred - code) : (pred + code);
311    ff_tlog(s->avctx,"H.263+ UMV Motion = %d\n", code);
312    return code;
313
314 }
315
316 /**
317  * read the next MVs for OBMC. yes this is an ugly hack, feel free to send a patch :)
318  */
319 static void preview_obmc(MpegEncContext *s){
320     GetBitContext gb= s->gb;
321
322     int cbpc, i, pred_x, pred_y, mx, my;
323     int16_t *mot_val;
324     const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
325     const int stride= s->b8_stride*2;
326
327     for(i=0; i<4; i++)
328         s->block_index[i]+= 2;
329     for(i=4; i<6; i++)
330         s->block_index[i]+= 1;
331     s->mb_x++;
332
333     av_assert2(s->pict_type == AV_PICTURE_TYPE_P);
334
335     do{
336         if (get_bits1(&s->gb)) {
337             /* skip mb */
338             mot_val = s->current_picture.motion_val[0][s->block_index[0]];
339             mot_val[0       ]= mot_val[2       ]=
340             mot_val[0+stride]= mot_val[2+stride]= 0;
341             mot_val[1       ]= mot_val[3       ]=
342             mot_val[1+stride]= mot_val[3+stride]= 0;
343
344             s->current_picture.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
345             goto end;
346         }
347         cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
348     }while(cbpc == 20);
349
350     if(cbpc & 4){
351         s->current_picture.mb_type[xy] = MB_TYPE_INTRA;
352     }else{
353         get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
354         if (cbpc & 8) {
355             if(s->modified_quant){
356                 if(get_bits1(&s->gb)) skip_bits(&s->gb, 1);
357                 else                  skip_bits(&s->gb, 5);
358             }else
359                 skip_bits(&s->gb, 2);
360         }
361
362         if ((cbpc & 16) == 0) {
363                 s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
364                 /* 16x16 motion prediction */
365                 mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
366                 if (s->umvplus)
367                     mx = h263p_decode_umotion(s, pred_x);
368                 else
369                     mx = ff_h263_decode_motion(s, pred_x, 1);
370
371                 if (s->umvplus)
372                     my = h263p_decode_umotion(s, pred_y);
373                 else
374                     my = ff_h263_decode_motion(s, pred_y, 1);
375
376                 mot_val[0       ]= mot_val[2       ]=
377                 mot_val[0+stride]= mot_val[2+stride]= mx;
378                 mot_val[1       ]= mot_val[3       ]=
379                 mot_val[1+stride]= mot_val[3+stride]= my;
380         } else {
381             s->current_picture.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;
382             for(i=0;i<4;i++) {
383                 mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
384                 if (s->umvplus)
385                     mx = h263p_decode_umotion(s, pred_x);
386                 else
387                     mx = ff_h263_decode_motion(s, pred_x, 1);
388
389                 if (s->umvplus)
390                     my = h263p_decode_umotion(s, pred_y);
391                 else
392                     my = ff_h263_decode_motion(s, pred_y, 1);
393                 if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
394                     skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
395                 mot_val[0] = mx;
396                 mot_val[1] = my;
397             }
398         }
399     }
400 end:
401
402     for(i=0; i<4; i++)
403         s->block_index[i]-= 2;
404     for(i=4; i<6; i++)
405         s->block_index[i]-= 1;
406     s->mb_x--;
407
408     s->gb= gb;
409 }
410
411 static void h263_decode_dquant(MpegEncContext *s){
412     static const int8_t quant_tab[4] = { -1, -2, 1, 2 };
413
414     if(s->modified_quant){
415         if(get_bits1(&s->gb))
416             s->qscale= ff_modified_quant_tab[get_bits1(&s->gb)][ s->qscale ];
417         else
418             s->qscale= get_bits(&s->gb, 5);
419     }else
420         s->qscale += quant_tab[get_bits(&s->gb, 2)];
421     ff_set_qscale(s, s->qscale);
422 }
423
424 static int h263_decode_block(MpegEncContext * s, int16_t * block,
425                              int n, int coded)
426 {
427     int level, i, j, run;
428     RLTable *rl = &ff_h263_rl_inter;
429     const uint8_t *scan_table;
430     GetBitContext gb= s->gb;
431
432     scan_table = s->intra_scantable.permutated;
433     if (s->h263_aic && s->mb_intra) {
434         rl = &ff_rl_intra_aic;
435         i = 0;
436         if (s->ac_pred) {
437             if (s->h263_aic_dir)
438                 scan_table = s->intra_v_scantable.permutated; /* left */
439             else
440                 scan_table = s->intra_h_scantable.permutated; /* top */
441         }
442     } else if (s->mb_intra) {
443         /* DC coef */
444         if (CONFIG_RV10_DECODER && s->codec_id == AV_CODEC_ID_RV10) {
445           if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) {
446             int component, diff;
447             component = (n <= 3 ? 0 : n - 4 + 1);
448             level = s->last_dc[component];
449             if (s->rv10_first_dc_coded[component]) {
450                 diff = ff_rv_decode_dc(s, n);
451                 if (diff == 0xffff)
452                     return -1;
453                 level += diff;
454                 level = level & 0xff; /* handle wrap round */
455                 s->last_dc[component] = level;
456             } else {
457                 s->rv10_first_dc_coded[component] = 1;
458             }
459           } else {
460                 level = get_bits(&s->gb, 8);
461                 if (level == 255)
462                     level = 128;
463           }
464         }else{
465             level = get_bits(&s->gb, 8);
466             if((level&0x7F) == 0){
467                 av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y);
468                 if (s->avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))
469                     return -1;
470             }
471             if (level == 255)
472                 level = 128;
473         }
474         block[0] = level;
475         i = 1;
476     } else {
477         i = 0;
478     }
479     if (!coded) {
480         if (s->mb_intra && s->h263_aic)
481             goto not_coded;
482         s->block_last_index[n] = i - 1;
483         return 0;
484     }
485 retry:
486     {
487     OPEN_READER(re, &s->gb);
488     i--; // offset by -1 to allow direct indexing of scan_table
489     for(;;) {
490         UPDATE_CACHE(re, &s->gb);
491         GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0);
492         if (run == 66) {
493             if (level){
494                 CLOSE_READER(re, &s->gb);
495                 av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y);
496                 return -1;
497             }
498             /* escape */
499             if (CONFIG_FLV_DECODER && s->h263_flv > 1) {
500                 int is11 = SHOW_UBITS(re, &s->gb, 1);
501                 SKIP_CACHE(re, &s->gb, 1);
502                 run = SHOW_UBITS(re, &s->gb, 7) + 1;
503                 if (is11) {
504                     SKIP_COUNTER(re, &s->gb, 1 + 7);
505                     UPDATE_CACHE(re, &s->gb);
506                     level = SHOW_SBITS(re, &s->gb, 11);
507                     SKIP_COUNTER(re, &s->gb, 11);
508                 } else {
509                     SKIP_CACHE(re, &s->gb, 7);
510                     level = SHOW_SBITS(re, &s->gb, 7);
511                     SKIP_COUNTER(re, &s->gb, 1 + 7 + 7);
512                 }
513             } else {
514                 run = SHOW_UBITS(re, &s->gb, 7) + 1;
515                 SKIP_CACHE(re, &s->gb, 7);
516                 level = (int8_t)SHOW_UBITS(re, &s->gb, 8);
517                 SKIP_COUNTER(re, &s->gb, 7 + 8);
518                 if(level == -128){
519                     UPDATE_CACHE(re, &s->gb);
520                     if (s->codec_id == AV_CODEC_ID_RV10) {
521                         /* XXX: should patch encoder too */
522                         level = SHOW_SBITS(re, &s->gb, 12);
523                         SKIP_COUNTER(re, &s->gb, 12);
524                     }else{
525                         level = SHOW_UBITS(re, &s->gb, 5);
526                         SKIP_CACHE(re, &s->gb, 5);
527                         level |= SHOW_SBITS(re, &s->gb, 6)<<5;
528                         SKIP_COUNTER(re, &s->gb, 5 + 6);
529                     }
530                 }
531             }
532         } else {
533             if (SHOW_UBITS(re, &s->gb, 1))
534                 level = -level;
535             SKIP_COUNTER(re, &s->gb, 1);
536         }
537         i += run;
538         if (i >= 64){
539             CLOSE_READER(re, &s->gb);
540             // redo update without last flag, revert -1 offset
541             i = i - run + ((run-1)&63) + 1;
542             if (i < 64) {
543                 // only last marker, no overrun
544                 block[scan_table[i]] = level;
545                 break;
546             }
547             if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){
548                 //Looks like a hack but no, it's the way it is supposed to work ...
549                 rl = &ff_rl_intra_aic;
550                 i = 0;
551                 s->gb= gb;
552                 s->bdsp.clear_block(block);
553                 goto retry;
554             }
555             av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra);
556             return -1;
557         }
558         j = scan_table[i];
559         block[j] = level;
560     }
561     }
562 not_coded:
563     if (s->mb_intra && s->h263_aic) {
564         ff_h263_pred_acdc(s, block, n);
565         i = 63;
566     }
567     s->block_last_index[n] = i;
568     return 0;
569 }
570
571 static int h263_skip_b_part(MpegEncContext *s, int cbp)
572 {
573     LOCAL_ALIGNED_16(int16_t, dblock, [64]);
574     int i, mbi;
575     int bli[6];
576
577     /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly
578      * but real value should be restored in order to be used later (in OBMC condition)
579      */
580     mbi = s->mb_intra;
581     memcpy(bli, s->block_last_index, sizeof(bli));
582     s->mb_intra = 0;
583     for (i = 0; i < 6; i++) {
584         if (h263_decode_block(s, dblock, i, cbp&32) < 0)
585             return -1;
586         cbp+=cbp;
587     }
588     s->mb_intra = mbi;
589     memcpy(s->block_last_index, bli, sizeof(bli));
590     return 0;
591 }
592
593 static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb)
594 {
595     int c, mv = 1;
596
597     if (pb_frame < 3) { // h.263 Annex G and i263 PB-frame
598         c = get_bits1(gb);
599         if (pb_frame == 2 && c)
600             mv = !get_bits1(gb);
601     } else { // h.263 Annex M improved PB-frame
602         mv = get_unary(gb, 0, 4) + 1;
603         c = mv & 1;
604         mv = !!(mv & 2);
605     }
606     if(c)
607         *cbpb = get_bits(gb, 6);
608     return mv;
609 }
610
611 int ff_h263_decode_mb(MpegEncContext *s,
612                       int16_t block[6][64])
613 {
614     int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant;
615     int16_t *mot_val;
616     const int xy= s->mb_x + s->mb_y * s->mb_stride;
617     int cbpb = 0, pb_mv_count = 0;
618
619     av_assert2(!s->h263_pred);
620
621     if (s->pict_type == AV_PICTURE_TYPE_P) {
622         do{
623             if (get_bits1(&s->gb)) {
624                 /* skip mb */
625                 s->mb_intra = 0;
626                 for(i=0;i<6;i++)
627                     s->block_last_index[i] = -1;
628                 s->mv_dir = MV_DIR_FORWARD;
629                 s->mv_type = MV_TYPE_16X16;
630                 s->current_picture.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
631                 s->mv[0][0][0] = 0;
632                 s->mv[0][0][1] = 0;
633                 s->mb_skipped = !(s->obmc | s->loop_filter);
634                 goto end;
635             }
636             cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
637             if (cbpc < 0){
638                 av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
639                 return -1;
640             }
641         }while(cbpc == 20);
642
643         s->bdsp.clear_blocks(s->block[0]);
644
645         dquant = cbpc & 8;
646         s->mb_intra = ((cbpc & 4) != 0);
647         if (s->mb_intra) goto intra;
648
649         if(s->pb_frame && get_bits1(&s->gb))
650             pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
651         cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
652
653         if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
654             cbpy ^= 0xF;
655
656         cbp = (cbpc & 3) | (cbpy << 2);
657         if (dquant) {
658             h263_decode_dquant(s);
659         }
660
661         s->mv_dir = MV_DIR_FORWARD;
662         if ((cbpc & 16) == 0) {
663             s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
664             /* 16x16 motion prediction */
665             s->mv_type = MV_TYPE_16X16;
666             ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
667             if (s->umvplus)
668                mx = h263p_decode_umotion(s, pred_x);
669             else
670                mx = ff_h263_decode_motion(s, pred_x, 1);
671
672             if (mx >= 0xffff)
673                 return -1;
674
675             if (s->umvplus)
676                my = h263p_decode_umotion(s, pred_y);
677             else
678                my = ff_h263_decode_motion(s, pred_y, 1);
679
680             if (my >= 0xffff)
681                 return -1;
682             s->mv[0][0][0] = mx;
683             s->mv[0][0][1] = my;
684
685             if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
686                skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
687         } else {
688             s->current_picture.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0;
689             s->mv_type = MV_TYPE_8X8;
690             for(i=0;i<4;i++) {
691                 mot_val = ff_h263_pred_motion(s, i, 0, &pred_x, &pred_y);
692                 if (s->umvplus)
693                     mx = h263p_decode_umotion(s, pred_x);
694                 else
695                     mx = ff_h263_decode_motion(s, pred_x, 1);
696                 if (mx >= 0xffff)
697                     return -1;
698
699                 if (s->umvplus)
700                     my = h263p_decode_umotion(s, pred_y);
701                 else
702                     my = ff_h263_decode_motion(s, pred_y, 1);
703                 if (my >= 0xffff)
704                     return -1;
705                 s->mv[0][i][0] = mx;
706                 s->mv[0][i][1] = my;
707                 if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
708                   skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
709                 mot_val[0] = mx;
710                 mot_val[1] = my;
711             }
712         }
713     } else if(s->pict_type==AV_PICTURE_TYPE_B) {
714         int mb_type;
715         const int stride= s->b8_stride;
716         int16_t *mot_val0 = s->current_picture.motion_val[0][2 * (s->mb_x + s->mb_y * stride)];
717         int16_t *mot_val1 = s->current_picture.motion_val[1][2 * (s->mb_x + s->mb_y * stride)];
718 //        const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride;
719
720         //FIXME ugly
721         mot_val0[0       ]= mot_val0[2       ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]=
722         mot_val0[1       ]= mot_val0[3       ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]=
723         mot_val1[0       ]= mot_val1[2       ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]=
724         mot_val1[1       ]= mot_val1[3       ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0;
725
726         do{
727             mb_type= get_vlc2(&s->gb, h263_mbtype_b_vlc.table, H263_MBTYPE_B_VLC_BITS, 2);
728             if (mb_type < 0){
729                 av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y);
730                 return -1;
731             }
732
733             mb_type= h263_mb_type_b_map[ mb_type ];
734         }while(!mb_type);
735
736         s->mb_intra = IS_INTRA(mb_type);
737         if(HAS_CBP(mb_type)){
738             s->bdsp.clear_blocks(s->block[0]);
739             cbpc = get_vlc2(&s->gb, cbpc_b_vlc.table, CBPC_B_VLC_BITS, 1);
740             if(s->mb_intra){
741                 dquant = IS_QUANT(mb_type);
742                 goto intra;
743             }
744
745             cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
746
747             if (cbpy < 0){
748                 av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
749                 return -1;
750             }
751
752             if(s->alt_inter_vlc==0 || (cbpc & 3)!=3)
753                 cbpy ^= 0xF;
754
755             cbp = (cbpc & 3) | (cbpy << 2);
756         }else
757             cbp=0;
758
759         av_assert2(!s->mb_intra);
760
761         if(IS_QUANT(mb_type)){
762             h263_decode_dquant(s);
763         }
764
765         if(IS_DIRECT(mb_type)){
766             s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;
767             mb_type |= ff_mpeg4_set_direct_mv(s, 0, 0);
768         }else{
769             s->mv_dir = 0;
770             s->mv_type= MV_TYPE_16X16;
771 //FIXME UMV
772
773             if(USES_LIST(mb_type, 0)){
774                 int16_t *mot_val= ff_h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
775                 s->mv_dir = MV_DIR_FORWARD;
776
777                 if (s->umvplus)
778                     mx = h263p_decode_umotion(s, pred_x);
779                 else
780                     mx = ff_h263_decode_motion(s, pred_x, 1);
781                 if (mx >= 0xffff)
782                     return -1;
783
784                 if (s->umvplus)
785                     my = h263p_decode_umotion(s, pred_y);
786                 else
787                     my = ff_h263_decode_motion(s, pred_y, 1);
788                 if (my >= 0xffff)
789                     return -1;
790
791                 if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
792                     skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
793
794                 s->mv[0][0][0] = mx;
795                 s->mv[0][0][1] = my;
796                 mot_val[0       ]= mot_val[2       ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
797                 mot_val[1       ]= mot_val[3       ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
798             }
799
800             if(USES_LIST(mb_type, 1)){
801                 int16_t *mot_val= ff_h263_pred_motion(s, 0, 1, &pred_x, &pred_y);
802                 s->mv_dir |= MV_DIR_BACKWARD;
803
804                 if (s->umvplus)
805                     mx = h263p_decode_umotion(s, pred_x);
806                 else
807                     mx = ff_h263_decode_motion(s, pred_x, 1);
808                 if (mx >= 0xffff)
809                     return -1;
810
811                 if (s->umvplus)
812                     my = h263p_decode_umotion(s, pred_y);
813                 else
814                     my = ff_h263_decode_motion(s, pred_y, 1);
815                 if (my >= 0xffff)
816                     return -1;
817
818                 if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1)
819                     skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */
820
821                 s->mv[1][0][0] = mx;
822                 s->mv[1][0][1] = my;
823                 mot_val[0       ]= mot_val[2       ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx;
824                 mot_val[1       ]= mot_val[3       ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my;
825             }
826         }
827
828         s->current_picture.mb_type[xy] = mb_type;
829     } else { /* I-Frame */
830         do{
831             cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2);
832             if (cbpc < 0){
833                 av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y);
834                 return -1;
835             }
836         }while(cbpc == 8);
837
838         s->bdsp.clear_blocks(s->block[0]);
839
840         dquant = cbpc & 4;
841         s->mb_intra = 1;
842 intra:
843         s->current_picture.mb_type[xy] = MB_TYPE_INTRA;
844         if (s->h263_aic) {
845             s->ac_pred = get_bits1(&s->gb);
846             if(s->ac_pred){
847                 s->current_picture.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED;
848
849                 s->h263_aic_dir = get_bits1(&s->gb);
850             }
851         }else
852             s->ac_pred = 0;
853
854         if(s->pb_frame && get_bits1(&s->gb))
855             pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb);
856         cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
857         if(cbpy<0){
858             av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y);
859             return -1;
860         }
861         cbp = (cbpc & 3) | (cbpy << 2);
862         if (dquant) {
863             h263_decode_dquant(s);
864         }
865
866         pb_mv_count += !!s->pb_frame;
867     }
868
869     while(pb_mv_count--){
870         ff_h263_decode_motion(s, 0, 1);
871         ff_h263_decode_motion(s, 0, 1);
872     }
873
874     /* decode each block */
875     for (i = 0; i < 6; i++) {
876         if (h263_decode_block(s, block[i], i, cbp&32) < 0)
877             return -1;
878         cbp+=cbp;
879     }
880
881     if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0)
882         return -1;
883     if(s->obmc && !s->mb_intra){
884         if(s->pict_type == AV_PICTURE_TYPE_P && s->mb_x+1<s->mb_width && s->mb_num_left != 1)
885             preview_obmc(s);
886     }
887 end:
888
889         /* per-MB end of slice check */
890     {
891         int v= show_bits(&s->gb, 16);
892
893         if (get_bits_left(&s->gb) < 16) {
894             v >>= 16 - get_bits_left(&s->gb);
895         }
896
897         if(v==0)
898             return SLICE_END;
899     }
900
901     return SLICE_OK;
902 }
903
904 /* Most is hardcoded; should extend to handle all H.263 streams. */
905 int ff_h263_decode_picture_header(MpegEncContext *s)
906 {
907     int format, width, height, i, ret;
908     uint32_t startcode;
909
910     align_get_bits(&s->gb);
911
912     if (show_bits(&s->gb, 2) == 2 && s->avctx->frame_number == 0) {
913          av_log(s->avctx, AV_LOG_WARNING, "Header looks like RTP instead of H.263\n");
914     }
915
916     startcode= get_bits(&s->gb, 22-8);
917
918     for(i= get_bits_left(&s->gb); i>24; i-=8) {
919         startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF;
920
921         if(startcode == 0x20)
922             break;
923     }
924
925     if (startcode != 0x20) {
926         av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
927         return -1;
928     }
929     /* temporal reference */
930     i = get_bits(&s->gb, 8); /* picture timestamp */
931     if( (s->picture_number&~0xFF)+i < s->picture_number)
932         i+= 256;
933     s->picture_number= (s->picture_number&~0xFF) + i;
934
935     /* PTYPE starts here */
936     if (check_marker(s->avctx, &s->gb, "in PTYPE") != 1) {
937         return -1;
938     }
939     if (get_bits1(&s->gb) != 0) {
940         av_log(s->avctx, AV_LOG_ERROR, "Bad H.263 id\n");
941         return -1;      /* H.263 id */
942     }
943     skip_bits1(&s->gb);         /* split screen off */
944     skip_bits1(&s->gb);         /* camera  off */
945     skip_bits1(&s->gb);         /* freeze picture release off */
946
947     format = get_bits(&s->gb, 3);
948     /*
949         0    forbidden
950         1    sub-QCIF
951         10   QCIF
952         7       extended PTYPE (PLUSPTYPE)
953     */
954
955     if (format != 7 && format != 6) {
956         s->h263_plus = 0;
957         /* H.263v1 */
958         width = ff_h263_format[format][0];
959         height = ff_h263_format[format][1];
960         if (!width)
961             return -1;
962
963         s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb);
964
965         s->h263_long_vectors = get_bits1(&s->gb);
966
967         if (get_bits1(&s->gb) != 0) {
968             av_log(s->avctx, AV_LOG_ERROR, "H.263 SAC not supported\n");
969             return -1; /* SAC: off */
970         }
971         s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
972         s->unrestricted_mv = s->h263_long_vectors || s->obmc;
973
974         s->pb_frame = get_bits1(&s->gb);
975         s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
976         skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */
977
978         s->width = width;
979         s->height = height;
980         s->avctx->sample_aspect_ratio= (AVRational){12,11};
981         s->avctx->framerate = (AVRational){ 30000, 1001 };
982     } else {
983         int ufep;
984
985         /* H.263v2 */
986         s->h263_plus = 1;
987         ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */
988
989         /* ufep other than 0 and 1 are reserved */
990         if (ufep == 1) {
991             /* OPPTYPE */
992             format = get_bits(&s->gb, 3);
993             ff_dlog(s->avctx, "ufep=1, format: %d\n", format);
994             s->custom_pcf= get_bits1(&s->gb);
995             s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */
996             if (get_bits1(&s->gb) != 0) {
997                 av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n");
998             }
999             s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */
1000             s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */
1001             s->loop_filter= get_bits1(&s->gb);
1002             s->unrestricted_mv = s->umvplus || s->obmc || s->loop_filter;
1003             if(s->avctx->lowres)
1004                 s->loop_filter = 0;
1005
1006             s->h263_slice_structured= get_bits1(&s->gb);
1007             if (get_bits1(&s->gb) != 0) {
1008                 av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n");
1009             }
1010             if (get_bits1(&s->gb) != 0) {
1011                 av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n");
1012             }
1013             s->alt_inter_vlc= get_bits1(&s->gb);
1014             s->modified_quant= get_bits1(&s->gb);
1015             if(s->modified_quant)
1016                 s->chroma_qscale_table= ff_h263_chroma_qscale_table;
1017
1018             skip_bits(&s->gb, 1); /* Prevent start code emulation */
1019
1020             skip_bits(&s->gb, 3); /* Reserved */
1021         } else if (ufep != 0) {
1022             av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep);
1023             return -1;
1024         }
1025
1026         /* MPPTYPE */
1027         s->pict_type = get_bits(&s->gb, 3);
1028         switch(s->pict_type){
1029         case 0: s->pict_type= AV_PICTURE_TYPE_I;break;
1030         case 1: s->pict_type= AV_PICTURE_TYPE_P;break;
1031         case 2: s->pict_type= AV_PICTURE_TYPE_P;s->pb_frame = 3;break;
1032         case 3: s->pict_type= AV_PICTURE_TYPE_B;break;
1033         case 7: s->pict_type= AV_PICTURE_TYPE_I;break; //ZYGO
1034         default:
1035             return -1;
1036         }
1037         skip_bits(&s->gb, 2);
1038         s->no_rounding = get_bits1(&s->gb);
1039         skip_bits(&s->gb, 4);
1040
1041         /* Get the picture dimensions */
1042         if (ufep) {
1043             if (format == 6) {
1044                 /* Custom Picture Format (CPFMT) */
1045                 s->aspect_ratio_info = get_bits(&s->gb, 4);
1046                 ff_dlog(s->avctx, "aspect: %d\n", s->aspect_ratio_info);
1047                 /* aspect ratios:
1048                 0 - forbidden
1049                 1 - 1:1
1050                 2 - 12:11 (CIF 4:3)
1051                 3 - 10:11 (525-type 4:3)
1052                 4 - 16:11 (CIF 16:9)
1053                 5 - 40:33 (525-type 16:9)
1054                 6-14 - reserved
1055                 */
1056                 width = (get_bits(&s->gb, 9) + 1) * 4;
1057                 check_marker(s->avctx, &s->gb, "in dimensions");
1058                 height = get_bits(&s->gb, 9) * 4;
1059                 ff_dlog(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height);
1060                 if (s->aspect_ratio_info == FF_ASPECT_EXTENDED) {
1061                     /* expected dimensions */
1062                     s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8);
1063                     s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8);
1064                 }else{
1065                     s->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[s->aspect_ratio_info];
1066                 }
1067             } else {
1068                 width = ff_h263_format[format][0];
1069                 height = ff_h263_format[format][1];
1070                 s->avctx->sample_aspect_ratio= (AVRational){12,11};
1071             }
1072             s->avctx->sample_aspect_ratio.den <<= s->ehc_mode;
1073             if ((width == 0) || (height == 0))
1074                 return -1;
1075             s->width = width;
1076             s->height = height;
1077
1078             if(s->custom_pcf){
1079                 int gcd;
1080                 s->avctx->framerate.num  = 1800000;
1081                 s->avctx->framerate.den  = 1000 + get_bits1(&s->gb);
1082                 s->avctx->framerate.den *= get_bits(&s->gb, 7);
1083                 if(s->avctx->framerate.den == 0){
1084                     av_log(s, AV_LOG_ERROR, "zero framerate\n");
1085                     return -1;
1086                 }
1087                 gcd= av_gcd(s->avctx->framerate.den, s->avctx->framerate.num);
1088                 s->avctx->framerate.den /= gcd;
1089                 s->avctx->framerate.num /= gcd;
1090             }else{
1091                 s->avctx->framerate = (AVRational){ 30000, 1001 };
1092             }
1093         }
1094
1095         if(s->custom_pcf){
1096             skip_bits(&s->gb, 2); //extended Temporal reference
1097         }
1098
1099         if (ufep) {
1100             if (s->umvplus) {
1101                 if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */
1102                     skip_bits1(&s->gb);
1103             }
1104             if(s->h263_slice_structured){
1105                 if (get_bits1(&s->gb) != 0) {
1106                     av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n");
1107                 }
1108                 if (get_bits1(&s->gb) != 0) {
1109                     av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n");
1110                 }
1111             }
1112             if (s->pict_type == AV_PICTURE_TYPE_B) {
1113                 skip_bits(&s->gb, 4); //ELNUM
1114                 if (ufep == 1) {
1115                     skip_bits(&s->gb, 4); // RLNUM
1116                 }
1117             }
1118         }
1119
1120         s->qscale = get_bits(&s->gb, 5);
1121     }
1122
1123     if ((ret = av_image_check_size(s->width, s->height, 0, s)) < 0)
1124         return ret;
1125
1126     s->mb_width = (s->width  + 15) / 16;
1127     s->mb_height = (s->height  + 15) / 16;
1128     s->mb_num = s->mb_width * s->mb_height;
1129
1130     if (s->pb_frame) {
1131         skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */
1132         if (s->custom_pcf)
1133             skip_bits(&s->gb, 2); //extended Temporal reference
1134         skip_bits(&s->gb, 2); /* Quantization information for B-pictures */
1135     }
1136
1137     if (s->pict_type!=AV_PICTURE_TYPE_B) {
1138         s->time            = s->picture_number;
1139         s->pp_time         = s->time - s->last_non_b_time;
1140         s->last_non_b_time = s->time;
1141     }else{
1142         s->time    = s->picture_number;
1143         s->pb_time = s->pp_time - (s->last_non_b_time - s->time);
1144         if (s->pp_time <=s->pb_time ||
1145             s->pp_time <= s->pp_time - s->pb_time ||
1146             s->pp_time <= 0){
1147             s->pp_time = 2;
1148             s->pb_time = 1;
1149         }
1150         ff_mpeg4_init_direct_mv(s);
1151     }
1152
1153     /* PEI */
1154     if (skip_1stop_8data_bits(&s->gb) < 0)
1155         return AVERROR_INVALIDDATA;
1156
1157     if(s->h263_slice_structured){
1158         if (check_marker(s->avctx, &s->gb, "SEPB1") != 1) {
1159             return -1;
1160         }
1161
1162         ff_h263_decode_mba(s);
1163
1164         if (check_marker(s->avctx, &s->gb, "SEPB2") != 1) {
1165             return -1;
1166         }
1167     }
1168     s->f_code = 1;
1169
1170     if (s->pict_type == AV_PICTURE_TYPE_B)
1171         s->low_delay = 0;
1172
1173     if(s->h263_aic){
1174          s->y_dc_scale_table=
1175          s->c_dc_scale_table= ff_aic_dc_scale_table;
1176     }else{
1177         s->y_dc_scale_table=
1178         s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
1179     }
1180
1181         ff_h263_show_pict_info(s);
1182     if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO") && get_bits_left(&s->gb) >= 85 + 13*3*16 + 50){
1183         int i,j;
1184         for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
1185         av_log(s->avctx, AV_LOG_DEBUG, "\n");
1186         for(i=0; i<13; i++){
1187             for(j=0; j<3; j++){
1188                 int v= get_bits(&s->gb, 8);
1189                 v |= get_sbits(&s->gb, 8)<<8;
1190                 av_log(s->avctx, AV_LOG_DEBUG, " %5d", v);
1191             }
1192             av_log(s->avctx, AV_LOG_DEBUG, "\n");
1193         }
1194         for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
1195     }
1196
1197     return 0;
1198 }