summaryrefslogtreecommitdiff
path: root/device.c
diff options
context:
space:
mode:
authorKlaus Schmidinger <vdr@tvdr.de>2017-03-18 16:33:59 +0100
committerKlaus Schmidinger <vdr@tvdr.de>2017-03-18 16:33:59 +0100
commit2cc25e65f445162fad126f4e4b29bc380e002c0f (patch)
tree113bfcaf0fec1a76a14820be3556c95c28a22c00 /device.c
parent3f9cdea1c16cb25b7a3ce7c875d46e6d100d593d (diff)
downloadvdr-2cc25e65f445162fad126f4e4b29bc380e002c0f.tar.gz
vdr-2cc25e65f445162fad126f4e4b29bc380e002c0f.tar.bz2
Implemented support for MTD
Diffstat (limited to 'device.c')
-rw-r--r--device.c86
1 files changed, 77 insertions, 9 deletions
diff --git a/device.c b/device.c
index 0c8b0018..b6a6ee10 100644
--- a/device.c
+++ b/device.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: device.c 4.7 2017/02/21 13:38:01 kls Exp $
+ * $Id: device.c 4.8 2017/03/18 15:45:53 kls Exp $
*/
#include "device.h"
@@ -281,8 +281,13 @@ cDevice *cDevice::GetDevice(const cChannel *Channel, int Priority, bool LiveView
continue; // CAM slot can't be used with this device
bool ndr;
if (device[i]->ProvidesChannel(Channel, Priority, &ndr)) { // this device is basically able to do the job
- if (NumUsableSlots && !HasInternalCam && device[i]->CamSlot() && device[i]->CamSlot() != CamSlots.Get(j))
- ndr = true; // using a different CAM slot requires detaching receivers
+ if (NumUsableSlots && !HasInternalCam) {
+ if (cCamSlot *csi = device[i]->CamSlot()) {
+ cCamSlot *csj = CamSlots.Get(j);
+ if ((csj->MtdActive() ? csi->MasterSlot() : csi) != csj)
+ ndr = true; // using a different CAM slot requires detaching receivers
+ }
+ }
// Put together an integer number that reflects the "impact" using
// this device would have on the overall system. Each condition is represented
// by one bit in the number (or several bits, if the condition is actually
@@ -319,12 +324,75 @@ cDevice *cDevice::GetDevice(const cChannel *Channel, int Priority, bool LiveView
if (NeedsDetachReceivers)
d->DetachAllReceivers();
if (s) {
- if (s->Device() != d) {
- if (s->Device())
- s->Device()->DetachAllReceivers();
- if (d->CamSlot())
- d->CamSlot()->Assign(NULL);
- s->Assign(d);
+ // Some of the following statements could probably be combined, but let's keep them
+ // explicit so we can clearly see every single aspect of the decisions made here.
+ if (d->CamSlot()) {
+ if (s->MtdActive()) {
+ if (s == d->CamSlot()->MasterSlot()) {
+ // device d already has a proper CAM slot, so nothing to do here
+ }
+ else {
+ // device d has a CAM slot, but it's not the right one
+ d->CamSlot()->Assign(NULL);
+ s = s->MtdSpawn();
+ s->Assign(d);
+ }
+ }
+ else {
+ if (s->Device()) {
+ if (s->Device() != d) {
+ // CAM slot s is currently assigned to a different device than d
+ if (Priority > s->Priority()) {
+ s->Device()->DetachAllReceivers();
+ d->CamSlot()->Assign(NULL);
+ s->Assign(d);
+ }
+ else {
+ d = NULL;
+ s = NULL;
+ }
+ }
+ else {
+ // device d already has a proper CAM slot, so nothing to do here
+ }
+ }
+ else {
+ if (s != d->CamSlot()) {
+ // device d has a CAM slot, but it's not the right one
+ d->CamSlot()->Assign(NULL);
+ s->Assign(d);
+ }
+ else {
+ // device d already has a proper CAM slot, so nothing to do here
+ }
+ }
+ }
+ }
+ else {
+ // device d has no CAM slot, ...
+ if (s->MtdActive()) {
+ // ... so we assign s with MTD support
+ s = s->MtdSpawn();
+ s->Assign(d);
+ }
+ else {
+ // CAM slot s has no MTD support ...
+ if (s->Device()) {
+ // ... but it is assigned to a different device, so we reassign it to d
+ if (Priority > s->Priority()) {
+ s->Device()->DetachAllReceivers();
+ s->Assign(d);
+ }
+ else {
+ d = NULL;
+ s = NULL;
+ }
+ }
+ else {
+ // ... and is not assigned to any device, so we just assign it to d
+ s->Assign(d);
+ }
+ }
}
}
else if (d->CamSlot() && !d->CamSlot()->IsDecrypting())