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