From 1610dc32e41f835576a36e9d0bfa41cdee1f763e Mon Sep 17 00:00:00 2001 From: Paul Harrison Date: Sun, 26 May 2013 23:53:06 +0100 Subject: [PATCH] MythMusic: rip out the CDWatcherThread We will use the media monitor instead now it seems to be more stable. --- mythplugins/mythmusic/mythmusic/main.cpp | 6 +- .../mythmusic/mythmusic/musiccommon.cpp | 14 -- .../mythmusic/mythmusic/musicplayer.cpp | 142 +----------------- mythplugins/mythmusic/mythmusic/musicplayer.h | 32 +--- 4 files changed, 7 insertions(+), 187 deletions(-) diff --git a/mythplugins/mythmusic/mythmusic/main.cpp b/mythplugins/mythmusic/mythmusic/main.cpp index 0a38174034d..a99a6a4eb41 100644 --- a/mythplugins/mythmusic/mythmusic/main.cpp +++ b/mythplugins/mythmusic/mythmusic/main.cpp @@ -48,10 +48,6 @@ #include "cdrip.h" #endif - -// This stores the last MythMediaDevice that was detected: -QString gCDdevice; - /** * \brief Work out the best CD drive to use at this time */ @@ -588,7 +584,7 @@ int mythplugin_init(const char *libversion) setupKeys(); - gPlayer = new MusicPlayer(NULL, chooseCD()); + gPlayer = new MusicPlayer(NULL); gMusicData = new MusicData(); return 0; diff --git a/mythplugins/mythmusic/mythmusic/musiccommon.cpp b/mythplugins/mythmusic/mythmusic/musiccommon.cpp index 7a1950dbf80..c7907a5c13a 100644 --- a/mythplugins/mythmusic/mythmusic/musiccommon.cpp +++ b/mythplugins/mythmusic/mythmusic/musiccommon.cpp @@ -52,13 +52,6 @@ MusicCommon::MusicCommon(MythScreenStack *parent, const QString &name) m_currentTime = 0; m_maxTime = 0; -#if 0 - cd_reader_thread = NULL; - cd_watcher = NULL; - scan_for_cd = gContext->GetNumSetting("AutoPlayCD", 0); - m_CDdevice = dev; -#endif - m_cycleVisualizer = gCoreContext->GetNumSetting("VisualCycleOnSongChange", 0); if (LCD *lcd = LCD::Get()) @@ -481,13 +474,6 @@ void MusicCommon::switchView(MusicView view) gPlayer->setAllowRestorePos(true); } -#if 0 -bool MusicCommon::onMediaEvent(MythMediaDevice*) -{ - return scan_for_cd; -} -#endif - bool MusicCommon::keyPressEvent(QKeyEvent *e) { bool handled = false; diff --git a/mythplugins/mythmusic/mythmusic/musicplayer.cpp b/mythplugins/mythmusic/mythmusic/musicplayer.cpp index 19d37ffa496..a2b00ac859d 100644 --- a/mythplugins/mythmusic/mythmusic/musicplayer.cpp +++ b/mythplugins/mythmusic/mythmusic/musicplayer.cpp @@ -34,6 +34,7 @@ #define LASTPLAY_DELAY 15 MusicPlayer *gPlayer = NULL; +QString gCDdevice = ""; //////////////////////////////////////////////////////////////// @@ -49,15 +50,13 @@ QEvent::Type MusicPlayerEvent::CDChangedEvent = (QEvent::Type) QEvent::registerE QEvent::Type MusicPlayerEvent::PlaylistChangedEvent = (QEvent::Type) QEvent::registerEventType(); QEvent::Type MusicPlayerEvent::PlayedTracksChangedEvent = (QEvent::Type) QEvent::registerEventType(); -MusicPlayer::MusicPlayer(QObject *parent, const QString &dev) +MusicPlayer::MusicPlayer(QObject *parent) :QObject(parent) { setObjectName("MusicPlayer"); - m_CDdevice = dev; m_output = NULL; m_decoderHandler = NULL; - m_cdWatcher = NULL; m_currentPlaylist = NULL; m_currentTrack = -1; @@ -107,14 +106,6 @@ MusicPlayer::MusicPlayer(QObject *parent, const QString &dev) MusicPlayer::~MusicPlayer() { - if (m_cdWatcher) - { - m_cdWatcher->stop(); - m_cdWatcher->wait(); - delete m_cdWatcher; - m_cdWatcher = NULL; - } - if (!hasClient()) savePosition(); @@ -236,15 +227,6 @@ void MusicPlayer::loadSettings(void ) m_lastplayDelay = gCoreContext->GetNumSetting("MusicLastPlayDelay", LASTPLAY_DELAY); m_autoShowPlayer = (gCoreContext->GetNumSetting("MusicAutoShowPlayer", 1) > 0); - - // Do we check the CD? - bool checkCD = gCoreContext->GetNumSetting("AutoLookupCD"); - if (checkCD) - { - m_cdWatcher = new CDWatcherThread(m_CDdevice); - // don't start the cd watcher here - // since the playlists haven't been loaded yet - } } // this stops playing the playlist and plays the file pointed to by mdata @@ -297,12 +279,6 @@ void MusicPlayer::stop(bool stopAll) m_output = NULL; } - if (stopAll && m_cdWatcher) - { - m_cdWatcher->stop(); - m_cdWatcher->wait(); - } - // because we don't actually stop the audio output we have to fake a Stopped // event so any listeners can act on it OutputEvent oe(OutputEvent::Stopped); @@ -903,10 +879,6 @@ void MusicPlayer::loadPlaylist(void) } m_currentMetadata = NULL; - - // now we have the playlist loaded we can start the cd watcher - if (m_cdWatcher) - m_cdWatcher->start(); } void MusicPlayer::loadStreamPlaylist(void) @@ -1394,7 +1366,7 @@ void MusicPlayer::decoderHandlerReady(void) #ifdef HAVE_CDIO CdDecoder *cddecoder = dynamic_cast(getDecoder()); if (cddecoder) - cddecoder->setDevice(m_CDdevice); + cddecoder->setDevice(gCDdevice); #endif getDecoder()->setOutput(m_output); @@ -1473,111 +1445,3 @@ StreamList *MusicPlayer::getStreamList(void) { return gMusicData->all_streams->getStreams(); } - -/////////////////////////////////////////////////////////////////////////////// - -CDWatcherThread::CDWatcherThread(const QString &dev) -{ - m_cdDevice = dev; - m_cdStatusChanged = false; - m_stopped = false; -} - -void CDWatcherThread::run() -{ -#ifdef HAVE_CDIO - while (!m_stopped) - { - // lock all_music and cd_status_changed while running thread - QMutexLocker locker(getLock()); - - m_cdStatusChanged = false; - - CdDecoder *decoder = new CdDecoder("cda", NULL, NULL); - decoder->setDevice(m_cdDevice); - int numTracks = decoder->getNumCDAudioTracks(); - bool redo = false; - - if (numTracks != gMusicData->all_music->getCDTrackCount()) - { - m_cdStatusChanged = true; - LOG(VB_GENERAL, LOG_NOTICE, QString("CD status has changed.")); - } - - if (numTracks == 0) - { - // No CD, or no recognizable CD - gMusicData->all_music->clearCDData(); - gMusicData->all_playlists->clearCDList(); - } - else if (numTracks > 0) - { - // Check the last track to see if it's changed - MusicMetadata *checker = decoder->getLastMetadata(); - if (checker) - { - if (!gMusicData->all_music->checkCDTrack(checker)) - { - redo = true; - m_cdStatusChanged = true; - gMusicData->all_music->clearCDData(); - gMusicData->all_playlists->clearCDList(); - } - else - m_cdStatusChanged = false; - delete checker; - } - else - { - LOG(VB_GENERAL, LOG_ERR, "The cddecoder said it had audio tracks, " - "but it won't tell me about them"); - } - } - - int tracks = decoder->getNumTracks(); - bool setTitle = false; - - for (int actual_tracknum = 1; - redo && actual_tracknum <= tracks; actual_tracknum++) - { - MusicMetadata *track = decoder->getMetadata(actual_tracknum); - if (track) - { - gMusicData->all_music->addCDTrack(*track); - - if (!setTitle) - { - - QString parenttitle = " "; - if (track->FormatArtist().length() > 0) - { - parenttitle += track->FormatArtist(); - parenttitle += " ~ "; - } - - if (track->Album().length() > 0) - parenttitle += track->Album(); - else - { - parenttitle = " " + QObject::tr("Unknown"); - LOG(VB_GENERAL, LOG_INFO, "Couldn't find your " - " CD. It may not be in the freedb database.\n" - " More likely, however, is that you need to delete\n" - " ~/.cddb and ~/.cdserverrc and restart MythMusic."); - } - gMusicData->all_music->setCDTitle(parenttitle); - setTitle = true; - } - delete track; - } - } - - delete decoder; - - if (m_cdStatusChanged) - gPlayer->sendCDChangedEvent(); - - usleep(1000000); - } -#endif // HAVE_CDIO -} diff --git a/mythplugins/mythmusic/mythmusic/musicplayer.h b/mythplugins/mythmusic/mythmusic/musicplayer.h index 872cccb4fe1..b764f5d319c 100644 --- a/mythplugins/mythmusic/mythmusic/musicplayer.h +++ b/mythplugins/mythmusic/mythmusic/musicplayer.h @@ -15,7 +15,6 @@ class AudioOutput; class MainVisual; class Playlist; -class CDWatcherThread; class MusicPlayerEvent : public MythEvent { @@ -53,7 +52,7 @@ class MusicPlayer : public QObject, public MythObservable Q_OBJECT public: - MusicPlayer(QObject *parent, const QString &dev); + MusicPlayer(QObject *parent); ~MusicPlayer(void); enum PlayMode @@ -73,8 +72,6 @@ class MusicPlayer : public QObject, public MythObservable void addVisual(MainVisual *visual); void removeVisual(MainVisual *visual); - void setCDDevice(const QString &dev) { m_CDdevice = dev; } - void toggleMute(void); MuteState getMuteState(void) const; bool isMuted(void) const { return getMuteState() == kMuteAll; } @@ -209,8 +206,6 @@ class MusicPlayer : public QObject, public MythObservable QSet m_visualisers; - QString m_CDdevice; - PlayMode m_playMode; bool m_isPlaying; bool m_isAutoplay; @@ -228,9 +223,6 @@ class MusicPlayer : public QObject, public MythObservable float m_playSpeed; - // cd stuff - CDWatcherThread *m_cdWatcher; - // radio stuff QList m_playedList; int m_lastTrackStart; @@ -244,25 +236,7 @@ Q_DECLARE_METATYPE(MusicPlayer::ShuffleMode); // This global variable contains the MusicPlayer instance for the application extern MPUBLIC MusicPlayer *gPlayer; - -/////////////////////////////////////////////////////////////////////////////// - -class CDWatcherThread : public QThread -{ - public: - - CDWatcherThread(const QString &dev); - virtual void run(void); - bool statusChanged(void) { return m_cdStatusChanged; } - QMutex *getLock(void) { return &m_musicLock; } - void stop(void) { m_stopped = true; } - - private: - - bool m_stopped; - QString m_cdDevice; - bool m_cdStatusChanged; - QMutex m_musicLock; -}; + // This stores the last MythMediaDevice that was detected: +extern MPUBLIC QString gCDdevice; #endif