summaryrefslogtreecommitdiff
path: root/receiver.c
blob: de5d0aea25308be6e3db992ae08e8593089b0797 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * receiver.c: The basic receiver interface
 *
 * See the main source file 'vdr.c' for copyright information and
 * how to reach the author.
 *
 * $Id: receiver.c 3.1 2014/01/01 12:03:00 kls Exp $
 */

#include "receiver.h"
#include <stdio.h>
#include "tools.h"

cReceiver::cReceiver(const cChannel *Channel, int Priority)
{
  device = NULL;
  priority = constrain(Priority, MINPRIORITY, MAXPRIORITY);
  numPids = 0;
  SetPids(Channel);
}

cReceiver::~cReceiver()
{
  if (device) {
     const char *msg = "ERROR: cReceiver has not been detached yet! This is a design fault and VDR will segfault now!";
     esyslog("%s", msg);
     fprintf(stderr, "%s\n", msg);
     *(char *)0 = 0; // cause a segfault
     }
}

bool cReceiver::AddPid(int Pid)
{
  if (Pid) {
     if (numPids < MAXRECEIVEPIDS)
        pids[numPids++] = Pid;
     else {
        dsyslog("too many PIDs in cReceiver (Pid = %d)", Pid);
        return false;
        }
     }
  return true;
}

bool cReceiver::AddPids(const int *Pids)
{
  if (Pids) {
     while (*Pids) {
           if (!AddPid(*Pids++))
              return false;
           }
     }
  return true;
}

bool cReceiver::AddPids(int Pid1, int Pid2, int Pid3, int Pid4, int Pid5, int Pid6, int Pid7, int Pid8, int Pid9)
{
  return AddPid(Pid1) && AddPid(Pid2) && AddPid(Pid3) && AddPid(Pid4) && AddPid(Pid5) && AddPid(Pid6) && AddPid(Pid7) && AddPid(Pid8) && AddPid(Pid9);
}

bool cReceiver::SetPids(const cChannel *Channel)
{
  numPids = 0;
  if (Channel) {
     channelID = Channel->GetChannelID();
     return AddPid(Channel->Vpid()) &&
            (Channel->Ppid() == Channel->Vpid() || AddPid(Channel->Ppid())) &&
            AddPids(Channel->Apids()) &&
            AddPids(Channel->Dpids()) &&
            AddPids(Channel->Spids());
     }
  return true;
}

void cReceiver::DelPid(int Pid)
{
  if (Pid) {
     for (int i = 0; i < numPids; i++) {
         if (pids[i] == Pid) {
            for ( ; i < numPids; i++) // we also copy the terminating 0!
                pids[i] = pids[i + 1];
            numPids--;
            return;
            }
         }
     }
}

void cReceiver::DelPids(const int *Pids)
{
  if (Pids) {
     while (*Pids)
           DelPid(*Pids++);
     }
}

bool cReceiver::WantsPid(int Pid)
{
  if (Pid) {
     for (int i = 0; i < numPids; i++) {
         if (pids[i] == Pid)
            return true;
         }
     }
  return false;
}

void cReceiver::Detach(void)
{
  if (device)
     device->Detach(this);
}