summaryrefslogtreecommitdiff
path: root/patches/sc-1.0.0pre-HG-29b7b5f231c8-dynamite.patch
blob: 81e07e77588291f708ae4ad57fc5354adcd9f68a (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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
diff --git a/Makefile b/Makefile
index d0f256c..e0cd8e2 100644
--- a/Makefile
+++ b/Makefile
@@ -144,8 +144,8 @@ ifneq ($(strip $(MAXCAID)),)
 endif
 
 # FFdeCSA
-CPUOPT     ?= pentium
-PARALLEL   ?= PARALLEL_32_INT
+CPUOPT     ?= k8
+PARALLEL   ?= PARALLEL_128_SSE
 CSAFLAGS   ?= -Wall -fPIC -g -O3 -mmmx -fomit-frame-pointer -fexpensive-optimizations -funroll-loops
 FFDECSADIR  = FFdecsa
 FFDECSA     = $(FFDECSADIR)/FFdecsa.o
diff --git a/device-hd.c b/device-hd.c
index bc13996..c3134e5 100644
--- a/device-hd.c
+++ b/device-hd.c
@@ -50,12 +50,18 @@ bool cScDvbHdFfDevice::SetCaDescr(ca_descr_t *ca_descr, bool initial)
 {
   if(!initial) cCondWait::SleepMs(150);
   cMutexLock lock(&cafdMutex);
+// BEGIN vdr-plugin-dynamite
+  if(fd_ca < 0) return false;
+// END vdr-plugin-dynamite
   return ioctl(fd_ca,CA_SET_DESCR,ca_descr)>=0;
 }
 
 bool cScDvbHdFfDevice::SetCaPid(ca_pid_t *ca_pid)
 {
   cMutexLock lock(&cafdMutex);
+// BEGIN vdr-plugin-dynamite
+  if(fd_ca < 0) return false;
+// END vdr-plugin-dynamite
   return ioctl(fd_ca,CA_SET_PID,ca_pid)>=0;
 }
 
diff --git a/device-sd.c b/device-sd.c
index 2dc828f..a1eda3e 100644
--- a/device-sd.c
+++ b/device-sd.c
@@ -59,12 +59,18 @@ bool cScDvbSdFfDevice::CheckFullTs(void)
 bool cScDvbSdFfDevice::SetCaDescr(ca_descr_t *ca_descr, bool initial)
 {
   cMutexLock lock(&cafdMutex);
+// BEGIN vdr-plugin-dynamite
+  if(fd_ca < 0) return false;
+// END vdr-plugin-dynamite
   return ioctl(fd_ca,CA_SET_DESCR,ca_descr)>=0;
 }
 
 bool cScDvbSdFfDevice::SetCaPid(ca_pid_t *ca_pid)
 {
   cMutexLock lock(&cafdMutex);
+// BEGIN vdr-plugin-dynamite
+  if(fd_ca < 0) return false;
+// END vdr-plugin-dynamite
   return ioctl(fd_ca,CA_SET_PID,ca_pid)>=0;
 }
 
@@ -88,6 +94,9 @@ static void av7110_write(int fd, unsigned int addr, unsigned int val)
 
 void cScDvbSdFfDevice::DumpAV(void)
 {
+// BEGIN vdr-plugin-dynamite
+  if(fd_ca < 0) return;
+// END vdr-plugin-dynamite
   if(LOG(L_CORE_AV7110)) {
 #define CODEBASE (0x2e000404+0x1ce00)
     cMutexLock lock(&cafdMutex);
diff --git a/device-tmpl.c b/device-tmpl.c
index 6643cea..292daa6 100644
--- a/device-tmpl.c
+++ b/device-tmpl.c
@@ -62,6 +62,14 @@ public:
 #else
   cCam *Cam(void) { return cam; }
 #endif //!SASC
+// BEGIN vdr-plugin-dynamite
+private:
+  bool lateInit;
+public:
+#ifdef __DYNAMIC_DEVICE_PROBE
+  virtual bool SetIdleDevice(bool Idle, bool TestOnly);
+#endif
+// END vdr-plugin-dynamite
   };
 
 SCDEVICE::SCDEVICE(cScDevicePlugin *DevPlugin, int Adapter, int Frontend, int cafd)
@@ -75,6 +83,9 @@ SCDEVICE::SCDEVICE(cScDevicePlugin *DevPlugin, int Adapter, int Frontend, int ca
 :DVBDEVICE(Adapter)
 #endif //APIVERSNUM >= 10711
 {
+// BEGIN vdr-plugin-dynamite
+  lateInit = false;
+// END vdr-plugin-dynamite
 #ifndef SASC
   tsBuffer=0; hwciadapter=0;
 #endif
@@ -88,10 +99,18 @@ SCDEVICE::SCDEVICE(cScDevicePlugin *DevPlugin, int Adapter, int Frontend, int ca
 #ifdef SASC
   cam=new cCam(this,Adapter,0,devId,devplugin,softcsa,fullts);
 #endif // !SASC
+// BEGIN vdr-plugin-dynamite
+  cScDevices::AddScDevice(this);
+  if (cScDevices::AutoLateInit())
+     LateInit();
+// END vdr-plugin-dynamite
 }
 
 SCDEVICE::~SCDEVICE()
 {
+// BEGIN vdr-plugin-dynamite
+  cScDevices::DelScDevice(this);
+// END vdr-plugin-dynamite
 #ifndef SASC
   DetachAllReceivers();
   Cancel(3);
@@ -139,6 +158,9 @@ bool SCDEVICE::CheckFullTs(void)
 
 void SCDEVICE::LateInit(void)
 {
+  if (lateInit)
+     return;
+  lateInit = true;
   int n=CardIndex();
   if(DeviceNumber()!=n)
     PRINTF(L_GEN_ERROR,"CardIndex - DeviceNumber mismatch! Put SC plugin first on VDR commandline!");
@@ -155,8 +177,17 @@ void SCDEVICE::LateInit(void)
     if(fullts) PRINTF(L_GEN_INFO,"Enabling hybrid full-ts mode on card %s",devId);
     else PRINTF(L_GEN_INFO,"Using software decryption on card %s",devId);
     }
-  if(fd_ca2>=0) hwciadapter=cDvbCiAdapter::CreateCiAdapter(this,fd_ca2);
-  cam=new cCam(this,DVB_DEV_SPEC,devId,devplugin,softcsa,fullts);
+// BEGIN vdr-plugin-dynamite
+#ifdef __DYNAMIC_DEVICE_PROBE
+  cDevice *cidev = parentDevice ? parentDevice : this;
+#else
+  cDevice *cidev = this;
+#endif
+  if(fd_ca2>=0) hwciadapter=cDvbCiAdapter::CreateCiAdapter(cidev,fd_ca2);
+  if (cidev != this)
+     fd_ca2 = -1; // will be closed by patched cDvbCiAdapter
+  cam=new cCam(cidev,DVB_DEV_SPEC,devId,devplugin,softcsa,fullts);
+// END vdr-plugin-dynamite
 }
 
 bool SCDEVICE::HasCi(void)
@@ -225,6 +256,36 @@ bool SCDEVICE::GetTSPacket(uchar *&Data)
   return false;
 }
 
+// BEGIN vdr-plugin-dynamite
+#ifdef __DYNAMIC_DEVICE_PROBE
+bool SCDEVICE::SetIdleDevice(bool Idle, bool TestOnly)
+{
+  if (TestOnly) {
+     if (hwciadapter)
+        return hwciadapter->SetIdle(Idle, true);
+     return DVBDEVICE::SetIdleDevice(Idle, true);
+     }
+  if (hwciadapter && !hwciadapter->SetIdle(Idle, false))
+     return false;
+  if (!DVBDEVICE::SetIdleDevice(Idle, false)) {
+     if (hwciadapter)
+        hwciadapter->SetIdle(!Idle, false);
+     return false;
+     }
+  if (Idle) {
+     if (fd_ca >= 0)
+        close(fd_ca);
+     fd_ca = -1;
+     }
+  else {
+     if (fd_ca < 0)
+        fd_ca = cScDevices::DvbOpen(DEV_DVB_CA,adapter,frontend,O_RDWR);
+     }
+  return true;
+}
+#endif
+// END vdr-plugin-dynamite
+
 #endif // !SASC
 
 #undef SCDEVICE
diff --git a/device.c b/device.c
index 04bbef1..b5b165e 100644
--- a/device.c
+++ b/device.c
@@ -285,6 +285,58 @@ uint32_t cScDeviceProbe::GetSubsystemId(int Adapter, int Frontend)
 
 int cScDevices::budget=0;
 
+// BEGIN vdr-plugin-dynamite
+// dynamite fills the vdr::cDevice::device array with vdr::plugin::dynamite::cDynamicDevice
+// we have to maintain our own list of sc-devices
+int cScDevices::numScDevices = 0;
+cDevice *cScDevices::scdevice[MAXDEVICES] = { NULL };
+bool cScDevices::autoLateInit = false;
+
+int cScDevices::NumScDevices(void)
+{
+  return numScDevices;
+}
+
+cDevice *cScDevices::GetScDevice(int CardIndex)
+{
+  for (int n = 0; n < numScDevices; n++) {
+      if (scdevice[n] && (scdevice[n]->CardIndex() == CardIndex))
+         return scdevice[n];
+      }
+  return NULL;
+}
+
+void cScDevices::AddScDevice(cDevice *Device)
+{
+  if (Device == NULL)
+     return;
+  int i = 0;
+  while ((i < numScDevices) && (i < MAXDEVICES) && (scdevice[i] != Device))
+        i++;
+  if (i < MAXDEVICES) {
+     scdevice[i] = Device;
+     if (i == numScDevices)
+        numScDevices++;
+     }
+  else
+     esyslog("too many sc-devices!");
+}
+
+void cScDevices::DelScDevice(cDevice *Device)
+{
+  if (Device == NULL)
+     return;
+  int i = 0;
+  while ((i < numScDevices) && (i < MAXDEVICES)) {
+        if (scdevice[i] == Device) {
+           scdevice[i] = NULL;
+           break;
+           }
+        i++;
+        }
+}
+// END vdr-plugin-dynamite
+
 void cScDevices::DvbName(const char *Name, int a, int f, char *buffer, int len)
 {
   snprintf(buffer,len,"%s/%s%d/%s%d",DEV_DVB_BASE,DEV_DVB_ADAPTER,a,Name,f);
@@ -393,17 +445,22 @@ void cScDevices::Startup(void)
 {
   if(ScSetup.ForceTransfer)
     SetTransferModeForDolbyDigital(2);
-  for(int n=cDevice::NumDevices(); --n>=0;) {
-    cDevice *dev=cDevice::GetDevice(n);
+// BEGIN vdr-plugin-dynamite
+  for(int n=NumScDevices(); --n>=0;) {
+    cDevice *dev=GetScDevice(n);
     for(cScDevicePlugin *dp=devplugins.First(); dp; dp=devplugins.Next(dp))
       if(dp->LateInit(dev)) break;
     }
+  autoLateInit = true;
+// END vdr-plugin-dynamite
 }
 
 void cScDevices::Shutdown(void)
 {
-  for(int n=cDevice::NumDevices(); --n>=0;) {
-    cDevice *dev=cDevice::GetDevice(n);
+// BEGIN vdr-plugin-dynamite
+  for(int n=NumScDevices(); --n>=0;) {
+    cDevice *dev=GetScDevice(n);
+// END vdr-plugin-dynamite
     for(cScDevicePlugin *dp=devplugins.First(); dp; dp=devplugins.Next(dp))
       if(dp->EarlyShutdown(dev)) break;
     }
diff --git a/device.h b/device.h
index c251f5d..a7d5b0e 100644
--- a/device.h
+++ b/device.h
@@ -87,6 +87,21 @@ public:
   static bool ForceBudget(int n);
   static void DvbName(const char *Name, int a, int f, char *buffer, int len);
   static int DvbOpen(const char *Name, int a, int f, int Mode, bool ReportError=false);
+
+// BEGIN vdr-plugin-dynamite
+// dynamite fills the vdr::cDevice::device array with vdr::plugin::dynamite::cDynamicDevice
+// we have to maintain our own list of sc-devices
+private:
+  static int numScDevices;
+  static cDevice *scdevice[MAXDEVICES];
+  static bool autoLateInit;
+public:
+  static int NumScDevices(void);
+  static cDevice *GetScDevice(int CardIndex);
+  static void AddScDevice(cDevice *Device);
+  static void DelScDevice(cDevice *Device);
+  static bool AutoLateInit() { return autoLateInit; };
+// END vdr-plugin-dynamite
   };
 
 // ----------------------------------------------------------------
diff --git a/sc.c b/sc.c
index 099392c..0b45047 100644
--- a/sc.c
+++ b/sc.c
@@ -968,8 +968,8 @@ cScSetup::cScSetup(void)
 {
   AutoUpdate=1;
   memset(ScCaps,0,sizeof(ScCaps));
-  ScCaps[0]=1;
-  ScCaps[1]=2;
+  for(int i=0; i<MAXSCCAPS; i++)
+    ScCaps[i]=i+1;
   ConcurrentFF=0;
   LocalPriority=0;
   ForceTransfer=1;