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"
34#include "libmythbase/mythversion.h"
35
36// MythExternRecorder
37#include "MythExternControl.h"
38#include "MythExternRecApp.h"
40
41int 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;
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,
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,
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,
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}
bool toBool(const QString &key) const
Returns stored QVariant as a boolean.
virtual bool Parse(int argc, const char *const *argv)
Loop through argv and populate arguments with values.
int ConfigureLogging(const QString &mask="general", bool progress=false)
Read in logging options and initialize the logging interface.
QString toString(const QString &key) const
Returns stored QVariant as a QString, falling to default if not provided.
static void PrintVersion(void)
Print application version information.
QString GetLogFilePath(void)
Helper utility for logging interface to pull path from –logpath.
void PrintHelp(void) const
Print command line option help.
void ErrorMessage(const QString &msg)
void TuneStatus(const QString &serial)
void StartStreaming(const QString &serial)
void SetBlockSize(const QString &serial, int blksz)
void HasTuner(const QString &serial)
void HasPictureAttributes(const QString &serial)
void Fill(const QByteArray &buffer)
void SendMessage(const QString &command, const QString &serial, const QString &message, const QString &status="")
void FirstChannel(const QString &serial)
void DataStarted(void)
void Cleanup(void)
void TuneChannel(const QString &serial, const QVariantMap &args)
void NextChannel(const QString &serial)
void LoadChannels(const QString &serial)
void Streaming(bool val)
void SetDescription(const QString &desc)
void StopStreaming(const QString &serial, bool silent)
void LockTimeout(const QString &serial)
void Close(void)
void LockTimeout(const QString &serial)
void StartStreaming(const QString &serial)
void SetDescription(const QString &desc)
void Streaming(bool val)
void Done(void)
void TuneChannel(const QString &serial, const QVariantMap &chaninfo)
void Opened(void)
void SendMessage(const QString &command, const QString &serial, const QString &message, const QString &status="")
void HasTuner(const QString &serial)
void FirstChannel(const QString &serial)
void Fill(const QByteArray &buffer)
void StopStreaming(const QString &serial, bool silent)
void LoadChannels(const QString &serial)
void NextChannel(const QString &serial)
void ErrorMessage(const QString &msg)
void TuneStatus(const QString &serial)
void SetBlockSize(const QString &serial, int blksz)
void HasPictureAttributes(const QString &serial)
@ GENERIC_EXIT_OK
Exited with no error.
Definition: exitcodes.h:13
@ GENERIC_EXIT_INVALID_CMDLINE
Command line parse error.
Definition: exitcodes.h:18
@ GENERIC_EXIT_NOT_OK
Exited with error.
Definition: exitcodes.h:14
void logStop(void)
Entry point for stopping logging for an application.
Definition: logging.cpp:685
QString logPropagateArgs
Definition: logging.cpp:82
static constexpr const char * MYTH_APPNAME_MYTHEXTERNRECORDER
Definition: mythappname.h:22
int main(int argc, char *argv[])
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythCommFlagCommandLineParser cmdline