1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
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__null; |
17 | priority = constrain(Priority, MINPRIORITY(-99), MAXPRIORITY99); |
18 | numPids = 0; |
19 | SetPids(Channel); |
20 | } |
21 | |
22 | cReceiver::~cReceiver() |
23 | { |
24 | if (device) { |
| |
25 | const char *msg = "ERROR: cReceiver has not been detached yet! This is a design fault and VDR will segfault now!"; |
26 | esyslog("%s", msg)void( (SysLogLevel > 0) ? syslog_with_tid(3, "%s", msg) : void () ); |
27 | fprintf(stderrstderr, "%s\n", msg); |
28 | *(char *)0 = 0; |
| 2 | | Dereference of null pointer |
|
29 | } |
30 | } |
31 | |
32 | bool cReceiver::AddPid(int Pid) |
33 | { |
34 | if (Pid) { |
35 | if (numPids < MAXRECEIVEPIDS64) |
36 | pids[numPids++] = Pid; |
37 | else { |
38 | dsyslog("too many PIDs in cReceiver (Pid = %d)", Pid)void( (SysLogLevel > 2) ? syslog_with_tid(7, "too many PIDs in cReceiver (Pid = %d)" , Pid) : void() ); |
39 | return false; |
40 | } |
41 | } |
42 | return true; |
43 | } |
44 | |
45 | bool cReceiver::AddPids(const int *Pids) |
46 | { |
47 | if (Pids) { |
48 | while (*Pids) { |
49 | if (!AddPid(*Pids++)) |
50 | return false; |
51 | } |
52 | } |
53 | return true; |
54 | } |
55 | |
56 | bool cReceiver::AddPids(int Pid1, int Pid2, int Pid3, int Pid4, int Pid5, int Pid6, int Pid7, int Pid8, int Pid9) |
57 | { |
58 | return AddPid(Pid1) && AddPid(Pid2) && AddPid(Pid3) && AddPid(Pid4) && AddPid(Pid5) && AddPid(Pid6) && AddPid(Pid7) && AddPid(Pid8) && AddPid(Pid9); |
59 | } |
60 | |
61 | bool cReceiver::SetPids(const cChannel *Channel) |
62 | { |
63 | numPids = 0; |
64 | if (Channel) { |
65 | channelID = Channel->GetChannelID(); |
66 | return AddPid(Channel->Vpid()) && |
67 | (Channel->Ppid() == Channel->Vpid() || AddPid(Channel->Ppid())) && |
68 | AddPids(Channel->Apids()) && |
69 | AddPids(Channel->Dpids()) && |
70 | AddPids(Channel->Spids()); |
71 | } |
72 | return true; |
73 | } |
74 | |
75 | void cReceiver::DelPid(int Pid) |
76 | { |
77 | if (Pid) { |
78 | for (int i = 0; i < numPids; i++) { |
79 | if (pids[i] == Pid) { |
80 | for ( ; i < numPids; i++) |
81 | pids[i] = pids[i + 1]; |
82 | numPids--; |
83 | return; |
84 | } |
85 | } |
86 | } |
87 | } |
88 | |
89 | void cReceiver::DelPids(const int *Pids) |
90 | { |
91 | if (Pids) { |
92 | while (*Pids) |
93 | DelPid(*Pids++); |
94 | } |
95 | } |
96 | |
97 | bool cReceiver::WantsPid(int Pid) |
98 | { |
99 | if (Pid) { |
100 | for (int i = 0; i < numPids; i++) { |
101 | if (pids[i] == Pid) |
102 | return true; |
103 | } |
104 | } |
105 | return false; |
106 | } |
107 | |
108 | void cReceiver::Detach(void) |
109 | { |
110 | if (device) |
111 | device->Detach(this); |
112 | } |