]> git.sesse.net Git - vlc/blob - src/video_decoder/video_parser.h
. the IDCT functions are now located in modules : the classic IDCT,
[vlc] / src / video_decoder / video_parser.h
1 /*****************************************************************************
2  * video_parser.h : video parser thread
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: video_parser.h,v 1.3 2001/01/13 12:57:20 sam Exp $
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
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     vlc_thread_t        thread_id;                /* id for thread functions */
88
89     /* Thread configuration */
90     /* XXX?? */
91 //    int *pi_status;
92
93
94     /* Input properties */
95     decoder_fifo_t *    p_fifo;                            /* PES input fifo */
96     bit_stream_t        bit_stream;
97     vdec_config_t *     p_config;
98     /* Bitstream context */
99     mtime_t             next_pts, next_dts;
100
101     /* Output properties */
102     vout_thread_t *     p_vout;                       /* video output thread */
103
104     /* Decoder properties */
105     struct vdec_thread_s *      pp_vdec[NB_VDEC];
106     video_fifo_t                vfifo;
107 #ifdef VDEC_SMP
108     video_buffer_t              vbuffer;
109 #endif
110
111     /* Parser properties */
112     sequence_t              sequence;
113     picture_parsing_t       picture;
114     macroblock_parsing_t    mb;
115     video_synchro_t         synchro;
116
117     /* Lookup tables */
118 #ifdef MPEG2_COMPLIANT
119     s16                     pi_crop_buf[8192];
120     s16 *                   pi_crop;
121 #endif
122     lookup_t                pl_mb_addr_inc[2048];    /* for macroblock
123                                                         address increment */
124     /* tables for macroblock types 0=P 1=B */
125     lookup_t                ppl_mb_type[2][64];
126     /* table for coded_block_pattern */
127     lookup_t *              pl_coded_pattern;
128     /* variable length codes for the structure dct_dc_size for intra blocks */
129     lookup_t *              pppl_dct_dc_size[2][2];
130     /* Structure to store the tables B14 & B15 (ISO/CEI 13818-2 B.4) */
131     dct_lookup_t            ppl_dct_coef[2][16384];
132
133     /* IDCT plugin used and shortcuts to access its capabilities */
134     struct module_s *       p_module;
135     idct_init_t             pf_init;
136     f_idct_t                pf_sparse_idct;
137     f_idct_t                pf_idct;
138
139 #ifdef STATS
140     /* Statistics */
141     count_t         c_loops;                              /* number of loops */
142     count_t         c_sequences;                      /* number of sequences */
143     count_t         pc_pictures[4]; /* number of (coding_type) pictures read */
144     count_t         pc_decoded_pictures[4];       /* number of (coding_type)
145                                                    *        pictures decoded */
146     count_t         pc_malformed_pictures[4];  /* number of pictures trashed
147                                                 * during parsing             */
148 #endif
149 } vpar_thread_t;
150
151 /*****************************************************************************
152  * Prototypes
153  *****************************************************************************/
154
155 /* Thread management functions */
156 vlc_thread_t vpar_CreateThread       ( vdec_config_t * );
157
158 /*****************************************************************************
159  * NextStartCode : Find the next start code
160  *****************************************************************************/
161 static __inline__ void NextStartCode( bit_stream_t * p_bit_stream )
162 {
163     /* Re-align the buffer on an 8-bit boundary */
164     RealignBits( p_bit_stream );
165
166     while( ShowBits( p_bit_stream, 24 ) != 0x01L
167             && !p_bit_stream->p_decoder_fifo->b_die )
168     {
169         RemoveBits( p_bit_stream, 8 );
170     }
171 }
172
173 /*****************************************************************************
174  * LoadQuantizerScale
175  *****************************************************************************
176  * Quantizer scale factor (ISO/IEC 13818-2 7.4.2.2)
177  *****************************************************************************/
178 static __inline__ void LoadQuantizerScale( struct vpar_thread_s * p_vpar )
179 {
180     /* Quantization coefficient table */
181     static u8   ppi_quantizer_scale[3][32] =
182     {
183         /* MPEG-2 */
184         {
185             /* q_scale_type */
186             /* linear */
187             0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,
188             32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62
189         },
190         {
191             /* non-linear */
192             0, 1, 2, 3, 4, 5, 6, 7, 8, 10,12,14,16,18,20, 22,
193             24,28,32,36,40,44,48,52,56,64,72,80,88,96,104,112
194         },
195         /* MPEG-1 */
196         {
197             0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
198             16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
199         }
200     };
201
202     p_vpar->mb.i_quantizer_scale = ppi_quantizer_scale
203            [(!p_vpar->sequence.b_mpeg2 << 1) | p_vpar->picture.b_q_scale_type]
204            [GetBits( &p_vpar->bit_stream, 5 )];
205 }
206