diff --git a/src/app/xineEngine.cpp b/src/app/xineEngine.cpp index 3ae7220..441ab3d 100644 --- a/src/app/xineEngine.cpp +++ b/src/app/xineEngine.cpp @@ -26,7 +26,6 @@ namespace Codeine { VideoWindow *VideoWindow::s_instance = nullptr; -bool VideoWindow::s_logarithmicVolume = false; VideoWindow::VideoWindow( TQWidget *parent ) @@ -54,13 +53,6 @@ VideoWindow::VideoWindow( TQWidget *parent ) //TODO sucks //TODO namespace this? myList->next = myList; //init the buffer list - - // Detect xine version, this is used for volume adjustment. - // Xine versions prior to 1.2.13 use linear volume, so the engine uses logarithmic volume. - // Xine versions starting from 1.2.13 use logarithmic volume, so the engine uses linear volume. - int xinemajor = 0, xineminor = 0, xinemaint = 0; - xine_get_version(&xinemajor, &xineminor, &xinemaint); - s_logarithmicVolume = (xinemajor * 1000000 + xineminor * 1000 + xinemaint < 1002013); } VideoWindow::~VideoWindow() @@ -70,31 +62,37 @@ VideoWindow::~VideoWindow() eject(); // fade out volume on exit - if( m_stream && xine_get_status( m_stream ) == XINE_STATUS_PLAY ) { + const int volBeforeFade = xine_get_param(m_stream, XINE_PARAM_AUDIO_VOLUME); + if (m_stream && xine_get_status(m_stream) == XINE_STATUS_PLAY) + { int cum = 0; - for( int v = 99; v >= 0; v-- ) { - int vol = v; - if (s_logarithmicVolume) - { - vol = makeVolumeLogarithmic(vol); - } - xine_set_param( m_stream, XINE_PARAM_AUDIO_AMP_LEVEL, vol ); - int sleep = int(32000 * (-std::log10( double(v + 1) ) + 2)); + int vol = volBeforeFade; - ::usleep( sleep ); + while (vol > 0) + { + vol -= 1; + xine_set_param(m_stream, XINE_PARAM_AUDIO_VOLUME, vol); + int sleep = int(32000 * (-std::log10(vol + 1.0) + 2)); + + ::usleep(sleep); cum += sleep; } debug() << "Total sleep: " << cum << "x10^-6 s\n"; - xine_stop( m_stream ); + xine_stop(m_stream); - ::sleep( 1 ); + ::sleep(1); } //xine_set_param( m_stream, XINE_PARAM_IGNORE_VIDEO, 1 ); + // Xine (or the audio driver) seems to remember the volume level, + // even when xine's audio.volume.remember_volume is set to false. + // FIXME: The VolumeSlider doesn't reflect this initial volume! + xine_set_param(m_stream, XINE_PARAM_AUDIO_VOLUME, volBeforeFade); + if( m_osd ) xine_osd_free( m_osd ); if( m_stream ) xine_close( m_stream ); if( m_eventQueue ) xine_event_dispose_queue( m_eventQueue ); @@ -268,8 +266,7 @@ VideoWindow::load( const KURL &url ) setParameter( XINE_PARAM_SPU_CHANNEL, -1 ); setParameter( XINE_PARAM_AUDIO_CHANNEL_LOGICAL, -1 ); setParameter( XINE_PARAM_VO_ASPECT_RATIO, 0 ); - // 100 is the same for both linear and logarithmic volume control - setParameter( XINE_PARAM_AUDIO_AMP_LEVEL, 100 ); + setParameter( XINE_PARAM_AUDIO_VOLUME, 100 ); #undef setParameter videoWindow()->setShown( xine_get_stream_info( m_stream, XINE_STREAM_INFO_HAS_VIDEO ) ); @@ -456,14 +453,10 @@ VideoWindow::posTimeLength( PosTimeLength type ) const return 0; //--warning } -uint +int VideoWindow::volume() const { - int vol = xine_get_param( m_stream, XINE_PARAM_AUDIO_AMP_LEVEL ); - if (s_logarithmicVolume) - { - vol = 100 - 100.0 * (pow(10, (100.0 - vol) / 100.0) - 1) / 9.0; - } + int vol = xine_get_param(m_stream, XINE_PARAM_AUDIO_VOLUME); if (vol < 0) { vol = 0; @@ -472,7 +465,7 @@ VideoWindow::volume() const { vol = 100; } - return (uint)vol; + return vol; } void @@ -505,7 +498,7 @@ VideoWindow::seek( uint pos ) // xine_play unpauses stream if stream was paused // was broken at 1.0.1 still wasPaused = true; - xine_set_param( m_stream, XINE_PARAM_AUDIO_AMP_MUTE, 1 ); + xine_set_param( m_stream, XINE_PARAM_AUDIO_MUTE, 1 ); break; default: ; @@ -553,16 +546,11 @@ VideoWindow::seek( uint pos ) //after xine_play because the hide command uses stream position xine_osd_hide( m_osd, xine_get_current_vpts( m_stream ) + 180000 ); //2 seconds - if( wasPaused ) - xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE ), - xine_set_param( m_stream, XINE_PARAM_AUDIO_AMP_MUTE, 0 ); -} - -int -VideoWindow::makeVolumeLogarithmic(int volume) -{ - // We're using a logarithmic function to make the volume ramp more natural. - return static_cast( 100 - 100.0 * std::log10( ( 100 - volume ) * 0.09 + 1.0 ) ); + if (wasPaused) + { + xine_set_param( m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE ); + xine_set_param( m_stream, XINE_PARAM_AUDIO_MUTE, 0 ); + } } void @@ -589,12 +577,8 @@ VideoWindow::setStreamParameter( int value ) parameter = XINE_PARAM_VO_ASPECT_RATIO; else if( sender == "volume" ) { - parameter = XINE_PARAM_AUDIO_AMP_LEVEL; + parameter = XINE_PARAM_AUDIO_VOLUME; value = 100 - value; // TQt sliders are wrong way round when vertical - if (s_logarithmicVolume) - { - value = makeVolumeLogarithmic(value); - } } else return; diff --git a/src/app/xineEngine.h b/src/app/xineEngine.h index d152a96..318f7ff 100644 --- a/src/app/xineEngine.h +++ b/src/app/xineEngine.h @@ -39,7 +39,6 @@ namespace Codeine enum PosTimeLength { Pos, Time, Length }; static VideoWindow *s_instance; - static bool s_logarithmicVolume; VideoWindow( const VideoWindow& ); //disable VideoWindow &operator=( const VideoWindow& ); //disable @@ -62,7 +61,7 @@ namespace Codeine uint time() const { return posTimeLength( Time ); } uint length() const { return posTimeLength( Length ); } - uint volume() const; + int volume() const; const Engine::Scope &scope(); Engine::State state() const; @@ -121,7 +120,6 @@ namespace Codeine private: static void destSizeCallBack( void*, int, int, double, int*, int*, double* ); static void frameOutputCallBack( void*, int, int, double, int*, int*, int*, int*, double*, int*, int* ); - static int makeVolumeLogarithmic(int volume); void initVideo(); void cleanUpVideo();