MythTV  master
mythtv/programs/mythexternrecorder/main.cpp
Go to the documentation of this file.
1 /* -*- Mode: c++ -*-
2  *
3  * Copyright (C) John Poet 2018
4  *
5  * This file is part of MythTV
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "commandlineparser.h"
22 #include "MythExternRecApp.h"
23 #include "MythExternControl.h"
24 
25 #include "exitcodes.h"
26 #include "mythcontext.h"
27 #include "mythversion.h"
28 #include "mythlogging.h"
29 
30 #include <unistd.h>
31 
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 
35 #include <QCoreApplication>
36 
37 int main(int argc, char *argv[])
38 {
40 
41  if (!cmdline.Parse(argc, argv))
42  {
45  }
46 
47  if (cmdline.toBool("showhelp"))
48  {
50  return GENERIC_EXIT_OK;
51  }
52 
53  if (cmdline.toBool("showversion"))
54  {
56  return GENERIC_EXIT_OK;
57  }
58 
59  QCoreApplication app(argc, argv);
60  QCoreApplication::setApplicationName("mythexternrecorder");
61 
62  int retval = cmdline.ConfigureLogging();
63  if (retval != GENERIC_EXIT_OK)
64  return retval;
65  QString logfile = cmdline.GetLogFilePath();
66  QString logging = logPropagateArgs;
67 
68  MythExternControl *control = new MythExternControl();
69  MythExternRecApp *process = nullptr;
70 
71  QString conf_file = cmdline.toString("conf");
72  if (!conf_file.isEmpty())
73  {
74  process = new MythExternRecApp("", conf_file, logfile, logging);
75  }
76  else if (!cmdline.toString("exec").isEmpty())
77  {
78  QString command = cmdline.toString("exec");
79  process = new MythExternRecApp(command, "", logfile, logging);
80  }
81  else if (!cmdline.toString("infile").isEmpty())
82  {
83  QString filename = cmdline.toString("infile");
84  QString command = QString("ffmpeg -re -i \"%1\" "
85  "-c:v copy -c:a copy -f mpegts -")
86  .arg(filename);
87  process = new MythExternRecApp(command, "", logfile, logging);
88  }
89 
90  QObject::connect(process, &MythExternRecApp::Opened,
91  control, &MythExternControl::Opened);
92  QObject::connect(process, &MythExternRecApp::Done,
93  control, &MythExternControl::Done);
94  QObject::connect(process, &MythExternRecApp::SetDescription,
96  QObject::connect(process, &MythExternRecApp::SendMessage,
98  QObject::connect(process, &MythExternRecApp::ErrorMessage,
100  QObject::connect(process, &MythExternRecApp::Streaming,
101  control, &MythExternControl::Streaming);
102  QObject::connect(process, &MythExternRecApp::Fill,
103  control, &MythExternControl::Fill);
104 
105  QObject::connect(control, &MythExternControl::Close,
106  process, &MythExternRecApp::Close);
107  QObject::connect(control, &MythExternControl::StartStreaming,
109  QObject::connect(control, &MythExternControl::StopStreaming,
111  QObject::connect(control, &MythExternControl::LockTimeout,
113  QObject::connect(control, &MythExternControl::HasTuner,
114  process, &MythExternRecApp::HasTuner);
115  QObject::connect(control, &MythExternControl::LoadChannels,
117  QObject::connect(control, &MythExternControl::FirstChannel,
119  QObject::connect(control, &MythExternControl::NextChannel,
121  QObject::connect(control, &MythExternControl::TuneChannel,
123  QObject::connect(control, &MythExternControl::HasPictureAttributes,
125  QObject::connect(control, &MythExternControl::SetBlockSize,
127 
128  process->Run();
129 
130  delete process;
131  delete control;
132  logStop();
133 
134  LOG(VB_GENERAL, LOG_WARNING, "Finished.");
135 
136  return GENERIC_EXIT_OK;
137 }
QString logfile
int main(int argc, char *argv[])
void ErrorMessage(const QString &msg)
void NextChannel(const QString &serial)
void ErrorMessage(const QString &msg)
#define GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:10
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
static void PrintVersion(void)
Print application version information.
void FirstChannel(const QString &serial)
void TuneChannel(const QString &serial, const QString &channum)
void PrintHelp(void) const
Print command line option help.
QString logPropagateArgs
Definition: logging.cpp:89
void Fill(const QByteArray &buffer)
void SendMessage(const QString &func, const QString &serial, const QString &msg)
void StopStreaming(const QString &serial, bool silent)
void FirstChannel(const QString &serial)
void StartStreaming(const QString &serial)
void HasTuner(const QString &serial)
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
void Fill(const QByteArray &buffer)
void SetBlockSize(const QString &serial, int blksz)
void SetDescription(const QString &desc)
void StartStreaming(const QString &serial)
void Streaming(bool val)
void SetDescription(const QString &desc)
void Close(void)
MythCommFlagCommandLineParser cmdline
void StopStreaming(const QString &serial, bool silent)
void Streaming(bool val)
void HasPictureAttributes(const QString &serial) const
void Done(void)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void SetBlockSize(const QString &serial, int blksz)
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
void logStop(void)
Entry point for stopping logging for an application.
Definition: logging.cpp:740
void HasTuner(const QString &serial) const
void LockTimeout(const QString &serial)
void TuneChannel(const QString &serial, const QString &channum)
void HasPictureAttributes(const QString &serial)
void LoadChannels(const QString &serial)
void SendMessage(const QString &cmd, const QString &serial, const QString &msg)
void Opened(void)
#define GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:15
QString GetLogFilePath(void)
Helper utility for logging interface to pull path from –logpath.
void NextChannel(const QString &serial)
void LoadChannels(const QString &serial)
int ConfigureLogging(const QString &mask="general", unsigned int progress=0)
Read in logging options and initialize the logging interface.
void LockTimeout(const QString &serial) const