1 /*****************************************************************************
2 * vpar_headers.c : headers parsing
4 *****************************************************************************/
6 /*****************************************************************************
8 *****************************************************************************/
16 #include <X11/extensions/XShm.h>
21 #include "vlc_thread.h"
24 #include "debug.h" /* ?? temporaire, requis par netlist.h */
27 #include "input_netlist.h"
28 #include "decoder_fifo.h"
30 #include "video_output.h"
32 #include "vdec_idct.h"
33 #include "video_decoder.h"
34 #include "vdec_motion.h"
36 #include "vpar_blocks.h"
37 #include "vpar_headers.h"
38 #include "video_fifo.h"
39 #include "vpar_synchro.h"
40 #include "video_parser.h"
45 static __inline__ void NextStartCode( vpar_thread_t * p_vpar );
46 static void SequenceHeader( vpar_thread_t * p_vpar );
47 static void GroupHeader( vpar_thread_t * p_vpar );
48 static void PictureHeader( vpar_thread_t * p_vpar );
49 static void SliceHeader00( vpar_thread_t * p_vpar,
50 int * pi_mb_address, int i_mb_base,
52 static void SliceHeader01( vpar_thread_t * p_vpar,
53 int * pi_mb_address, int i_mb_base,
55 static void SliceHeader10( vpar_thread_t * p_vpar,
56 int * pi_mb_address, int i_mb_base,
58 static void SliceHeader11( vpar_thread_t * p_vpar,
59 int * pi_mb_address, int i_mb_base,
61 static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
62 int * pi_mb_address, int i_mb_base,
64 static void ExtensionAndUserData( vpar_thread_t * p_vpar );
65 static void QuantMatrixExtension( vpar_thread_t * p_vpar );
66 static void SequenceScalableExtension( vpar_thread_t * p_vpar );
67 static void SequenceDisplayExtension( vpar_thread_t * p_vpar );
68 static void PictureDisplayExtension( vpar_thread_t * p_vpar );
69 static void PictureSpatialScalableExtension( vpar_thread_t * p_vpar );
70 static void PictureTemporalScalableExtension( vpar_thread_t * p_vpar );
71 static void CopyrightExtension( vpar_thread_t * p_vpar );
74 * Local inline functions.
77 /*****************************************************************************
78 * NextStartCode : Find the next start code
79 *****************************************************************************/
80 static __inline__ void NextStartCode( vpar_thread_t * p_vpar )
82 /* Re-align the buffer on an 8-bit boundary */
83 RealignBits( &p_vpar->bit_stream );
85 while( ShowBits( &p_vpar->bit_stream, 24 ) != 0x01L && !p_vpar->b_die )
87 DumpBits( &p_vpar->bit_stream, 8 );
91 /*****************************************************************************
92 * ReferenceUpdate : Update the reference pointers when we have a new picture
93 *****************************************************************************/
94 static void __inline__ ReferenceUpdate( vpar_thread_t * p_vpar,
96 picture_t * p_newref )
98 if( i_coding_type != B_CODING_TYPE )
100 if( p_vpar->sequence.p_forward != NULL )
101 vout_UnlinkPicture( p_vpar->p_vout, p_vpar->sequence.p_forward );
102 p_vpar->sequence.p_forward = p_vpar->sequence.p_backward;
103 p_vpar->sequence.p_backward = p_newref;
104 if( p_newref != NULL )
105 vout_LinkPicture( p_vpar->p_vout, p_newref );
109 /*****************************************************************************
110 * ReferenceReplace : Replace the last reference pointer when we destroy
112 *****************************************************************************/
113 static void __inline__ ReferenceReplace( vpar_thread_t * p_vpar,
115 picture_t * p_newref )
117 if( i_coding_type != B_CODING_TYPE )
119 if( p_vpar->sequence.p_backward != NULL )
120 vout_UnlinkPicture( p_vpar->p_vout, p_vpar->sequence.p_backward );
121 p_vpar->sequence.p_backward = p_newref;
122 if( p_newref != NULL )
123 vout_LinkPicture( p_vpar->p_vout, p_newref );
127 /*****************************************************************************
128 * LoadMatrix : Load a quantization matrix
129 *****************************************************************************/
130 static __inline__ void LoadMatrix( vpar_thread_t * p_vpar, quant_matrix_t * p_matrix )
134 if( !p_matrix->b_allocated )
136 /* Allocate a piece of memory to load the matrix. */
137 p_matrix->pi_matrix = (int *)malloc( 64*sizeof(int) );
138 p_matrix->b_allocated = 1;
141 for( i_dummy = 0; i_dummy < 64; i_dummy++ )
143 p_matrix->pi_matrix[pi_scan[SCAN_ZIGZAG][i_dummy]]
144 = GetBits( &p_vpar->bit_stream, 8 );
148 /* Discrete Fourier Transform requires the quantization matrices to
149 * be normalized before using them. */
150 vdec_NormQuantMatrix( p_matrix->pi_matrix );
154 /*****************************************************************************
155 * LinkMatrix : Link a quantization matrix to another
156 *****************************************************************************/
157 static __inline__ void LinkMatrix( quant_matrix_t * p_matrix, int * pi_array )
161 if( p_matrix->b_allocated )
163 /* Deallocate the piece of memory. */
164 free( p_matrix->pi_matrix );
165 p_matrix->b_allocated = 0;
168 p_matrix->pi_matrix = pi_array;
172 * Exported functions.
175 /*****************************************************************************
176 * vpar_NextSequenceHeader : Find the next sequence header
177 *****************************************************************************/
178 int vpar_NextSequenceHeader( vpar_thread_t * p_vpar )
180 while( !p_vpar->b_die )
182 NextStartCode( p_vpar );
183 if( ShowBits( &p_vpar->bit_stream, 32 ) == SEQUENCE_HEADER_CODE )
189 /*****************************************************************************
190 * vpar_ParseHeader : Parse the next header
191 *****************************************************************************/
192 int vpar_ParseHeader( vpar_thread_t * p_vpar )
194 while( !p_vpar->b_die )
196 NextStartCode( p_vpar );
197 switch( GetBits32( &p_vpar->bit_stream ) )
199 case SEQUENCE_HEADER_CODE:
200 SequenceHeader( p_vpar );
204 case GROUP_START_CODE:
205 GroupHeader( p_vpar );
209 case PICTURE_START_CODE:
210 PictureHeader( p_vpar );
214 case SEQUENCE_END_CODE:
226 * Following functions are local
229 /*****************************************************************************
230 * SequenceHeader : Parse the next sequence header
231 *****************************************************************************/
232 static void SequenceHeader( vpar_thread_t * p_vpar )
235 static double d_frame_rate_table[16] =
238 ((23.0*1000.0)/1001.0),
241 ((30.0*1000.0)/1001.0),
244 ((60.0*1000.0)/1001.0),
246 RESERVED, RESERVED, RESERVED, RESERVED, RESERVED, RESERVED, RESERVED
250 int i_height_save, i_width_save;
252 i_height_save = p_vpar->sequence.i_height;
253 i_width_save = p_vpar->sequence.i_width;
255 p_vpar->sequence.i_height = GetBits( &p_vpar->bit_stream, 12 );
256 p_vpar->sequence.i_width = GetBits( &p_vpar->bit_stream, 12 );
257 p_vpar->sequence.i_aspect_ratio = GetBits( &p_vpar->bit_stream, 4 );
258 p_vpar->sequence.d_frame_rate =
259 d_frame_rate_table[ GetBits( &p_vpar->bit_stream, 4 ) ];
261 /* We don't need bit_rate_value, marker_bit, vbv_buffer_size,
262 * constrained_parameters_flag */
263 DumpBits( &p_vpar->bit_stream, 30 );
266 * Quantization matrices
268 if( GetBits( &p_vpar->bit_stream, 1 ) ) /* load_intra_quantizer_matrix */
270 LoadMatrix( p_vpar, &p_vpar->sequence.intra_quant );
274 /* Use default matrix. */
275 LinkMatrix( &p_vpar->sequence.intra_quant, pi_default_intra_quant );
278 if( GetBits( &p_vpar->bit_stream, 1 ) ) /* load_non_intra_quantizer_matrix */
280 LoadMatrix( p_vpar, &p_vpar->sequence.nonintra_quant );
284 /* Use default matrix. */
285 LinkMatrix( &p_vpar->sequence.nonintra_quant, pi_default_nonintra_quant );
288 /* Unless later overwritten by a matrix extension, we have the same
289 * matrices for luminance and chrominance. */
290 LinkMatrix( &p_vpar->sequence.chroma_intra_quant,
291 p_vpar->sequence.intra_quant.pi_matrix );
292 LinkMatrix( &p_vpar->sequence.chroma_nonintra_quant,
293 p_vpar->sequence.nonintra_quant.pi_matrix );
298 NextStartCode( p_vpar );
299 if( ShowBits( &p_vpar->bit_stream, 32 ) == EXTENSION_START_CODE )
302 static f_chroma_pattern_t ppf_chroma_pattern[4] =
303 {NULL, vpar_CodedPattern420,
304 vpar_CodedPattern422, vpar_CodedPattern444};
306 /* Parse sequence_extension */
307 DumpBits32( &p_vpar->bit_stream );
308 /* extension_start_code_identifier, profile_and_level_indication */
309 DumpBits( &p_vpar->bit_stream, 12 );
310 p_vpar->sequence.b_progressive = GetBits( &p_vpar->bit_stream, 1 );
311 p_vpar->sequence.i_chroma_format = GetBits( &p_vpar->bit_stream, 2 );
312 p_vpar->sequence.pf_decode_pattern = ppf_chroma_pattern
313 [p_vpar->sequence.i_chroma_format];
314 p_vpar->sequence.i_width |= GetBits( &p_vpar->bit_stream, 2 ) << 12;
315 p_vpar->sequence.i_height |= GetBits( &p_vpar->bit_stream, 2 ) << 12;
316 /* bit_rate_extension, marker_bit, vbv_buffer_size_extension, low_delay */
317 DumpBits( &p_vpar->bit_stream, 22 );
318 /* frame_rate_extension_n */
319 i_dummy = GetBits( &p_vpar->bit_stream, 2 );
320 /* frame_rate_extension_d */
321 p_vpar->sequence.d_frame_rate *= (i_dummy + 1)
322 / (GetBits( &p_vpar->bit_stream, 5 ) + 1);
324 p_vpar->sequence.pf_decode_mv = vpar_MPEG2MotionVector;
328 /* It's an MPEG-1 stream. Put adequate parameters. */
329 p_vpar->sequence.b_progressive = 1;
330 p_vpar->sequence.i_chroma_format = CHROMA_420;
331 p_vpar->sequence.pf_decode_pattern = vpar_CodedPattern420;
333 p_vpar->sequence.pf_decode_mv = vpar_MPEG1MotionVector;
337 p_vpar->sequence.i_mb_width = (p_vpar->sequence.i_width + 15) / 16;
338 p_vpar->sequence.i_mb_height = (p_vpar->sequence.b_progressive) ?
339 (p_vpar->sequence.i_height + 15) / 16 :
340 2 * (p_vpar->sequence.i_height + 31) / 32;
341 p_vpar->sequence.i_mb_size = p_vpar->sequence.i_mb_width
342 * p_vpar->sequence.i_mb_height;
343 p_vpar->sequence.i_width = (p_vpar->sequence.i_mb_width * 16);
344 p_vpar->sequence.i_height = (p_vpar->sequence.i_mb_height * 16);
345 p_vpar->sequence.i_size = p_vpar->sequence.i_width
346 * p_vpar->sequence.i_height;
348 /* Update chromatic information */
349 switch( p_vpar->sequence.i_chroma_format )
352 p_vpar->sequence.i_chroma_nb_blocks = 2;
353 p_vpar->sequence.i_chroma_width = p_vpar->sequence.i_width >> 2;
354 p_vpar->i_chroma_mb_width = 8;
355 p_vpar->i_chroma_mb_height = 8;
359 p_vpar->sequence.i_chroma_nb_blocks = 4;
360 p_vpar->sequence.i_chroma_width = p_vpar->sequence.i_width >> 1;
361 p_vpar->i_chroma_mb_width = 8;
362 p_vpar->i_chroma_mb_height = 16;
366 p_vpar->sequence.i_chroma_nb_blocks = 8;
367 p_vpar->sequence.i_chroma_width = p_vpar->sequence.i_width;
368 p_vpar->i_chroma_mb_width = 16;
369 p_vpar->i_chroma_mb_height = 16;
372 /* Slice Header functions */
373 if( p_vpar->sequence.i_height <= 2800 )
375 if( p_vpar->sequence.i_scalable_mode != SC_DP )
377 p_vpar->sequence.pf_slice_header = SliceHeader00;
381 p_vpar->sequence.pf_slice_header = SliceHeader01;
386 if( p_vpar->sequence.i_scalable_mode != SC_DP )
388 p_vpar->sequence.pf_slice_header = SliceHeader10;
392 p_vpar->sequence.pf_slice_header = SliceHeader11;
396 if( p_vpar->sequence.i_width != i_width_save
397 || p_vpar->sequence.i_height != i_height_save )
399 /* What do we do in case of a size change ??? */
402 /* Extension and User data */
403 ExtensionAndUserData( p_vpar );
406 /*****************************************************************************
407 * GroupHeader : Parse the next group of pictures header
408 *****************************************************************************/
409 static void GroupHeader( vpar_thread_t * p_vpar )
411 /* Nothing to do, we don't care. */
412 DumpBits( &p_vpar->bit_stream, 27 );
413 ExtensionAndUserData( p_vpar );
416 /*****************************************************************************
417 * PictureHeader : Parse the next picture header
418 *****************************************************************************/
419 static void PictureHeader( vpar_thread_t * p_vpar )
421 static f_macroblock_type_t ppf_macroblock_type[4] =
422 {vpar_IMBType, vpar_PMBType,
423 vpar_BMBType, vpar_DMBType};
426 int i_mb_address, i_mb_base, i_mb;
427 elem_t * p_y, p_u, p_v;
428 boolean_t b_parsable;
431 DumpBits( &p_vpar->bit_stream, 10 ); /* temporal_reference */
432 p_vpar->picture.i_coding_type = GetBits( &p_vpar->bit_stream, 3 );
433 p_vpar->picture.pf_macroblock_type = ppf_macroblock_type
434 [p_vpar->picture.i_coding_type];
436 DumpBits( &p_vpar->bit_stream, 16 ); /* vbv_delay */
438 p_vpar->picture.b_full_pel_forward_vector = GetBits( &p_vpar->bit_stream, 1 );
439 p_vpar->picture.i_forward_f_code = GetBits( &p_vpar->bit_stream, 3 );
440 p_vpar->picture.b_full_pel_backward_vector = GetBits( &p_vpar->bit_stream, 1 );
441 p_vpar->picture.i_backward_f_code = GetBits( &p_vpar->bit_stream, 3 );
443 /* extra_information_picture */
444 while( GetBits( &p_vpar->bit_stream, 1 ) )
446 DumpBits( &p_vpar->bit_stream, 8 );
450 * Picture Coding Extension
452 NextStartCode( p_vpar );
453 if( ShowBits( &p_vpar->bit_stream, 32 ) == EXTENSION_START_CODE )
455 /* Parse picture_coding_extension */
456 DumpBits32( &p_vpar->bit_stream );
457 /* extension_start_code_identifier */
458 DumpBits( &p_vpar->bit_stream, 4 );
460 p_vpar->picture.ppi_f_code[0][0] = GetBits( &p_vpar->bit_stream, 4 );
461 p_vpar->picture.ppi_f_code[0][1] = GetBits( &p_vpar->bit_stream, 4 );
462 p_vpar->picture.ppi_f_code[1][0] = GetBits( &p_vpar->bit_stream, 4 );
463 p_vpar->picture.ppi_f_code[1][1] = GetBits( &p_vpar->bit_stream, 4 );
464 p_vpar->picture.i_intra_dc_precision = GetBits( &p_vpar->bit_stream, 2 );
465 i_structure = GetBits( &p_vpar->bit_stream, 2 );
466 p_vpar->picture.b_top_field_first = GetBits( &p_vpar->bit_stream, 1 );
467 p_vpar->picture.b_frame_pred_frame_dct
468 = GetBits( &p_vpar->bit_stream, 1 );
469 p_vpar->picture.b_concealment_mv = GetBits( &p_vpar->bit_stream, 1 );
470 p_vpar->picture.b_q_scale_type = GetBits( &p_vpar->bit_stream, 1 );
471 p_vpar->picture.b_intra_vlc_format = GetBits( &p_vpar->bit_stream, 1 );
472 p_vpar->picture.b_alternate_scan = GetBits( &p_vpar->bit_stream, 1 );
473 p_vpar->picture.b_repeat_first_field = GetBits( &p_vpar->bit_stream, 1 );
474 /* repeat_first_field (ISO/IEC 13818-2 6.3.10 is necessary to know
475 * the length of the picture_display_extension structure.
476 * chroma_420_type (obsolete) */
477 DumpBits( &p_vpar->bit_stream, 1 );
478 p_vpar->picture.b_progressive_frame = GetBits( &p_vpar->bit_stream, 1 );
480 /* composite_display_flag */
481 if( GetBits( &p_vpar->bit_stream, 1 ) )
483 /* v_axis, field_sequence, sub_carrier, burst_amplitude,
484 * sub_carrier_phase */
485 DumpBits( &p_vpar->bit_stream, 20 );
490 /* MPEG-1 compatibility flags */
491 p_vpar->picture.i_intra_dc_precision = 0; /* 8 bits */
492 i_structure = FRAME_STRUCTURE;
493 p_vpar->picture.b_frame_pred_frame_dct = 1;
494 p_vpar->picture.b_concealment_mv = 0;
495 p_vpar->picture.b_q_scale_type = 0;
496 p_vpar->picture.b_intra_vlc_format = 0;
497 p_vpar->picture.b_alternate_scan = 0; /* zigzag */
498 p_vpar->picture.b_repeat_first_field = 0;
499 p_vpar->picture.b_progressive_frame = 1;
502 if( p_vpar->picture.i_current_structure &&
503 (i_structure == FRAME_STRUCTURE ||
504 i_structure == p_vpar->picture.i_current_structure) )
506 /* We don't have the second field of the buffered frame. */
507 if( p_vpar->picture.p_picture != NULL )
509 ReferenceReplace( p_vpar,
510 p_vpar->picture.i_coding_type,
513 for( i_mb = 0; i_mb < p_vpar->sequence.i_mb_size >> 1; i_mb++ )
515 vpar_DestroyMacroblock( &p_vpar->vfifo,
516 p_vpar->picture.pp_mb[i_mb] );
518 vout_DestroyPicture( p_vpar->p_vout, p_vpar->picture.p_picture );
521 p_vpar->picture.i_current_structure = 0;
523 intf_DbgMsg("vpar debug: odd number of field picture.");
526 if( p_vpar->picture.i_current_structure )
528 /* Second field of a frame. We will decode it if, and only if we
529 * have decoded the first frame. */
530 b_parsable = (p_vpar->picture.p_picture != NULL);
534 /* Do we have the reference pictures ? */
535 b_parsable = !((p_vpar->picture.i_coding_type == P_CODING_TYPE) &&
536 (p_vpar->sequence.p_forward == NULL)) ||
537 ((p_vpar->picture.i_coding_type == B_CODING_TYPE) &&
538 (p_vpar->sequence.p_forward == NULL ||
539 p_vpar->sequence.p_backward == NULL));
543 /* Does synchro say we have enough time to decode it ? */
544 b_parsable = vpar_SynchroChoose( p_vpar,
545 p_vpar->picture.i_coding_type, i_structure );
551 /* Update the reference pointers. */
552 ReferenceUpdate( p_vpar, p_vpar->picture.i_coding_type, NULL );
554 /* Warn Synchro we have trashed a picture. */
555 vpar_SynchroTrash( p_vpar, p_vpar->picture.i_coding_type, i_structure );
557 /* Update context. */
558 if( i_structure != FRAME_STRUCTURE )
559 p_vpar->picture.i_current_structure = i_structure;
560 p_vpar->picture.p_picture = NULL;
565 /* OK, now we are sure we will decode the picture. */
566 #define P_picture p_vpar->picture.p_picture
567 p_vpar->picture.b_error = 0;
569 if( !p_vpar->picture.i_current_structure )
571 /* This is a new frame. Get a structure from the video_output. */
572 P_picture = vout_CreatePicture( p_vpar->p_vout,
573 SPLITTED_YUV_PICTURE,
574 p_vpar->sequence.i_width,
575 p_vpar->sequence.i_height,
576 p_vpar->sequence.i_chroma_format );
578 /* Initialize values. */
579 P_picture->date = vpar_SynchroDecode( p_vpar,
580 p_vpar->picture.i_coding_type,
582 p_vpar->picture.i_l_stride = - 8 + ( p_vpar->sequence.i_width
583 << ( 1 - p_vpar->picture.b_frame_structure ) );
584 p_vpar->picture.i_c_stride = -8 + ( p_vpar->sequence.i_width
585 << (( 1 - p_vpar->picture.b_frame_structure ) +
586 ( 3 - p_vpar->sequence.i_chroma_format )) );
588 /* Update the reference pointers. */
589 ReferenceUpdate( p_vpar, p_vpar->picture.i_coding_type, P_picture );
591 p_vpar->picture.i_current_structure |= i_structure;
592 p_vpar->picture.i_structure = i_structure;
593 p_vpar->picture.b_frame_structure = (i_structure == FRAME_STRUCTURE);
595 /* Initialize picture data for decoding. */
596 if( i_structure == BOTTOM_FIELD )
598 i_mb_base = p_vpar->sequence.i_mb_size >> 1;
599 p_vpar->mb.i_l_y = 16;
600 p_vpar->mb.i_c_y = p_vpar->sequence.i_chroma_mb_height;
605 p_vpar->mb.i_l_y = p_vpar->mb.i_c_y = 0;
608 p_vpar->mb.i_l_x = p_vpar->mb.i_c_x = 0;
610 /* Extension and User data. */
611 ExtensionAndUserData( p_vpar );
613 /* Picture data (ISO/IEC 13818-2 6.2.3.7). */
614 NextStartCode( p_vpar );
615 while( i_mb_address+i_mb_base < p_vpar->sequence.i_mb_size
616 && !p_vpar->picture.b_error)
618 if( ((i_dummy = ShowBits( &p_vpar->bit_stream, 32 ))
619 < SLICE_START_CODE_MIN) ||
620 (i_dummy > SLICE_START_CODE_MAX) )
622 intf_DbgMsg("vpar debug: premature end of picture");
623 p_vpar->picture.b_error = 1;
626 DumpBits32( &p_vpar->bit_stream );
628 /* Decode slice data. */
629 SliceHeader( p_vpar, &i_mb_address, i_mb_base, i_dummy & 255 );
632 if( p_vpar->picture.b_error )
635 for( i_mb = 0; p_vpar->picture.pp_mb[i_mb]; i_mb++ )
637 vpar_DestroyMacroblock( &p_vpar->vfifo, p_vpar->picture.pp_mb[i_mb] );
640 ReferenceReplace( p_vpar, p_vpar->picture.i_coding_type, NULL );
641 vout_DestroyPicture( p_vpar->p_vout, P_picture );
643 /* Prepare context for the next picture. */
646 else if( p_vpar->picture.i_current_structure == FRAME_STRUCTURE )
648 /* Frame completely parsed. */
649 P_picture.i_deccount = p_vpar->sequence.i_mb_size;
650 for( i_mb = 0; i_mb < p_vpar->sequence.i_mb_size; i_mb++ )
652 vpar_DecodeMacroblock( &p_vpar->vfifo, p_vpar->picture.pp_mb[i_mb] );
655 /* Prepare context for the next picture. */
661 /*****************************************************************************
662 * SliceHeader : Parse the next slice structure
663 *****************************************************************************/
664 static __inline__ void SliceHeader( vpar_thread_t * p_vpar,
665 int * pi_mb_address, int i_mb_base,
668 /* DC predictors initialization table */
669 static int pi_dc_dct_reinit[4] = {128,256,512,1024};
671 int i_mb_address_save = *pi_mb_address;
673 /* slice_vertical_position_extension and priority_breakpoint already done */
674 LoadQuantizerScale( p_vpar );
676 if( GetBits( &p_vpar->bit_stream, 1 ) )
678 /* intra_slice, slice_id */
679 DumpBits( &p_vpar->bit_stream, 8 );
680 /* extra_information_slice */
681 while( GetBits( &p_vpar->bit_stream, 1 ) )
683 DumpBits( &p_vpar->bit_stream, 8 );
687 *pi_mb_address = (i_vert_code - 1)*p_vpar->sequence.i_mb_width;
689 /* Reset DC coefficients predictors (ISO/IEC 13818-2 7.2.1). Why
690 * does the reference decoder put 0 instead of the normative values ? */
691 p_vpar->slice.pi_dc_dct_pred[0] = p_vpar->slice.pi_dc_dct_pred[1]
692 = p_vpar->slice.pi_dc_dct_pred[2]
693 = pi_dc_dct_reinit[p_vpar->picture.i_intra_dc_precision];
695 /* Reset motion vector predictors (ISO/IEC 13818-2 7.6.3.4). */
696 memset( p_vpar->slice.pppi_pmv, 0, 8*sizeof(int) );
700 vpar_ParseMacroblock( p_vpar, pi_mb_address, i_mb_address_save,
702 i_mb_address_save = *pi_mb_address;
704 while( !ShowBits( &p_vpar->bit_stream, 23 ) );
707 /*****************************************************************************
708 * SliceHeaderXY : Parse the next slice structure
709 *****************************************************************************
710 * X = i_height > 2800 ?
711 * Y = scalable_mode == SC_DP ?
712 *****************************************************************************/
713 static void SliceHeader00( vpar_thread_t * p_vpar,
714 int * pi_mb_address, int i_mb_base,
717 SliceHeader( p_vpar, pi_mb_address, i_mb_base, i_vert_code );
720 static void SliceHeader01( vpar_thread_t * p_vpar,
721 int * pi_mb_address, int i_mb_base,
724 DumpBits( &p_vpar->bit_stream, 7 ); /* priority_breakpoint */
725 SliceHeader( p_vpar, pi_mb_address, i_mb_base, i_vert_code );
728 static void SliceHeader10( vpar_thread_t * p_vpar,
729 int * pi_mb_address, int i_mb_base,
732 i_vert_code += GetBits( &p_vpar->bit_stream, 3 ) << 7;
733 SliceHeader( p_vpar, pi_mb_address, i_mb_base, i_vert_code );
736 static void SliceHeader11( vpar_thread_t * p_vpar,
737 int * pi_mb_address, int i_mb_base,
740 i_vert_code += GetBits( &p_vpar->bit_stream, 3 ) << 7;
741 DumpBits( &p_vpar->bit_stream, 7 ); /* priority_breakpoint */
742 SliceHeader( p_vpar, pi_mb_address, i_mb_base, i_vert_code );
745 /*****************************************************************************
746 * ExtensionAndUserData : Parse the extension_and_user_data structure
747 *****************************************************************************/
748 static void ExtensionAndUserData( vpar_thread_t * p_vpar )
750 while( !p_vpar->b_die )
752 NextStartCode( p_vpar );
753 switch( ShowBits( &p_vpar->bit_stream, 32 ) )
755 case EXTENSION_START_CODE:
756 DumpBits32( &p_vpar->bit_stream );
757 switch( GetBits( &p_vpar->bit_stream, 4 ) )
759 case SEQUENCE_DISPLAY_EXTENSION_ID:
760 SequenceDisplayExtension( p_vpar );
762 case QUANT_MATRIX_EXTENSION_ID:
763 QuantMatrixExtension( p_vpar );
765 case SEQUENCE_SCALABLE_EXTENSION_ID:
766 SequenceScalableExtension( p_vpar );
768 case PICTURE_DISPLAY_EXTENSION_ID:
769 PictureDisplayExtension( p_vpar );
771 case PICTURE_SPATIAL_SCALABLE_EXTENSION_ID:
772 PictureSpatialScalableExtension( p_vpar );
774 case PICTURE_TEMPORAL_SCALABLE_EXTENSION_ID:
775 PictureTemporalScalableExtension( p_vpar );
777 case COPYRIGHT_EXTENSION_ID:
778 CopyrightExtension( p_vpar );
784 case USER_DATA_START_CODE:
785 DumpBits32( &p_vpar->bit_stream );
786 /* Wait for the next start code */
796 /*****************************************************************************
797 * SequenceDisplayExtension : Parse the sequence_display_extension structure *
798 *****************************************************************************/
800 static void SequenceDisplayExtension( vpar_thread_t * p_vpar )
802 /* We don't care sequence_display_extension. */
804 DumpBits( &p_vpar->bit_stream, 3 );
805 if( GetBits( &p_vpar->bit_stream, 1 ) )
807 /* Three bytes for color_desciption */
808 DumpBits( &p_vpar->bit_stream, 24 );
810 /* display_horizontal and vertical_size and a marker_bit */
811 DumpBits( &p_vpar->bit_stream, 29 );
815 /*****************************************************************************
816 * QuantMatrixExtension : Load quantization matrices for luminance *
818 *****************************************************************************/
820 static void QuantMatrixExtension( vpar_thread_t * p_vpar )
822 if( GetBits( &p_vpar->bit_stream, 1 ) )
824 /* Load intra_quantiser_matrix for luminance. */
825 LoadMatrix( p_vpar, &p_vpar->sequence.intra_quant );
829 /* Use the default matrix. */
830 LinkMatrix( &p_vpar->sequence.intra_quant,
831 pi_default_intra_quant );
833 if( GetBits( &p_vpar->bit_stream, 1 ) )
835 /* Load non_intra_quantiser_matrix for luminance. */
836 LoadMatrix( p_vpar, &p_vpar->sequence.nonintra_quant );
840 /* Use the default matrix. */
841 LinkMatrix( &p_vpar->sequence.nonintra_quant,
842 pi_default_nonintra_quant );
844 if( GetBits( &p_vpar->bit_stream, 1 ) )
846 /* Load intra_quantiser_matrix for chrominance. */
847 LoadMatrix( p_vpar, &p_vpar->sequence.chroma_intra_quant );
851 /* Link the chrominance intra matrix to the luminance one. */
852 LinkMatrix( &p_vpar->sequence.chroma_intra_quant,
853 p_vpar->sequence.intra_quant.pi_matrix );
855 if( GetBits( &p_vpar->bit_stream, 1 ) )
857 /* Load non_intra_quantiser_matrix for chrominance. */
858 LoadMatrix( p_vpar, &p_vpar->sequence.chroma_nonintra_quant );
862 /* Link the chrominance intra matrix to the luminance one. */
863 LinkMatrix( &p_vpar->sequence.chroma_intra_quant,
864 p_vpar->sequence.intra_quant.pi_matrix );
866 if( GetBits( &p_vpar->bit_stream, 1 ) )
868 /* Load non_intra_quantiser_matrix for chrominance. */
869 LoadMatrix( p_vpar, &p_vpar->sequence.chroma_nonintra_quant );
873 /* Link the chrominance nonintra matrix to the luminance one. */
874 LinkMatrix( &p_vpar->sequence.chroma_nonintra_quant,
875 p_vpar->sequence.nonintra_quant.pi_matrix );
880 /*****************************************************************************
881 * SequenceScalableExtension : Parse the sequence_scalable_extension *
882 * structure to handle scalable coding *
883 *****************************************************************************/
885 static void SequenceScalableExtension( vpar_thread_t * p_vpar )
887 /* We don't care about anything scalable except the scalable mode. */
888 switch( p_vpar->sequence.i_scalable_mode = GetBits( &p_vpar->bit_stream, 2 ) )
889 /* The length of the structure depends on the value of the scalable_mode */
892 DumpBits32( &p_vpar->bit_stream );
893 DumpBits( &p_vpar->bit_stream, 21 );
896 DumpBits( &p_vpar->bit_stream, 12 );
899 DumpBits( &p_vpar->bit_stream, 4 );
903 /*****************************************************************************
904 * PictureDisplayExtension : Parse the picture_display_extension structure *
905 *****************************************************************************/
907 static void PictureDisplayExtension( vpar_thread_t * p_vpar )
909 /* Number of frame center offset */
911 /* I am not sure it works but it should
912 (fewer tests than shown in ยง6.3.12) */
913 nb = p_vpar->sequence.b_progressive ? p_vpar->sequence.b_progressive +
914 p_vpar->picture.b_repeat_first_field +
915 p_vpar->picture.b_top_field_first
916 : ( p_vpar->picture.b_frame_structure + 1 ) +
917 p_vpar->picture.b_repeat_first_field;
918 DumpBits( &p_vpar->bit_stream, 34 * nb );
922 /*****************************************************************************
923 * PictureSpatialScalableExtension *
924 *****************************************************************************/
926 static void PictureSpatialScalableExtension( vpar_thread_t * p_vpar )
928 /* That's scalable, so we trash it */
929 DumpBits32( &p_vpar->bit_stream );
930 DumpBits( &p_vpar->bit_stream, 14 );
934 /*****************************************************************************
935 * PictureTemporalScalableExtension *
936 *****************************************************************************/
938 static void PictureTemporalScalableExtension( vpar_thread_t * p_vpar )
940 /* Scalable again, trashed again */
941 DumpBits( &p_vpar->bit_stream, 23 );
945 /*****************************************************************************
946 * CopyrightExtension : Keeps some legal informations *
947 *****************************************************************************/
949 static void CopyrightExtension( vpar_thread_t * p_vpar )
951 u32 i_copyright_nb_1, i_copyright_nb_2; /* local integers */
952 p_vpar->sequence.b_copyright_flag = GetBits( &p_vpar->bit_stream, 1 );
953 /* A flag that says whether the copyright information is significant */
954 p_vpar->sequence.i_copyright_id = GetBits( &p_vpar->bit_stream, 8 );
955 /* An identifier compliant with ISO/CEI JTC 1/SC 29 */
956 p_vpar->sequence.b_original = GetBits( &p_vpar->bit_stream, 1 );
958 DumpBits( &p_vpar->bit_stream, 8 );
959 /* The copyright_number is split in three parts */
961 i_copyright_nb_1 = GetBits( &p_vpar->bit_stream, 20 );
962 DumpBits( &p_vpar->bit_stream, 1 );
964 i_copyright_nb_2 = GetBits( &p_vpar->bit_stream, 22 );
965 DumpBits( &p_vpar->bit_stream, 1 );
966 /* third part and sum */
967 p_vpar->sequence.i_copyright_nb = ( (u64)i_copyright_nb_1 << 44 ) +
968 ( (u64)i_copyright_nb_2 << 22 ) +
969 ( (u64)GetBits( &p_vpar->bit_stream, 22 ) );