]> git.sesse.net Git - vlc/blob - modules/access/fake.c
* changed some strings as suggested by E-bola
[vlc] / modules / access / fake.c
1 /*****************************************************************************
2  * fake.c : Fake video input for VLC
3  *****************************************************************************
4  * Copyright (C) 2005 VideoLAN
5  * $Id$
6  *
7  * Author: Christophe Massiot <massiot@via.ecp.fr>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30
31 #include <vlc/vlc.h>
32 #include <vlc/input.h>
33
34 /*****************************************************************************
35  * Module descriptior
36  *****************************************************************************/
37 static int  Open ( vlc_object_t * );
38 static void Close( vlc_object_t * );
39
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.97, 30).")
47
48 vlc_module_begin();
49     set_shortname( _("Fake") );
50     set_description( _("Fake input") );
51     set_category( CAT_INPUT );
52     set_subcategory( SUBCAT_INPUT_ACCESS );
53
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 );
57
58     add_shortcut( "fake" );
59     set_capability( "access_demux", 0 );
60     set_callbacks( Open, Close );
61 vlc_module_end();
62
63 /*****************************************************************************
64  * Access: local prototypes
65  *****************************************************************************/
66 static int Demux  ( demux_t * );
67 static int Control( demux_t *, int, va_list );
68
69 struct demux_sys_t
70 {
71     float f_fps;
72     mtime_t i_last_pts;    /* only used when f_fps > 0 */
73
74     es_out_id_t  *p_es_video;
75 };
76
77 /*****************************************************************************
78  * Open: opens fake device
79  *****************************************************************************/
80 static int Open( vlc_object_t *p_this )
81 {
82     demux_t     *p_demux = (demux_t*)p_this;
83     demux_sys_t *p_sys;
84     vlc_value_t val;
85     es_format_t fmt;
86
87     /* Only when selected */
88     if( *p_demux->psz_access == '\0' )
89         return VLC_EGENERIC;
90
91     /* Set up p_demux */
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 ) );
99
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;
104
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 );
108
109     /* Update default_pts to a suitable value for access */
110     var_Create( p_demux, "fake-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
111
112     return VLC_SUCCESS;
113 }
114
115 /*****************************************************************************
116  * Close: close device, free resources
117  *****************************************************************************/
118 static void Close( vlc_object_t *p_this )
119 {
120     demux_t     *p_demux = (demux_t *)p_this;
121     demux_sys_t *p_sys   = p_demux->p_sys;
122
123     free( p_sys );
124 }
125
126 /*****************************************************************************
127  * Control:
128  *****************************************************************************/
129 static int Control( demux_t *p_demux, int i_query, va_list args )
130 {
131     demux_sys_t *p_sys = p_demux->p_sys;
132     vlc_bool_t *pb;
133     int64_t    *pi64;
134
135     switch( i_query )
136     {
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 * );
142             *pb = VLC_FALSE;
143             return VLC_SUCCESS;
144
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;
148             return VLC_SUCCESS;
149
150         case DEMUX_GET_TIME:
151             pi64 = (int64_t*)va_arg( args, int64_t * );
152             *pi64 = p_sys->i_last_pts;
153             return VLC_SUCCESS;
154
155         /* TODO implement others */
156         default:
157             return VLC_EGENERIC;
158     }
159
160     return VLC_EGENERIC;
161 }
162
163 /*****************************************************************************
164  * Demux:
165  *****************************************************************************/
166 static int Demux( demux_t *p_demux )
167 {
168     demux_sys_t *p_sys = p_demux->p_sys;
169     block_t *p_block = block_New( p_demux, 1 );
170
171     if ( !p_sys->i_last_pts )
172     {
173         p_sys->i_last_pts = mdate();
174     }
175     else
176     {
177         p_sys->i_last_pts += I64C(1000000) / p_sys->f_fps;
178         mwait( p_sys->i_last_pts );
179     }
180
181     p_block->i_flags |= BLOCK_FLAG_TYPE_I;
182     p_block->i_dts = p_block->i_pts = p_sys->i_last_pts;
183
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 );
186
187     return 1;
188 }
189