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;
58 p_vpar->vfifo.p_undec_p[i].p_mb_info = NULL;
62 /*****************************************************************************
63 * vpar_GetPicture : return a picture to be decoded
64 *****************************************************************************/
65 undec_picture_t * vpar_GetPicture( video_fifo_t * p_fifo )
67 undec_picture_t * p_undec_p;
69 vlc_mutex_lock( &p_fifo->lock );
70 while( VIDEO_FIFO_ISEMPTY( *p_fifo ) )
72 vlc_cond_wait( &p_fifo->wait, &p_fifo->lock );
73 if( p_fifo->p_vpar->b_die )
75 vlc_mutex_unlock( &p_fifo->lock );
80 p_undec_p = VIDEO_FIFO_START( *p_fifo );
81 VIDEO_FIFO_INCSTART( *p_fifo );
83 vlc_mutex_unlock( &p_fifo->lock );
88 /*****************************************************************************
89 * vpar_NewPicture : return a buffer for the parser
90 *****************************************************************************/
91 undec_picture_t * vpar_NewPicture( video_fifo_t * p_fifo )
93 undec_picture_t * p_undec_p;
95 #define P_buffer p_fifo->p_vpar.vbuffer
96 vlc_mutex_lock( &P_buffer->lock );
97 if( P_buffer.i_index == -1 )
99 /* No more structures available. This should not happen ! */
103 p_undec_p = P_buffer->pp_undec_free[ P_buffer->i_index-- ];
106 vlc_mutex_unlock( &P_buffer->lock );
110 /*****************************************************************************
111 * vpar_DecodePicture : put a picture in the video fifo, if it is decodable
112 *****************************************************************************/
113 void vpar_DecodePicture( video_fifo_t * p_fifo, undec_picture_t * p_undec_p )
115 boolean_t b_decodable;
120 b_decodable = ((p_undec_p->p_backward_p != NULL) &&
121 (p_undec_p->p_forward_p != NULL));
124 b_decodable = (p_undec_p->p_backward_p != NULL);
131 /* That should not happen */
136 /* Place picture in the video FIFO */
137 vlc_mutex_lock( &p_fifo->lock );
139 /* By construction, the video FIFO cannot be full */
140 VIDEO_FIFO_END( *p_fifo ) = p_undec_p;
141 VIDEO_FIFO_INCEND( *p_fifo );
143 vlc_mutex_unlock( &p_fifo->lock );
147 /*****************************************************************************
148 * vpar_ReleasePicture : put a picture in the video_output fifo, and update
150 *****************************************************************************/
151 void vpar_ReleasePicture( video_fifo_t * p_fifo, undec_picture_t * p_undec_p )
155 /* Tell referencing pictures so that they can be decoded */
156 for( i_ref = 0; p_undec_p->pp_referencing_undec[i_ref].p_undec != NULL
157 && i_ref < MAX_REFERENCING_UNDEC; i_ref++ )
159 *p_undec_p->pp_referencing_undec[i_ref].pp_frame = p_undec_p->p_picture;
160 vout_LinkPicture( p_fifo->p_vpar.p_vout, p_picture );
162 /* Try to put the referencing picture in the video FIFO */
163 vpar_DecodePicture( p_fifo, p_undec_p->pp_referencing_undec[i_ref].p_undec );
166 /* Unlink referenced pictures */
167 if( p_undec_p->p_forward_ref != NULL )
169 vout_UnlinkPicture( p_fifo->p_vpar.p_vout, p_undec_p->p_forward_ref );
170 if( p_undec_p->p_backward_ref != NULL )
172 vout_UnlinkPicture( p_fifo->p_vpar.p_vout, p_undec_p->p_backward_ref );
176 /* Mark the picture to be displayed */
177 vout_DisplayPicture( p_fifo->p_vpar.p_vout, p_undec_p->p_picture );
179 /* Release the undec_picture_t structure */
180 #define P_buffer p_fifo->p_vpar.vbuffer
181 vlc_mutex_lock( &P_buffer->lock );
183 P_buffer->pp_undec_free[ ++P_buffer->i_index ] = p_undec_p;
185 vlc_mutex_unlock( &P_buffer->lock );
190 /*****************************************************************************
191 * vpar_DestroyPicture : destroy a picture in case of error
192 *****************************************************************************/
193 void vpar_DestroyPicture( video_fifo_t * p_fifo, undec_picture_t * p_undec_p )
197 /* Destroy referencing pictures */
198 for( i_ref = 0; p_undec_p->pp_referencing_undec[i_ref].p_undec != NULL
199 && i_ref < MAX_REFERENCING_UNDEC; i_ref++ )
201 /* Try to put the referencing picture in the video FIFO */
202 vpar_DestroyPicture( p_fifo, p_undec_p->pp_referencing_undec[i_ref].p_undec );
205 /* Unlink referenced pictures */
206 if( p_undec_p->p_forward_ref != NULL )
208 vout_UnlinkPicture( p_fifo->p_vpar.p_vout, p_undec_p->p_forward_ref );
209 if( p_undec_p->p_backward_ref != NULL )
211 vout_UnlinkPicture( p_fifo->p_vpar.p_vout, p_undec_p->p_backward_ref );
215 /* Release the picture buffer */
216 vout_DestroyPicture( p_fifo->p_vpar.p_vout, p_undec_p->p_picture );
218 /* Release the undec_picture_t structure */
219 #define P_buffer p_fifo->p_vpar.vbuffer
220 vlc_mutex_lock( &P_buffer->lock );
222 P_buffer->pp_undec_free[ ++P_buffer->i_index ] = p_undec_p;
224 vlc_mutex_unlock( &P_buffer->lock );