[vlc-devel] commit: LibVLC: allow setting playback rate even without input ( Rémi Denis-Courmont )

git version control git at videolan.org
Sun Feb 14 12:50:51 CET 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Feb 14 13:50:36 2010 +0200| [f561f73c3fa78d447000ded1f52adfe3685a1417] | committer: Rémi Denis-Courmont 

LibVLC: allow setting playback rate even without input

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f561f73c3fa78d447000ded1f52adfe3685a1417
---

 include/vlc/libvlc_media_player.h |    6 +++-
 src/control/media_player.c        |   41 ++++++++++---------------------------
 2 files changed, 15 insertions(+), 32 deletions(-)

diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index eaaa358..16a878b 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -409,10 +409,12 @@ VLC_PUBLIC_API void libvlc_media_player_previous_chapter( libvlc_media_player_t
 VLC_PUBLIC_API void libvlc_media_player_next_chapter( libvlc_media_player_t *p_mi );
 
 /**
- * Get movie play rate
+ * Get the requested movie play rate.
+ * @warning Depending on the underlying media, the requested rate may be
+ * different from the real playback rate.
  *
  * \param p_mi the Media Player
- * \return movie play rate, or zero in case of error
+ * \return movie play rate
  */
 VLC_PUBLIC_API float libvlc_media_player_get_rate( libvlc_media_player_t *p_mi );
 
diff --git a/src/control/media_player.c b/src/control/media_player.c
index 4901319..6521712 100644
--- a/src/control/media_player.c
+++ b/src/control/media_player.c
@@ -496,6 +496,9 @@ libvlc_media_player_new( libvlc_instance_t *instance )
     }
     vlc_object_attach (mp, mp->p_libvlc);
 
+    /* Input */
+    var_Create (mp, "rate", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT);
+
     /* Video */
     var_Create (mp, "drawable-xid", VLC_VAR_INTEGER);
 #ifdef WIN32
@@ -1221,21 +1224,17 @@ int libvlc_media_player_will_play( libvlc_media_player_t *p_mi )
 
 int libvlc_media_player_set_rate( libvlc_media_player_t *p_mi, float rate )
 {
-    input_thread_t *p_input_thread;
-    bool b_can_rewind;
-
-    p_input_thread = libvlc_get_input_thread ( p_mi );
-    if( !p_input_thread )
-        return -1;
-
-    b_can_rewind = var_GetBool( p_input_thread, "can-rewind" );
-    if( (rate < 0.0) && !b_can_rewind )
+    if (rate < 0.)
     {
-        vlc_object_release( p_input_thread );
-        libvlc_printerr( "Invalid playback rate" );
+        libvlc_printerr ("Playing backward not supported");
         return -1;
     }
 
+    var_SetFloat (p_mi, "rate", rate);
+
+    input_thread_t *p_input_thread = libvlc_get_input_thread ( p_mi );
+    if( !p_input_thread )
+        return 0;
     var_SetFloat( p_input_thread, "rate", rate );
     vlc_object_release( p_input_thread );
     return 0;
@@ -1243,25 +1242,7 @@ int libvlc_media_player_set_rate( libvlc_media_player_t *p_mi, float rate )
 
 float libvlc_media_player_get_rate( libvlc_media_player_t *p_mi )
 {
-    input_thread_t *p_input_thread;
-    float f_rate;
-    bool b_can_rewind;
-
-    p_input_thread = libvlc_get_input_thread ( p_mi );
-    if( !p_input_thread )
-        return 0.0;  /* rate < 0 indicates rewind */
-
-    f_rate = var_GetFloat( p_input_thread, "rate" );
-    b_can_rewind = var_GetBool( p_input_thread, "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 f_rate;
+    return var_GetFloat (p_mi, "rate");
 }
 
 libvlc_state_t libvlc_media_player_get_state( libvlc_media_player_t *p_mi )




More information about the vlc-devel mailing list