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.
|
|
|
|
*
|
2004-01-04 12:30:00 +01:00
|
|
|
* $Id: device.c 1.51 2004/01/04 11:30:05 kls Exp $
|
2002-06-16 12:57:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "device.h"
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/mman.h>
|
2002-11-03 11:53:58 +01:00
|
|
|
#include "audio.h"
|
2002-10-06 10:25:42 +02:00
|
|
|
#include "channels.h"
|
2002-09-04 17:26:02 +02:00
|
|
|
#include "i18n.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-09-08 09:03:10 +02:00
|
|
|
// --- cDevice ---------------------------------------------------------------
|
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
// The default priority for non-primary devices:
|
2003-05-25 11:02:58 +02:00
|
|
|
#define DEFAULTPRIORITY -1
|
2002-06-16 12:57:31 +02:00
|
|
|
|
|
|
|
int cDevice::numDevices = 0;
|
|
|
|
int cDevice::useDevice = 0;
|
2002-08-04 14:57:29 +02:00
|
|
|
int cDevice::nextCardIndex = 0;
|
2003-06-08 09:25:07 +02:00
|
|
|
int cDevice::currentChannel = 1;
|
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
|
|
|
|
2003-10-18 12:29:08 +02:00
|
|
|
SetDescription("receiver on device %d", CardIndex() + 1);
|
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
SetVideoFormat(Setup.VideoFormat);
|
2002-06-16 12:57:31 +02:00
|
|
|
|
|
|
|
active = false;
|
|
|
|
|
|
|
|
mute = false;
|
|
|
|
volume = Setup.CurrentVolume;
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
sectionHandler = NULL;
|
|
|
|
eitFilter = NULL;
|
|
|
|
patFilter = NULL;
|
2004-01-04 12:30:00 +01:00
|
|
|
sdtFilter = NULL;
|
2003-12-22 13:29:24 +01:00
|
|
|
|
2003-01-06 14:44:27 +01:00
|
|
|
ciHandler = NULL;
|
2002-06-16 12:57:31 +02:00
|
|
|
player = NULL;
|
|
|
|
|
|
|
|
for (int i = 0; i < MAXRECEIVERS; i++)
|
|
|
|
receiver[i] = NULL;
|
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]);
|
2003-01-06 14:44:27 +01:00
|
|
|
delete ciHandler;
|
2004-01-04 12:30:00 +01:00
|
|
|
delete sdtFilter;
|
2003-12-22 13:29:24 +01:00
|
|
|
delete patFilter;
|
2004-01-04 12:30:00 +01:00
|
|
|
delete eitFilter;
|
2003-12-22 13:29:24 +01:00
|
|
|
delete sectionHandler;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-10-07 16:21:46 +02:00
|
|
|
int cDevice::DeviceNumber(void) const
|
|
|
|
{
|
|
|
|
for (int i = 0; i < numDevices; i++) {
|
|
|
|
if (device[i] == this)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
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]) {
|
2003-04-12 12:20:07 +02:00
|
|
|
isyslog("setting primary device to %d", n + 1);
|
|
|
|
if (primaryDevice)
|
|
|
|
primaryDevice->MakePrimaryDevice(false);
|
|
|
|
primaryDevice = device[n];
|
|
|
|
primaryDevice->MakePrimaryDevice(true);
|
|
|
|
return true;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
2003-04-12 12:20:07 +02:00
|
|
|
esyslog("ERROR: invalid primary device number: %d", n + 1);
|
2002-08-04 14:57:29 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cDevice::HasDecoder(void) const
|
|
|
|
{
|
2002-06-16 12:57:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-08-25 09:36:09 +02:00
|
|
|
cOsdBase *cDevice::NewOsd(int x, int y)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-09-08 14:17:51 +02:00
|
|
|
cSpuDecoder *cDevice::GetSpuDecoder(void)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-05-11 09:01:51 +02:00
|
|
|
cDevice *cDevice::ActualDevice(void)
|
|
|
|
{
|
|
|
|
cDevice *d = cTransferControl::ReceiverDevice();
|
|
|
|
if (!d)
|
|
|
|
d = PrimaryDevice();
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2002-09-04 17:26:02 +02:00
|
|
|
cDevice *cDevice::GetDevice(int Index)
|
|
|
|
{
|
|
|
|
return (0 <= Index && Index < numDevices) ? device[Index] : NULL;
|
|
|
|
}
|
|
|
|
|
2002-09-06 14:10:17 +02:00
|
|
|
cDevice *cDevice::GetDevice(const cChannel *Channel, int Priority, bool *NeedsDetachReceivers)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
|
|
|
cDevice *d = NULL;
|
2003-08-02 11:52:29 +02:00
|
|
|
int select = 7, pri;
|
|
|
|
|
2002-06-16 12:57:31 +02:00
|
|
|
for (int i = 0; i < numDevices; i++) {
|
2002-09-06 14:10:17 +02:00
|
|
|
bool ndr;
|
2003-08-02 11:52:29 +02:00
|
|
|
if (device[i]->ProvidesChannel(Channel, Priority, &ndr)) { // this device is basicly able to do the job
|
|
|
|
if (device[i]->Receiving() && !ndr)
|
|
|
|
pri = 0; // receiving and allows additional receivers
|
2004-01-04 12:30:00 +01:00
|
|
|
else if (d && !device[i]->Receiving() && device[i]->ProvidesCa(Channel) < d->ProvidesCa(Channel))
|
2003-08-02 11:52:29 +02:00
|
|
|
pri = 1; // free and fewer Ca's
|
|
|
|
else if (!device[i]->Receiving() && !device[i]->IsPrimaryDevice())
|
|
|
|
pri = 2; // free and not the primary device
|
|
|
|
else if (!device[i]->Receiving())
|
|
|
|
pri = 3; // free
|
|
|
|
else if (d && device[i]->Priority() < d->Priority())
|
|
|
|
pri = 4; // receiving but priority is lower
|
2004-01-04 12:30:00 +01:00
|
|
|
else if (d && device[i]->Priority() == d->Priority() && device[i]->ProvidesCa(Channel) < d->ProvidesCa(Channel))
|
2003-08-02 11:52:29 +02:00
|
|
|
pri = 5; // receiving with same priority but fewer Ca's
|
|
|
|
else
|
|
|
|
pri = 6; // all others
|
|
|
|
if (pri < select) {
|
|
|
|
select = pri;
|
|
|
|
d = device[i];
|
|
|
|
if (NeedsDetachReceivers)
|
|
|
|
*NeedsDetachReceivers = ndr;
|
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
2003-08-02 11:52:29 +02:00
|
|
|
|
2002-06-16 12:57:31 +02:00
|
|
|
/*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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-08-15 13:05:50 +02:00
|
|
|
eVideoSystem cDevice::GetVideoSystem(void)
|
|
|
|
{
|
|
|
|
return vsPAL;
|
|
|
|
}
|
|
|
|
|
2002-09-04 17:26:02 +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); }
|
2002-06-16 12:57:31 +02:00
|
|
|
#define PRINTPIDS(s)
|
|
|
|
|
2002-09-29 13:40:45 +02:00
|
|
|
bool cDevice::HasPid(int Pid) const
|
2002-09-04 17:26:02 +02:00
|
|
|
{
|
|
|
|
for (int i = 0; i < MAXPIDHANDLES; i++) {
|
|
|
|
if (pidHandles[i].pid == Pid)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-06-16 12:57:31 +02:00
|
|
|
bool cDevice::AddPid(int Pid, ePidType PidType)
|
|
|
|
{
|
2003-05-02 09:24:31 +02:00
|
|
|
if (Pid || PidType == ptPcr) {
|
2002-06-16 12:57:31 +02:00
|
|
|
int n = -1;
|
|
|
|
int a = -1;
|
2003-05-02 09:24:31 +02:00
|
|
|
if (PidType != ptPcr) { // PPID always has to be explicit
|
|
|
|
for (int i = 0; i < MAXPIDHANDLES; i++) {
|
|
|
|
if (i != ptPcr) {
|
|
|
|
if (pidHandles[i].pid == Pid)
|
|
|
|
n = i;
|
|
|
|
else if (a < 0 && i >= ptOther && !pidHandles[i].used)
|
|
|
|
a = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
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-09-04 17:26:02 +02:00
|
|
|
PRINTPIDS("A");
|
2002-08-04 14:57:29 +02:00
|
|
|
return SetPid(&pidHandles[n], n, true);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
2002-09-04 17:26:02 +02:00
|
|
|
PRINTPIDS("a");
|
2002-06-16 12:57:31 +02:00
|
|
|
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;
|
2002-09-04 17:26:02 +02:00
|
|
|
PRINTPIDS("C");
|
2002-08-04 14:57:29 +02:00
|
|
|
return SetPid(&pidHandles[n], n, true);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-05-02 09:24:31 +02:00
|
|
|
void cDevice::DelPid(int Pid, ePidType PidType)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
2003-05-02 09:24:31 +02:00
|
|
|
if (Pid || PidType == ptPcr) {
|
|
|
|
int n = -1;
|
|
|
|
if (PidType == ptPcr)
|
|
|
|
n = PidType; // PPID always has to be explicit
|
|
|
|
else {
|
|
|
|
for (int i = 0; i < MAXPIDHANDLES; i++) {
|
|
|
|
if (pidHandles[i].pid == Pid) {
|
|
|
|
n = i;
|
|
|
|
break;
|
2002-08-04 14:57:29 +02:00
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
2003-05-02 09:24:31 +02:00
|
|
|
}
|
|
|
|
if (n >= 0 && pidHandles[n].used) {
|
|
|
|
PRINTPIDS("D");
|
|
|
|
if (--pidHandles[n].used < 2) {
|
|
|
|
SetPid(&pidHandles[n], n, false);
|
|
|
|
if (pidHandles[n].used == 0) {
|
|
|
|
pidHandles[n].handle = -1;
|
|
|
|
pidHandles[n].pid = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PRINTPIDS("E");
|
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-12-22 13:29:24 +01:00
|
|
|
void cDevice::StartSectionHandler(void)
|
|
|
|
{
|
|
|
|
if (!sectionHandler) {
|
|
|
|
sectionHandler = new cSectionHandler(this);
|
|
|
|
AttachFilter(eitFilter = new cEitFilter);
|
|
|
|
AttachFilter(patFilter = new cPatFilter);
|
2004-01-04 12:30:00 +01:00
|
|
|
AttachFilter(sdtFilter = new cSdtFilter(patFilter));
|
2003-12-22 13:29:24 +01:00
|
|
|
sectionHandler->SetStatus(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int cDevice::OpenFilter(u_short Pid, u_char Tid, u_char Mask)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::AttachFilter(cFilter *Filter)
|
|
|
|
{
|
|
|
|
sectionHandler->Attach(Filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::Detach(cFilter *Filter)
|
|
|
|
{
|
|
|
|
sectionHandler->Detach(Filter);
|
|
|
|
}
|
|
|
|
|
2002-10-06 10:25:42 +02:00
|
|
|
bool cDevice::ProvidesSource(int Source) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-01-04 12:30:00 +01:00
|
|
|
bool cDevice::ProvidesTransponder(const cChannel *Channel) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-09-29 13:40:45 +02:00
|
|
|
bool cDevice::ProvidesChannel(const cChannel *Channel, int Priority, bool *NeedsDetachReceivers) const
|
2002-09-04 17:26:02 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cDevice::SwitchChannel(const cChannel *Channel, bool LiveView)
|
|
|
|
{
|
|
|
|
if (LiveView)
|
2002-10-06 10:25:42 +02:00
|
|
|
isyslog("switching to channel %d", Channel->Number());
|
2002-09-04 17:26:02 +02:00
|
|
|
for (int i = 3; i--;) {
|
|
|
|
switch (SetChannel(Channel, LiveView)) {
|
|
|
|
case scrOk: return true;
|
2002-10-06 11:34:02 +02:00
|
|
|
case scrNotAvailable: if (Interface)
|
|
|
|
Interface->Error(tr("Channel not available!"));
|
|
|
|
return false;
|
2002-09-04 17:26:02 +02:00
|
|
|
case scrNoTransfer: if (Interface)
|
|
|
|
Interface->Error(tr("Can't start Transfer Mode!"));
|
|
|
|
return false;
|
|
|
|
case scrFailed: break; // loop will retry
|
|
|
|
}
|
|
|
|
esyslog("retrying");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-09-08 11:46:53 +02:00
|
|
|
bool cDevice::SwitchChannel(int Direction)
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
Direction = sgn(Direction);
|
|
|
|
if (Direction) {
|
|
|
|
int n = CurrentChannel() + Direction;
|
|
|
|
int first = n;
|
2002-10-06 11:34:02 +02:00
|
|
|
cChannel *channel;
|
2002-10-19 15:33:37 +02:00
|
|
|
while ((channel = Channels.GetByNumber(n, Direction)) != NULL) {
|
2002-10-06 11:34:02 +02:00
|
|
|
// try only channels which are currently available
|
2002-10-26 11:51:37 +02:00
|
|
|
if (PrimaryDevice()->ProvidesChannel(channel, Setup.PrimaryLimit) || PrimaryDevice()->CanReplay() && GetDevice(channel, 0))
|
2002-10-06 11:34:02 +02:00
|
|
|
break;
|
2002-10-20 16:07:56 +02:00
|
|
|
n = channel->Number() + Direction;
|
2002-10-06 11:34:02 +02:00
|
|
|
}
|
|
|
|
if (channel) {
|
|
|
|
int d = n - first;
|
|
|
|
if (abs(d) == 1)
|
|
|
|
dsyslog("skipped channel %d", first);
|
|
|
|
else if (d)
|
|
|
|
dsyslog("skipped channels %d..%d", first, n - sgn(d));
|
|
|
|
if (PrimaryDevice()->SwitchChannel(channel, true))
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
else if (n != first && Interface)
|
|
|
|
Interface->Error(tr("Channel not available!"));
|
2002-09-08 11:46:53 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-09-04 17:26:02 +02:00
|
|
|
eSetChannelResult cDevice::SetChannel(const cChannel *Channel, bool LiveView)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
2002-09-04 17:26:02 +02:00
|
|
|
if (LiveView)
|
|
|
|
StopReplay();
|
2002-08-04 14:57:29 +02:00
|
|
|
|
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-09-04 17:26:02 +02:00
|
|
|
bool NeedsTransferMode = (LiveView && IsPrimaryDevice() && !ProvidesChannel(Channel, Setup.PrimaryLimit));
|
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-09-06 14:10:17 +02:00
|
|
|
cDevice *CaDevice = GetDevice(Channel, 0);
|
2002-10-26 11:51:37 +02:00
|
|
|
if (CaDevice && CanReplay()) {
|
2002-09-15 11:52:43 +02:00
|
|
|
cStatus::MsgChannelSwitch(this, 0); // only report status if we are actually going to switch the channel
|
2002-09-06 14:10:17 +02:00
|
|
|
if (CaDevice->SetChannel(Channel, false) == scrOk) // calling SetChannel() directly, not SwitchChannel()!
|
2002-10-12 14:29:46 +02:00
|
|
|
cControl::Launch(new cTransferControl(CaDevice, Channel->Vpid(), Channel->Apid1(), Channel->Apid2(), Channel->Dpid1(), Channel->Dpid2()));//XXX+
|
2002-09-04 17:26:02 +02:00
|
|
|
else
|
|
|
|
Result = scrNoTransfer;
|
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
else
|
2002-09-04 17:26:02 +02:00
|
|
|
Result = scrNotAvailable;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
2002-09-15 11:52:43 +02:00
|
|
|
else {
|
2004-01-04 12:30:00 +01:00
|
|
|
Channels.Lock(false);
|
2002-09-15 11:52:43 +02:00
|
|
|
cStatus::MsgChannelSwitch(this, 0); // only report status if we are actually going to switch the channel
|
2003-12-22 13:29:24 +01:00
|
|
|
// Stop section handling:
|
|
|
|
if (sectionHandler) {
|
|
|
|
sectionHandler->SetStatus(false);
|
|
|
|
sectionHandler->SetSource(0, 0);
|
|
|
|
}
|
|
|
|
if (SetChannelDevice(Channel, LiveView)) {
|
|
|
|
// Start section handling:
|
|
|
|
if (sectionHandler) {
|
2004-01-04 12:30:00 +01:00
|
|
|
sectionHandler->SetSource(Channel->Source(), Channel->Transponder());
|
2003-12-22 13:29:24 +01:00
|
|
|
sectionHandler->SetStatus(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2002-09-15 11:52:43 +02:00
|
|
|
Result = scrFailed;
|
2004-01-04 12:30:00 +01:00
|
|
|
Channels.Unlock();
|
2002-09-08 11:46:53 +02:00
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2002-09-15 11:52:43 +02:00
|
|
|
if (Result == scrOk) {
|
2003-12-22 13:29:24 +01:00
|
|
|
if (LiveView && IsPrimaryDevice())
|
2002-10-06 10:25:42 +02:00
|
|
|
currentChannel = Channel->Number();
|
|
|
|
cStatus::MsgChannelSwitch(this, Channel->Number()); // only report status if channel switch successfull
|
2002-09-15 11:52:43 +02:00
|
|
|
}
|
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-09-04 17:26:02 +02:00
|
|
|
bool cDevice::SetChannelDevice(const cChannel *Channel, bool LiveView)
|
2002-08-04 14:57:29 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2004-01-04 12:30:00 +01:00
|
|
|
bool cDevice::HasLock(void)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-05-03 13:42:37 +02:00
|
|
|
bool cDevice::HasProgramme(void)
|
|
|
|
{
|
|
|
|
return Replaying() || pidHandles[ptAudio].pid || pidHandles[ptVideo].pid;
|
|
|
|
}
|
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
void cDevice::SetVolumeDevice(int Volume)
|
|
|
|
{
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
2002-10-12 14:29:46 +02:00
|
|
|
int cDevice::NumAudioTracksDevice(void) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char **cDevice::GetAudioTracksDevice(int *CurrentTrack) const
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::SetAudioTrackDevice(int Index)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-06-16 12:57:31 +02:00
|
|
|
bool cDevice::ToggleMute(void)
|
|
|
|
{
|
|
|
|
int OldVolume = volume;
|
|
|
|
mute = !mute;
|
2003-03-30 12:42:23 +02:00
|
|
|
//XXX why is it necessary to use different sequences???
|
|
|
|
if (mute) {
|
|
|
|
SetVolume(0, mute);
|
|
|
|
Audios.MuteAudio(mute); // Mute external audio after analog audio
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Audios.MuteAudio(mute); // Enable external audio before analog audio
|
|
|
|
SetVolume(0, mute);
|
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
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);
|
2002-11-03 11:53:58 +01:00
|
|
|
if (volume > 0) {
|
2002-08-04 14:57:29 +02:00
|
|
|
mute = false;
|
2002-11-03 11:53:58 +01:00
|
|
|
Audios.MuteAudio(mute);
|
|
|
|
}
|
2002-08-04 14:57:29 +02:00
|
|
|
}
|
|
|
|
|
2002-10-12 14:29:46 +02:00
|
|
|
int cDevice::NumAudioTracks(void) const
|
|
|
|
{
|
|
|
|
return player ? player->NumAudioTracks() : NumAudioTracksDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char **cDevice::GetAudioTracks(int *CurrentTrack) const
|
|
|
|
{
|
|
|
|
return player ? player->GetAudioTracks(CurrentTrack) : GetAudioTracksDevice(CurrentTrack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::SetAudioTrack(int Index)
|
|
|
|
{
|
|
|
|
if (player)
|
|
|
|
player->SetAudioTrack(Index);
|
|
|
|
else
|
|
|
|
SetAudioTrackDevice(Index);
|
|
|
|
}
|
|
|
|
|
2002-10-26 11:51:37 +02:00
|
|
|
bool cDevice::CanReplay(void) const
|
|
|
|
{
|
|
|
|
return HasDecoder();
|
|
|
|
}
|
|
|
|
|
2002-08-15 11:16:34 +02:00
|
|
|
bool cDevice::SetPlayMode(ePlayMode PlayMode)
|
2002-08-04 14:57:29 +02:00
|
|
|
{
|
2002-08-15 11:16:34 +02:00
|
|
|
return false;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
2003-11-07 14:16:25 +01:00
|
|
|
int64_t cDevice::GetSTC(void)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-06-16 12:57:31 +02:00
|
|
|
void cDevice::TrickSpeed(int Speed)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::Clear(void)
|
|
|
|
{
|
2002-11-03 11:53:58 +01:00
|
|
|
Audios.ClearAudio();
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::Play(void)
|
|
|
|
{
|
2003-03-30 12:42:23 +02:00
|
|
|
Audios.MuteAudio(mute);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::Freeze(void)
|
|
|
|
{
|
2003-03-30 12:42:23 +02:00
|
|
|
Audios.MuteAudio(true);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::Mute(void)
|
|
|
|
{
|
2002-11-03 11:53:58 +01:00
|
|
|
Audios.MuteAudio(true);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::StillPicture(const uchar *Data, int Length)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-09-29 13:40:45 +02:00
|
|
|
bool cDevice::Replaying(void) const
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
|
|
|
return player != NULL;
|
|
|
|
}
|
|
|
|
|
2002-06-22 13:45:53 +02:00
|
|
|
bool cDevice::AttachPlayer(cPlayer *Player)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
2002-10-26 11:51:37 +02:00
|
|
|
if (CanReplay()) {
|
2002-06-16 12:57:31 +02:00
|
|
|
if (player)
|
|
|
|
Detach(player);
|
|
|
|
player = Player;
|
|
|
|
player->device = this;
|
2002-08-15 11:16:34 +02:00
|
|
|
SetPlayMode(player->playMode);
|
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->device = NULL;
|
|
|
|
player = NULL;
|
2002-08-15 11:16:34 +02:00
|
|
|
SetPlayMode(pmNone);
|
2003-03-30 12:42:23 +02:00
|
|
|
Audios.ClearAudio();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-16 09:22:29 +02:00
|
|
|
bool cDevice::Poll(cPoller &Poller, int TimeoutMs)
|
2002-08-15 10:13:03 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-06-16 12:57:31 +02:00
|
|
|
int cDevice::PlayVideo(const uchar *Data, int Length)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-11-03 11:53:58 +01:00
|
|
|
void cDevice::PlayAudio(const uchar *Data, int Length)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
2002-11-03 11:53:58 +01:00
|
|
|
Audios.PlayAudio(Data, Length);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
2002-10-26 09:43:11 +02:00
|
|
|
int cDevice::Ca(void) const
|
|
|
|
{
|
|
|
|
int ca = 0;
|
|
|
|
for (int i = 0; i < MAXRECEIVERS; i++) {
|
|
|
|
if (receiver[i] && (ca = receiver[i]->ca) != 0)
|
|
|
|
break; // all receivers have the same ca
|
|
|
|
}
|
|
|
|
return ca;
|
|
|
|
}
|
|
|
|
|
2002-09-29 13:40:45 +02:00
|
|
|
int cDevice::Priority(void) const
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
2002-09-04 17:26:02 +02:00
|
|
|
int priority = IsPrimaryDevice() ? Setup.PrimaryLimit - 1 : DEFAULTPRIORITY;
|
2002-06-16 12:57:31 +02:00
|
|
|
for (int i = 0; i < MAXRECEIVERS; i++) {
|
|
|
|
if (receiver[i])
|
|
|
|
priority = max(receiver[i]->priority, priority);
|
|
|
|
}
|
|
|
|
return priority;
|
|
|
|
}
|
|
|
|
|
2002-09-29 13:40:45 +02:00
|
|
|
int cDevice::CanShift(int Ca, int Priority, int UsedCards) const
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
|
|
|
return -1;//XXX+ too complex with multiple recordings per device
|
2004-01-04 12:30:00 +01:00
|
|
|
/*XXX
|
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;
|
2004-01-04 12:30:00 +01:00
|
|
|
XXX*/
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
2004-01-04 12:30:00 +01:00
|
|
|
int cDevice::ProvidesCa(const cChannel *Channel) const
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
2004-01-04 12:30:00 +01:00
|
|
|
int Ca = Channel->Ca();
|
2002-06-16 12:57:31 +02:00
|
|
|
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
|
2004-01-04 12:30:00 +01:00
|
|
|
return !Ca; // by default every card can provide FTA
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
2002-11-01 11:11:20 +01:00
|
|
|
bool cDevice::Receiving(bool CheckAny) const
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
|
|
|
for (int i = 0; i < MAXRECEIVERS; i++) {
|
2002-11-01 11:11:20 +01:00
|
|
|
if (receiver[i] && (CheckAny || 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)
|
|
|
|
{
|
2002-08-04 14:57:29 +02:00
|
|
|
if (OpenDvr()) {
|
2002-06-16 12:57:31 +02:00
|
|
|
active = true;
|
|
|
|
for (; active;) {
|
|
|
|
// Read data from the DVR device:
|
2002-09-08 09:03:10 +02:00
|
|
|
uchar *b = NULL;
|
|
|
|
if (GetTSPacket(b)) {
|
|
|
|
if (b) {
|
2002-08-04 14:57:29 +02:00
|
|
|
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-09-08 09:03:10 +02:00
|
|
|
else
|
2002-08-04 14:57:29 +02:00
|
|
|
break;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
2002-08-04 14:57:29 +02:00
|
|
|
CloseDvr();
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-04 14:57:29 +02:00
|
|
|
bool cDevice::OpenDvr(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDevice::CloseDvr(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-09-08 09:03:10 +02:00
|
|
|
bool cDevice::GetTSPacket(uchar *&Data)
|
2002-08-04 14:57:29 +02:00
|
|
|
{
|
2002-09-08 09:03:10 +02:00
|
|
|
return false;
|
2002-08-04 14:57:29 +02:00
|
|
|
}
|
|
|
|
|
2002-06-22 13:45:53 +02:00
|
|
|
bool cDevice::AttachReceiver(cReceiver *Receiver)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
|
|
|
if (!Receiver)
|
|
|
|
return false;
|
|
|
|
if (Receiver->device == this)
|
|
|
|
return true;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2002-09-08 09:03:10 +02:00
|
|
|
|
|
|
|
// --- cTSBuffer -------------------------------------------------------------
|
|
|
|
|
|
|
|
cTSBuffer::cTSBuffer(int File, int Size, int CardIndex)
|
|
|
|
{
|
|
|
|
f = File;
|
|
|
|
size = Size / TS_SIZE * TS_SIZE;
|
|
|
|
cardIndex = CardIndex;
|
|
|
|
tsRead = tsWrite = 0;
|
|
|
|
buf = (f >= 0 && size >= TS_SIZE) ? MALLOC(uchar, size + TS_SIZE) : NULL;
|
|
|
|
// the '+ TS_SIZE' allocates some extra space for handling packets that got split by a buffer roll-over
|
|
|
|
firstRead = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
cTSBuffer::~cTSBuffer()
|
|
|
|
{
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cTSBuffer::Read(void)
|
|
|
|
{
|
|
|
|
if (buf) {
|
|
|
|
cPoller Poller(f, false);
|
|
|
|
bool repeat;
|
|
|
|
int total = 0;
|
|
|
|
do {
|
|
|
|
repeat = false;
|
|
|
|
if (firstRead || Used() > TS_SIZE || Poller.Poll(100)) { // only wait if there's not enough data in the buffer
|
|
|
|
firstRead = false;
|
|
|
|
if (tsRead == tsWrite)
|
|
|
|
tsRead = tsWrite = 0; // keep the maximum buffer space available
|
|
|
|
if (tsWrite >= size && tsRead > 0)
|
|
|
|
tsWrite = 0;
|
|
|
|
int free = tsRead <= tsWrite ? size - tsWrite : tsRead - tsWrite - 1;
|
|
|
|
if (free > 0) {
|
|
|
|
int r = read(f, buf + tsWrite, free);
|
|
|
|
if (r > 0) {
|
|
|
|
total += r;
|
|
|
|
tsWrite += r;
|
|
|
|
if (tsWrite >= size && tsRead > 0) {
|
|
|
|
tsWrite = 0;
|
|
|
|
repeat = true; // read again after a boundary roll-over
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (repeat);
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uchar *cTSBuffer::Get(void)
|
|
|
|
{
|
|
|
|
if (Used() >= TS_SIZE) {
|
|
|
|
uchar *p = buf + tsRead;
|
|
|
|
if (*p != TS_SYNC_BYTE) {
|
|
|
|
esyslog("ERROR: not sync'ed to TS packet on device %d", cardIndex);
|
|
|
|
int tsMax = tsRead < tsWrite ? tsWrite : size;
|
|
|
|
for (int i = tsRead; i < tsMax; i++) {
|
|
|
|
if (buf[i] == TS_SYNC_BYTE) {
|
|
|
|
esyslog("ERROR: skipped %d bytes to sync on TS packet on device %d", i - tsRead, cardIndex);
|
|
|
|
tsRead = i;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((tsRead = tsMax) >= size)
|
|
|
|
tsRead = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (tsRead + TS_SIZE > size) {
|
|
|
|
// the packet rolled over the buffer boundary, so let's fetch the rest from the beginning (which MUST be there, since Used() >= TS_SIZE)
|
|
|
|
int rest = TS_SIZE - (size - tsRead);
|
|
|
|
memcpy(buf + size, buf, rest);
|
|
|
|
tsRead = rest;
|
|
|
|
}
|
|
|
|
else if ((tsRead += TS_SIZE) >= size)
|
|
|
|
tsRead = 0;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|