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"
32 #include "vdec_idct.h"
33 #include "video_decoder.h"
34 #include "vdec_motion.h"
36 #include "vpar_blocks.h"
37 #include "vpar_headers.h"
38 #include "video_fifo.h"
39 #include "vpar_synchro.h"
40 #include "video_parser.h"
42 /*****************************************************************************
43 * vpar_InitFIFO : initialize the video FIFO
44 *****************************************************************************/
45 void vpar_InitFIFO( vpar_thread_t * p_vpar )
49 /* Initialize mutex and cond */
50 vlc_mutex_init( &p_vpar->vfifo.lock );
51 vlc_cond_init( &p_vpar->vfifo.wait );
52 vlc_mutex_init( &p_vpar->vbuffer.lock );
54 /* Initialize FIFO properties */
55 p_vpar->vfifo.i_start = p_vpar->vfifo.i_end = 0;
56 p_vpar->vfifo.p_vpar = p_vpar;
58 /* Initialize buffer properties */
59 p_vpar->vbuffer.i_index = VFIFO_SIZE; /* all structures are available */
60 for( i_dummy = 0; i_dummy < VFIFO_SIZE + 1; i_dummy++ )
62 p_vpar->vbuffer.pp_mb_free[i_dummy] = p_vpar->vbuffer.p_macroblocks
67 /*****************************************************************************
68 * vpar_GetMacroblock : return a macroblock to be decoded
69 *****************************************************************************/
70 macroblock_t * vpar_GetMacroblock( video_fifo_t * p_fifo )
74 vlc_mutex_lock( &p_fifo->lock );
75 while( VIDEO_FIFO_ISEMPTY( *p_fifo ) )
77 vlc_cond_wait( &p_fifo->wait, &p_fifo->lock );
78 if( p_fifo->p_vpar->b_die )
80 vlc_mutex_unlock( &p_fifo->lock );
85 p_mb = VIDEO_FIFO_START( *p_fifo );
86 VIDEO_FIFO_INCSTART( *p_fifo );
88 vlc_mutex_unlock( &p_fifo->lock );
93 /*****************************************************************************
94 * vpar_NewMacroblock : return a buffer for the parser
95 *****************************************************************************/
96 macroblock_t * vpar_NewMacroblock( video_fifo_t * p_fifo )
100 #define P_buffer p_fifo->p_vpar->vbuffer
101 vlc_mutex_lock( &P_buffer.lock );
102 if( P_buffer.i_index == -1 )
104 /* No more structures available. This should not happen ! */
108 p_mb = P_buffer.pp_mb_free[ P_buffer.i_index-- ];
110 vlc_mutex_unlock( &P_buffer.lock );
115 /*****************************************************************************
116 * vpar_DecodeMacroblock : put a macroblock in the video fifo
117 *****************************************************************************/
118 void vpar_DecodeMacroblock( video_fifo_t * p_fifo, macroblock_t * p_mb )
120 /* Place picture in the video FIFO */
121 vlc_mutex_lock( &p_fifo->lock );
123 /* By construction, the video FIFO cannot be full */
124 VIDEO_FIFO_END( *p_fifo ) = p_mb;
125 VIDEO_FIFO_INCEND( *p_fifo );
127 vlc_mutex_unlock( &p_fifo->lock );
130 /*****************************************************************************
131 * vpar_ReleaseMacroblock : release a macroblock and put the picture in the
132 * video output heap, if it is finished
133 *****************************************************************************/
134 void vpar_ReleaseMacroblock( video_fifo_t * p_fifo, macroblock_t * p_mb )
136 /* Unlink picture buffer */
137 vlc_mutex_lock( &p_mb->p_picture->lock_deccount );
138 p_mb->p_picture->i_deccount--;
140 /* Test if it was the last block of the picture */
141 if( p_mb->p_picture->i_deccount == 0 )
143 /* Mark the picture to be displayed */
144 vout_DisplayPicture( p_fifo->p_vpar->p_vout, p_mb->p_picture );
146 /* Warn Synchro for its records. */
147 vpar_SynchroEnd( p_fifo->p_vpar );
149 /* Unlink referenced pictures */
150 if( p_mb->p_forward != NULL )
152 vout_UnlinkPicture( p_fifo->p_vpar->p_vout, p_mb->p_forward );
154 if( p_mb->p_backward != NULL )
156 vout_UnlinkPicture( p_fifo->p_vpar->p_vout, p_mb->p_backward );
159 vlc_mutex_unlock( & p_mb->p_picture->lock_deccount );
161 /* Release the macroblock_t structure */
162 #define P_buffer p_fifo->p_vpar->vbuffer
163 vlc_mutex_lock( &P_buffer.lock );
164 P_buffer.pp_mb_free[ ++P_buffer.i_index ] = p_mb;
165 vlc_mutex_unlock( &P_buffer.lock );
169 /*****************************************************************************
170 * vpar_DestroyMacroblock : destroy a macroblock in case of error
171 *****************************************************************************/
172 void vpar_DestroyMacroblock( video_fifo_t * p_fifo, macroblock_t * p_mb )
174 /* Release the macroblock_t structure */
175 #define P_buffer p_fifo->p_vpar->vbuffer
176 vlc_mutex_lock( &P_buffer.lock );
177 P_buffer.pp_mb_free[ ++P_buffer.i_index ] = p_mb;
178 vlc_mutex_unlock( &P_buffer.lock );