Commit ea33ac4c authored by Laurent Aimar's avatar Laurent Aimar

* input: fixed position-offset, time and time-offset.

 * hotkeys: never _never_ use  demux_Control outside of src/input/ (it's
 completely broken,  there is a lot  more things to do),  all interfaces
 have  to  use  var_Get/Set  (time(-offset),  position(-offset),  state,
 rate(-slower|-faster)...  ).
 Btw,   input_SetStatus,   input_Seek,   input_Tell,   input_ChangeArea,
 input_ToggleES,  will   be  quickly   obsolete  and   removed(at  least
 unavailable for intf), so we should convert remaining interfaces (ie all
 except wx, osx, rc, http, hotkeys).

 * avi: implemented DEMUX_SET_TIME (not yet used).
parent 2069ebe6
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* decoder.c: AAC decoder using libfaad2 * decoder.c: AAC decoder using libfaad2
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2003 VideoLAN * Copyright (C) 2001, 2003 VideoLAN
* $Id: faad.c,v 1.1 2003/11/03 22:30:15 fenrir Exp $ * $Id: faad.c,v 1.2 2003/11/04 02:23:11 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -323,15 +323,3 @@ static int EndDecoder ( decoder_t *p_dec ) ...@@ -323,15 +323,3 @@ static int EndDecoder ( decoder_t *p_dec )
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* hotkeys.c: Hotkey handling for vlc * hotkeys.c: Hotkey handling for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2003 VideoLAN * Copyright (C) 2003 VideoLAN
* $Id: hotkeys.c,v 1.7 2003/10/31 18:18:46 gbazin Exp $ * $Id: hotkeys.c,v 1.8 2003/11/04 02:23:11 fenrir Exp $
* *
* Authors: Sigmund Augdal <sigmunau@idi.ntnu.no> * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
* *
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
* Preamble * Preamble
*****************************************************************************/ *****************************************************************************/
#include <stdlib.h> /* malloc(), free() */ #include <stdlib.h> /* malloc(), free() */
#include <string.h>
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/intf.h> #include <vlc/intf.h>
...@@ -240,11 +239,16 @@ static void Run( intf_thread_t *p_intf ) ...@@ -240,11 +239,16 @@ static void Run( intf_thread_t *p_intf )
} }
else if( i_action == ACTIONID_PLAY_PAUSE ) else if( i_action == ACTIONID_PLAY_PAUSE )
{ {
if( p_input && val.i_int = PLAYING_S;
p_input->stream.control.i_status != PAUSE_S ) if( p_input )
{
var_Get( p_input, "state", &val );
}
if( p_input && val.i_int != PAUSE_S )
{ {
vout_OSDMessage( VLC_OBJECT(p_intf), _( "Pause" ) ); vout_OSDMessage( VLC_OBJECT(p_intf), _( "Pause" ) );
input_SetStatus( p_input, INPUT_STATUS_PAUSE ); val.i_int = PAUSE_S;
var_Set( p_input, "state", val );
} }
else else
{ {
...@@ -265,48 +269,47 @@ static void Run( intf_thread_t *p_intf ) ...@@ -265,48 +269,47 @@ static void Run( intf_thread_t *p_intf )
} }
else if( p_input ) else if( p_input )
{ {
uint64_t i_time;
if( i_action == ACTIONID_PAUSE ) if( i_action == ACTIONID_PAUSE )
{ {
vout_OSDMessage( VLC_OBJECT(p_intf), _( "Pause" ) ); vout_OSDMessage( VLC_OBJECT(p_intf), _( "Pause" ) );
input_SetStatus( p_input, INPUT_STATUS_PAUSE ); val.i_int = PAUSE_S;
var_Set( p_input, "state", val );
} }
else if( i_action == ACTIONID_JUMP_BACKWARD_10SEC ) else if( i_action == ACTIONID_JUMP_BACKWARD_10SEC )
{ {
vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump -10 seconds" ) ); vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump -10 seconds" ) );
demux_Control( p_input, DEMUX_GET_TIME, &i_time ); val.i_time = -10000000LL;
demux_Control( p_input, DEMUX_SET_TIME, i_time - 10000000 ); var_Set( p_input, "time-offset", val );
} }
else if( i_action == ACTIONID_JUMP_FORWARD_10SEC ) else if( i_action == ACTIONID_JUMP_FORWARD_10SEC )
{ {
vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump +10 seconds" ) ); vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump +10 seconds" ) );
demux_Control( p_input, DEMUX_GET_TIME, &i_time ); val.i_time = 10000000LL;
demux_Control( p_input, DEMUX_SET_TIME, i_time + 10000000 ); var_Set( p_input, "time-offset", val );
} }
else if( i_action == ACTIONID_JUMP_BACKWARD_1MIN ) else if( i_action == ACTIONID_JUMP_BACKWARD_1MIN )
{ {
vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump -1 minute" ) ); vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump -1 minute" ) );
demux_Control( p_input, DEMUX_GET_TIME, &i_time ); val.i_time = -60000000LL;
demux_Control( p_input, DEMUX_SET_TIME, i_time - 60000000 ); var_Set( p_input, "time-offset", val );
} }
else if( i_action == ACTIONID_JUMP_FORWARD_1MIN ) else if( i_action == ACTIONID_JUMP_FORWARD_1MIN )
{ {
vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump +1 minute" ) ); vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump +1 minute" ) );
demux_Control( p_input, DEMUX_GET_TIME, &i_time ); val.i_time = 60000000LL;
demux_Control( p_input, DEMUX_SET_TIME, i_time + 60000000 ); var_Set( p_input, "time-offset", val );
} }
else if( i_action == ACTIONID_JUMP_BACKWARD_5MIN ) else if( i_action == ACTIONID_JUMP_BACKWARD_5MIN )
{ {
vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump -5 minutes" ) ); vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump -5 minutes" ) );
demux_Control( p_input, DEMUX_GET_TIME, &i_time ); val.i_time = -300000000LL;
demux_Control( p_input, DEMUX_SET_TIME, i_time - 300000000 ); var_Set( p_input, "time-offset", val );
} }
else if( i_action == ACTIONID_JUMP_FORWARD_5MIN ) else if( i_action == ACTIONID_JUMP_FORWARD_5MIN )
{ {
vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump +5 minutes" ) ); vout_OSDMessage( VLC_OBJECT(p_intf), _( "Jump +5 minutes" ) );
demux_Control( p_input, DEMUX_GET_TIME, &i_time ); val.i_time = 300000000LL;
demux_Control( p_input, DEMUX_SET_TIME, i_time + 300000000 ); var_Set( p_input, "time-offset", val );
} }
else if( i_action == ACTIONID_NEXT ) else if( i_action == ACTIONID_NEXT )
{ {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* avi.c : AVI file Stream input module for vlc * avi.c : AVI file Stream input module for vlc
***************************************************************************** *****************************************************************************
* Copyright (C) 2001 VideoLAN * Copyright (C) 2001 VideoLAN
* $Id: avi.c,v 1.63 2003/10/19 13:39:11 hartman Exp $ * $Id: avi.c,v 1.64 2003/11/04 02:23:11 fenrir Exp $
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
...@@ -1087,7 +1087,7 @@ static int Seek( input_thread_t *p_input, mtime_t i_date, int i_percent ) ...@@ -1087,7 +1087,7 @@ static int Seek( input_thread_t *p_input, mtime_t i_date, int i_percent )
if( p_avi->b_seekable ) if( p_avi->b_seekable )
{ {
if( !p_avi->i_length || p_avi->b_interleaved ) if( !p_avi->i_length ) //|| p_avi->b_interleaved )
{ {
avi_stream_t *p_stream; avi_stream_t *p_stream;
int64_t i_pos; int64_t i_pos;
...@@ -1201,32 +1201,24 @@ static int Seek( input_thread_t *p_input, mtime_t i_date, int i_percent ) ...@@ -1201,32 +1201,24 @@ static int Seek( input_thread_t *p_input, mtime_t i_date, int i_percent )
***************************************************************************** *****************************************************************************
* *
*****************************************************************************/ *****************************************************************************/
static int Control( input_thread_t *p_input, int i_query, va_list args ) static double ControlGetPosition( input_thread_t *p_input )
{ {
demux_sys_t *p_sys = p_input->p_demux_data; demux_sys_t *p_sys = p_input->p_demux_data;
int i;
double f, *pf;
int64_t i64, *pi64;
switch( i_query )
{
case DEMUX_GET_POSITION:
pf = (double*)va_arg( args, double * );
if( p_sys->i_length > 0 ) if( p_sys->i_length > 0 )
{ {
*pf = (double)p_sys->i_time / (double)( p_sys->i_length * (mtime_t)1000000 ); return (double)p_sys->i_time / (double)( p_sys->i_length * (mtime_t)1000000 );
return VLC_SUCCESS;
} }
else if( stream_Size( p_input->s ) > 0 ) else if( stream_Size( p_input->s ) > 0 )
{ {
unsigned int i; unsigned int i;
int64_t i_tmp; int64_t i_tmp;
int64_t i64 = 0;
i64 = 0;
/* search the more advanced selected es */ /* search the more advanced selected es */
for( i = 0; i < p_sys->i_streams; i++ ) for( i = 0; i < p_sys->i_streams; i++ )
{ {
#define tk p_sys->pp_info[i] avi_stream_t *tk = p_sys->pp_info[i];
if( tk->b_activated && tk->i_idxposc < tk->i_idxnb ) if( tk->b_activated && tk->i_idxposc < tk->i_idxnb )
{ {
i_tmp = tk->p_index[tk->i_idxposc].i_pos + i_tmp = tk->p_index[tk->i_idxposc].i_pos +
...@@ -1236,40 +1228,55 @@ static int Control( input_thread_t *p_input, int i_query, va_list args ) ...@@ -1236,40 +1228,55 @@ static int Control( input_thread_t *p_input, int i_query, va_list args )
i64 = i_tmp; i64 = i_tmp;
} }
} }
#undef tk
} }
*pf = (double)i64 / (double)stream_Size( p_input->s ); return (double)i64 / (double)stream_Size( p_input->s );
return VLC_SUCCESS;
} }
else return 0.0;
}
static int Control( input_thread_t *p_input, int i_query, va_list args )
{
demux_sys_t *p_sys = p_input->p_demux_data;
int i;
double f, *pf;
int64_t i64, *pi64;
switch( i_query )
{ {
*pf = 0.0; case DEMUX_GET_POSITION:
pf = (double*)va_arg( args, double * );
*pf = ControlGetPosition( p_input );
return VLC_SUCCESS; return VLC_SUCCESS;
}
case DEMUX_SET_POSITION: case DEMUX_SET_POSITION:
if( p_sys->b_seekable ) if( p_sys->b_seekable )
{ {
int i_ret;
f = (double)va_arg( args, double ); f = (double)va_arg( args, double );
i64 = (mtime_t)(1000000.0 * p_sys->i_length * f ); i64 = (mtime_t)(1000000.0 * p_sys->i_length * f );
i_ret = Seek( p_input, i64, (int)(f * 100) ); return Seek( p_input, i64, (int)(f * 100) );
return i_ret;
} }
else
{
return demux_vaControlDefault( p_input, i_query, args ); return demux_vaControlDefault( p_input, i_query, args );
}
case DEMUX_GET_TIME: case DEMUX_GET_TIME:
pi64 = (int64_t*)va_arg( args, int64_t * ); pi64 = (int64_t*)va_arg( args, int64_t * );
*pi64 = p_sys->i_time; *pi64 = p_sys->i_time;
return VLC_SUCCESS; return VLC_SUCCESS;
case DEMUX_SET_TIME: case DEMUX_SET_TIME:
msg_Err( p_input, "FIXME DEMUX_SET_TIME to be implemented" ); {
return VLC_EGENERIC; int i_percent = 0;
/* return demux_vaControlDefault( p_input, i_query, args ); */
i64 = (int64_t)va_arg( args, int64_t );
if( p_sys->i_length > 0 )
{
i_percent = 100 * i64 / (p_sys->i_length*1000000ULL);
}
else if( p_sys->i_time > 0 )
{
i_percent = (int)( 100.0 * ControlGetPosition( p_input ) *
(double)i64 / (double)p_sys->i_time );
}
return Seek( p_input, i64, i_percent );
}
case DEMUX_GET_LENGTH: case DEMUX_GET_LENGTH:
pi64 = (int64_t*)va_arg( args, int64_t * ); pi64 = (int64_t*)va_arg( args, int64_t * );
*pi64 = p_sys->i_length * (mtime_t)1000000; *pi64 = p_sys->i_length * (mtime_t)1000000;
...@@ -1280,13 +1287,12 @@ static int Control( input_thread_t *p_input, int i_query, va_list args ) ...@@ -1280,13 +1287,12 @@ static int Control( input_thread_t *p_input, int i_query, va_list args )
*pf = 0.0; *pf = 0.0;
for( i = 0; i < (int)p_sys->i_streams; i++ ) for( i = 0; i < (int)p_sys->i_streams; i++ )
{ {
#define tk p_sys->pp_info[i] avi_stream_t *tk = p_sys->pp_info[i];
if( tk->i_cat == VIDEO_ES && tk->i_scale > 0) if( tk->i_cat == VIDEO_ES && tk->i_scale > 0)
{ {
*pf = (float)tk->i_rate / (float)tk->i_scale; *pf = (float)tk->i_rate / (float)tk->i_scale;
break; break;
} }
#undef tk
} }
return VLC_SUCCESS; return VLC_SUCCESS;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* decoders. * decoders.
***************************************************************************** *****************************************************************************
* Copyright (C) 1998-2002 VideoLAN * Copyright (C) 1998-2002 VideoLAN
* $Id: input.c,v 1.250 2003/10/29 01:33:26 gbazin Exp $ * $Id: input.c,v 1.251 2003/11/04 02:23:11 fenrir Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -127,6 +127,7 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent, ...@@ -127,6 +127,7 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
val.f_float = 0.0; val.f_float = 0.0;
var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL ); var_Change( p_input, "position", VLC_VAR_SETVALUE, &val, NULL );
var_AddCallback( p_input, "position", PositionCallback, NULL ); var_AddCallback( p_input, "position", PositionCallback, NULL );
var_AddCallback( p_input, "position-offset", PositionCallback, NULL );
/* time variable */ /* time variable */
var_Create( p_input, "time", VLC_VAR_TIME ); var_Create( p_input, "time", VLC_VAR_TIME );
...@@ -134,6 +135,7 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent, ...@@ -134,6 +135,7 @@ input_thread_t *__input_CreateThread( vlc_object_t *p_parent,
val.i_time = 0; val.i_time = 0;
var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL ); var_Change( p_input, "time", VLC_VAR_SETVALUE, &val, NULL );
var_AddCallback( p_input, "time", TimeCallback, NULL ); var_AddCallback( p_input, "time", TimeCallback, NULL );
var_AddCallback( p_input, "time-offset", TimeCallback, NULL );
/* length variable */ /* length variable */
var_Create( p_input, "length", VLC_VAR_TIME ); var_Create( p_input, "length", VLC_VAR_TIME );
...@@ -1219,22 +1221,23 @@ static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd, ...@@ -1219,22 +1221,23 @@ static int PositionCallback( vlc_object_t *p_this, char const *psz_cmd,
void *p_data ) void *p_data )
{ {
input_thread_t *p_input = (input_thread_t *)p_this; input_thread_t *p_input = (input_thread_t *)p_this;
int64_t i_offset;
msg_Dbg( p_input, "cmd=%s old=%f new=%f", psz_cmd, msg_Dbg( p_input, "cmd=%s old=%f new=%f", psz_cmd,
oldval.f_float, newval.f_float ); oldval.f_float, newval.f_float );
vlc_mutex_lock( &p_input->stream.stream_lock );
i_offset = (int64_t)( newval.f_float *
(double)p_input->stream.p_selected_area->i_size );
if( !strcmp( psz_cmd, "position-offset" ) ) if( !strcmp( psz_cmd, "position-offset" ) )
{ {
p_input->stream.p_selected_area->i_seek += i_offset; vlc_value_t val;
} var_Get( p_input, "position", &val );
else
{ newval.f_float += val.f_float;
p_input->stream.p_selected_area->i_seek = i_offset;
} }
vlc_mutex_lock( &p_input->stream.stream_lock );
p_input->stream.p_selected_area->i_seek =
(int64_t)( newval.f_float *
(double)p_input->stream.p_selected_area->i_size );
if( p_input->stream.p_selected_area->i_seek < 0 ) if( p_input->stream.p_selected_area->i_seek < 0 )
{ {
p_input->stream.p_selected_area->i_seek = 0; p_input->stream.p_selected_area->i_seek = 0;
...@@ -1248,29 +1251,29 @@ static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd, ...@@ -1248,29 +1251,29 @@ static int TimeCallback( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data ) vlc_value_t oldval, vlc_value_t newval, void *p_data )
{ {
input_thread_t *p_input = (input_thread_t *)p_this; input_thread_t *p_input = (input_thread_t *)p_this;
int64_t i_offset; vlc_value_t val;
/* FIXME TODO FIXME */ /* FIXME TODO FIXME */
msg_Dbg( p_input, "cmd=%s old=%lld new=%lld", psz_cmd, msg_Dbg( p_input, "cmd=%s old=%lld new=%lld", psz_cmd,
oldval.i_time, newval.i_time ); oldval.i_time, newval.i_time );
var_Get( p_input, "length", &val );
vlc_mutex_lock( &p_input->stream.stream_lock ); if( val.i_time > 0 )
i_offset = newval.i_time / 1000000 * 50 * p_input->stream.i_mux_rate; {
val.f_float = (double)newval.i_time / (double)val.i_time;
if( !strcmp( psz_cmd, "time-offset" ) ) if( !strcmp( psz_cmd, "time-offset" ) )
{ {
p_input->stream.p_selected_area->i_seek += i_offset; var_Set( p_input, "position-offset", val );
} }
else else
{ {
p_input->stream.p_selected_area->i_seek = i_offset; var_Set( p_input, "position", val );
} }
if( p_input->stream.p_selected_area->i_seek < 0 ) }
else
{ {
p_input->stream.p_selected_area->i_seek = 0; msg_Warn( p_input, "TimeCallback: length <= 0 -> can't seek" );
} }
vlc_mutex_unlock( &p_input->stream.stream_lock );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
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