]> git.sesse.net Git - vlc/blob - include/video_parser.h
Encore un commit venu tout droit des abysses de l'enfer, d�sol� pour
[vlc] / include / video_parser.h
1 /*****************************************************************************
2  * video_parser.h : video parser thread
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  *
6  * Authors:
7  *
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.
12  *
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 GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this program; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Requires:
26  *  "config.h"
27  *  "common.h"
28  *  "mtime.h"
29  *  "threads.h"
30  *  "input.h"
31  *  "video.h"
32  *  "video_output.h"
33  *  "decoder_fifo.h"
34  *  "video_fifo.h"
35  *  "vpar_headers.h"
36  *****************************************************************************/
37
38 /*****************************************************************************
39  * video_fifo_t
40  *****************************************************************************
41  * This rotative FIFO contains undecoded macroblocks that are to be decoded
42  *****************************************************************************/
43 struct vpar_thread_s;
44
45 typedef struct video_fifo_s
46 {
47 #ifdef VDEC_SMP
48     vlc_mutex_t         lock;                              /* fifo data lock */
49     vlc_cond_t          wait;              /* fifo data conditional variable */
50
51     /* buffer is an array of undec_picture_t pointers */
52     macroblock_t *      buffer[VFIFO_SIZE + 1];
53     int                 i_start;
54     int                 i_end;
55 #else
56     macroblock_t        buffer;
57 #endif
58
59     struct vpar_thread_s *      p_vpar;
60 } video_fifo_t;
61
62 /*****************************************************************************
63  * video_buffer_t
64  *****************************************************************************
65  * This structure enables the parser to maintain a list of free
66  * macroblock_t structures
67  *****************************************************************************/
68 #ifdef VDEC_SMP
69 typedef struct video_buffer_s
70 {
71     vlc_mutex_t         lock;                            /* buffer data lock */
72
73     macroblock_t        p_macroblocks[VFIFO_SIZE + 1];
74     macroblock_t *      pp_mb_free[VFIFO_SIZE+1];          /* this is a LIFO */
75     int                 i_index;
76 } video_buffer_t;
77 #endif
78
79 /*****************************************************************************
80  * vpar_thread_t: video parser thread descriptor
81  *****************************************************************************
82  * XXX??
83  *****************************************************************************/
84 typedef struct vpar_thread_s
85 {
86     /* Thread properties and locks */
87     boolean_t           b_die;                                 /* `die' flag */
88     boolean_t           b_run;                                 /* `run' flag */
89     boolean_t           b_error;                             /* `error' flag */
90     boolean_t           b_active;                           /* `active' flag */
91     vlc_thread_t        thread_id;                /* id for thread functions */
92
93     /* Thread configuration */
94     /* XXX?? */
95 //    int *pi_status;
96
97
98     /* Input properties */
99     decoder_fifo_t      fifo;                              /* PES input fifo */
100
101     /* The bit stream structure handles the PES stream at the bit level */
102     bit_stream_t        bit_stream;
103
104     /* Output properties */
105     vout_thread_t *     p_vout;                       /* video output thread */
106
107     /* Decoder properties */
108     struct vdec_thread_s *      pp_vdec[NB_VDEC];
109     video_fifo_t                vfifo;
110 #ifdef VDEC_SMP
111     video_buffer_t              vbuffer;
112 #endif
113
114     /* Parser properties */
115     sequence_t              sequence;
116     picture_parsing_t       picture;
117     macroblock_parsing_t    mb;
118     video_synchro_t         synchro;
119
120     /* Lookup tables */
121 #ifdef MPEG2_COMPLIANT
122     s16                     pi_crop_buf[8192];
123     s16 *                   pi_crop;
124 #endif
125     lookup_t                pl_mb_addr_inc[2048];    /* for macroblock
126                                                         address increment */
127     /* tables for macroblock types 0=P 1=B */
128     lookup_t                ppl_mb_type[2][64];
129     /* table for coded_block_pattern */
130     lookup_t *              pl_coded_pattern;
131     /* variable length codes for the structure dct_dc_size for intra blocks */
132     lookup_t *              pppl_dct_dc_size[2][2];
133     /* Structure to store the tables B14 & B15 (ISO/CEI 13818-2 B.4) */
134      dct_lookup_t           ppl_dct_coef[2][16384];
135
136
137
138 #ifdef STATS
139     /* Statistics */
140     count_t         c_loops;                              /* number of loops */
141     count_t         c_idle_loops;                    /* number of idle loops */
142     count_t         c_sequences;                      /* number of sequences */
143     count_t         c_pictures;                   /* number of pictures read */
144     count_t         c_i_pictures;               /* number of I pictures read */
145     count_t         c_p_pictures;               /* number of P pictures read */
146     count_t         c_b_pictures;               /* number of B pictures read */
147     count_t         c_decoded_pictures;        /* number of pictures decoded */
148     count_t         c_decoded_i_pictures;    /* number of I pictures decoded */
149     count_t         c_decoded_p_pictures;    /* number of P pictures decoded */
150     count_t         c_decoded_b_pictures;    /* number of B pictures decoded */
151 #endif
152 } vpar_thread_t;
153
154 /*****************************************************************************
155  * Prototypes
156  *****************************************************************************/
157
158 /* Thread management functions */
159 vpar_thread_t * vpar_CreateThread       ( /* video_cfg_t *p_cfg, */ input_thread_t *p_input /*,
160                                           vout_thread_t *p_vout, int *pi_status */ );
161 void            vpar_DestroyThread      ( vpar_thread_t *p_vpar /*, int *pi_status */ );
162
163 /* Time management functions */
164 /* XXX?? */
165
166 /* Dynamic thread settings */
167 /* XXX?? */
168
169
170 /*****************************************************************************
171  * NextStartCode : Find the next start code
172  *****************************************************************************/
173 static __inline__ void NextStartCode( vpar_thread_t * p_vpar )
174 {
175     /* Re-align the buffer on an 8-bit boundary */
176     RealignBits( &p_vpar->bit_stream );
177
178     while( ShowBits( &p_vpar->bit_stream, 24 ) != 0x01L && !p_vpar->b_die )
179     {
180         RemoveBits( &p_vpar->bit_stream, 8 );
181     }
182 }
183
184 /*****************************************************************************
185  * LoadQuantizerScale
186  *****************************************************************************
187  * Quantizer scale factor (ISO/IEC 13818-2 7.4.2.2)
188  *****************************************************************************/
189 static __inline__ void LoadQuantizerScale( struct vpar_thread_s * p_vpar )
190 {
191     /* Quantization coefficient table */
192     static u8   ppi_quantizer_scale[3][32] =
193     {
194         /* MPEG-2 */
195         {
196             /* q_scale_type */
197             /* linear */
198             0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,
199             32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62
200         },
201         {
202             /* non-linear */
203             0, 1, 2, 3, 4, 5, 6, 7, 8, 10,12,14,16,18,20, 22,
204             24,28,32,36,40,44,48,52,56,64,72,80,88,96,104,112
205         },
206         /* MPEG-1 */
207         {
208             0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
209             16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
210         }
211     };
212
213     p_vpar->mb.i_quantizer_scale = ppi_quantizer_scale
214            [(!p_vpar->sequence.b_mpeg2 << 1) | p_vpar->picture.b_q_scale_type]
215            [GetBits( &p_vpar->bit_stream, 5 )];
216 }
217