Commit f561f73c authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

LibVLC: allow setting playback rate even without input

parent 951dd377
...@@ -409,10 +409,12 @@ VLC_PUBLIC_API void libvlc_media_player_previous_chapter( libvlc_media_player_t ...@@ -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 ); 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 * \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 ); VLC_PUBLIC_API float libvlc_media_player_get_rate( libvlc_media_player_t *p_mi );
......
...@@ -496,6 +496,9 @@ libvlc_media_player_new( libvlc_instance_t *instance ) ...@@ -496,6 +496,9 @@ libvlc_media_player_new( libvlc_instance_t *instance )
} }
vlc_object_attach (mp, mp->p_libvlc); vlc_object_attach (mp, mp->p_libvlc);
/* Input */
var_Create (mp, "rate", VLC_VAR_FLOAT|VLC_VAR_DOINHERIT);
/* Video */ /* Video */
var_Create (mp, "drawable-xid", VLC_VAR_INTEGER); var_Create (mp, "drawable-xid", VLC_VAR_INTEGER);
#ifdef WIN32 #ifdef WIN32
...@@ -1221,21 +1224,17 @@ int libvlc_media_player_will_play( libvlc_media_player_t *p_mi ) ...@@ -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 ) int libvlc_media_player_set_rate( libvlc_media_player_t *p_mi, float rate )
{ {
input_thread_t *p_input_thread; if (rate < 0.)
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 )
{ {
vlc_object_release( p_input_thread ); libvlc_printerr ("Playing backward not supported");
libvlc_printerr( "Invalid playback rate" );
return -1; 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 ); var_SetFloat( p_input_thread, "rate", rate );
vlc_object_release( p_input_thread ); vlc_object_release( p_input_thread );
return 0; return 0;
...@@ -1243,25 +1242,7 @@ int libvlc_media_player_set_rate( libvlc_media_player_t *p_mi, float rate ) ...@@ -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 ) float libvlc_media_player_get_rate( libvlc_media_player_t *p_mi )
{ {
input_thread_t *p_input_thread; return var_GetFloat (p_mi, "rate");
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;
} }
libvlc_state_t libvlc_media_player_get_state( libvlc_media_player_t *p_mi ) libvlc_state_t libvlc_media_player_get_state( libvlc_media_player_t *p_mi )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment