1 /*****************************************************************************
2 * rawvid.c : raw video input module for vlc
3 *****************************************************************************
4 * Copyright (C) 2007 the VideoLAN team
5 * $Id: rawdv.c 18062 2006-11-26 14:20:34Z zorglub $
7 * Authors: Gildas Bazin <gbazin@videolan.org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
30 #include <vlc_demux.h>
32 /*****************************************************************************
34 *****************************************************************************/
35 static int Open ( vlc_object_t * );
36 static void Close( vlc_object_t * );
38 #define FPS_TEXT N_("Frames per Second")
39 #define FPS_LONGTEXT N_("This is the desired frame rate when " \
40 "playing raw video streams.")
42 #define WIDTH_TEXT N_("Width")
43 #define WIDTH_LONGTEXT N_("This specifies the width in pixels of the raw " \
46 #define HEIGHT_TEXT N_("Height")
47 #define HEIGHT_LONGTEXT N_("This specifies the height in pixels of the raw " \
51 set_shortname( "Raw Video" );
52 set_description( _("Raw video demuxer") );
53 set_capability( "demux2", 2 );
54 set_category( CAT_INPUT );
55 set_subcategory( SUBCAT_INPUT_DEMUX );
56 set_callbacks( Open, Close );
57 add_shortcut( "rawvideo" );
58 add_float( "rawvid-fps", 25, 0, FPS_TEXT, FPS_LONGTEXT, VLC_FALSE );
59 add_integer( "rawvid-width", 176, 0, WIDTH_TEXT, WIDTH_LONGTEXT, 0 );
60 add_integer( "rawvid-height", 144, 0, HEIGHT_TEXT, HEIGHT_LONGTEXT, 0 );
63 /*****************************************************************************
64 * Definitions of structures used by this plugin
65 *****************************************************************************/
71 es_out_id_t *p_es_video;
72 es_format_t fmt_video;
77 /*****************************************************************************
79 *****************************************************************************/
80 static int Demux( demux_t * );
81 static int Control( demux_t *, int i_query, va_list args );
83 /*****************************************************************************
84 * Open: initializes raw DV demux structures
85 *****************************************************************************/
86 static int Open( vlc_object_t * p_this )
88 demux_t *p_demux = (demux_t*)p_this;
90 int i_width, i_height;
94 /* Check for YUV file extension */
95 psz_ext = strrchr( p_demux->psz_path, '.' );
96 if( ( !psz_ext || strcasecmp( psz_ext, ".yuv") ) &&
97 strcmp(p_demux->psz_demux, "rawvid") )
102 /* Set p_input field */
103 p_demux->pf_demux = Demux;
104 p_demux->pf_control = Control;
105 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
108 var_Create( p_demux, "rawvid-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
109 var_Get( p_demux, "rawvid-fps", &val );
110 p_sys->f_fps = val.f_float;
111 var_Create( p_demux, "rawvid-width", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
112 var_Get( p_demux, "rawvid-width", &val );
114 var_Create( p_demux, "rawvid-height", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT);
115 var_Get( p_demux, "rawvid-height", &val );
116 i_height = val.i_int;
118 /* Only handle YV12 for now */
119 es_format_Init( &p_sys->fmt_video, VIDEO_ES, VLC_FOURCC('Y','V','1','2') );
120 p_sys->fmt_video.video.i_width = i_width;
121 p_sys->fmt_video.video.i_height = i_height;
122 p_sys->frame_size = i_width * i_height * 3 / 2;
123 p_sys->p_es_video = es_out_Add( p_demux->out, &p_sys->fmt_video );
128 /*****************************************************************************
129 * Close: frees unused data
130 *****************************************************************************/
131 static void Close( vlc_object_t *p_this )
133 demux_t *p_demux = (demux_t*)p_this;
134 demux_sys_t *p_sys = p_demux->p_sys;
138 /*****************************************************************************
139 * Demux: reads and demuxes data packets
140 *****************************************************************************
141 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
142 *****************************************************************************/
143 static int Demux( demux_t *p_demux )
145 demux_sys_t *p_sys = p_demux->p_sys;
148 /* Call the pace control */
149 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_sys->i_pcr );
151 if( ( p_block = stream_Block( p_demux->s, p_sys->frame_size ) ) == NULL )
157 p_block->i_dts = p_block->i_pts = p_sys->i_pcr;
158 es_out_Send( p_demux->out, p_sys->p_es_video, p_block );
160 p_sys->i_pcr += ( I64C(1000000) / p_sys->f_fps );
165 /*****************************************************************************
167 *****************************************************************************/
168 static int Control( demux_t *p_demux, int i_query, va_list args )
170 demux_sys_t *p_sys = p_demux->p_sys;
172 /* XXX: DEMUX_SET_TIME is precise here */
173 return demux2_vaControlHelper( p_demux->s, 0, -1,
174 p_sys->frame_size * p_sys->f_fps * 8,
175 p_sys->frame_size, i_query, args );