1 /*****************************************************************************
2 * vpar_blocks.c : blocks parsing
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: vpar_blocks.c,v 1.1 2001/11/13 12:09:18 henri Exp $
7 * Authors: Michel Lespinasse <walken@zoy.org>
8 * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
9 * Christophe Massiot <massiot@via.ecp.fr>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
31 #include <string.h> /* memset */
40 #include "video_output.h"
42 #include "modules_export.h"
43 #include "stream_control.h"
44 #include "input_ext-dec.h"
47 #include "vdec_ext-plugins.h"
48 #include "vpar_pool.h"
49 #include "video_parser.h"
51 #include "vpar_blocks.h"
54 * Welcome to vpar_blocks.c ! Here's where the heavy processor-critical parsing
55 * task is done. This file is divided in several parts :
56 * - Decoding of coded blocks
57 * - Decoding of motion vectors
58 * - Decoding of the other macroblock structures
59 * - Picture data parsing management (slices and error handling)
60 * It's a pretty long file. Good luck and have a nice day.
64 /*****************************************************************************
65 * vpar_InitScanTable : Initialize scan table
66 *****************************************************************************/
67 void vpar_InitScanTable( vpar_thread_t * p_vpar )
71 memcpy( p_vpar->ppi_scan, pi_scan, sizeof(pi_scan) );
72 p_vpar->pf_norm_scan( p_vpar->ppi_scan );
74 /* If scan table has changed, we must change the quantization matrices. */
75 for( i = 0; i < 64; i++ )
77 p_vpar->pi_default_intra_quant[ p_vpar->ppi_scan[0][i] ] =
78 pi_default_intra_quant[ pi_scan[0][i] ];
79 p_vpar->pi_default_nonintra_quant[ p_vpar->ppi_scan[0][i] ] =
80 pi_default_nonintra_quant[ pi_scan[0][i] ];
89 /*****************************************************************************
90 * GetLumaDCDiff : Get the luminance DC coefficient difference
91 *****************************************************************************/
92 static __inline__ int GetLumaDCDiff( vpar_thread_t * p_vpar )
95 int i_size, i_dc_diff, i_code;
97 if( (i_code = ShowBits( &p_vpar->bit_stream, 5 )) < 0x1F )
99 p_tab = DC_lum_5 + i_code;
100 i_size = p_tab->i_value;
103 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
104 i_dc_diff = GetBits( &p_vpar->bit_stream, i_size );
105 if ((i_dc_diff & (1 << (i_size - 1))) == 0)
107 i_dc_diff -= (1 << i_size) - 1;
113 RemoveBits( &p_vpar->bit_stream, 3 );
119 p_tab = DC_long - 0x1e0 + ShowBits( &p_vpar->bit_stream, 9 );
120 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
121 i_size = p_tab->i_value;
122 i_dc_diff = GetBits( &p_vpar->bit_stream, i_size );
123 if ((i_dc_diff & (1 << (i_size - 1))) == 0)
125 i_dc_diff -= (1 << i_size) - 1;
131 /*****************************************************************************
132 * GetChromaDCDiff : Get the chrominance DC coefficient difference
133 *****************************************************************************/
134 static __inline__ int GetChromaDCDiff( vpar_thread_t * p_vpar )
137 int i_size, i_dc_diff, i_code;
139 if( (i_code = ShowBits( &p_vpar->bit_stream, 5 )) < 0x1F )
141 p_tab = DC_chrom_5 + i_code;
142 i_size = p_tab->i_value;
145 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
146 i_dc_diff = GetBits( &p_vpar->bit_stream, i_size );
147 if ((i_dc_diff & (1 << (i_size - 1))) == 0)
149 i_dc_diff -= (1 << i_size) - 1;
155 RemoveBits( &p_vpar->bit_stream, 2 );
161 p_tab = DC_long - 0x3e0 + ShowBits( &p_vpar->bit_stream, 10 );
162 RemoveBits( &p_vpar->bit_stream, p_tab->i_length + 1 );
163 i_size = p_tab->i_value;
164 i_dc_diff = GetBits( &p_vpar->bit_stream, i_size );
165 if ((i_dc_diff & (1 << (i_size - 1))) == 0)
167 i_dc_diff -= (1 << i_size) - 1;
174 #define SATURATE(val) \
175 if ((u32)(val + 2048) > 4095) \
177 val = (val > 0) ? 2047 : -2048; \
180 /*****************************************************************************
181 * MPEG2IntraB14 : Decode an intra block according to ISO/IEC 13818-2 table B14
182 *****************************************************************************/
183 static void MPEG2IntraB14( vpar_thread_t * p_vpar, idct_inner_t * p_idct,
186 int i_coeff, i_mismatch, i_code, i_pos, i_value, i_nc;
188 dct_lookup_t * p_tab;
190 int i_q_scale = p_vpar->mb.i_quantizer_scale;
191 dctelem_t * p_dest = p_idct->pi_block;
192 u8 * p_scan = p_vpar->picture.pi_scan;
195 i_mismatch = ~p_dest[0];
196 i_nc = (p_dest[0] != 0);
200 if( (i_code = ShowBits( &p_vpar->bit_stream, 5 )) >= 0x5 )
202 p_tab = DCT_B14AC_5 - 5 + i_code;
203 i_coeff += p_tab->i_run;
212 i_pos = p_scan[ i_coeff ];
213 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
214 i_value = (p_tab->i_level * i_q_scale * pi_quant[i_pos])
217 i_sign = GetSignedBits( &p_vpar->bit_stream, 1 );
218 /* if (i_sign) i_value = -i_value; */
219 i_value = (i_value ^ i_sign) - i_sign;
222 p_dest[i_pos] = i_value;
223 i_mismatch ^= i_value;
227 else if( (i_code = ShowBits( &p_vpar->bit_stream, 8 )) >= 0x4 )
229 p_tab = DCT_B14_8 - 4 + i_code;
230 i_coeff += p_tab->i_run;
233 /* Normal coefficient */
238 i_coeff += (GetBits( &p_vpar->bit_stream, 12 ) & 0x3F) - 64;
241 /* Illegal, but needed to avoid overflow */
242 intf_WarnMsg( 2, "Intra-B14 coeff is out of bound" );
243 p_vpar->picture.b_error = 1;
248 i_pos = p_scan[i_coeff];
249 i_value = (GetSignedBits( &p_vpar->bit_stream, 12 )
250 * i_q_scale * pi_quant[i_pos]) / 16;
253 p_dest[i_pos] = i_value;
254 i_mismatch ^= i_value;
257 else if( (i_code = ShowBits( &p_vpar->bit_stream, 16)) >= 0x0200 )
259 p_tab = DCT_B14_10 - 8 + (i_code >> 6);
260 i_coeff += p_tab->i_run;
266 else if( i_code >= 0x0080 )
268 p_tab = DCT_13 - 16 + (i_code >> 3);
269 i_coeff += p_tab->i_run;
275 else if( i_code >= 0x0020 )
277 p_tab = DCT_15 - 16 + (i_code >> 1);
278 i_coeff += p_tab->i_run;
286 p_tab = DCT_16 + i_code;
287 i_coeff += p_tab->i_run;
294 intf_WarnMsg( 2, "Intra-B14 coeff is out of bound" );
295 p_vpar->picture.b_error = 1;
299 p_dest[63] ^= i_mismatch & 1;
300 RemoveBits( &p_vpar->bit_stream, 2 ); /* End of Block */
308 p_idct->pf_idct = p_vpar->pf_sparse_idct_copy;
309 p_idct->i_sparse_pos = 63;
313 p_idct->pf_idct = p_vpar->pf_idct_copy;
318 p_idct->pf_idct = p_vpar->pf_sparse_idct_copy;
319 p_idct->i_sparse_pos = i_coeff - p_tab->i_run;
324 p_idct->pf_idct = p_vpar->pf_idct_copy;
328 /*****************************************************************************
329 * MPEG2IntraB15 : Decode an intra block according to ISO/IEC 13818-2 table B15
330 *****************************************************************************/
331 static void MPEG2IntraB15( vpar_thread_t * p_vpar, idct_inner_t * p_idct,
334 int i_coeff, i_mismatch, i_code, i_pos, i_value, i_nc;
336 dct_lookup_t * p_tab;
338 int i_q_scale = p_vpar->mb.i_quantizer_scale;
339 dctelem_t * p_dest = p_idct->pi_block;
340 u8 * p_scan = p_vpar->picture.pi_scan;
343 i_mismatch = ~p_dest[0];
344 i_nc = (p_dest[0] != 0);
348 if( (i_code = ShowBits( &p_vpar->bit_stream, 8 )) >= 0x4 )
350 p_tab = DCT_B15_8 - 4 + i_code;
351 i_coeff += p_tab->i_run;
357 i_pos = p_scan[ i_coeff ];
358 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
359 i_value = (p_tab->i_level * i_q_scale * pi_quant[i_pos])
362 i_sign = GetSignedBits( &p_vpar->bit_stream, 1 );
363 /* if (i_sign) i_value = -i_value; */
364 i_value = (i_value ^ i_sign) - i_sign;
367 p_dest[i_pos] = i_value;
368 i_mismatch ^= i_value;
381 i_coeff += (GetBits( &p_vpar->bit_stream, 12 ) & 0x3F) - 64;
384 /* Illegal, but needed to avoid overflow */
385 intf_WarnMsg( 2, "Intra-B15 coeff is out of bound" );
386 p_vpar->picture.b_error = 1;
391 i_pos = p_scan[i_coeff];
392 i_value = (GetSignedBits( &p_vpar->bit_stream, 12 )
393 * i_q_scale * pi_quant[i_pos]) / 16;
396 p_dest[i_pos] = i_value;
397 i_mismatch ^= i_value;
401 else if( (i_code = ShowBits( &p_vpar->bit_stream, 16)) >= 0x0200 )
403 p_tab = DCT_B15_10 - 8 + (i_code >> 6);
404 i_coeff += p_tab->i_run;
410 else if( i_code >= 0x0080 )
412 p_tab = DCT_13 - 16 + (i_code >> 3);
413 i_coeff += p_tab->i_run;
419 else if( i_code >= 0x0020 )
421 p_tab = DCT_15 - 16 + (i_code >> 1);
422 i_coeff += p_tab->i_run;
430 p_tab = DCT_16 + i_code;
431 i_coeff += p_tab->i_run;
438 intf_WarnMsg( 2, "Intra-B15 coeff is out of bound" );
439 p_vpar->picture.b_error = 1;
443 p_dest[63] ^= i_mismatch & 1;
444 RemoveBits( &p_vpar->bit_stream, 4 ); /* End of Block */
452 p_idct->pf_idct = p_vpar->pf_sparse_idct_copy;
453 p_idct->i_sparse_pos = 63;
457 p_idct->pf_idct = p_vpar->pf_idct_copy;
462 p_idct->pf_idct = p_vpar->pf_sparse_idct_copy;
463 p_idct->i_sparse_pos = i_coeff - p_tab->i_run;
468 p_idct->pf_idct = p_vpar->pf_idct_copy;
472 /*****************************************************************************
473 * MPEG2NonIntra : Decode a non-intra MPEG-2 block
474 *****************************************************************************/
475 static void MPEG2NonIntra( vpar_thread_t * p_vpar, idct_inner_t * p_idct,
478 int i_coeff, i_mismatch, i_code, i_pos, i_value, i_nc;
480 dct_lookup_t * p_tab;
482 int i_q_scale = p_vpar->mb.i_quantizer_scale;
483 dctelem_t * p_dest = p_idct->pi_block;
484 u8 * p_scan = p_vpar->picture.pi_scan;
490 if( (i_code = ShowBits( &p_vpar->bit_stream, 5 )) >= 0x5 )
492 p_tab = DCT_B14DC_5 - 5 + i_code;
502 if( (i_code = ShowBits( &p_vpar->bit_stream, 5 )) >= 0x5 )
504 p_tab = DCT_B14AC_5 - 5 + i_code;
506 i_coeff += p_tab->i_run;
515 i_pos = p_scan[ i_coeff ];
516 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
517 i_value = ((2 * p_tab->i_level + 1) * i_q_scale * pi_quant[i_pos])
520 i_sign = GetSignedBits( &p_vpar->bit_stream, 1 );
521 /* if (i_sign) i_value = -i_value; */
522 i_value = (i_value ^ i_sign) - i_sign;
525 p_dest[i_pos] = i_value;
526 i_mismatch ^= i_value;
531 if( (i_code = ShowBits( &p_vpar->bit_stream, 8 )) >= 0x4 )
533 p_tab = DCT_B14_8 - 4 + i_code;
534 i_coeff += p_tab->i_run;
537 /* Normal coefficient */
542 i_coeff += (GetBits( &p_vpar->bit_stream, 12 ) & 0x3F) - 64;
545 /* Illegal, but needed to avoid overflow */
546 intf_WarnMsg( 2, "MPEG2NonIntra coeff is out of bound" );
547 p_vpar->picture.b_error = 1;
552 i_pos = p_scan[i_coeff];
553 i_value = 2 * (ShowSignedBits( &p_vpar->bit_stream, 1 )
554 + GetSignedBits( &p_vpar->bit_stream, 12 )) + 1;
556 i_value = (i_value * i_q_scale * pi_quant[i_pos]) / 32;
559 p_dest[i_pos] = i_value;
560 i_mismatch ^= i_value;
563 else if( (i_code = ShowBits( &p_vpar->bit_stream, 16)) >= 0x0200 )
565 p_tab = DCT_B14_10 - 8 + (i_code >> 6);
566 i_coeff += p_tab->i_run;
572 else if( i_code >= 0x0080 )
574 p_tab = DCT_13 - 16 + (i_code >> 3);
575 i_coeff += p_tab->i_run;
581 else if( i_code >= 0x0020 )
583 p_tab = DCT_15 - 16 + (i_code >> 1);
584 i_coeff += p_tab->i_run;
592 p_tab = DCT_16 + i_code;
593 i_coeff += p_tab->i_run;
600 intf_WarnMsg( 2, "MPEG2NonIntra coeff is out of bound" );
601 p_vpar->picture.b_error = 1;
605 p_dest[63] ^= i_mismatch & 1;
606 RemoveBits( &p_vpar->bit_stream, 2 ); /* End of Block */
614 p_idct->pf_idct = p_vpar->pf_sparse_idct_add;
615 p_idct->i_sparse_pos = 63;
619 p_idct->pf_idct = p_vpar->pf_idct_add;
624 p_idct->pf_idct = p_vpar->pf_sparse_idct_add;
627 p_idct->i_sparse_pos = 0;
631 p_idct->i_sparse_pos = i_coeff - p_tab->i_run;
637 p_idct->pf_idct = p_vpar->pf_idct_add;
641 /*****************************************************************************
642 * MPEG1Intra : Decode an MPEG-1 intra block
643 *****************************************************************************/
644 static void MPEG1Intra( vpar_thread_t * p_vpar, idct_inner_t * p_idct,
647 int i_coeff, i_code, i_pos, i_value, i_nc;
649 dct_lookup_t * p_tab;
651 int i_q_scale = p_vpar->mb.i_quantizer_scale;
652 dctelem_t * p_dest = p_idct->pi_block;
653 u8 * p_scan = p_vpar->picture.pi_scan;
656 i_nc = (p_dest[0] != 0);
660 if( (i_code = ShowBits( &p_vpar->bit_stream, 5 )) >= 0x5 )
662 p_tab = DCT_B14AC_5 - 5 + i_code;
663 i_coeff += p_tab->i_run;
672 i_pos = p_scan[ i_coeff ];
673 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
674 i_value = (p_tab->i_level * i_q_scale * pi_quant[i_pos])
678 i_value = (i_value - 1) | 1;
680 i_sign = GetSignedBits( &p_vpar->bit_stream, 1 );
681 /* if (i_sign) i_value = -i_value; */
682 i_value = (i_value ^ i_sign) - i_sign;
685 p_dest[i_pos] = i_value;
689 else if( (i_code = ShowBits( &p_vpar->bit_stream, 8 )) >= 0x4 )
691 p_tab = DCT_B14_8 - 4 + i_code;
692 i_coeff += p_tab->i_run;
695 /* Normal coefficient */
700 i_coeff += (GetBits( &p_vpar->bit_stream, 12 ) & 0x3F) - 64;
703 /* Illegal, but needed to avoid overflow */
704 intf_WarnMsg( 2, "MPEG1Intra coeff is out of bound" );
705 p_vpar->picture.b_error = 1;
710 i_pos = p_scan[i_coeff];
712 i_value = ShowSignedBits( &p_vpar->bit_stream, 8 );
713 if( !(i_value & 0x7F) )
715 RemoveBits( &p_vpar->bit_stream, 8 );
716 i_value = ShowBits( &p_vpar->bit_stream, 8 ) + 2 * i_value;
719 i_value = (i_value * i_q_scale * pi_quant[i_pos]) / 16;
722 i_value = (i_value + ~ShowSignedBits( &p_vpar->bit_stream, 1 )) | 1;
725 p_dest[i_pos] = i_value;
726 RemoveBits( &p_vpar->bit_stream, 8 );
729 else if( (i_code = ShowBits( &p_vpar->bit_stream, 16)) >= 0x0200 )
731 p_tab = DCT_B14_10 - 8 + (i_code >> 6);
732 i_coeff += p_tab->i_run;
738 else if( i_code >= 0x0080 )
740 p_tab = DCT_13 - 16 + (i_code >> 3);
741 i_coeff += p_tab->i_run;
747 else if( i_code >= 0x0020 )
749 p_tab = DCT_15 - 16 + (i_code >> 1);
750 i_coeff += p_tab->i_run;
758 p_tab = DCT_16 + i_code;
759 i_coeff += p_tab->i_run;
766 intf_WarnMsg( 2, "MPEG1Intra coeff is out of bound" );
767 p_vpar->picture.b_error = 1;
771 RemoveBits( &p_vpar->bit_stream, 2 ); /* End of Block */
775 p_idct->pf_idct = p_vpar->pf_sparse_idct_copy;
776 p_idct->i_sparse_pos = i_coeff - p_tab->i_run;
780 p_idct->pf_idct = p_vpar->pf_idct_copy;
784 /*****************************************************************************
785 * MPEG1NonIntra : Decode a non-intra MPEG-1 block
786 *****************************************************************************/
787 static void MPEG1NonIntra( vpar_thread_t * p_vpar, idct_inner_t * p_idct,
790 int i_coeff, i_code, i_pos, i_value, i_nc;
792 dct_lookup_t * p_tab;
794 int i_q_scale = p_vpar->mb.i_quantizer_scale;
795 dctelem_t * p_dest = p_idct->pi_block;
796 u8 * p_scan = p_vpar->picture.pi_scan;
801 if( (i_code = ShowBits( &p_vpar->bit_stream, 5 )) >= 0x5 )
803 p_tab = DCT_B14DC_5 - 5 + i_code;
813 if( (i_code = ShowBits( &p_vpar->bit_stream, 5 )) >= 0x5 )
815 p_tab = DCT_B14AC_5 - 5 + i_code;
817 i_coeff += p_tab->i_run;
826 i_pos = p_scan[ i_coeff ];
827 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
828 i_value = ((2 * p_tab->i_level + 1) * i_q_scale * pi_quant[i_pos])
832 i_value = (i_value - 1) | 1;
834 i_sign = GetSignedBits( &p_vpar->bit_stream, 1 );
835 /* if (i_sign) i_value = -i_value; */
836 i_value = (i_value ^ i_sign) - i_sign;
839 p_dest[i_pos] = i_value;
844 if( (i_code = ShowBits( &p_vpar->bit_stream, 8 )) >= 0x4 )
846 p_tab = DCT_B14_8 - 4 + i_code;
847 i_coeff += p_tab->i_run;
850 /* Normal coefficient */
855 i_coeff += (GetBits( &p_vpar->bit_stream, 12 ) & 0x3F) - 64;
858 /* Illegal, but needed to avoid overflow */
859 intf_WarnMsg( 2, "MPEG1NonIntra coeff is out of bound" );
860 p_vpar->picture.b_error = 1;
865 i_pos = p_scan[i_coeff];
866 i_value = ShowSignedBits( &p_vpar->bit_stream, 8 );
867 if( !(i_value & 0x7F) )
869 RemoveBits( &p_vpar->bit_stream, 8 );
870 i_value = ShowBits( &p_vpar->bit_stream, 8 ) + 2 * i_value;
872 i_sign = ShowSignedBits( &p_vpar->bit_stream, 1 );
873 i_value = 2 * (i_sign + i_value) + 1;
874 i_value = (i_value * i_q_scale * pi_quant[i_pos]) / 32;
877 i_value = (i_value + ~i_sign) | 1;
880 p_dest[i_pos] = i_value;
881 RemoveBits( &p_vpar->bit_stream, 8 );
884 else if( (i_code = ShowBits( &p_vpar->bit_stream, 16)) >= 0x0200 )
886 p_tab = DCT_B14_10 - 8 + (i_code >> 6);
887 i_coeff += p_tab->i_run;
893 else if( i_code >= 0x0080 )
895 p_tab = DCT_13 - 16 + (i_code >> 3);
896 i_coeff += p_tab->i_run;
902 else if( i_code >= 0x0020 )
904 p_tab = DCT_15 - 16 + (i_code >> 1);
905 i_coeff += p_tab->i_run;
913 p_tab = DCT_16 + i_code;
914 i_coeff += p_tab->i_run;
921 intf_WarnMsg( 2, "MPEG1NonIntra coeff is out of bound" );
922 p_vpar->picture.b_error = 1;
926 RemoveBits( &p_vpar->bit_stream, 2 ); /* End of Block */
930 p_idct->pf_idct = p_vpar->pf_sparse_idct_add;
933 p_idct->i_sparse_pos = 0;
937 p_idct->i_sparse_pos = i_coeff - p_tab->i_run;
942 p_idct->pf_idct = p_vpar->pf_idct_add;
948 /*****************************************************************************
949 * *MB : decode all blocks of the macroblock
950 *****************************************************************************/
951 #define DECODE_LUMABLOCK( I_B, PF_MBFUNC ) \
952 p_idct = &p_mb->p_idcts[I_B]; \
953 memset( p_idct->pi_block, 0, 64*sizeof(dctelem_t) ); \
954 p_vpar->mb.pi_dc_dct_pred[0] += GetLumaDCDiff( p_vpar ); \
955 p_idct->pi_block[0] = p_vpar->mb.pi_dc_dct_pred[0] \
956 << (3 - p_vpar->picture.i_intra_dc_precision ); \
957 PF_MBFUNC( p_vpar, p_idct, p_vpar->sequence.intra_quant.pi_matrix );
959 #define DECODE_CHROMABLOCK( I_B, PF_MBFUNC, I_CC ) \
960 p_idct = &p_mb->p_idcts[I_B]; \
961 memset( p_idct->pi_block, 0, 64*sizeof(dctelem_t) ); \
962 p_vpar->mb.pi_dc_dct_pred[I_CC] += GetChromaDCDiff( p_vpar ); \
963 p_idct->pi_block[0] = p_vpar->mb.pi_dc_dct_pred[I_CC] \
964 << (3 - p_vpar->picture.i_intra_dc_precision ); \
965 PF_MBFUNC( p_vpar, p_idct, \
966 p_vpar->sequence.chroma_intra_quant.pi_matrix );
968 #define DECLARE_INTRAMB( PSZ_NAME, PF_MBFUNC ) \
969 static __inline__ void PSZ_NAME( vpar_thread_t * p_vpar, \
970 macroblock_t * p_mb ) \
972 idct_inner_t * p_idct; \
975 p_mb->p_y_data = p_mb->pp_dest[0] + p_vpar->mb.i_offset; \
976 p_mb->p_u_data = p_mb->pp_dest[1] + (p_vpar->mb.i_offset \
977 >> p_vpar->sequence.b_chroma_h_subsampled); \
978 p_mb->p_v_data = p_mb->pp_dest[2] + (p_vpar->mb.i_offset \
979 >> p_vpar->sequence.b_chroma_h_subsampled); \
981 DECODE_LUMABLOCK( 0, PF_MBFUNC ); \
982 DECODE_LUMABLOCK( 1, PF_MBFUNC ); \
983 DECODE_LUMABLOCK( 2, PF_MBFUNC ); \
984 DECODE_LUMABLOCK( 3, PF_MBFUNC ); \
988 DECODE_CHROMABLOCK( i_b, PF_MBFUNC, 1 ); \
989 DECODE_CHROMABLOCK( i_b + 1, PF_MBFUNC, 2 ); \
992 while( i_b < 4 + p_vpar->sequence.i_chroma_nb_blocks ); \
995 DECLARE_INTRAMB( MPEG1IntraMB, MPEG1Intra );
996 DECLARE_INTRAMB( MPEG2IntraB14MB, MPEG2IntraB14 );
997 DECLARE_INTRAMB( MPEG2IntraB15MB, MPEG2IntraB15 );
999 #undef DECLARE_INTRAMB
1000 #undef DECODE_LUMABLOCK
1001 #undef DECODE_CHROMABLOCK
1003 #define DECODE_LUMABLOCK( I_B, PF_MBFUNC ) \
1004 if( p_mb->i_coded_block_pattern & (1 << (11 - (I_B))) ) \
1006 p_idct = &p_mb->p_idcts[I_B]; \
1007 memset( p_idct->pi_block, 0, 64*sizeof(dctelem_t) ); \
1008 PF_MBFUNC( p_vpar, p_idct, \
1009 p_vpar->sequence.nonintra_quant.pi_matrix ); \
1012 #define DECODE_CHROMABLOCK( I_B, PF_MBFUNC ) \
1013 if( p_mb->i_coded_block_pattern & (1 << (11 - (I_B))) ) \
1015 p_idct = &p_mb->p_idcts[I_B]; \
1016 memset( p_idct->pi_block, 0, 64*sizeof(dctelem_t) ); \
1017 PF_MBFUNC( p_vpar, p_idct, \
1018 p_vpar->sequence.chroma_nonintra_quant.pi_matrix ); \
1021 #define DECLARE_NONINTRAMB( PSZ_NAME, PF_MBFUNC ) \
1022 static __inline__ void PSZ_NAME( vpar_thread_t * p_vpar, \
1023 macroblock_t * p_mb ) \
1025 idct_inner_t * p_idct; \
1028 p_mb->p_y_data = p_mb->pp_dest[0] + p_vpar->mb.i_offset; \
1029 p_mb->p_u_data = p_mb->pp_dest[1] + (p_vpar->mb.i_offset \
1030 >> p_vpar->sequence.b_chroma_h_subsampled); \
1031 p_mb->p_v_data = p_mb->pp_dest[2] + (p_vpar->mb.i_offset \
1032 >> p_vpar->sequence.b_chroma_h_subsampled); \
1034 DECODE_LUMABLOCK( 0, PF_MBFUNC ); \
1035 DECODE_LUMABLOCK( 1, PF_MBFUNC ); \
1036 DECODE_LUMABLOCK( 2, PF_MBFUNC ); \
1037 DECODE_LUMABLOCK( 3, PF_MBFUNC ); \
1041 DECODE_CHROMABLOCK( i_b, PF_MBFUNC ); \
1042 DECODE_CHROMABLOCK( i_b + 1, PF_MBFUNC ); \
1045 while( i_b < 4 + p_vpar->sequence.i_chroma_nb_blocks ); \
1048 DECLARE_NONINTRAMB( MPEG1NonIntraMB, MPEG1NonIntra );
1049 DECLARE_NONINTRAMB( MPEG2NonIntraMB, MPEG2NonIntra );
1051 #undef DECLARE_NONINTRAMB
1052 #undef DECODE_LUMABLOCK
1053 #undef DECODE_CHROMABLOCK
1060 /****************************************************************************
1061 * MotionDelta : Parse the next motion delta
1062 ****************************************************************************/
1063 static __inline__ int MotionDelta( vpar_thread_t * p_vpar, int i_f_code )
1065 int i_delta, i_sign, i_code;
1068 if( ShowBits( &p_vpar->bit_stream, 1 ) )
1070 RemoveBits( &p_vpar->bit_stream, 1 );
1074 if( (i_code = ShowBits( &p_vpar->bit_stream, 6 )) >= 0x3 )
1076 p_tab = MV_4 + (i_code >> 2);
1077 i_delta = (p_tab->i_value << i_f_code) + 1;
1078 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
1080 i_sign = GetSignedBits( &p_vpar->bit_stream, 1 );
1083 i_delta += GetBits( &p_vpar->bit_stream, i_f_code );
1086 return (i_delta ^ i_sign) - i_sign;
1091 p_tab = MV_10 + ShowBits( &p_vpar->bit_stream, 10 );
1092 i_delta = (p_tab->i_value << i_f_code) + 1;
1093 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
1095 i_sign = GetSignedBits( &p_vpar->bit_stream, 1 );
1098 i_delta += GetBits( &p_vpar->bit_stream, i_f_code );
1101 return (i_delta ^ i_sign) - i_sign;
1105 /****************************************************************************
1106 * BoundMotionVector : Bound a motion_vector :-)
1107 ****************************************************************************/
1108 static __inline__ int BoundMotionVector( int i_vector, int i_f_code )
1112 i_limit = 16 << i_f_code;
1114 if( i_vector >= i_limit )
1116 return i_vector - 2 * i_limit;
1118 else if( i_vector < -i_limit)
1120 return i_vector + 2 * i_limit;
1128 /****************************************************************************
1129 * GetDMV : Decode a differential motion vector (Dual Prime Arithmetic)
1130 ****************************************************************************/
1131 static __inline__ int GetDMV( vpar_thread_t * p_vpar )
1133 dmv_lookup_t * p_tab;
1135 p_tab = DMV_2 + ShowBits( &p_vpar->bit_stream, 2 );
1136 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
1137 return( p_tab->i_value );
1140 /****************************************************************************
1141 * Motion* : Parse motion vectors
1142 ****************************************************************************/
1143 #define MOTION_BLOCK( b_aver, i_x, i_y, i_dest, \
1144 pp_src, i_src, i_str, i_hei, \
1147 motion_inner_t * p_m_inner = p_mb->p_motions + p_mb->i_nb_motions; \
1148 p_m_inner->b_average = b_aver; \
1149 p_m_inner->i_x_pred = i_x; \
1150 p_m_inner->i_y_pred = i_y; \
1151 p_m_inner->pp_source[0] = pp_src[0]; \
1152 p_m_inner->pp_source[1] = pp_src[1]; \
1153 p_m_inner->pp_source[2] = pp_src[2]; \
1154 p_m_inner->i_dest_offset = i_dest; \
1155 p_m_inner->i_src_offset = i_src; \
1156 p_m_inner->i_stride = i_str; \
1157 p_m_inner->i_height = i_hei; \
1158 p_m_inner->b_second_half = b_s_half; \
1159 p_mb->i_nb_motions++; \
1162 /* MPEG-1 predictions. */
1164 static void MotionMPEG1( vpar_thread_t * p_vpar,
1165 macroblock_t * p_mb,
1166 motion_t * p_motion,
1167 boolean_t b_average )
1169 int i_motion_x, i_motion_y;
1170 int i_offset = p_vpar->mb.i_offset;
1171 int i_width = p_vpar->picture.i_field_width;
1173 i_motion_x = p_motion->ppi_pmv[0][0]
1174 + MotionDelta( p_vpar, p_motion->pi_f_code[0] );
1175 i_motion_x = BoundMotionVector( i_motion_x, p_motion->pi_f_code[0] );
1176 p_motion->ppi_pmv[0][0] = i_motion_x;
1178 i_motion_y = p_motion->ppi_pmv[0][1]
1179 + MotionDelta( p_vpar, p_motion->pi_f_code[0] );
1180 i_motion_y = BoundMotionVector( i_motion_y, p_motion->pi_f_code[0] );
1181 p_motion->ppi_pmv[0][1] = i_motion_y;
1183 if( p_motion->pi_f_code[1] )
1189 MOTION_BLOCK( b_average, i_motion_x, i_motion_y, i_offset,
1190 p_motion->pppi_ref[0], i_offset, i_width, 16, 0 );
1193 static void MotionMPEG1Reuse( vpar_thread_t * p_vpar,
1194 macroblock_t * p_mb,
1195 motion_t * p_motion,
1196 boolean_t b_average )
1198 int i_motion_x, i_motion_y;
1199 int i_offset = p_vpar->mb.i_offset;
1200 int i_width = p_vpar->picture.i_field_width;
1202 i_motion_x = p_motion->ppi_pmv[0][0];
1203 i_motion_y = p_motion->ppi_pmv[0][1];
1205 if( p_motion->pi_f_code[1] )
1211 MOTION_BLOCK( b_average, p_motion->ppi_pmv[0][0], p_motion->ppi_pmv[0][1],
1212 i_offset, p_motion->pppi_ref[0], i_offset, i_width, 16, 0 );
1215 /* MPEG-2 frame predictions. */
1217 static void MotionFrameFrame( vpar_thread_t * p_vpar,
1218 macroblock_t * p_mb,
1219 motion_t * p_motion,
1220 boolean_t b_average )
1222 int i_motion_x, i_motion_y;
1223 int i_offset = p_vpar->mb.i_offset;
1224 int i_width = p_vpar->picture.i_field_width;
1226 i_motion_x = p_motion->ppi_pmv[0][0]
1227 + MotionDelta( p_vpar, p_motion->pi_f_code[0] );
1228 i_motion_x = BoundMotionVector( i_motion_x, p_motion->pi_f_code[0] );
1229 p_motion->ppi_pmv[1][0] = p_motion->ppi_pmv[0][0] = i_motion_x;
1231 i_motion_y = p_motion->ppi_pmv[0][1]
1232 + MotionDelta( p_vpar, p_motion->pi_f_code[1] );
1233 i_motion_y = BoundMotionVector( i_motion_y, p_motion->pi_f_code[1] );
1234 p_motion->ppi_pmv[1][1] = p_motion->ppi_pmv[0][1] = i_motion_y;
1236 MOTION_BLOCK( b_average, i_motion_x, i_motion_y, i_offset,
1237 p_motion->pppi_ref[0], i_offset, i_width, 16, 0 );
1240 static void MotionFrameField( vpar_thread_t * p_vpar,
1241 macroblock_t * p_mb,
1242 motion_t * p_motion,
1243 boolean_t b_average )
1245 int i_motion_x, i_motion_y, i_field_select;
1246 int i_offset = p_vpar->mb.i_offset;
1247 int i_width = p_vpar->picture.i_field_width;
1249 i_field_select = GetSignedBits( &p_vpar->bit_stream, 1 );
1251 i_motion_x = p_motion->ppi_pmv[0][0]
1252 + MotionDelta( p_vpar, p_motion->pi_f_code[0] );
1253 i_motion_x = BoundMotionVector( i_motion_x, p_motion->pi_f_code[0] );
1254 p_motion->ppi_pmv[0][0] = i_motion_x;
1256 i_motion_y = (p_motion->ppi_pmv[0][1] >> 1)
1257 + MotionDelta( p_vpar, p_motion->pi_f_code[1] );
1258 /* According to ISO/IEC 13818-2 section 7.6.3.2, the vertical motion
1259 * vector is restricted to a range that implies it doesn't need to
1261 /* i_motion_y = BoundMotionVector( i_motion_y, p_motion->pi_f_code[1] ); */
1262 p_motion->ppi_pmv[0][1] = i_motion_y << 1;
1264 MOTION_BLOCK( b_average, i_motion_x, i_motion_y, i_offset,
1265 p_motion->pppi_ref[0], i_offset + (i_field_select & i_width),
1266 i_width * 2, 8, 0 );
1268 i_field_select = GetSignedBits( &p_vpar->bit_stream, 1 );
1270 i_motion_x = p_motion->ppi_pmv[1][0]
1271 + MotionDelta( p_vpar, p_motion->pi_f_code[0] );
1272 i_motion_x = BoundMotionVector( i_motion_x, p_motion->pi_f_code[0] );
1273 p_motion->ppi_pmv[1][0] = i_motion_x;
1275 i_motion_y = (p_motion->ppi_pmv[1][1] >> 1)
1276 + MotionDelta( p_vpar, p_motion->pi_f_code[1] );
1277 /* i_motion_y = BoundMotionVector( i_motion_y, p_motion->pi_f_code[1] ); */
1278 p_motion->ppi_pmv[1][1] = i_motion_y << 1;
1280 MOTION_BLOCK( b_average, i_motion_x, i_motion_y, i_offset + i_width,
1281 p_motion->pppi_ref[0], i_offset + (i_field_select & i_width),
1282 i_width * 2, 8, 0 );
1285 static void MotionFrameDMV( vpar_thread_t * p_vpar,
1286 macroblock_t * p_mb,
1287 motion_t * p_motion,
1288 boolean_t b_average )
1290 int i_motion_x, i_motion_y;
1291 int i_dmv_x, i_dmv_y;
1292 int i_tmp_x, i_tmp_y;
1294 int i_offset = p_vpar->mb.i_offset;
1295 int i_width = p_vpar->picture.i_field_width;
1298 i_motion_x = p_motion->ppi_pmv[0][0]
1299 + MotionDelta( p_vpar, p_motion->pi_f_code[0] );
1300 i_motion_x = BoundMotionVector( i_motion_x, p_motion->pi_f_code[0] );
1301 p_motion->ppi_pmv[1][0] = p_motion->ppi_pmv[0][0] = i_motion_x;
1303 i_dmv_x = GetDMV( p_vpar );
1305 i_motion_y = (p_motion->ppi_pmv[0][1] >> 1)
1306 + MotionDelta( p_vpar, p_motion->pi_f_code[1] );
1307 /* i_motion_y = BoundMotionVector( i_motion_y, p_motion->pi_f_code[1] ); */
1308 p_motion->ppi_pmv[1][1] = p_motion->ppi_pmv[0][1] = i_motion_y << 1;
1310 i_dmv_y = GetDMV( p_vpar );
1313 MOTION_BLOCK( 0, i_motion_x, i_motion_y, i_offset,
1314 p_motion->pppi_ref[0], i_offset, i_width * 2, 8, 0 );
1315 m = p_vpar->picture.b_top_field_first ? 1 : 3;
1316 i_tmp_x = ((i_motion_x * m + (i_motion_x > 0)) >> 1) + i_dmv_x;
1317 i_tmp_y = ((i_motion_y * m + (i_motion_y > 0)) >> 1) + i_dmv_y - 1;
1318 MOTION_BLOCK( 1, i_tmp_x, i_tmp_y, i_offset, p_motion->pppi_ref[0],
1319 i_offset + i_width, i_width * 2, 8, 0 );
1322 MOTION_BLOCK( 0, i_motion_x, i_motion_y, i_offset + i_width,
1323 p_motion->pppi_ref[0], i_offset + i_width, i_width * 2, 8, 0 );
1324 m = p_vpar->picture.b_top_field_first ? 3 : 1;
1325 i_tmp_x = ((i_motion_x * m + (i_motion_x > 0)) >> 1) + i_dmv_x;
1326 i_tmp_y = ((i_motion_y * m + (i_motion_y > 0)) >> 1) + i_dmv_y + 1;
1327 MOTION_BLOCK( 1, i_tmp_x, i_tmp_y, i_offset + i_width,
1328 p_motion->pppi_ref[0], i_offset, i_width * 2, 8, 0 );
1331 static void MotionFrameZero( vpar_thread_t * p_vpar,
1332 macroblock_t * p_mb,
1333 motion_t * p_motion,
1334 boolean_t b_average )
1336 int i_offset = p_vpar->mb.i_offset;
1337 int i_width = p_vpar->picture.i_field_width;
1339 MOTION_BLOCK( b_average, 0, 0, i_offset, p_motion->pppi_ref[0],
1340 i_offset, i_width, 16, 0 );
1343 static void MotionFrameReuse( vpar_thread_t * p_vpar,
1344 macroblock_t * p_mb,
1345 motion_t * p_motion,
1346 boolean_t b_average )
1348 int i_offset = p_vpar->mb.i_offset;
1349 int i_width = p_vpar->picture.i_field_width;
1351 MOTION_BLOCK( b_average, p_motion->ppi_pmv[0][0], p_motion->ppi_pmv[0][1],
1352 i_offset, p_motion->pppi_ref[0], i_offset, i_width, 16, 0 );
1355 /* MPEG-2 field predictions. */
1357 static void MotionFieldField( vpar_thread_t * p_vpar,
1358 macroblock_t * p_mb,
1359 motion_t * p_motion,
1360 boolean_t b_average )
1362 int i_motion_x, i_motion_y;
1363 boolean_t b_field_select;
1364 int i_offset = p_vpar->mb.i_offset;
1365 int i_width = p_vpar->picture.i_field_width;
1367 b_field_select = GetBits( &p_vpar->bit_stream, 1 );
1369 i_motion_x = p_motion->ppi_pmv[0][0]
1370 + MotionDelta( p_vpar, p_motion->pi_f_code[0] );
1371 i_motion_x = BoundMotionVector( i_motion_x, p_motion->pi_f_code[0] );
1372 p_motion->ppi_pmv[1][0] = p_motion->ppi_pmv[0][0] = i_motion_x;
1374 i_motion_y = p_motion->ppi_pmv[0][1]
1375 + MotionDelta( p_vpar, p_motion->pi_f_code[1] );
1376 i_motion_y = BoundMotionVector( i_motion_y, p_motion->pi_f_code[1] );
1377 p_motion->ppi_pmv[1][1] = p_motion->ppi_pmv[0][1] = i_motion_y;
1379 MOTION_BLOCK( b_average, i_motion_x, i_motion_y, i_offset,
1380 p_motion->pppi_ref[b_field_select], i_offset, i_width, 16, 0 );
1383 static void MotionField16x8( vpar_thread_t * p_vpar,
1384 macroblock_t * p_mb,
1385 motion_t * p_motion,
1386 boolean_t b_average )
1388 int i_motion_x, i_motion_y;
1389 boolean_t b_field_select;
1390 int i_offset = p_vpar->mb.i_offset;
1391 int i_width = p_vpar->picture.i_field_width;
1394 b_field_select = GetBits( &p_vpar->bit_stream, 1 );
1396 i_motion_x = p_motion->ppi_pmv[0][0]
1397 + MotionDelta( p_vpar, p_motion->pi_f_code[0] );
1398 i_motion_x = BoundMotionVector( i_motion_x, p_motion->pi_f_code[0] );
1399 p_motion->ppi_pmv[0][0] = i_motion_x;
1401 i_motion_y = p_motion->ppi_pmv[0][1]
1402 + MotionDelta( p_vpar, p_motion->pi_f_code[1] );
1403 i_motion_y = BoundMotionVector( i_motion_y, p_motion->pi_f_code[1] );
1404 p_motion->ppi_pmv[0][1] = i_motion_y;
1406 MOTION_BLOCK( b_average, i_motion_x, i_motion_y, i_offset,
1407 p_motion->pppi_ref[b_field_select], i_offset, i_width, 8, 0 );
1410 b_field_select = GetBits( &p_vpar->bit_stream, 1 );
1412 i_motion_x = p_motion->ppi_pmv[1][0]
1413 + MotionDelta( p_vpar, p_motion->pi_f_code[0] );
1414 i_motion_x = BoundMotionVector( i_motion_x, p_motion->pi_f_code[0] );
1415 p_motion->ppi_pmv[1][0] = i_motion_x;
1417 i_motion_y = p_motion->ppi_pmv[1][1]
1418 + MotionDelta( p_vpar, p_motion->pi_f_code[1] );
1419 i_motion_y = BoundMotionVector( i_motion_y, p_motion->pi_f_code[1] );
1420 p_motion->ppi_pmv[1][1] = i_motion_y;
1422 MOTION_BLOCK( b_average, i_motion_x, i_motion_y, i_offset,
1423 p_motion->pppi_ref[b_field_select], i_offset, i_width, 8, 1 );
1426 static void MotionFieldDMV( vpar_thread_t * p_vpar,
1427 macroblock_t * p_mb,
1428 motion_t * p_motion,
1429 boolean_t b_average )
1431 int i_motion_x, i_motion_y;
1432 int i_dmv_x, i_dmv_y;
1433 int i_offset = p_vpar->mb.i_offset;
1434 int i_width = p_vpar->picture.i_field_width;
1435 boolean_t b_current_field = p_vpar->picture.b_current_field;
1437 i_motion_x = p_motion->ppi_pmv[0][0]
1438 + MotionDelta( p_vpar, p_motion->pi_f_code[0] );
1439 i_motion_x = BoundMotionVector( i_motion_x, p_motion->pi_f_code[0] );
1440 p_motion->ppi_pmv[1][0] = p_motion->ppi_pmv[0][0] = i_motion_x;
1442 i_dmv_x = GetDMV( p_vpar );
1444 i_motion_y = p_motion->ppi_pmv[0][1]
1445 + MotionDelta( p_vpar, p_motion->pi_f_code[1] );
1446 i_motion_y = BoundMotionVector( i_motion_y, p_motion->pi_f_code[1] );
1447 p_motion->ppi_pmv[1][1] = p_motion->ppi_pmv[0][1] = i_motion_y;
1449 i_dmv_y = GetDMV( p_vpar );
1451 MOTION_BLOCK( 0, i_motion_x, i_motion_y, i_offset,
1452 p_motion->pppi_ref[b_current_field],
1453 i_offset, i_width, 16, 0 );
1455 i_motion_x = ((i_motion_x + (i_motion_x > 0)) >> 1) + i_dmv_x;
1456 i_motion_y = ((i_motion_y + (i_motion_y > 0)) >> 1) + i_dmv_y
1457 + 2 * b_current_field - 1;
1458 MOTION_BLOCK( 1, i_motion_x, i_motion_y, i_offset,
1459 p_motion->pppi_ref[!b_current_field],
1460 i_offset, i_width, 16, 0 );
1463 static void MotionFieldZero( vpar_thread_t * p_vpar,
1464 macroblock_t * p_mb,
1465 motion_t * p_motion,
1466 boolean_t b_average )
1468 int i_offset = p_vpar->mb.i_offset;
1469 int i_width = p_vpar->picture.i_field_width;
1470 boolean_t b_current_field = p_vpar->picture.b_current_field;
1472 MOTION_BLOCK( b_average, 0, 0, i_offset, p_motion->pppi_ref[b_current_field],
1473 i_offset, i_width, 16, 0 );
1476 static void MotionFieldReuse( vpar_thread_t * p_vpar,
1477 macroblock_t * p_mb,
1478 motion_t * p_motion,
1479 boolean_t b_average )
1481 int i_offset = p_vpar->mb.i_offset;
1482 int i_width = p_vpar->picture.i_field_width;
1483 boolean_t b_current_field = p_vpar->picture.b_current_field;
1485 MOTION_BLOCK( b_average, p_motion->ppi_pmv[0][0], p_motion->ppi_pmv[0][1],
1486 i_offset, p_motion->pppi_ref[b_current_field],
1487 i_offset, i_width, 16, 0 );
1490 /* MPEG-2 concealment motion vectors. */
1492 static void MotionFrameConceal( vpar_thread_t * p_vpar,
1493 macroblock_t * p_mv,
1494 motion_t * p_motion )
1498 i_tmp = p_motion->ppi_pmv[0][0]
1499 + MotionDelta( p_vpar, p_motion->pi_f_code[0] );
1500 i_tmp = BoundMotionVector( i_tmp, p_motion->pi_f_code[0] );
1501 p_motion->ppi_pmv[1][0] = p_motion->ppi_pmv[0][0] = i_tmp;
1503 i_tmp = p_motion->ppi_pmv[0][1]
1504 + MotionDelta( p_vpar, p_motion->pi_f_code[1] );
1505 i_tmp = BoundMotionVector( i_tmp, p_motion->pi_f_code[1] );
1506 p_motion->ppi_pmv[1][1] = p_motion->ppi_pmv[0][1] = i_tmp;
1509 RemoveBits( &p_vpar->bit_stream, 1 );
1512 static void MotionFieldConceal( vpar_thread_t * p_vpar,
1513 macroblock_t * p_mv,
1514 motion_t * p_motion )
1519 RemoveBits( &p_vpar->bit_stream, 1 );
1521 i_tmp = p_motion->ppi_pmv[0][0]
1522 + MotionDelta( p_vpar, p_motion->pi_f_code[0] );
1523 i_tmp = BoundMotionVector( i_tmp, p_motion->pi_f_code[0] );
1524 p_motion->ppi_pmv[1][0] = p_motion->ppi_pmv[0][0] = i_tmp;
1526 i_tmp = p_motion->ppi_pmv[0][1]
1527 + MotionDelta( p_vpar, p_motion->pi_f_code[1] );
1528 i_tmp = BoundMotionVector( i_tmp, p_motion->pi_f_code[1] );
1529 p_motion->ppi_pmv[1][1] = p_motion->ppi_pmv[0][1] = i_tmp;
1532 RemoveBits( &p_vpar->bit_stream, 1 );
1537 * Macroblock information structures
1540 /*****************************************************************************
1541 * MacroblockAddressIncrement : Get the macroblock_address_increment field
1542 *****************************************************************************/
1543 static __inline__ int MacroblockAddressIncrement( vpar_thread_t * p_vpar )
1551 if( (i_code = ShowBits( &p_vpar->bit_stream, 5 ) ) >= 0x2 )
1553 p_tab = MBA_5 - 2 + i_code;
1554 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
1555 return( i_mba + p_tab->i_value );
1557 else if( (i_code = ShowBits( &p_vpar->bit_stream, 11 )) >= 0x18 )
1559 p_tab = MBA_11 - 24 + i_code;
1560 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
1561 return( i_mba + p_tab->i_value );
1563 else switch( i_code )
1566 /* Macroblock escape */
1570 /* Macroblock stuffing (MPEG-1 ONLY) */
1571 RemoveBits( &p_vpar->bit_stream, 11 );
1575 /* End of slice, or error */
1581 /*****************************************************************************
1582 * CodedPattern : coded_block_pattern
1583 *****************************************************************************/
1584 static __inline__ int CodedPattern( vpar_thread_t * p_vpar )
1589 if( (i_code = ShowBits( &p_vpar->bit_stream, 7 )) >= 0x10 )
1591 p_tab = CBP_7 - 16 + i_code;
1592 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
1596 p_tab = CBP_9 + ShowBits( &p_vpar->bit_stream, 9 );
1597 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
1599 if( p_vpar->sequence.i_chroma_format == CHROMA_420 )
1601 return( p_tab->i_value << 6 );
1603 if( p_vpar->sequence.i_chroma_format == CHROMA_422 )
1605 return( (p_tab->i_value << 6)
1606 | (GetBits( &p_vpar->bit_stream, 2 ) << 4) );
1608 return( (p_tab->i_value << 6)
1609 | GetBits( &p_vpar->bit_stream, 6 ) );
1612 /*****************************************************************************
1613 * MacroblockModes : Get the macroblock_modes structure
1614 *****************************************************************************/
1615 static __inline__ int MacroblockModes( vpar_thread_t * p_vpar,
1616 macroblock_t * p_mb,
1623 switch( i_coding_type )
1626 p_tab = MB_I + ShowBits( &p_vpar->bit_stream, 1 );
1627 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
1628 i_mb_modes = p_tab->i_value;
1630 if( (i_structure == FRAME_STRUCTURE) &&
1631 (!p_vpar->picture.b_frame_pred_frame_dct) )
1633 i_mb_modes |= GetBits( &p_vpar->bit_stream, 1 )
1634 * DCT_TYPE_INTERLACED;
1636 return( i_mb_modes );
1639 p_tab = MB_P + ShowBits( &p_vpar->bit_stream, 5 );
1640 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
1641 i_mb_modes = p_tab->i_value;
1643 if( i_structure != FRAME_STRUCTURE )
1645 if( i_mb_modes & MB_MOTION_FORWARD )
1647 i_mb_modes |= GetBits( &p_vpar->bit_stream, 2 )
1650 return( i_mb_modes );
1652 else if( p_vpar->picture.b_frame_pred_frame_dct )
1654 if( i_mb_modes & MB_MOTION_FORWARD )
1656 i_mb_modes |= MC_FRAME;
1658 return( i_mb_modes );
1662 if( i_mb_modes & MB_MOTION_FORWARD )
1664 i_mb_modes |= GetBits( &p_vpar->bit_stream, 2 )
1667 if( i_mb_modes & (MB_INTRA | MB_PATTERN) )
1669 i_mb_modes |= GetBits( &p_vpar->bit_stream, 1 )
1670 * DCT_TYPE_INTERLACED;
1672 return( i_mb_modes );
1676 p_tab = MB_B + ShowBits( &p_vpar->bit_stream, 6 );
1677 RemoveBits( &p_vpar->bit_stream, p_tab->i_length );
1678 i_mb_modes = p_tab->i_value;
1680 if( i_structure != FRAME_STRUCTURE )
1682 if( !( i_mb_modes & MB_INTRA ) )
1684 i_mb_modes |= GetBits( &p_vpar->bit_stream, 2 )
1687 return( i_mb_modes );
1689 else if( p_vpar->picture.b_frame_pred_frame_dct )
1691 i_mb_modes |= MC_FRAME;
1692 return( i_mb_modes );
1696 if( i_mb_modes & MB_INTRA )
1700 i_mb_modes |= GetBits( &p_vpar->bit_stream, 2 )
1702 if( i_mb_modes & (MB_INTRA | MB_PATTERN) )
1705 i_mb_modes |= GetBits( &p_vpar->bit_stream, 1 )
1706 * DCT_TYPE_INTERLACED;
1708 return( i_mb_modes );
1712 RemoveBits( &p_vpar->bit_stream, 1 );
1722 * Picture data parsing management
1725 /*****************************************************************************
1726 * ParseSlice : Parse the next slice structure
1727 *****************************************************************************/
1728 #define MOTION( pf_routine, i_direction ) \
1729 if( (i_direction) & MB_MOTION_FORWARD ) \
1731 pf_routine( p_vpar, p_mb, &p_vpar->mb.f_motion, 0 ); \
1732 if( (i_coding_type == B_CODING_TYPE) \
1733 && ((i_direction) & MB_MOTION_BACKWARD) ) \
1735 pf_routine( p_vpar, p_mb, &p_vpar->mb.b_motion, 1 ); \
1738 else if( (i_coding_type == B_CODING_TYPE) \
1739 && ((i_direction) & MB_MOTION_BACKWARD) ) \
1741 pf_routine( p_vpar, p_mb, &p_vpar->mb.b_motion, 0 ); \
1744 #define CHECK_BOUNDARIES \
1745 i_offset = p_vpar->mb.i_offset; \
1746 if( i_offset == i_width ) \
1748 if( i_coding_type != I_CODING_TYPE || \
1749 p_vpar->picture.b_concealment_mv ) \
1751 p_f_motion->pppi_ref[0][0] += 16 * i_offset; \
1752 p_f_motion->pppi_ref[0][1] += i_chroma_tmp; \
1753 p_f_motion->pppi_ref[0][2] += i_chroma_tmp; \
1755 if( i_coding_type == B_CODING_TYPE ) \
1757 p_b_motion->pppi_ref[0][0] += 16 * i_offset; \
1758 p_b_motion->pppi_ref[0][1] += i_chroma_tmp; \
1759 p_b_motion->pppi_ref[0][2] += i_chroma_tmp; \
1761 p_dest[0] += 16 * i_offset; \
1762 p_dest[1] += 4 * i_offset; \
1763 p_dest[2] += 4 * i_offset; \
1766 p_vpar->mb.i_offset = i_offset;
1768 #define PARSEERROR \
1769 if( p_vpar->picture.b_error ) \
1771 /* Go to the next slice. */ \
1772 p_vpar->pool.pf_free_mb( &p_vpar->pool, p_mb ); \
1776 static __inline__ void ParseSlice( vpar_thread_t * p_vpar,
1777 u32 i_vert_code, boolean_t b_mpeg2,
1778 int i_coding_type, int i_structure )
1780 int i_offset, i_width, i_chroma_tmp;
1781 picture_t * pp_forward_ref[2];
1782 yuv_data_t * p_dest[3];
1784 motion_t * p_f_motion = &p_vpar->mb.f_motion;
1785 motion_t * p_b_motion = &p_vpar->mb.b_motion;
1788 LoadQuantizerScale( p_vpar );
1790 if( GetBits( &p_vpar->bit_stream, 1 ) )
1792 /* intra_slice, slice_id */
1793 RemoveBits( &p_vpar->bit_stream, 8 );
1794 /* extra_information_slice */
1795 while( GetBits( &p_vpar->bit_stream, 1 ) )
1797 RemoveBits( &p_vpar->bit_stream, 8 );
1801 /* Calculate the position of the macroblock. */
1802 i_width = p_vpar->sequence.i_width;
1803 i_offset = (i_vert_code - 1) * i_width * 4;
1805 /* Initialize motion context. */
1806 pp_forward_ref[0] = p_vpar->sequence.p_forward;
1808 if( i_structure != FRAME_STRUCTURE )
1812 i_offset * (2 - p_vpar->sequence.b_chroma_v_subsampled)
1813 * (2 - p_vpar->sequence.b_chroma_h_subsampled)
1814 + (i_width >> p_vpar->sequence.b_chroma_h_subsampled);
1815 pp_forward_ref[1] = p_vpar->sequence.p_forward;
1817 if( i_coding_type != B_CODING_TYPE && p_vpar->picture.b_second_field )
1819 pp_forward_ref[!p_vpar->picture.b_current_field] =
1820 p_vpar->picture.p_picture;
1822 if( i_coding_type != I_CODING_TYPE || p_vpar->picture.b_concealment_mv )
1824 p_f_motion->pppi_ref[1][0] =
1825 pp_forward_ref[1]->p_y + i_offset * 4 + i_width;
1826 p_f_motion->pppi_ref[1][1] =
1827 pp_forward_ref[1]->p_u + i_chroma_tmp;
1828 p_f_motion->pppi_ref[1][2] =
1829 pp_forward_ref[1]->p_v + i_chroma_tmp;
1831 if( i_coding_type == B_CODING_TYPE )
1833 p_b_motion->pppi_ref[1][0] =
1834 p_vpar->sequence.p_backward->p_y + i_offset * 4 + i_width;
1835 p_b_motion->pppi_ref[1][1] =
1836 p_vpar->sequence.p_backward->p_u + i_chroma_tmp;
1837 p_b_motion->pppi_ref[1][2] =
1838 p_vpar->sequence.p_backward->p_v + i_chroma_tmp;
1842 i_chroma_tmp = i_offset
1843 * (2 - p_vpar->sequence.b_chroma_v_subsampled)
1844 * (2 - p_vpar->sequence.b_chroma_h_subsampled);
1845 if( i_coding_type != I_CODING_TYPE || p_vpar->picture.b_concealment_mv )
1847 p_f_motion->pppi_ref[0][0] = pp_forward_ref[0]->p_y + i_offset * 4;
1848 p_f_motion->pppi_ref[0][1] = pp_forward_ref[0]->p_u + i_chroma_tmp;
1849 p_f_motion->pppi_ref[0][2] = pp_forward_ref[0]->p_v + i_chroma_tmp;
1850 p_f_motion->pi_f_code[0] = p_vpar->picture.ppi_f_code[0][0];
1851 p_f_motion->pi_f_code[1] = p_vpar->picture.ppi_f_code[0][1];
1852 p_f_motion->ppi_pmv[0][0] = p_f_motion->ppi_pmv[0][1] = 0;
1853 p_f_motion->ppi_pmv[1][0] = p_f_motion->ppi_pmv[1][1] = 0;
1856 if( i_coding_type == B_CODING_TYPE )
1858 p_b_motion->pppi_ref[0][0] = p_vpar->sequence.p_backward->p_y
1860 p_b_motion->pppi_ref[0][1] = p_vpar->sequence.p_backward->p_u
1862 p_b_motion->pppi_ref[0][2] = p_vpar->sequence.p_backward->p_v
1864 p_b_motion->pi_f_code[0] = p_vpar->picture.ppi_f_code[1][0];
1865 p_b_motion->pi_f_code[1] = p_vpar->picture.ppi_f_code[1][1];
1866 p_b_motion->ppi_pmv[0][0] = p_b_motion->ppi_pmv[0][1] = 0;
1867 p_b_motion->ppi_pmv[1][0] = p_b_motion->ppi_pmv[1][1] = 0;
1870 /* Initialize destination pointers. */
1871 p_dest[0] = p_vpar->picture.p_picture->p_y + i_offset * 4;
1872 p_dest[1] = p_vpar->picture.p_picture->p_u + i_chroma_tmp;
1873 p_dest[2] = p_vpar->picture.p_picture->p_v + i_chroma_tmp;
1875 if( i_structure == BOTTOM_FIELD )
1877 p_dest[0] += i_width;
1878 p_dest[1] += i_width >> p_vpar->sequence.b_chroma_h_subsampled;
1879 p_dest[2] += i_width >> p_vpar->sequence.b_chroma_h_subsampled;
1881 i_width = p_vpar->picture.i_field_width;
1883 /* Reset intra DC coefficients predictors (ISO/IEC 13818-2 7.2.1). */
1884 p_vpar->mb.pi_dc_dct_pred[0] = p_vpar->mb.pi_dc_dct_pred[1]
1885 = p_vpar->mb.pi_dc_dct_pred[2]
1886 = 1 << (7 + p_vpar->picture.i_intra_dc_precision);
1888 p_vpar->mb.i_offset = MacroblockAddressIncrement( p_vpar ) << 4;
1890 i_chroma_tmp = i_width * 4
1891 * (2 - p_vpar->sequence.b_chroma_v_subsampled)
1892 * (2 - p_vpar->sequence.b_chroma_h_subsampled);
1893 while( (int)(p_vpar->mb.i_offset - p_vpar->sequence.i_width) >= 0 )
1895 /* Unusual construct at the start of some slices. Jump one line. */
1896 p_vpar->mb.i_offset -= p_vpar->sequence.i_width;
1897 p_dest[0] += i_width * 16;
1898 p_dest[1] += i_chroma_tmp;
1899 p_dest[2] += i_chroma_tmp;
1900 p_f_motion->pppi_ref[0][0] += i_width * 16;
1901 p_f_motion->pppi_ref[0][1] += i_chroma_tmp;
1902 p_f_motion->pppi_ref[0][2] += i_chroma_tmp;
1903 p_f_motion->pppi_ref[1][0] += i_width * 16;
1904 p_f_motion->pppi_ref[1][1] += i_chroma_tmp;
1905 p_f_motion->pppi_ref[1][2] += i_chroma_tmp;
1910 /* Decode macroblocks. */
1911 macroblock_t * p_mb;
1914 /* Get a macroblock structure. */
1915 p_mb = p_vpar->pool.pf_new_mb( &p_vpar->pool );
1916 p_mb->i_nb_motions = 0;
1917 p_mb->pp_dest[0] = p_dest[0];
1918 p_mb->pp_dest[1] = p_dest[1];
1919 p_mb->pp_dest[2] = p_dest[2];
1921 /* Parse off macroblock_modes structure. */
1922 p_mb->i_mb_modes = i_mb_modes =
1923 MacroblockModes( p_vpar, p_mb, i_coding_type, i_structure );
1925 if( i_mb_modes & MB_QUANT )
1927 LoadQuantizerScale( p_vpar );
1930 if( i_mb_modes & MB_INTRA )
1932 if( p_vpar->picture.b_concealment_mv )
1934 if( i_structure == FRAME_STRUCTURE )
1936 MotionFrameConceal( p_vpar, p_mb, p_f_motion );
1940 MotionFieldConceal( p_vpar, p_mb, p_f_motion );
1945 /* Reset motion vectors predictors. */
1946 p_f_motion->ppi_pmv[0][0] = p_f_motion->ppi_pmv[0][1] = 0;
1947 p_f_motion->ppi_pmv[1][0] = p_f_motion->ppi_pmv[1][1] = 0;
1948 p_b_motion->ppi_pmv[0][0] = p_b_motion->ppi_pmv[0][1] = 0;
1949 p_b_motion->ppi_pmv[1][0] = p_b_motion->ppi_pmv[1][1] = 0;
1955 if( p_vpar->picture.b_intra_vlc_format )
1957 MPEG2IntraB15MB( p_vpar, p_mb );
1961 MPEG2IntraB14MB( p_vpar, p_mb );
1966 MPEG1IntraMB( p_vpar, p_mb );
1969 if( i_coding_type == D_CODING_TYPE )
1971 RemoveBits( &p_vpar->bit_stream, 1 );
1976 /* Non-intra block */
1979 if( (i_mb_modes & MOTION_TYPE_MASK) == MC_FRAME )
1981 MOTION( MotionMPEG1, i_mb_modes );
1985 /* Non-intra MB without forward mv in a P picture. */
1986 p_f_motion->ppi_pmv[0][0] = p_f_motion->ppi_pmv[0][1] = 0;
1987 p_f_motion->ppi_pmv[1][0] = p_f_motion->ppi_pmv[1][1] = 0;
1988 MOTION( MotionFrameZero, MB_MOTION_FORWARD );
1991 else if( i_structure == FRAME_STRUCTURE )
1993 switch( i_mb_modes & MOTION_TYPE_MASK )
1996 MOTION( MotionFrameFrame, i_mb_modes );
2000 MOTION( MotionFrameField, i_mb_modes );
2004 MOTION( MotionFrameDMV, MB_MOTION_FORWARD );
2008 /* Non-intra MB without forward mv in a P picture. */
2009 p_f_motion->ppi_pmv[0][0] = p_f_motion->ppi_pmv[0][1] = 0;
2010 p_f_motion->ppi_pmv[1][0] = p_f_motion->ppi_pmv[1][1] = 0;
2011 MOTION( MotionFrameZero, MB_MOTION_FORWARD );
2016 /* Field structure. */
2017 switch( i_mb_modes & MOTION_TYPE_MASK )
2020 MOTION( MotionFieldField, i_mb_modes );
2024 MOTION( MotionField16x8, i_mb_modes );
2028 MOTION( MotionFieldDMV, i_mb_modes );
2032 /* Non-intra MB without forward mv in a P picture. */
2033 p_f_motion->ppi_pmv[0][0] = p_f_motion->ppi_pmv[0][1] = 0;
2034 p_f_motion->ppi_pmv[1][0] = p_f_motion->ppi_pmv[1][1] = 0;
2035 MOTION( MotionFieldZero, MB_MOTION_FORWARD );
2039 /* ISO/IEC 13818-2 6.3.17.4 : Coded Block Pattern */
2040 if( i_mb_modes & MB_PATTERN )
2042 p_mb->i_coded_block_pattern = CodedPattern( p_vpar );
2045 MPEG2NonIntraMB( p_vpar, p_mb );
2049 MPEG1NonIntraMB( p_vpar, p_mb );
2054 p_mb->i_coded_block_pattern = 0;
2057 /* Reset intra DC coefficients predictors. */
2058 p_vpar->mb.pi_dc_dct_pred[0] = p_vpar->mb.pi_dc_dct_pred[1]
2059 = p_vpar->mb.pi_dc_dct_pred[2]
2060 = 1 << (7 + p_vpar->picture.i_intra_dc_precision);
2063 /* End of macroblock. */
2065 p_vpar->pool.pf_decode_mb( &p_vpar->pool, p_mb );
2067 /* Prepare context for the next macroblock. */
2068 p_vpar->mb.i_offset += 16;
2071 if( ShowBits( &p_vpar->bit_stream, 1 ) )
2073 /* Macroblock Address Increment == 1 */
2074 RemoveBits( &p_vpar->bit_stream, 1 );
2078 /* Check for skipped macroblock(s). */
2081 i_mba_inc = MacroblockAddressIncrement( p_vpar );
2088 /* Reset intra DC predictors. */
2089 p_vpar->mb.pi_dc_dct_pred[0] = p_vpar->mb.pi_dc_dct_pred[1]
2090 = p_vpar->mb.pi_dc_dct_pred[2]
2091 = 1 << (7 + p_vpar->picture.i_intra_dc_precision);
2093 if( i_coding_type == P_CODING_TYPE )
2095 p_f_motion->ppi_pmv[0][0] = p_f_motion->ppi_pmv[0][1] = 0;
2096 p_f_motion->ppi_pmv[1][0] = p_f_motion->ppi_pmv[1][1] = 0;
2099 p_mb = p_vpar->pool.pf_new_mb( &p_vpar->pool );
2100 p_mb->i_mb_modes = 0;
2101 p_mb->i_nb_motions = 0;
2102 p_mb->i_coded_block_pattern = 0;
2103 p_mb->pp_dest[0] = p_dest[0];
2104 p_mb->pp_dest[1] = p_dest[1];
2105 p_mb->pp_dest[2] = p_dest[2];
2107 if( i_structure == FRAME_STRUCTURE )
2109 MOTION( MotionFrameZero, MB_MOTION_FORWARD );
2113 MOTION( MotionFieldZero, MB_MOTION_FORWARD );
2116 p_vpar->pool.pf_decode_mb( &p_vpar->pool, p_mb );
2117 p_vpar->mb.i_offset += 16;
2119 } while( --i_mba_inc );
2124 p_mb = p_vpar->pool.pf_new_mb( &p_vpar->pool );
2125 p_mb->i_mb_modes = 0;
2126 p_mb->i_nb_motions = 0;
2127 p_mb->i_coded_block_pattern = 0;
2128 p_mb->pp_dest[0] = p_dest[0];
2129 p_mb->pp_dest[1] = p_dest[1];
2130 p_mb->pp_dest[2] = p_dest[2];
2134 MOTION( MotionMPEG1Reuse, i_mb_modes );
2136 else if( i_structure == FRAME_STRUCTURE )
2138 MOTION( MotionFrameReuse, i_mb_modes );
2142 MOTION( MotionFieldReuse, i_mb_modes );
2145 p_vpar->pool.pf_decode_mb( &p_vpar->pool, p_mb );
2146 p_vpar->mb.i_offset += 16;
2148 } while( --i_mba_inc );
2153 NextStartCode( &p_vpar->bit_stream );
2156 /*****************************************************************************
2157 * PictureData : Parse off all macroblocks (ISO/IEC 13818-2 6.2.3.7)
2158 *****************************************************************************/
2159 static __inline__ void vpar_PictureData( vpar_thread_t * p_vpar,
2161 int i_coding_type, int i_structure )
2165 NextStartCode( &p_vpar->bit_stream );
2166 while( !p_vpar->picture.b_error && !p_vpar->p_fifo->b_die )
2168 if( ((i_dummy = ShowBits( &p_vpar->bit_stream, 32 ))
2169 < SLICE_START_CODE_MIN) ||
2170 (i_dummy > SLICE_START_CODE_MAX) )
2174 RemoveBits32( &p_vpar->bit_stream );
2176 /* Decode slice data. */
2177 ParseSlice( p_vpar, i_dummy & 255, b_mpeg2, i_coding_type,
2182 #define DECLARE_PICD( FUNCNAME, B_MPEG2, I_CODING_TYPE, I_STRUCTURE ) \
2183 void FUNCNAME( vpar_thread_t * p_vpar ) \
2185 vpar_PictureData( p_vpar, B_MPEG2, I_CODING_TYPE, I_STRUCTURE ); \
2188 DECLARE_PICD( vpar_PictureDataGENERIC, p_vpar->sequence.b_mpeg2,
2189 p_vpar->picture.i_coding_type, p_vpar->picture.i_structure );
2190 #if (VPAR_OPTIM_LEVEL > 0)
2191 DECLARE_PICD( vpar_PictureData2IF, 1, I_CODING_TYPE, FRAME_STRUCTURE );
2192 DECLARE_PICD( vpar_PictureData2PF, 1, P_CODING_TYPE, FRAME_STRUCTURE );
2193 DECLARE_PICD( vpar_PictureData2BF, 1, B_CODING_TYPE, FRAME_STRUCTURE );
2195 #if (VPAR_OPTIM_LEVEL > 1)
2196 DECLARE_PICD( vpar_PictureData2IT, 1, I_CODING_TYPE, TOP_FIELD );
2197 DECLARE_PICD( vpar_PictureData2PT, 1, P_CODING_TYPE, TOP_FIELD );
2198 DECLARE_PICD( vpar_PictureData2BT, 1, B_CODING_TYPE, TOP_FIELD );
2199 DECLARE_PICD( vpar_PictureData2IB, 1, I_CODING_TYPE, BOTTOM_FIELD );
2200 DECLARE_PICD( vpar_PictureData2PB, 1, P_CODING_TYPE, BOTTOM_FIELD );
2201 DECLARE_PICD( vpar_PictureData2BB, 1, B_CODING_TYPE, BOTTOM_FIELD );
2202 DECLARE_PICD( vpar_PictureData1I, 0, I_CODING_TYPE, FRAME_STRUCTURE );
2203 DECLARE_PICD( vpar_PictureData1P, 0, P_CODING_TYPE, FRAME_STRUCTURE );
2204 DECLARE_PICD( vpar_PictureData1B, 0, B_CODING_TYPE, FRAME_STRUCTURE );
2205 DECLARE_PICD( vpar_PictureData1D, 0, D_CODING_TYPE, FRAME_STRUCTURE );