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"
34 #include "libmythbase/mythversion.h"
35 
36 // MythExternRecorder
37 #include "MythExternControl.h"
38 #include "MythExternRecApp.h"
40 
41 int main(int argc, char *argv[])
42 {
44 
45  if (!cmdline.Parse(argc, argv))
46  {
49  }
50 
51  if (cmdline.toBool("showhelp"))
52  {
54  return GENERIC_EXIT_OK;
55  }
56 
57  if (cmdline.toBool("showversion"))
58  {
60  return GENERIC_EXIT_OK;
61  }
62 
63  QCoreApplication app(argc, argv);
64  QCoreApplication::setApplicationName(MYTH_APPNAME_MYTHEXTERNRECORDER);
65 
66  int retval = cmdline.ConfigureLogging();
67  if (retval != GENERIC_EXIT_OK)
68  return retval;
69  QString logfile = cmdline.GetLogFilePath();
70  QString logging = logPropagateArgs;
71 
72  auto *control = new MythExternControl();
73  MythExternRecApp *process = nullptr;
74 
75  QString conf_file = cmdline.toString("conf");
76  if (!conf_file.isEmpty())
77  {
78  process = new MythExternRecApp("", conf_file, logfile, logging);
79  }
80  else if (!cmdline.toString("exec").isEmpty())
81  {
82  QString command = cmdline.toString("exec");
83  process = new MythExternRecApp(command, "", logfile, logging);
84  }
85  else if (!cmdline.toString("infile").isEmpty())
86  {
87  QString filename = cmdline.toString("infile");
88  QString command = QString("ffmpeg -re -i \"%1\" "
89  "-c:v copy -c:a copy -f mpegts -")
90  .arg(filename);
91  process = new MythExternRecApp(command, "", logfile, logging);
92  }
93  if (process == nullptr)
94  {
95  delete control;
96  return GENERIC_EXIT_NOT_OK;
97  }
98 
99  QObject::connect(process, &MythExternRecApp::Opened,
100  control, &MythExternControl::Opened);
101  QObject::connect(process, &MythExternRecApp::Done,
102  control, &MythExternControl::Done);
103  QObject::connect(process, &MythExternRecApp::SetDescription,
105  QObject::connect(process, &MythExternRecApp::SendMessage,
107  QObject::connect(process, &MythExternRecApp::ErrorMessage,
109  QObject::connect(process, &MythExternRecApp::Streaming,
110  control, &MythExternControl::Streaming);
111  QObject::connect(process, &MythExternRecApp::Fill,
112  control, &MythExternControl::Fill);
113 
114  QObject::connect(control, &MythExternControl::Close,
115  process, &MythExternRecApp::Close);
116  QObject::connect(control, &MythExternControl::StartStreaming,
118  QObject::connect(control, &MythExternControl::StopStreaming,
120  QObject::connect(control, &MythExternControl::LockTimeout,
122  QObject::connect(control, &MythExternControl::HasTuner,
123  process, &MythExternRecApp::HasTuner);
124  QObject::connect(control, &MythExternControl::Cleanup,
125  process, &MythExternRecApp::Cleanup);
126  QObject::connect(control, &MythExternControl::DataStarted,
128  QObject::connect(control, &MythExternControl::LoadChannels,
130  QObject::connect(control, &MythExternControl::FirstChannel,
132  QObject::connect(control, &MythExternControl::NextChannel,
134  QObject::connect(control, &MythExternControl::TuneChannel,
136  QObject::connect(control, &MythExternControl::TuneStatus,
137  process, &MythExternRecApp::TuneStatus);
138  QObject::connect(control, &MythExternControl::HasPictureAttributes,
140  QObject::connect(control, &MythExternControl::SetBlockSize,
142 
143  process->Run();
144 
145  delete process;
146  delete control;
147  logStop();
148 
149  LOG(VB_GENERAL, LOG_WARNING, "Finished.");
150 
151  return GENERIC_EXIT_OK;
152 }
MythExternRecApp::SetDescription
void SetDescription(const QString &desc)
MythExternRecApp::HasTuner
void HasTuner(const QString &serial)
Definition: MythExternRecApp.cpp:882
MythExternControl::Cleanup
void Cleanup(void)
MythExternRecApp::TuneChannel
void TuneChannel(const QString &serial, const QVariantMap &chaninfo)
Definition: MythExternRecApp.cpp:683
MythExternControl::Fill
void Fill(const QByteArray &buffer)
Definition: MythExternControl.h:173
MythExternRecApp::StopStreaming
void StopStreaming(const QString &serial, bool silent)
Definition: MythExternRecApp.cpp:955
MythExternRecApp::Streaming
void Streaming(bool val)
cmdline
MythCommFlagCommandLineParser cmdline
Definition: mythcommflag.cpp:63
MythExternControl::FirstChannel
void FirstChannel(const QString &serial)
MythExternRecApp::Run
void Run(void)
Definition: MythExternRecApp.cpp:375
MythExternRecApp::Done
void Done(void)
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythExternRecApp::SetBlockSize
void SetBlockSize(const QString &serial, int blksz)
Definition: MythExternRecApp.cpp:893
MythExternControl::HasTuner
void HasTuner(const QString &serial)
MythExternRecApp::HasPictureAttributes
void HasPictureAttributes(const QString &serial)
Definition: MythExternRecApp.cpp:888
MythExternRecApp::TuneStatus
void TuneStatus(const QString &serial)
Definition: MythExternRecApp.cpp:830
MythExternRecApp::LockTimeout
void LockTimeout(const QString &serial)
Definition: MythExternRecApp.cpp:859
MythExternControl.h
MythExternControl::TuneChannel
void TuneChannel(const QString &serial, const QVariantMap &args)
MythExternRecApp::Close
void Close(void)
Definition: MythExternRecApp.cpp:349
MythExternControl::Opened
void Opened(void)
Definition: MythExternControl.cpp:58
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:1558
MythExternRecApp::Opened
void Opened(void)
MythExternRecApp.h
MythExternRecApp::LoadChannels
void LoadChannels(const QString &serial)
Definition: MythExternRecApp.cpp:512
MythExternControl::Streaming
void Streaming(bool val)
Definition: MythExternControl.cpp:66
GENERIC_EXIT_INVALID_CMDLINE
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:18
mythlogging.h
MythExternRecApp::Cleanup
void Cleanup(void)
Definition: MythExternRecApp.cpp:408
MythExternRecApp::SendMessage
void SendMessage(const QString &command, const QString &serial, const QString &message, const QString &status="")
GENERIC_EXIT_OK
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:13
MythExternRecApp
Definition: MythExternRecApp.h:37
MythCommandLineParser::PrintVersion
static void PrintVersion(void)
Print application version information.
Definition: mythcommandlineparser.cpp:1386
MythExternRecApp::ErrorMessage
void ErrorMessage(const QString &msg)
MythCommandLineParser::PrintHelp
void PrintHelp(void) const
Print command line option help.
Definition: mythcommandlineparser.cpp:1402
mythexternrecorder_commandlineparser.h
MythExternControl::StopStreaming
void StopStreaming(const QString &serial, bool silent)
MythExternRecApp::NextChannel
void NextChannel(const QString &serial)
Definition: MythExternRecApp.cpp:628
logStop
void logStop(void)
Entry point for stopping logging for an application.
Definition: logging.cpp:685
mythappname.h
MythExternControl::TuneStatus
void TuneStatus(const QString &serial)
MythExternControl
Definition: MythExternControl.h:124
MythExternControl::NextChannel
void NextChannel(const QString &serial)
MythExternRecorderCommandLineParser
Definition: mythexternrecorder_commandlineparser.h:6
MythExternRecApp::FirstChannel
void FirstChannel(const QString &serial)
Definition: MythExternRecApp.cpp:622
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:2360
MythCommandLineParser::toBool
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
Definition: mythcommandlineparser.cpp:2203
MythExternControl::Close
void Close(void)
MythExternRecApp::DataStarted
void DataStarted(void)
Definition: MythExternRecApp.cpp:444
MythExternControl::Done
void Done(void)
Definition: MythExternControl.cpp:77
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:163
GENERIC_EXIT_NOT_OK
@ GENERIC_EXIT_NOT_OK
Exited with error.
Definition: exitcodes.h:14
main
int main(int argc, char *argv[])
Definition: mythexternrecorder.cpp:41
MythCommandLineParser::GetLogFilePath
QString GetLogFilePath(void)
Helper utility for logging interface to pull path from –logpath.
Definition: mythcommandlineparser.cpp:2783
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:2876
logPropagateArgs
QString logPropagateArgs
Definition: logging.cpp:82
MythExternRecApp::StartStreaming
void StartStreaming(const QString &serial)
Definition: MythExternRecApp.cpp:899
MYTH_APPNAME_MYTHEXTERNRECORDER
static constexpr const char * MYTH_APPNAME_MYTHEXTERNRECORDER
Definition: mythappname.h:22
exitcodes.h
build_compdb.filename
filename
Definition: build_compdb.py:21
MythExternControl::ErrorMessage
void ErrorMessage(const QString &msg)
Definition: MythExternControl.cpp:124
MythExternControl::SendMessage
void SendMessage(const QString &command, const QString &serial, const QString &message, const QString &status="")
Definition: MythExternControl.cpp:115
MythExternRecApp::Fill
void Fill(const QByteArray &buffer)