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  auto *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  if (process == nullptr)
90  {
91  delete control;
92  return GENERIC_EXIT_NOT_OK;
93  }
94 
95  QObject::connect(process, &MythExternRecApp::Opened,
96  control, &MythExternControl::Opened);
97  QObject::connect(process, &MythExternRecApp::Done,
98  control, &MythExternControl::Done);
99  QObject::connect(process, &MythExternRecApp::SetDescription,
101  QObject::connect(process, &MythExternRecApp::SendMessage,
103  QObject::connect(process, &MythExternRecApp::ErrorMessage,
105  QObject::connect(process, &MythExternRecApp::Streaming,
106  control, &MythExternControl::Streaming);
107  QObject::connect(process, &MythExternRecApp::Fill,
108  control, &MythExternControl::Fill);
109 
110  QObject::connect(control, &MythExternControl::Close,
111  process, &MythExternRecApp::Close);
112  QObject::connect(control, &MythExternControl::StartStreaming,
114  QObject::connect(control, &MythExternControl::StopStreaming,
116  QObject::connect(control, &MythExternControl::LockTimeout,
118  QObject::connect(control, &MythExternControl::HasTuner,
119  process, &MythExternRecApp::HasTuner);
120  QObject::connect(control, &MythExternControl::Cleanup,
121  process, &MythExternRecApp::Cleanup);
122  QObject::connect(control, &MythExternControl::DataStarted,
124  QObject::connect(control, &MythExternControl::LoadChannels,
126  QObject::connect(control, &MythExternControl::FirstChannel,
128  QObject::connect(control, &MythExternControl::NextChannel,
130  QObject::connect(control, &MythExternControl::TuneChannel,
132  QObject::connect(control, &MythExternControl::TuneStatus,
133  process, &MythExternRecApp::TuneStatus);
134  QObject::connect(control, &MythExternControl::HasPictureAttributes,
136  QObject::connect(control, &MythExternControl::SetBlockSize,
138 
139  process->Run();
140 
141  delete process;
142  delete control;
143  logStop();
144 
145  LOG(VB_GENERAL, LOG_WARNING, "Finished.");
146 
147  return GENERIC_EXIT_OK;
148 }
MythExternRecApp::SetDescription
void SetDescription(const QString &desc)
commandlineparser.h
MythExternControl::HasTuner
void HasTuner(const QString &serial) const
MythExternRecApp::HasTuner
void HasTuner(const QString &serial)
Definition: MythExternRecApp.cpp:663
MythExternControl::Cleanup
void Cleanup(void)
GENERIC_EXIT_OK
#define GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:10
MythExternControl::Fill
void Fill(const QByteArray &buffer)
Definition: MythExternControl.h:166
MythExternRecApp::StopStreaming
void StopStreaming(const QString &serial, bool silent)
Definition: MythExternRecApp.cpp:735
MythExternRecApp::Streaming
void Streaming(bool val)
MythExternControl::FirstChannel
void FirstChannel(const QString &serial)
MythExternRecApp::Run
void Run(void)
Definition: MythExternRecApp.cpp:235
MythExternRecApp::Done
void Done(void)
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythExternRecApp::SetBlockSize
void SetBlockSize(const QString &serial, int blksz)
Definition: MythExternRecApp.cpp:675
GENERIC_EXIT_INVALID_CMDLINE
#define GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:15
MythExternRecApp::HasPictureAttributes
void HasPictureAttributes(const QString &serial)
Definition: MythExternRecApp.cpp:670
MythExternRecApp::TuneStatus
void TuneStatus(const QString &serial)
Definition: MythExternRecApp.cpp:609
MythExternRecApp::TuneChannel
void TuneChannel(const QString &serial, const QString &channum)
Definition: MythExternRecApp.cpp:496
MythExternRecApp::LockTimeout
void LockTimeout(const QString &serial)
Definition: MythExternRecApp.cpp:639
mythversion.h
MythExternControl.h
MythExternRecApp::Close
void Close(void)
Definition: MythExternRecApp.cpp:209
MythExternControl::Opened
void Opened(void)
Definition: MythExternControl.cpp:55
MythCommandLineParser::Parse
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
Definition: mythcommandlineparser.cpp:1441
MythExternRecApp::Opened
void Opened(void)
MythExternRecApp.h
MythExternRecApp::LoadChannels
void LoadChannels(const QString &serial)
Definition: MythExternRecApp.cpp:337
MythExternControl::Streaming
void Streaming(bool val)
Definition: MythExternControl.cpp:63
mythlogging.h
main
int main(int argc, char *argv[])
Definition: mythtv/programs/mythexternrecorder/main.cpp:37
MythExternControl::TuneChannel
void TuneChannel(const QString &serial, const QString &channum)
MythExternRecApp::Cleanup
void Cleanup(void)
Definition: MythExternRecApp.cpp:268
logfile
QString logfile
Definition: backendcontext.cpp:14
MythExternRecApp
Definition: MythExternRecApp.h:33
MythExternControl::HasPictureAttributes
void HasPictureAttributes(const QString &serial) const
MythCommandLineParser::PrintVersion
static void PrintVersion(void)
Print application version information.
Definition: mythcommandlineparser.cpp:1268
filename
QString filename
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:634
MythExternRecApp::ErrorMessage
void ErrorMessage(const QString &msg)
MythCommandLineParser::PrintHelp
void PrintHelp(void) const
Print command line option help.
Definition: mythcommandlineparser.cpp:1284
MythExternControl::StopStreaming
void StopStreaming(const QString &serial, bool silent)
MythExternRecApp::NextChannel
void NextChannel(const QString &serial)
Definition: MythExternRecApp.cpp:458
logStop
void logStop(void)
Entry point for stopping logging for an application.
Definition: logging.cpp:755
MythExternControl::TuneStatus
void TuneStatus(const QString &serial)
MythExternControl
Definition: MythExternControl.h:121
MythExternControl::NextChannel
void NextChannel(const QString &serial)
cmdline
MythCommFlagCommandLineParser cmdline
Definition: mythtv/programs/mythcommflag/main.cpp:77
MythExternRecorderCommandLineParser
Definition: mythexternrecorder/commandlineparser.h:7
MythExternControl::SendMessage
void SendMessage(const QString &cmd, const QString &serial, const QString &msg)
Definition: MythExternControl.cpp:112
MythExternRecApp::FirstChannel
void FirstChannel(const QString &serial)
Definition: MythExternRecApp.cpp:452
MythExternControl::DataStarted
void DataStarted(void)
MythExternControl::StartStreaming
void StartStreaming(const QString &serial)
MythCommandLineParser::toString
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
Definition: mythcommandlineparser.cpp:2100
GENERIC_EXIT_NOT_OK
#define GENERIC_EXIT_NOT_OK
Exited with error.
Definition: exitcodes.h:11
MythExternControl::LockTimeout
void LockTimeout(const QString &serial) const
MythCommandLineParser::toBool
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
Definition: mythcommandlineparser.cpp:1955
MythExternControl::Close
void Close(void)
MythExternRecApp::SendMessage
void SendMessage(const QString &func, const QString &serial, const QString &msg)
MythExternRecApp::DataStarted
void DataStarted(void)
Definition: MythExternRecApp.cpp:302
MythExternControl::Done
void Done(void)
Definition: MythExternControl.cpp:74
MythExternControl::LoadChannels
void LoadChannels(const QString &serial)
mythcontext.h
MythExternControl::SetBlockSize
void SetBlockSize(const QString &serial, int blksz)
MythExternControl::SetDescription
void SetDescription(const QString &desc)
Definition: MythExternControl.h:159
MythCommandLineParser::GetLogFilePath
QString GetLogFilePath(void)
Helper utility for logging interface to pull path from –logpath.
Definition: mythcommandlineparser.cpp:2497
MythCommandLineParser::ConfigureLogging
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
Definition: mythcommandlineparser.cpp:2583
logPropagateArgs
QString logPropagateArgs
Definition: logging.cpp:89
MythExternRecApp::StartStreaming
void StartStreaming(const QString &serial)
Definition: MythExternRecApp.cpp:681
exitcodes.h
MythExternControl::ErrorMessage
void ErrorMessage(const QString &msg)
Definition: MythExternControl.cpp:120
MythExternRecApp::Fill
void Fill(const QByteArray &buffer)