2002-06-16 12:57:31 +02:00
|
|
|
/*
|
|
|
|
* device.c: The basic device interface
|
|
|
|
*
|
|
|
|
* See the main source file 'vdr.c' for copyright information and
|
|
|
|
* how to reach the author.
|
|
|
|
*
|
2002-08-04 15:18:05 +02:00
|
|
|
* $Id: device.c 1.8 2002/08/04 15:18:05 kls Exp $
|
2002-06-16 12:57:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "device.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mman.h>
|
2002-08-04 14:57:29 +02:00
|
|
|
#include "eit.h"
|
2002-06-16 12:57:31 +02:00
|
|
|
#include "player.h"
|
|
|
|
#include "receiver.h"
|
|
|
|
#include "status.h"
|
2002-06-22 13:45:53 +02:00
|
|
|
#include "transfer.h"
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
// The default priority for non-primary devices:
|
2002-06-16 12:57:31 +02:00
|
|
|
#define DEFAULTPRIORITY -2
|
|
|
|
|
|
|
|
// The maximum time we wait before assuming that a recorded video data stream
|
|
|
|
// is broken:
|
|
|
|
#define MAXBROKENTIMEOUT 30 // seconds
|
|
|
|
|
|
|
|
int cDevice::numDevices = 0;
|
|
|
|
int cDevice::useDevice = 0;
|
2002-08-04 14:57:29 +02:00
|
|
|
int cDevice::nextCardIndex = 0;
|
2002-06-16 12:57:31 +02:00
|
|
|
cDevice *cDevice::device[MAXDEVICES] = { NULL };
|
|
|
|
cDevice *cDevice::primaryDevice = NULL;
|
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
cDevice::cDevice(void)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
2002-08-04 14:57:29 +02:00
|
|
|
cardIndex = nextCardIndex++;
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
SetVideoFormat(Setup.VideoFormat);
|
2002-06-16 12:57:31 +02:00
|
|
|
|
|
|
|
active = false;
|
|
|
|
|
|
|
|
currentChannel = 0;
|
|
|
|
|
|
|
|
mute = false;
|
|
|
|
volume = Setup.CurrentVolume;
|
|
|
|
|
|
|
|
player = NULL;
|
|
|
|
|
|
|
|
for (int i = 0; i < MAXRECEIVERS; i++)
|
|
|
|
receiver[i] = NULL;
|
|
|
|
ca = -1;
|
2002-08-04 14:57:29 +02:00
|
|
|
|
|
|
|
if (numDevices < MAXDEVICES) {
|
|
|
|
device[numDevices++] = this;
|
|
|
|
SetCaCaps(cardIndex);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
esyslog("ERROR: too many devices!");
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cDevice::~cDevice()
|
|
|
|
{
|
|
|
|
Detach(player);
|
|
|
|
for (int i = 0; i < MAXRECEIVERS; i++)
|
|
|
|
Detach(receiver[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::SetUseDevice(int n)
|
|
|
|
{
|
|
|
|
if (n < MAXDEVICES)
|
|
|
|
useDevice |= (1 << n);
|
|
|
|
}
|
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
int cDevice::NextCardIndex(int n)
|
|
|
|
{
|
|
|
|
if (n > 0) {
|
|
|
|
nextCardIndex += n;
|
|
|
|
if (nextCardIndex >= MAXDEVICES)
|
|
|
|
esyslog("ERROR: nextCardIndex too big (%d)", nextCardIndex);
|
|
|
|
}
|
|
|
|
else if (n < 0)
|
|
|
|
esyslog("ERROR: illegal value in IncCardIndex(%d)", n);
|
|
|
|
return nextCardIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::MakePrimaryDevice(bool On)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-06-16 12:57:31 +02:00
|
|
|
bool cDevice::SetPrimaryDevice(int n)
|
|
|
|
{
|
|
|
|
n--;
|
|
|
|
if (0 <= n && n < numDevices && device[n]) {
|
|
|
|
isyslog("setting primary device to %d", n + 1);
|
2002-08-04 14:57:29 +02:00
|
|
|
if (primaryDevice)
|
|
|
|
primaryDevice->MakePrimaryDevice(false);
|
2002-06-16 12:57:31 +02:00
|
|
|
primaryDevice = device[n];
|
2002-08-04 14:57:29 +02:00
|
|
|
primaryDevice->MakePrimaryDevice(true);
|
2002-06-16 12:57:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
2002-08-04 14:57:29 +02:00
|
|
|
esyslog("invalid device number: %d", n + 1);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cDevice::CanBeReUsed(int Frequency, int Vpid)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cDevice::HasDecoder(void) const
|
|
|
|
{
|
2002-06-16 12:57:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cDevice *cDevice::GetDevice(int Ca, int Priority, int Frequency, int Vpid, bool *ReUse)
|
|
|
|
{
|
|
|
|
if (ReUse)
|
|
|
|
*ReUse = false;
|
|
|
|
cDevice *d = NULL;
|
|
|
|
int Provides[MAXDEVICES];
|
|
|
|
// Check which devices provide Ca:
|
|
|
|
for (int i = 0; i < numDevices; i++) {
|
|
|
|
if ((Provides[i] = device[i]->ProvidesCa(Ca)) != 0) { // this device is basicly able to do the job
|
|
|
|
//XXX+ dsyslog("GetDevice: %d %d %d %5d %5d", i, device[i]->HasDecoder(), device[i]->Receiving(), Frequency, device[i]->frequency);//XXX
|
2002-08-04 14:57:29 +02:00
|
|
|
if (device[i]->CanBeReUsed(Frequency, Vpid)) {
|
2002-06-16 12:57:31 +02:00
|
|
|
d = device[i];
|
|
|
|
if (ReUse)
|
|
|
|
*ReUse = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (Priority > device[i]->Priority() // Priority is high enough to use this device
|
|
|
|
&& (!d // we don't have a device yet, or...
|
|
|
|
|| device[i]->Priority() < d->Priority() // ...this one has an even lower Priority
|
|
|
|
|| (device[i]->Priority() == d->Priority() // ...same Priority...
|
|
|
|
&& Provides[i] < Provides[d->CardIndex()] // ...but this one provides fewer Ca values
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
d = device[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*XXX+ too complex with multiple recordings per device
|
|
|
|
if (!d && Ca > MAXDEVICES) {
|
|
|
|
// We didn't find one the easy way, so now we have to try harder:
|
|
|
|
int ShiftLevel = -1;
|
|
|
|
for (int i = 0; i < numDevices; i++) {
|
|
|
|
if (Provides[i]) { // this device is basicly able to do the job, but for some reason we didn't get it above
|
|
|
|
int sl = device[i]->CanShift(Ca, Priority); // asks this device to shift its job to another device
|
|
|
|
if (sl >= 0 && (ShiftLevel < 0 || sl < ShiftLevel)) {
|
|
|
|
d = device[i]; // found one that can be shifted with the fewest number of subsequent shifts
|
|
|
|
ShiftLevel = sl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XXX*/
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
void cDevice::SetCaCaps(int Index)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
|
|
|
for (int d = 0; d < numDevices; d++) {
|
2002-08-04 14:57:29 +02:00
|
|
|
if (Index < 0 || Index == device[d]->CardIndex()) {
|
|
|
|
for (int i = 0; i < MAXCACAPS; i++)
|
|
|
|
device[d]->caCaps[i] = Setup.CaCaps[device[d]->CardIndex()][i];
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::Shutdown(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < numDevices; i++) {
|
|
|
|
delete device[i];
|
|
|
|
device[i] = NULL;
|
|
|
|
}
|
|
|
|
primaryDevice = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cDevice::GrabImage(const char *FileName, bool Jpeg, int Quality, int SizeX, int SizeY)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
void cDevice::SetVideoFormat(bool VideoFormat16_9)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//#define PRINTPIDS(s) { char b[500]; char *q = b; q += sprintf(q, "%d %s ", CardIndex(), s); for (int i = 0; i < MAXPIDHANDLES; i++) q += sprintf(q, " %s%4d %d", i == ptOther ? "* " : "", pidHandles[i].pid, pidHandles[i].used); dsyslog(b); } //XXX+
|
|
|
|
#define PRINTPIDS(s)
|
|
|
|
|
|
|
|
bool cDevice::AddPid(int Pid, ePidType PidType)
|
|
|
|
{
|
|
|
|
if (Pid) {
|
|
|
|
int n = -1;
|
|
|
|
int a = -1;
|
|
|
|
for (int i = 0; i < MAXPIDHANDLES; i++) {
|
|
|
|
if (pidHandles[i].pid == Pid)
|
|
|
|
n = i;
|
|
|
|
else if (a < 0 && i >= ptOther && !pidHandles[i].used)
|
|
|
|
a = i;
|
|
|
|
}
|
|
|
|
if (n >= 0) {
|
|
|
|
// The Pid is already in use
|
|
|
|
if (++pidHandles[n].used == 2 && n <= ptTeletext) {
|
2002-08-04 14:57:29 +02:00
|
|
|
// It's a special PID that may have to be switched into "tap" mode
|
2002-06-16 12:57:31 +02:00
|
|
|
PRINTPIDS("A");//XXX+
|
2002-08-04 14:57:29 +02:00
|
|
|
return SetPid(&pidHandles[n], n, true);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
PRINTPIDS("a");//XXX+
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (PidType < ptOther) {
|
|
|
|
// The Pid is not yet in use and it is a special one
|
|
|
|
n = PidType;
|
|
|
|
}
|
|
|
|
else if (a >= 0) {
|
|
|
|
// The Pid is not yet in use and we have a free slot
|
|
|
|
n = a;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
esyslog("ERROR: no free slot for PID %d", Pid);
|
|
|
|
if (n >= 0) {
|
|
|
|
pidHandles[n].pid = Pid;
|
|
|
|
pidHandles[n].used = 1;
|
|
|
|
PRINTPIDS("C");//XXX+
|
2002-08-04 14:57:29 +02:00
|
|
|
return SetPid(&pidHandles[n], n, true);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
void cDevice::DelPid(int Pid)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
|
|
|
if (Pid) {
|
|
|
|
for (int i = 0; i < MAXPIDHANDLES; i++) {
|
|
|
|
if (pidHandles[i].pid == Pid) {
|
2002-08-04 14:57:29 +02:00
|
|
|
if (--pidHandles[i].used < 2) {
|
|
|
|
SetPid(&pidHandles[i], i, false);
|
|
|
|
if (pidHandles[i].used == 0) {
|
|
|
|
pidHandles[i].handle = -1;
|
|
|
|
pidHandles[i].pid = 0;
|
|
|
|
}
|
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
PRINTPIDS("D");//XXX+
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
bool cDevice::SetPid(cPidHandle *Handle, int Type, bool On)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
2002-08-04 14:57:29 +02:00
|
|
|
return false;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
eSetChannelResult cDevice::SetChannel(const cChannel *Channel)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
2002-06-16 13:26:00 +02:00
|
|
|
cStatus::MsgChannelSwitch(this, 0);
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
StopReplay();
|
|
|
|
|
2002-06-16 12:57:31 +02:00
|
|
|
// Must set this anyway to avoid getting stuck when switching through
|
|
|
|
// channels with 'Up' and 'Down' keys:
|
2002-08-04 14:57:29 +02:00
|
|
|
currentChannel = Channel->number;
|
2002-06-16 12:57:31 +02:00
|
|
|
|
|
|
|
// If this card can't receive this channel, we must not actually switch
|
|
|
|
// the channel here, because that would irritate the driver when we
|
|
|
|
// start replaying in Transfer Mode immediately after switching the channel:
|
2002-08-04 14:57:29 +02:00
|
|
|
bool NeedsTransferMode = (IsPrimaryDevice() && !ProvidesCa(Channel->ca));
|
2002-06-16 12:57:31 +02:00
|
|
|
|
|
|
|
eSetChannelResult Result = scrOk;
|
|
|
|
|
|
|
|
// If this DVB card can't receive this channel, let's see if we can
|
|
|
|
// use the card that actually can receive it and transfer data from there:
|
|
|
|
|
|
|
|
if (NeedsTransferMode) {
|
2002-08-04 14:57:29 +02:00
|
|
|
cDevice *CaDevice = GetDevice(Channel->ca, 0);
|
|
|
|
if (CaDevice && !CaDevice->Receiving() && CaDevice->SetChannel(Channel) == scrOk)
|
|
|
|
cControl::Launch(new cTransferControl(CaDevice, Channel->vpid, Channel->apid1, 0, 0, 0));//XXX+
|
2002-06-16 12:57:31 +02:00
|
|
|
else
|
|
|
|
Result = scrNoTransfer;
|
|
|
|
}
|
2002-08-04 14:57:29 +02:00
|
|
|
else if (!SetChannelDevice(Channel))
|
|
|
|
Result = scrFailed;
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
if (IsPrimaryDevice())
|
|
|
|
cSIProcessor::SetCurrentServiceID(Channel->pnr);
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
cStatus::MsgChannelSwitch(this, Channel->number);
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
return Result;
|
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
bool cDevice::SetChannelDevice(const cChannel *Channel)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
void cDevice::SetVolumeDevice(int Volume)
|
|
|
|
{
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cDevice::ToggleMute(void)
|
|
|
|
{
|
|
|
|
int OldVolume = volume;
|
|
|
|
mute = !mute;
|
|
|
|
SetVolume(0, mute);
|
|
|
|
volume = OldVolume;
|
|
|
|
return mute;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::SetVolume(int Volume, bool Absolute)
|
|
|
|
{
|
2002-08-04 14:57:29 +02:00
|
|
|
volume = min(max(Absolute ? Volume : volume + Volume, 0), MAXVOLUME);
|
|
|
|
SetVolumeDevice(volume);
|
|
|
|
cStatus::MsgSetVolume(volume, Absolute);
|
|
|
|
if (volume > 0)
|
|
|
|
mute = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cDevice::SetPlayMode(bool On)
|
|
|
|
{
|
|
|
|
return -1;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::TrickSpeed(int Speed)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::Clear(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::Play(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::Freeze(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::Mute(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::StillPicture(const uchar *Data, int Length)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cDevice::Replaying(void)
|
|
|
|
{
|
|
|
|
return player != NULL;
|
|
|
|
}
|
|
|
|
|
2002-06-22 13:45:53 +02:00
|
|
|
bool cDevice::AttachPlayer(cPlayer *Player)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
|
|
|
if (Receiving()) {
|
|
|
|
esyslog("ERROR: attempt to attach a cPlayer while receiving on device %d - ignored", CardIndex() + 1);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (HasDecoder()) {
|
|
|
|
if (player)
|
|
|
|
Detach(player);
|
|
|
|
player = Player;
|
|
|
|
player->device = this;
|
2002-08-04 14:57:29 +02:00
|
|
|
player->deviceFileHandle = SetPlayMode(true);
|
2002-06-16 12:57:31 +02:00
|
|
|
player->Activate(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::Detach(cPlayer *Player)
|
|
|
|
{
|
|
|
|
if (Player && player == Player) {
|
|
|
|
player->Activate(false);
|
|
|
|
player->deviceFileHandle = -1;
|
|
|
|
player->device = NULL;
|
|
|
|
player = NULL;
|
2002-08-04 14:57:29 +02:00
|
|
|
SetPlayMode(false);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::StopReplay(void)
|
|
|
|
{
|
|
|
|
if (player) {
|
|
|
|
Detach(player);
|
2002-06-23 12:59:58 +02:00
|
|
|
if (IsPrimaryDevice())
|
|
|
|
cControl::Shutdown();
|
2002-06-16 12:57:31 +02:00
|
|
|
/*XXX+
|
|
|
|
if (IsPrimaryDevice()) {
|
|
|
|
// let's explicitly switch the channel back in case it was in Transfer Mode:
|
|
|
|
cChannel *Channel = Channels.GetByNumber(currentChannel);
|
|
|
|
if (Channel) {
|
|
|
|
Channel->Switch(this, false);
|
|
|
|
usleep(100000); // allow driver to sync in case a new replay will start immediately
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XXX*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int cDevice::PlayVideo(const uchar *Data, int Length)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cDevice::PlayAudio(const uchar *Data, int Length)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cDevice::Priority(void)
|
|
|
|
{
|
|
|
|
if (IsPrimaryDevice() && !Receiving())
|
|
|
|
return Setup.PrimaryLimit - 1;
|
|
|
|
int priority = DEFAULTPRIORITY;
|
|
|
|
for (int i = 0; i < MAXRECEIVERS; i++) {
|
|
|
|
if (receiver[i])
|
|
|
|
priority = max(receiver[i]->priority, priority);
|
|
|
|
}
|
|
|
|
return priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cDevice::CanShift(int Ca, int Priority, int UsedCards)
|
|
|
|
{
|
|
|
|
return -1;//XXX+ too complex with multiple recordings per device
|
2002-08-04 14:57:29 +02:00
|
|
|
// Test whether a receiver on this device can be shifted to another one
|
2002-06-16 12:57:31 +02:00
|
|
|
// in order to perform a new receiving with the given Ca and Priority on this device:
|
|
|
|
int ShiftLevel = -1; // default means this device can't be shifted
|
|
|
|
if (UsedCards & (1 << CardIndex()) != 0)
|
|
|
|
return ShiftLevel; // otherwise we would get into a loop
|
|
|
|
if (Receiving()) {
|
|
|
|
if (ProvidesCa(Ca) // this device provides the requested Ca
|
|
|
|
&& (Ca != this->Ca() // the requested Ca is different from the one currently used...
|
|
|
|
|| Priority > this->Priority())) { // ...or the request comes from a higher priority
|
|
|
|
cDevice *d = NULL;
|
|
|
|
int Provides[MAXDEVICES];
|
|
|
|
UsedCards |= (1 << CardIndex());
|
|
|
|
for (int i = 0; i < numDevices; i++) {
|
|
|
|
if ((Provides[i] = device[i]->ProvidesCa(this->Ca())) != 0) { // this device is basicly able to do the job
|
|
|
|
if (device[i] != this) { // it is not _this_ device
|
|
|
|
int sl = device[i]->CanShift(this->Ca(), Priority, UsedCards); // this is the original Priority!
|
|
|
|
if (sl >= 0 && (ShiftLevel < 0 || sl < ShiftLevel)) {
|
|
|
|
d = device[i];
|
|
|
|
ShiftLevel = sl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ShiftLevel >= 0)
|
|
|
|
ShiftLevel++; // adds the device's own shift
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Priority > this->Priority())
|
|
|
|
ShiftLevel = 0; // no shifting necessary, this device can do the job
|
|
|
|
return ShiftLevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cDevice::ProvidesCa(int Ca)
|
|
|
|
{
|
|
|
|
if (Ca == CardIndex() + 1)
|
|
|
|
return 1; // exactly _this_ card was requested
|
|
|
|
if (Ca && Ca <= MAXDEVICES)
|
|
|
|
return 0; // a specific card was requested, but not _this_ one
|
|
|
|
int result = Ca ? 0 : 1; // by default every card can provide FTA
|
|
|
|
int others = Ca ? 1 : 0;
|
|
|
|
for (int i = 0; i < MAXCACAPS; i++) {
|
|
|
|
if (caCaps[i]) {
|
|
|
|
if (caCaps[i] == Ca)
|
|
|
|
result = 1;
|
|
|
|
else
|
|
|
|
others++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result ? result + others : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cDevice::Receiving(void)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < MAXRECEIVERS; i++) {
|
2002-08-04 15:18:05 +02:00
|
|
|
if (receiver[i] && receiver[i]->priority >= 0) // cReceiver with priority < 0 doesn't count
|
2002-06-16 12:57:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::Action(void)
|
|
|
|
{
|
|
|
|
dsyslog("receiver thread started on device %d (pid=%d)", CardIndex() + 1, getpid());
|
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
if (OpenDvr()) {
|
2002-06-16 12:57:31 +02:00
|
|
|
uchar b[TS_SIZE];
|
|
|
|
time_t t = time(NULL);
|
|
|
|
active = true;
|
|
|
|
for (; active;) {
|
|
|
|
// Read data from the DVR device:
|
2002-08-04 14:57:29 +02:00
|
|
|
int r = GetTSPacket(b);
|
|
|
|
if (r == TS_SIZE) {
|
|
|
|
if (*b == TS_SYNC_BYTE) {
|
|
|
|
// We're locked on to a TS packet
|
|
|
|
int Pid = (((uint16_t)b[1] & PID_MASK_HI) << 8) | b[2];
|
|
|
|
// Distribute the packet to all attached receivers:
|
|
|
|
Lock();
|
|
|
|
for (int i = 0; i < MAXRECEIVERS; i++) {
|
|
|
|
if (receiver[i] && receiver[i]->WantsPid(Pid))
|
|
|
|
receiver[i]->Receive(b, TS_SIZE);
|
|
|
|
}
|
|
|
|
Unlock();
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
2002-08-04 14:57:29 +02:00
|
|
|
t = time(NULL);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
2002-08-04 14:57:29 +02:00
|
|
|
else if (r > 0)
|
|
|
|
esyslog("ERROR: got incomplete TS packet (%d bytes) on device %d", r, CardIndex() + 1);//XXX+ TODO do we have to read the rest???
|
|
|
|
else if (r < 0)
|
|
|
|
break;
|
2002-06-16 12:57:31 +02:00
|
|
|
|
|
|
|
//XXX+ put this into the recorder??? or give the receiver a flag whether it wants this?
|
|
|
|
if (time(NULL) - t > MAXBROKENTIMEOUT) {
|
|
|
|
esyslog("ERROR: video data stream broken on device %d", CardIndex() + 1);
|
|
|
|
cThread::EmergencyExit(true);
|
|
|
|
t = time(NULL);
|
|
|
|
}
|
|
|
|
}
|
2002-08-04 14:57:29 +02:00
|
|
|
CloseDvr();
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
dsyslog("receiver thread ended on device %d (pid=%d)", CardIndex() + 1, getpid());
|
|
|
|
}
|
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
bool cDevice::OpenDvr(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::CloseDvr(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int cDevice::GetTSPacket(uchar *Data)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-06-22 13:45:53 +02:00
|
|
|
bool cDevice::AttachReceiver(cReceiver *Receiver)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
|
|
|
//XXX+ check for same transponder???
|
|
|
|
if (!Receiver)
|
|
|
|
return false;
|
|
|
|
if (Receiver->device == this)
|
|
|
|
return true;
|
|
|
|
StopReplay();
|
|
|
|
for (int i = 0; i < MAXRECEIVERS; i++) {
|
|
|
|
if (!receiver[i]) {
|
2002-07-28 11:29:32 +02:00
|
|
|
for (int n = 0; n < MAXRECEIVEPIDS; n++)
|
|
|
|
AddPid(Receiver->pids[n]);//XXX+ retval!
|
2002-06-16 12:57:31 +02:00
|
|
|
Receiver->Activate(true);
|
|
|
|
Lock();
|
|
|
|
Receiver->device = this;
|
|
|
|
receiver[i] = Receiver;
|
|
|
|
Unlock();
|
|
|
|
Start();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
esyslog("ERROR: no free receiver slot!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::Detach(cReceiver *Receiver)
|
|
|
|
{
|
|
|
|
if (!Receiver || Receiver->device != this)
|
|
|
|
return;
|
|
|
|
bool receiversLeft = false;
|
|
|
|
for (int i = 0; i < MAXRECEIVERS; i++) {
|
|
|
|
if (receiver[i] == Receiver) {
|
|
|
|
Receiver->Activate(false);
|
|
|
|
Lock();
|
|
|
|
receiver[i] = NULL;
|
|
|
|
Receiver->device = NULL;
|
|
|
|
Unlock();
|
2002-07-28 11:29:32 +02:00
|
|
|
for (int n = 0; n < MAXRECEIVEPIDS; n++)
|
|
|
|
DelPid(Receiver->pids[n]);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
else if (receiver[i])
|
|
|
|
receiversLeft = true;
|
|
|
|
}
|
|
|
|
if (!receiversLeft) {
|
|
|
|
active = false;
|
|
|
|
Cancel(3);
|
|
|
|
}
|
|
|
|
}
|