From patchwork Sat May 27 09:42:58 2006 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Klaus Schmidinger X-Patchwork-Id: 12320 Received: from raven.cadsoft.de ([217.7.101.211]) by www.linuxtv.org with esmtp (Exim 4.50) id 1FjvKA-0003EU-Va for vdr@linuxtv.org; Sat, 27 May 2006 11:43:11 +0200 Received: from [192.168.100.10] (hawk.cadsoft.de [192.168.100.10]) by raven.cadsoft.de (8.13.3/8.13.3) with ESMTP id k4R9h0Hi031054 for ; Sat, 27 May 2006 11:43:00 +0200 Message-ID: <44781F22.601@cadsoft.de> Date: Sat, 27 May 2006 11:42:58 +0200 From: Klaus Schmidinger Organization: CadSoft Computer GmbH User-Agent: Thunderbird 1.5.0.2 (X11/20060420) MIME-Version: 1.0 To: vdr@linuxtv.org Subject: Re: [vdr] RFC: recording strategy on timer conflicts References: <200605200840.48851.cwieninger@gmx.de> <200605232332.14916.cwieninger@gmx.de> <4477000B.60408@cadsoft.de> <200605270758.39474.cwieninger@gmx.de> <447815A2.3090502@cadsoft.de> In-Reply-To: <447815A2.3090502@cadsoft.de> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0 (raven.cadsoft.de [192.168.1.1]); Sat, 27 May 2006 11:43:00 +0200 (CEST) X-BeenThere: vdr@linuxtv.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: VDR Mailing List List-Id: VDR Mailing List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 May 2006 09:43:11 -0000 Status: O X-Status: X-Keywords: X-UID: 9605 Klaus Schmidinger wrote: > Christian Wieninger wrote: >> ... >>> //XXX what if Priority() is < -1? -> limit to -1..MAXPRIORITY??? >> >> how can one set a priority below -1 and what would this mean? As far >> as understood the cDevice class, this can only be done in a >> cDevice-derived class. So perhaps cDevice::Priority should limit its >> return value to -1 ... MAXPRIORITY? > > The priority comes from the cReveicers attached to the device: > > cReceiver(int Ca, int Priority, int Pid, const int *Pids1 = NULL, > const int *Pids2 = NULL, const int *Pids3 = NULL); > ... > ///< Priority may be any value in the range 0..99. Negative values > indicate > ///< that this cReceiver may be detached at any time (without > blocking the > ///< cDevice it is attached to). > > So officially the value can't be greater than 99, but it may well > be any negative value. However, VDR itself only uses '-1', and I guess > it's fair to assume that no plugin will be using too large negative > values. To be on the safe side I guess I'll do > > imp <<= 8; imp |= min(max(device[i]->Priority() + MAXPRIORITY, 0), > 0xFF); > > which would allow values in the range -99..99, and in any case limit the > result to 0..255. I just noticed that I have inadvertently removed assigning 'ndr' to the resulting 'NeedsDetachReceivers'. So attached is an updated version of the fix. Klaus --- device.c 2006/04/14 14:34:43 1.128 +++ device.c 2006/05/27 09:38:38 @@ -281,32 +281,20 @@ cDevice *cDevice::GetDevice(const cChannel *Channel, int Priority, bool *NeedsDetachReceivers) { cDevice *d = NULL; - int select = INT_MAX; - + uint Impact = 0xFFFFFFFF; for (int i = 0; i < numDevices; i++) { bool ndr; if (device[i]->ProvidesChannel(Channel, Priority, &ndr)) { // this device is basicly able to do the job - int pri; - if (device[i]->Receiving() && !ndr) - pri = 0; // receiving and allows additional receivers - else if (!device[i]->Receiving(true) && d && device[i]->ProvidesCa(Channel) < d->ProvidesCa(Channel)) - pri = 1; // free and fewer Ca's - else if (!device[i]->Receiving() && !device[i]->HasDecoder()) - pri = 2; // free and not a full featured card - else if (!device[i]->Receiving() && device[i] != ActualDevice()) - pri = 3; // free and not the actual device - else if (!device[i]->Receiving() && !device[i]->IsPrimaryDevice()) - pri = 4; // free and not the primary device - else if (!device[i]->Receiving()) - pri = 5; // free - else if (d && device[i]->Priority() < d->Priority()) - pri = 6; // receiving but priority is lower - else if (d && device[i]->Priority() == d->Priority() && device[i]->ProvidesCa(Channel) < d->ProvidesCa(Channel)) - pri = 7; // receiving with same priority but fewer Ca's - else - pri = 8; // all others - if (pri <= select) { - select = pri; + uint imp = 0; + imp <<= 1; imp |= !device[i]->Receiving() || ndr; + imp <<= 1; imp |= device[i]->Receiving(); + imp <<= 1; imp |= device[i] == ActualDevice(); + imp <<= 1; imp |= device[i]->IsPrimaryDevice(); + imp <<= 1; imp |= device[i]->HasDecoder(); + imp <<= 8; imp |= min(max(device[i]->Priority() + MAXPRIORITY, 0), 0xFF); + imp <<= 8; imp |= min(max(device[i]->ProvidesCa(Channel), 0), 0xFF); + if (imp < Impact) { + Impact = imp; d = device[i]; if (NeedsDetachReceivers) *NeedsDetachReceivers = ndr;