1 /*****************************************************************************
2 * video_parser.h : video parser thread
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
21 *****************************************************************************/
23 /*****************************************************************************
35 *****************************************************************************/
37 /*****************************************************************************
39 *****************************************************************************
40 * This rotative FIFO contains undecoded macroblocks that are to be decoded
41 *****************************************************************************/
44 typedef struct video_fifo_s
47 vlc_mutex_t lock; /* fifo data lock */
48 vlc_cond_t wait; /* fifo data conditional variable */
50 /* buffer is an array of undec_picture_t pointers */
51 macroblock_t * buffer[VFIFO_SIZE + 1];
58 struct vpar_thread_s * p_vpar;
61 /*****************************************************************************
63 *****************************************************************************
64 * This structure enables the parser to maintain a list of free
65 * macroblock_t structures
66 *****************************************************************************/
68 typedef struct video_buffer_s
70 vlc_mutex_t lock; /* buffer data lock */
72 macroblock_t p_macroblocks[VFIFO_SIZE + 1];
73 macroblock_t * pp_mb_free[VFIFO_SIZE+1]; /* this is a LIFO */
78 /*****************************************************************************
79 * vpar_thread_t: video parser thread descriptor
80 *****************************************************************************
82 *****************************************************************************/
83 typedef struct vpar_thread_s
85 /* Thread properties and locks */
86 boolean_t b_die; /* `die' flag */
87 boolean_t b_run; /* `run' flag */
88 boolean_t b_error; /* `error' flag */
89 boolean_t b_active; /* `active' flag */
90 vlc_thread_t thread_id; /* id for thread functions */
92 /* Thread configuration */
97 /* Input properties */
98 decoder_fifo_t fifo; /* PES input fifo */
100 /* The bit stream structure handles the PES stream at the bit level */
101 bit_stream_t bit_stream;
103 /* Output properties */
104 vout_thread_t * p_vout; /* video output thread */
106 /* Decoder properties */
107 struct vdec_thread_s * pp_vdec[NB_VDEC];
110 video_buffer_t vbuffer;
113 /* Parser properties */
115 picture_parsing_t picture;
116 macroblock_parsing_t mb;
117 video_synchro_t synchro;
120 #ifdef MPEG2_COMPLIANT
121 s16 pi_crop_buf[8192];
124 lookup_t pl_mb_addr_inc[2048]; /* for macroblock
126 /* tables for macroblock types 0=P 1=B */
127 lookup_t ppl_mb_type[2][64];
128 /* table for coded_block_pattern */
129 lookup_t * pl_coded_pattern;
130 /* variable length codes for the structure dct_dc_size for intra blocks */
131 lookup_t * pppl_dct_dc_size[2][2];
132 /* Structure to store the tables B14 & B15 (ISO/CEI 13818-2 B.4) */
133 dct_lookup_t ppl_dct_coef[2][16384];
139 count_t c_loops; /* number of loops */
140 count_t c_idle_loops; /* number of idle loops */
141 count_t c_sequences; /* number of sequences */
142 count_t c_pictures; /* number of pictures read */
143 count_t c_i_pictures; /* number of I pictures read */
144 count_t c_p_pictures; /* number of P pictures read */
145 count_t c_b_pictures; /* number of B pictures read */
146 count_t c_decoded_pictures; /* number of pictures decoded */
147 count_t c_decoded_i_pictures; /* number of I pictures decoded */
148 count_t c_decoded_p_pictures; /* number of P pictures decoded */
149 count_t c_decoded_b_pictures; /* number of B pictures decoded */
153 /*****************************************************************************
155 *****************************************************************************/
157 /* Thread management functions */
158 vpar_thread_t * vpar_CreateThread ( /* video_cfg_t *p_cfg, */ input_thread_t *p_input /*,
159 vout_thread_t *p_vout, int *pi_status */ );
160 void vpar_DestroyThread ( vpar_thread_t *p_vpar /*, int *pi_status */ );
162 /* Time management functions */
165 /* Dynamic thread settings */
169 /*****************************************************************************
170 * NextStartCode : Find the next start code
171 *****************************************************************************/
172 static __inline__ void NextStartCode( vpar_thread_t * p_vpar )
174 /* Re-align the buffer on an 8-bit boundary */
175 RealignBits( &p_vpar->bit_stream );
177 while( ShowBits( &p_vpar->bit_stream, 24 ) != 0x01L && !p_vpar->b_die )
179 RemoveBits( &p_vpar->bit_stream, 8 );
183 /*****************************************************************************
185 *****************************************************************************
186 * Quantizer scale factor (ISO/IEC 13818-2 7.4.2.2)
187 *****************************************************************************/
188 static __inline__ void LoadQuantizerScale( struct vpar_thread_s * p_vpar )
190 /* Quantization coefficient table */
191 static u8 ppi_quantizer_scale[3][32] =
197 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,
198 32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62
202 0, 1, 2, 3, 4, 5, 6, 7, 8, 10,12,14,16,18,20, 22,
203 24,28,32,36,40,44,48,52,56,64,72,80,88,96,104,112
207 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
208 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
212 p_vpar->mb.i_quantizer_scale = ppi_quantizer_scale
213 [(!p_vpar->sequence.b_mpeg2 << 1) | p_vpar->picture.b_q_scale_type]
214 [GetBits( &p_vpar->bit_stream, 5 )];