vdr  2.4.7
vdr.c
Go to the documentation of this file.
1 /*
2  * vdr.c: Video Disk Recorder main program
3  *
4  * Copyright (C) 2000-2018 Klaus Schmidinger
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  * Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  *
21  * The author can be reached at vdr@tvdr.de
22  *
23  * The project's page is at http://www.tvdr.de
24  *
25  * $Id: vdr.c 4.34 2020/11/20 13:49:58 kls Exp $
26  */
27 
28 #include <getopt.h>
29 #include <grp.h>
30 #include <langinfo.h>
31 #include <locale.h>
32 #include <pwd.h>
33 #include <signal.h>
34 #include <stdlib.h>
35 #include <sys/capability.h>
36 #include <sys/prctl.h>
37 #ifdef SDNOTIFY
38 #include <systemd/sd-daemon.h>
39 #endif
40 #include <termios.h>
41 #include <unistd.h>
42 #include "args.h"
43 #include "audio.h"
44 #include "channels.h"
45 #include "config.h"
46 #include "cutter.h"
47 #include "device.h"
48 #include "diseqc.h"
49 #include "dvbdevice.h"
50 #include "eitscan.h"
51 #include "epg.h"
52 #include "i18n.h"
53 #include "interface.h"
54 #include "keys.h"
55 #include "libsi/si.h"
56 #include "lirc.h"
57 #include "menu.h"
58 #include "osdbase.h"
59 #include "plugin.h"
60 #include "recording.h"
61 #include "shutdown.h"
62 #include "skinclassic.h"
63 #include "skinlcars.h"
64 #include "skinsttng.h"
65 #include "sourceparams.h"
66 #include "sources.h"
67 #include "status.h"
68 #include "svdrp.h"
69 #include "themes.h"
70 #include "timers.h"
71 #include "tools.h"
72 #include "transfer.h"
73 #include "videodir.h"
74 
75 #define MINCHANNELWAIT 10 // seconds to wait between failed channel switchings
76 #define ACTIVITYTIMEOUT 60 // seconds before starting housekeeping
77 #define SHUTDOWNWAIT 300 // seconds to wait in user prompt before automatic shutdown
78 #define SHUTDOWNRETRY 360 // seconds before trying again to shut down
79 #define SHUTDOWNFORCEPROMPT 5 // seconds to wait in user prompt to allow forcing shutdown
80 #define SHUTDOWNCANCELPROMPT 5 // seconds to wait in user prompt to allow canceling shutdown
81 #define RESTARTCANCELPROMPT 5 // seconds to wait in user prompt before restarting on SIGHUP
82 #define MANUALSTART 600 // seconds the next timer must be in the future to assume manual start
83 #define CHANNELSAVEDELTA 600 // seconds before saving channels.conf after automatic modifications
84 #define DEVICEREADYTIMEOUT 30 // seconds to wait until all devices are ready
85 #define MENUTIMEOUT 120 // seconds of user inactivity after which an OSD display is closed
86 #define TIMERCHECKDELTA 10 // seconds between checks for timers that need to see their channel
87 #define TIMERDEVICETIMEOUT 8 // seconds before a device used for timer check may be reused
88 #define TIMERLOOKAHEADTIME 60 // seconds before a non-VPS timer starts and the channel is switched if possible
89 #define VPSLOOKAHEADTIME 24 // hours within which VPS timers will make sure their events are up to date
90 #define VPSUPTODATETIME 3600 // seconds before the event or schedule of a VPS timer needs to be refreshed
91 
92 #define EXIT(v) { ShutdownHandler.Exit(v); goto Exit; }
93 
94 static int LastSignal = 0;
95 
96 static bool SetUser(const char *User, bool UserDump)
97 {
98  if (User) {
99  struct passwd *user = isnumber(User) ? getpwuid(atoi(User)) : getpwnam(User);
100  if (!user) {
101  fprintf(stderr, "vdr: unknown user: '%s'\n", User);
102  return false;
103  }
104  if (setgid(user->pw_gid) < 0) {
105  fprintf(stderr, "vdr: cannot set group id %u: %s\n", (unsigned int)user->pw_gid, strerror(errno));
106  return false;
107  }
108  if (initgroups(user->pw_name, user->pw_gid) < 0) {
109  fprintf(stderr, "vdr: cannot set supplemental group ids for user %s: %s\n", user->pw_name, strerror(errno));
110  return false;
111  }
112  if (setuid(user->pw_uid) < 0) {
113  fprintf(stderr, "vdr: cannot set user id %u: %s\n", (unsigned int)user->pw_uid, strerror(errno));
114  return false;
115  }
116  if (UserDump && prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) < 0)
117  fprintf(stderr, "vdr: warning - cannot set dumpable: %s\n", strerror(errno));
118  setenv("HOME", user->pw_dir, 1);
119  setenv("USER", user->pw_name, 1);
120  setenv("LOGNAME", user->pw_name, 1);
121  setenv("SHELL", user->pw_shell, 1);
122  }
123  return true;
124 }
125 
126 static bool DropCaps(void)
127 {
128  // drop all capabilities except selected ones
129  cap_t caps_all = cap_get_proc();
130  if (!caps_all) {
131  fprintf(stderr, "vdr: cap_get_proc failed: %s\n", strerror(errno));
132  return false;
133  }
134  cap_flag_value_t cap_flag_value;
135  if (cap_get_flag(caps_all, CAP_SYS_TIME, CAP_PERMITTED , &cap_flag_value)) {
136  fprintf(stderr, "vdr: cap_get_flag failed: %s\n", strerror(errno));
137  return false;
138  }
139  cap_t caps;
140  if (cap_flag_value == CAP_SET)
141  caps = cap_from_text("= cap_sys_nice,cap_sys_time,cap_net_raw=ep");
142  else {
143  fprintf(stdout,"vdr: OS does not support cap_sys_time\n");
144  caps = cap_from_text("= cap_sys_nice,cap_net_raw=ep");
145  }
146  if (!caps) {
147  fprintf(stderr, "vdr: cap_from_text failed: %s\n", strerror(errno));
148  return false;
149  }
150  if (cap_set_proc(caps) == -1) {
151  fprintf(stderr, "vdr: cap_set_proc failed: %s\n", strerror(errno));
152  cap_free(caps);
153  return false;
154  }
155  cap_free(caps);
156  return true;
157 }
158 
159 static bool SetKeepCaps(bool On)
160 {
161  // set keeping capabilities during setuid() on/off
162  if (prctl(PR_SET_KEEPCAPS, On ? 1 : 0, 0, 0, 0) != 0) {
163  fprintf(stderr, "vdr: prctl failed\n");
164  return false;
165  }
166  return true;
167 }
168 
169 static void SignalHandler(int signum)
170 {
171  switch (signum) {
172  case SIGPIPE:
173  break;
174  case SIGHUP:
175  LastSignal = signum;
176  break;
177  default:
178  LastSignal = signum;
179  Interface->Interrupt();
181  }
182  signal(signum, SignalHandler);
183 }
184 
185 static void Watchdog(int signum)
186 {
187  // Something terrible must have happened that prevented the 'alarm()' from
188  // being called in time, so let's get out of here:
189  esyslog("PANIC: watchdog timer expired - exiting!");
190 #ifdef SDNOTIFY
191  sd_notify(0, "STOPPING=1\nSTATUS=PANIC");
192 #endif
193  exit(1);
194 }
195 
196 int main(int argc, char *argv[])
197 {
198  // Save terminal settings:
199 
200  struct termios savedTm;
201  bool HasStdin = (tcgetpgrp(STDIN_FILENO) == getpid() || getppid() != (pid_t)1) && tcgetattr(STDIN_FILENO, &savedTm) == 0;
202 
203  // Initiate locale:
204 
205  setlocale(LC_ALL, "");
206 
207  // Command line options:
208 
209 #define dd(a, b) (*a ? a : b)
210 #define DEFAULTSVDRPPORT 6419
211 #define DEFAULTWATCHDOG 0 // seconds
212 #define DEFAULTVIDEODIR VIDEODIR
213 #define DEFAULTCONFDIR dd(CONFDIR, VideoDirectory)
214 #define DEFAULTARGSDIR dd(ARGSDIR, "/etc/vdr/conf.d")
215 #define DEFAULTCACHEDIR dd(CACHEDIR, VideoDirectory)
216 #define DEFAULTRESDIR dd(RESDIR, ConfigDirectory)
217 #define DEFAULTPLUGINDIR PLUGINDIR
218 #define DEFAULTLOCDIR LOCDIR
219 #define DEFAULTEPGDATAFILENAME "epg.data"
220 
221  bool StartedAsRoot = false;
222  const char *VdrUser = NULL;
223  bool UserDump = false;
224  int SVDRPport = DEFAULTSVDRPPORT;
225  const char *AudioCommand = NULL;
226  const char *VideoDirectory = DEFAULTVIDEODIR;
227  const char *ConfigDirectory = NULL;
228  const char *CacheDirectory = NULL;
229  const char *ResourceDirectory = NULL;
230  const char *LocaleDirectory = DEFAULTLOCDIR;
231  const char *EpgDataFileName = DEFAULTEPGDATAFILENAME;
232  bool DisplayHelp = false;
233  bool DisplayVersion = false;
234  bool DaemonMode = false;
235  int SysLogTarget = LOG_USER;
236  bool MuteAudio = false;
237  int WatchdogTimeout = DEFAULTWATCHDOG;
238  const char *Terminal = NULL;
239  const char *OverrideCharacterTable = NULL;
240 #ifndef DEPRECATED_VDR_CHARSET_OVERRIDE
241 #define DEPRECATED_VDR_CHARSET_OVERRIDE 0
242 #endif
243 #if DEPRECATED_VDR_CHARSET_OVERRIDE
244  OverrideCharacterTable = getenv("VDR_CHARSET_OVERRIDE");
245  const char *DeprecatedVdrCharsetOverride = OverrideCharacterTable;
246 #endif
247 
248  bool UseKbd = true;
249  const char *LircDevice = NULL;
250 #if !defined(REMOTE_KBD)
251  UseKbd = false;
252 #endif
253 #if defined(REMOTE_LIRC)
254  LircDevice = LIRC_DEVICE;
255 #endif
256 #if defined(VDR_USER)
257  VdrUser = VDR_USER;
258 #endif
259 #ifdef SDNOTIFY
260  time_t SdWatchdog = 0;
261  int SdWatchdogTimeout = 0;
262 #endif
263 
264  cArgs *Args = NULL;
265  if (argc == 1) {
266  Args = new cArgs(argv[0]);
267  if (Args->ReadDirectory(DEFAULTARGSDIR)) {
268  argc = Args->GetArgc();
269  argv = Args->GetArgv();
270  }
271  }
272 
273  cVideoDirectory::SetName(VideoDirectory);
274  cPluginManager PluginManager(DEFAULTPLUGINDIR);
275 
276  static struct option long_options[] = {
277  { "audio", required_argument, NULL, 'a' },
278  { "cachedir", required_argument, NULL, 'c' | 0x100 },
279  { "chartab", required_argument, NULL, 'c' | 0x200 },
280  { "config", required_argument, NULL, 'c' },
281  { "daemon", no_argument, NULL, 'd' },
282  { "device", required_argument, NULL, 'D' },
283  { "dirnames", required_argument, NULL, 'd' | 0x100 },
284  { "edit", required_argument, NULL, 'e' | 0x100 },
285  { "epgfile", required_argument, NULL, 'E' },
286  { "filesize", required_argument, NULL, 'f' | 0x100 },
287  { "genindex", required_argument, NULL, 'g' | 0x100 },
288  { "grab", required_argument, NULL, 'g' },
289  { "help", no_argument, NULL, 'h' },
290  { "instance", required_argument, NULL, 'i' },
291  { "lib", required_argument, NULL, 'L' },
292  { "lirc", optional_argument, NULL, 'l' | 0x100 },
293  { "localedir",required_argument, NULL, 'l' | 0x200 },
294  { "log", required_argument, NULL, 'l' },
295  { "mute", no_argument, NULL, 'm' },
296  { "no-kbd", no_argument, NULL, 'n' | 0x100 },
297  { "plugin", required_argument, NULL, 'P' },
298  { "port", required_argument, NULL, 'p' },
299  { "record", required_argument, NULL, 'r' },
300  { "resdir", required_argument, NULL, 'r' | 0x100 },
301  { "showargs", optional_argument, NULL, 's' | 0x200 },
302  { "shutdown", required_argument, NULL, 's' },
303  { "split", no_argument, NULL, 's' | 0x100 },
304  { "terminal", required_argument, NULL, 't' },
305  { "updindex", required_argument, NULL, 'u' | 0x200 },
306  { "user", required_argument, NULL, 'u' },
307  { "userdump", no_argument, NULL, 'u' | 0x100 },
308  { "version", no_argument, NULL, 'V' },
309  { "vfat", no_argument, NULL, 'v' | 0x100 },
310  { "video", required_argument, NULL, 'v' },
311  { "watchdog", required_argument, NULL, 'w' },
312  { NULL, no_argument, NULL, 0 }
313  };
314 
315  int c;
316  while ((c = getopt_long(argc, argv, "a:c:dD:e:E:g:hi:l:L:mp:P:r:s:t:u:v:Vw:", long_options, NULL)) != -1) {
317  switch (c) {
318  case 'a': AudioCommand = optarg;
319  break;
320  case 'c' | 0x100:
321  CacheDirectory = optarg;
322  break;
323  case 'c' | 0x200:
324  OverrideCharacterTable = optarg;
325  break;
326  case 'c': ConfigDirectory = optarg;
327  break;
328  case 'd': DaemonMode = true;
329  break;
330  case 'D': if (*optarg == '-') {
332  break;
333  }
334  if (isnumber(optarg)) {
335  int n = atoi(optarg);
336  if (0 <= n && n < MAXDEVICES) {
338  break;
339  }
340  }
341  fprintf(stderr, "vdr: invalid DVB device number: %s\n", optarg);
342  return 2;
343  case 'd' | 0x100: {
344  char *s = optarg;
345  if (*s != ',') {
346  int n = strtol(s, &s, 10);
347  if (n <= 0 || n >= PATH_MAX) { // PATH_MAX includes the terminating 0
348  fprintf(stderr, "vdr: invalid directory path length: %s\n", optarg);
349  return 2;
350  }
351  DirectoryPathMax = n;
352  if (!*s)
353  break;
354  if (*s != ',') {
355  fprintf(stderr, "vdr: invalid delimiter: %s\n", optarg);
356  return 2;
357  }
358  }
359  s++;
360  if (!*s)
361  break;
362  if (*s != ',') {
363  int n = strtol(s, &s, 10);
364  if (n <= 0 || n > NAME_MAX) { // NAME_MAX excludes the terminating 0
365  fprintf(stderr, "vdr: invalid directory name length: %s\n", optarg);
366  return 2;
367  }
368  DirectoryNameMax = n;
369  if (!*s)
370  break;
371  if (*s != ',') {
372  fprintf(stderr, "vdr: invalid delimiter: %s\n", optarg);
373  return 2;
374  }
375  }
376  s++;
377  if (!*s)
378  break;
379  int n = strtol(s, &s, 10);
380  if (n != 0 && n != 1) {
381  fprintf(stderr, "vdr: invalid directory encoding: %s\n", optarg);
382  return 2;
383  }
384  DirectoryEncoding = n;
385  if (*s) {
386  fprintf(stderr, "vdr: unexpected data: %s\n", optarg);
387  return 2;
388  }
389  }
390  break;
391  case 'e' | 0x100:
392  return CutRecording(optarg) ? 0 : 2;
393  case 'E': EpgDataFileName = (*optarg != '-' ? optarg : NULL);
394  break;
395  case 'f' | 0x100:
396  Setup.MaxVideoFileSize = StrToNum(optarg) / MEGABYTE(1);
401  break;
402  case 'g' | 0x100:
403  return GenerateIndex(optarg) ? 0 : 2;
404  case 'g': SetSVDRPGrabImageDir(*optarg != '-' ? optarg : NULL);
405  break;
406  case 'h': DisplayHelp = true;
407  break;
408  case 'i': if (isnumber(optarg)) {
409  InstanceId = atoi(optarg);
410  if (InstanceId >= 0)
411  break;
412  }
413  fprintf(stderr, "vdr: invalid instance id: %s\n", optarg);
414  return 2;
415  case 'l': {
416  char *p = strchr(optarg, '.');
417  if (p)
418  *p = 0;
419  if (isnumber(optarg)) {
420  int l = atoi(optarg);
421  if (0 <= l && l <= 3) {
422  SysLogLevel = l;
423  if (!p)
424  break;
425  *p = '.';
426  if (isnumber(p + 1)) {
427  int l = atoi(p + 1);
428  if (0 <= l && l <= 7) {
429  int targets[] = { LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3, LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7 };
430  SysLogTarget = targets[l];
431  break;
432  }
433  }
434  }
435  }
436  if (p)
437  *p = '.';
438  fprintf(stderr, "vdr: invalid log level: %s\n", optarg);
439  return 2;
440  }
441  case 'L': if (access(optarg, R_OK | X_OK) == 0)
442  PluginManager.SetDirectory(optarg);
443  else {
444  fprintf(stderr, "vdr: can't access plugin directory: %s\n", optarg);
445  return 2;
446  }
447  break;
448  case 'l' | 0x100:
449  LircDevice = optarg ? optarg : LIRC_DEVICE;
450  break;
451  case 'l' | 0x200:
452  if (access(optarg, R_OK | X_OK) == 0)
453  LocaleDirectory = optarg;
454  else {
455  fprintf(stderr, "vdr: can't access locale directory: %s\n", optarg);
456  return 2;
457  }
458  break;
459  case 'm': MuteAudio = true;
460  break;
461  case 'n' | 0x100:
462  UseKbd = false;
463  break;
464  case 'p': if (isnumber(optarg))
465  SVDRPport = atoi(optarg);
466  else {
467  fprintf(stderr, "vdr: invalid port number: %s\n", optarg);
468  return 2;
469  }
470  break;
471  case 'P': PluginManager.AddPlugin(optarg);
472  break;
473  case 'r': cRecordingUserCommand::SetCommand(optarg);
474  break;
475  case 'r' | 0x100:
476  ResourceDirectory = optarg;
477  break;
478  case 's': ShutdownHandler.SetShutdownCommand(optarg);
479  break;
480  case 's' | 0x100:
482  break;
483  case 's' | 0x200: {
484  const char *ArgsDir = optarg ? optarg : DEFAULTARGSDIR;
485  cArgs Args(argv[0]);
486  if (!Args.ReadDirectory(ArgsDir)) {
487  fprintf(stderr, "vdr: can't read arguments from directory: %s\n", ArgsDir);
488  return 2;
489  }
490  int c = Args.GetArgc();
491  char **v = Args.GetArgv();
492  for (int i = 1; i < c; i++)
493  printf("%s\n", v[i]);
494  return 0;
495  }
496  case 't': Terminal = optarg;
497  if (access(Terminal, R_OK | W_OK) < 0) {
498  fprintf(stderr, "vdr: can't access terminal: %s\n", Terminal);
499  return 2;
500  }
501  break;
502  case 'u': if (*optarg)
503  VdrUser = optarg;
504  break;
505  case 'u' | 0x100:
506  UserDump = true;
507  break;
508  case 'u' | 0x200:
509  return GenerateIndex(optarg, true) ? 0 : 2;
510  case 'V': DisplayVersion = true;
511  break;
512  case 'v' | 0x100:
513  DirectoryPathMax = 250;
514  DirectoryNameMax = 40;
515  DirectoryEncoding = true;
516  break;
517  case 'v': VideoDirectory = optarg;
518  while (optarg && *optarg && optarg[strlen(optarg) - 1] == '/')
519  optarg[strlen(optarg) - 1] = 0;
520  cVideoDirectory::SetName(VideoDirectory);
521  break;
522  case 'w': if (isnumber(optarg)) {
523  int t = atoi(optarg);
524  if (t >= 0) {
525  WatchdogTimeout = t;
526  break;
527  }
528  }
529  fprintf(stderr, "vdr: invalid watchdog timeout: %s\n", optarg);
530  return 2;
531  default: return 2;
532  }
533  }
534 
535  // Set user id in case we were started as root:
536 
537  if (VdrUser && geteuid() == 0) {
538  StartedAsRoot = true;
539  if (strcmp(VdrUser, "root") && strcmp(VdrUser, "0")) {
540  if (!SetKeepCaps(true))
541  return 2;
542  if (!SetUser(VdrUser, UserDump))
543  return 2;
544  if (!SetKeepCaps(false))
545  return 2;
546  if (!DropCaps())
547  return 2;
548  }
549  }
550 
551  // Help and version info:
552 
553  if (DisplayHelp || DisplayVersion) {
554  if (!PluginManager.HasPlugins())
555  PluginManager.AddPlugin("*"); // adds all available plugins
556  PluginManager.LoadPlugins();
557  if (DisplayHelp) {
558  printf("Usage: vdr [OPTIONS]\n\n" // for easier orientation, this is column 80|
559  " -a CMD, --audio=CMD send Dolby Digital audio to stdin of command CMD\n"
560  " --cachedir=DIR save cache files in DIR (default: %s)\n"
561  " --chartab=CHARACTER_TABLE\n"
562  " set the character table to use for strings in the\n"
563  " DVB data stream that don't begin with a character\n"
564  " table indicator, but don't use the standard default\n"
565  " character table (for instance ISO-8859-9)\n"
566  " -c DIR, --config=DIR read config files from DIR (default: %s)\n"
567  " -d, --daemon run in daemon mode\n"
568  " -D NUM, --device=NUM use only the given DVB device (NUM = 0, 1, 2...)\n"
569  " there may be several -D options (default: all DVB\n"
570  " devices will be used); if -D- is given, no DVB\n"
571  " devices will be used at all, independent of any\n"
572  " other -D options\n"
573  " --dirnames=PATH[,NAME[,ENC]]\n"
574  " set the maximum directory path length to PATH\n"
575  " (default: %d); if NAME is also given, it defines\n"
576  " the maximum directory name length (default: %d);\n"
577  " the optional ENC can be 0 or 1, and controls whether\n"
578  " special characters in directory names are encoded as\n"
579  " hex values (default: 0); if PATH or NAME are left\n"
580  " empty (as in \",,1\" to only set ENC), the defaults\n"
581  " apply\n"
582  " --edit=REC cut recording REC and exit\n"
583  " -E FILE, --epgfile=FILE write the EPG data into the given FILE (default is\n"
584  " '%s' in the cache directory)\n"
585  " '-E-' disables this\n"
586  " if FILE is a directory, the default EPG file will be\n"
587  " created in that directory\n"
588  " --filesize=SIZE limit video files to SIZE bytes (default is %dM)\n"
589  " only useful in conjunction with --edit\n"
590  " --genindex=REC generate index for recording REC and exit\n"
591  " -g DIR, --grab=DIR write images from the SVDRP command GRAB into the\n"
592  " given DIR; DIR must be the full path name of an\n"
593  " existing directory, without any \"..\", double '/'\n"
594  " or symlinks (default: none, same as -g-)\n"
595  " -h, --help print this help and exit\n"
596  " -i ID, --instance=ID use ID as the id of this VDR instance (default: 0)\n"
597  " -l LEVEL, --log=LEVEL set log level (default: 3)\n"
598  " 0 = no logging, 1 = errors only,\n"
599  " 2 = errors and info, 3 = errors, info and debug\n"
600  " if logging should be done to LOG_LOCALn instead of\n"
601  " LOG_USER, add '.n' to LEVEL, as in 3.7 (n=0..7)\n"
602  " -L DIR, --lib=DIR search for plugins in DIR (default is %s)\n"
603  " --lirc[=PATH] use a LIRC remote control device, attached to PATH\n"
604  " (default: %s)\n"
605  " --localedir=DIR search for locale files in DIR (default is\n"
606  " %s)\n"
607  " -m, --mute mute audio of the primary DVB device at startup\n"
608  " --no-kbd don't use the keyboard as an input device\n"
609  " -p PORT, --port=PORT use PORT for SVDRP (default: %d)\n"
610  " 0 turns off SVDRP\n"
611  " -P OPT, --plugin=OPT load a plugin defined by the given options\n"
612  " -r CMD, --record=CMD call CMD before and after a recording, and after\n"
613  " a recording has been edited or deleted\n"
614  " --resdir=DIR read resource files from DIR (default: %s)\n"
615  " -s CMD, --shutdown=CMD call CMD to shutdown the computer\n"
616  " --split split edited files at the editing marks (only\n"
617  " useful in conjunction with --edit)\n"
618  " --showargs[=DIR] print the arguments read from DIR and exit\n"
619  " (default: %s)\n"
620  " -t TTY, --terminal=TTY controlling tty\n"
621  " -u USER, --user=USER run as user USER; only applicable if started as\n"
622  " root; USER can be a user name or a numerical id\n"
623  " --updindex=REC update index for recording REC and exit\n"
624  " --userdump allow coredumps if -u is given (debugging)\n"
625  " -v DIR, --video=DIR use DIR as video directory (default: %s)\n"
626  " -V, --version print version information and exit\n"
627  " --vfat for backwards compatibility (same as\n"
628  " --dirnames=250,40,1)\n"
629  " -w SEC, --watchdog=SEC activate the watchdog timer with a timeout of SEC\n"
630  " seconds (default: %d); '0' disables the watchdog\n"
631  "\n",
634  PATH_MAX - 1,
635  NAME_MAX,
639  LIRC_DEVICE,
646  );
647  }
648  if (DisplayVersion)
649  printf("vdr (%s/%s) - The Video Disk Recorder\n", VDRVERSION, APIVERSION);
650  if (PluginManager.HasPlugins()) {
651  if (DisplayHelp)
652  printf("Plugins: vdr -P\"name [OPTIONS]\"\n\n");
653  for (int i = 0; ; i++) {
654  cPlugin *p = PluginManager.GetPlugin(i);
655  if (p) {
656  const char *help = p->CommandLineHelp();
657  printf("%s (%s) - %s\n", p->Name(), p->Version(), p->Description());
658  if (DisplayHelp && help) {
659  printf("\n");
660  puts(help);
661  }
662  }
663  else
664  break;
665  }
666  }
667  return 0;
668  }
669 
670  // Log file:
671 
672  if (SysLogLevel > 0)
673  openlog("vdr", LOG_CONS, SysLogTarget); // LOG_PID doesn't work as expected under NPTL
674 
675  // Check the video directory:
676 
677  if (!DirectoryOk(VideoDirectory, true)) {
678  fprintf(stderr, "vdr: can't access video directory %s\n", VideoDirectory);
679  return 2;
680  }
681 
682  // Daemon mode:
683 
684  if (DaemonMode) {
685  if (daemon(1, 0) == -1) {
686  fprintf(stderr, "vdr: %m\n");
687  esyslog("ERROR: %m");
688  return 2;
689  }
690  }
691  else if (Terminal) {
692  // Claim new controlling terminal
693  stdin = freopen(Terminal, "r", stdin);
694  stdout = freopen(Terminal, "w", stdout);
695  stderr = freopen(Terminal, "w", stderr);
696  HasStdin = true;
697  tcgetattr(STDIN_FILENO, &savedTm);
698  }
699 
700  isyslog("VDR version %s started", VDRVERSION);
701  if (StartedAsRoot && VdrUser)
702  isyslog("switched to user '%s'", VdrUser);
703  if (DaemonMode)
704  dsyslog("running as daemon (tid=%d)", cThread::ThreadId());
706 
707  // Set the system character table:
708 
709  char *CodeSet = NULL;
710  if (setlocale(LC_CTYPE, ""))
711  CodeSet = nl_langinfo(CODESET);
712  else {
713  char *LangEnv = getenv("LANG"); // last resort in case locale stuff isn't installed
714  if (LangEnv) {
715  CodeSet = strchr(LangEnv, '.');
716  if (CodeSet)
717  CodeSet++; // skip the dot
718  }
719  }
720  if (CodeSet) {
721  bool known = SI::SetSystemCharacterTable(CodeSet);
722  isyslog("codeset is '%s' - %s", CodeSet, known ? "known" : "unknown");
724  }
725 #if DEPRECATED_VDR_CHARSET_OVERRIDE
726  if (DeprecatedVdrCharsetOverride)
727  isyslog("use of environment variable VDR_CHARSET_OVERRIDE (%s) is deprecated!", DeprecatedVdrCharsetOverride);
728 #endif
731  isyslog("override character table is '%s' - %s", OverrideCharacterTable, known ? "known" : "unknown");
732  }
733 
734  // Initialize internationalization:
735 
736  I18nInitialize(LocaleDirectory);
737 
738  // Main program loop variables - need to be here to have them initialized before any EXIT():
739 
740  cEpgDataReader EpgDataReader;
741  cOsdObject *Menu = NULL;
742  int LastChannel = 0;
743  int LastTimerChannel = -1;
744  int PreviousChannel[2] = { 1, 1 };
745  int PreviousChannelIndex = 0;
746  time_t LastChannelChanged = time(NULL);
747  time_t LastInteract = 0;
748  int MaxLatencyTime = 0;
749  bool InhibitEpgScan = false;
750  bool IsInfoMenu = false;
751  cSkin *CurrentSkin = NULL;
752  int OldPrimaryDVB = 0;
753 
754  // Load plugins:
755 
756  if (!PluginManager.LoadPlugins(true))
757  EXIT(2);
758 
759  // Directories:
760 
761  if (!ConfigDirectory)
762  ConfigDirectory = DEFAULTCONFDIR;
763  cPlugin::SetConfigDirectory(ConfigDirectory);
764  if (!CacheDirectory)
765  CacheDirectory = DEFAULTCACHEDIR;
766  cPlugin::SetCacheDirectory(CacheDirectory);
767  if (!ResourceDirectory)
768  ResourceDirectory = DEFAULTRESDIR;
769  cPlugin::SetResourceDirectory(ResourceDirectory);
770  cThemes::SetThemesDirectory("/var/lib/vdr/data/themes");
771 
772  // Configuration data:
773 
774  Setup.Load(AddDirectory(ConfigDirectory, "setup.conf"));
775  Sources.Load(AddDirectory(ConfigDirectory, "sources.conf"), true, true);
776  Diseqcs.Load(AddDirectory(ConfigDirectory, "diseqc.conf"), true, Setup.DiSEqC);
777  Scrs.Load(AddDirectory(ConfigDirectory, "scr.conf"), true);
778  cChannels::Load(AddDirectory(ConfigDirectory, "channels.conf"), false, true);
779  cTimers::Load(AddDirectory(ConfigDirectory, "timers.conf"));
780  Commands.Load(AddDirectory(ConfigDirectory, "commands.conf"));
781  RecordingCommands.Load(AddDirectory(ConfigDirectory, "reccmds.conf"));
782  SVDRPhosts.Load(AddDirectory(ConfigDirectory, "svdrphosts.conf"), true);
783  Keys.Load(AddDirectory(ConfigDirectory, "remote.conf"));
784  KeyMacros.Load(AddDirectory(ConfigDirectory, "keymacros.conf"), true);
785  Folders.Load(AddDirectory(ConfigDirectory, "folders.conf"));
786  CamResponsesLoad(AddDirectory(ConfigDirectory, "camresponses.conf"), true);
787 
789  const char *msg = "no fonts available - OSD will not show any text!";
790  fprintf(stderr, "vdr: %s\n", msg);
791  esyslog("ERROR: %s", msg);
792  }
793 
794  // Recordings:
795 
797 
798  // EPG data:
799 
800  if (EpgDataFileName) {
801  const char *EpgDirectory = NULL;
802  if (DirectoryOk(EpgDataFileName)) {
803  EpgDirectory = EpgDataFileName;
804  EpgDataFileName = DEFAULTEPGDATAFILENAME;
805  }
806  else if (*EpgDataFileName != '/' && *EpgDataFileName != '.')
807  EpgDirectory = CacheDirectory;
808  if (EpgDirectory)
809  cSchedules::SetEpgDataFileName(AddDirectory(EpgDirectory, EpgDataFileName));
810  else
811  cSchedules::SetEpgDataFileName(EpgDataFileName);
812  EpgDataReader.Start();
813  }
814 
815  // DVB interfaces:
816 
819 
820  // Initialize plugins:
821 
822  if (!PluginManager.InitializePlugins())
823  EXIT(2);
824 
825  // Primary device:
826 
828  if (!cDevice::PrimaryDevice() || !cDevice::PrimaryDevice()->HasDecoder()) {
829  if (cDevice::PrimaryDevice() && !cDevice::PrimaryDevice()->HasDecoder())
830  isyslog("device %d has no MPEG decoder", cDevice::PrimaryDevice()->DeviceNumber() + 1);
831  for (int i = 0; i < cDevice::NumDevices(); i++) {
832  cDevice *d = cDevice::GetDevice(i);
833  if (d && d->HasDecoder()) {
834  isyslog("trying device number %d instead", i + 1);
835  if (cDevice::SetPrimaryDevice(i + 1)) {
836  Setup.PrimaryDVB = i + 1;
837  break;
838  }
839  }
840  }
841  if (!cDevice::PrimaryDevice()) {
842  const char *msg = "no primary device found - using first device!";
843  fprintf(stderr, "vdr: %s\n", msg);
844  esyslog("ERROR: %s", msg);
846  EXIT(2);
847  if (!cDevice::PrimaryDevice()) {
848  const char *msg = "no primary device found - giving up!";
849  fprintf(stderr, "vdr: %s\n", msg);
850  esyslog("ERROR: %s", msg);
851  EXIT(2);
852  }
853  }
854  }
855  OldPrimaryDVB = Setup.PrimaryDVB;
856 
857  // Check for timers in automatic start time window:
858 
860 
861  // User interface:
862 
863  Interface = new cInterface;
864 
865  // Default skins:
866 
867  new cSkinLCARS;
868  new cSkinSTTNG;
869  new cSkinClassic;
872  CurrentSkin = Skins.Current();
873 
874  // Start plugins:
875 
876  if (!PluginManager.StartPlugins())
877  EXIT(2);
878 
879  // Set skin and theme in case they're implemented by a plugin:
880 
881  if (!CurrentSkin || CurrentSkin == Skins.Current() && strcmp(Skins.Current()->Name(), Setup.OSDSkin) != 0) {
884  }
885 
886  // Remote Controls:
887  if (LircDevice)
888  new cLircRemote(LircDevice);
889  if (!DaemonMode && HasStdin && UseKbd)
890  new cKbdRemote;
891  Interface->LearnKeys();
892 
893  // External audio:
894 
895  if (AudioCommand)
896  new cExternalAudio(AudioCommand);
897 
898  // Positioner:
899 
900  if (!cPositioner::GetPositioner()) // no plugin has created a positioner
901  new cDiseqcPositioner;
902 
903  // CAM data:
904 
905  ChannelCamRelations.Load(AddDirectory(CacheDirectory, "cam.data"));
906 
907  // Channel:
908 
910  dsyslog("not all devices ready after %d seconds", DEVICEREADYTIMEOUT);
912  dsyslog("not all CAM slots ready after %d seconds", DEVICEREADYTIMEOUT);
913  if (*Setup.InitialChannel) {
915  if (isnumber(Setup.InitialChannel)) { // for compatibility with old setup.conf files
916  if (const cChannel *Channel = Channels->GetByNumber(atoi(Setup.InitialChannel)))
917  Setup.InitialChannel = Channel->GetChannelID().ToString();
918  }
919  if (const cChannel *Channel = Channels->GetByChannelID(tChannelID::FromString(Setup.InitialChannel)))
920  Setup.CurrentChannel = Channel->Number();
921  }
922  if (Setup.InitialVolume >= 0)
924  {
926  Channels->SwitchTo(Setup.CurrentChannel);
927  }
928  if (MuteAudio)
930  else
932 
933  // Signal handlers:
934 
935  if (signal(SIGHUP, SignalHandler) == SIG_IGN) signal(SIGHUP, SIG_IGN);
936  if (signal(SIGINT, SignalHandler) == SIG_IGN) signal(SIGINT, SIG_IGN);
937  if (signal(SIGTERM, SignalHandler) == SIG_IGN) signal(SIGTERM, SIG_IGN);
938  if (signal(SIGPIPE, SignalHandler) == SIG_IGN) signal(SIGPIPE, SIG_IGN);
939  if (WatchdogTimeout > 0)
940  if (signal(SIGALRM, Watchdog) == SIG_IGN) signal(SIGALRM, SIG_IGN);
941 
942  // Watchdog:
943 
944  if (WatchdogTimeout > 0) {
945  dsyslog("setting watchdog timer to %d seconds", WatchdogTimeout);
946  alarm(WatchdogTimeout); // Initial watchdog timer start
947  }
948 
949 #ifdef SDNOTIFY
950  if (sd_watchdog_enabled(0, NULL) > 0) {
951  uint64_t timeout;
952  SdWatchdog = time(NULL);
953  sd_watchdog_enabled(0, &timeout);
954  SdWatchdogTimeout = (int)timeout/1000000;
955  dsyslog("SD_WATCHDOG enabled with timeout set to %d seconds", SdWatchdogTimeout);
956  }
957 
958  // Startup notification:
959 
960  sd_notify(0, "READY=1\nSTATUS=Ready");
961 #endif
962 
963  // SVDRP:
964 
965  SetSVDRPPorts(SVDRPport, DEFAULTSVDRPPORT);
967 
968  // Main program loop:
969 
970 #define DELETE_MENU ((IsInfoMenu &= (Menu == NULL)), delete Menu, Menu = NULL)
971 
972  while (!ShutdownHandler.DoExit()) {
973 #ifdef DEBUGRINGBUFFERS
974  cRingBufferLinear::PrintDebugRBL();
975 #endif
976  // Attach launched player control:
978 
979  time_t Now = time(NULL);
980 
981  // Make sure we have a visible programme in case device usage has changed:
983  static time_t lastTime = 0;
984  if (!cDevice::PrimaryDevice()->HasProgramme()) {
985  if (!CamMenuActive() && Now - lastTime > MINCHANNELWAIT) { // !CamMenuActive() to avoid interfering with the CAM if a CAM menu is open
987  const cChannel *Channel = Channels->GetByNumber(cDevice::CurrentChannel());
988  if (Channel && (Channel->Vpid() || Channel->Apid(0) || Channel->Dpid(0))) {
989  if (cDevice::GetDeviceForTransponder(Channel, LIVEPRIORITY) && Channels->SwitchTo(Channel->Number())) // try to switch to the original channel...
990  ;
991  else if (LastTimerChannel > 0) {
992  Channel = Channels->GetByNumber(LastTimerChannel);
993  if (Channel && cDevice::GetDeviceForTransponder(Channel, LIVEPRIORITY) && Channels->SwitchTo(LastTimerChannel)) // ...or the one used by the last timer
994  ;
995  }
996  }
997  lastTime = Now; // don't do this too often
998  LastTimerChannel = -1;
999  }
1000  }
1001  else
1002  lastTime = 0; // makes sure we immediately try again next time
1003  }
1004  // Update the OSD size:
1005  {
1006  static time_t lastOsdSizeUpdate = 0;
1007  if (Now != lastOsdSizeUpdate) { // once per second
1009  static int OsdState = 0;
1010  if (cOsdProvider::OsdSizeChanged(OsdState)) {
1011  if (cOsdMenu *OsdMenu = dynamic_cast<cOsdMenu *>(Menu))
1012  OsdMenu->Display();
1013  }
1014  lastOsdSizeUpdate = Now;
1015  }
1016  }
1017  // Restart the Watchdog timer:
1018  if (WatchdogTimeout > 0) {
1019  int LatencyTime = WatchdogTimeout - alarm(WatchdogTimeout);
1020  if (LatencyTime > MaxLatencyTime) {
1021  MaxLatencyTime = LatencyTime;
1022  dsyslog("max. latency time %d seconds", MaxLatencyTime);
1023  }
1024  }
1025 #ifdef SDNOTIFY
1026  // Ping systemd watchdog when half the timeout is elapsed:
1027  if (SdWatchdogTimeout && (Now - SdWatchdog) * 2 > SdWatchdogTimeout) {
1028  sd_notify(0, "WATCHDOG=1");
1029  SdWatchdog = Now;
1030  dsyslog("SD_WATCHDOG ping");
1031  }
1032 #endif
1033  // Handle channel and timer modifications:
1034  static bool ChannelsRenumber = false;
1035  {
1036  // Channels and timers need to be stored in a consistent manner,
1037  // therefore if one of them is changed, we save both.
1038  static time_t ChannelSaveTimeout = 0;
1039  static cStateKey TimersStateKey(true);
1040  static cStateKey ChannelsStateKey(true);
1041  static int ChannelsModifiedByUser = 0;
1042  const cTimers *Timers = cTimers::GetTimersRead(TimersStateKey);
1043  const cChannels *Channels = cChannels::GetChannelsRead(ChannelsStateKey);
1044  if (ChannelSaveTimeout != 1) {
1045  if (Channels) {
1046  if (Channels->ModifiedByUser(ChannelsModifiedByUser))
1047  ChannelSaveTimeout = 1; // triggers an immediate save
1048  else if (!ChannelSaveTimeout)
1049  ChannelSaveTimeout = Now + CHANNELSAVEDELTA;
1050  }
1051  if (Timers)
1052  ChannelSaveTimeout = 1; // triggers an immediate save
1053  }
1054  if (ChannelSaveTimeout && Now > ChannelSaveTimeout && !cRecordControls::Active())
1055  ChannelSaveTimeout = 1; // triggers an immediate save
1056  if (Timers && Channels) {
1057  Channels->Save();
1058  Timers->Save();
1059  ChannelSaveTimeout = 0;
1060  }
1061  if (Channels) {
1062  for (const cChannel *Channel = Channels->First(); Channel; Channel = Channels->Next(Channel)) {
1063  int ChannelModification = Channel->Modification(CHANNELMOD_ALL);
1064  if (ChannelModification & CHANNELMOD_TRANSP)
1065  ChannelsRenumber = true;
1066  if (ChannelModification & CHANNELMOD_RETUNE) {
1068  if (Channel->Number() == cDevice::CurrentChannel() && cDevice::PrimaryDevice()->HasDecoder()) {
1069  if (!cDevice::PrimaryDevice()->Replaying() || cDevice::PrimaryDevice()->Transferring()) {
1070  if (cDevice::ActualDevice()->ProvidesTransponder(Channel)) { // avoids retune on devices that don't really access the transponder
1071  isyslog("retuning due to modification of channel %d (%s)", Channel->Number(), Channel->Name());
1072  Channels->SwitchTo(Channel->Number());
1073  }
1074  }
1075  }
1076  cStatus::MsgChannelChange(Channel);
1077  }
1078  }
1079  }
1080  // State keys are removed in reverse order!
1081  if (Channels)
1082  ChannelsStateKey.Remove();
1083  if (Timers)
1084  TimersStateKey.Remove();
1085  if (ChannelSaveTimeout == 1) {
1086  // Only one of them was modified, so we reset the state keys to handle them both in the next turn:
1087  ChannelsStateKey.Reset();
1088  TimersStateKey.Reset();
1089  }
1090  }
1091  // Channel display:
1092  if (!EITScanner.Active() && cDevice::CurrentChannel() != LastChannel) {
1093  if (!Menu)
1094  Menu = new cDisplayChannel(cDevice::CurrentChannel(), LastChannel >= 0);
1095  LastChannel = cDevice::CurrentChannel();
1096  LastChannelChanged = Now;
1097  }
1098  if (Now - LastChannelChanged >= Setup.ZapTimeout && LastChannel != PreviousChannel[PreviousChannelIndex])
1099  PreviousChannel[PreviousChannelIndex ^= 1] = LastChannel;
1100  {
1101  // Timers and Recordings:
1102  static cStateKey TimersStateKey;
1103  cTimers *Timers = cTimers::GetTimersWrite(TimersStateKey);
1104  {
1105  // Assign events to timers:
1106  static cStateKey SchedulesStateKey;
1107  if (TimersStateKey.StateChanged())
1108  SchedulesStateKey.Reset(); // we assign events if either the Timers or the Schedules have changed
1109  bool TimersModified = false;
1110  if (const cSchedules *Schedules = cSchedules::GetSchedulesRead(SchedulesStateKey)) {
1112  if (Timers->SetEvents(Schedules))
1113  TimersModified = true;
1114  SchedulesStateKey.Remove();
1115  }
1116  TimersStateKey.Remove(TimersModified); // we need to remove the key here, so that syncing StateKeySVDRPRemoteTimersPoll takes effect!
1117  }
1118  // Must do all following calls with the exact same time!
1119  // Process ongoing recordings:
1120  Timers = cTimers::GetTimersWrite(TimersStateKey);
1121  bool TimersModified = false;
1122  if (cRecordControls::Process(Timers, Now))
1123  TimersModified = true;
1124  // Start new recordings:
1125  if (cTimer *Timer = Timers->GetMatch(Now)) {
1126  if (!cRecordControls::Start(Timers, Timer))
1127  Timer->SetPending(true);
1128  else
1129  LastTimerChannel = Timer->Channel()->Number();
1130  TimersModified = true;
1131  }
1132  // Make sure timers "see" their channel early enough:
1133  static time_t LastTimerCheck = 0;
1134  if (Now - LastTimerCheck > TIMERCHECKDELTA) { // don't do this too often
1135  InhibitEpgScan = false;
1136  for (cTimer *Timer = Timers->First(); Timer; Timer = Timers->Next(Timer)) {
1137  if (Timer->Remote())
1138  continue;
1139  bool InVpsMargin = false;
1140  bool NeedsTransponder = false;
1141  if (Timer->HasFlags(tfActive) && !Timer->Recording()) {
1142  if (Timer->HasFlags(tfVps)) {
1143  if (Timer->Matches(Now, true, Setup.VpsMargin)) {
1144  InVpsMargin = true;
1145  Timer->SetInVpsMargin(InVpsMargin);
1146  }
1147  else if (Timer->Event()) {
1148  InVpsMargin = Timer->Event()->StartTime() <= Now && Now < Timer->Event()->EndTime();
1149  NeedsTransponder = Timer->Event()->StartTime() - Now < VPSLOOKAHEADTIME * 3600 && !Timer->Event()->SeenWithin(VPSUPTODATETIME);
1150  }
1151  else {
1153  const cSchedule *Schedule = Schedules->GetSchedule(Timer->Channel());
1154  InVpsMargin = !Schedule; // we must make sure we have the schedule
1155  NeedsTransponder = Schedule && !Schedule->PresentSeenWithin(VPSUPTODATETIME);
1156  }
1157  InhibitEpgScan |= InVpsMargin | NeedsTransponder;
1158  }
1159  else
1160  NeedsTransponder = Timer->Matches(Now, true, TIMERLOOKAHEADTIME);
1161  }
1162  if (NeedsTransponder || InVpsMargin) {
1163  // Find a device that provides the required transponder:
1164  cDevice *Device = cDevice::GetDeviceForTransponder(Timer->Channel(), MINPRIORITY);
1165  if (!Device && InVpsMargin)
1166  Device = cDevice::GetDeviceForTransponder(Timer->Channel(), LIVEPRIORITY);
1167  // Switch the device to the transponder:
1168  if (Device) {
1169  bool HadProgramme = cDevice::PrimaryDevice()->HasProgramme();
1170  if (!Device->IsTunedToTransponder(Timer->Channel())) {
1171  if (Device == cDevice::ActualDevice() && !Device->IsPrimaryDevice())
1172  cDevice::PrimaryDevice()->StopReplay(); // stop transfer mode
1173  dsyslog("switching device %d to channel %d %s (%s)", Device->DeviceNumber() + 1, Timer->Channel()->Number(), *Timer->Channel()->GetChannelID().ToString(), Timer->Channel()->Name());
1174  if (Device->SwitchChannel(Timer->Channel(), false))
1176  }
1177  if (cDevice::PrimaryDevice()->HasDecoder() && HadProgramme && !cDevice::PrimaryDevice()->HasProgramme())
1178  Skins.QueueMessage(mtInfo, tr("Upcoming recording!")); // the previous SwitchChannel() has switched away the current live channel
1179  }
1180  }
1181  }
1182  LastTimerCheck = Now;
1183  }
1184  // Delete expired timers:
1185  if (Timers->DeleteExpired())
1186  TimersModified = true;
1187  // Make sure there is enough free disk space for ongoing recordings:
1188  int MaxPriority = Timers->GetMaxPriority();
1189  if (MaxPriority >= 0)
1190  AssertFreeDiskSpace(MaxPriority);
1191  TimersStateKey.Remove(TimersModified);
1192  }
1193  // Renumber channels on LCN update
1194  if (ChannelsRenumber) {
1196  Channels->ReNumber();
1197  ChannelsRenumber = false;
1198  }
1199  // Recordings:
1200  if (!Menu) {
1203  }
1204  // CAM control:
1205  if (!Menu && !cOsd::IsOpen())
1206  Menu = CamControl();
1207  // Queued messages:
1209  // User Input:
1210  bool NeedsFastResponse = Menu && Menu->NeedsFastResponse();
1211  if (!NeedsFastResponse) {
1212  // Must limit the scope of ControlMutexLock here to not hold the lock during the call to Interface->GetKey().
1213  cMutexLock ControlMutexLock;
1214  cControl *Control = cControl::Control(ControlMutexLock);
1215  NeedsFastResponse = Control && Control->NeedsFastResponse();
1216  }
1217  eKeys key = Interface->GetKey(!NeedsFastResponse);
1218  cOsdObject *Interact = Menu;
1219  cMutexLock ControlMutexLock;
1220  cControl *Control = NULL;
1221  if (!Menu)
1222  Interact = Control = cControl::Control(ControlMutexLock);
1223  if (ISREALKEY(key)) {
1224  EITScanner.Activity();
1225  // Cancel shutdown countdown:
1228  // Set user active for MinUserInactivity time in the future:
1230  }
1231  // Keys that must work independent of any interactive mode:
1232  switch (int(key)) {
1233  // Menu control:
1234  case kMenu: {
1235  key = kNone; // nobody else needs to see this key
1236  bool WasOpen = Interact != NULL;
1237  bool WasMenu = Interact && Interact->IsMenu();
1238  if (Menu)
1239  DELETE_MENU;
1240  else if (Control) {
1241  if (cOsd::IsOpen())
1242  Control->Hide();
1243  else
1244  WasOpen = false;
1245  }
1246  if (!WasOpen || !WasMenu && !Setup.MenuKeyCloses)
1247  Menu = new cMenuMain;
1248  }
1249  break;
1250  // Info:
1251  case kInfo: {
1252  if (IsInfoMenu) {
1253  key = kNone; // nobody else needs to see this key
1254  DELETE_MENU;
1255  }
1256  else if (!Menu) {
1257  IsInfoMenu = true;
1258  if (Control) {
1259  Control->Hide();
1260  Menu = Control->GetInfo();
1261  if (Menu)
1262  Menu->Show();
1263  else
1264  IsInfoMenu = false;
1265  }
1266  else {
1267  cRemote::Put(kOk, true);
1268  cRemote::Put(kSchedule, true);
1269  }
1270  key = kNone; // nobody else needs to see this key
1271  }
1272  }
1273  break;
1274  // Direct main menu functions:
1275  #define DirectMainFunction(function)\
1276  { DELETE_MENU;\
1277  if (Control)\
1278  Control->Hide();\
1279  Menu = new cMenuMain(function);\
1280  key = kNone; } // nobody else needs to see this key
1281  case kSchedule: DirectMainFunction(osSchedule); break;
1282  case kChannels: DirectMainFunction(osChannels); break;
1283  case kTimers: DirectMainFunction(osTimers); break;
1285  case kSetup: DirectMainFunction(osSetup); break;
1286  case kCommands: DirectMainFunction(osCommands); break;
1287  case kUser0 ... kUser9: cRemote::PutMacro(key); key = kNone; break;
1288  case k_Plugin: {
1289  const char *PluginName = cRemote::GetPlugin();
1290  if (PluginName) {
1291  DELETE_MENU;
1292  if (Control)
1293  Control->Hide();
1294  cPlugin *plugin = cPluginManager::GetPlugin(PluginName);
1295  if (plugin) {
1296  Menu = plugin->MainMenuAction();
1297  if (Menu)
1298  Menu->Show();
1299  }
1300  else
1301  esyslog("ERROR: unknown plugin '%s'", PluginName);
1302  }
1303  key = kNone; // nobody else needs to see these keys
1304  }
1305  break;
1306  // Channel up/down:
1307  case kChanUp|k_Repeat:
1308  case kChanUp:
1309  case kChanDn|k_Repeat:
1310  case kChanDn:
1311  if (!Interact) {
1312  Menu = new cDisplayChannel(NORMALKEY(key));
1313  continue;
1314  }
1315  else if (cDisplayChannel::IsOpen() || Control) {
1316  Interact->ProcessKey(key);
1317  continue;
1318  }
1319  else
1320  cDevice::SwitchChannel(NORMALKEY(key) == kChanUp ? 1 : -1);
1321  break;
1322  // Volume control:
1323  case kVolUp|k_Repeat:
1324  case kVolUp:
1325  case kVolDn|k_Repeat:
1326  case kVolDn:
1327  case kMute:
1328  if (key == kMute) {
1329  if (!cDevice::PrimaryDevice()->ToggleMute() && !Menu) {
1330  key = kNone; // nobody else needs to see these keys
1331  break; // no need to display "mute off"
1332  }
1333  }
1334  else
1336  if (!Menu && !cOsd::IsOpen())
1337  Menu = cDisplayVolume::Create();
1339  key = kNone; // nobody else needs to see these keys
1340  break;
1341  // Audio track control:
1342  case kAudio:
1343  if (Control)
1344  Control->Hide();
1345  if (!cDisplayTracks::IsOpen()) {
1346  DELETE_MENU;
1347  Menu = cDisplayTracks::Create();
1348  }
1349  else
1351  key = kNone;
1352  break;
1353  // Subtitle track control:
1354  case kSubtitles:
1355  if (Control)
1356  Control->Hide();
1358  DELETE_MENU;
1360  }
1361  else
1363  key = kNone;
1364  break;
1365  // Pausing live video:
1366  case kPlayPause:
1367  case kPause:
1368  if (!Control) {
1369  DELETE_MENU;
1370  if (Setup.PauseKeyHandling) {
1371  if (Setup.PauseKeyHandling > 1 || Interface->Confirm(tr("Pause live video?"))) {
1373  Skins.QueueMessage(mtError, tr("No free DVB device to record!"));
1374  }
1375  }
1376  key = kNone; // nobody else needs to see this key
1377  }
1378  break;
1379  // Instant recording:
1380  case kRecord:
1381  if (!Control) {
1382  if (Setup.RecordKeyHandling) {
1383  if (Setup.RecordKeyHandling > 1 || Interface->Confirm(tr("Start recording?"))) {
1384  if (cRecordControls::Start())
1385  Skins.QueueMessage(mtInfo, tr("Recording started"));
1386  }
1387  }
1388  key = kNone; // nobody else needs to see this key
1389  }
1390  break;
1391  // Power off:
1392  case kPower:
1393  isyslog("Power button pressed");
1394  DELETE_MENU;
1395  // Check for activity, request power button again if active:
1396  if (!ShutdownHandler.ConfirmShutdown(false) && Skins.Message(mtWarning, tr("VDR will shut down later - press Power to force"), SHUTDOWNFORCEPROMPT) != kPower) {
1397  // Not pressed power - set VDR to be non-interactive and power down later:
1399  break;
1400  }
1401  // No activity or power button pressed twice - ask for confirmation:
1402  if (!ShutdownHandler.ConfirmShutdown(true)) {
1403  // Non-confirmed background activity - set VDR to be non-interactive and power down later:
1405  break;
1406  }
1407  // Ask the final question:
1408  if (!Interface->Confirm(tr("Press any key to cancel shutdown"), SHUTDOWNCANCELPROMPT, true))
1409  // If final question was canceled, continue to be active:
1410  break;
1411  // Ok, now call the shutdown script:
1413  // Set VDR to be non-interactive and power down again later:
1415  // Do not attempt to automatically shut down for a while:
1417  break;
1418  default: break;
1419  }
1420  Interact = Menu ? Menu : Control; // might have been closed in the mean time
1421  if (Interact) {
1422  LastInteract = Now;
1423  eOSState state = Interact->ProcessKey(key);
1424  if (state == osUnknown && Interact != Control) {
1425  if (ISMODELESSKEY(key) && Control) {
1426  state = Control->ProcessKey(key);
1427  if (state == osEnd) {
1428  // let's not close a menu when replay ends:
1429  Control = NULL;
1431  continue;
1432  }
1433  }
1434  else if (Now - cRemote::LastActivity() > MENUTIMEOUT)
1435  state = osEnd;
1436  }
1437  switch (state) {
1438  case osPause: DELETE_MENU;
1440  Skins.QueueMessage(mtError, tr("No free DVB device to record!"));
1441  break;
1442  case osRecord: DELETE_MENU;
1443  if (cRecordControls::Start())
1444  Skins.QueueMessage(mtInfo, tr("Recording started"));
1445  break;
1446  case osRecordings:
1447  DELETE_MENU;
1448  Control = NULL;
1450  Menu = new cMenuMain(osRecordings, true);
1451  break;
1452  case osReplay: DELETE_MENU;
1453  Control = NULL;
1456  break;
1457  case osStopReplay:
1458  DELETE_MENU;
1459  Control = NULL;
1461  break;
1462  case osPlugin: DELETE_MENU;
1463  Menu = cMenuMain::PluginOsdObject();
1464  if (Menu)
1465  Menu->Show();
1466  break;
1467  case osBack:
1468  case osEnd: if (Interact == Menu)
1469  DELETE_MENU;
1470  else {
1471  Control = NULL;
1473  }
1474  break;
1475  default: ;
1476  }
1477  }
1478  else {
1479  // Key functions in "normal" viewing mode:
1480  if (key != kNone && KeyMacros.Get(key)) {
1481  cRemote::PutMacro(key);
1482  key = kNone;
1483  }
1484  switch (int(key)) {
1485  // Toggle channels:
1486  case kChanPrev:
1487  case k0: {
1488  if (PreviousChannel[PreviousChannelIndex ^ 1] == LastChannel || LastChannel != PreviousChannel[0] && LastChannel != PreviousChannel[1])
1489  PreviousChannelIndex ^= 1;
1491  Channels->SwitchTo(PreviousChannel[PreviousChannelIndex ^= 1]);
1492  break;
1493  }
1494  // Direct Channel Select:
1495  case k1 ... k9:
1496  // Left/Right rotates through channel groups:
1497  case kLeft|k_Repeat:
1498  case kLeft:
1499  case kRight|k_Repeat:
1500  case kRight:
1501  // Previous/Next rotates through channel groups:
1502  case kPrev|k_Repeat:
1503  case kPrev:
1504  case kNext|k_Repeat:
1505  case kNext:
1506  // Up/Down Channel Select:
1507  case kUp|k_Repeat:
1508  case kUp:
1509  case kDown|k_Repeat:
1510  case kDown:
1511  Menu = new cDisplayChannel(NORMALKEY(key));
1512  break;
1513  // Viewing Control:
1514  case kOk: LastChannel = -1; break; // forces channel display
1515  // Instant resume of the last viewed recording:
1516  case kPlay:
1518  Control = NULL;
1521  }
1522  else
1523  DirectMainFunction(osRecordings); // no last viewed recording, so enter the Recordings menu
1524  break;
1525  default: break;
1526  }
1527  }
1528  if (!Menu) {
1529  if (!InhibitEpgScan)
1530  EITScanner.Process();
1531  bool Error = false;
1532  if (RecordingsHandler.Finished(Error)) {
1533  if (Error)
1534  Skins.Message(mtError, tr("Editing process failed!"));
1535  else
1536  Skins.Message(mtInfo, tr("Editing process finished"));
1537  }
1538  }
1539 
1540  // Change primary device:
1541  int NewPrimaryDVB = Setup.PrimaryDVB;
1542  if (NewPrimaryDVB != OldPrimaryDVB) {
1543  DELETE_MENU;
1544  Control = NULL;
1546  Skins.QueueMessage(mtInfo, tr("Switching primary DVB..."));
1548  cDevice::SetPrimaryDevice(NewPrimaryDVB);
1549  OldPrimaryDVB = NewPrimaryDVB;
1550  }
1551 
1552  // SIGHUP shall cause a restart:
1553  if (LastSignal == SIGHUP) {
1554  if (ShutdownHandler.ConfirmRestart(true) && Interface->Confirm(tr("Press any key to cancel restart"), RESTARTCANCELPROMPT, true))
1555  EXIT(1);
1556  LastSignal = 0;
1557  }
1558 
1559  // Update the shutdown countdown:
1561  if (!ShutdownHandler.ConfirmShutdown(false))
1563  }
1564 
1565  if (!Control && !cRecordControls::Active() && !RecordingsHandler.Active() && (Now - cRemote::LastActivity()) > ACTIVITYTIMEOUT) {
1566  // Shutdown:
1567  // Check whether VDR will be ready for shutdown in SHUTDOWNWAIT seconds:
1568  time_t Soon = Now + SHUTDOWNWAIT;
1570  if (ShutdownHandler.ConfirmShutdown(false))
1571  // Time to shut down - start final countdown:
1572  ShutdownHandler.countdown.Start(tr("VDR will shut down in %s minutes"), SHUTDOWNWAIT); // the placeholder is really %s!
1573  // Dont try to shut down again for a while:
1575  }
1576  // Countdown run down to 0?
1577  if (ShutdownHandler.countdown.Done()) {
1578  // Timed out, now do a final check:
1580  ShutdownHandler.DoShutdown(false);
1581  // Do this again a bit later:
1583  }
1584  // Handle housekeeping tasks
1585  if ((Now - LastInteract) > ACTIVITYTIMEOUT) {
1586  // Disk housekeeping:
1590  // Plugins housekeeping:
1591  PluginManager.Housekeeping();
1592  }
1593  }
1594 
1596 
1597  // Main thread hooks of plugins:
1598  PluginManager.MainThreadHook();
1599  }
1600 
1602  esyslog("emergency exit requested - shutting down");
1603 
1604 Exit:
1605 
1606  // Reset all signal handlers to default before Interface gets deleted:
1607  signal(SIGHUP, SIG_DFL);
1608  signal(SIGINT, SIG_DFL);
1609  signal(SIGTERM, SIG_DFL);
1610  signal(SIGPIPE, SIG_DFL);
1611  signal(SIGALRM, SIG_DFL);
1612 
1613  StopSVDRPHandler();
1616  PluginManager.StopPlugins();
1618  delete Menu;
1620  delete Interface;
1622  Remotes.Clear();
1623  Audios.Clear();
1624  Skins.Clear();
1625  SourceParams.Clear();
1626  if (ShutdownHandler.GetExitCode() != 2) {
1629  Setup.Save();
1630  }
1634  EpgHandlers.Clear();
1635  cSchedules::Cleanup(true);
1638  PluginManager.Shutdown(true);
1639  ReportEpgBugFixStats(true);
1640  if (WatchdogTimeout > 0)
1641  dsyslog("max. latency time %d seconds", MaxLatencyTime);
1642  if (LastSignal)
1643  isyslog("caught signal %d", LastSignal);
1645  esyslog("emergency exit!");
1646  isyslog("exiting, exit code %d", ShutdownHandler.GetExitCode());
1647  if (SysLogLevel > 0)
1648  closelog();
1649  if (HasStdin)
1650  tcsetattr(STDIN_FILENO, TCSANOW, &savedTm);
1651 #ifdef SDNOTIFY
1652  if (ShutdownHandler.GetExitCode() == 2)
1653  sd_notify(0, "STOPPING=1\nSTATUS=Startup failed, exiting");
1654  else
1655  sd_notify(0, "STOPPING=1\nSTATUS=Exiting");
1656 #endif
1657  return ShutdownHandler.GetExitCode();
1658 }
cAudios Audios
Definition: audio.c:27
#define CHANNELMOD_ALL
Definition: channels.h:21
#define CHANNELMOD_RETUNE
Definition: channels.h:29
#define CHANNELMOD_TRANSP
Definition: channels.h:27
#define LOCK_CHANNELS_READ
Definition: channels.h:269
#define LOCK_CHANNELS_WRITE
Definition: channels.h:270
cChannelCamRelations ChannelCamRelations
Definition: ci.c:2943
cCamSlots CamSlots
Definition: ci.c:2834
cCiResourceHandlers CiResourceHandlers
Definition: ci.c:1773
bool CamResponsesLoad(const char *FileName, bool AllowComments, bool MustExist)
Definition: ci.c:477
Definition: args.h:17
int GetArgc(void) const
Definition: args.h:30
char ** GetArgv(void) const
Definition: args.h:31
bool ReadDirectory(const char *Directory)
Definition: args.c:39
bool WaitForAllCamSlotsReady(int Timeout=0)
Waits until all CAM slots have become ready, or the given Timeout (seconds) has expired.
Definition: ci.c:2846
void Load(const char *FileName)
Definition: ci.c:3039
void Save(void)
Definition: ci.c:3073
int Vpid(void) const
Definition: channels.h:154
int Number(void) const
Definition: channels.h:179
int Dpid(int i) const
Definition: channels.h:161
int Apid(int i) const
Definition: channels.h:160
bool ModifiedByUser(int &State) const
Returns true if the channels have been modified by the user since the last call to this function with...
Definition: channels.c:1125
static const cChannels * GetChannelsRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of channels for read access.
Definition: channels.c:850
bool SwitchTo(int Number) const
Definition: channels.c:1089
static bool Load(const char *FileName, bool AllowComments=false, bool MustExist=false)
Definition: channels.c:879
static void SetSystemCharacterTable(const char *CharacterTable)
Definition: tools.c:970
bool Save(void) const
Definition: config.h:167
bool Load(const char *FileName=NULL, bool AllowComments=false, bool MustExist=false)
Definition: config.h:120
static void Shutdown(void)
Definition: player.c:108
virtual cOsdObject * GetInfo(void)
Returns an OSD object that displays information about the currently played programme.
Definition: player.c:58
static void Attach(void)
Definition: player.c:95
static cControl * Control(bool Hidden=false)
Old version of this function, for backwards compatibility with plugins.
Definition: player.c:74
static void Launch(cControl *Control)
Definition: player.c:87
virtual void Hide(void)=0
bool Update(void)
Update status display of the countdown.
Definition: shutdown.c:64
void Start(const char *Message, int Seconds)
Start the 5 minute shutdown warning countdown.
Definition: shutdown.c:37
void Cancel(void)
Cancel the 5 minute shutdown warning countdown.
Definition: shutdown.c:46
bool Done(void)
Check if countdown timer has run out without canceling.
Definition: shutdown.c:55
bool IsPrimaryDevice(void) const
Definition: device.h:220
static bool WaitForAllDevicesReady(int Timeout=0)
Waits until all devices have become ready, or the given Timeout (seconds) has expired.
Definition: device.c:131
static cDevice * ActualDevice(void)
Returns the actual receiving device in case of Transfer Mode, or the primary device otherwise.
Definition: device.c:220
static void SetUseDevice(int n)
Sets the 'useDevice' flag of the given device.
Definition: device.c:147
static cDevice * GetDevice(int Index)
Gets the device with the given Index.
Definition: device.c:228
static void Shutdown(void)
Closes down all devices.
Definition: device.c:451
void SetOccupied(int Seconds)
Sets the occupied timeout for this device to the given number of Seconds, This can be used to tune a ...
Definition: device.c:952
bool SwitchChannel(const cChannel *Channel, bool LiveView)
Switches the device to the given Channel, initiating transfer mode if necessary.
Definition: device.c:801
int DeviceNumber(void) const
Returns the number of this device (0 ... numDevices - 1).
Definition: device.c:165
static int CurrentChannel(void)
Returns the number of the current channel on the primary device.
Definition: device.h:358
static bool SetPrimaryDevice(int n)
Sets the primary device to 'n'.
Definition: device.c:192
void StopReplay(void)
Stops the current replay session (if any).
Definition: device.c:1373
void SetVolume(int Volume, bool Absolute=false)
Sets the volume to the given value, either absolutely or relative to the current volume.
Definition: device.c:1028
static int NumDevices(void)
Returns the total number of devices.
Definition: device.h:129
virtual bool HasDecoder(void) const
Tells whether this device has an MPEG decoder.
Definition: device.c:210
virtual bool HasProgramme(void) const
Returns true if the device is currently showing any programme to the user, either through replaying o...
Definition: device.c:968
static int CurrentVolume(void)
Definition: device.h:632
virtual bool IsTunedToTransponder(const cChannel *Channel) const
Returns true if this device is currently tuned to the given Channel's transponder.
Definition: device.c:791
static cDevice * PrimaryDevice(void)
Returns the primary device.
Definition: device.h:148
static cDevice * GetDeviceForTransponder(const cChannel *Channel, int Priority)
Returns a device that is not currently "occupied" and can be tuned to the transponder of the given Ch...
Definition: device.c:420
bool ToggleMute(void)
Turns the volume off or on and returns the new mute state.
Definition: device.c:999
bool Load(const char *FileName, bool AllowComments=false, bool MustExist=false)
Definition: diseqc.c:441
static bool IsOpen(void)
Definition: menu.h:143
static void Process(eKeys Key)
Definition: menu.c:5271
static bool IsOpen(void)
Definition: menu.h:190
static cDisplaySubtitleTracks * Create(void)
Definition: menu.c:5260
static cDisplayTracks * Create(void)
Definition: menu.c:5142
static void Process(eKeys Key)
Definition: menu.c:5153
static bool IsOpen(void)
Definition: menu.h:172
static cDisplayVolume * Create(void)
Definition: menu.c:5052
static void Process(eKeys Key)
Definition: menu.c:5059
static bool BondDevices(const char *Bondings)
Bonds the devices as defined in the given Bondings string.
Definition: dvbdevice.c:2003
static bool useDvbDevices
Definition: dvbdevice.h:178
static bool Initialize(void)
Initializes the DVB devices.
Definition: dvbdevice.c:1940
bool Active(void)
Definition: eitscan.h:33
void Process(void)
Definition: eitscan.c:128
void Activity(void)
Definition: eitscan.c:118
static cString GetFontFileName(const char *FontName)
Returns the actual font file name for the given FontName.
Definition: font.c:479
bool Confirm(const char *s, int Seconds=10, bool WaitForTimeout=false)
Definition: interface.c:59
void Interrupt(void)
Definition: interface.h:24
eKeys GetKey(bool Wait=true)
Definition: interface.c:31
void LearnKeys(void)
Definition: interface.c:147
const cKeyMacro * Get(eKeys Key)
Definition: keys.c:269
virtual void Clear(void)
Definition: tools.c:2235
void SetSyncStateKey(cStateKey &StateKey)
When making changes to this list (while holding a write lock) that shall not affect some other code t...
Definition: tools.h:566
void Purge(bool Force=false)
Definition: tools.c:2117
const T * Next(const T *Object) const
< Returns the element immediately before Object in this list, or NULL if Object is the first element ...
Definition: tools.h:617
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
Definition: tools.h:610
static cOsdObject * PluginOsdObject(void)
Definition: menu.c:4478
bool Load(const char *FileName)
Definition: config.c:234
virtual bool NeedsFastResponse(void)
Definition: osdbase.h:79
virtual eOSState ProcessKey(eKeys Key)
Definition: osdbase.h:82
bool IsMenu(void) const
Definition: osdbase.h:80
virtual void Show(void)
Definition: osdbase.c:70
static bool OsdSizeChanged(int &State)
Checks if the OSD size has changed and a currently displayed OSD needs to be redrawn.
Definition: osd.c:2262
static void Shutdown(void)
Shuts down the OSD provider facility by deleting the current OSD provider.
Definition: osd.c:2322
static void UpdateOsdSize(bool Force=false)
Inquires the actual size of the video display and adjusts the OSD and font sizes accordingly.
Definition: osd.c:2235
static int IsOpen(void)
Returns true if there is currently a level 0 OSD open.
Definition: osd.h:819
void StopPlugins(void)
Definition: plugin.c:512
void MainThreadHook(void)
Definition: plugin.c:418
bool StartPlugins(void)
Definition: plugin.c:388
void SetDirectory(const char *Directory)
Definition: plugin.c:324
bool InitializePlugins(void)
Definition: plugin.c:375
void AddPlugin(const char *Args)
Definition: plugin.c:330
static bool HasPlugins(void)
Definition: plugin.c:464
bool LoadPlugins(bool Log=false)
Definition: plugin.c:366
void Shutdown(bool Log=false)
Definition: plugin.c:524
void Housekeeping(void)
Definition: plugin.c:402
static cPlugin * GetPlugin(int Index)
Definition: plugin.c:469
Definition: plugin.h:22
virtual const char * CommandLineHelp(void)
Definition: plugin.c:48
virtual const char * Description(void)=0
const char * Name(void)
Definition: plugin.h:36
static void SetCacheDirectory(const char *Dir)
Definition: plugin.c:149
virtual const char * Version(void)=0
virtual cOsdObject * MainMenuAction(void)
Definition: plugin.c:95
static void SetConfigDirectory(const char *Dir)
Definition: plugin.c:135
static void SetResourceDirectory(const char *Dir)
Definition: plugin.c:163
static cPositioner * GetPositioner(void)
Returns a previously created positioner.
Definition: positioner.c:133
static void DestroyPositioner(void)
Destroys a previously created positioner.
Definition: positioner.c:138
static void ChannelDataModified(const cChannel *Channel)
Definition: menu.c:5615
static bool Process(cTimers *Timers, time_t t)
Definition: menu.c:5600
static bool PauseLiveVideo(void)
Definition: menu.c:5552
static void Shutdown(void)
Definition: menu.c:5641
static bool Start(cTimers *Timers, cTimer *Timer, bool Pause=false)
Definition: menu.c:5457
static bool Active(void)
Definition: menu.c:5632
static void SetCommand(const char *Command)
Definition: recording.h:434
void DelAll(void)
Deletes/terminates all operations.
Definition: recording.c:2065
bool Finished(bool &Error)
Returns true if all operations in the list have been finished.
Definition: recording.c:2080
static void Update(bool Wait=false)
Triggers an update of the list of recordings, which will run as a separate thread if Wait is false.
Definition: recording.c:1528
static bool NeedsUpdate(void)
Definition: recording.c:1520
static const char * GetPlugin(void)
Returns the name of the plugin that was set with a previous call to PutMacro() or CallPlugin().
Definition: remote.c:162
bool Put(uint64_t Code, bool Repeat=false, bool Release=false)
Definition: remote.c:124
static bool PutMacro(eKeys Key)
Definition: remote.c:110
static time_t LastActivity(void)
Absolute time when last key was delivered by Get().
Definition: remote.h:68
static const char * LastReplayed(void)
Definition: menu.c:5794
Definition: epg.h:150
bool PresentSeenWithin(int Seconds) const
Definition: epg.h:166
static const cSchedules * GetSchedulesRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of schedules for read access.
Definition: epg.c:1231
static void SetEpgDataFileName(const char *FileName)
Definition: epg.c:1241
static void Cleanup(bool Force=false)
Definition: epg.c:1248
bool Load(const char *FileName, bool AllowComments=false, bool MustExist=false)
Definition: diseqc.c:184
int SplitEditedFiles
Definition: config.h:338
int CurrentVolume
Definition: config.h:359
int CurrentChannel
Definition: config.h:358
bool Save(void)
Definition: config.c:736
char OSDTheme[MaxThemeName]
Definition: config.h:260
char OSDSkin[MaxSkinName]
Definition: config.h:259
int VpsMargin
Definition: config.h:308
int ZapTimeout
Definition: config.h:298
int RecordKeyHandling
Definition: config.h:303
int PauseKeyHandling
Definition: config.h:304
bool Load(const char *FileName)
Definition: config.c:543
int MenuKeyCloses
Definition: config.h:266
int DiSEqC
Definition: config.h:273
char FontOsd[MAXFONTNAME]
Definition: config.h:328
int MaxVideoFileSize
Definition: config.h:337
cString DeviceBondings
Definition: config.h:369
int PrimaryDVB
Definition: config.h:261
cString InitialChannel
Definition: config.h:368
int InitialVolume
Definition: config.h:363
void CheckManualStart(int ManualStart)
Check whether the next timer is in ManualStart time window.
Definition: shutdown.c:104
void SetShutdownCommand(const char *ShutdownCommand)
Set the command string for shutdown command.
Definition: shutdown.c:121
bool ConfirmShutdown(bool Ask)
Check for background activity that blocks shutdown.
Definition: shutdown.c:157
bool EmergencyExitRequested(void)
Returns true if an emergency exit was requested.
Definition: shutdown.h:61
void SetRetry(int Seconds)
Set shutdown retry so that VDR will not try to automatically shut down within Seconds.
Definition: shutdown.h:93
bool Retry(time_t AtTime=0)
Check whether its time to re-try the shutdown.
Definition: shutdown.h:88
bool IsUserInactive(time_t AtTime=0)
Check whether VDR is in interactive mode or non-interactive mode (waiting for shutdown).
Definition: shutdown.h:72
bool DoShutdown(bool Force)
Call the shutdown script with data of the next pending timer.
Definition: shutdown.c:233
bool ConfirmRestart(bool Ask)
Check for background activity that blocks restart.
Definition: shutdown.c:209
void Exit(int ExitCode)
Set VDR exit code and initiate end of VDR main loop.
Definition: shutdown.h:54
void SetUserInactiveTimeout(int Seconds=-1, bool Force=false)
Set the time in the future when VDR will switch into non-interactive mode or power down.
Definition: shutdown.c:141
bool DoExit(void)
Check if an exit code was set, and VDR should exit.
Definition: shutdown.h:57
cCountdown countdown
Definition: shutdown.h:51
void SetUserInactive(void)
Set VDR manually into non-interactive mode from now on.
Definition: shutdown.h:86
int GetExitCode(void)
Get the currently set exit code of VDR.
Definition: shutdown.h:59
Definition: skins.h:402
cTheme * Theme(void)
Definition: skins.h:422
const char * Name(void)
Definition: skins.h:421
bool SetCurrent(const char *Name=NULL)
Sets the current skin to the one indicated by name.
Definition: skins.c:231
eKeys Message(eMessageType Type, const char *s, int Seconds=0)
Displays the given message, either through a currently visible display object that is capable of doin...
Definition: skins.c:250
cSkin * Current(void)
Returns a pointer to the current skin.
Definition: skins.h:468
virtual void Clear(void)
Free up all registered skins.
Definition: skins.c:408
void ProcessQueuedMessages(void)
Processes the first queued message, if any.
Definition: skins.c:352
int QueueMessage(eMessageType Type, const char *s, int Seconds=0, int Timeout=0)
Like Message(), but this function may be called from a background thread.
Definition: skins.c:296
void Remove(bool IncState=true)
Removes this key from the lock it was previously used with.
Definition: thread.c:859
void Reset(void)
Resets the state of this key, so that the next call to a lock's Lock() function with this key will re...
Definition: thread.c:854
bool StateChanged(void)
Returns true if this key is used for obtaining a write lock, and the lock's state differs from that o...
Definition: thread.c:869
static void MsgChannelChange(const cChannel *Channel)
Definition: status.c:26
static void SetThemesDirectory(const char *ThemesDirectory)
Definition: themes.c:295
bool Load(const char *SkinName)
Definition: themes.c:239
static void SetMainThreadId(void)
Definition: thread.c:377
void bool Start(void)
Sets the description of this thread, which will be used when logging starting or stopping of the thre...
Definition: thread.c:304
bool Active(void)
Checks whether the thread is still alive.
Definition: thread.c:329
static tThreadId ThreadId(void)
Definition: thread.c:372
Definition: timers.h:27
static bool Load(const char *FileName)
Definition: timers.c:735
int GetMaxPriority(void) const
Returns the maximum priority of all local timers that are currently recording.
Definition: timers.c:820
static cTimers * GetTimersWrite(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of timers for write access.
Definition: timers.c:848
static const cTimers * GetTimersRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of timers for read access.
Definition: timers.c:843
const cTimer * GetMatch(time_t t) const
Definition: timers.c:779
bool DeleteExpired(void)
Definition: timers.c:890
bool SetEvents(const cSchedules *Schedules)
Definition: timers.c:882
static void Destroy(void)
Definition: videodir.c:50
static void SetName(const char *Name)
Definition: videodir.c:65
cNestedItemList Commands
Definition: config.c:275
cSetup Setup
Definition: config.c:372
cSVDRPhosts SVDRPhosts
Definition: config.c:280
cNestedItemList Folders
Definition: config.c:274
cNestedItemList RecordingCommands
Definition: config.c:276
#define MINPRIORITY
Definition: config.h:40
#define VDRVERSION
Definition: config.h:25
#define APIVERSION
Definition: config.h:30
#define LIVEPRIORITY
Definition: config.h:41
bool CutRecording(const char *FileName)
Definition: cutter.c:726
#define MAXDEVICES
Definition: device.h:29
#define VOLUMEDELTA
Definition: device.h:33
cDiseqcs Diseqcs
Definition: diseqc.c:439
cScrs Scrs
Definition: diseqc.c:182
cEITScanner EITScanner
Definition: eitscan.c:90
cEpgHandlers EpgHandlers
Definition: epg.c:1389
void ReportEpgBugFixStats(bool Force)
Definition: epg.c:611
#define LOCK_SCHEDULES_READ
Definition: epg.h:224
void I18nInitialize(const char *LocaleDir)
Detects all available locales and loads the language names and codes.
Definition: i18n.c:140
#define tr(s)
Definition: i18n.h:85
cInterface * Interface
Definition: interface.c:20
cKeyMacros KeyMacros
Definition: keys.c:267
cKeys Keys
Definition: keys.c:156
#define ISMODELESSKEY(k)
Definition: keys.h:80
#define ISREALKEY(k)
Definition: keys.h:81
#define NORMALKEY(k)
Definition: keys.h:79
eKeys
Definition: keys.h:16
@ kPower
Definition: keys.h:39
@ kRecord
Definition: keys.h:34
@ kSchedule
Definition: keys.h:48
@ kUser9
Definition: keys.h:54
@ kPlayPause
Definition: keys.h:30
@ kCommands
Definition: keys.h:53
@ kRight
Definition: keys.h:23
@ kRecordings
Definition: keys.h:51
@ kPause
Definition: keys.h:32
@ k9
Definition: keys.h:28
@ kSetup
Definition: keys.h:52
@ kUp
Definition: keys.h:17
@ kChanUp
Definition: keys.h:40
@ kNone
Definition: keys.h:55
@ kPlay
Definition: keys.h:31
@ kChanPrev
Definition: keys.h:42
@ kDown
Definition: keys.h:18
@ k1
Definition: keys.h:28
@ kSubtitles
Definition: keys.h:47
@ kLeft
Definition: keys.h:22
@ k_Plugin
Definition: keys.h:58
@ kAudio
Definition: keys.h:46
@ kMute
Definition: keys.h:45
@ kPrev
Definition: keys.h:38
@ k0
Definition: keys.h:28
@ kChannels
Definition: keys.h:49
@ kTimers
Definition: keys.h:50
@ kMenu
Definition: keys.h:19
@ k_Repeat
Definition: keys.h:61
@ kChanDn
Definition: keys.h:41
@ kVolDn
Definition: keys.h:44
@ kNext
Definition: keys.h:37
@ kOk
Definition: keys.h:20
@ kVolUp
Definition: keys.h:43
@ kInfo
Definition: keys.h:29
@ kUser0
Definition: keys.h:54
bool CamMenuActive(void)
Definition: menu.c:2439
cOsdObject * CamControl(void)
Definition: menu.c:2430
bool SetSystemCharacterTable(const char *CharacterTable)
Definition: si.c:339
static char * OverrideCharacterTable
Definition: si.c:322
bool SetOverrideCharacterTable(const char *CharacterTable)
Definition: si.c:324
eOSState
Definition: osdbase.h:18
@ osRecordings
Definition: osdbase.h:23
@ osPause
Definition: osdbase.h:27
@ osPlugin
Definition: osdbase.h:24
@ osChannels
Definition: osdbase.h:21
@ osStopReplay
Definition: osdbase.h:31
@ osRecord
Definition: osdbase.h:28
@ osEnd
Definition: osdbase.h:34
@ osSetup
Definition: osdbase.h:25
@ osTimers
Definition: osdbase.h:22
@ osReplay
Definition: osdbase.h:29
@ osUnknown
Definition: osdbase.h:18
@ osSchedule
Definition: osdbase.h:20
@ osCommands
Definition: osdbase.h:26
@ osBack
Definition: osdbase.h:33
int DirectoryNameMax
Definition: recording.c:77
bool GenerateIndex(const char *FileName, bool Update)
Generates the index of the existing recording with the given FileName.
Definition: recording.c:2861
void AssertFreeDiskSpace(int Priority, bool Force)
The special Priority value -1 means that we shall get rid of any deleted recordings faster than norma...
Definition: recording.c:154
int DirectoryPathMax
Definition: recording.c:76
int InstanceId
Definition: recording.c:79
bool DirectoryEncoding
Definition: recording.c:78
cRecordingsHandler RecordingsHandler
Definition: recording.c:1975
void RemoveDeletedRecordings(void)
Definition: recording.c:137
#define MAXVIDEOFILESIZEDEFAULT
Definition: recording.h:449
#define MAXVIDEOFILESIZETS
Definition: recording.h:446
#define MINVIDEOFILESIZE
Definition: recording.h:448
cRemotes Remotes
Definition: remote.c:211
cShutdownHandler ShutdownHandler
Definition: shutdown.c:27
cSkins Skins
Definition: skins.c:219
@ mtWarning
Definition: skins.h:37
@ mtInfo
Definition: skins.h:37
@ mtError
Definition: skins.h:37
cSourceParams SourceParams
Definition: sourceparams.c:34
cSources Sources
Definition: sources.c:117
static tChannelID FromString(const char *s)
Definition: channels.c:24
void StopSVDRPHandler(void)
Definition: svdrp.c:2834
void SetSVDRPGrabImageDir(const char *GrabImageDir)
Definition: svdrp.c:2736
void StartSVDRPHandler(void)
Definition: svdrp.c:2818
void SetSVDRPPorts(int TcpPort, int UdpPort)
Definition: svdrp.c:2730
cStateKey StateKeySVDRPRemoteTimersPoll
Controls whether a change to the local list of timers needs to result in sending a POLL to the remote...
@ tfActive
Definition: timers.h:19
@ tfVps
Definition: timers.h:21
int SysLogLevel
Definition: tools.c:31
bool DirectoryOk(const char *DirName, bool LogErrors)
Definition: tools.c:465
bool isnumber(const char *s)
Definition: tools.c:348
cString AddDirectory(const char *DirName, const char *FileName)
Definition: tools.c:386
cListGarbageCollector ListGarbageCollector
Definition: tools.c:2094
int64_t StrToNum(const char *s)
Converts the given string to a number.
Definition: tools.c:359
#define MEGABYTE(n)
Definition: tools.h:45
#define dsyslog(a...)
Definition: tools.h:37
#define esyslog(a...)
Definition: tools.h:35
#define isyslog(a...)
Definition: tools.h:36
static bool SetUser(const char *User, bool UserDump)
Definition: vdr.c:96
#define SHUTDOWNFORCEPROMPT
Definition: vdr.c:79
static int LastSignal
Definition: vdr.c:94
int main(int argc, char *argv[])
Definition: vdr.c:196
#define DEFAULTRESDIR
#define DEFAULTWATCHDOG
#define DEFAULTARGSDIR
#define MANUALSTART
Definition: vdr.c:82
#define DEFAULTLOCDIR
#define TIMERLOOKAHEADTIME
Definition: vdr.c:88
#define DEFAULTPLUGINDIR
#define CHANNELSAVEDELTA
Definition: vdr.c:83
#define SHUTDOWNCANCELPROMPT
Definition: vdr.c:80
#define SHUTDOWNWAIT
Definition: vdr.c:77
#define DEFAULTEPGDATAFILENAME
static void SignalHandler(int signum)
Definition: vdr.c:169
#define DEFAULTCONFDIR
static bool SetKeepCaps(bool On)
Definition: vdr.c:159
#define DEFAULTVIDEODIR
#define VPSLOOKAHEADTIME
Definition: vdr.c:89
#define DirectMainFunction(function)
#define MINCHANNELWAIT
Definition: vdr.c:75
#define TIMERDEVICETIMEOUT
Definition: vdr.c:87
static bool DropCaps(void)
Definition: vdr.c:126
#define MENUTIMEOUT
Definition: vdr.c:85
static void Watchdog(int signum)
Definition: vdr.c:185
#define RESTARTCANCELPROMPT
Definition: vdr.c:81
#define EXIT(v)
Definition: vdr.c:92
#define DEFAULTCACHEDIR
#define DEVICEREADYTIMEOUT
Definition: vdr.c:84
#define TIMERCHECKDELTA
Definition: vdr.c:86
#define ACTIVITYTIMEOUT
Definition: vdr.c:76
#define VPSUPTODATETIME
Definition: vdr.c:90
#define DELETE_MENU
#define SHUTDOWNRETRY
Definition: vdr.c:78
#define DEFAULTSVDRPPORT