summaryrefslogtreecommitdiff
path: root/patches/reelvdr-device-handling-patch.diff
blob: d0592aae5154d9d679e1619170b2d9d25ad54c6d (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
Index: device.c
===================================================================
--- device.c	(Revision 10504)
+++ device.c	(Arbeitskopie)
@@ -270,14 +270,19 @@
   for (int i = 0; i < MAXRECEIVERS; i++)
       receiver[i] = NULL;
 
-  if (numDevices < MAXDEVICES)
-     device[numDevices++] = this;
-  else
-     esyslog("ERROR: too many devices!");
+  for (int i = 0; i < MAXDEVICES; i++)
+  if (!device[i]) {
+     device[i] = this;
+     numDevices++;
+     return;
+     }
+  esyslog("ERROR: too many devices!");
 }
 
 cDevice::~cDevice()
 {
+  numDevices--;
+  device[DeviceNumber()] = NULL;
   Detach(player);
   for (int i = 0; i < MAXRECEIVERS; i++)
       Detach(receiver[i]);
@@ -290,7 +295,7 @@
 {
   for (time_t t0 = time(NULL); time(NULL) - t0 < Timeout; ) {
       bool ready = true;
-      for (int i = 0; i < numDevices; i++) {
+      for (int i = 0; i < MAXDEVICES; i++) {
           if (device[i] && !device[i]->Ready())
              ready = false;
           }
@@ -322,7 +327,7 @@
 
 int cDevice::DeviceNumber(void) const
 {
-  for (int i = 0; i < numDevices; i++) {
+  for (int i = 0; i < MAXDEVICES; i++) {
       if (device[i] == this)
          return i;
       }
@@ -336,7 +341,7 @@
 bool cDevice::SetPrimaryDevice(int n)
 {
   n--;
-  if (0 <= n && n < numDevices && device[n]) {
+  if (0 <= n && n < MAXDEVICES && device[n]) {
      isyslog("setting primary device to %d", n + 1);
      if (primaryDevice)
         primaryDevice->MakePrimaryDevice(false);
@@ -369,15 +374,17 @@
 
 cDevice *cDevice::GetDevice(int Index)
 {
-  return (0 <= Index && Index < numDevices) ? device[Index] : NULL;
+  return (0 <= Index && Index < MAXDEVICES) ? device[Index] : NULL;
 }
 
 cDevice *cDevice::GetDevice(const cChannel *Channel, int Priority, bool *NeedsDetachReceivers)
 {
   cDevice *d = NULL;
   uint Impact = 0xFFFFFFFF; // we're looking for a device with the least impact
-  for (int i = 0; i < numDevices; i++) {
+  for (int i = 0; i < MAXDEVICES; i++) {
       bool ndr;
+      if (device[i] == NULL)
+        continue; // this device was not allocated
 #ifdef DETACH_UNUSED_DEVICES
       if(!device[i]->Receiving()) {
         isyslog("device %d (%p) not receiving", i, device[i]);
@@ -419,10 +426,11 @@
 void cDevice::Shutdown(void)
 {
   primaryDevice = NULL;
-  for (int i = 0; i < numDevices; i++) {
-      delete device[i];
-      device[i] = NULL;
+  for (int i = 0; i < MAXDEVICES; i++) {
+      if( device[i]) {
+        delete device[i];
       }
+    }
 }
 
 uchar *cDevice::GrabImage(int &Size, bool Jpeg, int Quality, int SizeX, int SizeY)
@@ -724,6 +732,16 @@
   return -1;
 }
 
+int cDevice::ReadFilter(int Handle, void *Buffer, size_t Length)
+{
+  return safe_read(Handle, Buffer, Length);
+}
+
+void cDevice::CloseFilter(int Handle)
+{
+  close(Handle);
+}
+
 void cDevice::AttachFilter(cFilter *Filter)
 {
   if (sectionHandler)
@@ -753,7 +771,7 @@
 
 bool cDevice::ProvidesTransponderExclusively(const cChannel *Channel) const
 {
-  for (int i = 0; i < numDevices; i++) {
+  for (int i = 0; i < MAXDEVICES; i++) {
       if (device[i] && device[i] != this && device[i]->ProvidesTransponder(Channel))
          return false;
       }
Index: device.h
===================================================================
--- device.h	(Revision 10504)
+++ device.h	(Arbeitskopie)
@@ -326,6 +326,15 @@
        ///< Opens a file handle for the given filter data.
        ///< A derived device that provides section data must
        ///< implement this function.
+  virtual int ReadFilter(int Handle, void *Buffer, size_t Length);
+       ///< Read from a handle for the given filter data.
+       ///< a derived class need not implement this function, because this
+       ///< is done by the default implementation.
+  virtual void CloseFilter(int Handle);
+       ///< Closes a file handle that has previously been opened
+       ///< by OpenFilter(). If this is as simple as calling close(Handle),
+       ///< a derived class need not implement this function, because this
+       ///< is done by the default implementation.
   void AttachFilter(cFilter *Filter);
        ///< Attaches the given filter to this device.
   void Detach(cFilter *Filter);
Index: sections.c
===================================================================
--- sections.c	(Revision 10504)
+++ sections.c	(Arbeitskopie)
@@ -105,7 +105,7 @@
   for (fh = filterHandles.First(); fh; fh = filterHandles.Next(fh)) {
       if (fh->filterData.Is(FilterData->pid, FilterData->tid, FilterData->mask)) {
          if (--fh->used <= 0) {
-            close(fh->handle);
+            device->CloseFilter(fh->handle);
             filterHandles.Del(fh);
             break;
             }
@@ -198,7 +198,7 @@
                   if (fh) {
                      // Read section data:
                      unsigned char buf[4096]; // max. allowed size for any EIT section
-                     int r = safe_read(fh->handle, buf, sizeof(buf));
+                     int r = device->ReadFilter(fh->handle, buf, sizeof(buf));
                      if (!DeviceHasLock)
                         continue; // we do the read anyway, to flush any data that might have come from a different transponder
                      if (r > 3) { // minimum number of bytes necessary to get section length