Skip to content

Commit

Permalink
MythMusic: rip out the CDWatcherThread
Browse files Browse the repository at this point in the history
We will use the media monitor instead now it seems to be more stable.
  • Loading branch information
Paul Harrison committed May 26, 2013
1 parent b4a344b commit 1610dc3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 187 deletions.
6 changes: 1 addition & 5 deletions mythplugins/mythmusic/mythmusic/main.cpp
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 0 additions & 14 deletions mythplugins/mythmusic/mythmusic/musiccommon.cpp
Expand Up @@ -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())
Expand Down Expand Up @@ -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;
Expand Down
142 changes: 3 additions & 139 deletions mythplugins/mythmusic/mythmusic/musicplayer.cpp
Expand Up @@ -34,6 +34,7 @@
#define LASTPLAY_DELAY 15

MusicPlayer *gPlayer = NULL;
QString gCDdevice = "";

////////////////////////////////////////////////////////////////

Expand All @@ -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;

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1394,7 +1366,7 @@ void MusicPlayer::decoderHandlerReady(void)
#ifdef HAVE_CDIO
CdDecoder *cddecoder = dynamic_cast<CdDecoder*>(getDecoder());
if (cddecoder)
cddecoder->setDevice(m_CDdevice);
cddecoder->setDevice(gCDdevice);
#endif

getDecoder()->setOutput(m_output);
Expand Down Expand Up @@ -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
}
32 changes: 3 additions & 29 deletions mythplugins/mythmusic/mythmusic/musicplayer.h
Expand Up @@ -15,7 +15,6 @@
class AudioOutput;
class MainVisual;
class Playlist;
class CDWatcherThread;

class MusicPlayerEvent : public MythEvent
{
Expand Down Expand Up @@ -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
Expand All @@ -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; }
Expand Down Expand Up @@ -209,8 +206,6 @@ class MusicPlayer : public QObject, public MythObservable

QSet<QObject*> m_visualisers;

QString m_CDdevice;

PlayMode m_playMode;
bool m_isPlaying;
bool m_isAutoplay;
Expand All @@ -228,9 +223,6 @@ class MusicPlayer : public QObject, public MythObservable

float m_playSpeed;

// cd stuff
CDWatcherThread *m_cdWatcher;

// radio stuff
QList<MusicMetadata*> m_playedList;
int m_lastTrackStart;
Expand All @@ -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

0 comments on commit 1610dc3

Please sign in to comment.