2000-02-19 13:36:48 +01:00
|
|
|
/*
|
2000-04-24 09:46:05 +02:00
|
|
|
* vdr.c: Video Disk Recorder main program
|
2000-02-19 13:36:48 +01:00
|
|
|
*
|
|
|
|
* Copyright (C) 2000 Klaus Schmidinger
|
2001-08-03 14:18:08 +02:00
|
|
|
*
|
2000-02-19 13:36:48 +01:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2001-08-03 14:18:08 +02:00
|
|
|
*
|
2000-02-19 13:36:48 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2001-08-03 14:18:08 +02:00
|
|
|
*
|
2000-02-19 13:36:48 +01:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
* Or, point your browser to http://www.gnu.org/copyleft/gpl.html
|
2001-08-03 14:18:08 +02:00
|
|
|
*
|
2000-02-19 13:36:48 +01:00
|
|
|
* The author can be reached at kls@cadsoft.de
|
|
|
|
*
|
|
|
|
* The project's page is at http://www.cadsoft.de/people/kls/vdr
|
|
|
|
*
|
2002-03-03 16:12:29 +01:00
|
|
|
* $Id: vdr.c 1.98 2002/03/03 14:56:03 kls Exp $
|
2000-02-19 13:36:48 +01:00
|
|
|
*/
|
|
|
|
|
2000-07-23 15:01:31 +02:00
|
|
|
#include <getopt.h>
|
2001-10-07 11:00:35 +02:00
|
|
|
#include <locale.h>
|
2000-04-15 17:38:11 +02:00
|
|
|
#include <signal.h>
|
2000-07-23 15:01:31 +02:00
|
|
|
#include <stdlib.h>
|
2000-07-23 15:36:43 +02:00
|
|
|
#include <unistd.h>
|
2000-02-19 13:36:48 +01:00
|
|
|
#include "config.h"
|
2000-05-01 16:29:46 +02:00
|
|
|
#include "dvbapi.h"
|
2002-02-23 17:11:19 +01:00
|
|
|
#include "eit.h"
|
2000-11-11 10:39:27 +01:00
|
|
|
#include "i18n.h"
|
2000-02-19 13:36:48 +01:00
|
|
|
#include "interface.h"
|
|
|
|
#include "menu.h"
|
2000-03-11 11:22:37 +01:00
|
|
|
#include "recording.h"
|
2000-02-19 13:36:48 +01:00
|
|
|
#include "tools.h"
|
2000-07-29 15:21:42 +02:00
|
|
|
#include "videodir.h"
|
2000-02-19 13:36:48 +01:00
|
|
|
|
2000-07-15 12:39:20 +02:00
|
|
|
#ifdef REMOTE_KBD
|
2000-02-19 13:36:48 +01:00
|
|
|
#define KEYS_CONF "keys-pc.conf"
|
|
|
|
#else
|
|
|
|
#define KEYS_CONF "keys.conf"
|
|
|
|
#endif
|
|
|
|
|
2001-02-11 14:53:44 +01:00
|
|
|
#define ACTIVITYTIMEOUT 60 // seconds before starting housekeeping
|
2001-09-01 09:04:37 +02:00
|
|
|
#define SHUTDOWNWAIT 300 // seconds to wait in user prompt before automatic shutdown
|
2001-09-07 15:37:26 +02:00
|
|
|
#define MANUALSTART 600 // seconds the next timer must be in the future to assume manual start
|
2001-02-11 14:53:44 +01:00
|
|
|
|
2001-09-16 15:06:54 +02:00
|
|
|
#define VOLUMEDELTA 5 // used to increase/decrease the volume
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
static int Interrupted = 0;
|
|
|
|
|
2000-09-15 13:58:36 +02:00
|
|
|
static void SignalHandler(int signum)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
2001-09-01 09:04:37 +02:00
|
|
|
if (signum != SIGPIPE) {
|
2000-09-15 13:58:36 +02:00
|
|
|
Interrupted = signum;
|
2001-09-01 09:04:37 +02:00
|
|
|
Interface->Interrupt();
|
|
|
|
}
|
2000-09-15 13:58:36 +02:00
|
|
|
signal(signum, SignalHandler);
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2001-02-24 16:18:43 +01:00
|
|
|
static void Watchdog(int signum)
|
|
|
|
{
|
|
|
|
// Something terrible must have happened that prevented the 'alarm()' from
|
|
|
|
// being called in time, so let's get out of here:
|
|
|
|
esyslog(LOG_ERR, "PANIC: watchdog timer expired - exiting!");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2000-02-19 13:36:48 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2001-10-07 11:00:35 +02:00
|
|
|
// Initiate locale:
|
|
|
|
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
2000-07-23 15:01:31 +02:00
|
|
|
// Command line options:
|
|
|
|
|
|
|
|
#define DEFAULTSVDRPPORT 2001
|
2001-02-24 16:18:43 +01:00
|
|
|
#define DEFAULTWATCHDOG 0 // seconds
|
2000-07-23 15:01:31 +02:00
|
|
|
|
|
|
|
int SVDRPport = DEFAULTSVDRPPORT;
|
2000-09-15 15:09:15 +02:00
|
|
|
const char *ConfigDirectory = NULL;
|
2000-07-23 15:36:43 +02:00
|
|
|
bool DaemonMode = false;
|
2001-02-24 16:18:43 +01:00
|
|
|
int WatchdogTimeout = DEFAULTWATCHDOG;
|
2001-09-01 09:04:37 +02:00
|
|
|
const char *Terminal = NULL;
|
|
|
|
const char *Shutdown = NULL;
|
2000-07-23 15:01:31 +02:00
|
|
|
|
|
|
|
static struct option long_options[] = {
|
2001-06-24 17:42:19 +02:00
|
|
|
{ "audio", required_argument, NULL, 'a' },
|
2001-02-24 16:18:43 +01:00
|
|
|
{ "config", required_argument, NULL, 'c' },
|
|
|
|
{ "daemon", no_argument, NULL, 'd' },
|
|
|
|
{ "device", required_argument, NULL, 'D' },
|
2001-08-11 09:38:12 +02:00
|
|
|
{ "epgfile", required_argument, NULL, 'E' },
|
2001-02-24 16:18:43 +01:00
|
|
|
{ "help", no_argument, NULL, 'h' },
|
|
|
|
{ "log", required_argument, NULL, 'l' },
|
|
|
|
{ "port", required_argument, NULL, 'p' },
|
2001-09-22 14:23:55 +02:00
|
|
|
{ "record", required_argument, NULL, 'r' },
|
2001-09-01 09:04:37 +02:00
|
|
|
{ "shutdown", required_argument, NULL, 's' },
|
|
|
|
{ "terminal", required_argument, NULL, 't' },
|
2001-02-24 16:18:43 +01:00
|
|
|
{ "video", required_argument, NULL, 'v' },
|
|
|
|
{ "watchdog", required_argument, NULL, 'w' },
|
2001-08-11 09:38:12 +02:00
|
|
|
{ NULL }
|
2000-07-23 15:01:31 +02:00
|
|
|
};
|
2001-08-03 14:18:08 +02:00
|
|
|
|
2000-07-23 15:01:31 +02:00
|
|
|
int c;
|
|
|
|
int option_index = 0;
|
2002-02-24 14:07:21 +01:00
|
|
|
while ((c = getopt_long(argc, argv, "a:c:dD:E:hl:p:r:s:t:v:w:", long_options, &option_index)) != -1) {
|
2000-07-23 15:01:31 +02:00
|
|
|
switch (c) {
|
2001-06-24 17:42:19 +02:00
|
|
|
case 'a': cDvbApi::SetAudioCommand(optarg);
|
|
|
|
break;
|
2000-09-15 15:09:15 +02:00
|
|
|
case 'c': ConfigDirectory = optarg;
|
|
|
|
break;
|
2000-07-23 15:36:43 +02:00
|
|
|
case 'd': DaemonMode = true; break;
|
2001-02-02 15:49:46 +01:00
|
|
|
case 'D': if (isnumber(optarg)) {
|
|
|
|
int n = atoi(optarg);
|
|
|
|
if (0 <= n && n < MAXDVBAPI) {
|
|
|
|
cDvbApi::SetUseDvbApi(n);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, "vdr: invalid DVB device number: %s\n", optarg);
|
2001-04-01 11:18:28 +02:00
|
|
|
return 2;
|
2001-02-02 15:49:46 +01:00
|
|
|
break;
|
2001-08-11 09:38:12 +02:00
|
|
|
case 'E': cSIProcessor::SetEpgDataFileName(*optarg != '-' ? optarg : NULL);
|
|
|
|
break;
|
2000-09-15 15:09:15 +02:00
|
|
|
case 'h': printf("Usage: vdr [OPTION]\n\n" // for easier orientation, this is column 80|
|
2001-06-24 17:42:19 +02:00
|
|
|
" -a CMD, --audio=CMD send Dolby Digital audio to stdin of command CMD\n"
|
2001-02-24 16:18:43 +01:00
|
|
|
" -c DIR, --config=DIR read config files from DIR (default is to read them\n"
|
|
|
|
" from the video directory)\n"
|
|
|
|
" -d, --daemon run in daemon mode\n"
|
|
|
|
" -D NUM, --device=NUM use only the given DVB device (NUM = 0, 1, 2...)\n"
|
|
|
|
" there may be several -D options (default: all DVB\n"
|
|
|
|
" devices will be used)\n"
|
2001-08-11 09:38:12 +02:00
|
|
|
" -E FILE --epgfile=FILE write the EPG data into the given FILE (default is\n"
|
|
|
|
" %s); use '-E-' to disable this\n"
|
|
|
|
" if FILE is a directory, the default EPG file will be\n"
|
|
|
|
" created in that directory\n"
|
|
|
|
" -h, --help display this help and exit\n"
|
2001-02-24 16:18:43 +01:00
|
|
|
" -l LEVEL, --log=LEVEL set log level (default: 3)\n"
|
|
|
|
" 0 = no logging, 1 = errors only,\n"
|
|
|
|
" 2 = errors and info, 3 = errors, info and debug\n"
|
|
|
|
" -p PORT, --port=PORT use PORT for SVDRP (default: %d)\n"
|
|
|
|
" 0 turns off SVDRP\n"
|
2001-09-22 14:23:55 +02:00
|
|
|
" -r CMD, --record=CMD call CMD before and after a recording\n"
|
2001-09-01 09:04:37 +02:00
|
|
|
" -s CMD, --shutdown=CMD call CMD to shutdown the computer\n"
|
2001-08-11 09:38:12 +02:00
|
|
|
" -t TTY, --terminal=TTY controlling tty\n"
|
2001-03-31 10:32:58 +02:00
|
|
|
" -v DIR, --video=DIR use DIR as video directory (default: %s)\n"
|
2001-02-24 16:18:43 +01:00
|
|
|
" -w SEC, --watchdog=SEC activate the watchdog timer with a timeout of SEC\n"
|
|
|
|
" seconds (default: %d); '0' disables the watchdog\n"
|
2000-07-23 15:01:31 +02:00
|
|
|
"\n"
|
2000-07-28 13:44:31 +02:00
|
|
|
"Report bugs to <vdr-bugs@cadsoft.de>\n",
|
2001-08-11 09:38:12 +02:00
|
|
|
cSIProcessor::GetEpgDataFileName() ? cSIProcessor::GetEpgDataFileName() : "'-'",
|
2000-07-28 13:44:31 +02:00
|
|
|
DEFAULTSVDRPPORT,
|
2001-02-24 16:18:43 +01:00
|
|
|
VideoDirectory,
|
|
|
|
DEFAULTWATCHDOG
|
2000-07-23 15:01:31 +02:00
|
|
|
);
|
|
|
|
return 0;
|
|
|
|
break;
|
2000-07-29 19:03:09 +02:00
|
|
|
case 'l': if (isnumber(optarg)) {
|
|
|
|
int l = atoi(optarg);
|
|
|
|
if (0 <= l && l <= 3) {
|
|
|
|
SysLogLevel = l;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, "vdr: invalid log level: %s\n", optarg);
|
2001-04-01 11:18:28 +02:00
|
|
|
return 2;
|
2000-07-29 19:03:09 +02:00
|
|
|
break;
|
2000-07-23 15:01:31 +02:00
|
|
|
case 'p': if (isnumber(optarg))
|
2000-07-29 19:03:09 +02:00
|
|
|
SVDRPport = atoi(optarg);
|
2000-07-23 15:01:31 +02:00
|
|
|
else {
|
|
|
|
fprintf(stderr, "vdr: invalid port number: %s\n", optarg);
|
2001-04-01 11:18:28 +02:00
|
|
|
return 2;
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
break;
|
2001-09-23 14:02:11 +02:00
|
|
|
case 'r': cRecordingUserCommand::SetCommand(optarg);
|
2001-09-22 14:23:55 +02:00
|
|
|
break;
|
2001-09-01 09:04:37 +02:00
|
|
|
case 's': Shutdown = optarg;
|
|
|
|
break;
|
2001-03-31 10:32:58 +02:00
|
|
|
case 't': Terminal = optarg;
|
|
|
|
break;
|
2000-07-28 13:44:31 +02:00
|
|
|
case 'v': VideoDirectory = optarg;
|
2000-09-17 14:18:14 +02:00
|
|
|
while (optarg && *optarg && optarg[strlen(optarg) - 1] == '/')
|
|
|
|
optarg[strlen(optarg) - 1] = 0;
|
2000-07-28 13:44:31 +02:00
|
|
|
break;
|
2001-02-24 16:18:43 +01:00
|
|
|
case 'w': if (isnumber(optarg)) {
|
|
|
|
int t = atoi(optarg);
|
|
|
|
if (t >= 0) {
|
|
|
|
WatchdogTimeout = t;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stderr, "vdr: invalid watchdog timeout: %s\n", optarg);
|
2001-04-01 11:18:28 +02:00
|
|
|
return 2;
|
2001-02-24 16:18:43 +01:00
|
|
|
break;
|
2001-04-01 11:18:28 +02:00
|
|
|
default: return 2;
|
2000-07-23 15:01:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Log file:
|
2001-08-03 14:18:08 +02:00
|
|
|
|
2000-07-29 19:03:09 +02:00
|
|
|
if (SysLogLevel > 0)
|
|
|
|
openlog("vdr", LOG_PID | LOG_CONS, LOG_USER);
|
2000-07-23 15:36:43 +02:00
|
|
|
|
2000-07-28 13:44:31 +02:00
|
|
|
// Check the video directory:
|
|
|
|
|
2000-07-29 15:21:42 +02:00
|
|
|
if (!DirectoryOk(VideoDirectory, true)) {
|
2000-07-28 13:44:31 +02:00
|
|
|
fprintf(stderr, "vdr: can't access video directory %s\n", VideoDirectory);
|
2001-04-01 11:18:28 +02:00
|
|
|
return 2;
|
2000-07-28 13:44:31 +02:00
|
|
|
}
|
|
|
|
|
2000-07-23 15:36:43 +02:00
|
|
|
// Daemon mode:
|
|
|
|
|
|
|
|
if (DaemonMode) {
|
2000-09-20 16:49:49 +02:00
|
|
|
#if !defined(DEBUG_OSD) && !defined(REMOTE_KBD)
|
2000-07-23 15:36:43 +02:00
|
|
|
pid_t pid = fork();
|
|
|
|
if (pid < 0) {
|
2000-12-08 16:23:32 +01:00
|
|
|
fprintf(stderr, "%m\n");
|
|
|
|
esyslog(LOG_ERR, "ERROR: %m");
|
2001-04-01 11:18:28 +02:00
|
|
|
return 2;
|
2000-07-23 15:36:43 +02:00
|
|
|
}
|
|
|
|
if (pid != 0)
|
|
|
|
return 0; // initial program immediately returns
|
|
|
|
fclose(stdin);
|
|
|
|
fclose(stdout);
|
|
|
|
fclose(stderr);
|
|
|
|
#else
|
2000-09-20 16:49:49 +02:00
|
|
|
fprintf(stderr, "vdr: can't run in daemon mode with DEBUG_OSD or REMOTE_KBD on!\n");
|
2001-04-01 11:18:28 +02:00
|
|
|
return 2;
|
2000-07-23 15:36:43 +02:00
|
|
|
#endif
|
|
|
|
}
|
2001-03-31 10:32:58 +02:00
|
|
|
else if (Terminal) {
|
|
|
|
// Claim new controlling terminal
|
|
|
|
stdin = freopen(Terminal, "r", stdin);
|
|
|
|
stdout = freopen(Terminal, "w", stdout);
|
|
|
|
stderr = freopen(Terminal, "w", stderr);
|
|
|
|
}
|
|
|
|
|
2000-07-29 18:19:49 +02:00
|
|
|
isyslog(LOG_INFO, "VDR version %s started", VDRVERSION);
|
2000-02-19 13:36:48 +01:00
|
|
|
|
2000-07-23 15:01:31 +02:00
|
|
|
// Configuration data:
|
|
|
|
|
2000-09-15 15:09:15 +02:00
|
|
|
if (!ConfigDirectory)
|
|
|
|
ConfigDirectory = VideoDirectory;
|
|
|
|
|
|
|
|
Setup.Load(AddDirectory(ConfigDirectory, "setup.conf"));
|
|
|
|
Channels.Load(AddDirectory(ConfigDirectory, "channels.conf"));
|
|
|
|
Timers.Load(AddDirectory(ConfigDirectory, "timers.conf"));
|
2000-11-11 16:38:41 +01:00
|
|
|
Commands.Load(AddDirectory(ConfigDirectory, "commands.conf"));
|
2002-02-02 17:20:54 +01:00
|
|
|
SVDRPhosts.Load(AddDirectory(ConfigDirectory, "svdrphosts.conf"), true);
|
2002-03-03 16:12:29 +01:00
|
|
|
CaDefinitions.Load(AddDirectory(ConfigDirectory, "ca.conf"), true);
|
2001-02-04 19:41:24 +01:00
|
|
|
#if defined(REMOTE_LIRC)
|
2000-07-15 16:35:18 +02:00
|
|
|
Keys.SetDummyValues();
|
2001-02-04 19:41:24 +01:00
|
|
|
#elif !defined(REMOTE_NONE)
|
2000-10-29 14:00:00 +01:00
|
|
|
bool KeysLoaded = Keys.Load(AddDirectory(ConfigDirectory, KEYS_CONF));
|
2000-07-15 12:39:20 +02:00
|
|
|
#endif
|
2000-02-19 13:36:48 +01:00
|
|
|
|
2000-11-03 15:31:03 +01:00
|
|
|
// DVB interfaces:
|
|
|
|
|
|
|
|
if (!cDvbApi::Init())
|
2001-04-01 11:18:28 +02:00
|
|
|
return 2;
|
2000-11-03 15:31:03 +01:00
|
|
|
|
2000-09-10 10:51:58 +02:00
|
|
|
cDvbApi::SetPrimaryDvbApi(Setup.PrimaryDVB);
|
|
|
|
|
2002-02-23 17:11:19 +01:00
|
|
|
cSIProcessor::Read();
|
|
|
|
|
2001-01-14 15:29:51 +01:00
|
|
|
Channels.SwitchTo(Setup.CurrentChannel);
|
2001-09-22 13:41:49 +02:00
|
|
|
cDvbApi::PrimaryDvbApi->SetVolume(Setup.CurrentVolume, true);
|
2000-02-19 13:36:48 +01:00
|
|
|
|
2000-11-18 13:57:32 +01:00
|
|
|
cEITScanner EITScanner;
|
|
|
|
|
2000-10-29 14:00:00 +01:00
|
|
|
// User interface:
|
|
|
|
|
|
|
|
Interface = new cInterface(SVDRPport);
|
2001-02-04 19:41:24 +01:00
|
|
|
#if !defined(REMOTE_LIRC) && !defined(REMOTE_NONE)
|
2000-10-29 14:00:00 +01:00
|
|
|
if (!KeysLoaded)
|
|
|
|
Interface->LearnKeys();
|
|
|
|
#endif
|
|
|
|
|
2000-07-23 15:01:31 +02:00
|
|
|
// Signal handlers:
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
if (signal(SIGHUP, SignalHandler) == SIG_IGN) signal(SIGHUP, SIG_IGN);
|
|
|
|
if (signal(SIGINT, SignalHandler) == SIG_IGN) signal(SIGINT, SIG_IGN);
|
|
|
|
if (signal(SIGTERM, SignalHandler) == SIG_IGN) signal(SIGTERM, SIG_IGN);
|
2000-09-15 13:58:36 +02:00
|
|
|
if (signal(SIGPIPE, SignalHandler) == SIG_IGN) signal(SIGPIPE, SIG_IGN);
|
2001-02-24 16:18:43 +01:00
|
|
|
if (WatchdogTimeout > 0)
|
|
|
|
if (signal(SIGALRM, Watchdog) == SIG_IGN) signal(SIGALRM, SIG_IGN);
|
2000-04-15 17:38:11 +02:00
|
|
|
|
2000-07-23 15:01:31 +02:00
|
|
|
// Main program loop:
|
|
|
|
|
2000-09-10 14:56:18 +02:00
|
|
|
cOsdBase *Menu = NULL;
|
2000-04-29 15:57:42 +02:00
|
|
|
cReplayControl *ReplayControl = NULL;
|
2000-04-22 13:51:48 +02:00
|
|
|
int LastChannel = -1;
|
2000-11-05 18:39:17 +01:00
|
|
|
int PreviousChannel = cDvbApi::CurrentChannel();
|
2001-09-01 09:04:37 +02:00
|
|
|
time_t LastActivity = 0;
|
2001-02-24 16:18:43 +01:00
|
|
|
int MaxLatencyTime = 0;
|
2001-09-01 11:44:08 +02:00
|
|
|
bool ForceShutdown = false;
|
2001-02-24 16:18:43 +01:00
|
|
|
|
|
|
|
if (WatchdogTimeout > 0) {
|
|
|
|
dsyslog(LOG_INFO, "setting watchdog timer to %d seconds", WatchdogTimeout);
|
|
|
|
alarm(WatchdogTimeout); // Initial watchdog timer start
|
|
|
|
}
|
2000-02-19 13:36:48 +01:00
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
while (!Interrupted) {
|
2001-06-02 10:47:40 +02:00
|
|
|
// Handle emergency exits:
|
|
|
|
if (cThread::EmergencyExit()) {
|
|
|
|
esyslog(LOG_ERR, "emergency exit requested - shutting down");
|
|
|
|
break;
|
|
|
|
}
|
2001-02-24 16:18:43 +01:00
|
|
|
// Restart the Watchdog timer:
|
|
|
|
if (WatchdogTimeout > 0) {
|
|
|
|
int LatencyTime = WatchdogTimeout - alarm(WatchdogTimeout);
|
|
|
|
if (LatencyTime > MaxLatencyTime) {
|
|
|
|
MaxLatencyTime = LatencyTime;
|
|
|
|
dsyslog(LOG_INFO, "max. latency time %d seconds", MaxLatencyTime);
|
|
|
|
}
|
|
|
|
}
|
2000-04-22 13:51:48 +02:00
|
|
|
// Channel display:
|
2000-11-18 13:57:32 +01:00
|
|
|
if (!EITScanner.Active() && cDvbApi::CurrentChannel() != LastChannel) {
|
2000-09-09 14:57:43 +02:00
|
|
|
if (!Menu)
|
2000-11-05 18:39:17 +01:00
|
|
|
Menu = new cDisplayChannel(cDvbApi::CurrentChannel(), LastChannel > 0);
|
2001-09-08 12:18:02 +02:00
|
|
|
if (LastChannel > 0)
|
|
|
|
PreviousChannel = LastChannel;
|
2000-11-05 18:39:17 +01:00
|
|
|
LastChannel = cDvbApi::CurrentChannel();
|
2000-04-22 13:51:48 +02:00
|
|
|
}
|
2000-05-01 16:29:46 +02:00
|
|
|
// Timers and Recordings:
|
|
|
|
if (!Menu) {
|
2001-09-01 15:04:14 +02:00
|
|
|
time_t Now = time(NULL); // must do both following calls with the exact same time!
|
|
|
|
cRecordControls::Process(Now);
|
|
|
|
cTimer *Timer = Timers.GetMatch(Now);
|
2000-04-30 10:22:13 +02:00
|
|
|
if (Timer) {
|
2001-08-11 15:48:54 +02:00
|
|
|
if (!cRecordControls::Start(Timer))
|
|
|
|
Timer->SetPending(true);
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
}
|
2000-04-16 15:50:21 +02:00
|
|
|
// User Input:
|
2000-09-10 14:56:18 +02:00
|
|
|
cOsdBase **Interact = Menu ? &Menu : (cOsdBase **)&ReplayControl;
|
2000-10-08 12:24:30 +02:00
|
|
|
eKeys key = Interface->GetKey(!*Interact || !(*Interact)->NeedsFastResponse());
|
2001-09-01 09:04:37 +02:00
|
|
|
if (NORMALKEY(key) != kNone) {
|
2000-11-18 13:57:32 +01:00
|
|
|
EITScanner.Activity();
|
2001-09-01 09:04:37 +02:00
|
|
|
LastActivity = time(NULL);
|
|
|
|
}
|
2001-09-23 14:36:38 +02:00
|
|
|
// Keys that must work independent of any interactive mode:
|
|
|
|
switch (key) {
|
|
|
|
// Volume Control:
|
|
|
|
case kVolUp|k_Repeat:
|
|
|
|
case kVolUp:
|
|
|
|
case kVolDn|k_Repeat:
|
|
|
|
case kVolDn:
|
|
|
|
cDvbApi::PrimaryDvbApi->SetVolume(NORMALKEY(key) == kVolDn ? -VOLUMEDELTA : VOLUMEDELTA);
|
|
|
|
break;
|
|
|
|
case kMute:
|
|
|
|
cDvbApi::PrimaryDvbApi->ToggleMute();
|
|
|
|
break;
|
|
|
|
// Power off:
|
|
|
|
case kPower: isyslog(LOG_INFO, "Power button pressed");
|
|
|
|
DELETENULL(*Interact);
|
|
|
|
if (!Shutdown) {
|
|
|
|
Interface->Error(tr("Can't shutdown - option '-s' not given!"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (cRecordControls::Active()) {
|
|
|
|
if (Interface->Confirm(tr("Recording - shut down anyway?")))
|
|
|
|
ForceShutdown = true;
|
|
|
|
}
|
|
|
|
LastActivity = 1; // not 0, see below!
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (*Interact) {
|
|
|
|
switch ((*Interact)->ProcessKey(key)) {
|
|
|
|
case osMenu: DELETENULL(Menu);
|
|
|
|
Menu = new cMenuMain(ReplayControl);
|
|
|
|
break;
|
|
|
|
case osRecord: DELETENULL(Menu);
|
|
|
|
if (!cRecordControls::Start())
|
|
|
|
Interface->Error(tr("No free DVB device to record!"));
|
|
|
|
break;
|
|
|
|
case osRecordings:
|
|
|
|
DELETENULL(Menu);
|
|
|
|
DELETENULL(ReplayControl);
|
2001-10-20 11:23:27 +02:00
|
|
|
Menu = new cMenuMain(ReplayControl, osRecordings);
|
2001-09-23 14:36:38 +02:00
|
|
|
break;
|
|
|
|
case osReplay: DELETENULL(Menu);
|
|
|
|
DELETENULL(ReplayControl);
|
|
|
|
ReplayControl = new cReplayControl;
|
|
|
|
break;
|
|
|
|
case osStopReplay:
|
|
|
|
DELETENULL(*Interact);
|
|
|
|
DELETENULL(ReplayControl);
|
|
|
|
break;
|
|
|
|
case osSwitchDvb:
|
|
|
|
DELETENULL(*Interact);
|
|
|
|
Interface->Info(tr("Switching primary DVB..."));
|
|
|
|
cDvbApi::SetPrimaryDvbApi(Setup.PrimaryDVB);
|
|
|
|
break;
|
|
|
|
case osBack:
|
|
|
|
case osEnd: DELETENULL(*Interact);
|
|
|
|
break;
|
|
|
|
default: ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Key functions in "normal" viewing mode:
|
|
|
|
switch (key) {
|
|
|
|
// Toggle channels:
|
|
|
|
case k0: {
|
|
|
|
int CurrentChannel = cDvbApi::CurrentChannel();
|
|
|
|
Channels.SwitchTo(PreviousChannel);
|
|
|
|
PreviousChannel = CurrentChannel;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Direct Channel Select:
|
|
|
|
case k1 ... k9:
|
|
|
|
Menu = new cDisplayChannel(key);
|
|
|
|
break;
|
|
|
|
// Left/Right rotates trough channel groups:
|
|
|
|
case kLeft|k_Repeat:
|
|
|
|
case kLeft:
|
|
|
|
case kRight|k_Repeat:
|
|
|
|
case kRight:
|
|
|
|
Menu = new cDisplayChannel(NORMALKEY(key));
|
|
|
|
break;
|
|
|
|
// Up/Down Channel Select:
|
|
|
|
case kUp|k_Repeat:
|
|
|
|
case kUp:
|
|
|
|
case kDown|k_Repeat:
|
|
|
|
case kDown: {
|
|
|
|
int n = cDvbApi::CurrentChannel() + (NORMALKEY(key) == kUp ? 1 : -1);
|
|
|
|
cChannel *channel = Channels.GetByNumber(n);
|
|
|
|
if (channel)
|
|
|
|
channel->Switch();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Menu Control:
|
|
|
|
case kMenu: Menu = new cMenuMain(ReplayControl); break;
|
|
|
|
// Viewing Control:
|
|
|
|
case kOk: LastChannel = -1; break; // forces channel display
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-12-28 12:57:16 +01:00
|
|
|
if (!Menu) {
|
2000-11-18 13:57:32 +01:00
|
|
|
EITScanner.Process();
|
2002-01-26 13:42:15 +01:00
|
|
|
if (!cVideoCutter::Active() && cVideoCutter::Ended()) {
|
|
|
|
if (cVideoCutter::Error())
|
|
|
|
Interface->Error(tr("Editing process failed!"));
|
|
|
|
else
|
|
|
|
Interface->Info(tr("Editing process finished"));
|
|
|
|
}
|
2000-12-28 12:57:16 +01:00
|
|
|
}
|
2001-09-01 11:44:08 +02:00
|
|
|
if (!*Interact && (!cRecordControls::Active() || ForceShutdown)) {
|
2001-09-01 09:04:37 +02:00
|
|
|
time_t Now = time(NULL);
|
|
|
|
if (Now - LastActivity > ACTIVITYTIMEOUT) {
|
|
|
|
// Shutdown:
|
2001-11-03 11:49:39 +01:00
|
|
|
if (Shutdown && (Setup.MinUserInactivity || LastActivity == 1) && Now - LastActivity > Setup.MinUserInactivity * 60) {
|
2001-09-01 09:04:37 +02:00
|
|
|
cTimer *timer = Timers.GetNextActiveTimer();
|
2001-09-01 11:44:08 +02:00
|
|
|
time_t Next = timer ? timer->StartTime() : 0;
|
|
|
|
time_t Delta = timer ? Next - Now : 0;
|
2001-09-07 15:37:26 +02:00
|
|
|
if (!LastActivity) {
|
|
|
|
if (!timer || Delta > MANUALSTART) {
|
2001-09-01 11:44:08 +02:00
|
|
|
// Apparently the user started VDR manually
|
|
|
|
dsyslog(LOG_INFO, "assuming manual start of VDR");
|
|
|
|
LastActivity = Now;
|
2001-09-07 15:37:26 +02:00
|
|
|
continue; // don't run into the actual shutdown procedure below
|
2001-09-01 11:44:08 +02:00
|
|
|
}
|
2001-09-07 15:37:26 +02:00
|
|
|
else
|
|
|
|
LastActivity = 1;
|
|
|
|
}
|
2002-02-10 15:18:45 +01:00
|
|
|
bool UserShutdown = key == kPower;
|
|
|
|
if (UserShutdown && Next && Delta <= Setup.MinEventTimeout * 60 && !ForceShutdown) {
|
|
|
|
char *buf;
|
|
|
|
asprintf(&buf, tr("Recording in %d minutes, shut down anyway?"), Delta / 60);
|
|
|
|
if (Interface->Confirm(buf))
|
|
|
|
ForceShutdown = true;
|
|
|
|
delete buf;
|
|
|
|
}
|
2001-09-08 13:02:05 +02:00
|
|
|
if (!Next || Delta > Setup.MinEventTimeout * 60 || ForceShutdown) {
|
|
|
|
ForceShutdown = false;
|
2001-09-07 15:37:26 +02:00
|
|
|
if (timer)
|
|
|
|
dsyslog(LOG_INFO, "next timer event at %s", ctime(&Next));
|
2001-09-01 11:44:08 +02:00
|
|
|
if (WatchdogTimeout > 0)
|
|
|
|
signal(SIGALRM, SIG_IGN);
|
2001-11-03 12:23:45 +01:00
|
|
|
if (Interface->Confirm(tr("Press any key to cancel shutdown"), UserShutdown ? 5 : SHUTDOWNWAIT, true)) {
|
2001-09-30 12:35:09 +02:00
|
|
|
int Channel = timer ? timer->channel : 0;
|
|
|
|
const char *File = timer ? timer->file : "";
|
2001-09-01 11:44:08 +02:00
|
|
|
char *cmd;
|
2002-01-26 12:04:32 +01:00
|
|
|
asprintf(&cmd, "%s %ld %ld %d \"%s\" %d", Shutdown, Next, Delta, Channel, strescape(File, "\"$"), UserShutdown);
|
2001-09-01 11:44:08 +02:00
|
|
|
isyslog(LOG_INFO, "executing '%s'", cmd);
|
2001-10-20 10:39:27 +02:00
|
|
|
SystemExec(cmd);
|
2001-09-01 11:44:08 +02:00
|
|
|
delete cmd;
|
|
|
|
}
|
|
|
|
else if (WatchdogTimeout > 0) {
|
|
|
|
alarm(WatchdogTimeout);
|
|
|
|
if (signal(SIGALRM, Watchdog) == SIG_IGN)
|
2001-09-01 09:04:37 +02:00
|
|
|
signal(SIGALRM, SIG_IGN);
|
|
|
|
}
|
2002-01-26 14:09:21 +01:00
|
|
|
LastActivity = time(NULL); // don't try again too soon
|
2001-09-01 11:44:08 +02:00
|
|
|
continue; // skip the rest of the housekeeping for now
|
2001-09-01 09:04:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Disk housekeeping:
|
2001-02-11 14:53:44 +01:00
|
|
|
RemoveDeletedRecordings();
|
|
|
|
}
|
|
|
|
}
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
if (Interrupted)
|
|
|
|
isyslog(LOG_INFO, "caught signal %d", Interrupted);
|
2001-01-14 15:29:51 +01:00
|
|
|
Setup.CurrentChannel = cDvbApi::CurrentChannel();
|
2001-10-27 09:57:59 +02:00
|
|
|
Setup.CurrentVolume = cDvbApi::CurrentVolume();
|
2001-01-14 15:29:51 +01:00
|
|
|
Setup.Save();
|
2000-12-28 12:57:16 +01:00
|
|
|
cVideoCutter::Stop();
|
2000-04-30 10:22:13 +02:00
|
|
|
delete Menu;
|
|
|
|
delete ReplayControl;
|
2000-10-08 12:24:30 +02:00
|
|
|
delete Interface;
|
2000-05-01 16:29:46 +02:00
|
|
|
cDvbApi::Cleanup();
|
2001-02-24 16:18:43 +01:00
|
|
|
if (WatchdogTimeout > 0)
|
|
|
|
dsyslog(LOG_INFO, "max. latency time %d seconds", MaxLatencyTime);
|
2000-04-16 13:54:16 +02:00
|
|
|
isyslog(LOG_INFO, "exiting");
|
2000-07-29 19:03:09 +02:00
|
|
|
if (SysLogLevel > 0)
|
|
|
|
closelog();
|
2001-06-02 10:47:40 +02:00
|
|
|
if (cThread::EmergencyExit()) {
|
|
|
|
esyslog(LOG_ERR, "emergency exit!");
|
|
|
|
return 1;
|
|
|
|
}
|
2000-04-15 17:38:11 +02:00
|
|
|
return 0;
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|