From ef5c233752d6808a6f9b61cdfc92d44baa5ca824 Mon Sep 17 00:00:00 2001 From: Cyril Deguet Date: Sun, 9 Apr 2006 14:29:26 +0000 Subject: [PATCH] * all: new skin text variable "$B" to get the stream bitrate * winamp2.xml: added "kbps" info in winamp skins --- doc/skins/skins2-howto.xml | 3 +++ modules/gui/skins2/src/file_bitmap.cpp | 2 ++ modules/gui/skins2/src/vlcproc.cpp | 22 +++++++++++++++++----- modules/gui/skins2/src/vlcproc.hpp | 5 +++++ modules/gui/skins2/utils/ustring.cpp | 10 ++++++++++ modules/gui/skins2/utils/ustring.hpp | 3 +++ modules/gui/skins2/utils/var_text.cpp | 10 ++++++++++ share/skins2/winamp2.xml | 1 + 8 files changed, 51 insertions(+), 5 deletions(-) diff --git a/doc/skins/skins2-howto.xml b/doc/skins/skins2-howto.xml index f548bc5a96..3791898c83 100644 --- a/doc/skins/skins2-howto.xml +++ b/doc/skins/skins2-howto.xml @@ -897,6 +897,9 @@ difficulty to understand how VLC skins work. When specifying the text attribute of the Text control or any tooltip attribute, you can insert escape sequences which will be expanded dynamically. An escape sequence always starts with the '$' character, followed by one or more predefined letters. Here is the list of accepted escape sequences: + + $B: Get the stream bitrate (in kb/s). + $V: Value of the volume (from 0 to 100 --> useful for a percentage). diff --git a/modules/gui/skins2/src/file_bitmap.cpp b/modules/gui/skins2/src/file_bitmap.cpp index b41a79650f..e52415d1de 100644 --- a/modules/gui/skins2/src/file_bitmap.cpp +++ b/modules/gui/skins2/src/file_bitmap.cpp @@ -37,6 +37,8 @@ FileBitmap::FileBitmap( intf_thread_t *pIntf, image_handler_t *pImageHandler, fmt_out.i_chroma = VLC_FOURCC('R','V','3','2'); +fprintf(stderr,"FILE %s\n", fileName.c_str()); + pPic = image_ReadUrl( pImageHandler, fileName.c_str(), &fmt_in, &fmt_out ); if( !pPic ) return; diff --git a/modules/gui/skins2/src/vlcproc.cpp b/modules/gui/skins2/src/vlcproc.cpp index 125c43bafa..bc97821977 100644 --- a/modules/gui/skins2/src/vlcproc.cpp +++ b/modules/gui/skins2/src/vlcproc.cpp @@ -26,6 +26,7 @@ #include #include +#include #include "vlcproc.hpp" #include "os_factory.hpp" #include "os_timer.hpp" @@ -108,6 +109,8 @@ VlcProc::VlcProc( intf_thread_t *pIntf ): SkinObject( pIntf ), pVarManager->registerVar( m_cVarStreamName, "streamName" ); m_cVarStreamURI = VariablePtr( new VarText( getIntf(), false ) ); pVarManager->registerVar( m_cVarStreamURI, "streamURI" ); + m_cVarStreamBitRate = VariablePtr( new VarText( getIntf(), false ) ); + pVarManager->registerVar( m_cVarStreamBitRate, "bitrate" ); // Register the equalizer bands for( int i = 0; i < EqualizerBands::kNbBands; i++) @@ -239,6 +242,7 @@ void VlcProc::manage() VarBoolImpl *pVarDvdActive = (VarBoolImpl*)m_cVarDvdActive.get(); VarBoolImpl *pVarFullscreen = (VarBoolImpl*)m_cVarFullscreen.get(); VarBoolImpl *pVarHasVout = (VarBoolImpl*)m_cVarHasVout.get(); + VarText *pBitrate = (VarText*)m_cVarStreamBitRate.get(); // Refresh audio variables refreshAudio(); @@ -290,6 +294,12 @@ void VlcProc::manage() pVarFullscreen->set( pVout->b_fullscreen ); vlc_object_release( pVout ); } + + // Get information on the current playlist item + input_item_t *pItem = pInput->input.p_item; + // Get the input bitrate + int bitrate = (int)(roundf(pItem->p_stats->f_demux_bitrate*8000)); + pBitrate->set( UString::fromInt( getIntf(), bitrate ) ); } else { @@ -558,13 +568,16 @@ int VlcProc::onInteraction( vlc_object_t *pObj, const char *pVariable, void VlcProc::updateStreamName( playlist_t *p_playlist ) { - if( p_playlist->p_input ) + if( p_playlist && p_playlist->p_input ) { + // Get playlist item information + input_item_t *pItem = p_playlist->p_input->input.p_item; + VarText &rStreamName = getStreamNameVar(); VarText &rStreamURI = getStreamURIVar(); // XXX: we should not need to access p_input->psz_source directly, a // getter should be provided by VLC core - string name = p_playlist->p_input->input.p_item->psz_name; + string name = pItem->psz_name; // XXX: This should be done in VLC core, not here... // Remove path information if any OSFactory *pFactory = OSFactory::instance( getIntf() ); @@ -574,10 +587,9 @@ void VlcProc::updateStreamName( playlist_t *p_playlist ) name = name.substr( pos + 1, name.size() - pos + 1 ); } UString srcName( getIntf(), name.c_str() ); - UString srcURI( getIntf(), - p_playlist->p_input->input.p_item->psz_uri ); + UString srcURI( getIntf(), pItem->psz_uri ); - // Create commands to update the stream variables + // Create commands to update the stream variables CmdSetText *pCmd1 = new CmdSetText( getIntf(), rStreamName, srcName ); CmdSetText *pCmd2 = new CmdSetText( getIntf(), rStreamURI, srcURI ); // Push the commands in the asynchronous command queue diff --git a/modules/gui/skins2/src/vlcproc.hpp b/modules/gui/skins2/src/vlcproc.hpp index 94bf422b0a..d298c13367 100644 --- a/modules/gui/skins2/src/vlcproc.hpp +++ b/modules/gui/skins2/src/vlcproc.hpp @@ -72,6 +72,10 @@ class VlcProc: public SkinObject VarText &getStreamURIVar() { return *((VarText*)(m_cVarStreamURI.get())); } + /// Getter for the stream bitrate variable + VarText &getStreamBitRateVar() + { return *((VarText*)(m_cVarStreamBitRate.get())); } + /// Getter for the vout size variable VarBox &getVoutSizeVar() { return m_varVoutSize; } @@ -110,6 +114,7 @@ class VlcProc: public SkinObject /// Variable for current stream properties VariablePtr m_cVarStreamName; VariablePtr m_cVarStreamURI; + VariablePtr m_cVarStreamBitRate; /// Variable for the "mute" state VariablePtr m_cVarMute; /// Variables related to the input diff --git a/modules/gui/skins2/utils/ustring.cpp b/modules/gui/skins2/utils/ustring.cpp index 8689f9377e..5513fe4344 100644 --- a/modules/gui/skins2/utils/ustring.cpp +++ b/modules/gui/skins2/utils/ustring.cpp @@ -23,6 +23,7 @@ *****************************************************************************/ #include +#include #include "ustring.hpp" @@ -328,3 +329,12 @@ UString UString::substr( uint32_t position, uint32_t n) const return tmp; } + + +UString UString::fromInt( intf_thread_t *pIntf, int number) +{ + stringstream ss; + ss << number; + return UString( pIntf, ss.str().c_str() ); +} + diff --git a/modules/gui/skins2/utils/ustring.hpp b/modules/gui/skins2/utils/ustring.hpp index ed74132992..90175b6c21 100644 --- a/modules/gui/skins2/utils/ustring.hpp +++ b/modules/gui/skins2/utils/ustring.hpp @@ -82,6 +82,9 @@ class UString: public SkinObject /// characters in this string starting at index position UString substr( uint32_t position = 0, uint32_t n = npos) const; + /// Build a string from an integer + static UString fromInt(intf_thread_t *pIntf, int number); + /// XXX: temporary void debug() const; diff --git a/modules/gui/skins2/utils/var_text.cpp b/modules/gui/skins2/utils/var_text.cpp index 4b0dda3403..7ca12fd7bc 100644 --- a/modules/gui/skins2/utils/var_text.cpp +++ b/modules/gui/skins2/utils/var_text.cpp @@ -48,6 +48,7 @@ VarText::~VarText() pVlcProc->getVolumeVar().delObserver( this ); pVlcProc->getStreamURIVar().delObserver( this ); pVlcProc->getStreamNameVar().delObserver( this ); + pVlcProc->getStreamBitRateVar().delObserver( this ); VarManager *pVarManager = VarManager::instance( getIntf() ); pVarManager->getHelpText().delObserver( this ); } @@ -121,6 +122,10 @@ const UString VarText::get() const { temp.replace( pos, 2, pVlcProc->getStreamURIVar().get() ); } + while( (pos = temp.find( "$B" )) != UString::npos ) + { + temp.replace( pos, 2, pVlcProc->getStreamBitRateVar().get() ); + } return temp; } @@ -144,6 +149,7 @@ void VarText::set( const UString &rText ) pVlcProc->getVolumeVar().delObserver( this ); pVlcProc->getStreamNameVar().delObserver( this ); pVlcProc->getStreamURIVar().delObserver( this ); + pVlcProc->getStreamBitRateVar().delObserver( this ); VarManager *pVarManager = VarManager::instance( getIntf() ); pVarManager->getHelpText().delObserver( this ); @@ -179,6 +185,10 @@ void VarText::set( const UString &rText ) { pVlcProc->getStreamURIVar().addObserver( this ); } + if( m_text.find( "$B" ) != UString::npos ) + { + pVlcProc->getStreamBitRateVar().addObserver( this ); + } } notify(); diff --git a/share/skins2/winamp2.xml b/share/skins2/winamp2.xml index 9bd0c497cf..2371ff2d92 100644 --- a/share/skins2/winamp2.xml +++ b/share/skins2/winamp2.xml @@ -194,6 +194,7 @@ + -- 2.39.2