Commit b180b18e authored by Erwan Tulou's avatar Erwan Tulou

skins2: use new input-item variable for callbacks on input variables and some cleanup

parent 28726d57
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* *
* Authors: Cyril Deguet <asmax@via.ecp.fr> * Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulière <ipkiss@via.ecp.fr> * Olivier Teulière <ipkiss@via.ecp.fr>
* Erwan Tulou <erwan10@videolan.org>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
...@@ -168,9 +169,9 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ), ...@@ -168,9 +169,9 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
// Called when the "interface shower" wants us to show the skin // Called when the "interface shower" wants us to show the skin
var_AddCallback( pIntf->p_libvlc, "intf-show", var_AddCallback( pIntf->p_libvlc, "intf-show",
onIntfShow, this ); onIntfShow, this );
// Called when the current played item changes // Called when the current input changes
var_AddCallback( pIntf->p_sys->p_playlist, "item-current", var_AddCallback( pIntf->p_sys->p_playlist, "input-current",
onPlaylistChange, this ); onInputNew, this );
// Called when a playlist item changed // Called when a playlist item changed
var_AddCallback( pIntf->p_sys->p_playlist, "item-change", var_AddCallback( pIntf->p_sys->p_playlist, "item-change",
onItemChange, this ); onItemChange, this );
...@@ -182,7 +183,8 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ), ...@@ -182,7 +183,8 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ),
var_AddCallback( pIntf, "interaction", onInteraction, this ); var_AddCallback( pIntf, "interaction", onInteraction, this );
interaction_Register( pIntf ); interaction_Register( pIntf );
getIntf()->p_sys->p_input = NULL; // initialize variables refering to liblvc and playlist objects
init_variables();
} }
...@@ -202,20 +204,22 @@ VlcProc::~VlcProc() ...@@ -202,20 +204,22 @@ VlcProc::~VlcProc()
m_pVout = NULL; m_pVout = NULL;
} }
input_thread_t* pInput = getIntf()->p_sys->p_input; if( getIntf()->p_sys->p_input )
if( pInput ) reset_input();
{
var_DelCallback( pInput, "intf-event", onGenericCallback, this );
var_DelCallback( pInput, "bit-rate", onGenericCallback, this );
var_DelCallback( pInput, "sample-rate", onGenericCallback, this );
var_DelCallback( pInput, "can-Record", onGenericCallback, this );
vlc_object_release( pInput );
getIntf()->p_sys->p_input = NULL;
}
interaction_Unregister( getIntf() ); interaction_Unregister( getIntf() );
var_DelCallback( getIntf()->p_libvlc, "volume-change",
onGenericCallback, this );
var_DelCallback( getIntf()->p_sys->p_playlist, "item-current",
onGenericCallback, this );
var_DelCallback( getIntf()->p_sys->p_playlist, "random",
onGenericCallback, this );
var_DelCallback( getIntf()->p_sys->p_playlist, "loop",
onGenericCallback, this );
var_DelCallback( getIntf()->p_sys->p_playlist, "repeat",
onGenericCallback, this );
var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change", var_DelCallback( getIntf()->p_sys->p_playlist, "intf-change",
onIntfChange, this ); onIntfChange, this );
var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-append", var_DelCallback( getIntf()->p_sys->p_playlist, "playlist-item-append",
...@@ -224,10 +228,8 @@ VlcProc::~VlcProc() ...@@ -224,10 +228,8 @@ VlcProc::~VlcProc()
onItemDelete, this ); onItemDelete, this );
var_DelCallback( getIntf()->p_libvlc, "intf-show", var_DelCallback( getIntf()->p_libvlc, "intf-show",
onIntfShow, this ); onIntfShow, this );
var_DelCallback( getIntf()->p_sys->p_playlist, "item-current", var_DelCallback( getIntf()->p_sys->p_playlist, "input-current",
onGenericCallback, this ); onInputNew, this );
var_DelCallback( getIntf()->p_sys->p_playlist, "item-current",
onPlaylistChange, this );
var_DelCallback( getIntf()->p_sys->p_playlist, "item-change", var_DelCallback( getIntf()->p_sys->p_playlist, "item-change",
onItemChange, this ); onItemChange, this );
var_DelCallback( getIntf(), "skin-to-load", onSkinToLoad, this ); var_DelCallback( getIntf(), "skin-to-load", onSkinToLoad, this );
...@@ -296,6 +298,20 @@ int VlcProc::onIntfShow( vlc_object_t *pObj, const char *pVariable, ...@@ -296,6 +298,20 @@ int VlcProc::onIntfShow( vlc_object_t *pObj, const char *pVariable,
return VLC_SUCCESS; return VLC_SUCCESS;
} }
int VlcProc::onInputNew( vlc_object_t *pObj, const char *pVariable,
vlc_value_t oldval, vlc_value_t newval, void *pParam )
{
VlcProc *pThis = (VlcProc*)pParam;
input_thread_t *pInput = static_cast<input_thread_t*>(newval.p_address);
var_AddCallback( pInput, "intf-event", onGenericCallback, pThis );
var_AddCallback( pInput, "bit-rate", onGenericCallback, pThis );
var_AddCallback( pInput, "sample-rate", onGenericCallback, pThis );
var_AddCallback( pInput, "can-record", onGenericCallback, pThis );
return VLC_SUCCESS;
}
int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable, int VlcProc::onItemChange( vlc_object_t *pObj, const char *pVariable,
vlc_value_t oldval, vlc_value_t newval, vlc_value_t oldval, vlc_value_t newval,
...@@ -362,32 +378,6 @@ int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable, ...@@ -362,32 +378,6 @@ int VlcProc::onItemDelete( vlc_object_t *pObj, const char *pVariable,
} }
int VlcProc::onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
vlc_value_t oldval, vlc_value_t newval,
void *pParam )
{
VlcProc *pThis = (VlcProc*)pParam;
input_item_t *p_item = static_cast<input_item_t*>(newval.p_address);
AsyncQueue *pQueue = AsyncQueue::instance( pThis->getIntf() );
// Update the stream variable
pThis->updateStreamName();
// Create two playtree notify commands: one for old item, one for new
#if 0 /* FIXME: Heck, no! You cannot do that.
There is no warranty that the old item is still valid. */
CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(),
oldVal.i_int );
pQueue->push( CmdGenericPtr( pCmdTree ) , true );
#endif
CmdPlaytreeUpdate *pCmdTree = new CmdPlaytreeUpdate( pThis->getIntf(), p_item->i_id );
pQueue->push( CmdGenericPtr( pCmdTree ) , true );
return VLC_SUCCESS;
}
int VlcProc::onSkinToLoad( vlc_object_t *pObj, const char *pVariable, int VlcProc::onSkinToLoad( vlc_object_t *pObj, const char *pVariable,
vlc_value_t oldVal, vlc_value_t newVal, vlc_value_t oldVal, vlc_value_t newVal,
void *pParam ) void *pParam )
...@@ -504,27 +494,25 @@ int VlcProc::onGenericCallback( vlc_object_t *pObj, const char *pVariable, ...@@ -504,27 +494,25 @@ int VlcProc::onGenericCallback( vlc_object_t *pObj, const char *pVariable,
void VlcProc::on_item_current_changed( vlc_object_t* p_obj, vlc_value_t newVal ) void VlcProc::on_item_current_changed( vlc_object_t* p_obj, vlc_value_t newVal )
{ {
playlist_t * pPlaylist = getIntf()->p_sys->p_playlist;
input_thread_t* pInput = getIntf()->p_sys->p_input; input_thread_t* pInput = getIntf()->p_sys->p_input;
input_item_t *p_item = static_cast<input_item_t*>(newVal.p_address);
if( pInput ) if( pInput )
{ reset_input();
var_DelCallback( pInput, "intf-event", onGenericCallback, this );
var_DelCallback( pInput, "bit-rate", onGenericCallback, this );
var_DelCallback( pInput, "sample-rate", onGenericCallback, this );
var_DelCallback( pInput, "can-record", onGenericCallback, this );
vlc_object_release( pInput );
pInput = getIntf()->p_sys->p_input = NULL;
}
playlist_t * pPlaylist = getIntf()->p_sys->p_playlist;
pInput = playlist_CurrentInput( pPlaylist ); pInput = playlist_CurrentInput( pPlaylist );
if( !pInput ) if( pInput )
return;
var_AddCallback( pInput, "intf-event", onGenericCallback, this );
var_AddCallback( pInput, "bit-rate", onGenericCallback, this );
var_AddCallback( pInput, "sample-rate", onGenericCallback, this );
var_AddCallback( pInput, "can-record", onGenericCallback, this );
getIntf()->p_sys->p_input = pInput; getIntf()->p_sys->p_input = pInput;
// Update the stream variable
updateStreamName();
// Create a playtree notify command
AsyncQueue *pQueue = AsyncQueue::instance( getIntf() );
CmdPlaytreeUpdate *pCmdTree =
new CmdPlaytreeUpdate( getIntf(), p_item->i_id );
pQueue->push( CmdGenericPtr( pCmdTree ) , true );
} }
void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal ) void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
...@@ -533,6 +521,8 @@ void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal ) ...@@ -533,6 +521,8 @@ void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
StreamTime *pTime = (StreamTime*)m_cVarTime.get(); StreamTime *pTime = (StreamTime*)m_cVarTime.get();
VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get(); VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
VarBoolImpl *pVarRecordable = (VarBoolImpl*)m_cVarRecordable.get();
VarBoolImpl *pVarRecording = (VarBoolImpl*)m_cVarRecording.get();
VarBoolImpl *pVarDvdActive = (VarBoolImpl*)m_cVarDvdActive.get(); VarBoolImpl *pVarDvdActive = (VarBoolImpl*)m_cVarDvdActive.get();
VarBoolImpl *pVarHasVout = (VarBoolImpl*)m_cVarHasVout.get(); VarBoolImpl *pVarHasVout = (VarBoolImpl*)m_cVarHasVout.get();
VarBoolImpl *pVarHasAudio = (VarBoolImpl*)m_cVarHasAudio.get(); VarBoolImpl *pVarHasAudio = (VarBoolImpl*)m_cVarHasAudio.get();
...@@ -542,8 +532,6 @@ void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal ) ...@@ -542,8 +532,6 @@ void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get(); VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();
VarBoolImpl *pVarEqualizer = (VarBoolImpl*)m_cVarEqualizer.get(); VarBoolImpl *pVarEqualizer = (VarBoolImpl*)m_cVarEqualizer.get();
if( vlc_object_alive( pInput ) )
{
switch( newVal.i_int ) switch( newVal.i_int )
{ {
case INPUT_EVENT_STATE: case INPUT_EVENT_STATE:
...@@ -646,45 +634,16 @@ void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal ) ...@@ -646,45 +634,16 @@ void VlcProc::on_intf_event_changed( vlc_object_t* p_obj, vlc_value_t newVal )
} }
case INPUT_EVENT_RECORD: case INPUT_EVENT_RECORD:
{
VarBoolImpl *pVarRecording =
(VarBoolImpl*)m_cVarRecording.get();
pVarRecording->set( var_GetBool( pInput, "record" ) ); pVarRecording->set( var_GetBool( pInput, "record" ) );
break; break;
}
case INPUT_EVENT_DEAD: case INPUT_EVENT_DEAD:
case INPUT_EVENT_ABORT: reset_input();
{
var_DelCallback( pInput, "intf-event",
onGenericCallback, this );
var_DelCallback( pInput, "bit-rate",
onGenericCallback, this );
var_DelCallback( pInput, "sample-rate",
onGenericCallback, this );
var_DelCallback( pInput, "can-record" ,
onGenericCallback, this );
vlc_object_release( pInput );
getIntf()->p_sys->p_input = NULL;
break; break;
}
default: default:
break; break;
} }
}
else
{
pVarSeekable->set( false );
pVarDvdActive->set( false );
pTime->set( 0, false );
pVarFullscreen->set( false );
pVarHasAudio->set( false );
pVarHasVout->set( false );
pVarStopped->set( true );
pVarPlaying->set( false );
pVarPaused->set( false );
}
} }
void VlcProc::on_bit_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal ) void VlcProc::on_bit_rate_changed( vlc_object_t* p_obj, vlc_value_t newVal )
...@@ -742,7 +701,6 @@ void VlcProc::on_repeat_changed( vlc_object_t* p_obj, vlc_value_t newVal ) ...@@ -742,7 +701,6 @@ void VlcProc::on_repeat_changed( vlc_object_t* p_obj, vlc_value_t newVal )
pVarRepeat->set( var_GetBool( pPlaylist, "repeat" ) ); pVarRepeat->set( var_GetBool( pPlaylist, "repeat" ) );
} }
void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal ) void VlcProc::on_volume_changed( vlc_object_t* p_obj, vlc_value_t newVal )
{ {
(void)p_obj; (void)newVal; (void)p_obj; (void)newVal;
...@@ -772,3 +730,76 @@ void VlcProc::on_audio_filter_changed( vlc_object_t* p_obj, vlc_value_t newVal ) ...@@ -772,3 +730,76 @@ void VlcProc::on_audio_filter_changed( vlc_object_t* p_obj, vlc_value_t newVal )
pVarEqualizer->set( b_equalizer ); pVarEqualizer->set( b_equalizer );
free( pFilters ); free( pFilters );
} }
void VlcProc::reset_input()
{
input_thread_t* pInput = getIntf()->p_sys->p_input;
if( pInput )
{
StreamTime *pTime = (StreamTime*)m_cVarTime.get();
VarBoolImpl *pVarSeekable = (VarBoolImpl*)m_cVarSeekable.get();
VarBoolImpl *pVarRecordable = (VarBoolImpl*)m_cVarRecordable.get();
VarBoolImpl *pVarRecording = (VarBoolImpl*)m_cVarRecording.get();
VarBoolImpl *pVarDvdActive = (VarBoolImpl*)m_cVarDvdActive.get();
VarBoolImpl *pVarHasVout = (VarBoolImpl*)m_cVarHasVout.get();
VarBoolImpl *pVarHasAudio = (VarBoolImpl*)m_cVarHasAudio.get();
VarBoolImpl *pVarFullscreen = (VarBoolImpl*)m_cVarFullscreen.get();
VarBoolImpl *pVarPlaying = (VarBoolImpl*)m_cVarPlaying.get();
VarBoolImpl *pVarStopped = (VarBoolImpl*)m_cVarStopped.get();
VarBoolImpl *pVarPaused = (VarBoolImpl*)m_cVarPaused.get();
VarBoolImpl *pVarEqualizer = (VarBoolImpl*)m_cVarEqualizer.get();
VarText *pBitrate = (VarText*)m_cVarStreamBitRate.get();
VarText *pSampleRate = (VarText*)m_cVarStreamSampleRate.get();
pVarSeekable->set( false );
pVarRecordable->set( false );
pVarRecording->set( false );
pVarDvdActive->set( false );
pTime->set( 0, false );
pVarFullscreen->set( false );
pVarHasAudio->set( false );
pVarHasVout->set( false );
pVarStopped->set( true );
pVarPlaying->set( false );
pVarPaused->set( false );
pBitrate->set( UString( getIntf(), "") );
pSampleRate->set( UString( getIntf(), "") );
var_DelCallback( pInput, "intf-event", onGenericCallback, this );
var_DelCallback( pInput, "bit-rate", onGenericCallback, this );
var_DelCallback( pInput, "sample-rate", onGenericCallback, this );
var_DelCallback( pInput, "can-record" , onGenericCallback, this );
vlc_object_release( pInput );
getIntf()->p_sys->p_input = NULL;
}
}
void VlcProc::init_variables()
{
playlist_t* pPlaylist = getIntf()->p_sys->p_playlist;
// Refresh the random variable
VarBoolImpl *pVarRandom = (VarBoolImpl*)m_cVarRandom.get();
pVarRandom->set( var_GetBool( pPlaylist, "random" ) );
// Refresh the loop variable
VarBoolImpl *pVarLoop = (VarBoolImpl*)m_cVarLoop.get();
pVarLoop->set( var_GetBool( pPlaylist, "loop" ) );
// Refresh the repeat variable
VarBoolImpl *pVarRepeat = (VarBoolImpl*)m_cVarRepeat.get();
pVarRepeat->set( var_GetBool( pPlaylist, "repeat" ) );
// Refresh sound volume
audio_volume_t volume;
aout_VolumeGet( pPlaylist, &volume );
Volume *pVolume = (Volume*)m_cVarVolume.get();
pVolume->set( (double)volume * 2.0 / AOUT_VOLUME_MAX, false );
// Set the mute variable
VarBoolImpl *pVarMute = (VarBoolImpl*)m_cVarMute.get();
pVarMute->set( volume == 0 );
}
...@@ -158,6 +158,12 @@ class VlcProc: public SkinObject ...@@ -158,6 +158,12 @@ class VlcProc: public SkinObject
*/ */
void manage(); void manage();
// reset variables when input is over
void reset_input();
// init variables (libvlc and playlist levels)
void init_variables();
/// Define the command that calls manage() /// Define the command that calls manage()
DEFINE_CALLBACK( VlcProc, Manage ); DEFINE_CALLBACK( VlcProc, Manage );
...@@ -174,6 +180,11 @@ class VlcProc: public SkinObject ...@@ -174,6 +180,11 @@ class VlcProc: public SkinObject
vlc_value_t oldVal, vlc_value_t newVal, vlc_value_t oldVal, vlc_value_t newVal,
void *pParam ); void *pParam );
/// Callback for input-current variable
static int onInputNew( vlc_object_t *pObj, const char *pVariable,
vlc_value_t oldVal, vlc_value_t newVal,
void *pParam );
/// Callback for item-change variable /// Callback for item-change variable
static int onItemChange( vlc_object_t *pObj, const char *pVariable, static int onItemChange( vlc_object_t *pObj, const char *pVariable,
vlc_value_t oldVal, vlc_value_t newVal, vlc_value_t oldVal, vlc_value_t newVal,
...@@ -189,12 +200,6 @@ class VlcProc: public SkinObject ...@@ -189,12 +200,6 @@ class VlcProc: public SkinObject
vlc_value_t oldVal, vlc_value_t newVal, vlc_value_t oldVal, vlc_value_t newVal,
void *pParam ); void *pParam );
/// Callback for playlist-current variable
static int onPlaylistChange( vlc_object_t *pObj, const char *pVariable,
vlc_value_t oldVal, vlc_value_t newVal,
void *pParam );
/// Callback for skins2-to-load variable /// Callback for skins2-to-load variable
static int onSkinToLoad( vlc_object_t *pObj, const char *pVariable, static int onSkinToLoad( vlc_object_t *pObj, const char *pVariable,
vlc_value_t oldVal, vlc_value_t newVal, vlc_value_t oldVal, vlc_value_t newVal,
......
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