1 /*****************************************************************************
2 * video_parser.h : video parser thread
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: video_parser.h,v 1.34 2001/05/06 04:32:02 sam Exp $
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
36 *****************************************************************************/
38 /*****************************************************************************
40 *****************************************************************************
41 * This rotative FIFO contains undecoded macroblocks that are to be decoded
42 *****************************************************************************/
45 typedef struct video_fifo_s
48 vlc_mutex_t lock; /* fifo data lock */
49 vlc_cond_t wait; /* fifo data conditional variable */
51 /* buffer is an array of undec_picture_t pointers */
52 macroblock_t * buffer[VFIFO_SIZE + 1];
59 struct vpar_thread_s * p_vpar;
62 /*****************************************************************************
64 *****************************************************************************
65 * This structure enables the parser to maintain a list of free
66 * macroblock_t structures
67 *****************************************************************************/
69 typedef struct video_buffer_s
71 vlc_mutex_t lock; /* buffer data lock */
73 macroblock_t p_macroblocks[VFIFO_SIZE + 1];
74 macroblock_t * pp_mb_free[VFIFO_SIZE+1]; /* this is a LIFO */
79 /*****************************************************************************
80 * vpar_thread_t: video parser thread descriptor
81 *****************************************************************************
83 *****************************************************************************/
84 typedef struct vpar_thread_s
86 bit_stream_t bit_stream;
88 /* Thread properties and locks */
89 vlc_thread_t thread_id; /* id for thread functions */
91 /* Thread configuration */
96 /* Input properties */
97 decoder_fifo_t * p_fifo; /* PES input fifo */
98 vdec_config_t * p_config;
100 /* Output properties */
101 vout_thread_t * p_vout; /* video output thread */
103 /* Decoder properties */
104 struct vdec_thread_s * pp_vdec[NB_VDEC];
107 video_buffer_t vbuffer;
110 /* Parser properties */
112 picture_parsing_t picture;
113 macroblock_parsing_t mb;
114 video_synchro_t synchro;
117 lookup_t pl_mb_addr_inc[2048]; /* for macroblock
119 /* tables for macroblock types 0=P 1=B */
120 lookup_t ppl_mb_type[2][64];
121 /* table for coded_block_pattern */
122 lookup_t * pl_coded_pattern;
123 /* variable length codes for the structure dct_dc_size for intra blocks */
124 lookup_t * pppl_dct_dc_size[2][2];
125 /* Structure to store the tables B14 & B15 (ISO/IEC 13818-2 B.4) */
126 dct_lookup_t ppl_dct_coef[2][16384];
129 /* Default quantization matrices */
130 u8 pi_default_intra_quant[64];
131 u8 pi_default_nonintra_quant[64];
133 /* Motion compensation plugin used and shortcuts */
134 struct module_s * p_motion_module;
135 void ( * pppf_motion[4][2][4] ) ( struct macroblock_s * );
136 void ( * ppf_motion_skipped[4][4] ) ( struct macroblock_s * );
138 /* IDCT plugin used and shortcuts to access its capabilities */
139 struct module_s * p_idct_module;
140 void ( * pf_idct_init ) ( struct vdec_thread_s * );
141 void ( * pf_sparse_idct ) ( struct vdec_thread_s *, dctelem_t*, int );
142 void ( * pf_idct ) ( struct vdec_thread_s *, dctelem_t*, int );
143 void ( * pf_norm_scan ) ( u8 ppi_scan[2][64] );
144 void ( * pf_vdec_init ) ( struct vdec_thread_s * );
145 void ( * pf_decode_mb_c ) ( struct vdec_thread_s *, struct macroblock_s * );
146 void ( * pf_decode_mb_bw )( struct vdec_thread_s *, struct macroblock_s * );
150 count_t c_loops; /* number of loops */
151 count_t c_sequences; /* number of sequences */
152 count_t pc_pictures[4]; /* number of (coding_type) pictures read */
153 count_t pc_decoded_pictures[4]; /* number of (coding_type)
154 * pictures decoded */
155 count_t pc_malformed_pictures[4]; /* number of pictures trashed
160 /*****************************************************************************
162 *****************************************************************************/
164 /* Thread management functions */
165 vlc_thread_t vpar_CreateThread ( vdec_config_t * );
167 /*****************************************************************************
168 * NextStartCode : Find the next start code
169 *****************************************************************************/
170 static __inline__ void NextStartCode( bit_stream_t * p_bit_stream )
172 /* Re-align the buffer on an 8-bit boundary */
173 RealignBits( p_bit_stream );
175 while( ShowBits( p_bit_stream, 24 ) != 0x01L
176 && !p_bit_stream->p_decoder_fifo->b_die )
178 RemoveBits( p_bit_stream, 8 );
182 /*****************************************************************************
184 *****************************************************************************
185 * Quantizer scale factor (ISO/IEC 13818-2 7.4.2.2)
186 *****************************************************************************/
187 static __inline__ void LoadQuantizerScale( struct vpar_thread_s * p_vpar )
189 /* Quantization coefficient table */
190 static u8 ppi_quantizer_scale[3][32] =
196 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,
197 32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62
201 0, 1, 2, 3, 4, 5, 6, 7, 8, 10,12,14,16,18,20, 22,
202 24,28,32,36,40,44,48,52,56,64,72,80,88,96,104,112
206 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
207 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
211 p_vpar->mb.i_quantizer_scale = ppi_quantizer_scale
212 [(!p_vpar->sequence.b_mpeg2 << 1) | p_vpar->picture.b_q_scale_type]
213 [GetBits( &p_vpar->bit_stream, 5 )];