1 /*******************************************************************************
2 * spu_decoder.c : spu decoder thread
4 *******************************************************************************/
6 /* repompé sur video_decoder.c
7 * ?? passer en terminate/destroy avec les signaux supplémentaires */
9 /*******************************************************************************
11 *******************************************************************************/
24 #include "vlc_thread.h"
27 #include "debug.h" /* ?? temporaire, requis par netlist.h */
30 #include "input_netlist.h"
31 #include "decoder_fifo.h"
33 #include "spu_decoder.h"
38 static int InitThread ( spudec_thread_t *p_spudec );
39 static void RunThread ( spudec_thread_t *p_spudec );
40 static void ErrorThread ( spudec_thread_t *p_spudec );
41 static void EndThread ( spudec_thread_t *p_spudec );
43 /******************************************************************************
44 * spudec_CreateThread: create a spu decoder thread
45 ******************************************************************************/
46 spudec_thread_t * spudec_CreateThread( input_thread_t * p_input )
48 spudec_thread_t * p_spudec;
50 intf_DbgMsg("spudec debug: creating spu decoder thread\n");
51 fprintf(stderr, "spudec debug: creating spu decoder thread\n");
53 /* Allocate the memory needed to store the thread's structure */
54 if ( (p_spudec = (spudec_thread_t *)malloc( sizeof(spudec_thread_t) )) == NULL )
56 intf_ErrMsg("spudec error: not enough memory for spudec_CreateThread() to create the new thread\n");
61 * Initialize the thread properties
64 p_spudec->b_error = 0;
66 /* Spawn the spu decoder thread */
67 if ( vlc_thread_create(&p_spudec->thread_id, "spu decoder",
68 (vlc_thread_func_t)RunThread, (void *)p_spudec) )
70 intf_ErrMsg("spudec error: can't spawn spu decoder thread\n");
75 intf_DbgMsg("spudec debug: spu decoder thread (%p) created\n", p_spudec);
79 /*******************************************************************************
80 * spudec_DestroyThread: destroy a spu decoder thread
81 *******************************************************************************
82 * Destroy and terminate thread. This function will return 0 if the thread could
83 * be destroyed, and non 0 else. The last case probably means that the thread
84 * was still active, and another try may succeed.
85 *******************************************************************************/
86 void spudec_DestroyThread( spudec_thread_t *p_spudec )
88 intf_DbgMsg("spudec debug: requesting termination of spu decoder thread %p\n", p_spudec);
89 fprintf(stderr, "spudec debug: requesting termination of spu decoder thread %p\n", p_spudec);
91 /* Ask thread to kill itself */
94 /* Waiting for the decoder thread to exit */
95 /* Remove this as soon as the "status" flag is implemented */
96 vlc_thread_join( p_spudec->thread_id );
99 /* following functions are local */
101 /*******************************************************************************
102 * InitThread: initialize spu decoder thread
103 *******************************************************************************
104 * This function is called from RunThread and performs the second step of the
105 * initialization. It returns 0 on success. Note that the thread's flag are not
106 * modified inside this function.
107 *******************************************************************************/
108 static int InitThread( spudec_thread_t *p_spudec )
111 intf_DbgMsg("spudec debug: initializing spu decoder thread %p\n", p_spudec);
113 /* Mark thread as running and return */
114 intf_DbgMsg("spudec debug: InitThread(%p) succeeded\n", p_spudec);
118 /*******************************************************************************
119 * RunThread: spu decoder thread
120 *******************************************************************************
121 * spu decoder thread. This function does only return when the thread is
123 *******************************************************************************/
124 static void RunThread( spudec_thread_t *p_spudec )
126 intf_DbgMsg("spudec debug: running spu decoder thread (%p) (pid == %i)\n",
130 * Initialize thread and free configuration
132 p_spudec->b_error = InitThread( p_spudec );
133 if( p_spudec->b_error )
140 * Main loop - it is not executed if an error occured during
143 while( (!p_spudec->b_die) && (!p_spudec->b_error) )
145 fprintf(stderr, "I'm a spu decoder !\n");
152 if( p_spudec->b_error )
154 ErrorThread( p_spudec );
158 EndThread( p_spudec );
162 /*******************************************************************************
163 * ErrorThread: RunThread() error loop
164 *******************************************************************************
165 * This function is called when an error occured during thread main's loop. The
166 * thread can still receive feed, but must be ready to terminate as soon as
168 *******************************************************************************/
169 static void ErrorThread( spudec_thread_t *p_spudec )
171 /* Wait until a `die' order */
172 while( !p_spudec->b_die )
178 /*******************************************************************************
179 * EndThread: thread destruction
180 *******************************************************************************
181 * This function is called when the thread ends after a sucessfull
183 *******************************************************************************/
184 static void EndThread( spudec_thread_t *p_spudec )
186 intf_DbgMsg("spudec debug: EndThread(%p)\n", p_spudec);