[svn] / branches / dev-api-3 / xvidcore / src / bitstream / mbcoding.c Repository:
ViewVC logotype

Diff of /branches/dev-api-3/xvidcore/src/bitstream/mbcoding.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/xvidcore/src/bitstream/mbcoding.c revision 153, Thu May 2 00:36:50 2002 UTC branches/dev-api-3/xvidcore/src/bitstream/mbcoding.c revision 790, Thu Jan 16 21:16:04 2003 UTC
# Line 41  Line 41 
41    *                                                                                                                                                        *    *                                                                                                                                                        *
42    *  Revision history:                                                         *    *  Revision history:                                                         *
43    *                                                                            *    *                                                                            *
44      *  28.10.2002 GMC support - gruel                                                                                        *
45      *  28.06.2002 added check_resync_marker()                                    *
46    *  14.04.2002 bframe encoding                                                                                            *    *  14.04.2002 bframe encoding                                                                                            *
47    *  08.03.2002 initial version; isibaar                                                           *    *  08.03.2002 initial version; isibaar                                                           *
48    *                                                                                                                                                        *    *                                                                                                                                                        *
49    ******************************************************************************/    ******************************************************************************/
50    
51    
52    #include <stdio.h>
53  #include <stdlib.h>  #include <stdlib.h>
54  #include "../portab.h"  #include "../portab.h"
55    #include "../global.h"
56  #include "bitstream.h"  #include "bitstream.h"
57  #include "zigzag.h"  #include "zigzag.h"
58  #include "vlc_codes.h"  #include "vlc_codes.h"
# Line 57  Line 60 
60    
61  #include "../utils/mbfunctions.h"  #include "../utils/mbfunctions.h"
62    
63  #define ABS(X) (((X)>0)?(X):-(X))  /* #define BIGLUT */
 #define CLIP(X,A) (X > A) ? (A) : (X)  
64    
65  VLC intra_table[524032];  #ifdef BIGLUT
66  VLC inter_table[524032];  #define LEVELOFFSET 2048
67    #else
68    #define LEVELOFFSET 32
69    #endif
70    
71  VLC DCT3Dintra[4096];  static REVERSE_EVENT DCT3D[2][4096];
 VLC DCT3Dinter[4096];  
72    
73  void init_vlc_tables(void)  #ifdef BIGLUT
74  {  static VLC coeff_VLC[2][2][4096][64];
75    static VLC *intra_table, *inter_table;
76    #else
77    static VLC coeff_VLC[2][2][64][64];
78    #endif
79    
80          int32_t k, l, i, intra, last;  /* not really MB related, but VLCs are only available here */
81          VLC *vlc[2];  void bs_put_spritetrajectory(Bitstream * bs, const int val)
82          VLC **coeff_ptr;  {
83          VLC *vlc1, *vlc2;          const int code = sprite_trajectory_code[val+16384].code;
84            const int len = sprite_trajectory_code[val+16384].len;
85            const int code2 = sprite_trajectory_len[len].code;
86            const int len2 = sprite_trajectory_len[len].len;
87    
88          vlc1 = DCT3Dintra;  //      printf("GMC=%d Code/Len  = %d / %d ",val, code,len);
89          vlc2 = DCT3Dinter;  //      printf("Code2 / Len2 = %d / %d \n",code2,len2);
90    
91          vlc[0] = intra_table;          BitstreamPutBits(bs, code2, len2);
92          vlc[1] = inter_table;          if (len) BitstreamPutBits(bs, code, len);
93    }
94    
95          // generate encoding vlc lookup tables  int bs_get_spritetrajectory(Bitstream * bs)
96          // the lookup table idea is taken from the excellent fame project by Vivien Chapellier  {
97          for(i = 0; i < 4; i++) {          int i;
98                  intra = i % 2;          for (i = 0; i < 12; i++)
99                  last = i / 2;          {
100                    if (BitstreamShowBits(bs, sprite_trajectory_len[i].len) == sprite_trajectory_len[i].code)
101                    {
102                            BitstreamSkip(bs, sprite_trajectory_len[i].len);
103                            return i;
104                    }
105            }
106            return -1;
107    }
108    
109                  coeff_ptr = coeff_vlc[last + 2 * intra];  void
110    init_vlc_tables(void)
111    {
112            uint32_t i, j, k, intra, last, run,  run_esc, level, level_esc, escape, escape_len, offset, limit;
113            int32_t l;
114    
115                  for(k = -2047; k < 2048; k++) { // level  #ifdef BIGLUT
116                          int8_t *max_level_ptr = max_level[last + 2 * intra];          intra_table = coeff_VLC[1];
117                          int8_t *max_run_ptr = max_run[last + 2 * intra];          inter_table = coeff_VLC[0];
118    #endif
119    
                         for(l = 0; l < 64; l++) { // run  
                                 int32_t level = k;  
                                 uint32_t run = l;  
120    
121                                  if((abs(level) <= max_level_ptr[run]) &&          for (intra = 0; intra < 2; intra++)
122                                     (run <= (uint32_t)max_run_ptr[abs(level)])) { // level < max_level and run < max_run                  for (i = 0; i < 4096; i++)
123                            DCT3D[intra][i].event.level = 0;
124    
125                                                  vlc[intra]->code = 0;          for (intra = 0; intra < 2; intra++)
126                                                  vlc[intra]->len = 0;                  for (last = 0; last < 2; last++)
127                                                  goto loop_end;                  {
128                            for (run = 0; run < 63 + last; run++)
129                                    for (level = 0; level < 32 << intra; level++)
130                                    {
131    #ifdef BIGLUT
132                                            offset = LEVELOFFSET;
133    #else
134                                            offset = !intra * LEVELOFFSET;
135    #endif
136                                            coeff_VLC[intra][last][level + offset][run].len = 128;
137                                  }                                  }
                                 else {  
                                         if(level > 0)                                        // correct level  
                                                 level -= max_level_ptr[run];  
                                         else  
                                                 level += max_level_ptr[run];  
   
                                         if((abs(level) <= max_level_ptr[run]) &&  
                                            (run <= (uint32_t) max_run_ptr[abs(level)])) {  
   
                                                 vlc[intra]->code = 0x06;  
                                                 vlc[intra]->len = 8;  
                                                 goto loop_end;  
138                                          }                                          }
139    
140                                          if(level > 0)                                       // still here?          for (intra = 0; intra < 2; intra++)
141                                                  level += max_level_ptr[run];    // restore level                  for (i = 0; i < 102; i++)
142                                          else                  {
143                                                  level -= max_level_ptr[run];  #ifdef BIGLUT
144                            offset = LEVELOFFSET;
145                                          run -= max_run_ptr[abs(level)] + 1; // and change run  #else
146                            offset = !intra * LEVELOFFSET;
147                                          if((abs(level) <= max_level_ptr[run]) &&  #endif
148                                             (run <= (uint32_t) max_run_ptr[abs(level)])) {                          for (j = 0; j < 1 << (12 - coeff_tab[intra][i].vlc.len); j++)
149                            {
150                                    DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].len       = coeff_tab[intra][i].vlc.len;
151                                    DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].event = coeff_tab[intra][i].event;
152                            }
153    
154                                                  vlc[intra]->code = 0x0e;                          coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].code
155                                                  vlc[intra]->len = 9;                                  = coeff_tab[intra][i].vlc.code << 1;
156                                                  goto loop_end;                          coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].len
157                                    = coeff_tab[intra][i].vlc.len + 1;
158    #ifndef BIGLUT
159                            if (!intra)
160    #endif
161                            {
162                                    coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].code
163                                            = (coeff_tab[intra][i].vlc.code << 1) | 1;
164                                    coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].len
165                                            = coeff_tab[intra][i].vlc.len + 1;
166                                          }                                          }
                                         run += max_run_ptr[abs(level)] + 1;  
167                                  }                                  }
168    
169                                  vlc[intra]->code = (uint32_t) ((l << 14) | (0x1e + last) << 20) |          for (intra = 0; intra < 2; intra++)
170                                                                                            (1 << 13) | ((k & 0xfff) << 1) | 1;                  for (last = 0; last < 2; last++)
171                            for (run = 0; run < 63 + last; run++)
172                                  vlc[intra]->len = 30;                          {
173                                  vlc[intra]++;                                  for (level = 1; level < 32 << intra; level++)
174                                    {
175                                            if (level <= max_level[intra][last][run] && run <= max_run[intra][last][level])
176                                  continue;                                  continue;
177    
178  loop_end:  #ifdef BIGLUT
179                                  if(level != 0) {                                          offset = LEVELOFFSET;
180                                          vlc[intra]->code = (vlc[intra]->code << (coeff_ptr[run][abs(level) - 1].len + 1)) |  #else
181                                                                             (coeff_ptr[run][abs(level) - 1].code << 1);                                          offset = !intra * LEVELOFFSET;
182                                          vlc[intra]->len = (coeff_ptr[run][abs(level) - 1].len + 1) + vlc[intra]->len;  #endif
183                        level_esc = level - max_level[intra][last][run];
184                                          if(level < 0)                                          run_esc = run - 1 - max_run[intra][last][level];
185                                                  vlc[intra]->code += 1;                                          /*use this test to use shorter esc2 codes when possible
186                                            if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc]
187                                                    && !(coeff_VLC[intra][last][level_esc + offset][run].len + 7 + 1
188                                                             > coeff_VLC[intra][last][level + offset][run_esc].code + 7 + 2))*/
189    
190                                            if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc])
191                                            {
192                                                    escape     = ESCAPE1;
193                                                    escape_len = 7 + 1;
194                                                    run_esc    = run;
195                                  }                                  }
196                                            else
197                                  vlc[intra]++;                                          {
198                                                    if (level <= max_level[intra][last][run_esc] && run_esc <= max_run[intra][last][level])
199                                                    {
200                                                            escape     = ESCAPE2;
201                                                            escape_len = 7 + 2;
202                                                            level_esc  = level;
203                          }                          }
204                                                    else
205                                                    {
206    #ifndef BIGLUT
207                                                            if (!intra)
208    #endif
209                                                            {
210                                                                    coeff_VLC[intra][last][level + offset][run].code
211                                                                            = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;
212                                                                    coeff_VLC[intra][last][level + offset][run].len = 30;
213                                                                            coeff_VLC[intra][last][offset - level][run].code
214                                                                            = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-level & 0xfff) << 1) | 1;
215                                                                    coeff_VLC[intra][last][offset - level][run].len = 30;
216                                                            }
217                                                            continue;
218                  }                  }
219          }          }
220    
221          for(i = 0; i < 4096; i++) {                                          coeff_VLC[intra][last][level + offset][run].code
222                  if(i >= 512) {                                                  = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)
223                          *vlc1 = DCT3Dtab3[(i >> 5) - 16];                                                  |  coeff_VLC[intra][last][level_esc + offset][run_esc].code;
224                          *vlc2 = DCT3Dtab0[(i >> 5) - 16];                                          coeff_VLC[intra][last][level + offset][run].len
225                                                    = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;
226    #ifndef BIGLUT
227                                            if (!intra)
228    #endif
229                                            {
230                                                    coeff_VLC[intra][last][offset - level][run].code
231                                                            = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)
232                                                            |  coeff_VLC[intra][last][level_esc + offset][run_esc].code | 1;
233                                                    coeff_VLC[intra][last][offset - level][run].len
234                                                            = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;
235                  }                  }
                 else if(i >= 128) {  
                         *vlc1 = DCT3Dtab4[(i >> 2) - 32];  
                         *vlc2 = DCT3Dtab1[(i >> 2) - 32];  
236                  }                  }
237                  else if(i >= 8) {  
238                          *vlc1 = DCT3Dtab5[i - 8];  #ifdef BIGLUT
239                          *vlc2 = DCT3Dtab2[i - 8];                                  for (level = 32 << intra; level < 2048; level++)
240                                    {
241                                            coeff_VLC[intra][last][level + offset][run].code
242                                                    = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;
243                                            coeff_VLC[intra][last][level + offset][run].len = 30;
244    
245                                            coeff_VLC[intra][last][offset - level][run].code
246                                                    = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-level & 0xfff) << 1) | 1;
247                                            coeff_VLC[intra][last][offset - level][run].len = 30;
248                                    }
249    #else
250                                    if (!intra)
251                                    {
252                                            coeff_VLC[intra][last][0][run].code
253                                                    = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-32 & 0xfff) << 1) | 1;
254                                            coeff_VLC[intra][last][0][run].len = 30;
255                  }                  }
256                  else {  #endif
                         *vlc1 = ERRtab[i];  
                         *vlc2 = ERRtab[i];  
257                  }                  }
258    /* init sprite_trajectory tables */
259    /* even if GMC is not specified (it might be used later...) */
260    
261                  vlc1++;          sprite_trajectory_code[0+16384].code = 0;
262                  vlc2++;          sprite_trajectory_code[0+16384].len = 0;
263            for (k=0;k<14;k++)
264            {
265                    int limit = (1<<k);
266    
267                    for (l=-(2*limit-1); l <= -limit; l++)
268                    {
269                            sprite_trajectory_code[i+16384].code = (2*limit-1)+l;
270                            sprite_trajectory_code[i+16384].len = k+1;
271          }          }
         DCT3D[0] = DCT3Dinter;  
         DCT3D[1] = DCT3Dintra;  
272    
273                    for (l=limit; l<= 2*limit-1; l++)
274                    {
275                            sprite_trajectory_code[i+16384].code = l;
276                            sprite_trajectory_code[i+16384].len = k+1;
277                    }
278            }
279  }  }
280    
281  static __inline void CodeVector(Bitstream *bs,  static __inline void
282    CodeVector(Bitstream * bs,
283                                  int32_t value,                                  int32_t value,
284                                  int32_t f_code,                                  int32_t f_code,
285                                  Statistics *pStat)                                  Statistics *pStat)
# Line 201  Line 298 
298          pStat->iMvCount++;          pStat->iMvCount++;
299    
300          if (value == 0) {          if (value == 0) {
301                  BitstreamPutBits(bs, mb_motion_table[32].code, mb_motion_table[32].len);                  BitstreamPutBits(bs, mb_motion_table[32].code,
302                                                     mb_motion_table[32].len);
303          } else {          } else {
304                  uint16_t length, code, mv_res, sign;                  uint16_t length, code, mv_res, sign;
305    
# Line 226  Line 324 
324                          code = -code;                          code = -code;
325    
326                  code += 32;                  code += 32;
327                  BitstreamPutBits(bs, mb_motion_table[code].code, mb_motion_table[code].len);                  BitstreamPutBits(bs, mb_motion_table[code].code,
328                                                     mb_motion_table[code].len);
329    
330                  if(f_code)                  if(f_code)
331                          BitstreamPutBits(bs, mv_res, f_code);                          BitstreamPutBits(bs, mv_res, f_code);
# Line 234  Line 333 
333    
334  }  }
335    
336    #ifdef BIGLUT
337    
338  static __inline void CodeCoeff(Bitstream *bs,  static __inline void
339    CodeCoeff(Bitstream * bs,
340                                 const int16_t qcoeff[64],                                 const int16_t qcoeff[64],
341                                 VLC *table,                                 VLC *table,
342                                 const uint16_t *zigzag,                                 const uint16_t *zigzag,
# Line 249  Line 350 
350          j = intra;          j = intra;
351          last = intra;          last = intra;
352    
353          while(j < 64 && (v = qcoeff[zigzag[j]]) == 0) j++;          while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)
354                    j++;
355    
356          do {          do {
357                  vlc = table + 64 * 2047 + (v << 6) + j - last;                  vlc = table + 64 * 2048 + (v << 6) + j - last;
358                  last = ++j;                  last = ++j;
359    
360                  // count zeroes                  /* count zeroes */
361                  while(j < 64 && (v = qcoeff[zigzag[j]]) == 0) j++;                  while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)
362                            j++;
363    
364                  // write code                  /* write code */
365                  if(j != 64) {                  if(j != 64) {
366                          BitstreamPutBits(bs, vlc->code, vlc->len);                          BitstreamPutBits(bs, vlc->code, vlc->len);
367                  } else {                  } else {
368                          vlc += 64 * 4095;                          vlc += 64 * 4096;
369                          BitstreamPutBits(bs, vlc->code, vlc->len);                          BitstreamPutBits(bs, vlc->code, vlc->len);
370                          break;                          break;
371                  }                  }
# Line 270  Line 373 
373    
374  }  }
375    
376    #else
377    
378    static __inline void
379    CodeCoeffInter(Bitstream * bs,
380                      const int16_t qcoeff[64],
381                      const uint16_t * zigzag)
382    {
383            uint32_t i, run, prev_run, code, len;
384            int32_t level, prev_level, level_shifted;
385    
386            i       = 0;
387            run = 0;
388    
389            while (!(level = qcoeff[zigzag[i++]]))
390                    run++;
391    
392            prev_level = level;
393            prev_run   = run;
394            run = 0;
395    
396            while (i < 64)
397            {
398                    if ((level = qcoeff[zigzag[i++]]) != 0)
399                    {
400                            level_shifted = prev_level + 32;
401                            if (!(level_shifted & -64))
402                            {
403                                    code = coeff_VLC[0][0][level_shifted][prev_run].code;
404                                    len      = coeff_VLC[0][0][level_shifted][prev_run].len;
405                            }
406                            else
407                            {
408                                    code = (ESCAPE3 << 21) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
409                                    len  = 30;
410                            }
411                            BitstreamPutBits(bs, code, len);
412                            prev_level = level;
413                            prev_run   = run;
414                            run = 0;
415                    }
416                    else
417                            run++;
418            }
419    
420            level_shifted = prev_level + 32;
421            if (!(level_shifted & -64))
422            {
423                    code = coeff_VLC[0][1][level_shifted][prev_run].code;
424                    len      = coeff_VLC[0][1][level_shifted][prev_run].len;
425            }
426            else
427            {
428                    code = (ESCAPE3 << 21) | (1 << 20) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
429                    len  = 30;
430            }
431            BitstreamPutBits(bs, code, len);
432    }
433    
434    static __inline void
435    CodeCoeffIntra(Bitstream * bs,
436                      const int16_t qcoeff[64],
437                      const uint16_t * zigzag)
438    {
439            uint32_t i, abs_level, run, prev_run, code, len;
440            int32_t level, prev_level;
441    
442            i       = 1;
443            run = 0;
444    
445            while (!(level = qcoeff[zigzag[i++]]))
446                    run++;
447    
448            prev_level = level;
449            prev_run   = run;
450            run = 0;
451    
452            while (i < 64)
453            {
454                    if ((level = qcoeff[zigzag[i++]]) != 0)
455                    {
456                            abs_level = ABS(prev_level);
457                            abs_level = abs_level < 64 ? abs_level : 0;
458                            code      = coeff_VLC[1][0][abs_level][prev_run].code;
459                            len               = coeff_VLC[1][0][abs_level][prev_run].len;
460                            if (len != 128)
461                                    code |= (prev_level < 0);
462                            else
463                            {
464                            code = (ESCAPE3 << 21) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
465                                    len  = 30;
466                            }
467                            BitstreamPutBits(bs, code, len);
468                            prev_level = level;
469                            prev_run   = run;
470                            run = 0;
471                    }
472                    else
473                            run++;
474            }
475    
476            abs_level = ABS(prev_level);
477            abs_level = abs_level < 64 ? abs_level : 0;
478            code      = coeff_VLC[1][1][abs_level][prev_run].code;
479            len               = coeff_VLC[1][1][abs_level][prev_run].len;
480            if (len != 128)
481                    code |= (prev_level < 0);
482            else
483            {
484                    code = (ESCAPE3 << 21) | (1 << 20) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
485                    len  = 30;
486            }
487            BitstreamPutBits(bs, code, len);
488    }
489    
490    #endif
491    
492  static void CodeBlockIntra(const FRAMEINFO * frame,  static __inline void
493    CodeBlockIntra(const FRAMEINFO * const frame,
494                             const MACROBLOCK *pMB,                             const MACROBLOCK *pMB,
495                             int16_t qcoeff[6*64],                             int16_t qcoeff[6*64],
496                             Bitstream * bs,                             Bitstream * bs,
# Line 285  Line 504 
504          // write mcbpc          // write mcbpc
505          if(frame->coding_type == I_VOP) {          if(frame->coding_type == I_VOP) {
506                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);
507                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code, mcbpc_intra_tab[mcbpc].len);                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code,
508          }                                                   mcbpc_intra_tab[mcbpc].len);
509          else {          } else {
510                  mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);                  mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);
511                  BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code, mcbpc_inter_tab[mcbpc].len);                  BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code,
512                                                     mcbpc_inter_tab[mcbpc].len);
513          }          }
514    
515          // ac prediction flag          // ac prediction flag
# Line 306  Line 526 
526                  BitstreamPutBits(bs, pMB->dquant, 2);                  BitstreamPutBits(bs, pMB->dquant, 2);
527    
528          // write interlacing          // write interlacing
529          if (frame->global_flags & XVID_INTERLACING)          if (frame->global_flags & XVID_INTERLACING) {
         {  
530                  BitstreamPutBit(bs, pMB->field_dct);                  BitstreamPutBit(bs, pMB->field_dct);
531          }          }
   
532          // code block coeffs          // code block coeffs
533          for(i = 0; i < 6; i++)          for (i = 0; i < 6; i++) {
         {  
534                  if(i < 4)                  if(i < 4)
535                          BitstreamPutBits(bs,                          BitstreamPutBits(bs, dcy_tab[qcoeff[i * 64 + 0] + 255].code,
                                          dcy_tab[qcoeff[i*64 + 0] + 255].code,  
536                                           dcy_tab[qcoeff[i*64 + 0] + 255].len);                                           dcy_tab[qcoeff[i*64 + 0] + 255].len);
537                  else                  else
538                          BitstreamPutBits(bs,                          BitstreamPutBits(bs, dcc_tab[qcoeff[i * 64 + 0] + 255].code,
                                          dcc_tab[qcoeff[i*64 + 0] + 255].code,  
539                                           dcc_tab[qcoeff[i*64 + 0] + 255].len);                                           dcc_tab[qcoeff[i*64 + 0] + 255].len);
540    
541                  if(pMB->cbp & (1 << (5 - i)))                  if (pMB->cbp & (1 << (5 - i))) {
542                  {                          const uint16_t *scan_table =
543                                    frame->global_flags & XVID_ALTERNATESCAN ?
544                                    scan_tables[2] : scan_tables[pMB->acpred_directions[i]];
545    
546                          bits = BitstreamPos(bs);                          bits = BitstreamPos(bs);
547    
548                          CodeCoeff(bs,  #ifdef BIGLUT
549                                    &qcoeff[i*64],                          CodeCoeff(bs, &qcoeff[i * 64], intra_table, scan_table, 1);
550                                    intra_table,  #else
551                                    scan_tables[pMB->acpred_directions[i]],                          CodeCoeffIntra(bs, &qcoeff[i * 64], scan_table);
552                                    1);  #endif
553    
554                          bits = BitstreamPos(bs) - bits;                          bits = BitstreamPos(bs) - bits;
555                          pStat->iTextBits += bits;                          pStat->iTextBits += bits;
# Line 341  Line 559 
559  }  }
560    
561    
562  static void CodeBlockInter(const FRAMEINFO * frame,  static void
563    CodeBlockInter(const FRAMEINFO * const frame,
564                             const MACROBLOCK *pMB,                             const MACROBLOCK *pMB,
565                             int16_t qcoeff[6*64],                             int16_t qcoeff[6*64],
566                             Bitstream * bs,                             Bitstream * bs,
# Line 355  Line 574 
574          cbpy = 15 - (pMB->cbp >> 2);          cbpy = 15 - (pMB->cbp >> 2);
575    
576          // write mcbpc          // write mcbpc
577          BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code, mcbpc_inter_tab[mcbpc].len);          BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code,
578                                             mcbpc_inter_tab[mcbpc].len);
579    
580            if ( (frame->coding_type == S_VOP) && (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) )
581                    BitstreamPutBit(bs, pMB->mcsel);                // mcsel: '0'=local motion, '1'=GMC
582    
583          // write cbpy          // write cbpy
584          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);
# Line 365  Line 588 
588                  BitstreamPutBits(bs, pMB->dquant, 2);                  BitstreamPutBits(bs, pMB->dquant, 2);
589    
590          // interlacing          // interlacing
591          if (frame->global_flags & XVID_INTERLACING)          if (frame->global_flags & XVID_INTERLACING) {
592          {                  if (pMB->cbp) {
593                  BitstreamPutBit(bs, pMB->field_dct);                  BitstreamPutBit(bs, pMB->field_dct);
594                  DEBUG1("codep: field_dct: ", pMB->field_dct);                          DPRINTF(DPRINTF_MB,"codep: field_dct: %i", pMB->field_dct);
595                    }
596    
597                  // if inter block, write field ME flag                  // if inter block, write field ME flag
598                  if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)                  if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {
                 {  
599                          BitstreamPutBit(bs, pMB->field_pred);                          BitstreamPutBit(bs, pMB->field_pred);
600                          DEBUG1("codep: field_pred: ", pMB->field_pred);                          DPRINTF(DPRINTF_MB,"codep: field_pred: %i", pMB->field_pred);
601    
602                          // write field prediction references                          // write field prediction references
603                          if (pMB->field_pred)                          if (pMB->field_pred) {
                         {  
604                                  BitstreamPutBit(bs, pMB->field_for_top);                                  BitstreamPutBit(bs, pMB->field_for_top);
605                                  BitstreamPutBit(bs, pMB->field_for_bot);                                  BitstreamPutBit(bs, pMB->field_for_bot);
606                          }                          }
607                  }                  }
608          }          }
609            // code motion vector(s) if motion is local
610          // code motion vector(s)          if (!pMB->mcsel)
611          for(i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++)                  for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {
         {  
612                  CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);                  CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);
613                  CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat);                  CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat);
614          }          }
# Line 397  Line 618 
618          // code block coeffs          // code block coeffs
619          for(i = 0; i < 6; i++)          for(i = 0; i < 6; i++)
620                  if(pMB->cbp & (1 << (5 - i)))                  if(pMB->cbp & (1 << (5 - i)))
621                          CodeCoeff(bs, &qcoeff[i*64], inter_table, scan_tables[0], 0);                  {
622                            const uint16_t *scan_table =
623                                    frame->global_flags & XVID_ALTERNATESCAN ?
624                                    scan_tables[2] : scan_tables[0];
625    
626    #ifdef BIGLUT
627                            CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_table, 0);
628    #else
629                            CodeCoeffInter(bs, &qcoeff[i * 64], scan_table);
630    #endif
631                    }
632    
633          bits = BitstreamPos(bs) - bits;          bits = BitstreamPos(bs) - bits;
634          pStat->iTextBits += bits;          pStat->iTextBits += bits;
   
635  }  }
636    
637    
638  void MBCoding(const FRAMEINFO * frame,  void
639    MBCoding(const FRAMEINFO * const frame,
640                MACROBLOCK *pMB,                MACROBLOCK *pMB,
641                int16_t qcoeff[6*64],                int16_t qcoeff[6*64],
642                Bitstream * bs,                Bitstream * bs,
643                Statistics * pStat)                Statistics * pStat)
644  {  {
645            if (frame->coding_type != I_VOP)
646                            BitstreamPutBit(bs, 0); // not_coded
647    
648          int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q);          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q)
   
         if(frame->coding_type == P_VOP) {  
                 if(pMB->cbp == 0 && pMB->mode == MODE_INTER &&  
                    pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0)  
                 {  
                         BitstreamPutBit(bs, 1);         // not_coded  
                         return;  
                 }  
                 else  
                         BitstreamPutBit(bs, 0);         // coded  
         }  
   
         if(intra)  
649                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);
650          else          else
651                  CodeBlockInter(frame, pMB, qcoeff, bs, pStat);                  CodeBlockInter(frame, pMB, qcoeff, bs, pStat);
652    
653  }  }
654    
655    /*
656    // moved to mbcoding.h so that in can be 'static __inline'
657    void
658    MBSkip(Bitstream * bs)
659    {
660            BitstreamPutBit(bs, 1); // not coded
661    }
662    */
663    
664  /***************************************************************  /***************************************************************
665   * bframe encoding start   * bframe encoding start
666   ***************************************************************/   ***************************************************************/
# Line 444  Line 673 
673          3       0001b   forward mc+q            dbquant, mvdf          3       0001b   forward mc+q            dbquant, mvdf
674  */  */
675    
676  void put_bvop_mbtype(Bitstream * bs, int value)  static __inline void
677    put_bvop_mbtype(Bitstream * bs,
678                                    int value)
679  {  {
680          switch(value)          switch (value) {
681          {                  case MODE_FORWARD:
         case 0 :        BitstreamPutBit(bs, 1);  
                                 return;  
   
         case 1 :        BitstreamPutBit(bs, 0);  
                                 BitstreamPutBit(bs, 1);  
                                 return;  
   
         case 2 :        BitstreamPutBit(bs, 0);  
682                                  BitstreamPutBit(bs, 0);                                  BitstreamPutBit(bs, 0);
683                                  BitstreamPutBit(bs, 1);                  case MODE_BACKWARD:
                                 return;  
   
         case 3 :        BitstreamPutBit(bs, 0);  
684                                  BitstreamPutBit(bs, 0);                                  BitstreamPutBit(bs, 0);
685                    case MODE_INTERPOLATE:
686                                  BitstreamPutBit(bs, 0);                                  BitstreamPutBit(bs, 0);
687                    case MODE_DIRECT:
688                                  BitstreamPutBit(bs, 1);                                  BitstreamPutBit(bs, 1);
689                                  return;                  default:
690                            break;
         default :       ; // invalid!  
   
691          }          }
   
692  }  }
693    
694  /*  /*
# Line 479  Line 698 
698          +2      11b          +2      11b
699  */  */
700    
701  void put_bvop_dbquant(Bitstream *bs, int value)  static __inline void
702    put_bvop_dbquant(Bitstream * bs,
703                                     int value)
704  {  {
705          switch (value)          switch (value) {
706          {          case 0:
707          case 0 :        BitstreamPutBit(bs, 0);                  BitstreamPutBit(bs, 0);
708                                  return;                                  return;
709    
710          case -2 :       BitstreamPutBit(bs, 1);          case -2:
711                    BitstreamPutBit(bs, 1);
712                                  BitstreamPutBit(bs, 0);                                  BitstreamPutBit(bs, 0);
713                                  return;                                  return;
714    
715          case 2 :        BitstreamPutBit(bs, 1);          case 2:
716                    BitstreamPutBit(bs, 1);
717                                  BitstreamPutBit(bs, 1);                                  BitstreamPutBit(bs, 1);
718                                  return;                                  return;
719    
# Line 500  Line 723 
723    
724    
725    
726  void MBCodingBVOP(const MACROBLOCK * mb,  void
727    MBCodingBVOP(const MACROBLOCK * mb,
728                                    const int16_t qcoeff[6*64],                                    const int16_t qcoeff[6*64],
729                                    const int32_t fcode,                                    const int32_t fcode,
730                                    const int32_t bcode,                                    const int32_t bcode,
731                                    Bitstream * bs,                                    Bitstream * bs,
732                                    Statistics * pStat)                           Statistics * pStat,
733                             int direction)
734  {  {
735          int i;          int vcode = fcode;
736            unsigned int i;
737    
738  /*      ------------------------------------------------------------------  /*      ------------------------------------------------------------------
739                  when a block is skipped it is decoded DIRECT(0,)                  when a block is skipped it is decoded DIRECT(0,0)
740                  hence are interpolated from forward & backward frames                  hence is interpolated from forward & backward frames
741          ------------------------------------------------------------------ */          ------------------------------------------------------------------ */
742    
743          if (mb->mode == 5)          if (mb->mode == MODE_DIRECT_NONE_MV) {
         {  
744                  BitstreamPutBit(bs, 1);         // skipped                  BitstreamPutBit(bs, 1);         // skipped
745                  return;                  return;
746          }          }
747    
748          BitstreamPutBit(bs, 0);         // not skipped          BitstreamPutBit(bs, 0);         // not skipped
749    
750          if (mb->cbp == 0)          if (mb->cbp == 0) {
         {  
751                  BitstreamPutBit(bs, 1);         // cbp == 0                  BitstreamPutBit(bs, 1);         // cbp == 0
752          }          } else {
         else  
         {  
753                  BitstreamPutBit(bs, 0);         // cbp == xxx                  BitstreamPutBit(bs, 0);         // cbp == xxx
754          }          }
755    
756          put_bvop_mbtype(bs, mb->mode);          put_bvop_mbtype(bs, mb->mode);
757    
758          if (mb->cbp)          if (mb->cbp) {
         {  
759                  BitstreamPutBits(bs, mb->cbp, 6);                  BitstreamPutBits(bs, mb->cbp, 6);
760          }          }
761    
762          if (mb->mode != MODE_DIRECT && mb->cbp != 0)          if (mb->mode != MODE_DIRECT && mb->cbp != 0) {
         {  
763                  put_bvop_dbquant(bs, 0); // todo: mb->dquant = 0                  put_bvop_dbquant(bs, 0); // todo: mb->dquant = 0
764          }          }
765    
766          if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_FORWARD)          switch (mb->mode) {
767          {                  case MODE_INTERPOLATE:
768              CodeVector(bs, mb->pmvs[0].x, fcode, pStat);                          CodeVector(bs, mb->pmvs[1].x, vcode, pStat); //forward vector of interpolate mode
769              CodeVector(bs, mb->pmvs[0].y, fcode, pStat);                          CodeVector(bs, mb->pmvs[1].y, vcode, pStat);
770          }                  case MODE_BACKWARD:
771                            vcode = bcode;
772          if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_BACKWARD)                  case MODE_FORWARD:
773          {                          CodeVector(bs, mb->pmvs[0].x, vcode, pStat);
774              CodeVector(bs, mb->b_pmvs[0].x, bcode, pStat);                          CodeVector(bs, mb->pmvs[0].y, vcode, pStat);
775              CodeVector(bs, mb->b_pmvs[0].y, bcode, pStat);                          break;
776          }                  case MODE_DIRECT:
777                            CodeVector(bs, mb->pmvs[3].x, 1, pStat);        // fcode is always 1 for delta vector
778          if (mb->mode == MODE_DIRECT)                          CodeVector(bs, mb->pmvs[3].y, 1, pStat);        // prediction is always (0,0)
779          {                  default: break;
                 // TODO: direct  
780          }          }
781    
782      for (i = 0; i < 6; i++)          for (i = 0; i < 6; i++) {
783      {                  if (mb->cbp & (1 << (5 - i))) {
784                  if (mb->cbp & (1 << (5 - i)))  #ifdef BIGLUT
                 {  
785                          CodeCoeff(bs, &qcoeff[i*64], inter_table, scan_tables[0], 0);                          CodeCoeff(bs, &qcoeff[i*64], inter_table, scan_tables[0], 0);
786    #else
787                            CodeCoeffInter(bs, &qcoeff[i * 64], scan_tables[0]);
788    #endif
789                  }                  }
790      }      }
791  }  }
# Line 575  Line 796 
796   * decoding stuff starts here                                  *   * decoding stuff starts here                                  *
797   ***************************************************************/   ***************************************************************/
798    
799  int get_mcbpc_intra(Bitstream * bs)  
800    // for IVOP addbits == 0
801    // for PVOP addbits == fcode - 1
802    // for BVOP addbits == max(fcode,bcode) - 1
803    // returns true or false
804    int
805    check_resync_marker(Bitstream * bs, int addbits)
806    {
807            uint32_t nbits;
808            uint32_t code;
809            uint32_t nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER + addbits;
810    
811            nbits = BitstreamNumBitsToByteAlign(bs);
812            code = BitstreamShowBits(bs, nbits);
813    
814            if (code == (((uint32_t)1 << (nbits - 1)) - 1))
815            {
816                    return BitstreamShowBitsFromByteAlign(bs, nbitsresyncmarker) == RESYNC_MARKER;
817            }
818    
819            return 0;
820    }
821    
822    
823    
824    int
825    get_mcbpc_intra(Bitstream * bs)
826  {  {
827    
828          uint32_t index;          uint32_t index;
829    
830          while((index = BitstreamShowBits(bs, 9)) == 1)          index = BitstreamShowBits(bs, 9);
                 BitstreamSkip(bs, 9);  
   
831          index >>= 3;          index >>= 3;
832    
833          BitstreamSkip(bs, mcbpc_intra_table[index].len);          BitstreamSkip(bs, mcbpc_intra_table[index].len);
# Line 591  Line 836 
836    
837  }  }
838    
839  int get_mcbpc_inter(Bitstream * bs)  int
840    get_mcbpc_inter(Bitstream * bs)
841  {  {
842    
843          uint32_t index;          uint32_t index;
844    
845          while((index = CLIP(BitstreamShowBits(bs, 9), 256)) == 1)          index = MIN(BitstreamShowBits(bs, 9), 256);
                 BitstreamSkip(bs, 9);  
846    
847          BitstreamSkip(bs,  mcbpc_inter_table[index].len);          BitstreamSkip(bs,  mcbpc_inter_table[index].len);
848    
# Line 605  Line 850 
850    
851  }  }
852    
853  int get_cbpy(Bitstream * bs, int intra)  int
854    get_cbpy(Bitstream * bs,
855                     int intra)
856  {  {
857    
858          int cbpy;          int cbpy;
# Line 621  Line 868 
868    
869  }  }
870    
871  int get_mv_data(Bitstream * bs)  static __inline int
872    get_mv_data(Bitstream * bs)
873  {  {
874    
875          uint32_t index;          uint32_t index;
# Line 631  Line 879 
879    
880          index = BitstreamShowBits(bs, 12);          index = BitstreamShowBits(bs, 12);
881    
882          if(index >= 512)          if (index >= 512) {
         {  
883                  index = (index >> 8) - 2;                  index = (index >> 8) - 2;
884                  BitstreamSkip(bs, TMNMVtab0[index].len);                  BitstreamSkip(bs, TMNMVtab0[index].len);
885                  return TMNMVtab0[index].code;                  return TMNMVtab0[index].code;
886          }          }
887    
888          if(index >= 128)          if (index >= 128) {
         {  
889                  index = (index >> 2) - 32;                  index = (index >> 2) - 32;
890                  BitstreamSkip(bs, TMNMVtab1[index].len);                  BitstreamSkip(bs, TMNMVtab1[index].len);
891                  return TMNMVtab1[index].code;                  return TMNMVtab1[index].code;
# Line 652  Line 898 
898    
899  }  }
900    
901  int get_mv(Bitstream * bs, int fcode)  int
902    get_mv(Bitstream * bs,
903               int fcode)
904  {  {
905    
906          int data;          int data;
# Line 672  Line 920 
920    
921  }  }
922    
923  int get_dc_dif(Bitstream * bs, uint32_t dc_size)  int
924    get_dc_dif(Bitstream * bs,
925                       uint32_t dc_size)
926  {  {
927    
928          int code = BitstreamGetBits(bs, dc_size);          int code = BitstreamGetBits(bs, dc_size);
# Line 685  Line 935 
935    
936  }  }
937    
938  int get_dc_size_lum(Bitstream * bs)  int
939    get_dc_size_lum(Bitstream * bs)
940  {  {
941    
942          int code, i;          int code, i;
943    
944          code = BitstreamShowBits(bs, 11);          code = BitstreamShowBits(bs, 11);
945    
946          for(i = 11; i > 3; i--) {          for(i = 11; i > 3; i--) {
# Line 705  Line 957 
957  }  }
958    
959    
960  int get_dc_size_chrom(Bitstream * bs)  int
961    get_dc_size_chrom(Bitstream * bs)
962  {  {
963    
964          uint32_t code, i;          uint32_t code, i;
965    
966          code = BitstreamShowBits(bs, 12);          code = BitstreamShowBits(bs, 12);
967    
968          for(i = 12; i > 2; i--) {          for(i = 12; i > 2; i--) {
# Line 723  Line 977 
977    
978  }  }
979    
980  void get_intra_block(Bitstream * bs, int16_t * block, int direction, int coeff)  static __inline int
981    get_coeff(Bitstream * bs,
982                      int *run,
983                      int *last,
984                      int intra,
985                      int short_video_header)
986  {  {
987    
988          const uint16_t * scan = scan_tables[ direction ];          uint32_t mode;
989          int level;          int32_t level;
990          int run;          REVERSE_EVENT *reverse_event;
991          int last;  
992            if (short_video_header)         /* inter-VLCs will be used for both intra and inter blocks */
993                    intra = 0;
994    
995            if (BitstreamShowBits(bs, 7) != ESCAPE) {
996                    reverse_event = &DCT3D[intra][BitstreamShowBits(bs, 12)];
997    
998                    if ((level = reverse_event->event.level) == 0)
999                            goto error;
1000    
1001                    *last = reverse_event->event.last;
1002                    *run  = reverse_event->event.run;
1003    
1004                    BitstreamSkip(bs, reverse_event->len);
1005    
1006                    return BitstreamGetBits(bs, 1) ? -level : level;
1007            }
1008    
1009            BitstreamSkip(bs, 7);
1010    
1011            if (short_video_header) {
1012                    /* escape mode 4 - H.263 type, only used if short_video_header = 1  */
1013                    *last = BitstreamGetBit(bs);
1014                    *run = BitstreamGetBits(bs, 6);
1015                    level = BitstreamGetBits(bs, 8);
1016    
1017                    if (level == 0 || level == 128)
1018                            DPRINTF(DPRINTF_ERROR, "Illegal LEVEL for ESCAPE mode 4: %d", level);
1019    
1020                    return (level << 24) >> 24;
1021            }
1022    
1023            mode = BitstreamShowBits(bs, 2);
1024    
1025          do          if (mode < 3) {
1026                    BitstreamSkip(bs, (mode == 2) ? 2 : 1);
1027    
1028                    reverse_event = &DCT3D[intra][BitstreamShowBits(bs, 12)];
1029    
1030                    if ((level = reverse_event->event.level) == 0)
1031                            goto error;
1032    
1033                    *last = reverse_event->event.last;
1034                    *run  = reverse_event->event.run;
1035    
1036                    BitstreamSkip(bs, reverse_event->len);
1037    
1038                    if (mode < 2)                   /* first escape mode, level is offset */
1039                            level += max_level[intra][*last][*run];
1040                    else                                    /* second escape mode, run is offset */
1041                            *run += max_run[intra][*last][level] + 1;
1042    
1043                    return BitstreamGetBits(bs, 1) ? -level : level;
1044            }
1045    
1046            /* third escape mode - fixed length codes */
1047            BitstreamSkip(bs, 2);
1048            *last = BitstreamGetBits(bs, 1);
1049            *run = BitstreamGetBits(bs, 6);
1050            BitstreamSkip(bs, 1);           /* marker */
1051            level = BitstreamGetBits(bs, 12);
1052            BitstreamSkip(bs, 1);           /* marker */
1053    
1054            return (level << 20) >> 20;
1055    
1056      error:
1057            *run = VLC_ERROR;
1058            return 0;
1059    }
1060    
1061    void
1062    get_intra_block(Bitstream * bs,
1063                                    int16_t * block,
1064                                    int direction,
1065                                    int coeff)
1066          {          {
1067    
1068            const uint16_t *scan = scan_tables[direction];
1069            int level, run, last;
1070    
1071            do {
1072                  level = get_coeff(bs, &run, &last, 1, 0);                  level = get_coeff(bs, &run, &last, 1, 0);
1073                  if (run == -1)                  if (run == -1) {
1074                  {                          DPRINTF(DPRINTF_ERROR,"fatal: invalid run");
                         DEBUG("fatal: invalid run");  
1075                          break;                          break;
1076                  }                  }
1077                  coeff += run;                  coeff += run;
1078                  block[ scan[coeff] ] = level;                  block[ scan[coeff] ] = level;
1079                  if (level < -127 || level > 127)  
1080                  {                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level);
1081                          DEBUG1("warning: intra_overflow", level);                  //DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32));
1082    
1083                    if (level < -2047 || level > 2047) {
1084                            DPRINTF(DPRINTF_ERROR,"warning: intra_overflow %i", level);
1085                  }                  }
1086                  coeff++;                  coeff++;
1087          } while (!last);          } while (!last);
1088    
1089  }  }
1090    
1091  void get_inter_block(Bitstream * bs, int16_t * block)  void
1092    get_inter_block(Bitstream * bs,
1093                                    int16_t * block,
1094                                    int direction)
1095  {  {
1096    
1097          const uint16_t * scan = scan_tables[0];          const uint16_t *scan = scan_tables[direction];
1098          int p;          int p;
1099          int level;          int level;
1100          int run;          int run;
1101          int last;          int last;
1102    
1103          p = 0;          p = 0;
1104          do          do {
         {  
1105                  level = get_coeff(bs, &run, &last, 0, 0);                  level = get_coeff(bs, &run, &last, 0, 0);
1106                  if (run == -1)                  if (run == -1) {
1107                  {                          DPRINTF(DPRINTF_ERROR,"fatal: invalid run");
                         DEBUG("fatal: invalid run");  
1108                          break;                          break;
1109                  }                  }
1110                  p += run;                  p += run;
1111    
1112                  block[ scan[p] ] = level;                  block[ scan[p] ] = level;
1113                  if (level < -127 || level > 127)  
1114                  {                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level);
1115                          DEBUG1("warning: inter_overflow", level);                  // DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[p], level, BitstreamShowBits(bs, 32));
1116    
1117                    if (level < -2047 || level > 2047) {
1118                            DPRINTF(DPRINTF_ERROR,"warning: inter overflow %i", level);
1119                  }                  }
1120                  p++;                  p++;
1121          } while (!last);          } while (!last);

Legend:
Removed from v.153  
changed lines
  Added in v.790

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4