]> git.sesse.net Git - vlc/blobdiff - src/playlist/engine.c
LGPL
[vlc] / src / playlist / engine.c
index 6d968b8a769f17c5d0309b79d98e3205b700969c..01d887ab25de603c84365d82a4993b455236fa67 100644 (file)
@@ -1,24 +1,24 @@
 /*****************************************************************************
  * engine.c : Run the playlist and handle its control
  *****************************************************************************
- * Copyright (C) 1999-2008 the VideoLAN team
+ * Copyright (C) 1999-2008 VLC authors and VideoLAN
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
  *          ClĂ©ment Stenac <zorglub@videolan.org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -74,10 +74,10 @@ static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
     return VLC_SUCCESS;
 }
 
-static int RateOffsetCallback( vlc_object_t *p_this, char const *psz_cmd,
+static int RateOffsetCallback( vlc_object_t *obj, char const *psz_cmd,
                                vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
-    playlist_t *p_playlist = (playlist_t*)p_this;
+    playlist_t *p_playlist = (playlist_t *)obj;
     VLC_UNUSED(oldval); VLC_UNUSED(p_data); VLC_UNUSED(newval);
 
     static const float pf_rate[] = {
@@ -85,48 +85,40 @@ static int RateOffsetCallback( vlc_object_t *p_this, char const *psz_cmd,
         1.0/1,
         3.0/2, 2.0/1, 3.0/1, 4.0/1, 8.0/1, 16.0/1, 32.0/1, 64.0/1,
     };
-    const unsigned i_rate_count = sizeof(pf_rate)/sizeof(*pf_rate);
+    const size_t i_rate_count = sizeof(pf_rate)/sizeof(*pf_rate);
+
+    float f_rate;
+    struct input_thread_t *input;
 
     PL_LOCK;
-    float f_rate = 1.;
-    if( pl_priv( p_playlist )->p_input )
-    {
-       f_rate = var_GetFloat( pl_priv(p_playlist)->p_input, "rate" );
-    }
-    else
-    {
-       f_rate = var_GetFloat( p_playlist, "rate" );
-    }
+    input = pl_priv( p_playlist )->p_input;
+    f_rate = var_GetFloat( input ? (vlc_object_t *)input : obj, "rate" );
     PL_UNLOCK;
 
-    /* Determine the factor closest to the current rate */
-    float f_error;
-    int i_idx;
-    for( unsigned i = 0; i < i_rate_count; i++ )
+    if( !strcmp( psz_cmd, "rate-faster" ) )
     {
-        const float f_test_e = fabs( fabs( f_rate ) - pf_rate[i] );
-        if( i == 0 || f_test_e < f_error )
-        {
-            i_idx = i;
-            f_error = f_test_e;
-        }
+        /* compensate for input rounding errors */
+        float r = f_rate * 1.1;
+        for( size_t i = 0; i < i_rate_count; i++ )
+            if( r < pf_rate[i] )
+            {
+                f_rate = pf_rate[i];
+                break;
+            }
     }
-    assert( i_idx < (int)i_rate_count );
-
-    /* */
-    i_idx += strcmp( psz_cmd, "rate-faster" ) == 0 ? 1 : -1;
-    if( i_idx >= 0 && i_idx < (int)i_rate_count )
+    else
     {
-        const float f_rate_min = (float)INPUT_RATE_DEFAULT / INPUT_RATE_MAX;
-        const float f_rate_max = (float)INPUT_RATE_DEFAULT / INPUT_RATE_MIN;
-        const float f_sign = f_rate >= 0 ? +1. : -1.;
-
-        var_SetFloat( p_playlist, "rate",
-                      f_sign * __MAX( __MIN( pf_rate[i_idx],
-                                             f_rate_max ),
-                                      f_rate_min ) );
-
+        /* compensate for input rounding errors */
+        float r = f_rate * .9;
+        for( size_t i = 1; i < i_rate_count; i++ )
+            if( r <= pf_rate[i] )
+            {
+                f_rate = pf_rate[i - 1];
+                break;
+            }
     }
+
+    var_SetFloat( p_playlist, "rate", f_rate );
     return VLC_SUCCESS;
 }
 
@@ -160,19 +152,16 @@ static int VideoSplitterCallback( vlc_object_t *p_this, char const *psz_cmd,
  */
 playlist_t * playlist_Create( vlc_object_t *p_parent )
 {
-    static const char playlist_name[] = "playlist";
     playlist_t *p_playlist;
     playlist_private_t *p;
 
     /* Allocate structure */
-    p = vlc_custom_create( p_parent, sizeof( *p ),
-                           VLC_OBJECT_GENERIC, playlist_name );
+    p = vlc_custom_create( p_parent, sizeof( *p ), "playlist" );
     if( !p )
         return NULL;
 
     assert( offsetof( playlist_private_t, public_data ) == 0 );
     p_playlist = &p->public_data;
-    vlc_object_attach( p_playlist, p_parent );
     TAB_INIT( pl_priv(p_playlist)->i_sds, pl_priv(p_playlist)->pp_sds );
 
     libvlc_priv(p_parent->p_libvlc)->p_playlist = p_playlist;
@@ -392,7 +381,7 @@ static void VariablesInit( playlist_t *p_playlist )
     var_SetBool( p_playlist, "intf-change", true );
 
     var_Create( p_playlist, "item-change", VLC_VAR_ADDRESS );
-    var_Create( p_playlist, "leaf-to-parent", VLC_VAR_ADDRESS );
+    var_Create( p_playlist, "leaf-to-parent", VLC_VAR_INTEGER );
 
     var_Create( p_playlist, "playlist-item-deleted", VLC_VAR_INTEGER );
     var_SetInteger( p_playlist, "playlist-item-deleted", -1 );
@@ -406,6 +395,7 @@ static void VariablesInit( playlist_t *p_playlist )
     var_SetInteger( p_playlist, "activity", 0 );
 
     /* Variables to control playback */
+    var_Create( p_playlist, "playlist-autostart", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     var_Create( p_playlist, "play-and-stop", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     var_Create( p_playlist, "play-and-exit", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     var_Create( p_playlist, "random", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
@@ -432,9 +422,8 @@ static void VariablesInit( playlist_t *p_playlist )
     var_Create( p_playlist, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
 
     /* Audio output parameters */
-    var_Create( p_playlist, "volume-muted", VLC_VAR_BOOL );
-    var_Create( p_playlist, "saved-volume", VLC_VAR_INTEGER );
-    var_Create( p_playlist, "volume-change", VLC_VAR_VOID );
+    var_Create( p_playlist, "mute", VLC_VAR_BOOL );
+    var_Create( p_playlist, "volume", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
     /* FIXME: horrible hack for audio output interface code */
     var_Create( p_playlist, "find-input-callback", VLC_VAR_ADDRESS );
     var_SetAddress( p_playlist, "find-input-callback", playlist_FindInput );