Skip to content
Permalink
Browse files

mythexternrecorder: Allow process environment to be configured.

  • Loading branch information...
jpoet committed May 25, 2019
1 parent 05d9dc2 commit c51c7d7bebc57fd184b050532f78cfb965372767
@@ -19,6 +19,7 @@
*/

#include <thread>
#include <csignal>
#include "commandlineparser.h"
#include "MythExternRecApp.h"

@@ -101,11 +102,24 @@ bool MythExternRecApp::config(void)
m_scan_command = settings.value("SCANNER/command", "").toString();
m_scan_timeout = settings.value("SCANNER/timeout", "").toInt();

settings.beginGroup("ENVIRONMENT");

m_app_env.clear();
QStringList keys = settings.childKeys();
QStringList::const_iterator Ienv;
for (Ienv = keys.constBegin(); Ienv != keys.constEnd(); ++Ienv)
{
if (!(*Ienv).isEmpty() && (*Ienv)[0] != '#')
m_app_env.insert((*Ienv).toLocal8Bit().constData(),
settings.value(*Ienv).toString());
}

if (!m_channels_ini.isEmpty())
{
if (!QFileInfo::exists(m_channels_ini))
{
// Assume the channels config is in the same directory as main config
// Assume the channels config is in the same directory as
// main config
QDir conf_path = QFileInfo(m_config_ini).absolutePath();
QFileInfo ini(conf_path, m_channels_ini);
m_channels_ini = ini.absoluteFilePath();
@@ -130,6 +144,20 @@ bool MythExternRecApp::Open(void)
return false;
}

if (!m_app_env.isEmpty())
{
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
QMap<QString, QString>::const_iterator Ienv;
for (Ienv = m_app_env.constBegin();
Ienv != m_app_env.constEnd(); ++Ienv)
{
env.insert(Ienv.key(), Ienv.value());
LOG(VB_RECORD, LOG_INFO, LOC + QString(" ENV: '%1' = '%2'")
.arg(Ienv.key()).arg(Ienv.value()));
}
m_proc.setProcessEnvironment(env);
}

QObject::connect(&m_proc, &QProcess::started, this,
&MythExternRecApp::ProcStarted);
#if 0
@@ -162,6 +190,31 @@ bool MythExternRecApp::Open(void)
return true;
}

void MythExternRecApp::TerminateProcess(void)
{
if (m_proc.state() == QProcess::Running)
{
LOG(VB_RECORD, LOG_INFO, LOC +
QString("Sending SIGINT to %1").arg(m_proc.pid()));
kill(m_proc.pid(), SIGINT);
m_proc.waitForFinished(5000);
}
if (m_proc.state() == QProcess::Running)
{
LOG(VB_RECORD, LOG_INFO, LOC +
QString("Sending SIGTERM to %1").arg(m_proc.pid()));
m_proc.terminate();
m_proc.waitForFinished();
}
if (m_proc.state() == QProcess::Running)
{
LOG(VB_RECORD, LOG_INFO, LOC +
QString("Sending SIGKILL to %1").arg(m_proc.pid()));
m_proc.kill();
m_proc.waitForFinished();
}
}

Q_SLOT void MythExternRecApp::Close(void)
{
if (m_run)
@@ -175,10 +228,7 @@ Q_SLOT void MythExternRecApp::Close(void)
if (m_proc.state() == QProcess::Running)
{
m_proc.closeReadChannel(QProcess::StandardOutput);
m_proc.terminate();
m_proc.waitForFinished();
m_proc.kill();
m_proc.waitForFinished();
TerminateProcess();
std::this_thread::sleep_for(std::chrono::microseconds(50));
}

@@ -212,10 +262,7 @@ void MythExternRecApp::Run(void)
if (m_proc.state() == QProcess::Running)
{
m_proc.closeReadChannel(QProcess::StandardOutput);
m_proc.terminate();
m_proc.waitForFinished();
m_proc.kill();
m_proc.waitForFinished();
TerminateProcess();
}

emit Done();
@@ -516,9 +563,7 @@ Q_SLOT void MythExternRecApp::StopStreaming(const QString & serial, bool silent)
m_streaming = false;
if (m_proc.state() == QProcess::Running)
{
m_proc.terminate();
m_proc.waitForFinished(3000);
m_proc.kill();
TerminateProcess();

LOG(VB_RECORD, LOG_INFO, LOC + ": External application terminated.");
if (silent)
@@ -79,6 +79,7 @@ class MythExternRecApp : public QObject

protected:
void GetChannel(const QString & serial, const QString & func);
void TerminateProcess(void);

private:
bool config(void);
@@ -100,6 +101,8 @@ class MythExternRecApp : public QObject
QString m_rec_command;
QString m_rec_desc;

QMap<QString, QString> m_app_env;

QString m_tune_command;
QString m_channels_ini;
uint m_lock_timeout;
@@ -0,0 +1,43 @@
[RECORDER]
# The recorder command to execute. %URL% is optional, and
# will be replaced with the channel's "URL" as defined in the
# [TUNER/channels] (channel conf) configuration file
#
# %LOGGING% will be replaced with mythtv logging params. For example:
# --verbose general,channel,record --logpath /var/log/mythtv --loglevel info --quiet

command="decklinkvideosrc device-number=0 mode=0 output-stream-time=True skip-first-time=500 output-cc=true video-format=2 ! queue max-size-buffers=1024 max-size-bytes=0 max-size-time=0 ! autovideoconvert ! queue max-size-buffers=1024 max-size-bytes=0 max-size-time=0 ! avenc_mpeg2video bitrate=9000000 ! mpegvideoparse ! queue max-size-buffers=1024 max-size-bytes=0 max-size-time=0 ! mpegtsmux name=mux ! queue max-size-buffers=1024 max-size-bytes=0 max-size-time=0 ! filesink location=/dev/stdout decklinkaudiosrc device-number=0 channels=2 name=audio ! queue max-size-buffers=1024 max-size-bytes=0 max-size-time=0 ! audioconvert ! queue max-size-buffers=1024 max-size-bytes=0 max-size-time=0 ! avenc_ac3 bitrate=480000 ! ac3parse ! queue max-size-buffers=1024 max-size-bytes=0 max-size-time=0 ! mux."

# Used in logging events, %ARG% are replaced from the channel info
#desc=GST \"%URL%\" \"%CHANNUM%\" \"%CHANNAME%\" \"%CALLSIGN%\"
desc="GST SDI0"


[ENVIRONMENT]
GST_DEBUG="*:FIXME,mythtvsink:INFO,gstmyth:INFO,decklinkvideosrc:INFO,decklinkaudiosrc:WARNING"
GST_DEBUG_FILE="/var/log/mythtv/gst-decklink-01.log"


[TUNER]
# An optional CONF file which provides channel details. If it does not
# exist, then channel changes are not supported.
#channels=

# If [TUNER/command] is provided, it will be executed to "tune" the
# channel. A %URL% parameter will be substituted with the "URL" as
# defined in the [TUNER/channels] configuration file
#command=

# Timeout for changing channels in msecs
#timeout=


[SCANNER]
# When MythTV scans for channels, The contents of the [TUNER/channels]
# config file are used to populate MythTV's channel information.
# If a command is provided here, it will be executed first, so it can
# populate the [TUNER/channels] config file
#command=/home/mythtv/bin/scan.sh "%CHANCONF%"

# Timeout for scan command in msecs
#timeout=60000
@@ -12,10 +12,12 @@ INSTALLS = target

QMAKE_CLEAN += $(TARGET)

config.path = $${PREFIX}/share/mythtv/
config.files += ffmpeg-channels.conf ffmpeg.conf
config.files += twitch-channels.conf twitch.conf
config.files += vlc-channels.conf vlc.conf
config.path = $${PREFIX}/share/mythtv/externrecorder
config.files += config/*.conf

#config.files += config/ffmpeg-channels.conf config/ffmpeg.conf
#config.files += config/twitch-channels.conf config/twitch.conf
#config.files += config/vlc-channels.conf config/vlc.conf

INSTALLS += config

0 comments on commit c51c7d7

Please sign in to comment.
You can’t perform that action at this time.