1 /*****************************************************************************
2 * fake.c: decoder reading from a fake stream, outputting a fixed image
3 *****************************************************************************
4 * Copyright (C) 2005 VideoLAN
7 * Authors: Christophe Massiot <massiot@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 *****************************************************************************/
28 #include <vlc/decoder.h>
30 #include "vlc_image.h"
32 /*****************************************************************************
33 * decoder_sys_t : fake decoder descriptor
34 *****************************************************************************/
40 /*****************************************************************************
42 *****************************************************************************/
43 static int OpenDecoder ( vlc_object_t * );
44 static void CloseDecoder ( vlc_object_t * );
46 static picture_t *DecodeBlock ( decoder_t *, block_t ** );
48 /*****************************************************************************
50 *****************************************************************************/
51 #define FILE_TEXT N_("Image file")
52 #define FILE_LONGTEXT N_( \
53 "Path of the image file when using the fake input." )
54 #define ASPECT_RATIO_TEXT N_("Background aspect ratio")
55 #define ASPECT_RATIO_LONGTEXT N_( \
56 "Aspect ratio of the image file (4:3, 16:9)." )
59 set_category( CAT_INPUT );
60 set_subcategory( SUBCAT_INPUT_VCODEC );
61 set_shortname( _("Fake") );
62 set_description( _("Fake video decoder") );
63 set_capability( "decoder", 1000 );
64 set_callbacks( OpenDecoder, CloseDecoder );
65 add_shortcut( "fake" );
67 add_file( "fake-file", "", NULL, FILE_TEXT,
68 FILE_LONGTEXT, VLC_FALSE );
69 add_string( "fake-aspect-ratio", "4:3", NULL,
70 ASPECT_RATIO_TEXT, ASPECT_RATIO_LONGTEXT, VLC_TRUE );
73 /*****************************************************************************
74 * OpenDecoder: probe the decoder and return score
75 *****************************************************************************/
76 static int OpenDecoder( vlc_object_t *p_this )
78 decoder_t *p_dec = (decoder_t*)p_this;
82 if( p_dec->fmt_in.i_codec != VLC_FOURCC('f','a','k','e') )
87 /* Allocate the memory needed to store the decoder's structure */
88 if( ( p_dec->p_sys = p_sys =
89 (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
91 msg_Err( p_dec, "out of memory" );
95 var_Create( p_dec, "fake-file", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
96 var_Get( p_dec, "fake-file", &val );
97 if( val.psz_string != NULL && *val.psz_string )
99 image_handler_t *p_handler = image_HandlerCreate( p_dec );
100 video_format_t fmt_in, fmt_out;
102 memset( &fmt_in, 0, sizeof(fmt_in) );
103 memset( &fmt_out, 0, sizeof(fmt_out) );
104 fmt_out.i_chroma = VLC_FOURCC('Y', 'V', '1', '2');
105 p_sys->p_image = image_ReadUrl( p_handler, val.psz_string,
107 image_HandlerDelete( p_handler );
109 if( p_sys->p_image == NULL )
111 msg_Err( p_dec, "unable to read image file %s", val.psz_string );
112 free( p_dec->p_sys );
115 msg_Dbg( p_dec, "file %s loaded successfully", val.psz_string );
116 p_dec->fmt_out.video = fmt_out;
118 if( val.psz_string ) free( val.psz_string );
120 var_Create( p_dec, "fake-aspect-ratio",
121 VLC_VAR_STRING | VLC_VAR_DOINHERIT );
122 var_Get( p_dec, "fake-aspect-ratio", &val );
123 if ( val.psz_string )
125 char *psz_parser = strchr( val.psz_string, ':' );
129 *psz_parser++ = '\0';
130 p_dec->fmt_out.video.i_aspect = atoi( val.psz_string )
131 * VOUT_ASPECT_FACTOR / atoi( psz_parser );
135 msg_Warn( p_dec, "bad aspect ratio %s", val.psz_string );
136 p_dec->fmt_out.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
139 free( val.psz_string );
143 p_dec->fmt_out.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
146 /* Set output properties */
147 p_dec->fmt_out.i_cat = VIDEO_ES;
148 p_dec->fmt_out.i_codec = VLC_FOURCC('Y','V','1','2');
151 p_dec->pf_decode_video = DecodeBlock;
156 /****************************************************************************
157 * DecodeBlock: the whole thing
158 ****************************************************************************/
159 static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
161 decoder_sys_t *p_sys = p_dec->p_sys;
164 if( pp_block == NULL || !*pp_block ) return NULL;
165 p_pic = p_dec->pf_vout_buffer_new( p_dec );
168 msg_Err( p_dec, "cannot get picture" );
172 vout_CopyPicture( p_dec, p_pic, p_sys->p_image );
173 p_pic->date = (*pp_block)->i_pts;
176 block_Release( *pp_block );
182 /*****************************************************************************
183 * CloseDecoder: fake decoder destruction
184 *****************************************************************************/
185 static void CloseDecoder( vlc_object_t *p_this )
187 decoder_t *p_dec = (decoder_t *)p_this;
188 decoder_sys_t *p_sys = p_dec->p_sys;
190 if( p_sys->p_image != NULL )
191 p_sys->p_image->pf_release( p_sys->p_image );