Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

fake.c

00001 /*****************************************************************************
00002  * fake.c : Fake video input for VLC
00003  *****************************************************************************
00004  * Copyright (C) 2005 the VideoLAN team
00005  * $Id: fake.c 11948 2005-08-01 17:58:22Z massiot $
00006  *
00007  * Author: Christophe Massiot <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00022  *****************************************************************************/
00023 
00024 /*****************************************************************************
00025  * Preamble
00026  *****************************************************************************/
00027 #include <stdlib.h>
00028 #include <stdio.h>
00029 #include <string.h>
00030 
00031 #include <vlc/vlc.h>
00032 #include <vlc/input.h>
00033 
00034 /*****************************************************************************
00035  * Module descriptior
00036  *****************************************************************************/
00037 static int  Open ( vlc_object_t * );
00038 static void Close( vlc_object_t * );
00039 
00040 #define CACHING_TEXT N_("Caching value in ms")
00041 #define CACHING_LONGTEXT N_( \
00042     "Allows you to modify the default caching value for fake streams. This " \
00043     "value should be set in millisecond units." )
00044 #define FPS_TEXT N_("Framerate")
00045 #define FPS_LONGTEXT N_( \
00046     "Specifies the number of frames per second (eg. 24, 25, 29.97, 30).")
00047 #define ID_TEXT N_("ID")
00048 #define ID_LONGTEXT N_( \
00049     "Allows you to set the ID of the fake elementary stream for use in " \
00050     "#duplicate{} constructs (default 0).")
00051 #define DURATION_TEXT N_("Duration in ms")
00052 #define DURATION_LONGTEXT N_( \
00053     "Specifies the duration of the fake streaming before faking an " \
00054     "end-of-file (default 0 means the stream is unlimited).")
00055 
00056 vlc_module_begin();
00057     set_shortname( _("Fake") );
00058     set_description( _("Fake input") );
00059     set_category( CAT_INPUT );
00060     set_subcategory( SUBCAT_INPUT_ACCESS );
00061 
00062     add_integer( "fake-caching", DEFAULT_PTS_DELAY / 1000, NULL,
00063                  CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
00064     add_float( "fake-fps", 25.0, NULL, FPS_TEXT, FPS_LONGTEXT, VLC_TRUE );
00065     add_integer( "fake-id", 0, NULL, ID_TEXT, ID_LONGTEXT, VLC_TRUE );
00066     add_integer( "fake-duration", 0, NULL, DURATION_TEXT, DURATION_LONGTEXT,
00067                  VLC_TRUE );
00068 
00069     add_shortcut( "fake" );
00070     set_capability( "access_demux", 0 );
00071     set_callbacks( Open, Close );
00072 vlc_module_end();
00073 
00074 /*****************************************************************************
00075  * Access: local prototypes
00076  *****************************************************************************/
00077 static int Demux  ( demux_t * );
00078 static int Control( demux_t *, int, va_list );
00079 
00080 struct demux_sys_t
00081 {
00082     float f_fps;
00083     mtime_t i_last_pts, i_duration, i_first_pts, i_end_pts, i_pause_pts;
00084 
00085     es_out_id_t  *p_es_video;
00086 };
00087 
00088 /*****************************************************************************
00089  * Open: opens fake device
00090  *****************************************************************************/
00091 static int Open( vlc_object_t *p_this )
00092 {
00093     demux_t     *p_demux = (demux_t*)p_this;
00094     demux_sys_t *p_sys;
00095     vlc_value_t val;
00096     es_format_t fmt;
00097 
00098     /* Only when selected */
00099     if( *p_demux->psz_access == '\0' )
00100         return VLC_EGENERIC;
00101 
00102     /* Set up p_demux */
00103     p_demux->pf_demux = Demux;
00104     p_demux->pf_control = Control;
00105     p_demux->info.i_update = 0;
00106     p_demux->info.i_title = 0;
00107     p_demux->info.i_seekpoint = 0;
00108     p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
00109     memset( p_sys, 0, sizeof( demux_sys_t ) );
00110 
00111     var_Create( p_demux, "fake-duration", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00112     var_Get( p_demux, "fake-duration", &val );
00113     p_sys->i_duration = val.i_int * 1000;
00114 
00115     var_Create( p_demux, "fake-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
00116     var_Get( p_demux, "fake-fps", &val );
00117     p_sys->f_fps = val.f_float;
00118 
00119     /* Declare the elementary stream */
00120     es_format_Init( &fmt, VIDEO_ES, VLC_FOURCC('f','a','k','e') );
00121     var_Create( p_demux, "fake-id", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00122     var_Get( p_demux, "fake-id", &val );
00123     fmt.i_id = val.i_int;
00124     p_sys->p_es_video = es_out_Add( p_demux->out, &fmt );
00125 
00126     /* Update default_pts to a suitable value for access */
00127     var_Create( p_demux, "fake-caching", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
00128 
00129     return VLC_SUCCESS;
00130 }
00131 
00132 /*****************************************************************************
00133  * Close: close device, free resources
00134  *****************************************************************************/
00135 static void Close( vlc_object_t *p_this )
00136 {
00137     demux_t     *p_demux = (demux_t *)p_this;
00138     demux_sys_t *p_sys   = p_demux->p_sys;
00139 
00140     free( p_sys );
00141 }
00142 
00143 /*****************************************************************************
00144  * Control:
00145  *****************************************************************************/
00146 static int Control( demux_t *p_demux, int i_query, va_list args )
00147 {
00148     demux_sys_t *p_sys = p_demux->p_sys;
00149     vlc_bool_t *pb, b;
00150     int64_t    *pi64, i64;
00151     double     *pf, f;
00152 
00153     switch( i_query )
00154     {
00155         /* Special for access_demux */
00156         case DEMUX_CAN_PAUSE:
00157         case DEMUX_CAN_CONTROL_PACE:
00158             pb = (vlc_bool_t *)va_arg( args, vlc_bool_t * );
00159             *pb = VLC_TRUE;
00160             return VLC_SUCCESS;
00161 
00162         case DEMUX_SET_PAUSE_STATE:
00163             b = (vlc_bool_t)va_arg( args, vlc_bool_t );
00164             if ( b )
00165             {
00166                 p_sys->i_pause_pts = mdate();
00167             }
00168             else if ( p_sys->i_pause_pts )
00169             {
00170                 mtime_t i_pause_duration = mdate() - p_sys->i_pause_pts;
00171                 p_sys->i_first_pts += i_pause_duration;
00172                 p_sys->i_last_pts += i_pause_duration;
00173                 if ( p_sys->i_duration )
00174                     p_sys->i_end_pts += i_pause_duration;
00175                 p_sys->i_pause_pts = 0;
00176             }
00177             return VLC_SUCCESS;
00178 
00179         case DEMUX_GET_PTS_DELAY:
00180             pi64 = (int64_t *)va_arg( args, int64_t * );
00181             *pi64 = (int64_t)var_GetInteger( p_demux, "fake-caching" ) * 1000;
00182             return VLC_SUCCESS;
00183 
00184         case DEMUX_GET_POSITION:
00185             pf = (double*)va_arg( args, double* );
00186             if( p_sys->i_duration > 0 )
00187             {
00188                 *pf = (double)( p_sys->i_last_pts - p_sys->i_first_pts )
00189                                 / (double)(p_sys->i_duration);
00190             }
00191             else
00192             {
00193                 *pf = 0;
00194             }
00195             return VLC_SUCCESS;
00196 
00197         case DEMUX_SET_POSITION:
00198             f = (double)va_arg( args, double );
00199             i64 = f * (double)p_sys->i_duration;
00200             p_sys->i_first_pts = p_sys->i_last_pts - i64;
00201             p_sys->i_end_pts = p_sys->i_first_pts + p_sys->i_duration;
00202             return VLC_SUCCESS;
00203 
00204         case DEMUX_GET_TIME:
00205             pi64 = (int64_t *)va_arg( args, int64_t * );
00206             if ( p_sys->i_duration )
00207                 *pi64 = p_sys->i_last_pts - p_sys->i_first_pts;
00208             else
00209                 *pi64 = p_sys->i_last_pts;
00210             return VLC_SUCCESS;
00211 
00212         case DEMUX_GET_LENGTH:
00213             pi64 = (int64_t*)va_arg( args, int64_t * );
00214             *pi64 = p_sys->i_duration;
00215             return VLC_SUCCESS;
00216 
00217         case DEMUX_SET_TIME:
00218             i64 = (int64_t)va_arg( args, int64_t );
00219             p_sys->i_first_pts = p_sys->i_last_pts - i64;
00220             p_sys->i_end_pts = p_sys->i_first_pts + p_sys->i_duration;
00221             return VLC_SUCCESS;
00222 
00223         /* TODO implement others */
00224         default:
00225             return VLC_EGENERIC;
00226     }
00227 
00228     return VLC_EGENERIC;
00229 }
00230 
00231 /*****************************************************************************
00232  * Demux:
00233  *****************************************************************************/
00234 static int Demux( demux_t *p_demux )
00235 {
00236     demux_sys_t *p_sys = p_demux->p_sys;
00237     block_t *p_block = block_New( p_demux, 1 );
00238 
00239     if ( !p_sys->i_last_pts )
00240     {
00241         p_sys->i_last_pts = p_sys->i_first_pts = mdate();
00242         if ( p_sys->i_duration )
00243             p_sys->i_end_pts = p_sys->i_first_pts + p_sys->i_duration;
00244     }
00245     else
00246     {
00247         p_sys->i_last_pts += (mtime_t)(1000000.0 / p_sys->f_fps);
00248         if ( p_sys->i_duration && p_sys->i_last_pts > p_sys->i_end_pts )
00249             return 0;
00250         mwait( p_sys->i_last_pts );
00251     }
00252 
00253     p_block->i_flags |= BLOCK_FLAG_TYPE_I;
00254     p_block->i_dts = p_block->i_pts = p_sys->i_last_pts;
00255 
00256     es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
00257     es_out_Send( p_demux->out, p_sys->p_es_video, p_block );
00258 
00259     return 1;
00260 }
00261 

Generated on Tue Dec 20 10:14:24 2005 for vlc-0.8.4a by  doxygen 1.4.2