Skip to content

Commit

Permalink
mythexternrecorder: Fix "tuning" of channels by external recorder, in…
Browse files Browse the repository at this point in the history
…stead of separate "tuner".
  • Loading branch information
jpoet committed Jun 7, 2020
1 parent 5cf1846 commit d033071
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions mythtv/programs/mythexternrecorder/MythExternRecApp.cpp
Expand Up @@ -485,7 +485,7 @@ void MythExternRecApp::NewEpisodeStarting(const QString & channum)
Q_SLOT void MythExternRecApp::TuneChannel(const QString & serial,
const QString & channum)
{
if (m_tuneCommand.isEmpty())
if (m_tuneCommand.isEmpty() && m_channelsIni.isEmpty())
{
LOG(VB_CHANNEL, LOG_ERR, LOC + ": No 'tuner' configured.");
emit SendMessage("TuneChannel", serial, "ERR:No 'tuner' configured.");
Expand All @@ -507,7 +507,7 @@ Q_SLOT void MythExternRecApp::TuneChannel(const QString & serial,
m_desc = m_recDesc;
m_command = m_recCommand;

QString tune = m_tuneCommand;
QString tunecmd = m_tuneCommand;
QString url;

if (!m_channelsIni.isEmpty())
Expand All @@ -525,7 +525,7 @@ Q_SLOT void MythExternRecApp::TuneChannel(const QString & serial,
LOG(VB_CHANNEL, LOG_ERR, LOC + ": " + msg);
}
else
tune.replace("%URL%", url);
tunecmd.replace("%URL%", url);

if (!url.isEmpty() && m_command.indexOf("%URL%") >= 0)
{
Expand All @@ -544,18 +544,9 @@ Q_SLOT void MythExternRecApp::TuneChannel(const QString & serial,
if (m_tuneProc.state() == QProcess::Running)
TerminateProcess(m_tuneProc, "Tune");

tune.replace("%CHANNUM%", channum);
tunecmd.replace("%CHANNUM%", channum);
m_command.replace("%CHANNUM%", channum);

m_tuneProc.start(tune);
if (!m_tuneProc.waitForStarted())
{
QString errmsg = QString("Tune `%1` failed: ").arg(tune) + ENO;
LOG(VB_CHANNEL, LOG_ERR, LOC + ": " + errmsg);
emit SendMessage("TuneChannel", serial, QString("ERR:%1").arg(errmsg));
return;
}

if (!m_logFile.isEmpty() && m_command.indexOf("%LOGFILE%") >= 0)
{
m_command.replace("%LOGFILE%", m_logFile);
Expand All @@ -574,12 +565,32 @@ Q_SLOT void MythExternRecApp::TuneChannel(const QString & serial,

m_desc.replace("%URL%", url);
m_desc.replace("%CHANNUM%", channum);
m_tuningChannel = channum;

LOG(VB_CHANNEL, LOG_INFO, LOC + QString(": Started `%1` URL '%2'")
.arg(tune).arg(url));
emit SendMessage("TuneChannel", serial,
QString("OK:InProgress `%1`").arg(tune));
if (!m_tuneCommand.isEmpty())
{
m_tuningChannel = channum;
m_tuneProc.start(tunecmd);
if (!m_tuneProc.waitForStarted())
{
QString errmsg = QString("Tune `%1` failed: ").arg(tunecmd) + ENO;
LOG(VB_CHANNEL, LOG_ERR, LOC + ": " + errmsg);
emit SendMessage("TuneChannel", serial,
QString("ERR:%1").arg(errmsg));
return;
}

LOG(VB_CHANNEL, LOG_INFO, LOC + QString(": Started `%1` URL '%2'")
.arg(tunecmd).arg(url));
emit SendMessage("TuneChannel", serial,
QString("OK:InProgress `%1`").arg(tunecmd));
}
else
{
m_tunedChannel = channum;
emit SetDescription(Desc());
emit SendMessage("TuneChannel", serial,
QString("OK:Tuned to %1").arg(m_tunedChannel));
}
}

Q_SLOT void MythExternRecApp::TuneStatus(const QString & serial)
Expand All @@ -592,7 +603,8 @@ Q_SLOT void MythExternRecApp::TuneStatus(const QString & serial)
return;
}

if (m_tuneProc.exitStatus() != QProcess::NormalExit)
if (!m_tuneCommand.isEmpty() &&
m_tuneProc.exitStatus() != QProcess::NormalExit)
{
QString errmsg = QString("'%1' failed: ")
.arg(m_tuneProc.program()) + ENO;
Expand Down Expand Up @@ -638,7 +650,8 @@ Q_SLOT void MythExternRecApp::LockTimeout(const QString & serial)
Q_SLOT void MythExternRecApp::HasTuner(const QString & serial)
{
emit SendMessage("HasTuner", serial, QString("OK:%1")
.arg(m_tuneCommand.isEmpty() ? "No" : "Yes"));
.arg(m_tuneCommand.isEmpty() &&
m_channelsIni.isEmpty() ? "No" : "Yes"));
}

Q_SLOT void MythExternRecApp::HasPictureAttributes(const QString & serial)
Expand Down

0 comments on commit d033071

Please sign in to comment.