[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: extragear/multimedia/amarok/src/engine/xine
From: Mark Kretschmann <markey () web ! de>
Date: 2006-12-25 10:00:18
Message-ID: 1167040818.644707.19587.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 616406 by markey:
Fix a nasty bug with fade-out: When a fade-out was running (after pressing Stop), and you started another \
track, Amarok would (mostly) freeze.
Also cleaned up the code and removed unnecessary nonsense.
M +132 -125 xine-engine.cpp
M +7 -5 xine-engine.h
--- trunk/extragear/multimedia/amarok/src/engine/xine/xine-engine.cpp #616405:616406
@@ -94,15 +94,14 @@
m_stopFader = true;
s_fader->resume(); // safety call if the engine is in the pause state
s_fader->wait();
- delete s_fader;
}
- if( s_outfader ) {
- s_outfader->wait();
- delete s_outfader;
- }
- fadeOut( true ); // true == exiting
+ delete s_fader;
+ delete s_outfader;
+ bool terminateFader = false;
+ fadeOut( &terminateFader, true ); // true == exiting
+
if( m_xine ) xine_config_save( m_xine, configPath() );
if( m_stream ) xine_close( m_stream );
@@ -216,6 +215,11 @@
Engine::Base::load( url, isStream );
+ if( s_outfader ) {
+ s_outfader->finish();
+ delete s_outfader;
+ }
+
if( m_xfadeLength > 0 && xine_get_status( m_stream ) == XINE_STATUS_PLAY &&
xine_get_param( m_stream, XINE_PARAM_SPEED ) != XINE_SPEED_PAUSE &&
( m_xfadeNextTrack || //set by engine controller when switching tracks automatically
@@ -367,7 +371,7 @@
return;
if( !m_fadeOutRunning || state() == Engine::Paused )
{
- s_outfader = new OutFader( this, true, true );
+ s_outfader = new OutFader( this );
s_outfader->start();
::usleep( 100 ); //to be sure engine state won't be changed before it is checked in fadeOut()
m_url = KURL(); //to ensure we return Empty from state()
@@ -513,7 +517,7 @@
}
void
-XineEngine::fadeOut( bool exiting )
+XineEngine::fadeOut( bool* terminate, bool exiting )
{
if( m_fadeOutRunning ) //Let us not start another fadeout...
return;
@@ -537,6 +541,8 @@
float mix = 0.0;
while ( mix < 1.0 )
{
+ if( *terminate ) break;
+
::usleep( stepSizeUs );
float vol = Engine::Base::makeVolumeLogarithmic( m_volume ) * m_preamp;
float mix = (float)t.elapsed() / (float)length;
@@ -1024,10 +1030,103 @@
return bundle;
}
+bool XineEngine::metaDataForUrl(const KURL &url, Engine::SimpleMetaBundle &b)
+{
+ bool result = false;
+ xine_stream_t* tmpstream = xine_stream_new(m_xine, NULL, NULL);
+ if (xine_open(tmpstream, QFile::encodeName(url.url()))) {
+ QString audioCodec = QString::fromUtf8(xine_get_meta_info(tmpstream, \
XINE_META_INFO_SYSTEMLAYER));
-//////////////////
+ if (audioCodec == "CDDA") {
+ QString title = QString::fromUtf8(
+ xine_get_meta_info(tmpstream, XINE_META_INFO_TITLE));
+ if ((!title.isNull()) && (!title.isEmpty())) { //no meta info
+ b.title = title;
+ b.artist =
+ QString::fromUtf8(
+ xine_get_meta_info(tmpstream, XINE_META_INFO_ARTIST));
+ b.album =
+ QString::fromUtf8(
+ xine_get_meta_info(tmpstream, XINE_META_INFO_ALBUM));
+ b.genre =
+ QString::fromUtf8(
+ xine_get_meta_info(tmpstream, XINE_META_INFO_GENRE));
+ b.year =
+ QString::fromUtf8(
+ xine_get_meta_info(tmpstream, XINE_META_INFO_YEAR));
+ b.tracknr =
+ QString::fromUtf8(
+ xine_get_meta_info(tmpstream, XINE_META_INFO_TRACK_NUMBER));
+ if( b.tracknr.isEmpty() )
+ b.tracknr = url.filename();
+ } else {
+ b.title = QString(i18n("Track %1")).arg(url.filename());
+ b.album = i18n("AudioCD");
+ }
+ }
+
+ if (audioCodec == "CDDA" || audioCodec == "WAV") {
+ result = true;
+ int samplerate = xine_get_stream_info( tmpstream, XINE_STREAM_INFO_AUDIO_SAMPLERATE );
+
+ // xine would provide a XINE_STREAM_INFO_AUDIO_BITRATE, but unfortunately not for CDDA or \
WAV + // so we calculate the bitrate by our own
+ int bitsPerSample = xine_get_stream_info( tmpstream, XINE_STREAM_INFO_AUDIO_BITS );
+ int nbrChannels = xine_get_stream_info( tmpstream, XINE_STREAM_INFO_AUDIO_CHANNELS );
+ int bitrate = (samplerate * bitsPerSample * nbrChannels) / 1000;
+
+ b.bitrate = QString::number(bitrate);
+ b.samplerate = QString::number(samplerate);
+ int pos, time, length = 0;
+ xine_get_pos_length(tmpstream, &pos, &time, &length);
+ b.length = QString::number(length / 1000);
+ }
+ xine_close(tmpstream);
+ }
+ xine_dispose(tmpstream);
+ return result;
+}
+
+bool XineEngine::getAudioCDContents(const QString &device, KURL::List &urls)
+{
+ char **xine_urls = NULL;
+ int num;
+ int i = 0;
+
+ if (!device.isNull()) {
+ debug() << "xine-engine setting CD Device to: " << device << endl;
+ xine_cfg_entry_t config;
+ if (!xine_config_lookup_entry(m_xine, "input.cdda_device", &config)) {
+ emit statusText(i18n("Failed CD device lookup in xine engine"));
+ return false;
+ }
+ config.str_value = (char *)device.latin1();
+ xine_config_update_entry(m_xine, &config);
+ }
+
+ emit statusText(i18n("Getting AudioCD contents..."));
+
+ xine_urls = xine_get_autoplay_mrls(m_xine, "CD", &num);
+
+ if (xine_urls) {
+ while (xine_urls[i]) {
+ urls << KURL(xine_urls[i]);
+ ++i;
+ }
+ }
+ else emit statusText(i18n("Could not read AudioCD"));
+
+ return true;
+}
+
+bool XineEngine::flushBuffer()
+{
+ return false;
+}
+
+//////////////////////////////////////////////////////////////////////////////
/// class Fader
-//////////////////
+//////////////////////////////////////////////////////////////////////////////
Fader::Fader( XineEngine *engine, uint fadeMs )
: QObject( engine )
@@ -1042,6 +1141,8 @@
, m_paused( false )
, m_terminated( false )
{
+ DEBUG_BLOCK
+
if( engine->makeNewStream() )
{
m_increase = engine->m_stream;
@@ -1056,10 +1157,10 @@
Fader::~Fader()
{
+ DEBUG_BLOCK
+
wait();
- DEBUG_FUNC_INFO
-
xine_close( m_decrease );
xine_dispose( m_decrease );
xine_close_audio_driver( m_xine, m_port );
@@ -1075,6 +1176,8 @@
void
Fader::run()
{
+ DEBUG_BLOCK
+
// do a volume change in 100 steps (or every 10ms)
uint stepsCount = m_fadeLength < 1000 ? m_fadeLength / 10 : 100;
uint stepSizeUs = (int)( 1000.0 * (float)m_fadeLength / (float)stepsCount );
@@ -1138,7 +1241,6 @@
m_paused = false;
}
-
void
Fader::finish()
{
@@ -1146,142 +1248,47 @@
m_terminated = true;
}
-//////////////////
+//////////////////////////////////////////////////////////////////////////////
/// class OutFader
-//////////////////
+//////////////////////////////////////////////////////////////////////////////
-OutFader::OutFader( XineEngine *engine, bool stop, bool force )
+OutFader::OutFader( XineEngine *engine )
: QObject( engine )
, QThread()
, m_engine( engine )
- , m_stop( stop )
- , m_force( force )
+ , m_terminated( false )
{
+ DEBUG_BLOCK
}
OutFader::~OutFader()
{
+ DEBUG_BLOCK
+
wait();
- DEBUG_FUNC_INFO
-
s_outfader = 0;
}
void
OutFader::run()
{
- m_engine->fadeOut();
- if( m_engine->m_fadeOutRunning == false || m_force )
- {
- if( m_stop )
- {
- xine_stop( m_engine->m_stream );
- xine_close( m_engine->m_stream );
- xine_set_param( m_engine->m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1);
- }
- else
- {
- xine_set_param( m_engine->m_stream, XINE_PARAM_SPEED, XINE_SPEED_PAUSE );
- xine_set_param( m_engine->m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1);
- }
- }
- QThread::sleep( 3 );
- deleteLater();
-}
+ DEBUG_BLOCK
-bool XineEngine::metaDataForUrl(const KURL &url, Engine::SimpleMetaBundle &b)
-{
- bool result = false;
- xine_stream_t* tmpstream = xine_stream_new(m_xine, NULL, NULL);
- if (xine_open(tmpstream, QFile::encodeName(url.url()))) {
- QString audioCodec = QString::fromUtf8(xine_get_meta_info(tmpstream, \
XINE_META_INFO_SYSTEMLAYER)); + m_engine->fadeOut( &m_terminated );
- if (audioCodec == "CDDA") {
- QString title = QString::fromUtf8(
- xine_get_meta_info(tmpstream, XINE_META_INFO_TITLE));
- if ((!title.isNull()) && (!title.isEmpty())) { //no meta info
- b.title = title;
- b.artist =
- QString::fromUtf8(
- xine_get_meta_info(tmpstream, XINE_META_INFO_ARTIST));
- b.album =
- QString::fromUtf8(
- xine_get_meta_info(tmpstream, XINE_META_INFO_ALBUM));
- b.genre =
- QString::fromUtf8(
- xine_get_meta_info(tmpstream, XINE_META_INFO_GENRE));
- b.year =
- QString::fromUtf8(
- xine_get_meta_info(tmpstream, XINE_META_INFO_YEAR));
- b.tracknr =
- QString::fromUtf8(
- xine_get_meta_info(tmpstream, XINE_META_INFO_TRACK_NUMBER));
- if( b.tracknr.isEmpty() )
- b.tracknr = url.filename();
- } else {
- b.title = QString(i18n("Track %1")).arg(url.filename());
- b.album = i18n("AudioCD");
- }
- }
+ xine_stop( m_engine->m_stream );
+ xine_close( m_engine->m_stream );
+ xine_set_param( m_engine->m_stream, XINE_PARAM_AUDIO_CLOSE_DEVICE, 1);
- if (audioCodec == "CDDA" || audioCodec == "WAV") {
- result = true;
- int samplerate = xine_get_stream_info( tmpstream, XINE_STREAM_INFO_AUDIO_SAMPLERATE );
-
- // xine would provide a XINE_STREAM_INFO_AUDIO_BITRATE, but unfortunately not for CDDA or \
WAV
- // so we calculate the bitrate by our own
- int bitsPerSample = xine_get_stream_info( tmpstream, XINE_STREAM_INFO_AUDIO_BITS );
- int nbrChannels = xine_get_stream_info( tmpstream, XINE_STREAM_INFO_AUDIO_CHANNELS );
- int bitrate = (samplerate * bitsPerSample * nbrChannels) / 1000;
-
- b.bitrate = QString::number(bitrate);
- b.samplerate = QString::number(samplerate);
- int pos, time, length = 0;
- xine_get_pos_length(tmpstream, &pos, &time, &length);
- b.length = QString::number(length / 1000);
- }
- xine_close(tmpstream);
- }
- xine_dispose(tmpstream);
- return result;
+ deleteLater();
}
-bool XineEngine::getAudioCDContents(const QString &device, KURL::List &urls)
+void
+OutFader::finish()
{
- char **xine_urls = NULL;
- int num;
- int i = 0;
-
- if (!device.isNull()) {
- debug() << "xine-engine setting CD Device to: " << device << endl;
- xine_cfg_entry_t config;
- if (!xine_config_lookup_entry(m_xine, "input.cdda_device", &config)) {
- emit statusText(i18n("Failed CD device lookup in xine engine"));
- return false;
- }
- config.str_value = (char *)device.latin1();
- xine_config_update_entry(m_xine, &config);
- }
-
- emit statusText(i18n("Getting AudioCD contents..."));
-
- xine_urls = xine_get_autoplay_mrls(m_xine, "CD", &num);
-
- if (xine_urls) {
- while (xine_urls[i]) {
- urls << KURL(xine_urls[i]);
- ++i;
- }
- }
- else emit statusText(i18n("Could not read AudioCD"));
-
- return true;
+ DEBUG_BLOCK
+ m_terminated = true;
}
-bool XineEngine::flushBuffer()
-{
- return false;
-}
-
#include "xine-engine.moc"
--- trunk/extragear/multimedia/amarok/src/engine/xine/xine-engine.h #616405:616406
@@ -53,7 +53,7 @@
virtual void setEqualizerEnabled( bool );
virtual void setEqualizerParameters( int preamp, const QValueList<int>& );
virtual void setVolumeSW( uint );
- virtual void fadeOut( bool exiting = false );
+ virtual void fadeOut( bool* terminate, bool exiting = false );
static void XineEventListener( void*, const xine_event_t* );
virtual void customEvent( QCustomEvent* );
@@ -121,14 +121,16 @@
class OutFader : public QObject, public QThread
{
- XineEngine *m_engine;
- bool m_stop;
- bool m_force;
+ XineEngine *m_engine;
+ bool m_terminated;
virtual void run();
+
public:
- OutFader( XineEngine *, bool stop, bool force = false );
+ OutFader( XineEngine * );
~OutFader();
+
+ void finish();
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic