idummy.c 5.84 KB
Newer Older
1
/*****************************************************************************
2
 * idummy.c: dummy input plugin, to manage "vlc://" special options
3
 *****************************************************************************
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
4
 * Copyright (C) 2001, 2002 VLC authors and VideoLAN
5
 * $Id$
6 7 8
 *
 * Authors: Samuel Hocevar <sam@zoy.org>
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
9 10 11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
12
 * (at your option) any later version.
13
 *
14 15
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
16 17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
18
 *
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
19 20 21
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 23 24 25 26 27
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/

28 29 30 31
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

32
#include <vlc_common.h>
33
#include <vlc_plugin.h>
34 35
#include <vlc_interface.h>
#include <vlc_demux.h>
36
#include <vlc_charset.h>
37

38 39 40 41 42 43 44
static int OpenDemux( vlc_object_t * );
static void CloseDemux( vlc_object_t * );

vlc_module_begin ()
    set_shortname( N_("Dummy") )
    set_description( N_("Dummy input") )
    set_capability( "access_demux", 0 )
45
    set_callbacks( OpenDemux, NULL )
46 47
    add_shortcut( "dummy", "vlc" )
vlc_module_end ()
Clément Stenac's avatar
Clément Stenac committed
48

49
static int DemuxControl( demux_t *, int, va_list );
50

51 52 53 54 55
static int DemuxNoOp( demux_t *demux )
{
    (void) demux;
    return 0;
}
56

57 58 59 60 61 62 63
static int DemuxHold( demux_t *demux )
{
    (void) demux;
    msleep( 10000 ); /* FIXME!!! */
    return 1;
}

64 65 66 67 68 69
struct demux_sys_t
{
    mtime_t end;
    mtime_t length;
};

70
static int DemuxPause( demux_t *demux )
71
{
72
    demux_sys_t *p_sys = demux->p_sys;
73
    mtime_t now = mdate();
74

75
    if( now >= p_sys->end )
76
        return 0;
77

78 79 80
    msleep( 10000 ); /* FIXME!!! */
    return 1;
}
81

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
static int ControlPause( demux_t *demux, int query, va_list args )
{
    demux_sys_t *p_sys = demux->p_sys;

    switch( query )
    {
        case DEMUX_GET_POSITION:
        {
            double *ppos = va_arg( args, double * );
            double pos;
            mtime_t now = mdate();

            pos = 1. + ((double)(now - p_sys->end) / (double)p_sys->length);
            *ppos = (pos <= 1.) ? pos : 1.;
            break;
        }

        case DEMUX_SET_POSITION:
        {
            double pos = va_arg( args, double );
            mtime_t now = mdate();

            p_sys->end = now + (p_sys->length * (1. - pos));
            break;
        }

        case DEMUX_GET_LENGTH:
        {
            mtime_t *plen = va_arg( args, mtime_t * );
            *plen = p_sys->length;
            break;
        }

        case DEMUX_GET_TIME:
        {
            mtime_t *ppos = va_arg( args, mtime_t * );
            *ppos = mdate() + p_sys->length - p_sys->end;
            break;
        }

        case DEMUX_SET_TIME:
        {
            mtime_t pos = va_arg( args, mtime_t );
            p_sys->end = mdate() + p_sys->length - pos;
            break;
        }

        case DEMUX_CAN_SEEK:
            *va_arg( args, bool * ) = true;
            break;

        default:
            return DemuxControl( demux, query, args );
    }
    return VLC_SUCCESS;
}

139 140 141
/*****************************************************************************
 * OpenDemux: initialize the target, ie. parse the command
 *****************************************************************************/
142
static int OpenDemux( vlc_object_t *p_this )
143
{
144
    demux_t *p_demux = (demux_t*)p_this;
145
    char * psz_name = p_demux->psz_location;
146

147
    p_demux->p_sys = NULL;
148

149
    /* Check for a "vlc://nop" command */
150
    if( !strcasecmp( psz_name, "nop" ) )
151
    {
152
nop:
153
        msg_Info( p_demux, "command `nop'" );
154
        p_demux->pf_demux = DemuxNoOp;
155
        p_demux->pf_control = DemuxControl;
156
        return VLC_SUCCESS;
157 158
    }

159
    /* Check for a "vlc://quit" command */
160
    if( !strcasecmp( psz_name, "quit" ) )
161
    {
162
        msg_Info( p_demux, "command `quit'" );
163
        p_demux->pf_demux = DemuxNoOp;
164
        p_demux->pf_control = DemuxControl;
165
        libvlc_Quit( p_demux->obj.libvlc );
166
        return VLC_SUCCESS;
167 168
    }

169 170 171 172 173 174 175 176 177
    if( !strcasecmp( psz_name, "pause" ) )
    {
        msg_Info( p_demux, "command `pause'" );

        p_demux->pf_demux = DemuxHold;
        p_demux->pf_control = DemuxControl;
        return VLC_SUCCESS;
    }

178
    /* Check for a "vlc://pause:***" command */
179
    if( !strncasecmp( psz_name, "pause:", 6 ) )
180
    {
181
        double f = us_atof( psz_name + 6 );
182
        mtime_t length = f * CLOCK_FREQ;
183

184
        msg_Info( p_demux, "command `pause %f'", f );
185 186
        if( length == 0 )
            goto nop; /* avoid division by zero */
187

188
        demux_sys_t *p_sys = vlc_malloc( p_this, sizeof( *p_sys ) );
189
        if( p_sys == NULL )
190
            return VLC_ENOMEM;
191 192 193 194 195 196 197

        p_sys->end = mdate() + length;
        p_sys->length = length;

        p_demux->p_sys = p_sys;
        p_demux->pf_demux = DemuxPause;
        p_demux->pf_control = ControlPause;
198
        return VLC_SUCCESS;
199
    }
200

201
    msg_Err( p_demux, "unknown command `%s'", psz_name );
202
    return VLC_EGENERIC;
203 204
}

205 206
static int DemuxControl( demux_t *p_demux, int i_query, va_list args )
{
207
    (void)p_demux; (void)i_query; (void)args;
208 209 210 211 212 213 214 215 216 217 218
    switch( i_query )
    {
    case DEMUX_GET_PTS_DELAY:
    {
        int64_t *pi_pts_delay = va_arg( args, int64_t * );
        *pi_pts_delay = DEFAULT_PTS_DELAY;
        return VLC_SUCCESS;
    }
    default:
        return VLC_EGENERIC;
    }
219
}