]> git.sesse.net Git - vlc/commitdiff
* input: fixed position-offset, time and time-offset.
authorLaurent Aimar <fenrir@videolan.org>
Tue, 4 Nov 2003 02:23:11 +0000 (02:23 +0000)
committerLaurent Aimar <fenrir@videolan.org>
Tue, 4 Nov 2003 02:23:11 +0000 (02:23 +0000)
 * hotkeys: never _never_ use  demux_Control outside of src/input/ (it's
 completely broken,  there is a lot  more things to do),  all interfaces
 have  to  use  var_Get/Set  (time(-offset),  position(-offset),  state,
 rate(-slower|-faster)...  ).
 Btw,   input_SetStatus,   input_Seek,   input_Tell,   input_ChangeArea,
 input_ToggleES,  will   be  quickly   obsolete  and   removed(at  least
 unavailable for intf), so we should convert remaining interfaces (ie all
 except wx, osx, rc, http, hotkeys).

 * avi: implemented DEMUX_SET_TIME (not yet used).

modules/codec/faad.c
modules/control/hotkeys.c
modules/demux/avi/avi.c
src/input/input.c

index 745d960215529a0735852539f183a58b1c8ec76a..d15aa6f6bb0e00827bd63884769368e6b4b96609 100644 (file)
@@ -2,7 +2,7 @@
  * decoder.c: AAC decoder using libfaad2
  *****************************************************************************
  * Copyright (C) 2001, 2003 VideoLAN
- * $Id: faad.c,v 1.1 2003/11/03 22:30:15 fenrir Exp $
+ * $Id: faad.c,v 1.2 2003/11/04 02:23:11 fenrir Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -323,15 +323,3 @@ static int  EndDecoder    ( decoder_t *p_dec )
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
index f64e099b5722dfcabf804ab287c9585c932c4ad3..4c554dcabfe9f8235b71867d3efbbbd1c94195a2 100755 (executable)
@@ -2,7 +2,7 @@
  * hotkeys.c: Hotkey handling for vlc
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: hotkeys.c,v 1.7 2003/10/31 18:18:46 gbazin Exp $
+ * $Id: hotkeys.c,v 1.8 2003/11/04 02:23:11 fenrir Exp $
  *
  * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
  *
@@ -25,7 +25,6 @@
  * Preamble
  *****************************************************************************/
 #include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>
 
 #include <vlc/vlc.h>
 #include <vlc/intf.h>
@@ -240,11 +239,16 @@ static void Run( intf_thread_t *p_intf )
         }
         else if( i_action == ACTIONID_PLAY_PAUSE )
         {
-            if( p_input &&
-                p_input->stream.control.i_status != PAUSE_S )
+            val.i_int = PLAYING_S;
+            if( p_input )
+            {
+                var_Get( p_input, "state", &val );
+            }
+            if( p_input && val.i_int != PAUSE_S )
             {
                 vout_OSDMessage( VLC_OBJECT(p_intf), _( "Pause" ) );
-                input_SetStatus( p_input, INPUT_STATUS_PAUSE );
+                val.i_int = PAUSE_S;
+                var_Set( p_input, "state", val );
             }
             else
             {
@@ -265,48 +269,47 @@ static void Run( intf_thread_t *p_intf )
         }
         else if( p_input )
         {
-            uint64_t i_time;
-
             if( i_action == ACTIONID_PAUSE )
             {
                 vout_OSDMessage( VLC_OBJECT(p_intf), _( "Pause" ) );
-                input_SetStatus( p_input, INPUT_STATUS_PAUSE );
+                val.i_int = PAUSE_S;
+                var_Set( p_input, "state", val );
             }
             else if( i_action == ACTIONID_JUMP_BACKWARD_10SEC )
             {
                 vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump -10 seconds" ) );
-                demux_Control( p_input, DEMUX_GET_TIME, &i_time );
-                demux_Control( p_input, DEMUX_SET_TIME, i_time - 10000000 );
+                val.i_time = -10000000LL;
+                var_Set( p_input, "time-offset", val );
             }
             else if( i_action == ACTIONID_JUMP_FORWARD_10SEC )
             {
                 vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump +10 seconds" ) );
-                demux_Control( p_input, DEMUX_GET_TIME, &i_time );
-                demux_Control( p_input, DEMUX_SET_TIME, i_time + 10000000 );
+                val.i_time = 10000000LL;
+                var_Set( p_input, "time-offset", val );
             }
             else if( i_action == ACTIONID_JUMP_BACKWARD_1MIN )
             {
                 vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump -1 minute" ) );
-                demux_Control( p_input, DEMUX_GET_TIME, &i_time );
-                demux_Control( p_input, DEMUX_SET_TIME, i_time - 60000000 );
+                val.i_time = -60000000LL;
+                var_Set( p_input, "time-offset", val );
             }
             else if( i_action == ACTIONID_JUMP_FORWARD_1MIN )
             {
                 vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump +1 minute" ) );
-                demux_Control( p_input, DEMUX_GET_TIME, &i_time );
-                demux_Control( p_input, DEMUX_SET_TIME, i_time + 60000000 );
+                val.i_time = 60000000LL;
+                var_Set( p_input, "time-offset", val );
             }
             else if( i_action == ACTIONID_JUMP_BACKWARD_5MIN )
             {
                 vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump -5 minutes" ) );
-                demux_Control( p_input, DEMUX_GET_TIME, &i_time );
-                demux_Control( p_input, DEMUX_SET_TIME, i_time - 300000000 );
+                val.i_time = -300000000LL;
+                var_Set( p_input, "time-offset", val );
             }
             else if( i_action == ACTIONID_JUMP_FORWARD_5MIN )
             {
                 vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump +5 minutes" ) );
-                demux_Control( p_input, DEMUX_GET_TIME, &i_time );
-                demux_Control( p_input, DEMUX_SET_TIME, i_time + 300000000 );
+                val.i_time = 300000000LL;
+                var_Set( p_input, "time-offset", val );
             }
             else if( i_action == ACTIONID_NEXT )
             {
index 251abf2e4917d0dd4334e11f7052f09e0794e833..21058edb1fb24bbe8139ca12ddd3ce6d121407a6 100644 (file)
@@ -2,7 +2,7 @@
  * avi.c : AVI file Stream input module for vlc
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: avi.c,v 1.63 2003/10/19 13:39:11 hartman Exp $
+ * $Id: avi.c,v 1.64 2003/11/04 02:23:11 fenrir Exp $
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -1087,7 +1087,7 @@ static int Seek( input_thread_t *p_input, mtime_t i_date, int i_percent )
 
     if( p_avi->b_seekable )
     {
-        if( !p_avi->i_length || p_avi->b_interleaved )
+        if( !p_avi->i_length ) //|| p_avi->b_interleaved )
         {
             avi_stream_t *p_stream;
             int64_t i_pos;
@@ -1201,6 +1201,39 @@ static int Seek( input_thread_t *p_input, mtime_t i_date, int i_percent )
  *****************************************************************************
  *
  *****************************************************************************/
+static double ControlGetPosition( input_thread_t *p_input )
+{
+    demux_sys_t *p_sys = p_input->p_demux_data;
+
+    if( p_sys->i_length > 0 )
+    {
+        return (double)p_sys->i_time / (double)( p_sys->i_length * (mtime_t)1000000 );
+    }
+    else if( stream_Size( p_input->s ) > 0 )
+    {
+        unsigned int i;
+        int64_t i_tmp;
+        int64_t i64 = 0;
+
+        /* search the more advanced selected es */
+        for( i = 0; i < p_sys->i_streams; i++ )
+        {
+            avi_stream_t *tk = p_sys->pp_info[i];
+            if( tk->b_activated && tk->i_idxposc < tk->i_idxnb )
+            {
+                i_tmp = tk->p_index[tk->i_idxposc].i_pos +
+                        tk->p_index[tk->i_idxposc].i_length + 8;
+                if( i_tmp > i64 )
+                {
+                    i64 = i_tmp;
+                }
+            }
+        }
+        return (double)i64 / (double)stream_Size( p_input->s );
+    }
+    return 0.0;
+}
+
 static int    Control( input_thread_t *p_input, int i_query, va_list args )
 {
     demux_sys_t *p_sys = p_input->p_demux_data;
@@ -1212,64 +1245,38 @@ static int    Control( input_thread_t *p_input, int i_query, va_list args )
     {
         case DEMUX_GET_POSITION:
             pf = (double*)va_arg( args, double * );
-            if( p_sys->i_length > 0 )
-            {
-                *pf = (double)p_sys->i_time / (double)( p_sys->i_length * (mtime_t)1000000 );
-                return VLC_SUCCESS;
-            }
-            else if( stream_Size( p_input->s ) > 0 )
-            {
-                unsigned int i;
-                int64_t i_tmp;
-
-                i64 = 0;
-                /* search the more advanced selected es */
-                for( i = 0; i < p_sys->i_streams; i++ )
-                {
-#define tk  p_sys->pp_info[i]
-                    if( tk->b_activated && tk->i_idxposc < tk->i_idxnb )
-                    {
-                        i_tmp = tk->p_index[tk->i_idxposc].i_pos +
-                                tk->p_index[tk->i_idxposc].i_length + 8;
-                        if( i_tmp > i64 )
-                        {
-                            i64 = i_tmp;
-                        }
-                    }
-#undef tk
-                }
-                *pf = (double)i64 / (double)stream_Size( p_input->s );
-                return VLC_SUCCESS;
-            }
-            else
-            {
-                *pf = 0.0;
-                return VLC_SUCCESS;
-            }
+            *pf = ControlGetPosition( p_input );
+            return VLC_SUCCESS;
         case DEMUX_SET_POSITION:
             if( p_sys->b_seekable )
             {
-                int i_ret;
-
                 f = (double)va_arg( args, double );
                 i64 = (mtime_t)(1000000.0 * p_sys->i_length * f );
-                i_ret = Seek( p_input, i64, (int)(f * 100) );
-                return i_ret;
-            }
-            else
-            {
-                return demux_vaControlDefault( p_input, i_query, args );
+                return Seek( p_input, i64, (int)(f * 100) );
             }
+            return demux_vaControlDefault( p_input, i_query, args );
+
         case DEMUX_GET_TIME:
             pi64 = (int64_t*)va_arg( args, int64_t * );
             *pi64 = p_sys->i_time;
             return VLC_SUCCESS;
 
         case DEMUX_SET_TIME:
-            msg_Err( p_input, "FIXME DEMUX_SET_TIME to be implemented" );
-            return VLC_EGENERIC;
-            /* return demux_vaControlDefault( p_input, i_query, args ); */
+        {
+            int i_percent = 0;
 
+            i64 = (int64_t)va_arg( args, int64_t );
+            if( p_sys->i_length > 0 )
+            {
+                i_percent = 100 * i64 / (p_sys->i_length*1000000ULL);
+            }
+            else if( p_sys->i_time > 0 )
+            {
+                i_percent = (int)( 100.0 * ControlGetPosition( p_input ) *
+                                   (double)i64 / (double)p_sys->i_time );
+            }
+            return Seek( p_input, i64, i_percent );
+        }
         case DEMUX_GET_LENGTH:
             pi64 = (int64_t*)va_arg( args, int64_t * );
             *pi64 = p_sys->i_length * (mtime_t)1000000;
@@ -1280,13 +1287,12 @@ static int    Control( input_thread_t *p_input, int i_query, va_list args )
             *pf = 0.0;
             for( i = 0; i < (int)p_sys->i_streams; i++ )
             {
-#define tk p_sys->pp_info[i]
+                avi_stream_t *tk = p_sys->pp_info[i];
                 if( tk->i_cat == VIDEO_ES && tk->i_scale > 0)
                 {
                     *pf = (float)tk->i_rate / (float)tk->i_scale;
                     break;
                 }
-#undef tk
             }
             return VLC_SUCCESS;
 
index 9139ebcb149f16378e98a732bccbc999058ceaff..a1a8966f92e00ea402891ca64c34ea8b0271d994 100644 (file)
@@ -4,7 +4,7 @@
  * decoders.
  *****************************************************************************
  * Copyright (C) 1998-2002 VideoLAN
- * $Id: input.c,v 1.250 2003/10/29 01:33:26 gbazin Exp $
+ * $Id: input.c,v 1.251 2003/11/04 02:23:11 fenrir Exp $
  *
  * Authors: Christophe Massiot <massiot@via.ecp.fr>
  *
@@ -127,6 +127,7 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
     val.f_float = 0.0;
     var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
     var_AddCallback( p_input, "position", PositionCallback, NULL );
+    var_AddCallback( p_input, "position-offset", PositionCallback, NULL );
 
     /* time variable */
     var_Create( p_input, "time",  VLC_VAR_TIME );
@@ -134,6 +135,7 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
     val.i_time = 0;
     var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
     var_AddCallback( p_input, "time", TimeCallback, NULL );
+    var_AddCallback( p_input, "time-offset", TimeCallback, NULL );
 
     /* length variable */
     var_Create( p_input, "length",  VLC_VAR_TIME );
@@ -1219,22 +1221,23 @@ static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
                              void *p_data )
 {
     input_thread_t *p_input = (input_thread_t *)p_this;
-    int64_t i_offset;
 
     msg_Dbg( p_input, "cmd=%s old=%f new=%f", psz_cmd,
              oldval.f_float, newval.f_float );
 
-    vlc_mutex_lock( &p_input->stream.stream_lock );
-    i_offset = (int64_t)( newval.f_float *
-                          (double)p_input->stream.p_selected_area->i_size );
     if( !strcmp( psz_cmd, "position-offset" ) )
     {
-        p_input->stream.p_selected_area->i_seek += i_offset;
-    }
-    else
-    {
-        p_input->stream.p_selected_area->i_seek = i_offset;
+        vlc_value_t val;
+        var_Get( p_input, "position", &val );
+
+        newval.f_float += val.f_float;
     }
+
+    vlc_mutex_lock( &p_input->stream.stream_lock );
+    p_input->stream.p_selected_area->i_seek =
+                    (int64_t)( newval.f_float *
+                               (double)p_input->stream.p_selected_area->i_size );
+
     if( p_input->stream.p_selected_area->i_seek < 0 )
     {
         p_input->stream.p_selected_area->i_seek = 0;
@@ -1248,29 +1251,29 @@ static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
     input_thread_t *p_input = (input_thread_t *)p_this;
-    int64_t i_offset;
+    vlc_value_t     val;
 
     /* FIXME TODO FIXME */
     msg_Dbg( p_input, "cmd=%s old=%lld new=%lld", psz_cmd,
              oldval.i_time, newval.i_time );
 
-
-    vlc_mutex_lock( &p_input->stream.stream_lock );
-    i_offset = newval.i_time / 1000000 * 50 * p_input->stream.i_mux_rate;
-    if( !strcmp( psz_cmd, "time-offset" ) )
+    var_Get( p_input, "length", &val );
+    if( val.i_time > 0 )
     {
-        p_input->stream.p_selected_area->i_seek += i_offset;
+        val.f_float = (double)newval.i_time / (double)val.i_time;
+        if( !strcmp( psz_cmd, "time-offset" ) )
+        {
+            var_Set( p_input, "position-offset", val );
+        }
+        else
+        {
+            var_Set( p_input, "position", val );
+        }
     }
     else
     {
-        p_input->stream.p_selected_area->i_seek = i_offset;
-    }
-    if( p_input->stream.p_selected_area->i_seek < 0 )
-    {
-        p_input->stream.p_selected_area->i_seek = 0;
+        msg_Warn( p_input, "TimeCallback: length <= 0 -> can't seek" );
     }
-    vlc_mutex_unlock( &p_input->stream.stream_lock );
-
     return VLC_SUCCESS;
 }