1 /*******************************************************************************
2 * video_fifo.c : video FIFO management
4 *******************************************************************************/
6 /*******************************************************************************
8 *******************************************************************************/
16 #include <X11/extensions/XShm.h>
21 #include "vlc_thread.h"
24 #include "debug.h" /* ?? temporaire, requis par netlist.h */
27 #include "input_netlist.h"
28 #include "decoder_fifo.h"
30 #include "video_output.h"
31 #include "video_parser.h"
33 #include "undec_picture.h"
34 #include "video_fifo.h"
35 #include "video_decoder.h"
37 /*****************************************************************************
38 * vpar_InitFIFO : initialize the video FIFO
39 *****************************************************************************/
40 void vpar_InitFIFO( vpar_thread_t * p_vpar )
44 /* Initialize mutex and cond */
45 vlc_mutex_init( p_vpar->vfifo.lock );
46 vlc_cond_init( p_vpar->vfifo.wait );
47 vlc_mutex_init( p_vpar->vbuffer.lock );
49 /* Initialize FIFO properties */
50 p_vpar->vfifo.i_start = p_vpar->vfifo.i_end = 0;
51 p_vpar->vfifo.p_vpar = p_vpar;
53 /* Initialize buffer properties */
54 i_index = VFIFO_SIZE; /* all structures are available */
55 for( i_dummy = 0; i_dummy < VFIFO_SIZE + 1; i_dummy++ )
57 p_vpar->vfifo.pp_undec_free[i_dummy] = p_vpar->vfifo.p_undec_p + i;
61 /*****************************************************************************
62 * vpar_GetPicture : return a picture to be decoded
63 *****************************************************************************/
64 undec_picture_t * vpar_GetPicture( video_fifo_t * p_fifo )
66 undec_picture_t * p_undec_p;
68 vlc_mutex_lock( &p_fifo->lock );
69 while( VIDEO_FIFO_ISEMPTY( *p_fifo ) )
71 vlc_cond_wait( &p_fifo->wait, &p_fifo->lock );
72 if( p_fifo->p_vpar->b_die )
74 vlc_mutex_unlock( &p_fifo->lock );
79 p_undec_p = VIDEO_FIFO_START( *p_fifo );
80 VIDEO_FIFO_INCSTART( *p_fifo );
82 vlc_mutex_unlock( &p_fifo->lock );
87 /*****************************************************************************
88 * vpar_NewPicture : return a buffer for the parser
89 *****************************************************************************/
90 undec_picture_t * vpar_NewPicture( video_fifo_t * p_fifo )
92 undec_picture_t * p_undec_p;
94 #define P_buffer p_fifo->p_vpar.vbuffer
95 vlc_mutex_lock( &P_buffer->lock );
96 if( P_buffer.i_index == -1 )
98 /* No more structures available. This should not happen ! */
102 p_undec_p = P_buffer->pp_undec_free[ P_buffer->i_index-- ];
105 vlc_mutex_unlock( &P_buffer->lock );
109 /*****************************************************************************
110 * vpar_DecodePicture : put a picture in the video fifo, if it is decodable
111 *****************************************************************************/
112 void vpar_DecodePicture( video_fifo_t * p_fifo, undec_picture_t * p_undec_p )
114 boolean_t b_decodable;
119 b_decodable = ((p_undec_p->p_backward_p != NULL) &&
120 (p_undec_p->p_forward_p != NULL));
123 b_decodable = (p_undec_p->p_backward_p != NULL);
130 /* That should not happen */
135 /* Place picture in the video FIFO */
136 vlc_mutex_lock( &p_fifo->lock );
138 /* By construction, the video FIFO cannot be full */
139 VIDEO_FIFO_END( *p_fifo ) = p_undec_p;
140 VIDEO_FIFO_INCEND( *p_fifo );
142 vlc_mutex_unlock( &p_fifo->lock );
146 /*****************************************************************************
147 * vpar_ReleasePicture : put a picture in the video_output fifo, and update
149 *****************************************************************************/
150 void vpar_ReleasePicture( video_fifo_t * p_fifo, undec_picture_t * p_undec_p )
154 /* Tell referencing pictures so that they can be decoded */
155 for( i_ref = 0; p_undec_p->pp_referencing_undec[i_ref].p_undec != NULL
156 && i_ref < MAX_REFERENCING_UNDEC; i_ref++ )
158 *p_undec_p->pp_referencing_undec[i_ref].pp_frame = p_undec_p->p_picture;
159 vout_LinkPicture( p_fifo->p_vpar.p_vout, p_picture );
161 /* Try to put the referencing picture in the video FIFO */
162 vpar_DecodePicture( p_fifo, p_undec_p->pp_referencing_undec[i_ref].p_undec );
165 /* Unlink referenced pictures */
166 if( p_undec_p->p_forward_ref != NULL )
168 vout_UnlinkPicture( p_fifo->p_vpar.p_vout, p_undec_p->p_forward_ref );
169 if( p_undec_p->p_backward_ref != NULL )
171 vout_UnlinkPicture( p_fifo->p_vpar.p_vout, p_undec_p->p_backward_ref );
175 /* Mark the picture to be displayed */
176 vout_DisplayPicture( p_fifo->p_vpar.p_vout, p_undec_p->p_picture );
178 /* Release the undec_picture_t structure */
179 #define P_buffer p_fifo->p_vpar.vbuffer
180 vlc_mutex_lock( &P_buffer->lock );
182 P_buffer->pp_undec_free[ ++P_buffer->i_index ] = p_undec_p;
184 vlc_mutex_unlock( &P_buffer->lock );
189 /*****************************************************************************
190 * vpar_DestroyPicture : destroy a picture in case of error
191 *****************************************************************************/
192 void vpar_DestroyPicture( video_fifo_t * p_fifo, undec_picture_t * p_undec_p )
196 /* Destroy referencing pictures */
197 for( i_ref = 0; p_undec_p->pp_referencing_undec[i_ref].p_undec != NULL
198 && i_ref < MAX_REFERENCING_UNDEC; i_ref++ )
200 /* Try to put the referencing picture in the video FIFO */
201 vpar_DestroyPicture( p_fifo, p_undec_p->pp_referencing_undec[i_ref].p_undec );
204 /* Unlink referenced pictures */
205 if( p_undec_p->p_forward_ref != NULL )
207 vout_UnlinkPicture( p_fifo->p_vpar.p_vout, p_undec_p->p_forward_ref );
208 if( p_undec_p->p_backward_ref != NULL )
210 vout_UnlinkPicture( p_fifo->p_vpar.p_vout, p_undec_p->p_backward_ref );
214 /* Release the picture buffer */
215 vout_DestroyPicture( p_fifo->p_vpar.p_vout, p_undec_p->p_picture );
217 /* Release the undec_picture_t structure */
218 #define P_buffer p_fifo->p_vpar.vbuffer
219 vlc_mutex_lock( &P_buffer->lock );
221 P_buffer->pp_undec_free[ ++P_buffer->i_index ] = p_undec_p;
223 vlc_mutex_unlock( &P_buffer->lock );