]> git.sesse.net Git - vlc/commitdiff
Convert "rate" variable to float everywhere
authorRémi Denis-Courmont <remi@remlab.net>
Mon, 23 Nov 2009 16:44:52 +0000 (18:44 +0200)
committerRémi Denis-Courmont <remi@remlab.net>
Mon, 23 Nov 2009 17:03:11 +0000 (19:03 +0200)
This follows the historical LibVLC semantic (and new --rate one), so
bigger is faster. In the process, simplify a few code paths, especially
those in LibVLC, but make many other code paths more complicated due to
integer<->float conversion. Most of those paths could probably be
simplified.

 * Fix RC "fastforward" command behaviour (it was slowing down instead)
 * Fix str_format_mera 'R' format string with negative rates and
   rates such that (rate % 1000 < 100).

14 files changed:
include/vlc_input.h
modules/control/hotkeys.c
modules/control/rc.c
modules/gui/beos/InterfaceWindow.cpp
modules/gui/qt4/input_manager.cpp
modules/gui/wince/timer.cpp
share/lua/intf/rc.lua
src/control/media_player.c
src/input/control.c
src/input/event.c
src/input/var.c
src/input/vlm.c
src/input/vlmshell.c
src/text/strings.c

index 330b574600494d33fca506638fd8b55a6c31813d..1f152eff8438e76ce1056810e7553157db736a40 100644 (file)
@@ -344,12 +344,14 @@ typedef enum input_state_e
 /**
  * Input rate.
  *
- * It is an integer used by the variable "rate" in the
- * range [INPUT_RATE_MIN, INPUT_RATE_MAX] the default value
- * being INPUT_RATE_DEFAULT.
+ * It is an float used by the variable "rate" in the
+ * range [INPUT_RATE_DEFAULT/INPUT_RATE_MAX, INPUT_RATE_DEFAULT/INPUT_RATE_MAX]
+ * the default value being 1. It represents the ratio of playback speed to
+ * nominal speed (bigger is faster).
  *
- * A value lower than INPUT_RATE_DEFAULT plays faster.
- * A value higher than INPUT_RATE_DEFAULT plays slower.
+ * Internally, the rate is stored as a value in the range
+ * [INPUT_RATE_MIN, INPUT_RATE_MAX].
+ * internal rate = INPUT_RATE_DEFAULT / rate variable
  */
 
 /**
@@ -452,7 +454,7 @@ enum input_query_e
     INPUT_GET_TIME,             /* arg1= int64_t *      res=    */
     INPUT_SET_TIME,             /* arg1= int64_t        res=can fail    */
 
-    /* input variable "rate" (1 is DEFAULT_RATE) */
+    /* input variable "rate" (nominal is INPUT_RATE_DEFAULT) */
     INPUT_GET_RATE,             /* arg1= int *          res=    */
     INPUT_SET_RATE,             /* arg1= int            res=can fail    */
 
index d0f1e4deb775412f2e9b1bf3107363b5a9b111b0..c91a948477b4cb1e9376c3166a68f4d794754cfc 100644 (file)
@@ -710,7 +710,7 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
             }
             else if( i_action == ACTIONID_RATE_NORMAL )
             {
-                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
+                var_SetFloat( p_input, "rate", 1. );
                 vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
                                  "%s", _("1.00x") );
             }
@@ -721,9 +721,12 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
                  * and we want to increase/decrease it by 0.1 while making sure
                  * that the resulting playback rate is a multiple of 0.1
                  */
-                int i_rate = var_GetInteger( p_input, "rate" );
-                if( i_rate == 0 )
+                int i_rate = 1. * INPUT_RATE_DEFAULT
+                             / var_GetFloat( p_input, "rate" );
+                if( i_rate < INPUT_RATE_MIN )
                     i_rate = INPUT_RATE_MIN;
+                else if( i_rate > INPUT_RATE_MAX )
+                    i_rate = INPUT_RATE_MAX;
                 int i_sign = i_rate < 0 ? -1 : 1;
                 const int i_dir = i_action == ACTIONID_RATE_FASTER_FINE ? 1 : -1;
 
@@ -735,7 +738,7 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
 
                 i_rate = i_sign * __MIN( __MAX( i_rate, INPUT_RATE_MIN ), INPUT_RATE_MAX );
 
-                var_SetInteger( p_input, "rate", i_rate );
+                var_SetFloat( p_input, "rate", i_rate );
 
                 char psz_msg[7+1];
                 snprintf( psz_msg, sizeof(psz_msg), _("%.2fx"), (double)INPUT_RATE_DEFAULT / i_rate );
@@ -809,9 +812,9 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
             }
             else if( i_action == ACTIONID_PLAY )
             {
-                if( var_GetInteger( p_input, "rate" ) != INPUT_RATE_DEFAULT )
+                if( var_GetFloat( p_input, "rate" ) != 1. )
                     /* Return to normal speed */
-                    var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
+                    var_SetFloat( p_input, "rate", 1. );
                 else
                 {
                     ClearChannels( p_intf, p_vout );
index 995d2d1bf67030294337312f4f34ae5af7de87ec..03f13b829bc012bc693edd3f1e05cce786e51fce 100644 (file)
@@ -962,8 +962,8 @@ static void RateChanged( intf_thread_t *p_intf,
                          input_thread_t *p_input )
 {
     vlc_mutex_lock( &p_intf->p_sys->status_lock );
-    msg_rc( STATUS_CHANGE "( new rate: %d )",
-            var_GetInteger( p_input, "rate" ) );
+    msg_rc( STATUS_CHANGE "( new rate: %.3f )",
+            var_GetFloat( p_input, "rate" ) );
     vlc_mutex_unlock( &p_intf->p_sys->status_lock );
 }
 static void PositionChanged( intf_thread_t *p_intf,
@@ -1059,9 +1059,9 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
     {
         if( var_GetBool( p_input, "can-rate" ) )
         {
-            int i_rate = var_GetInteger( p_input, "rate" );
-            i_rate = (i_rate < 0) ? -i_rate : i_rate * 2;
-            var_SetInteger( p_input, "rate", i_rate );
+            float f_rate = var_GetFloat( p_input, "rate" );
+            f_rate = (f_rate < 0) ? -f_rate : f_rate * 2;
+            var_SetFloat( p_input, "rate", f_rate );
         }
         else
         {
@@ -1073,9 +1073,9 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
     {
         if( var_GetBool( p_input, "can-rewind" ) )
         {
-            int i_rate = var_GetInteger( p_input, "rate" );
-            i_rate = (i_rate > 0) ? -i_rate : i_rate / 2;
-            var_SetInteger( p_input, "rate", i_rate );
+            float f_rate = var_GetFloat( p_input, "rate" );
+            f_rate = (f_rate > 0) ? -f_rate : f_rate * 2;
+            var_SetFloat( p_input, "rate", f_rate );
         }
         else
         {
index 45d0bd970bf70e4a3b26808f2e7d1e204bfc9811..5d250b023618e9a011929c4b91c74f220b1d2dc7 100644 (file)
@@ -487,49 +487,49 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
         case HEIGHTH_PLAY:
             if( p_input )
             {
-                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 8 );
+                var_SetFloat( p_input, "rate", .125 );
             }
             break;
 
         case QUARTER_PLAY:
             if( p_input )
             {
-                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 4 );
+                var_SetFloat( p_input, "rate", .25 );
             }
             break;
 
         case HALF_PLAY:
             if( p_input )
             {
-                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 2 );
+                var_SetFloat( p_input, "rate", .5 );
             }
             break;
 
         case NORMAL_PLAY:
             if( p_input )
             {
-                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
+                var_SetFloat( p_input, "rate", 1. );
             }
             break;
 
         case TWICE_PLAY:
             if( p_input )
             {
-                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 2 );
+                var_SetFloat( p_input, "rate", 2. );
             }
             break;
 
         case FOUR_PLAY:
             if( p_input )
             {
-                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 4 );
+                var_SetFloat( p_input, "rate", 4. );
             }
             break;
 
         case HEIGHT_PLAY:
             if( p_input )
             {
-                var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 8 );
+                var_SetFloat( p_input, "rate", 8. );
             }
             break;
 
@@ -840,12 +840,12 @@ void InterfaceWindow::UpdateInterface()
         p_mediaControl->SetEnabled( true );
         bool hasTitles   = !var_Get( p_input, "title", &val );
         bool hasChapters = !var_Get( p_input, "chapter", &val );
-        p_mediaControl->SetStatus( var_GetInteger( p_input, "state" ),
-                                   var_GetInteger( p_input, "rate" ) );
+        p_mediaControl->SetStatus( INPUT_RATE_DEFAULT / var_GetFloat( p_input, "state" ),
+                                   INPUT_RATE_DEFAULT / var_GetFloat( p_input, "rate" ) );
         var_Get( p_input, "position", &val );
         p_mediaControl->SetProgress( val.f_float );
         _SetMenusEnabled( true, hasChapters, hasTitles );
-        _UpdateSpeedMenu( var_GetInteger( p_input, "rate" ) );
+        _UpdateSpeedMenu( INPUT_RATE_DEFAULT / var_GetFloat( p_input, "rate" ) );
 
         // enable/disable skip buttons
 #if 0
index 200d5fb747fb75885344e826506956c9df62827f..ee16a914d36f1c4ac2ded11c6636a8eeb20400ad 100644 (file)
@@ -407,7 +407,7 @@ void InputManager::UpdateStatus()
 void InputManager::UpdateRate()
 {
     /* Update Rate */
-    int i_new_rate = var_GetInteger( p_input, "rate");
+    int i_new_rate = INPUT_RATE_DEFAULT / var_GetFloat( p_input, "rate" );
     if( i_new_rate != i_rate )
     {
         i_rate = i_new_rate;
@@ -776,8 +776,8 @@ void InputManager::reverse()
 {
     if( hasInput() )
     {
-        int i_rate = var_GetInteger( p_input, "rate" );
-        var_SetInteger( p_input, "rate", -i_rate );
+        float f_rate = var_GetFloat( p_input, "rate" );
+        var_SetFloat( p_input, "rate", -f_rate );
     }
 }
 
@@ -806,13 +806,14 @@ void InputManager::littleslower()
 void InputManager::normalRate()
 {
     if( hasInput() )
-        var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
+        var_SetFloat( p_input, "rate", 1. );
 }
 
 void InputManager::setRate( int new_rate )
 {
     if( hasInput() )
-        var_SetInteger( p_input, "rate", new_rate );
+        var_SetFloat( p_input, "rate",
+                      (float)INPUT_RATE_DEFAULT / (float)new_rate );
 }
 
 void InputManager::jumpFwd()
index b7da9e9097b8604c61396a8f498af896e4532467..73c8b071f629074109344406b3b1ef5b06ee12a6 100644 (file)
@@ -195,7 +195,7 @@ void Timer::Notify( void )
 
             /* Manage Speed status */
             var_Get( p_input, "rate", &val );
-            if( i_old_rate != val.i_int )
+            if( i_old_rate != (int)((float)INPUT_RATE_DEFAULT / val.f_float) )
             {
                 TCHAR psz_text[15];
                 _stprintf( psz_text + 2, _T("x%.2f"), 1000.0 / val.i_int );
index 4f9725d4711beca176ffd8fbc8c5e535badbaacb..d4c815a1b7fa221f5b0578fd6e7becc9bf400a18 100644 (file)
@@ -407,7 +407,7 @@ end
 function rate(name,client)
     local input = vlc.object.input()
     if name == "normal" then
-        vlc.var.set(input,"rate",1000) -- FIXME: INPUT_RATE_DEFAULT
+        vlc.var.set(input,"rate",1)
     else
         vlc.var.set(input,"rate-"..name,nil)
     end
index c753feca6daff9dffc52c1ee6b8134ba9ba03ff3..0a07ce141a4276fc4984275a1d08836dd90b0c41 100644 (file)
@@ -1052,7 +1052,7 @@ void libvlc_media_player_set_rate(
         return;
     }
 
-    var_SetInteger( p_input_thread, "rate", 1000.0f/rate );
+    var_SetFloat( p_input_thread, "rate", rate );
     vlc_object_release( p_input_thread );
 }
 
@@ -1061,23 +1061,24 @@ float libvlc_media_player_get_rate(
                                  libvlc_exception_t *p_e )
 {
     input_thread_t *p_input_thread;
-    int i_rate;
+    float f_rate;
     bool b_can_rewind;
 
     p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
     if( !p_input_thread )
         return 0.0;  /* rate < 0 indicates rewind */
 
-    i_rate = var_GetInteger( p_input_thread, "rate" );
+    f_rate = var_GetFloat( p_input_thread, "rate" );
     b_can_rewind = var_GetBool( p_input_thread, "can-rewind" );
-    if( i_rate < 0 && !b_can_rewind )
+    /* FIXME: why are negative values forbidden ?? (rewinding) */
+    if( f_rate < 0 && !b_can_rewind )
     {
         vlc_object_release( p_input_thread );
         return 0.0;
     }
     vlc_object_release( p_input_thread );
 
-    return (float)1000.0f/i_rate;
+    return f_rate;
 }
 
 libvlc_state_t libvlc_media_player_get_state(
index 826f096f4a69cf85019b53e2a01a07efc8e954db..237465e762d32cb10b5e0f42a2ac3f91c7d27303 100644 (file)
@@ -99,12 +99,13 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
 
         case INPUT_GET_RATE:
             pi_int = (int*)va_arg( args, int * );
-            *pi_int = var_GetInteger( p_input, "rate" );
+            *pi_int = INPUT_RATE_DEFAULT / var_GetFloat( p_input, "rate" );
             return VLC_SUCCESS;
 
         case INPUT_SET_RATE:
             i_int = (int)va_arg( args, int );
-            return var_SetInteger( p_input, "rate", i_int );
+            return var_SetFloat( p_input, "rate",
+                                 (float)INPUT_RATE_DEFAULT / (float)i_int );
 
         case INPUT_GET_STATE:
             pi_int = (int*)va_arg( args, int * );
index 308842c400c230ee60b0c439f5753ca7b27cfe05..adb8cdcdb3155bb512b605d92dcba7de95e72d73 100644 (file)
@@ -95,10 +95,10 @@ void input_SendEventStatistics( input_thread_t *p_input )
 }
 void input_SendEventRate( input_thread_t *p_input, int i_rate )
 {
-       vlc_value_t val;
+    vlc_value_t val;
 
-       val.i_int = i_rate;
-       var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
+    val.f_float = (float)INPUT_RATE_DEFAULT / (float)i_rate;
+    var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
 
     Trigger( p_input, INPUT_EVENT_RATE );
 }
index 1f3ed16a1dea93644a45c40841d4af3af312f5b7..bc5e47b008d71bf5dc012c7e2813e3915b3fd70c 100644 (file)
@@ -136,8 +136,8 @@ void input_ControlVarInit ( input_thread_t *p_input )
     var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
 
     /* Rate */
-    var_Create( p_input, "rate", VLC_VAR_INTEGER );
-    val.i_int = p_input->p->i_rate;
+    var_Create( p_input, "rate", VLC_VAR_FLOAT );
+    val.f_float = (float)INPUT_RATE_DEFAULT / (float)p_input->p->i_rate;
     var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
 
     var_Create( p_input, "rate-slower", VLC_VAR_VOID );
@@ -574,6 +574,7 @@ static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
     }
     else
     {
+        int i_rate = INPUT_RATE_DEFAULT / newval.f_float;
         input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval );
     }
     return VLC_SUCCESS;
index 185c4b5bcfaac0891eae4daed7e120cedd430da2..4c7d35d75b3eb5e90f60f35643056177b947dac7 100644 (file)
@@ -1064,7 +1064,8 @@ static int vlm_ControlMediaInstanceGets( vlm_t *p_vlm, int64_t id, vlm_media_ins
             p_idsc->d_position = var_GetFloat( p_instance->p_input, "position" );
             if( var_GetInteger( p_instance->p_input, "state" ) == PAUSE_S )
                 p_idsc->b_paused = true;
-            p_idsc->i_rate = var_GetInteger( p_instance->p_input, "rate" );
+            p_idsc->i_rate = INPUT_RATE_DEFAULT
+                             / var_GetFloat( p_instance->p_input, "rate" );
         }
 
         TAB_APPEND( i_idsc, pp_idsc, p_idsc );
index c08dc2e6a5ee5976eb60b7d76e9f486e2478357e..22e5fc2499aff7d3ac2749c0b7a6227c20611d93 100644 (file)
@@ -1365,7 +1365,7 @@ static vlm_message_t *vlm_ShowMedia( vlm_media_sys_t *p_media )
             APPEND_INPUT_INFO( "position", "%f", Float );
             APPEND_INPUT_INFO( "time", "%"PRIi64, Time );
             APPEND_INPUT_INFO( "length", "%"PRIi64, Time );
-            APPEND_INPUT_INFO( "rate", "%d", Integer );
+            APPEND_INPUT_INFO( "rate", "%f", Float );
             APPEND_INPUT_INFO( "title", "%d", Integer );
             APPEND_INPUT_INFO( "chapter", "%d", Integer );
             APPEND_INPUT_INFO( "can-seek", "%d", Bool );
index 3f21500f7aa654c5a64712f7733b91e97fb5d996..11b16e205e78fe6ff7fd47cc62fb8097f900a49b 100644 (file)
@@ -858,8 +858,8 @@ char *__str_format_meta( vlc_object_t *p_object, const char *string )
                 case 'R':
                     if( p_input )
                     {
-                        int r = var_GetInteger( p_input, "rate" );
-                        snprintf( buf, 10, "%d.%d", r/1000, r%1000 );
+                        float f = var_GetFloat( p_input, "rate" );
+                        snprintf( buf, 10, "%.3f", f );
                     }
                     else
                     {