1 /*****************************************************************************
2 * fake.c : Fake video input for VLC
3 *****************************************************************************
4 * Copyright (C) 2005 VideoLAN
7 * Author: 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 *****************************************************************************/
32 #include <vlc/input.h>
34 /*****************************************************************************
36 *****************************************************************************/
37 static int Open ( vlc_object_t * );
38 static void Close( vlc_object_t * );
40 #define CACHING_TEXT N_("Caching value in ms")
41 #define CACHING_LONGTEXT N_( \
42 "Allows you to modify the default caching value for fake streams. This " \
43 "value should be set in millisecond units." )
44 #define FPS_TEXT N_("Framerate")
45 #define FPS_LONGTEXT N_( \
46 "Specify the number of frames per second (eg. 24, 25, 29.997, 30).")
49 set_shortname( _("Fake") );
50 set_description( _("Fake input") );
51 set_category( CAT_INPUT );
52 set_subcategory( SUBCAT_INPUT_ACCESS );
54 add_integer( "fake-caching", DEFAULT_PTS_DELAY / 1000, NULL,
55 CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
56 add_float( "fake-fps", 25.0, NULL, FPS_TEXT, FPS_LONGTEXT, VLC_TRUE );
58 add_shortcut( "fake" );
59 set_capability( "access_demux", 0 );
60 set_callbacks( Open, Close );
63 /*****************************************************************************
64 * Access: local prototypes
65 *****************************************************************************/
66 static int Demux ( demux_t * );
67 static int Control( demux_t *, int, va_list );
72 mtime_t i_last_pts; /* only used when f_fps > 0 */
74 es_out_id_t *p_es_video;
77 /*****************************************************************************
78 * Open: opens fake device
79 *****************************************************************************/
80 static int Open( vlc_object_t *p_this )
82 demux_t *p_demux = (demux_t*)p_this;
87 /* Only when selected */
88 if( *p_demux->psz_access == '\0' )
92 p_demux->pf_demux = Demux;
93 p_demux->pf_control = Control;
94 p_demux->info.i_update = 0;
95 p_demux->info.i_title = 0;
96 p_demux->info.i_seekpoint = 0;
97 p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
98 memset( p_sys, 0, sizeof( demux_sys_t ) );
100 var_Create( p_demux, "fake-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
101 var_Get( p_demux, "fake-fps", &val );
102 p_sys->f_fps = val.f_float;
103 p_sys->i_last_pts = 0;
105 /* Declare elementary stream */
106 es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC('f', 'a', 'k', 'e') );
107 p_sys->p_es_video = es_out_Add( p_demux->out, &fmt );
109 /* Update default_pts to a suitable value for access */
110 var_Create( p_demux, "fake-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
115 /*****************************************************************************
116 * Close: close device, free resources
117 *****************************************************************************/
118 static void Close( vlc_object_t *p_this )
120 demux_t *p_demux = (demux_t *)p_this;
121 demux_sys_t *p_sys = p_demux->p_sys;
126 /*****************************************************************************
128 *****************************************************************************/
129 static int Control( demux_t *p_demux, int i_query, va_list args )
131 demux_sys_t *p_sys = p_demux->p_sys;
137 /* Special for access_demux */
138 case DEMUX_CAN_PAUSE:
139 case DEMUX_SET_PAUSE_STATE:
140 case DEMUX_CAN_CONTROL_PACE:
141 pb = (vlc_bool_t*)va_arg( args, vlc_bool_t * );
145 case DEMUX_GET_PTS_DELAY:
146 pi64 = (int64_t*)va_arg( args, int64_t * );
147 *pi64 = (int64_t)var_GetInteger( p_demux, "fake-caching" ) * 1000;
151 pi64 = (int64_t*)va_arg( args, int64_t * );
152 *pi64 = p_sys->i_last_pts;
155 /* TODO implement others */
163 /*****************************************************************************
165 *****************************************************************************/
166 static int Demux( demux_t *p_demux )
168 demux_sys_t *p_sys = p_demux->p_sys;
169 block_t *p_block = block_New( p_demux, 1 );
171 if ( !p_sys->i_last_pts )
173 p_sys->i_last_pts = mdate();
177 p_sys->i_last_pts += I64C(1000000) / p_sys->f_fps;
178 mwait( p_sys->i_last_pts );
181 p_block->i_flags |= BLOCK_FLAG_TYPE_I;
182 p_block->i_dts = p_block->i_pts = p_sys->i_last_pts;
184 es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
185 es_out_Send( p_demux->out, p_sys->p_es_video, p_block );