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 
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  (!Setup.SupportTeletext || AddPid(Channel->Tpid()));
77  }
78  return true;
79 }
80 
81 void cReceiver::DelPid(int Pid)
82 {
83  if (Pid) {
84  for (int i = 0; i < numPids; i++) {
85  if (pids[i] == Pid) {
86  for ( ; i < numPids; i++) // we also copy the terminating 0!
87  pids[i] = pids[i + 1];
88  numPids--;
89  return;
90  }
91  }
92  }
93 }
94 
95 void cReceiver::DelPids(const int *Pids)
96 {
97  if (Pids) {
98  while (*Pids)
99  DelPid(*Pids++);
100  }
101 }
102 
103 bool cReceiver::WantsPid(int Pid)
104 {
105  if (Pid) {
106  for (int i = 0; i < numPids; i++) {
107  if (pids[i] == Pid)
108  return true;
109  }
110  }
111  return false;
112 }
113 
115 {
116  if (device)
117  device->Detach(this);
118 }
#define MAXRECEIVEPIDS
Definition: receiver.h:15
int Vpid(void) const
Definition: channels.h:170
const int * Dpids(void) const
Definition: channels.h:174
#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:616
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:40
int Ppid(void) const
Definition: channels.h:171
int numPids
Definition: receiver.h:24
int Priority(void)
Definition: receiver.h:52
void DelPids(const int *Pids)
Deletes the given zero terminated list of Pids from the list of PIDs of this receiver.
Definition: receiver.c:95
T constrain(T v, T l, T h)
Definition: tools.h:60
int Tpid(void) const
Definition: channels.h:187
cSetup Setup
Definition: config.c:373
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:208
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:81
const int * Apids(void) const
Definition: channels.h:173
tChannelID channelID
Definition: receiver.h:21
#define MAXPRIORITY
Definition: config.h:39
int priority
Definition: receiver.h:22
bool WantsPid(int Pid)
Definition: receiver.c:103
const int * Spids(void) const
Definition: channels.h:175
int SupportTeletext
Definition: config.h:288
void SetPriority(int Priority)
Definition: receiver.c:32
void Detach(void)
Definition: receiver.c:114