1 /*****************************************************************************
2 * rawvid.c : raw video input module for vlc
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
8 * Antoine Cellerier <dionoea at videolan d.t org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
31 #include <vlc_demux.h>
32 #include <vlc_vout.h> /* vout_InitFormat */
34 /*****************************************************************************
36 *****************************************************************************/
37 static int Open ( vlc_object_t * );
38 static void Close( vlc_object_t * );
40 #define FPS_TEXT N_("Frames per Second")
41 #define FPS_LONGTEXT N_("This is the desired frame rate when " \
42 "playing raw video streams.")
44 #define WIDTH_TEXT N_("Width")
45 #define WIDTH_LONGTEXT N_("This specifies the width in pixels of the raw " \
48 #define HEIGHT_TEXT N_("Height")
49 #define HEIGHT_LONGTEXT N_("This specifies the height in pixels of the raw " \
52 #define CHROMA_TEXT N_("Force chroma (Use carefully)")
53 #define CHROMA_LONGTEXT N_("Force chroma. This is a four character string.")
55 #define ASPECT_RATIO_TEXT N_("Aspect ratio")
56 #define ASPECT_RATIO_LONGTEXT N_( \
57 "Aspect ratio (4:3, 16:9). Default is square pixels." )
60 set_shortname( "Raw Video" );
61 set_description( _("Raw video demuxer") );
62 set_capability( "demux2", 2 );
63 set_category( CAT_INPUT );
64 set_subcategory( SUBCAT_INPUT_DEMUX );
65 set_callbacks( Open, Close );
66 add_shortcut( "rawvideo" );
67 add_float( "rawvid-fps", 25, 0, FPS_TEXT, FPS_LONGTEXT, VLC_FALSE );
68 add_integer( "rawvid-width", 176, 0, WIDTH_TEXT, WIDTH_LONGTEXT, 0 );
69 add_integer( "rawvid-height", 144, 0, HEIGHT_TEXT, HEIGHT_LONGTEXT, 0 );
70 add_string( "rawvid-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
72 add_string( "rawvid-aspect-ratio", NULL, NULL,
73 ASPECT_RATIO_TEXT, ASPECT_RATIO_LONGTEXT, VLC_TRUE );
76 /*****************************************************************************
77 * Definitions of structures used by this plugin
78 *****************************************************************************/
84 es_out_id_t *p_es_video;
85 es_format_t fmt_video;
90 /*****************************************************************************
92 *****************************************************************************/
93 static int Demux( demux_t * );
94 static int Control( demux_t *, int i_query, va_list args );
96 /*****************************************************************************
97 * Open: initializes raw DV demux structures
98 *****************************************************************************/
99 static int Open( vlc_object_t * p_this )
101 demux_t *p_demux = (demux_t*)p_this;
103 int i_width, i_height;
107 char *psz_aspect_ratio;
108 unsigned int i_aspect;
110 /* Check for YUV file extension */
111 psz_ext = strrchr( p_demux->psz_path, '.' );
112 if( ( !psz_ext || strcasecmp( psz_ext, ".yuv") ) &&
113 strcmp(p_demux->psz_demux, "rawvid") )
118 /* Set p_input field */
119 p_demux->pf_demux = Demux;
120 p_demux->pf_control = Control;
121 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
124 p_sys->f_fps = var_CreateGetFloat( p_demux, "rawvid-fps" );
126 i_width = var_CreateGetInteger( p_demux, "rawvid-width" );
127 i_height = var_CreateGetInteger( p_demux, "rawvid-height" );
128 if( i_width <= 0 || i_height <= 0 )
130 msg_Err( p_demux, "width and height must be strictly positive." );
135 psz_chroma = var_CreateGetString( p_demux, "rawvid-chroma" );
136 psz_aspect_ratio = var_CreateGetString( p_demux, "rawvid-aspect-ratio" );
138 if( psz_aspect_ratio && *psz_aspect_ratio )
140 char *psz_parser = strchr( psz_aspect_ratio, ':' );
143 *psz_parser++ = '\0';
144 i_aspect = atoi( psz_aspect_ratio ) * VOUT_ASPECT_FACTOR
145 / atoi( psz_parser );
149 i_aspect = atof( psz_aspect_ratio ) * VOUT_ASPECT_FACTOR;
154 i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height;
156 free( psz_aspect_ratio );
158 if( psz_chroma && strlen( psz_chroma ) >= 4 )
160 memcpy( &i_chroma, psz_chroma, 4 );
161 msg_Dbg( p_demux, "Forcing chroma to 0x%.8x (%4.4s)", i_chroma,
166 i_chroma = VLC_FOURCC('Y','V','1','2');
167 msg_Dbg( p_demux, "Using default chroma 0x%.8x (%4.4s)", i_chroma,
172 es_format_Init( &p_sys->fmt_video, VIDEO_ES, i_chroma );
173 vout_InitFormat( &p_sys->fmt_video.video, i_chroma, i_width, i_height,
175 if( !p_sys->fmt_video.video.i_bits_per_pixel )
177 msg_Err( p_demux, "Unsupported chroma 0x%.8x (%4.4s)", i_chroma,
182 p_sys->frame_size = i_width * i_height
183 * p_sys->fmt_video.video.i_bits_per_pixel / 8;
184 p_sys->p_es_video = es_out_Add( p_demux->out, &p_sys->fmt_video );
189 /*****************************************************************************
190 * Close: frees unused data
191 *****************************************************************************/
192 static void Close( vlc_object_t *p_this )
194 demux_t *p_demux = (demux_t*)p_this;
195 demux_sys_t *p_sys = p_demux->p_sys;
199 /*****************************************************************************
200 * Demux: reads and demuxes data packets
201 *****************************************************************************
202 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
203 *****************************************************************************/
204 static int Demux( demux_t *p_demux )
206 demux_sys_t *p_sys = p_demux->p_sys;
209 /* Call the pace control */
210 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_pcr );
212 if( ( p_block = stream_Block( p_demux->s, p_sys->frame_size ) ) == NULL )
218 p_block->i_dts = p_block->i_pts = p_sys->i_pcr;
219 es_out_Send( p_demux->out, p_sys->p_es_video, p_block );
221 p_sys->i_pcr += ( I64C(1000000) / p_sys->f_fps );
226 /*****************************************************************************
228 *****************************************************************************/
229 static int Control( demux_t *p_demux, int i_query, va_list args )
231 demux_sys_t *p_sys = p_demux->p_sys;
233 /* XXX: DEMUX_SET_TIME is precise here */
234 return demux2_vaControlHelper( p_demux->s, 0, -1,
235 p_sys->frame_size * p_sys->f_fps * 8,
236 p_sys->frame_size, i_query, args );