[vlc-devel] [PATCH] negative stop-time offsets from the end

Aleksandr Pasechnik al at megamicron.net
Fri Mar 20 02:48:52 CET 2015


Negative stop-time, for example -N seconds, cause the stream to stop N seconds
before the end.

Original code suggestion by MooseSoftware in forum.videolan.org
---
 modules/gui/macosx/misc.m     |  2 +-
 modules/gui/macosx/open.m     |  2 +-
 modules/gui/macosx/playlist.m |  2 +-
 modules/gui/macosx/wizard.m   |  2 +-
 src/input/input.c             | 11 +++++++++++
 src/libvlc-module.c           |  3 ++-
 6 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/modules/gui/macosx/misc.m b/modules/gui/macosx/misc.m
index 9769172..b20ab77 100644
--- a/modules/gui/macosx/misc.m
+++ b/modules/gui/macosx/misc.m
@@ -867,7 +867,7 @@ void _drawFrameInRect(NSRect frameRect)
 {
     self = [super init];
     NSMutableCharacterSet *nonNumbers = [[[NSCharacterSet decimalDigitCharacterSet] invertedSet] mutableCopy];
-    [nonNumbers removeCharactersInString:@":"];
+    [nonNumbers removeCharactersInString:@"-:"];
     o_forbidden_characters = [nonNumbers copy];
     [nonNumbers release];
 
diff --git a/modules/gui/macosx/open.m b/modules/gui/macosx/open.m
index d37d497..c132793 100644
--- a/modules/gui/macosx/open.m
+++ b/modules/gui/macosx/open.m
@@ -475,7 +475,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
                 tempValue = [[components objectAtIndex:0] intValue] * 60 + [[components objectAtIndex:1] intValue];
             else if (componentCount == 3)
                 tempValue = [[components objectAtIndex:0] intValue] * 3600 + [[components objectAtIndex:1] intValue] * 60 + [[components objectAtIndex:2] intValue];
-            if (tempValue > 0)
+            if (tempValue != 0)
                 [o_options addObject: [NSString stringWithFormat:@"stop-time=%li", tempValue]];
         }
         if ([o_output_ckbox state] == NSOnState) {
diff --git a/modules/gui/macosx/playlist.m b/modules/gui/macosx/playlist.m
index 825f1c2..e29644a 100644
--- a/modules/gui/macosx/playlist.m
+++ b/modules/gui/macosx/playlist.m
@@ -973,7 +973,7 @@
     /* allow the user to over-write the start/stop/run-time */
     if (var_GetFloat(p_input_thread, "run-time") > 0 ||
         var_GetFloat(p_input_thread, "start-time") > 0 ||
-        var_GetFloat(p_input_thread, "stop-time") > 0) {
+        var_GetFloat(p_input_thread, "stop-time") != 0) {
         return;
     }
 
diff --git a/modules/gui/macosx/wizard.m b/modules/gui/macosx/wizard.m
index e8c832f..7db0503 100644
--- a/modules/gui/macosx/wizard.m
+++ b/modules/gui/macosx/wizard.m
@@ -1232,7 +1232,7 @@ static VLCWizard *_o_sharedInstance = nil;
                     time = 1000000 * ([[components objectAtIndex:0] intValue] * 3600 + [[components objectAtIndex:1] intValue] * 60 + [[components objectAtIndex:2] intValue]);
                 else
                     msg_Err(VLCIntf, "Invalid string format for time");
-                input_item_AddOption(p_input, [[NSString stringWithFormat: @"stop-time=%lu", time] UTF8String], VLC_INPUT_OPTION_TRUSTED);
+                input_item_AddOption(p_input, [[NSString stringWithFormat: @"stop-time=%ld", time] UTF8String], VLC_INPUT_OPTION_TRUSTED);
             }
 
             input_item_AddOption( p_input, [[NSString stringWithFormat:
diff --git a/src/input/input.c b/src/input/input.c
index 7de30ec..5f5dac2 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -900,6 +900,17 @@ static void StartTitle( input_thread_t * p_input )
         msg_Warn( p_input, "invalid run-time ignored" );
         p_input->p->i_run = 0;
     }
+    if( p_input->p->i_stop < 0 )
+    {
+        mtime_t duration = input_item_GetDuration( p_input->p->p_item );
+        /* check that the resulting stop-time will actually be positive */
+        if( duration + p_input->p->i_stop > 0 )
+        {
+            p_input->p->i_stop = duration + p_input->p->i_stop;
+            msg_Dbg( p_input, "recalculated stop-time to %ds",
+                     (int) p_input->p->i_stop );
+        }
+    }
 
     if( p_input->p->i_start > 0 )
     {
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 31037b4..e7ca2aa 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -627,7 +627,8 @@ static const char *const ppsz_prefres[] = {
 
 #define STOP_TIME_TEXT N_("Stop time")
 #define STOP_TIME_LONGTEXT N_( \
-    "The stream will stop at this position (in seconds)." )
+    "The stream will stop at this position (in seconds). " \
+    "Negative values are offset from the end." )
 
 #define RUN_TIME_TEXT N_("Run time")
 #define RUN_TIME_LONGTEXT N_( \
-- 
2.3.3




More information about the vlc-devel mailing list