vdr  2.2.0
receiver.c
Go to the documentation of this file.
1 /*
2  * receiver.c: The basic receiver interface
3  *
4  * See the main source file 'vdr.c' for copyright information and
5  * how to reach the author.
6  *
7  * $Id: receiver.c 3.3 2015/01/12 14:04:31 kls Exp $
8  */
9 
10 #include "receiver.h"
11 #include <stdio.h>
12 #include "tools.h"
13 
14 cReceiver::cReceiver(const cChannel *Channel, int Priority)
15 {
16  device = NULL;
17  SetPriority(Priority);
18  numPids = 0;
19  SetPids(Channel);
20 }
21 
23 {
24  if (device) {
25  const char *msg = "ERROR: cReceiver has not been detached yet! This is a design fault and VDR will abort now!";
26  esyslog("%s", msg);
27  fprintf(stderr, "%s\n", msg);
28  abort();
29  }
30 }
31 
32 void cReceiver::SetPriority(int Priority)
33 {
35 }
36 
37 bool cReceiver::AddPid(int Pid)
38 {
39  if (Pid) {
40  if (numPids < MAXRECEIVEPIDS)
41  pids[numPids++] = Pid;
42  else {
43  dsyslog("too many PIDs in cReceiver (Pid = %d)", Pid);
44  return false;
45  }
46  }
47  return true;
48 }
49 
50 bool cReceiver::AddPids(const int *Pids)
51 {
52  if (Pids) {
53  while (*Pids) {
54  if (!AddPid(*Pids++))
55  return false;
56  }
57  }
58  return true;
59 }
60 
61 bool cReceiver::AddPids(int Pid1, int Pid2, int Pid3, int Pid4, int Pid5, int Pid6, int Pid7, int Pid8, int Pid9)
62 {
63  return AddPid(Pid1) && AddPid(Pid2) && AddPid(Pid3) && AddPid(Pid4) && AddPid(Pid5) && AddPid(Pid6) && AddPid(Pid7) && AddPid(Pid8) && AddPid(Pid9);
64 }
65 
66 bool cReceiver::SetPids(const cChannel *Channel)
67 {
68  numPids = 0;
69  if (Channel) {
70  channelID = Channel->GetChannelID();
71  return AddPid(Channel->Vpid()) &&
72  (Channel->Ppid() == Channel->Vpid() || AddPid(Channel->Ppid())) &&
73  AddPids(Channel->Apids()) &&
74  AddPids(Channel->Dpids()) &&
75  AddPids(Channel->Spids());
76  }
77  return true;
78 }
79 
80 void cReceiver::DelPid(int Pid)
81 {
82  if (Pid) {
83  for (int i = 0; i < numPids; i++) {
84  if (pids[i] == Pid) {
85  for ( ; i < numPids; i++) // we also copy the terminating 0!
86  pids[i] = pids[i + 1];
87  numPids--;
88  return;
89  }
90  }
91  }
92 }
93 
94 void cReceiver::DelPids(const int *Pids)
95 {
96  if (Pids) {
97  while (*Pids)
98  DelPid(*Pids++);
99  }
100 }
101 
102 bool cReceiver::WantsPid(int Pid)
103 {
104  if (Pid) {
105  for (int i = 0; i < numPids; i++) {
106  if (pids[i] == Pid)
107  return true;
108  }
109  }
110  return false;
111 }
112 
114 {
115  if (device)
116  device->Detach(this);
117 }
#define MAXRECEIVEPIDS
Definition: receiver.h:15
int Vpid(void) const
Definition: channels.h:154
const int * Dpids(void) const
Definition: channels.h:158
#define dsyslog(a...)
Definition: tools.h:36
cReceiver(const cChannel *Channel=NULL, int Priority=MINPRIORITY)
Creates a new receiver for the given Channel with the given Priority.
Definition: receiver.c:14
virtual ~cReceiver()
Definition: receiver.c:22
#define esyslog(a...)
Definition: tools.h:34
void Detach(cFilter *Filter)
Detaches the given filter from this device.
Definition: device.c:667
bool AddPids(const int *Pids)
Adds the given zero terminated list of Pids to the list of PIDs of this receiver. ...
Definition: receiver.c:50
cDevice * device
Definition: receiver.h:20
#define MINPRIORITY
Definition: config.h:44
int Ppid(void) const
Definition: channels.h:155
int numPids
Definition: receiver.h:24
void DelPids(const int *Pids)
Deletes the given zero terminated list of Pids from the list of PIDs of this receiver.
Definition: receiver.c:94
T constrain(T v, T l, T h)
Definition: tools.h:60
bool SetPids(const cChannel *Channel)
Sets the PIDs of this receiver to those of the given Channel, replacing any previously stored PIDs...
Definition: receiver.c:66
tChannelID GetChannelID(void) const
Definition: channels.h:190
bool AddPid(int Pid)
Adds the given Pid to the list of PIDs of this receiver.
Definition: receiver.c:37
int pids[MAXRECEIVEPIDS]
Definition: receiver.h:23
void DelPid(int Pid)
Deletes the given Pid from the list of PIDs of this receiver.
Definition: receiver.c:80
const int * Apids(void) const
Definition: channels.h:157
tChannelID channelID
Definition: receiver.h:21
#define MAXPRIORITY
Definition: config.h:43
int priority
Definition: receiver.h:22
bool WantsPid(int Pid)
Definition: receiver.c:102
const int * Spids(void) const
Definition: channels.h:159
void SetPriority(int Priority)
Definition: receiver.c:32
void Detach(void)
Definition: receiver.c:113