]> git.sesse.net Git - vlc/blobdiff - plugins/dummy/input_dummy.c
* ALL: changed "struct foo_s" into "struct foo_t" to make greppers happy.
[vlc] / plugins / dummy / input_dummy.c
index b0e659cf40ff793915056ca83a31829f745a8e9d..fab47c066a9889ec26dc350bbc55d66b211eec18 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * input_dummy.c: dummy input plugin, to manage "vlc:***" special options
  *****************************************************************************
- * Copyright (C) 2001 VideoLAN
- * $Id: input_dummy.c,v 1.11 2001/12/30 07:09:55 sam Exp $
+ * Copyright (C) 2001, 2002 VideoLAN
+ * $Id: input_dummy.c,v 1.20 2002/07/20 18:01:42 sam Exp $
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *
 #include <string.h>
 #include <errno.h>
 
-#include <videolan/vlc.h>
-
-#ifdef STRNCASECMP_IN_STRINGS_H
-#   include <strings.h>
-#endif
-
-#include "interface.h"
-#include "intf_playlist.h"
-
-#include "stream_control.h"
-#include "input_ext-intf.h"
-#include "input_ext-dec.h"
-#include "input_ext-plugins.h"
+#include <vlc/vlc.h>
+#include <vlc/intf.h>
+#include <vlc/input.h>
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int  DummyProbe     ( probedata_t * );
-static void DummyOpen      ( struct input_thread_s * );
-static void DummyClose     ( struct input_thread_s * );
+static int  DummyInit   ( input_thread_t * );
+static int  DummyOpen   ( input_thread_t * );
+static void DummyClose  ( input_thread_t * );
+static void DummyEnd    ( input_thread_t * );
+static int  DummyDemux  ( input_thread_t * );
+
+/*****************************************************************************
+ * access_sys_t: private input data
+ *****************************************************************************/
+struct demux_sys_t
+{
+    /* The real command */
+    int i_command;
+
+    /* Used for the pause command */
+    mtime_t expiration;
+};
+
+#define COMMAND_NOP   0
+#define COMMAND_QUIT  1
+#define COMMAND_LOOP  2
+#define COMMAND_PAUSE 3
 
 /*****************************************************************************
  * Functions exported as capabilities. They are declared as static so that
  * we don't pollute the namespace too much.
  *****************************************************************************/
-void _M( input_getfunctions )( function_list_t * p_function_list )
+void _M( access_getfunctions )( function_list_t * p_function_list )
 {
-#define input p_function_list->functions.input
-    p_function_list->pf_probe = DummyProbe;
-    input.pf_init             = NULL; /* Not needed, open is called first */
+#define input p_function_list->functions.access
     input.pf_open             = DummyOpen;
+    input.pf_read             = NULL;
     input.pf_close            = DummyClose;
-    input.pf_end              = NULL;
+    input.pf_set_program      = NULL;
     input.pf_set_area         = NULL;
-    input.pf_read             = NULL;
-    input.pf_demux            = NULL;
-    input.pf_new_packet       = NULL;
-    input.pf_new_pes          = NULL;
-    input.pf_delete_packet    = NULL;
-    input.pf_delete_pes       = NULL;
-    input.pf_rewind           = NULL;
     input.pf_seek             = NULL;
 #undef input
 }
 
-/*
- * Data reading functions
- */
+void _M( demux_getfunctions )( function_list_t * p_function_list )
+{
+#define input p_function_list->functions.demux
+    input.pf_init             = DummyInit;
+    input.pf_end              = DummyEnd;
+    input.pf_demux            = DummyDemux;
+    input.pf_rewind           = NULL;
+#undef input
+}
 
 /*****************************************************************************
- * DummyProbe: verifies that the input is a vlc command
+ * DummyOpen: open the target, ie. do nothing
  *****************************************************************************/
-static int DummyProbe( probedata_t *p_data )
+static int DummyOpen( input_thread_t * p_input )
 {
-    input_thread_t *p_input = (input_thread_t *)p_data;
-    char *psz_name = p_input->p_source;
+    p_input->stream.i_method = INPUT_METHOD_NONE;
 
-    if( ( strlen(psz_name) > 4 ) && !strncasecmp( psz_name, "vlc:", 4 ) )
-    {
-        /* If the user specified "vlc:" then it's probably a file */
-        return( 100 );
-    }
+    /* Force dummy demux plug-in */
+    p_input->psz_demux = "vlc";
+    return 0;
+}
 
-    return( 1 );
+/*****************************************************************************
+ * DummyClose: close the target, ie. do nothing
+ *****************************************************************************/
+static void DummyClose( input_thread_t * p_input )
+{
 }
 
 /*****************************************************************************
- * DummyOpen: open the target, ie. do what the command says
+ * DummyInit: initialize the target, ie. parse the command
  *****************************************************************************/
-static void DummyOpen( input_thread_t * p_input )
+static int DummyInit( input_thread_t *p_input )
 {
-    char *psz_name = p_input->p_source;
-    int   i_len = strlen( psz_name );
+    char * psz_name = p_input->psz_name;
+    int i_len = strlen( psz_name );
+    struct demux_sys_t * p_method;
     int   i_arg;
     
-    /* XXX: Tell the input layer to quit immediately, there must
-     * be a nicer way to do this. */
-    p_input->b_error = 1;
+    p_input->stream.b_seekable = 0;
 
-    if( ( i_len <= 4 ) || strncasecmp( psz_name, "vlc:", 4 ) )
+    p_method = malloc( sizeof( struct demux_sys_t ) );
+    if( p_method == NULL )
     {
-        /* If the command doesn't start with "vlc:" then it's not for us */
-        return;
+        msg_Err( p_input, "out of memory" );
+        return -1;
     }
 
-    /* We don't need the "vlc:" stuff any more */
-    psz_name += 4;
-    i_len -= 4;
+    p_input->p_demux_data = p_method;
+    p_input->stream.p_demux_data = NULL;
+
+    /* Check for a "vlc:nop" command */
+    if( i_len == 3 && !strncasecmp( psz_name, "nop", 3 ) )
+    {
+        msg_Info( p_input, "command `nop'" );
+        p_method->i_command = COMMAND_NOP;
+        return 0;
+    }
 
     /* Check for a "vlc:quit" command */
     if( i_len == 4 && !strncasecmp( psz_name, "quit", 4 ) )
     {
-        intf_WarnMsg( 2, "input: command `quit'" );
-        p_main->p_intf->b_die = 1;
-        return;
+        msg_Info( p_input, "command `quit'" );
+        p_method->i_command = COMMAND_QUIT;
+        return 0;
     }
 
     /* Check for a "vlc:loop" command */
     if( i_len == 4 && !strncasecmp( psz_name, "loop", 4 ) )
     {
-        intf_WarnMsg( 2, "input: command `loop'" );
-        intf_PlaylistJumpto( p_main->p_playlist, -1 );
-        return;
+        msg_Info( p_input, "command `loop'" );
+        p_method->i_command = COMMAND_LOOP;
+        return 0;
     }
 
     /* Check for a "vlc:pause:***" command */
     if( i_len > 6 && !strncasecmp( psz_name, "pause:", 6 ) )
     {
         i_arg = atoi( psz_name + 6 );
-
-        intf_WarnMsgImm( 2, "input: command `pause %i'", i_arg );
-
-        msleep( i_arg * 1000000 );
-        return;
+        msg_Info( p_input, "command `pause %i'", i_arg );
+        p_method->i_command = COMMAND_PAUSE;
+        p_method->expiration = mdate() + (mtime_t)i_arg * (mtime_t)1000000;
+        return 0;
     }
 
-    intf_ErrMsg( "input error: unknown command `%s'", psz_name );
+    msg_Err( p_input, "unknown command `%s'", psz_name );
+    free( p_input->p_demux_data );
+    p_input->b_error = 1;
 
+    return -1;
 }
 
 /*****************************************************************************
- * DummyClose: close the target, ie. do nothing
+ * DummyEnd: end the target, ie. do nothing
  *****************************************************************************/
-static void DummyClose( input_thread_t * p_input )
+static void DummyEnd( input_thread_t *p_input )
 {
-    return;
+    free( p_input->p_demux_data );
+}
+
+/*****************************************************************************
+ * DummyDemux: do what the command says
+ *****************************************************************************/
+static int DummyDemux( input_thread_t *p_input )
+{
+    struct demux_sys_t * p_method = p_input->p_demux_data;
+    playlist_t *p_playlist;
+
+    p_playlist = vlc_object_find( p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
+
+    if( p_playlist == NULL )
+    {
+        msg_Err( p_input, "we are not attached to a playlist" );
+        p_input->b_error = 1;
+        return 1;
+    }
+
+    switch( p_method->i_command )
+    {
+        case COMMAND_QUIT:
+            p_input->p_vlc->b_die = 1;
+            break;
+
+        case COMMAND_LOOP:
+            playlist_Goto( p_playlist, 0 );
+            break;
+
+        case COMMAND_PAUSE:
+            if( mdate() < p_method->expiration )
+            {
+                msleep( 10000 );
+            }
+            else
+            {
+                p_input->b_eof = 1;
+            }
+            break;
+
+        case COMMAND_NOP:
+        default:
+            p_input->b_eof = 1;
+            break;
+    }
+
+    vlc_object_release( p_playlist );
+
+    return 1;
 }