]> git.sesse.net Git - vlc/blob - src/video_decoder/video_decoder.c
Initial revision
[vlc] / src / video_decoder / video_decoder.c
1 /*******************************************************************************
2  * video_decoder.c : video decoder thread
3  * (c)1999 VideoLAN
4  *******************************************************************************/
5
6 /* ?? passer en terminate/destroy avec les signaux supplĂ©mentaires */
7
8 /*******************************************************************************
9  * Preamble
10  *******************************************************************************/
11 #include <errno.h>
12 #include <pthread.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <string.h>
16 #include <sys/uio.h>
17 #include <X11/Xlib.h>
18 #include <X11/extensions/XShm.h>
19
20 #include "config.h"
21 #include "common.h"
22 #include "mtime.h"
23
24 #include "intf_msg.h"
25 #include "debug.h"                      /* ?? temporaire, requis par netlist.h */
26
27 #include "input.h"
28 #include "input_netlist.h"
29 #include "decoder_fifo.h"
30 #include "video.h"
31 #include "video_output.h"
32 #include "video_decoder.h"
33
34 /*
35  * Local prototypes
36  */
37 static int      CheckConfiguration  ( video_cfg_t *p_cfg );
38 static int      InitThread          ( vdec_thread_t *p_vdec );
39 static void     RunThread           ( vdec_thread_t *p_vdec );
40 static void     ErrorThread         ( vdec_thread_t *p_vdec );
41 static void     EndThread           ( vdec_thread_t *p_vdec );
42
43 /*******************************************************************************
44  * vdec_CreateThread: create a generic decoder thread
45  *******************************************************************************
46  * This function creates a new video decoder thread, and returns a pointer
47  * to its description. On error, it returns NULL.
48  * Following configuration properties are used:
49  * ??
50  *******************************************************************************/
51 vdec_thread_t * vdec_CreateThread( video_cfg_t *p_cfg, input_thread_t *p_input,
52                                    vout_thread_t *p_vout, int *pi_status )
53 {
54     /* ?? */
55 }
56
57 /*******************************************************************************
58  * vdec_DestroyThread: destroy a generic decoder thread
59  *******************************************************************************
60  * Destroy a terminated thread. This function will return 0 if the thread could
61  * be destroyed, and non 0 else. The last case probably means that the thread
62  * was still active, and another try may succeed.
63  *******************************************************************************/
64 void vdec_DestroyThread( vdec_thread_t *p_vdec, int *pi_status )
65 {
66     /* ?? */
67 }
68
69 /* following functions are local */
70
71 /*******************************************************************************
72  * CheckConfiguration: check vdec_CreateThread() configuration
73  *******************************************************************************
74  * Set default parameters where required. In DEBUG mode, check if configuration
75  * is valid.
76  *******************************************************************************/
77 static int CheckConfiguration( video_cfg_t *p_cfg )
78 {
79     /* ?? */
80
81     return( 0 );
82 }
83
84 /*******************************************************************************
85  * InitThread: initialize vdec output thread
86  *******************************************************************************
87  * This function is called from RunThread and performs the second step of the
88  * initialization. It returns 0 on success. Note that the thread's flag are not
89  * modified inside this function.
90  *******************************************************************************/
91 static int InitThread( vdec_thread_t *p_vdec )
92 {
93     /* ?? */
94     /* Create video stream */
95     p_vdec->i_stream =  vout_CreateStream( p_vdec->p_vout );
96     if( p_vdec->i_stream < 0 )                                        /* error */
97     {
98         return( 1 );        
99     }
100     
101     /* Initialize decoding data */    
102     /* ?? */
103
104     /* Initialize other properties */
105 #ifdef STATS
106     p_vdec->c_loops = 0;    
107     p_vdec->c_idle_loops = 0;
108     p_vdec->c_pictures = 0;
109     p_vdec->c_i_pictures = 0;
110     p_vdec->c_p_pictures = 0;
111     p_vdec->c_b_pictures = 0;
112     p_vdec->c_decoded_pictures = 0;
113     p_vdec->c_decoded_i_pictures = 0;
114     p_vdec->c_decoded_p_pictures = 0;
115     p_vdec->c_decoded_b_pictures = 0;
116 #endif
117
118     /* Mark thread as running and return */
119     intf_DbgMsg("vdec debug: InitThread(%p) succeeded\n", p_vdec);    
120     return( 0 );    
121 }
122
123 /*******************************************************************************
124  * RunThread: generic decoder thread
125  *******************************************************************************
126  * Generic decoder thread. This function does only returns when the thread is
127  * terminated. 
128  *******************************************************************************/
129 static void RunThread( vdec_thread_t *p_vdec )
130 {
131     /* 
132      * Initialize thread and free configuration 
133      */
134     p_vdec->b_error = InitThread( p_vdec );
135     if( p_vdec->b_error )
136     {
137         return;
138     }
139     p_vdec->b_run = 1;
140
141     /*
142      * Main loop - it is not executed if an error occured during
143      * initialization
144      */
145     while( (!p_vdec->b_die) && (!p_vdec->b_error) )
146     {
147         /* ?? */
148     } 
149
150     /*
151      * Error loop
152      */
153     if( p_vdec->b_error )
154     {
155         ErrorThread( p_vdec );        
156     }
157
158     /* End of thread */
159     EndThread( p_vdec );
160     p_vdec->b_run = 0;
161 }
162
163 /*******************************************************************************
164  * ErrorThread: RunThread() error loop
165  *******************************************************************************
166  * This function is called when an error occured during thread main's loop. The
167  * thread can still receive feed, but must be ready to terminate as soon as
168  * possible.
169  *******************************************************************************/
170 static void ErrorThread( vdec_thread_t *p_vdec )
171 {
172     /* Wait until a `die' order */
173     while( !p_vdec->b_die )
174     {
175         /* ?? trash all trashable PES packets */
176
177         /* Sleep a while */
178         msleep( VDEC_IDLE_SLEEP );                
179     }
180 }
181
182 /*******************************************************************************
183  * EndThread: thread destruction
184  *******************************************************************************
185  * This function is called when the thread ends after a sucessfull 
186  * initialization.
187  *******************************************************************************/
188 static void EndThread( vdec_thread_t *p_vdec )
189 {
190 #ifdef DEBUG
191     /* Check for remaining PES packets */
192     /* ?? */
193 #endif
194
195     /* Destroy thread structures allocated by InitThread */
196     vout_DestroyStream( p_vdec->p_vout, p_vdec->i_stream );
197     /* ?? */
198
199     intf_DbgMsg("vdec debug: EndThread(%p)\n", p_vdec);
200 }
201
202