]> git.sesse.net Git - vlc/blob - plugins/mpeg_vdec/vpar_pool.h
All decoders (audio, video, subtitles) are now modules.
[vlc] / plugins / mpeg_vdec / vpar_pool.h
1 /*****************************************************************************
2  * vpar_pool.h : video parser/video decoders communication
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: vpar_pool.h,v 1.1 2001/11/13 12:09:18 henri 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  * vdec_pool_t
26  *****************************************************************************
27  * This structure is used for the communication between the parser and the
28  * decoders.
29  *****************************************************************************/
30 typedef struct vdec_pool_s
31 {
32     /* Locks */
33     vlc_mutex_t         lock;                         /* Structure data lock */
34     vlc_cond_t          wait_empty;      /* The parser blocks there when all
35                                           * decoder threads are busy         */
36     vlc_cond_t          wait_undecoded; /* The decoders block there when no
37                                          * macroblock has been given by the
38                                          * parser */
39
40     /* Video decoder threads */
41     struct vdec_thread_s ** pp_vdec;       /* Array of video decoder threads */
42     int                 i_smp;     /* Number of symmetrical decoder threads,
43                                     * hence size of the pp_vdec, p_macroblocks
44                                     * and pp_new_macroblocks array */
45
46     /* Macroblocks */
47     macroblock_t *      p_macroblocks;
48
49     /* Empty macroblocks */
50     macroblock_t **     pp_empty_macroblocks;           /* Empty macroblocks */
51     int                 i_index_empty;              /* Last empty macroblock */
52
53     /* Undecoded macroblocks, read by the decoders */
54     macroblock_t **     pp_new_macroblocks;         /* Undecoded macroblocks */
55     int                 i_index_new;            /* Last undecoded macroblock */
56
57     /* Undecoded macroblock, used when the parser and the decoder share the
58      * same thread */
59     macroblock_t        mb;
60     struct vdec_thread_s * p_vdec;                     /* Fake video decoder */
61
62     /* Pointers to usual pool functions */
63     void             (* pf_wait_pool) ( struct vdec_pool_s * );
64     macroblock_t *   (* pf_new_mb) ( struct vdec_pool_s * );
65     void             (* pf_free_mb) ( struct vdec_pool_s *,
66                                       struct macroblock_s * );
67     void             (* pf_decode_mb) ( struct vdec_pool_s *,
68                                         struct macroblock_s * );
69
70     /* Pointer to the decoding function - used for B&W switching */
71     void             (* pf_vdec_decode) ( struct vdec_thread_s *,
72                                           struct macroblock_s * );
73     boolean_t           b_bw;                      /* Current value for B&W */
74
75     /* Access to the plug-ins needed by the video decoder thread */
76     void ( * pf_idct_init )   ( void ** );
77     void ( * ppppf_motion[2][2][4] ) ( yuv_data_t *, yuv_data_t *,
78                                        int, int );
79
80     struct vpar_thread_s * p_vpar;
81 } vdec_pool_t;
82
83 /*****************************************************************************
84  * Prototypes
85  *****************************************************************************/
86 void vpar_InitPool( struct vpar_thread_s * );
87 void vpar_SpawnPool( struct vpar_thread_s * );
88 void vpar_EndPool( struct vpar_thread_s * );
89
90 /*****************************************************************************
91  * vpar_GetMacroblock: In a vdec thread, get the next available macroblock
92  *****************************************************************************/
93 static __inline__ macroblock_t * vpar_GetMacroblock( vdec_pool_t * p_pool,
94                                                      boolean_t * pb_die )
95 {
96     macroblock_t *  p_mb;
97
98     vlc_mutex_lock( &p_pool->lock );
99     while( p_pool->i_index_new == 0 && !*pb_die )
100     {
101         vlc_cond_wait( &p_pool->wait_undecoded, &p_pool->lock );
102     }
103
104     if( *pb_die )
105     {
106         vlc_mutex_unlock( &p_pool->lock );
107         return( NULL );
108     }
109
110     p_mb = p_pool->pp_new_macroblocks[ --p_pool->i_index_new ];
111     vlc_mutex_unlock( &p_pool->lock );
112     return( p_mb );
113 }
114