Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support playing Audio CD from optical disc menu #835

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
10 changes: 5 additions & 5 deletions mythplugins/mythmusic/mythmusic/mythmusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ static QStringList BuildFileList(const QString &dir, const QStringList &filters)
return ret;
}

static void handleMedia(MythMediaDevice *cd)
static void handleMedia(MythMediaDevice *cd, bool forcePlayback)
{
static QString s_mountPath;

Expand Down Expand Up @@ -522,7 +522,7 @@ static void handleMedia(MythMediaDevice *cd)
s_mountPath.clear();

// don't show the music screen if AutoPlayCD is off
if (!gCoreContext->GetBoolSetting("AutoPlayCD", false))
if (!forcePlayback && !gCoreContext->GetBoolSetting("AutoPlayCD", false))
return;

if (!gMusicData->m_initialized)
Expand Down Expand Up @@ -627,7 +627,7 @@ static void handleMedia(MythMediaDevice *cd)
}

#ifdef HAVE_CDIO
static void handleCDMedia(MythMediaDevice *cd)
static void handleCDMedia(MythMediaDevice *cd, bool forcePlayback)
{

if (!cd)
Expand Down Expand Up @@ -739,7 +739,7 @@ static void handleCDMedia(MythMediaDevice *cd)

// if the AutoPlayCD setting is set we remove all the existing tracks
// from the playlist and replace them with the new CD tracks found
if (gCoreContext->GetBoolSetting("AutoPlayCD", false))
if (forcePlayback || gCoreContext->GetBoolSetting("AutoPlayCD", false))
{
gMusicData->m_all_playlists->getActive()->removeAllTracks();

Expand Down Expand Up @@ -776,7 +776,7 @@ static void handleCDMedia(MythMediaDevice *cd)
}
}
#else
static void handleCDMedia([[maybe_unused]] MythMediaDevice *cd)
static void handleCDMedia([[maybe_unused]] MythMediaDevice *cd, [[maybe_unused]] bool forcePlayback)
{
LOG(VB_GENERAL, LOG_NOTICE, "MythMusic got a media changed event"
"but cdio support is not compiled in");
Expand Down
11 changes: 5 additions & 6 deletions mythtv/libs/libmyth/mythmediamonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,14 +631,13 @@ QList<MythMediaDevice*> MediaMonitor::GetMedias(unsigned mediatypes)
* \param description Unused.
* \param callback The function to call when an event occurs.
* \param mediaType The type of media supported by this callback. The
* value must be an enum of type MythMediaType.
* value must be a bitmask of enums of type MythMediaType.
* \param extensions A list of file name extensions supported by this
* callback.
*/
void MediaMonitor::RegisterMediaHandler(const QString &destination,
const QString &description,
void (*callback)
(MythMediaDevice*),
MediaCallback callback,
int mediaType,
const QString &extensions)
{
Expand Down Expand Up @@ -673,7 +672,7 @@ void MediaMonitor::RegisterMediaHandler(const QString &destination,
* to allow the user to select which one to use,
* but for now, we're going to just use the first one.
*/
void MediaMonitor::JumpToMediaHandler(MythMediaDevice* pMedia)
void MediaMonitor::JumpToMediaHandler(MythMediaDevice* pMedia, bool forcePlayback)
{
QVector<MHData> handlers;
QMap<QString, MHData>::Iterator itr = m_handlerMap.begin();
Expand Down Expand Up @@ -701,7 +700,7 @@ void MediaMonitor::JumpToMediaHandler(MythMediaDevice* pMedia)
// if user didn't cancel, selected = handlers.at(choice);
int selected = 0;

handlers.at(selected).callback(pMedia);
handlers.at(selected).callback(pMedia, forcePlayback);
}

/**
Expand Down Expand Up @@ -815,7 +814,7 @@ bool MediaMonitor::eventFilter(QObject *obj, QEvent *event)
{
if ((*itr).MythMediaType & (int)pDev->getMediaType() ||
pDev->getStatus() == MEDIASTAT_OPEN)
(*itr).callback(pDev);
(*itr).callback(pDev, false);
itr++;
}
}
Expand Down
10 changes: 6 additions & 4 deletions mythtv/libs/libmyth/mythmediamonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
#include "libmythbase/mthread.h"
#include "libmythbase/mythmedia.h"

typedef void (*MediaCallback)(MythMediaDevice *mediadevice, bool forcePlayback);

/// Stores details of media handlers

// Adding member initializers caused compilation to fail with an error
// that it cannot convert a brace-enclosed initializer list to MHData.
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
struct MHData
{
void (*callback)(MythMediaDevice *mediadevice);
MediaCallback callback;
int MythMediaType;
QString destination;
QString description;
Expand Down Expand Up @@ -74,10 +76,10 @@ class MPUBLIC MediaMonitor : public QObject

void RegisterMediaHandler(const QString &destination,
const QString &description,
void (*callback) (MythMediaDevice*),
MediaCallback callback,
int mediaType,
const QString &extensions);
void JumpToMediaHandler(MythMediaDevice* pMedia);
void JumpToMediaHandler(MythMediaDevice* pMedia, bool forcePlayback = false);

// Plugins should use these if they need to access optical disks:
static QString defaultCDdevice();
Expand Down Expand Up @@ -137,7 +139,7 @@ class MPUBLIC MediaMonitor : public QObject
static inline void
REG_MEDIA_HANDLER (const QString& destination,
const QString& description,
void (*callback)(MythMediaDevice*),
MediaCallback callback,
int mediaType,
const QString& extensions)
{
Expand Down
56 changes: 39 additions & 17 deletions mythtv/programs/mythfrontend/mythfrontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,21 +780,12 @@ static void RunGallery()

static void playDisc()
{
//
// Get the command string to play a DVD
//

bool isBD = false;

QString command_string =
gCoreContext->GetSetting("mythdvd.DVDPlayerCommand");
// Check for Bluray
LOG(VB_MEDIA, LOG_DEBUG, "Checking for BluRay medium");
QString bluray_mountpoint =
gCoreContext->GetSetting("BluRayMountpoint", "/media/cdrom");
QDir bdtest(bluray_mountpoint + "/BDMV");

if (bdtest.exists() || MythCDROM::inspectImage(bluray_mountpoint) == MythCDROM::kBluray)
isBD = true;

const bool isBD = (bdtest.exists() || MythCDROM::inspectImage(bluray_mountpoint) == MythCDROM::kBluray);
if (isBD)
{
GetMythUI()->AddCurrentLocation("playdisc");
Expand All @@ -805,8 +796,19 @@ static void playDisc()
0, 0, "", 0min, "", "", true);

GetMythUI()->RemoveCurrentLocation();
return;
}
else

MediaMonitor *mediaMonitor = MediaMonitor::GetMediaMonitor();
if (!mediaMonitor)
{
LOG(VB_MEDIA, LOG_ERR, "Could not access media monitor");
return;
}

// Check for DVD
LOG(VB_MEDIA, LOG_DEBUG, "Checking for DVD medium");
if (!mediaMonitor->GetMedias(MEDIATYPE_DVD).isEmpty())
{
QString dvd_device = MediaMonitor::defaultDVDdevice();

Expand All @@ -815,6 +817,9 @@ static void playDisc()

GetMythUI()->AddCurrentLocation("playdisc");

// Get the command string to play a DVD
QString command_string =
gCoreContext->GetSetting("mythdvd.DVDPlayerCommand");
if ((command_string.indexOf("internal", 0, Qt::CaseInsensitive) > -1) ||
(command_string.length() < 1))
{
Expand All @@ -830,7 +835,7 @@ static void playDisc()

command_string = "Internal";
GetMythMainWindow()->HandleMedia(command_string, filename, "", "",
"", "", 0, 0, "", 0min, "", "", true);
"", "", 0, 0, "", 0min, "", "", true);
GetMythUI()->RemoveCurrentLocation();

return;
Expand All @@ -854,13 +859,30 @@ static void playDisc()
GetMythMainWindow()->activateWindow();
}
GetMythUI()->RemoveCurrentLocation();
return;
}

// Check for Audio CD
LOG(VB_MEDIA, LOG_DEBUG, "Checking for audio CD medium");
auto audioMedia = mediaMonitor->GetMedias(MEDIATYPE_AUDIO | MEDIATYPE_MIXED);
if (!audioMedia.isEmpty())
{
for (auto *medium : qAsConst(audioMedia))
{
if (medium->isUsable()) {
LOG(VB_MEDIA, LOG_DEBUG, QString("Found usable audio/mixed device %1").arg(medium->getDevicePath()));
mediaMonitor->JumpToMediaHandler(medium, true);
return;
}
}
}

}

/////////////////////////////////////////////////
//// Media handlers
/////////////////////////////////////////////////
static void handleDVDMedia(MythMediaDevice *dvd)
static void handleDVDMedia(MythMediaDevice *dvd, bool /*forcePlayback*/)
{
if (!dvd)
return;
Expand All @@ -882,7 +904,7 @@ static void handleDVDMedia(MythMediaDevice *dvd)
}
}

static void handleGalleryMedia(MythMediaDevice *dev)
static void handleGalleryMedia(MythMediaDevice *dev, bool forcePlayback)
{
// Only handle events for media that are newly mounted
if (!dev || (dev->getStatus() != MEDIASTAT_MOUNTED
Expand All @@ -904,7 +926,7 @@ static void handleGalleryMedia(MythMediaDevice *dev)
}
}

if (gCoreContext->GetBoolSetting("GalleryAutoLoad", false))
if (forcePlayback || gCoreContext->GetBoolSetting("GalleryAutoLoad", false))
{
LOG(VB_GUI, LOG_INFO, "Main: Autostarting Gallery for new media");
GetMythMainWindow()->JumpTo(JUMP_GALLERY_DEFAULT);
Expand Down