Added --run-time option to specify how many second VLC will play an item
authorLaurent Aimar <fenrir@videolan.org>
Wed, 13 Jun 2007 19:49:08 +0000 (19:49 +0000)
committerLaurent Aimar <fenrir@videolan.org>
Wed, 13 Jun 2007 19:49:08 +0000 (19:49 +0000)
(Usefull to save live programs like DVB/UDP)

src/input/input.c
src/input/input_internal.h
src/input/var.c
src/libvlc-module.c

index d5058bd..f8a3b1c 100644 (file)
@@ -147,6 +147,7 @@ static input_thread_t *Create( vlc_object_t *p_parent, input_item_t *p_item,
     p_input->p->i_start = 0;
     p_input->i_time  = 0;
     p_input->p->i_stop  = 0;
     p_input->p->i_start = 0;
     p_input->i_time  = 0;
     p_input->p->i_stop  = 0;
+    p_input->p->i_run  = 0;
     p_input->p->i_title = 0;
     p_input->p->title   = NULL;
     p_input->p->i_title_offset = p_input->p->i_seekpoint_offset = 0;
     p_input->p->i_title = 0;
     p_input->p->title   = NULL;
     p_input->p->i_title_offset = p_input->p->i_seekpoint_offset = 0;
@@ -573,6 +574,7 @@ exit:
  *****************************************************************************/
 static void MainLoop( input_thread_t *p_input )
 {
  *****************************************************************************/
 static void MainLoop( input_thread_t *p_input )
 {
+    int64_t i_start_mdate = mdate();
     int64_t i_intf_update = 0;
     int i_updates = 0;
 
     int64_t i_intf_update = 0;
     int i_updates = 0;
 
@@ -586,10 +588,11 @@ static void MainLoop( input_thread_t *p_input )
         /* Do the read */
         if( p_input->i_state != PAUSE_S  )
         {
         /* Do the read */
         if( p_input->i_state != PAUSE_S  )
         {
-            if( p_input->p->i_stop <= 0 || p_input->i_time < p_input->p->i_stop )
-                i_ret=p_input->p->input.p_demux->pf_demux(p_input->p->input.p_demux);
+            if( ( p_input->p->i_stop > 0 && p_input->i_time >= p_input->p->i_stop ) ||
+                ( p_input->p->i_run > 0 && i_start_mdate+p_input->p->i_run < mdate() ) )
+                i_ret = 0; /* EOF */
             else
             else
-                i_ret = 0;  /* EOF */
+                i_ret = p_input->p->input.p_demux->pf_demux(p_input->p->input.p_demux);
 
             if( i_ret > 0 )
             {
 
             if( i_ret > 0 )
             {
@@ -659,6 +662,9 @@ static void MainLoop( input_thread_t *p_input )
                         input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
                                            &val );
                     }
                         input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION,
                                            &val );
                     }
+
+                    /* */
+                    i_start_mdate = mdate();
                 }
             }
             else if( i_ret < 0 )
                 }
             }
             else if( i_ret < 0 )
@@ -915,10 +921,14 @@ static int Init( input_thread_t * p_input )
 
         /* Start time*/
         /* Set start time */
 
         /* Start time*/
         /* Set start time */
-        p_input->p->i_start = (int64_t)var_GetInteger( p_input, "start-time" ) *
-                           I64C(1000000);
-        p_input->p->i_stop  = (int64_t)var_GetInteger( p_input, "stop-time" ) *
-                           I64C(1000000);
+        p_input->p->i_start = I64C(1000000) * var_GetInteger( p_input, "start-time" );
+        p_input->p->i_stop  = I64C(1000000) * var_GetInteger( p_input, "stop-time" );
+        p_input->p->i_run   = I64C(1000000) * var_GetInteger( p_input, "run-time" );
+        if( p_input->p->i_run < 0 )
+        {
+            msg_Warn( p_input, "invalid run-time ignored" );
+            p_input->p->i_run = 0;
+        }
 
         if( p_input->p->i_start > 0 )
         {
 
         if( p_input->p->i_start > 0 )
         {
index 065ef08..bd1adf7 100644 (file)
@@ -75,6 +75,7 @@ struct input_thread_private_t
     /* */
     int64_t     i_start;    /* :start-time,0 by default */
     int64_t     i_stop;     /* :stop-time, 0 if none */
     /* */
     int64_t     i_start;    /* :start-time,0 by default */
     int64_t     i_stop;     /* :stop-time, 0 if none */
+    int64_t     i_run;      /* :run-time, 0 if none */
 
     /* Title infos FIXME multi-input (not easy) ? */
     int          i_title;
 
     /* Title infos FIXME multi-input (not easy) ? */
     int          i_title;
index d8db99a..59b3f60 100644 (file)
@@ -432,6 +432,7 @@ void input_ConfigVarInit ( input_thread_t *p_input )
                     VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
         var_Create( p_input, "start-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
         var_Create( p_input, "stop-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
                     VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
         var_Create( p_input, "start-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
         var_Create( p_input, "stop-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
+        var_Create( p_input, "run-time", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
 
         var_Create( p_input, "input-slave",
                     VLC_VAR_STRING | VLC_VAR_DOINHERIT );
 
         var_Create( p_input, "input-slave",
                     VLC_VAR_STRING | VLC_VAR_DOINHERIT );
index eae0b1b..d0aae16 100644 (file)
@@ -531,6 +531,10 @@ static const char *ppsz_clock_descriptions[] =
 #define STOP_TIME_LONGTEXT N_( \
     "The stream will stop at this position (in seconds)." )
 
 #define STOP_TIME_LONGTEXT N_( \
     "The stream will stop at this position (in seconds)." )
 
+#define RUN_TIME_TEXT N_("Run time")
+#define RUN_TIME_LONGTEXT N_( \
+    "The stream will run this duration (in seconds)." )
+
 #define INPUT_LIST_TEXT N_("Input list")
 #define INPUT_LIST_LONGTEXT N_( \
     "You can give a comma-separated list " \
 #define INPUT_LIST_TEXT N_("Input list")
 #define INPUT_LIST_LONGTEXT N_( \
     "You can give a comma-separated list " \
@@ -1454,6 +1458,8 @@ vlc_module_begin();
                  START_TIME_TEXT, START_TIME_LONGTEXT, VLC_TRUE );
     add_integer( "stop-time", 0, NULL,
                  STOP_TIME_TEXT, STOP_TIME_LONGTEXT, VLC_TRUE );
                  START_TIME_TEXT, START_TIME_LONGTEXT, VLC_TRUE );
     add_integer( "stop-time", 0, NULL,
                  STOP_TIME_TEXT, STOP_TIME_LONGTEXT, VLC_TRUE );
+    add_integer( "run-time", 0, NULL,
+                 RUN_TIME_TEXT, RUN_TIME_LONGTEXT, VLC_TRUE );
     add_string( "input-list", NULL, NULL,
                  INPUT_LIST_TEXT, INPUT_LIST_LONGTEXT, VLC_TRUE );
     add_string( "input-slave", NULL, NULL,
     add_string( "input-list", NULL, NULL,
                  INPUT_LIST_TEXT, INPUT_LIST_LONGTEXT, VLC_TRUE );
     add_string( "input-slave", NULL, NULL,