1 /*****************************************************************************
2 * rawvideo.c: Pseudo audio decoder; for raw video data
3 *****************************************************************************
4 * Copyright (C) 2001, 2002 VideoLAN
5 * $Id: rawvideo.c,v 1.5 2003/05/02 03:40:01 fenrir Exp $
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
29 #include <vlc/decoder.h>
30 #include <vlc/input.h>
32 #include <stdlib.h> /* malloc(), free() */
33 #include <string.h> /* strdup() */
35 /*****************************************************************************
37 *****************************************************************************/
41 /* Input properties */
42 decoder_fifo_t *p_fifo;
45 /* Output properties */
49 vout_thread_t *p_vout;
53 static int OpenDecoder ( vlc_object_t * );
55 static int RunDecoder ( decoder_fifo_t * );
56 static int InitThread ( vdec_thread_t * );
57 static void DecodeThread ( vdec_thread_t * );
58 static void EndThread ( vdec_thread_t * );
60 /*****************************************************************************
62 *****************************************************************************/
65 set_description( _("Pseudo Raw Video decoder") );
66 set_capability( "decoder", 50 );
67 set_callbacks( OpenDecoder, NULL );
71 /*****************************************************************************
72 * OpenDecoder: probe the decoder and return score
73 *****************************************************************************
74 * Tries to launch a decoder and return score so that the interface is able
76 *****************************************************************************/
77 static int OpenDecoder( vlc_object_t *p_this )
79 decoder_fifo_t *p_fifo = (decoder_fifo_t*) p_this;
81 switch( p_fifo->i_fourcc )
84 case VLC_FOURCC('I','4','4','4'):
85 case VLC_FOURCC('I','4','2','2'):
86 case VLC_FOURCC('I','4','2','0'):
87 case VLC_FOURCC('Y','V','1','2'):
88 case VLC_FOURCC('I','Y','U','V'):
89 case VLC_FOURCC('I','4','1','1'):
90 case VLC_FOURCC('I','4','1','0'):
93 case VLC_FOURCC('Y','U','Y','2'):
94 case VLC_FOURCC('U','Y','V','Y'):
97 case VLC_FOURCC('R','V','3','2'):
98 case VLC_FOURCC('R','V','2','4'):
99 case VLC_FOURCC('R','V','1','6'):
100 case VLC_FOURCC('R','V','1','5'):
102 p_fifo->pf_run = RunDecoder;
111 /*****************************************************************************
112 * RunDecoder: this function is called just after the thread is created
113 *****************************************************************************/
114 static int RunDecoder( decoder_fifo_t *p_fifo )
116 vdec_thread_t *p_vdec;
119 if( !( p_vdec = malloc( sizeof( vdec_thread_t ) ) ) )
121 msg_Err( p_fifo, "out of memory" );
122 DecoderError( p_fifo );
125 memset( p_vdec, 0, sizeof( vdec_thread_t ) );
127 p_vdec->p_fifo = p_fifo;
129 if( InitThread( p_vdec ) != 0 )
131 DecoderError( p_fifo );
135 while( ( !p_vdec->p_fifo->b_die )&&( !p_vdec->p_fifo->b_error ) )
137 DecodeThread( p_vdec );
141 if( ( b_error = p_vdec->p_fifo->b_error ) )
143 DecoderError( p_vdec->p_fifo );
156 #define FREE( p ) if( p ) { free( p ); p = NULL; }
159 /*****************************************************************************
160 * InitThread: initialize data before entering main loop
161 *****************************************************************************/
162 static int InitThread( vdec_thread_t * p_vdec )
167 #define bih ((BITMAPINFOHEADER*)p_vdec->p_fifo->p_bitmapinfoheader)
170 msg_Err( p_vdec->p_fifo,
171 "info missing, fatal" );
172 return( VLC_EGENERIC );
174 if( bih->biWidth <= 0 || bih->biHeight <= 0 )
176 msg_Err( p_vdec->p_fifo,
177 "invalid display size %dx%d",
178 bih->biWidth, bih->biHeight );
179 return( VLC_EGENERIC );
182 p_vdec->p_vout = vout_Request( p_vdec->p_fifo, NULL,
183 bih->biWidth, bih->biHeight,
184 p_vdec->p_fifo->i_fourcc,
185 VOUT_ASPECT_FACTOR * bih->biWidth /
188 if( p_vdec->p_vout == NULL )
190 msg_Err( p_vdec->p_fifo, "failed created vout" );
191 return( VLC_EGENERIC );
194 /* Find out p_vdec->i_raw_size */
195 vout_InitPicture( VLC_OBJECT(p_vdec->p_fifo), &pic,
196 bih->biWidth, bih->biHeight, p_vdec->p_fifo->i_fourcc );
197 p_vdec->i_raw_size = 0;
198 for( i = 0; i < pic.i_planes; i++ )
200 p_vdec->i_raw_size += pic.p[i].i_lines * pic.p[i].i_visible_pitch;
203 return( VLC_SUCCESS );
208 static void FillPicture( pes_packet_t *p_pes, picture_t *p_pic )
212 data_packet_t *p_data;
216 p_data = p_pes->p_first;
217 p_src = p_data->p_payload_start;
218 i_src = p_data->p_payload_end - p_data->p_payload_start;
220 for( i_plane = 0; i_plane < p_pic->i_planes; i_plane++ )
226 p_dst = p_pic->p[i_plane].p_pixels;
227 i_dst = p_pic->p[i_plane].i_pitch * p_pic->p[i_plane].i_lines;
233 i_copy = __MIN( i_src, i_dst );
236 memcpy( p_dst, p_src, i_copy );
247 p_data = p_data->p_next;
252 p_src = p_data->p_payload_start;
253 i_src = p_data->p_payload_end - p_data->p_payload_start;
254 } while( i_src <= 0 );
260 /*****************************************************************************
261 * DecodeThread: decodes a frame
262 *****************************************************************************/
263 static void DecodeThread( vdec_thread_t *p_vdec )
269 /* **** get frame **** */
270 input_ExtractPES( p_vdec->p_fifo, &p_pes );
273 p_vdec->p_fifo->b_error = 1;
276 i_size = p_pes->i_pes_size;
278 if( i_size < p_vdec->i_raw_size )
280 msg_Warn( p_vdec->p_fifo, "invalid frame size (%d < %d)",
281 i_size, p_vdec->i_raw_size );
282 //input_DeletePES( p_vdec->p_fifo->p_packets_mgt, p_pes );
286 /* **** get video picture **** */
287 while( !(p_pic = vout_CreatePicture( p_vdec->p_vout, 0, 0, 0 ) ) )
289 if( p_vdec->p_fifo->b_die || p_vdec->p_fifo->b_error )
293 msleep( VOUT_OUTMEM_SLEEP );
297 /* **** fill p_pic **** */
298 FillPicture( p_pes, p_pic );
300 /* **** display p_pic **** */
301 vout_DatePicture( p_vdec->p_vout, p_pic, p_pes->i_pts);
302 vout_DisplayPicture( p_vdec->p_vout, p_pic );
305 input_DeletePES( p_vdec->p_fifo->p_packets_mgt, p_pes );
309 /*****************************************************************************
310 * EndThread : faad decoder thread destruction
311 *****************************************************************************/
312 static void EndThread (vdec_thread_t *p_vdec)
316 vout_Request( p_vdec->p_fifo, p_vdec->p_vout, 0, 0, 0, 0 );
319 msg_Dbg( p_vdec->p_fifo, "raw video decoder closed" );