#endif
#include <vlc_common.h>
+#include <assert.h>
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
vlc_value_t oldval, vlc_value_t newval, void * );
static int RateCallback ( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void * );
+static int RateOffsetCallback( vlc_object_t *p_this, char const *psz_cmd,
+ vlc_value_t oldval, vlc_value_t newval, void * );
static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void * );
static int TimeCallback ( vlc_object_t *p_this, char const *psz_cmd,
{
CALLBACK( "state", StateCallback ),
CALLBACK( "rate", RateCallback ),
- CALLBACK( "rate-slower", RateCallback ),
- CALLBACK( "rate-faster", RateCallback ),
+ CALLBACK( "rate-slower", RateOffsetCallback ),
+ CALLBACK( "rate-faster", RateOffsetCallback ),
CALLBACK( "position", PositionCallback ),
CALLBACK( "position-offset", PositionCallback ),
CALLBACK( "time", TimeCallback ),
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 );
var_Change( p_input, "program", VLC_VAR_SETTEXT, &text, NULL );
/* Programs */
- var_Create( p_input, "programs", VLC_VAR_LIST | VLC_VAR_DOINHERIT );
+ var_Create( p_input, "programs", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
text.psz_string = _("Programs");
var_Change( p_input, "programs", VLC_VAR_SETTEXT, &text, NULL );
val.i_time = 0;
var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
+ var_Create( p_input, "bit-rate", VLC_VAR_INTEGER );
+ var_Create( p_input, "sample-rate", VLC_VAR_INTEGER );
+
if( !p_input->b_preparsing )
{
/* Special "intf-event" variable. */
*****************************************************************************/
void input_ControlVarStop( input_thread_t *p_input )
{
- InputDelCallbacks( p_input, p_input_callbacks );
+ if( !p_input->b_preparsing )
+ InputDelCallbacks( p_input, p_input_callbacks );
if( p_input->p->i_title > 0 )
{
var_AddCallback( p_input, val.psz_string,
NavigationCallback, (void *)(intptr_t)i );
+ char psz_length[MSTRTIME_MAX_SIZE + sizeof(" []")] = "";
+ if( p_input->p->title[i]->i_length > 0 )
+ {
+ strcpy( psz_length, " [" );
+ secstotimestr( &psz_length[2], p_input->p->title[i]->i_length / CLOCK_FREQ );
+ strcat( psz_length, "]" );
+ }
+
if( p_input->p->title[i]->psz_name == NULL ||
*p_input->p->title[i]->psz_name == '\0' )
{
- if( asprintf( &text.psz_string, _("Title %i"),
- i + p_input->p->i_title_offset ) == -1 )
+ if( asprintf( &text.psz_string, _("Title %i%s"),
+ i + p_input->p->i_title_offset, psz_length ) == -1 )
continue;
}
else
{
- text.psz_string = strdup( p_input->p->title[i]->psz_name );
+ if( asprintf( &text.psz_string, "%s%s",
+ p_input->p->title[i]->psz_name, psz_length ) == -1 )
+ continue;
}
var_Change( p_input, "navigation", VLC_VAR_ADDCHOICE, &val, &text );
void input_ControlVarTitle( input_thread_t *p_input, int i_title )
{
input_title_t *t = p_input->p->title[i_title];
- vlc_value_t val, text;
+ vlc_value_t text;
int i;
/* Create/Destroy command variables */
var_Destroy( p_input, "next-chapter" );
var_Destroy( p_input, "prev-chapter" );
}
- else if( var_Get( p_input, "next-chapter", &val ) != VLC_SUCCESS )
+ else if( var_Type( p_input, "next-chapter" ) == 0 )
{
var_Create( p_input, "next-chapter", VLC_VAR_VOID );
text.psz_string = _("Next chapter");
var_Change( p_input, "chapter", VLC_VAR_CLEARCHOICES, NULL, NULL );
for( i = 0; i < t->i_seekpoint; i++ )
{
+ vlc_value_t val;
val.i_int = i;
if( t->seekpoint[i]->psz_name == NULL ||
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
input_thread_t *p_input = (input_thread_t*)p_this;
- VLC_UNUSED(oldval); VLC_UNUSED(p_data);
+ VLC_UNUSED(oldval); VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
- /* Problem with this way: the "rate" variable is update after the input thread do the change */
- if( !strcmp( psz_cmd, "rate-slower" ) )
- {
- input_ControlPush( p_input, INPUT_CONTROL_SET_RATE_SLOWER, NULL );
- }
- else if( !strcmp( psz_cmd, "rate-faster" ) )
+ newval.i_int = INPUT_RATE_DEFAULT / newval.f_float;
+ input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval );
+
+ return VLC_SUCCESS;
+}
+
+static int RateOffsetCallback( 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;
+ VLC_UNUSED(oldval); VLC_UNUSED(p_data); VLC_UNUSED(newval);
+
+ static const float pf_rate[] = {
+ 1.0/64, 1.0/32, 1.0/16, 1.0/8, 1.0/4, 1.0/3, 1.0/2, 2.0/3,
+ 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 float f_rate = var_GetFloat( p_input, "rate" );
+
+ /* Determine the factor closest to the current rate */
+ float f_error;
+ int i_idx;
+ for( unsigned i = 0; i < i_rate_count; i++ )
{
- input_ControlPush( p_input, INPUT_CONTROL_SET_RATE_FASTER, NULL );
+ 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;
+ }
}
- else
+ 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 )
{
- input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval );
+ 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_input, "rate",
+ f_sign * __MAX( __MIN( pf_rate[i_idx],
+ f_rate_max ),
+ f_rate_min ) );
}
return VLC_SUCCESS;
}
void *p_data )
{
input_thread_t *p_input = (input_thread_t*)p_this;
- vlc_value_t val, length;
VLC_UNUSED(oldval); VLC_UNUSED(p_data);
if( !strcmp( psz_cmd, "position-offset" ) )
{
- val.f_float = var_GetFloat( p_input, "position" ) + newval.f_float;
- if( val.f_float < 0.0 ) val.f_float = 0.0;
- if( val.f_float > 1.0 ) val.f_float = 1.0;
-
- input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION_OFFSET, &newval );
+ float f_position = var_GetFloat( p_input, "position" ) + newval.f_float;
+ if( f_position < 0.0 )
+ f_position = 0.0;
+ else if( f_position > 1.0 )
+ f_position = 1.0;
+ var_SetFloat( p_this, "position", f_position );
}
else
{
- val.f_float = newval.f_float;
- input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval );
- }
+ /* Update "length" for better intf behavour */
+ const mtime_t i_length = var_GetTime( p_input, "length" );
+ if( i_length > 0 && newval.f_float >= 0.0 && newval.f_float <= 1.0 )
+ {
+ vlc_value_t val;
- /* Update "position" for better intf behavour */
- var_Get( p_input, "length", &length );
- if( length.i_time > 0 && val.f_float >= 0.0 && val.f_float <= 1.0 )
- {
- val.i_time = length.i_time * val.f_float;
- var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
- }
+ val.i_time = i_length * newval.f_float;
+ var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
+ }
+ /* */
+ input_ControlPush( p_input, INPUT_CONTROL_SET_POSITION, &newval );
+ }
return VLC_SUCCESS;
}
vlc_value_t oldval, vlc_value_t newval, void *p_data )
{
input_thread_t *p_input = (input_thread_t*)p_this;
- vlc_value_t val, length;
VLC_UNUSED(oldval); VLC_UNUSED(p_data);
if( !strcmp( psz_cmd, "time-offset" ) )
{
- val.i_time = var_GetTime( p_input, "time" ) + newval.i_time;
- if( val.i_time < 0 ) val.i_time = 0;
- input_ControlPush( p_input, INPUT_CONTROL_SET_TIME_OFFSET, &newval );
+ mtime_t i_time = var_GetTime( p_input, "time" ) + newval.i_time;
+ if( i_time < 0 )
+ i_time = 0;
+ var_SetTime( p_this, "time", i_time );
}
else
{
- val.i_time = newval.i_time;
- input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
- }
+ /* Update "position" for better intf behavour */
+ const mtime_t i_length = var_GetTime( p_input, "length" );
+ if( i_length > 0 && newval.i_time >= 0 && newval.i_time <= i_length )
+ {
+ vlc_value_t val;
- /* Update "position" for better intf behavour */
- var_Get( p_input, "length", &length );
- if( length.i_time > 0 && val.i_time >= 0 && val.i_time <= length.i_time )
- {
- val.f_float = (double)val.i_time/(double)length.i_time;
- var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
- }
+ val.f_float = (double)newval.i_time/(double)i_length;
+ var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
+ }
+ /* */
+ input_ControlPush( p_input, INPUT_CONTROL_SET_TIME, &newval );
+ }
return VLC_SUCCESS;
}
else
{
input_ControlPush( p_input, INPUT_CONTROL_SET_SEEKPOINT, &newval );
- val.i_int = newval.i_int;
- }
-
- /* Actualize "title %2i" variable */
- if( val.i_int >= 0 && val.i_int < count.i_int )
- {
- int i_title = var_GetInteger( p_input, "title" );
- char psz_titlevar[10] = {0};
- snprintf( psz_titlevar, 10, "title %2i", i_title );
- var_Change( p_input, psz_titlevar, VLC_VAR_SETVALUE, &val, NULL );
}
return VLC_SUCCESS;