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