1 /*******************************************************************************
2 * video_decoder.c : video decoder thread
4 *******************************************************************************/
6 /* ?? passer en terminate/destroy avec les signaux supplémentaires */
8 /*******************************************************************************
10 *******************************************************************************/
18 #include <X11/extensions/XShm.h>
25 #include "debug.h" /* ?? temporaire, requis par netlist.h */
28 #include "input_netlist.h"
29 #include "decoder_fifo.h"
31 #include "video_output.h"
32 #include "video_decoder.h"
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 );
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:
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 )
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 )
69 /* following functions are local */
71 /*******************************************************************************
72 * CheckConfiguration: check vdec_CreateThread() configuration
73 *******************************************************************************
74 * Set default parameters where required. In DEBUG mode, check if configuration
76 *******************************************************************************/
77 static int CheckConfiguration( video_cfg_t *p_cfg )
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 )
94 /* Create video stream */
95 p_vdec->i_stream = vout_CreateStream( p_vdec->p_vout );
96 if( p_vdec->i_stream < 0 ) /* error */
101 /* Initialize decoding data */
104 /* Initialize other properties */
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;
118 /* Mark thread as running and return */
119 intf_DbgMsg("vdec debug: InitThread(%p) succeeded\n", p_vdec);
123 /*******************************************************************************
124 * RunThread: generic decoder thread
125 *******************************************************************************
126 * Generic decoder thread. This function does only returns when the thread is
128 *******************************************************************************/
129 static void RunThread( vdec_thread_t *p_vdec )
132 * Initialize thread and free configuration
134 p_vdec->b_error = InitThread( p_vdec );
135 if( p_vdec->b_error )
142 * Main loop - it is not executed if an error occured during
145 while( (!p_vdec->b_die) && (!p_vdec->b_error) )
153 if( p_vdec->b_error )
155 ErrorThread( p_vdec );
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
169 *******************************************************************************/
170 static void ErrorThread( vdec_thread_t *p_vdec )
172 /* Wait until a `die' order */
173 while( !p_vdec->b_die )
175 /* ?? trash all trashable PES packets */
178 msleep( VDEC_IDLE_SLEEP );
182 /*******************************************************************************
183 * EndThread: thread destruction
184 *******************************************************************************
185 * This function is called when the thread ends after a sucessfull
187 *******************************************************************************/
188 static void EndThread( vdec_thread_t *p_vdec )
191 /* Check for remaining PES packets */
195 /* Destroy thread structures allocated by InitThread */
196 vout_DestroyStream( p_vdec->p_vout, p_vdec->i_stream );
199 intf_DbgMsg("vdec debug: EndThread(%p)\n", p_vdec);