MythTV  master
mythexternrecorder.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 // C/C++
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <unistd.h>
25 
26 // Qt
27 #include <QCoreApplication>
28 
29 // MythTV
30 #include "libmyth/mythcontext.h"
31 #include "libmythbase/exitcodes.h"
33 #include "libmythbase/mythversion.h"
34 
35 // MythExternRecorder
36 #include "MythExternControl.h"
37 #include "MythExternRecApp.h"
39 
40 int main(int argc, char *argv[])
41 {
43 
44  if (!cmdline.Parse(argc, argv))
45  {
48  }
49 
50  if (cmdline.toBool("showhelp"))
51  {
53  return GENERIC_EXIT_OK;
54  }
55 
56  if (cmdline.toBool("showversion"))
57  {
59  return GENERIC_EXIT_OK;
60  }
61 
62  QCoreApplication app(argc, argv);
63  QCoreApplication::setApplicationName("mythexternrecorder");
64 
65  int retval = cmdline.ConfigureLogging();
66  if (retval != GENERIC_EXIT_OK)
67  return retval;
68  QString logfile = cmdline.GetLogFilePath();
69  QString logging = logPropagateArgs;
70 
71  auto *control = new MythExternControl();
72  MythExternRecApp *process = nullptr;
73 
74  QString conf_file = cmdline.toString("conf");
75  if (!conf_file.isEmpty())
76  {
77  process = new MythExternRecApp("", conf_file, logfile, logging);
78  }
79  else if (!cmdline.toString("exec").isEmpty())
80  {
81  QString command = cmdline.toString("exec");
82  process = new MythExternRecApp(command, "", logfile, logging);
83  }
84  else if (!cmdline.toString("infile").isEmpty())
85  {
86  QString filename = cmdline.toString("infile");
87  QString command = QString("ffmpeg -re -i \"%1\" "
88  "-c:v copy -c:a copy -f mpegts -")
89  .arg(filename);
90  process = new MythExternRecApp(command, "", logfile, logging);
91  }
92  if (process == nullptr)
93  {
94  delete control;
95  return GENERIC_EXIT_NOT_OK;
96  }
97 
98  QObject::connect(process, &MythExternRecApp::Opened,
99  control, &MythExternControl::Opened);
100  QObject::connect(process, &MythExternRecApp::Done,
101  control, &MythExternControl::Done);
102  QObject::connect(process, &MythExternRecApp::SetDescription,
104  QObject::connect(process, &MythExternRecApp::SendMessage,
106  QObject::connect(process, &MythExternRecApp::ErrorMessage,
108  QObject::connect(process, &MythExternRecApp::Streaming,
109  control, &MythExternControl::Streaming);
110  QObject::connect(process, &MythExternRecApp::Fill,
111  control, &MythExternControl::Fill);
112 
113  QObject::connect(control, &MythExternControl::Close,
114  process, &MythExternRecApp::Close);
115  QObject::connect(control, &MythExternControl::StartStreaming,
117  QObject::connect(control, &MythExternControl::StopStreaming,
119  QObject::connect(control, &MythExternControl::LockTimeout,
121  QObject::connect(control, &MythExternControl::HasTuner,
122  process, &MythExternRecApp::HasTuner);
123  QObject::connect(control, &MythExternControl::Cleanup,
124  process, &MythExternRecApp::Cleanup);
125  QObject::connect(control, &MythExternControl::DataStarted,
127  QObject::connect(control, &MythExternControl::LoadChannels,
129  QObject::connect(control, &MythExternControl::FirstChannel,
131  QObject::connect(control, &MythExternControl::NextChannel,
133  QObject::connect(control, &MythExternControl::TuneChannel,
135  QObject::connect(control, &MythExternControl::TuneStatus,
136  process, &MythExternRecApp::TuneStatus);
137  QObject::connect(control, &MythExternControl::HasPictureAttributes,
139  QObject::connect(control, &MythExternControl::SetBlockSize,
141 
142  process->Run();
143 
144  delete process;
145  delete control;
146  logStop();
147 
148  LOG(VB_GENERAL, LOG_WARNING, "Finished.");
149 
150  return GENERIC_EXIT_OK;
151 }
MythExternRecApp::SetDescription
void SetDescription(const QString &desc)
MythExternRecApp::HasTuner
void HasTuner(const QString &serial)
Definition: MythExternRecApp.cpp:815
MythExternControl::Cleanup
void Cleanup(void)
MythExternControl::Fill
void Fill(const QByteArray &buffer)
Definition: MythExternControl.h:165
MythExternRecApp::StopStreaming
void StopStreaming(const QString &serial, bool silent)
Definition: MythExternRecApp.cpp:889
MythExternRecApp::Streaming
void Streaming(bool val)
cmdline
MythCommFlagCommandLineParser cmdline
Definition: mythcommflag.cpp:72
MythExternControl::FirstChannel
void FirstChannel(const QString &serial)
MythExternRecApp::Run
void Run(void)
Definition: MythExternRecApp.cpp:303
MythExternRecApp::Done
void Done(void)
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
logfile
QString logfile
Definition: mythjobqueue.cpp:45
MythExternRecApp::SetBlockSize
void SetBlockSize(const QString &serial, int blksz)
Definition: MythExternRecApp.cpp:827
MythExternControl::HasTuner
void HasTuner(const QString &serial)
MythExternRecApp::HasPictureAttributes
void HasPictureAttributes(const QString &serial)
Definition: MythExternRecApp.cpp:822
GENERIC_EXIT_OK
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:11
MythExternRecApp::TuneStatus
void TuneStatus(const QString &serial)
Definition: MythExternRecApp.cpp:761
MythExternRecApp::TuneChannel
void TuneChannel(const QString &serial, const QString &channum)
Definition: MythExternRecApp.cpp:615
MythExternRecApp::LockTimeout
void LockTimeout(const QString &serial)
Definition: MythExternRecApp.cpp:791
MythExternControl.h
MythExternRecApp::Close
void Close(void)
Definition: MythExternRecApp.cpp:277
MythExternControl::Opened
void Opened(void)
Definition: MythExternControl.cpp:56
MythExternControl::LockTimeout
void LockTimeout(const QString &serial)
MythCommandLineParser::Parse
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
Definition: mythcommandlineparser.cpp:1544
MythExternRecApp::Opened
void Opened(void)
MythExternRecApp.h
MythExternRecApp::LoadChannels
void LoadChannels(const QString &serial)
Definition: MythExternRecApp.cpp:439
MythExternControl::Streaming
void Streaming(bool val)
Definition: MythExternControl.cpp:64
mythlogging.h
MythExternControl::TuneChannel
void TuneChannel(const QString &serial, const QString &channum)
MythExternRecApp::Cleanup
void Cleanup(void)
Definition: MythExternRecApp.cpp:336
MythExternRecApp
Definition: MythExternRecApp.h:36
MythCommandLineParser::PrintVersion
static void PrintVersion(void)
Print application version information.
Definition: mythcommandlineparser.cpp:1372
MythExternRecApp::ErrorMessage
void ErrorMessage(const QString &msg)
MythCommandLineParser::PrintHelp
void PrintHelp(void) const
Print command line option help.
Definition: mythcommandlineparser.cpp:1388
mythexternrecorder_commandlineparser.h
GENERIC_EXIT_NOT_OK
@ GENERIC_EXIT_NOT_OK
Exited with error.
Definition: exitcodes.h:12
MythExternControl::StopStreaming
void StopStreaming(const QString &serial, bool silent)
MythExternRecApp::NextChannel
void NextChannel(const QString &serial)
Definition: MythExternRecApp.cpp:560
logStop
void logStop(void)
Entry point for stopping logging for an application.
Definition: logging.cpp:669
MythExternControl::TuneStatus
void TuneStatus(const QString &serial)
MythExternControl
Definition: MythExternControl.h:119
MythExternControl::NextChannel
void NextChannel(const QString &serial)
MythExternRecorderCommandLineParser
Definition: mythexternrecorder_commandlineparser.h:6
MythExternControl::SendMessage
void SendMessage(const QString &cmd, const QString &serial, const QString &msg)
Definition: MythExternControl.cpp:113
MythExternRecApp::FirstChannel
void FirstChannel(const QString &serial)
Definition: MythExternRecApp.cpp:554
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:2344
MythCommandLineParser::toBool
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
Definition: mythcommandlineparser.cpp:2187
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:370
MythExternControl::Done
void Done(void)
Definition: MythExternControl.cpp:75
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:158
main
int main(int argc, char *argv[])
Definition: mythexternrecorder.cpp:40
MythCommandLineParser::GetLogFilePath
QString GetLogFilePath(void)
Helper utility for logging interface to pull path from –logpath.
Definition: mythcommandlineparser.cpp:2756
MythExternControl::HasPictureAttributes
void HasPictureAttributes(const QString &serial)
MythCommandLineParser::ConfigureLogging
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
Definition: mythcommandlineparser.cpp:2849
logPropagateArgs
QString logPropagateArgs
Definition: logging.cpp:82
MythExternRecApp::StartStreaming
void StartStreaming(const QString &serial)
Definition: MythExternRecApp.cpp:833
exitcodes.h
build_compdb.filename
filename
Definition: build_compdb.py:21
GENERIC_EXIT_INVALID_CMDLINE
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:16
MythExternControl::ErrorMessage
void ErrorMessage(const QString &msg)
Definition: MythExternControl.cpp:121
MythExternRecApp::Fill
void Fill(const QByteArray &buffer)