]> git.sesse.net Git - vlc/blob - src/video_parser/vpar_headers.c
* Optimisation du parseur ;
[vlc] / src / video_parser / vpar_headers.c
1 /*****************************************************************************
2  * vpar_headers.c : headers parsing
3  * (c)1999 VideoLAN
4  *****************************************************************************/
5
6 /*****************************************************************************
7  * Preamble
8  *****************************************************************************/
9 #include <errno.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <unistd.h>
13 #include <string.h>
14 #include <sys/uio.h>
15
16 #include "config.h"
17 #include "common.h"
18 #include "mtime.h"
19 #include "vlc_thread.h"
20
21 #include "intf_msg.h"
22 #include "debug.h"                    /* ?? temporaire, requis par netlist.h */
23
24 #include "input.h"
25 #include "input_netlist.h"
26 #include "decoder_fifo.h"
27 #include "video.h"
28 #include "video_output.h"
29
30 #include "vdec_idct.h"
31 #include "video_decoder.h"
32 #include "vdec_motion.h"
33
34 #include "vpar_blocks.h"
35 #include "vpar_headers.h"
36 #include "vpar_synchro.h"
37 #include "video_parser.h"
38 #include "vpar_motion.h"
39 #include "video_fifo.h"
40
41 /*
42  * Local prototypes
43  */
44 static __inline__ void NextStartCode( vpar_thread_t * p_vpar );
45 static void SequenceHeader( vpar_thread_t * p_vpar );
46 static void GroupHeader( vpar_thread_t * p_vpar );
47 static void PictureHeader( vpar_thread_t * p_vpar );
48 static void SliceHeader00( vpar_thread_t * p_vpar,
49                            int * pi_mb_address, int i_mb_base,
50                            u32 i_vert_code );
51 static void SliceHeader01( vpar_thread_t * p_vpar,
52                            int * pi_mb_address, int i_mb_base,
53                            u32 i_vert_code );
54 static void SliceHeader10( vpar_thread_t * p_vpar,
55                            int * pi_mb_address, int i_mb_base,
56                            u32 i_vert_code );
57 static void SliceHeader11( vpar_thread_t * p_vpar,
58                            int * pi_mb_address, int i_mb_base,
59                            u32 i_vert_code );
60 static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
61                                     int * pi_mb_address, int i_mb_base,
62                                     u32 i_vert_code );
63 static void ExtensionAndUserData( vpar_thread_t * p_vpar );
64 static void QuantMatrixExtension( vpar_thread_t * p_vpar );
65 static void SequenceScalableExtension( vpar_thread_t * p_vpar );
66 static void SequenceDisplayExtension( vpar_thread_t * p_vpar );
67 static void PictureDisplayExtension( vpar_thread_t * p_vpar );
68 static void PictureSpatialScalableExtension( vpar_thread_t * p_vpar );
69 static void PictureTemporalScalableExtension( vpar_thread_t * p_vpar );
70 static void CopyrightExtension( vpar_thread_t * p_vpar );
71
72 /*
73  * Standard variables
74  */
75
76 /*****************************************************************************
77  * pi_default_intra_quant : default quantization matrix
78  *****************************************************************************/
79 #ifndef VDEC_DFT
80 int pi_default_intra_quant[] =
81 {
82     8,  16, 19, 22, 26, 27, 29, 34,
83     16, 16, 22, 24, 27, 29, 34, 37,
84     19, 22, 26, 27, 29, 34, 34, 38,
85     22, 22, 26, 27, 29, 34, 37, 40,
86     22, 26, 27, 29, 32, 35, 40, 48,
87     26, 27, 29, 32, 35, 40, 48, 58,
88     26, 27, 29, 34, 38, 46, 56, 69,
89     27, 29, 35, 38, 46, 56, 69, 83
90 };      
91 #else
92 int pi_default_intra_quant[] =
93 {
94     2048,   5681,   6355,   6623,   6656,   5431,   4018,   2401,
95     5681,   7880,   10207,  10021,  9587,   8091,   6534,   3625,
96     6355,   10207,  11363,  10619,  9700,   8935,   6155,   3507,
97     6623,   9186,   10226,  9557,   8730,   8041,   6028,   3322,
98     5632,   9232,   9031,   8730,   8192,   7040,   5542,   3390,
99     5230,   7533,   7621,   7568,   7040,   6321,   5225,   3219,
100     3602,   5189,   5250,   5539,   5265,   5007,   4199,   2638,
101     1907,   2841,   3230,   3156,   3249,   3108,   2638,   1617        
102 };
103 #endif
104
105 /*****************************************************************************
106  * pi_default_nonintra_quant : default quantization matrix
107  *****************************************************************************/
108 #ifndef VDEC_DFT
109 int pi_default_nonintra_quant[] =
110 {
111     16, 16, 16, 16, 16, 16, 16, 16,
112     16, 16, 16, 16, 16, 16, 16, 16,
113     16, 16, 16, 16, 16, 16, 16, 16,
114     16, 16, 16, 16, 16, 16, 16, 16,
115     16, 16, 16, 16, 16, 16, 16, 16,
116     16, 16, 16, 16, 16, 16, 16, 16,
117     16, 16, 16, 16, 16, 16, 16, 16,
118     16, 16, 16, 16, 16, 16, 16, 16
119 };
120 #else
121 int pi_default_nonintra_quanit[] =
122 {
123     4096,   5680,   5344,   4816,   4096,   3216,   2224,   1136,
124     5680,   7888,   7424,   6688,   5680,   4464,   3072,   1568,
125     5344,   7424,   6992,   6288,   5344,   4208,   2896,   1472,
126     4816,   6688,   6288,   5664,   4816,   3792,   2608,   1328,
127     4096,   5680,   5344,   4816,   4096,   3216,   2224,   1136,
128     3216,   4464,   4208,   3792,   3216,   2528,   1744,   880,
129     2224,   3072,   2896,   2608,   2224,   1744,   1200,   608,
130     1136,   1568,   1472,   1328,   1136,   880,    608,    304 
131 };
132 #endif
133
134 /*****************************************************************************
135  * pi_scan : zig-zag and alternate scan patterns
136  *****************************************************************************/
137 u8 pi_scan[2][64] =
138 {
139     { /* Zig-Zag pattern */
140         0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,
141         12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,
142         35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,
143         58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63
144     },
145     { /* Alternate scan pattern */
146         0,8,16,24,1,9,2,10,17,25,32,40,48,56,57,49,
147         41,33,26,18,3,11,4,12,19,27,34,42,50,58,35,43,
148         51,59,20,28,5,13,6,14,21,29,36,44,52,60,37,45,
149         53,61,22,30,7,15,23,31,38,46,54,62,39,47,55,63
150     }
151 };
152
153 /*
154  * Local inline functions.
155  */
156
157 /*****************************************************************************
158  * NextStartCode : Find the next start code
159  *****************************************************************************/
160 static __inline__ void NextStartCode( vpar_thread_t * p_vpar )
161 {
162     /* Re-align the buffer on an 8-bit boundary */
163     RealignBits( &p_vpar->bit_stream );
164
165     while( ShowBits( &p_vpar->bit_stream, 24 ) != 0x01L && !p_vpar->b_die )
166     {
167         RemoveBits( &p_vpar->bit_stream, 8 );
168     }
169 }
170
171 /*****************************************************************************
172  * ReferenceUpdate : Update the reference pointers when we have a new picture
173  *****************************************************************************/
174 static void __inline__ ReferenceUpdate( vpar_thread_t * p_vpar,
175                                         int i_coding_type,
176                                         picture_t * p_newref )
177 {
178     if( i_coding_type != B_CODING_TYPE )
179     {
180         if( p_vpar->sequence.p_forward != NULL )
181             vout_UnlinkPicture( p_vpar->p_vout, p_vpar->sequence.p_forward );
182         if( p_vpar->sequence.p_backward != NULL )
183         {
184             vout_DatePicture( p_vpar->p_vout, p_vpar->sequence.p_backward,
185                               vpar_SynchroDate( p_vpar ) );
186         }
187         p_vpar->sequence.p_forward = p_vpar->sequence.p_backward;
188         p_vpar->sequence.p_backward = p_newref;
189         if( p_newref != NULL )
190             vout_LinkPicture( p_vpar->p_vout, p_newref );
191     }
192 }
193
194 /*****************************************************************************
195  * ReferenceReplace : Replace the last reference pointer when we destroy
196  * a picture
197  *****************************************************************************/
198 static void __inline__ ReferenceReplace( vpar_thread_t * p_vpar,
199                                          int i_coding_type,
200                                          picture_t * p_newref )
201 {
202     if( i_coding_type != B_CODING_TYPE )
203     {
204         if( p_vpar->sequence.p_backward != NULL )
205             vout_UnlinkPicture( p_vpar->p_vout, p_vpar->sequence.p_backward );
206         p_vpar->sequence.p_backward = p_newref;
207         if( p_newref != NULL )
208             vout_LinkPicture( p_vpar->p_vout, p_newref );
209     }
210 }
211
212 /*****************************************************************************
213  * LoadMatrix : Load a quantization matrix
214  *****************************************************************************/
215 static __inline__ void LoadMatrix( vpar_thread_t * p_vpar, quant_matrix_t * p_matrix )
216 {
217     int i_dummy;
218     
219     if( !p_matrix->b_allocated )
220     {
221         /* Allocate a piece of memory to load the matrix. */
222         if( (p_matrix->pi_matrix = (int *)malloc( 64*sizeof(int) )) == NULL )
223         {
224             intf_ErrMsg("vpar error: allocation error in LoadMatrix()\n");
225             p_vpar->b_error = 1;
226             return;
227         }
228         p_matrix->b_allocated = 1;
229     }
230     
231     for( i_dummy = 0; i_dummy < 64; i_dummy++ )
232     {
233         p_matrix->pi_matrix[pi_scan[SCAN_ZIGZAG][i_dummy]]
234              = GetBits( &p_vpar->bit_stream, 8 );
235     }
236
237 #ifdef VDEC_DFT
238     /* Discrete Fourier Transform requires the quantization matrices to
239      * be normalized before using them. */
240     vdec_NormQuantMatrix( p_matrix->pi_matrix );
241 #endif
242 }
243
244 /*****************************************************************************
245  * LinkMatrix : Link a quantization matrix to another
246  *****************************************************************************/
247 static __inline__ void LinkMatrix( quant_matrix_t * p_matrix, int * pi_array )
248 {
249     if( p_matrix->b_allocated )
250     {
251         /* Deallocate the piece of memory. */
252         free( p_matrix->pi_matrix );
253         p_matrix->b_allocated = 0;
254     }
255     
256     p_matrix->pi_matrix = pi_array;
257 }
258
259 /*
260  * Exported functions.
261  */
262
263 /*****************************************************************************
264  * vpar_NextSequenceHeader : Find the next sequence header
265  *****************************************************************************/
266 int vpar_NextSequenceHeader( vpar_thread_t * p_vpar )
267 {
268     while( !p_vpar->b_die )
269     {
270         NextStartCode( p_vpar );
271         if( ShowBits( &p_vpar->bit_stream, 32 ) == SEQUENCE_HEADER_CODE )
272             return 0;
273         RemoveBits( &p_vpar->bit_stream, 8 );
274     }
275     return 1;
276 }
277
278 /*****************************************************************************
279  * vpar_ParseHeader : Parse the next header
280  *****************************************************************************/
281 int vpar_ParseHeader( vpar_thread_t * p_vpar )
282 {
283     while( !p_vpar->b_die )
284     {
285         NextStartCode( p_vpar );
286         switch( GetBits32( &p_vpar->bit_stream ) )
287         {
288         case SEQUENCE_HEADER_CODE:
289             SequenceHeader( p_vpar );
290             return 0;
291             break;
292
293         case GROUP_START_CODE:
294             GroupHeader( p_vpar );
295             return 0;
296             break;
297
298         case PICTURE_START_CODE:
299             PictureHeader( p_vpar );
300             return 0;
301             break;
302
303         case SEQUENCE_END_CODE:
304             intf_DbgMsg("vpar debug: sequence end code received\n");
305             return 1;
306             break;
307
308         default:
309         }
310     }
311
312     return 0;
313 }
314
315 /*
316  * Following functions are local
317  */
318
319 /*****************************************************************************
320  * SequenceHeader : Parse the next sequence header
321  *****************************************************************************/
322 static void SequenceHeader( vpar_thread_t * p_vpar )
323 {
324 #define RESERVED    -1 
325     static float r_frame_rate_table[16] =
326     {
327         0.0,
328         ((23.0*1000.0)/1001.0),
329         24.0,
330         25.0,
331         ((30.0*1000.0)/1001.0),
332         30.0,
333         50.0,
334         ((60.0*1000.0)/1001.0),
335         60.0,
336         RESERVED, RESERVED, RESERVED, RESERVED, RESERVED, RESERVED, RESERVED
337     };
338 #undef RESERVED
339
340     int i_height_save, i_width_save;
341     
342     i_height_save = p_vpar->sequence.i_height;
343     i_width_save = p_vpar->sequence.i_width;
344
345     p_vpar->sequence.i_width = GetBits( &p_vpar->bit_stream, 12 );
346     p_vpar->sequence.i_height = GetBits( &p_vpar->bit_stream, 12 );
347     p_vpar->sequence.i_aspect_ratio = GetBits( &p_vpar->bit_stream, 4 );
348     p_vpar->sequence.r_frame_rate =
349             r_frame_rate_table[ GetBits( &p_vpar->bit_stream, 4 ) ];
350
351     /* We don't need bit_rate_value, marker_bit, vbv_buffer_size,
352      * constrained_parameters_flag */
353     RemoveBits( &p_vpar->bit_stream, 30 );
354     
355     /*
356      * Quantization matrices
357      */
358     if( GetBits( &p_vpar->bit_stream, 1 ) ) /* load_intra_quantizer_matrix */
359     {
360         LoadMatrix( p_vpar, &p_vpar->sequence.intra_quant );
361     }
362     else
363     {
364         /* Use default matrix. */
365         LinkMatrix( &p_vpar->sequence.intra_quant, pi_default_intra_quant );
366     }
367     
368     if( GetBits( &p_vpar->bit_stream, 1 ) ) /* load_non_intra_quantizer_matrix */
369     {
370         LoadMatrix( p_vpar, &p_vpar->sequence.nonintra_quant );
371     }
372     else
373     {
374         /* Use default matrix. */
375         LinkMatrix( &p_vpar->sequence.nonintra_quant, pi_default_nonintra_quant );
376     }
377     
378     /* Unless later overwritten by a matrix extension, we have the same
379      * matrices for luminance and chrominance. */
380     LinkMatrix( &p_vpar->sequence.chroma_intra_quant,
381                 p_vpar->sequence.intra_quant.pi_matrix );
382     LinkMatrix( &p_vpar->sequence.chroma_nonintra_quant,
383                 p_vpar->sequence.nonintra_quant.pi_matrix );
384
385     /*
386      * Sequence Extension
387      */
388     NextStartCode( p_vpar );
389     if( ShowBits( &p_vpar->bit_stream, 32 ) == EXTENSION_START_CODE )
390     {
391         int                         i_dummy;
392
393         /* Turn the MPEG2 flag on */
394         p_vpar->sequence.b_mpeg2 = 1;
395     
396         /* Parse sequence_extension */
397         RemoveBits32( &p_vpar->bit_stream );
398         /* extension_start_code_identifier, profile_and_level_indication */
399         RemoveBits( &p_vpar->bit_stream, 12 );
400         p_vpar->sequence.b_progressive = GetBits( &p_vpar->bit_stream, 1 );
401         p_vpar->sequence.i_chroma_format = GetBits( &p_vpar->bit_stream, 2 );
402         p_vpar->sequence.i_width |= GetBits( &p_vpar->bit_stream, 2 ) << 12;
403         p_vpar->sequence.i_height |= GetBits( &p_vpar->bit_stream, 2 ) << 12;
404         /* bit_rate_extension, marker_bit, vbv_buffer_size_extension, low_delay */
405         RemoveBits( &p_vpar->bit_stream, 22 );
406         /* frame_rate_extension_n */
407         i_dummy = GetBits( &p_vpar->bit_stream, 2 );
408         /* frame_rate_extension_d */
409         p_vpar->sequence.r_frame_rate *= (i_dummy + 1)
410                                   / (GetBits( &p_vpar->bit_stream, 5 ) + 1);
411     }
412     else
413     {
414         /* It's an MPEG-1 stream. Put adequate parameters. */
415
416         p_vpar->sequence.b_mpeg2 = 0;
417         p_vpar->sequence.b_progressive = 1;
418         p_vpar->sequence.i_chroma_format = CHROMA_420;
419     }
420
421     /* Update sizes */
422     p_vpar->sequence.i_mb_width = (p_vpar->sequence.i_width + 15) / 16;
423     p_vpar->sequence.i_mb_height = (p_vpar->sequence.b_progressive) ?
424                                    (p_vpar->sequence.i_height + 15) / 16 :
425                                    2 * ((p_vpar->sequence.i_height + 31) / 32);
426     p_vpar->sequence.i_mb_size = p_vpar->sequence.i_mb_width
427                                         * p_vpar->sequence.i_mb_height;
428     p_vpar->sequence.i_width = (p_vpar->sequence.i_mb_width * 16);
429     p_vpar->sequence.i_height = (p_vpar->sequence.i_mb_height * 16);
430     p_vpar->sequence.i_size = p_vpar->sequence.i_width
431                                         * p_vpar->sequence.i_height;
432
433     /* Update chromatic information */
434     switch( p_vpar->sequence.i_chroma_format )
435     {
436     case CHROMA_420:
437         p_vpar->sequence.i_chroma_nb_blocks = 2;
438         p_vpar->sequence.i_chroma_width = p_vpar->sequence.i_width >> 1;
439         p_vpar->sequence.i_chroma_mb_width = 8;
440         p_vpar->sequence.i_chroma_mb_height = 8;
441         break;
442
443     case CHROMA_422:
444         p_vpar->sequence.i_chroma_nb_blocks = 4;
445         p_vpar->sequence.i_chroma_width = p_vpar->sequence.i_width >> 1;
446         p_vpar->sequence.i_chroma_mb_width = 8;
447         p_vpar->sequence.i_chroma_mb_height = 16;
448         break;
449
450     case CHROMA_444:
451         p_vpar->sequence.i_chroma_nb_blocks = 8;
452         p_vpar->sequence.i_chroma_width = p_vpar->sequence.i_width;
453         p_vpar->sequence.i_chroma_mb_width = 16;
454         p_vpar->sequence.i_chroma_mb_height = 16;
455     }
456
457     /* Slice Header functions */
458     if( p_vpar->sequence.i_height <= 2800 )
459     {
460         if( p_vpar->sequence.i_scalable_mode != SC_DP )
461         {
462             p_vpar->sequence.pf_slice_header = SliceHeader00;
463         }
464         else
465         {
466             p_vpar->sequence.pf_slice_header = SliceHeader01;
467         }
468     }
469     else
470     {
471         if( p_vpar->sequence.i_scalable_mode != SC_DP )
472         {
473             p_vpar->sequence.pf_slice_header = SliceHeader10;
474         }
475         else
476         {
477             p_vpar->sequence.pf_slice_header = SliceHeader11;
478         }
479     }
480
481     if(    p_vpar->sequence.i_width != i_width_save
482         || p_vpar->sequence.i_height != i_height_save )
483     {
484          /* What do we do in case of a size change ??? */
485     }
486
487     /* Extension and User data */
488     ExtensionAndUserData( p_vpar );
489 }
490
491 /*****************************************************************************
492  * GroupHeader : Parse the next group of pictures header
493  *****************************************************************************/
494 static void GroupHeader( vpar_thread_t * p_vpar )
495 {
496     /* Nothing to do, we don't care. */
497     RemoveBits( &p_vpar->bit_stream, 27 );
498     ExtensionAndUserData( p_vpar );
499 }
500
501 /*****************************************************************************
502  * PictureHeader : Parse the next picture header
503  *****************************************************************************/
504 static void PictureHeader( vpar_thread_t * p_vpar )
505 {
506     static f_parse_mb_t ppf_parse_mb[4][4][2] =
507     {
508         {
509             {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}
510         },
511         {
512             /* I_CODING_TYPE */
513             {NULL, NULL},
514             {vpar_ParseMacroblock2I420T0, vpar_ParseMacroblockGENERIC},
515             {vpar_ParseMacroblockGENERIC, vpar_ParseMacroblock2I420B1},
516             {vpar_ParseMacroblock2I420F0, vpar_ParseMacroblock2I420F0}
517         },
518         {
519             /* P_CODING_TYPE */
520             {NULL, NULL},
521             {vpar_ParseMacroblock2P420T0, vpar_ParseMacroblockGENERIC},
522             {vpar_ParseMacroblockGENERIC, vpar_ParseMacroblock2P420B1},
523             {vpar_ParseMacroblock2P420F0, vpar_ParseMacroblock2P420F0}
524         },
525         {
526             /* B_CODING_TYPE */
527             {NULL, NULL},
528             {vpar_ParseMacroblock2B420T0, vpar_ParseMacroblockGENERIC},
529             {vpar_ParseMacroblockGENERIC, vpar_ParseMacroblock2B420B1},
530             {vpar_ParseMacroblock2B420F0, vpar_ParseMacroblock2B420F0}
531         }
532     };
533
534     int                 i_structure;
535     int                 i_mb_address, i_mb_base;
536     boolean_t           b_parsable;
537     u32                 i_dummy;
538 #ifdef VDEC_SMP
539     int                 i_mb;
540 #endif
541     
542     RemoveBits( &p_vpar->bit_stream, 10 ); /* temporal_reference */
543     p_vpar->picture.i_coding_type = GetBits( &p_vpar->bit_stream, 3 );
544     RemoveBits( &p_vpar->bit_stream, 16 ); /* vbv_delay */
545
546     if( p_vpar->picture.i_coding_type == P_CODING_TYPE
547         || p_vpar->picture.i_coding_type == B_CODING_TYPE )
548     {
549         p_vpar->picture.pb_full_pel_vector[0] = GetBits( &p_vpar->bit_stream, 1 );
550         p_vpar->picture.i_forward_f_code = GetBits( &p_vpar->bit_stream, 3 );
551     }
552     if( p_vpar->picture.i_coding_type == B_CODING_TYPE )
553     {
554         p_vpar->picture.pb_full_pel_vector[1] = GetBits( &p_vpar->bit_stream, 1 );
555         p_vpar->picture.i_backward_f_code = GetBits( &p_vpar->bit_stream, 3 );
556     }
557
558     /* extra_information_picture */
559     while( GetBits( &p_vpar->bit_stream, 1 ) )
560     {
561         RemoveBits( &p_vpar->bit_stream, 8 );
562     }
563
564     /* 
565      * Picture Coding Extension
566      */
567     NextStartCode( p_vpar );
568     if( ShowBits( &p_vpar->bit_stream, 32 ) == EXTENSION_START_CODE )
569     {
570         /* Parse picture_coding_extension */
571         RemoveBits32( &p_vpar->bit_stream );
572         /* extension_start_code_identifier */
573         RemoveBits( &p_vpar->bit_stream, 4 );
574         
575         p_vpar->picture.ppi_f_code[0][0] = GetBits( &p_vpar->bit_stream, 4 );
576         p_vpar->picture.ppi_f_code[0][1] = GetBits( &p_vpar->bit_stream, 4 );
577         p_vpar->picture.ppi_f_code[1][0] = GetBits( &p_vpar->bit_stream, 4 );
578         p_vpar->picture.ppi_f_code[1][1] = GetBits( &p_vpar->bit_stream, 4 );
579         p_vpar->picture.i_intra_dc_precision = GetBits( &p_vpar->bit_stream, 2 );
580         i_structure = GetBits( &p_vpar->bit_stream, 2 );
581         p_vpar->picture.b_top_field_first = GetBits( &p_vpar->bit_stream, 1 );
582         p_vpar->picture.b_frame_pred_frame_dct
583              = GetBits( &p_vpar->bit_stream, 1 );
584         p_vpar->picture.b_concealment_mv = GetBits( &p_vpar->bit_stream, 1 );
585         p_vpar->picture.b_q_scale_type = GetBits( &p_vpar->bit_stream, 1 );
586         p_vpar->picture.b_intra_vlc_format = GetBits( &p_vpar->bit_stream, 1 );
587         p_vpar->picture.b_alternate_scan = GetBits( &p_vpar->bit_stream, 1 );
588         p_vpar->picture.b_repeat_first_field = GetBits( &p_vpar->bit_stream, 1 );
589         /* repeat_first_field (ISO/IEC 13818-2 6.3.10 is necessary to know
590          * the length of the picture_display_extension structure.
591          * chroma_420_type (obsolete) */
592         RemoveBits( &p_vpar->bit_stream, 1 );
593         p_vpar->picture.b_progressive_frame = GetBits( &p_vpar->bit_stream, 1 );
594         
595         /* composite_display_flag */
596         if( GetBits( &p_vpar->bit_stream, 1 ) )
597         {
598             /* v_axis, field_sequence, sub_carrier, burst_amplitude,
599              * sub_carrier_phase */
600             RemoveBits( &p_vpar->bit_stream, 20 );
601         }
602     }
603     else
604     {
605         /* MPEG-1 compatibility flags */
606         p_vpar->picture.i_intra_dc_precision = 0; /* 8 bits */
607         i_structure = FRAME_STRUCTURE;
608         p_vpar->picture.b_frame_pred_frame_dct = 1;
609         p_vpar->picture.b_concealment_mv = 0;
610         p_vpar->picture.b_q_scale_type = 0;
611         p_vpar->picture.b_intra_vlc_format = 0;
612         p_vpar->picture.b_alternate_scan = 0; /* zigzag */
613         p_vpar->picture.b_repeat_first_field = 0;
614         p_vpar->picture.b_progressive_frame = 1;
615     }
616
617     if( p_vpar->picture.i_current_structure &&
618         (i_structure == FRAME_STRUCTURE ||
619          i_structure == p_vpar->picture.i_current_structure) )
620     {
621         /* We don't have the second field of the buffered frame. */
622         if( p_vpar->picture.p_picture != NULL )
623         {
624             ReferenceReplace( p_vpar,
625                       p_vpar->picture.i_coding_type,
626                       NULL );
627
628 #ifdef VDEC_SMP
629             for( i_mb = 0; p_vpar->picture.pp_mb[i_mb] != NULL; i_mb++ )
630             {
631                 vpar_DestroyMacroblock( &p_vpar->vfifo,
632                                         p_vpar->picture.pp_mb[i_mb] );
633             }
634 #endif
635             vout_DestroyPicture( p_vpar->p_vout, p_vpar->picture.p_picture );
636         }
637         
638         p_vpar->picture.i_current_structure = 0;
639
640         intf_DbgMsg("vpar debug: odd number of field picture.\n");
641     }
642
643     /* Do we have the reference pictures ? */
644     b_parsable = !(((p_vpar->picture.i_coding_type == P_CODING_TYPE) &&
645                     (p_vpar->sequence.p_backward == NULL)) ||
646                      /* p_backward will become p_forward later */
647                    ((p_vpar->picture.i_coding_type == B_CODING_TYPE) &&
648                     (p_vpar->sequence.p_forward == NULL ||
649                      p_vpar->sequence.p_backward == NULL)));
650
651     if( b_parsable )
652     {
653         if( p_vpar->picture.i_current_structure )
654         {
655             /* Second field of a frame. We will decode it if, and only if we
656             * have decoded the first field. */
657             b_parsable = (p_vpar->picture.p_picture != NULL);
658         }
659         else
660         {
661             /* Does synchro say we have enough time to decode it ? */
662             b_parsable = vpar_SynchroChoose( p_vpar,
663                                p_vpar->picture.i_coding_type, i_structure );
664         }
665     }
666
667     if( !b_parsable )
668     {
669         /* Update the reference pointers. */
670         ReferenceUpdate( p_vpar, p_vpar->picture.i_coding_type, NULL );
671         
672         /* Warn Synchro we have trashed a picture. */
673         vpar_SynchroTrash( p_vpar, p_vpar->picture.i_coding_type, i_structure );
674
675         /* Update context. */
676         if( i_structure != FRAME_STRUCTURE )
677             p_vpar->picture.i_current_structure = i_structure;
678         p_vpar->picture.p_picture = NULL;
679
680         return;
681     }
682
683     /* OK, now we are sure we will decode the picture. */
684 #define P_picture p_vpar->picture.p_picture
685     p_vpar->picture.b_error = 0;
686     p_vpar->picture.b_frame_structure = (i_structure == FRAME_STRUCTURE);
687
688     if( !p_vpar->picture.i_current_structure )
689     {
690         /* This is a new frame. Get a structure from the video_output. */
691         while( ( P_picture = vout_CreatePicture( p_vpar->p_vout,
692                                         99+p_vpar->sequence.i_chroma_format, /*???*/
693                                         p_vpar->sequence.i_width,
694                                         p_vpar->sequence.i_height ) )
695              == NULL )
696         {
697             intf_DbgMsg("vpar debug: allocation error in vout_CreatePicture\n");
698             if( p_vpar->b_die || p_vpar->b_error )
699             {
700                 return;
701             }
702             msleep( VPAR_OUTMEM_SLEEP );
703         }
704
705         /* Initialize values. */
706         vpar_SynchroDecode( p_vpar, p_vpar->picture.i_coding_type, i_structure );
707         if( p_vpar->picture.i_coding_type == B_CODING_TYPE )
708         {
709             /* Put date immediately. */
710             vout_DatePicture( p_vpar->p_vout, P_picture,
711                               vpar_SynchroDate( p_vpar ) );
712         }
713         P_picture->i_aspect_ratio = p_vpar->sequence.i_aspect_ratio;
714         P_picture->i_matrix_coefficients = p_vpar->sequence.i_matrix_coefficients;
715         p_vpar->picture.i_l_stride = ( p_vpar->sequence.i_width
716                     << ( 1 - p_vpar->picture.b_frame_structure ) );
717         p_vpar->picture.i_c_stride = ( p_vpar->sequence.i_chroma_width
718                     << ( 1 - p_vpar->picture.b_frame_structure ));
719
720         P_picture->i_deccount = p_vpar->sequence.i_mb_size;
721         vlc_mutex_init( &p_vpar->picture.p_picture->lock_deccount );
722 #ifdef VDEC_SMP
723         memset( p_vpar->picture.pp_mb, 0, MAX_MB*sizeof(macroblock_t *) );
724 #endif
725 /* FIXME ! remove asap */
726 //memset( P_picture->p_data, 0, (p_vpar->sequence.i_mb_size*384));
727
728         /* Update the reference pointers. */
729         ReferenceUpdate( p_vpar, p_vpar->picture.i_coding_type, P_picture );
730
731 #ifdef VDEC_SMP
732         /* Link referenced pictures for the decoder 
733          * They are unlinked in vpar_ReleaseMacroblock() & vpar_DestroyMacroblock() */
734         if( p_vpar->picture.i_coding_type == P_CODING_TYPE ||
735             p_vpar->picture.i_coding_type == B_CODING_TYPE )
736         {
737             vout_LinkPicture( p_vpar->p_vout, p_vpar->sequence.p_forward );
738         }
739         if( p_vpar->picture.i_coding_type == B_CODING_TYPE )
740         {
741             vout_LinkPicture( p_vpar->p_vout, p_vpar->sequence.p_backward );
742         } 
743 #endif
744     }
745     p_vpar->picture.i_current_structure |= i_structure;
746     p_vpar->picture.i_structure = i_structure;
747
748     /* Initialize picture data for decoding. */
749     if( i_structure == BOTTOM_FIELD )
750     {
751         i_mb_base = p_vpar->sequence.i_mb_size >> 1;
752         p_vpar->mb.i_l_y = 1;
753         p_vpar->mb.i_c_y = 1;
754     }
755     else
756     {
757         i_mb_base = 0;
758         p_vpar->mb.i_l_y = p_vpar->mb.i_c_y = 0;
759     }
760     i_mb_address = 0;
761     p_vpar->mb.i_l_x = p_vpar->mb.i_c_x = 0;
762
763     /* Extension and User data. */
764     ExtensionAndUserData( p_vpar );
765
766     /* Macroblock parsing function. */
767     if( p_vpar->sequence.i_chroma_format != CHROMA_420
768         || !p_vpar->sequence.b_mpeg2 )
769     {
770         p_vpar->picture.pf_parse_mb = vpar_ParseMacroblockGENERIC;
771     }
772     else
773     {
774         p_vpar->picture.pf_parse_mb =
775             ppf_parse_mb[p_vpar->picture.i_coding_type]
776                         [p_vpar->picture.i_structure]
777                         [(p_vpar->picture.i_structure !=
778                              p_vpar->picture.i_current_structure)];
779     }
780
781     /* Picture data (ISO/IEC 13818-2 6.2.3.7). */
782     NextStartCode( p_vpar );
783     while( i_mb_address+i_mb_base < p_vpar->sequence.i_mb_size
784            && !p_vpar->b_die )
785     {
786         if( ((i_dummy = ShowBits( &p_vpar->bit_stream, 32 ))
787                  < SLICE_START_CODE_MIN) ||
788             (i_dummy > SLICE_START_CODE_MAX) )
789         {
790             intf_DbgMsg("vpar debug: premature end of picture\n");
791             p_vpar->picture.b_error = 1;
792             break;
793         }
794         RemoveBits32( &p_vpar->bit_stream );
795         
796         /* Decode slice data. */
797         p_vpar->sequence.pf_slice_header( p_vpar, &i_mb_address, i_mb_base, i_dummy & 255 );
798     }
799
800     if( p_vpar->b_die || p_vpar->b_error )
801     {
802         return;
803     }
804
805     if( p_vpar->picture.b_error )
806     {
807         /* Trash picture. */
808 //fprintf(stderr, "Image trashee\n");
809 #ifdef VDEC_SMP
810         for( i_mb = 1; p_vpar->picture.pp_mb[i_mb] != NULL; i_mb++ )
811         {
812             vpar_DestroyMacroblock( &p_vpar->vfifo, p_vpar->picture.pp_mb[i_mb] );
813         }
814 #endif
815
816         if( P_picture->i_deccount != 1 )
817         {
818             vout_DestroyPicture( p_vpar->p_vout, P_picture );
819         }
820
821         ReferenceReplace( p_vpar, p_vpar->picture.i_coding_type, NULL );
822
823         /* Prepare context for the next picture. */
824         P_picture = NULL;
825         if( p_vpar->picture.i_current_structure == FRAME_STRUCTURE )
826             p_vpar->picture.i_current_structure = 0;
827     }
828     else if( p_vpar->picture.i_current_structure == FRAME_STRUCTURE )
829     {
830 //fprintf(stderr, "Image parsee (%d)\n", p_vpar->picture.i_coding_type);
831         /* Frame completely parsed. */
832 #ifdef VDEC_SMP
833         for( i_mb = 1; p_vpar->picture.pp_mb[i_mb] != NULL; i_mb++ )
834         {
835             vpar_DecodeMacroblock( &p_vpar->vfifo, p_vpar->picture.pp_mb[i_mb] );
836         }
837
838         /* Send signal to the video_decoder. */
839         vlc_mutex_lock( &p_vpar->vfifo.lock );
840         vlc_cond_signal( &p_vpar->vfifo.wait );
841         vlc_mutex_unlock( &p_vpar->vfifo.lock );
842 #endif
843
844         /* Prepare context for the next picture. */
845         P_picture = NULL;
846         p_vpar->picture.i_current_structure = 0;
847     }
848 #undef P_picture
849 }
850
851 /*****************************************************************************
852  * SliceHeader : Parse the next slice structure
853  *****************************************************************************/
854 static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
855                                     int * pi_mb_address, int i_mb_base,
856                                     u32 i_vert_code )
857 {
858     /* DC predictors initialization table */
859     static int              pi_dc_dct_reinit[4] = {128,256,512,1024};
860
861     int                     i_mb_address_save = *pi_mb_address;
862
863     p_vpar->picture.b_error = 0;
864
865     /* slice_vertical_position_extension and priority_breakpoint already done */
866     LoadQuantizerScale( p_vpar );
867
868     if( GetBits( &p_vpar->bit_stream, 1 ) )
869     {
870         /* intra_slice, slice_id */
871         RemoveBits( &p_vpar->bit_stream, 8 );
872         /* extra_information_slice */
873         while( GetBits( &p_vpar->bit_stream, 1 ) )
874         {
875             RemoveBits( &p_vpar->bit_stream, 8 );
876         }
877     }
878     *pi_mb_address = (i_vert_code - 1)*p_vpar->sequence.i_mb_width;
879     
880     /* Reset DC coefficients predictors (ISO/IEC 13818-2 7.2.1). Why
881      * does the reference decoder put 0 instead of the normative values ? */
882     p_vpar->slice.pi_dc_dct_pred[0] = p_vpar->slice.pi_dc_dct_pred[1]
883         = p_vpar->slice.pi_dc_dct_pred[2]
884         = pi_dc_dct_reinit[p_vpar->picture.i_intra_dc_precision];
885
886     /* Reset motion vector predictors (ISO/IEC 13818-2 7.6.3.4). */
887     memset( p_vpar->slice.pppi_pmv, 0, 8*sizeof(int) );
888
889     do
890     {
891         p_vpar->picture.pf_parse_mb( p_vpar, pi_mb_address,
892                                      i_mb_address_save, i_mb_base,
893                                      p_vpar->sequence.b_mpeg2,
894                                      p_vpar->picture.i_coding_type,
895                                      p_vpar->sequence.i_chroma_format,
896                                      p_vpar->picture.i_structure,
897                                      (p_vpar->picture.i_structure !=
898                                         p_vpar->picture.i_current_structure) );
899         i_mb_address_save = *pi_mb_address;
900     }
901     while( ShowBits( &p_vpar->bit_stream, 23 ) && !p_vpar->picture.b_error
902             && !p_vpar->b_die );
903     NextStartCode( p_vpar );
904 }
905
906 /*****************************************************************************
907  * SliceHeaderXY : Parse the next slice structure
908  *****************************************************************************
909  * X = i_height > 2800 ?
910  * Y = scalable_mode == SC_DP ?
911  *****************************************************************************/
912 static void SliceHeader00( vpar_thread_t * p_vpar,
913                            int * pi_mb_address, int i_mb_base,
914                            u32 i_vert_code )
915 {
916     SliceHeader( p_vpar, pi_mb_address, i_mb_base, i_vert_code );
917 }
918
919 static void SliceHeader01( vpar_thread_t * p_vpar,
920                            int * pi_mb_address, int i_mb_base,
921                            u32 i_vert_code )
922 {
923     RemoveBits( &p_vpar->bit_stream, 7 ); /* priority_breakpoint */
924     SliceHeader( p_vpar, pi_mb_address, i_mb_base, i_vert_code );
925 }
926
927 static void SliceHeader10( vpar_thread_t * p_vpar,
928                            int * pi_mb_address, int i_mb_base,
929                            u32 i_vert_code )
930 {
931     i_vert_code += GetBits( &p_vpar->bit_stream, 3 ) << 7;
932     SliceHeader( p_vpar, pi_mb_address, i_mb_base, i_vert_code );
933 }
934
935 static void SliceHeader11( vpar_thread_t * p_vpar,
936                            int * pi_mb_address, int i_mb_base,
937                            u32 i_vert_code )
938 {
939     i_vert_code += GetBits( &p_vpar->bit_stream, 3 ) << 7;
940     RemoveBits( &p_vpar->bit_stream, 7 ); /* priority_breakpoint */
941     SliceHeader( p_vpar, pi_mb_address, i_mb_base, i_vert_code );
942 }
943
944 /*****************************************************************************
945  * ExtensionAndUserData : Parse the extension_and_user_data structure
946  *****************************************************************************/
947 static void ExtensionAndUserData( vpar_thread_t * p_vpar )
948 {
949     while( !p_vpar->b_die )
950     {
951         NextStartCode( p_vpar );
952         switch( ShowBits( &p_vpar->bit_stream, 32 ) )
953         {
954         case EXTENSION_START_CODE:
955             RemoveBits32( &p_vpar->bit_stream );
956             switch( GetBits( &p_vpar->bit_stream, 4 ) )
957             {
958             case SEQUENCE_DISPLAY_EXTENSION_ID:
959                 SequenceDisplayExtension( p_vpar );
960                 break;
961             case QUANT_MATRIX_EXTENSION_ID:
962                 QuantMatrixExtension( p_vpar );
963                 break;
964             case SEQUENCE_SCALABLE_EXTENSION_ID:
965                 SequenceScalableExtension( p_vpar );
966                 break;
967             case PICTURE_DISPLAY_EXTENSION_ID:
968                 PictureDisplayExtension( p_vpar );
969                 break;
970             case PICTURE_SPATIAL_SCALABLE_EXTENSION_ID:
971                 PictureSpatialScalableExtension( p_vpar );
972                 break;
973             case PICTURE_TEMPORAL_SCALABLE_EXTENSION_ID:
974                 PictureTemporalScalableExtension( p_vpar );
975                 break;
976             case COPYRIGHT_EXTENSION_ID:
977                 CopyrightExtension( p_vpar );
978                 break;
979             default:
980             }
981             break;
982
983         case USER_DATA_START_CODE:
984             RemoveBits32( &p_vpar->bit_stream );
985             /* Wait for the next start code */
986             break;
987
988         default:
989             return;
990         }
991     }
992 }
993
994
995 /*****************************************************************************
996  * SequenceDisplayExtension : Parse the sequence_display_extension structure *
997  *****************************************************************************/
998
999 static void SequenceDisplayExtension( vpar_thread_t * p_vpar )
1000 {
1001     /* We don't care sequence_display_extension. */
1002     /* video_format */
1003     RemoveBits( &p_vpar->bit_stream, 3 );
1004     if( GetBits( &p_vpar->bit_stream, 1 ) )
1005     {
1006         /* Two bytes for color_desciption */
1007         RemoveBits( &p_vpar->bit_stream, 16 );
1008         p_vpar->sequence.i_matrix_coefficients = GetBits( &p_vpar->bit_stream, 8 );
1009     }
1010     /* display_horizontal and vertical_size and a marker_bit */
1011     RemoveBits( &p_vpar->bit_stream, 29 );
1012 }
1013
1014
1015 /*****************************************************************************
1016  * QuantMatrixExtension : Load quantization matrices for luminance           *
1017  *                        and chrominance                                    *
1018  *****************************************************************************/
1019
1020 static void QuantMatrixExtension( vpar_thread_t * p_vpar )
1021 {
1022     if( GetBits( &p_vpar->bit_stream, 1 ) )
1023     {
1024         /* Load intra_quantiser_matrix for luminance. */
1025         LoadMatrix( p_vpar, &p_vpar->sequence.intra_quant );
1026     }
1027     else
1028     {
1029         /* Use the default matrix. */
1030         LinkMatrix( &p_vpar->sequence.intra_quant,
1031                     pi_default_intra_quant );
1032     }
1033     if( GetBits( &p_vpar->bit_stream, 1 ) )
1034     {
1035         /* Load non_intra_quantiser_matrix for luminance. */
1036         LoadMatrix( p_vpar, &p_vpar->sequence.nonintra_quant );
1037     }
1038     else
1039     {
1040         /* Use the default matrix. */
1041         LinkMatrix( &p_vpar->sequence.nonintra_quant,
1042                     pi_default_nonintra_quant );
1043     }
1044     if( GetBits( &p_vpar->bit_stream, 1 ) )
1045     {
1046         /* Load intra_quantiser_matrix for chrominance. */
1047         LoadMatrix( p_vpar, &p_vpar->sequence.chroma_intra_quant );
1048     }
1049     else
1050     {
1051         /* Link the chrominance intra matrix to the luminance one. */
1052         LinkMatrix( &p_vpar->sequence.chroma_intra_quant,
1053                     p_vpar->sequence.intra_quant.pi_matrix );
1054     }
1055     if( GetBits( &p_vpar->bit_stream, 1 ) )
1056     {
1057         /* Load non_intra_quantiser_matrix for chrominance. */
1058         LoadMatrix( p_vpar, &p_vpar->sequence.chroma_nonintra_quant );
1059     }
1060     else
1061     {
1062         /* Link the chrominance intra matrix to the luminance one. */
1063         LinkMatrix( &p_vpar->sequence.chroma_intra_quant,
1064                     p_vpar->sequence.intra_quant.pi_matrix );
1065     }
1066     if( GetBits( &p_vpar->bit_stream, 1 ) )
1067     {
1068         /* Load non_intra_quantiser_matrix for chrominance. */
1069         LoadMatrix( p_vpar, &p_vpar->sequence.chroma_nonintra_quant );
1070     }
1071     else
1072     {
1073         /* Link the chrominance nonintra matrix to the luminance one. */
1074         LinkMatrix( &p_vpar->sequence.chroma_nonintra_quant,
1075                     p_vpar->sequence.nonintra_quant.pi_matrix );
1076     }
1077 }
1078
1079
1080 /*****************************************************************************
1081  * SequenceScalableExtension : Parse the sequence_scalable_extension         *
1082  *                             structure to handle scalable coding           *
1083  *****************************************************************************/
1084
1085 static void SequenceScalableExtension( vpar_thread_t * p_vpar )
1086 {
1087     /* We don't care about anything scalable except the scalable mode. */
1088     switch( p_vpar->sequence.i_scalable_mode = GetBits( &p_vpar->bit_stream, 2 ) )
1089     /* The length of the structure depends on the value of the scalable_mode */
1090     {
1091         case 1:
1092             RemoveBits32( &p_vpar->bit_stream );
1093             RemoveBits( &p_vpar->bit_stream, 21 );
1094             break;
1095         case 2:
1096             RemoveBits( &p_vpar->bit_stream, 12 );
1097             break;
1098         default:
1099             RemoveBits( &p_vpar->bit_stream, 4 );
1100     }
1101
1102 }
1103 /*****************************************************************************
1104  * PictureDisplayExtension : Parse the picture_display_extension structure   *
1105  *****************************************************************************/
1106
1107 static void PictureDisplayExtension( vpar_thread_t * p_vpar )
1108 {
1109     /* Number of frame center offset */
1110     int i_nb, i_dummy;
1111     /* I am not sure it works but it should
1112         (fewer tests than shown in ยง6.3.12) */
1113     i_nb = p_vpar->sequence.b_progressive ? p_vpar->sequence.b_progressive +
1114                                             p_vpar->picture.b_repeat_first_field +
1115                                             p_vpar->picture.b_top_field_first
1116                            : ( p_vpar->picture.b_frame_structure + 1 ) +
1117                              p_vpar->picture.b_repeat_first_field;
1118     for( i_dummy = 0; i_dummy < i_nb; i_dummy++ )
1119     {
1120         RemoveBits( &p_vpar->bit_stream, 17 );
1121         RemoveBits( &p_vpar->bit_stream, 17 );
1122     }
1123 }
1124
1125
1126 /*****************************************************************************
1127  * PictureSpatialScalableExtension                                           *
1128  *****************************************************************************/
1129
1130 static void PictureSpatialScalableExtension( vpar_thread_t * p_vpar )
1131 {
1132     /* That's scalable, so we trash it */
1133     RemoveBits32( &p_vpar->bit_stream );
1134     RemoveBits( &p_vpar->bit_stream, 16 );
1135 }
1136
1137
1138 /*****************************************************************************
1139  * PictureTemporalScalableExtension                                          *
1140  *****************************************************************************/
1141
1142 static void PictureTemporalScalableExtension( vpar_thread_t * p_vpar )
1143 {
1144     /* Scalable again, trashed again */
1145     RemoveBits( &p_vpar->bit_stream, 23 );
1146 }
1147
1148
1149 /*****************************************************************************
1150  * CopyrightExtension : Keeps some legal informations                        *
1151  *****************************************************************************/
1152
1153 static void CopyrightExtension( vpar_thread_t * p_vpar )
1154 {
1155     u32     i_copyright_nb_1, i_copyright_nb_2; /* local integers */
1156     p_vpar->sequence.b_copyright_flag = GetBits( &p_vpar->bit_stream, 1 );
1157         /* A flag that says whether the copyright information is significant */
1158     p_vpar->sequence.i_copyright_id = GetBits( &p_vpar->bit_stream, 8 );
1159         /* An identifier compliant with ISO/CEI JTC 1/SC 29 */
1160     p_vpar->sequence.b_original = GetBits( &p_vpar->bit_stream, 1 );
1161         /* Reserved bits */
1162     RemoveBits( &p_vpar->bit_stream, 8 );
1163         /* The copyright_number is split in three parts */
1164         /* first part */
1165     i_copyright_nb_1 = GetBits( &p_vpar->bit_stream, 20 );
1166     RemoveBits( &p_vpar->bit_stream, 1 );
1167         /* second part */
1168     i_copyright_nb_2 = GetBits( &p_vpar->bit_stream, 22 );
1169     RemoveBits( &p_vpar->bit_stream, 1 );
1170         /* third part and sum */
1171     p_vpar->sequence.i_copyright_nb = ( (u64)i_copyright_nb_1 << 44 ) |
1172                                       ( (u64)i_copyright_nb_2 << 22 ) |
1173                                       ( (u64)GetBits( &p_vpar->bit_stream, 22 ) );
1174 }