1
0
mirror of https://github.com/rofafor/vdr-plugin-satip.git synced 2023-10-10 13:37:42 +02:00

Refactored the frontend handling.

This commit is contained in:
Rolf Ahrenberg 2015-01-15 23:33:51 +02:00
parent 26be862d89
commit a87dfc43f7
7 changed files with 326 additions and 140 deletions

View File

@ -328,20 +328,19 @@ bool cSatipDevice::SetChannelDevice(const cChannel *channelP, bool liveViewP)
return false;
}
cString address;
cSatipServer *server = cSatipDiscover::GetInstance()->GetServer(channelP->Source(), channelP->Transponder(), dtp.System());
cSatipServer *server = cSatipDiscover::GetInstance()->AssignServer(channelP->Source(), channelP->Transponder(), dtp.System());
if (!server) {
debug9("%s No suitable server found [device %u]", __PRETTY_FUNCTION__, deviceIndexM);
return false;
}
cSatipDiscover::GetInstance()->SetTransponder(server, channelP->Transponder());
if (pTunerM && pTunerM->SetSource(server, *params, deviceIndexM)) {
if (pTunerM && pTunerM->SetSource(server, channelP->Transponder(), *params, deviceIndexM)) {
channelM = *channelP;
deviceNameM = cString::sprintf("%s %d %s", *DeviceType(), deviceIndexM, *cSatipDiscover::GetInstance()->GetServerString(server));
return true;
}
}
else if (pTunerM) {
pTunerM->SetSource(NULL, NULL, deviceIndexM);
pTunerM->SetSource(NULL, 0, NULL, deviceIndexM);
return true;
}
return false;

View File

@ -269,11 +269,18 @@ int cSatipDiscover::GetServerCount(void)
return serversM.Count();
}
cSatipServer *cSatipDiscover::GetServer(int sourceP, int transponderP, int systemP)
cSatipServer *cSatipDiscover::AssignServer(int sourceP, int transponderP, int systemP)
{
debug16("%s (%d, %d, %d)", __PRETTY_FUNCTION__, sourceP, transponderP, systemP);
cMutexLock MutexLock(&mutexM);
return serversM.Find(sourceP, transponderP, systemP);
return serversM.Assign(sourceP, transponderP, systemP);
}
cSatipServer *cSatipDiscover::GetServer(int sourceP)
{
debug16("%s (%d)", __PRETTY_FUNCTION__, sourceP);
cMutexLock MutexLock(&mutexM);
return serversM.Find(sourceP);
}
cSatipServer *cSatipDiscover::GetServer(cSatipServer *serverP)
@ -304,18 +311,25 @@ cString cSatipDiscover::GetServerList(void)
return serversM.List();
}
void cSatipDiscover::SetTransponder(cSatipServer *serverP, int transponderP)
void cSatipDiscover::UseServer(cSatipServer *serverP, int transponderP, bool onOffP)
{
debug16("%s (, %d)", __PRETTY_FUNCTION__, transponderP);
debug16("%s (, %d, %d)", __PRETTY_FUNCTION__, transponderP, onOffP);
cMutexLock MutexLock(&mutexM);
serversM.SetTransponder(serverP, transponderP);
serversM.Use(serverP, transponderP, onOffP);
}
void cSatipDiscover::UseServer(cSatipServer *serverP, bool onOffP)
bool cSatipDiscover::IsServerQuirk(cSatipServer *serverP, int quirkP)
{
debug16("%s (, %d)", __PRETTY_FUNCTION__, onOffP);
debug16("%s (, %d)", __PRETTY_FUNCTION__, quirkP);
cMutexLock MutexLock(&mutexM);
serversM.Use(serverP, onOffP);
return serversM.IsQuirk(serverP, quirkP);
}
cString cSatipDiscover::GetServerAddress(cSatipServer *serverP)
{
debug16("%s", __PRETTY_FUNCTION__);
cMutexLock MutexLock(&mutexM);
return serversM.GetAddress(serverP);
}
int cSatipDiscover::NumProvidedSystems(void)

View File

@ -74,12 +74,14 @@ public:
virtual ~cSatipDiscover();
void TriggerScan(void) { probeIntervalM.Set(0); }
int GetServerCount(void);
cSatipServer *GetServer(int sourceP, int transponderP = 0, int systemP = -1);
cSatipServer *AssignServer(int sourceP, int transponderP, int systemP);
cSatipServer *GetServer(int sourceP);
cSatipServer *GetServer(cSatipServer *serverP);
cSatipServers *GetServers(void);
cString GetServerString(cSatipServer *serverP);
void SetTransponder(cSatipServer *serverP, int transponderP);
void UseServer(cSatipServer *serverP, bool onOffP);
void UseServer(cSatipServer *serverP, int transponderP, bool onOffP);
bool IsServerQuirk(cSatipServer *serverP, int quirkP);
cString GetServerAddress(cSatipServer *serverP);
cString GetServerList(void);
int NumProvidedSystems(void);

276
server.c
View File

@ -12,20 +12,70 @@
#include "log.h"
#include "server.h"
// --- cSatipFrontend ---------------------------------------------------------
cSatipFrontend::cSatipFrontend(const int indexP, const char *descriptionP)
: indexM(indexP),
transponderM(0),
descriptionM(descriptionP),
usedM(false)
{
}
cSatipFrontend::~cSatipFrontend()
{
}
// --- cSatipFrontends --------------------------------------------------------
bool cSatipFrontends::Matches(int transponderP)
{
for (cSatipFrontend *f = First(); f; f = Next(f)) {
if (f->IsUsed() && (f->Transponder() == transponderP))
return true;
}
return false;
}
bool cSatipFrontends::Assign(int transponderP)
{
cSatipFrontend *tmp = First();
// Prefer any unused one
for (cSatipFrontend *f = First(); f; f = Next(f)) {
if (!f->IsUsed()) {
tmp = f;
break;
}
}
if (tmp) {
tmp->SetTransponder(transponderP);
return true;
}
return false;
}
bool cSatipFrontends::Use(int transponderP, bool onOffP)
{
for (cSatipFrontend *f = First(); f; f = Next(f)) {
if (f->Transponder() == transponderP) {
f->Use(onOffP);
debug9("%s (%d, %d) %s/#%d", __PRETTY_FUNCTION__, transponderP, onOffP, *f->Description(), f->Index());
return true;
}
}
return false;
}
// --- cSatipServer -----------------------------------------------------------
cSatipServer::cSatipServer(const char *addressP, const char *modelP, const char *descriptionP)
: addressM((addressP && *addressP) ? addressP : "0.0.0.0"),
modelM((modelP && *modelP) ? modelP : "DVBS-1"),
descriptionM(!isempty(descriptionP) ? descriptionP : "MyBrokenHardware"),
modelTypeM(eSatipModelTypeNone),
quirkM(eSatipQuirkNone),
useCountM(0),
transponderM(0),
createdM(time(NULL)),
lastSeenM(0)
{
memset(modelCountM, 0, sizeof(modelCountM));
if (!SatipConfig.GetDisableServerQuirks()) {
debug3("%s quirks=%s", __PRETTY_FUNCTION__, *descriptionM);
// These devices contain a session id bug:
@ -51,34 +101,31 @@ cSatipServer::cSatipServer(const char *addressP, const char *modelP, const char
char *s, *p = strdup(*modelM);
char *r = strtok_r(p, ",", &s);
while (r) {
if (strstr(r, "DVBS2-")) {
modelTypeM |= eSatipModelTypeDVBS2;
if (char *c = strstr(r, "-"))
modelCountM[eSatipModuleDVBS2] = atoi(++c);
char *c;
if (c = strstr(r, "DVBS2-")) {
int count = atoi(c + 6);
for (int i = 1; i <= count; ++i)
frontendsM[eSatipFrontendDVBS2].Add(new cSatipFrontend(i, "DVB-S2"));
}
else if (strstr(r, "DVBT2-")) {
modelTypeM |= eSatipModelTypeDVBT2;
if (char *c = strstr(r, "-"))
modelCountM[eSatipModuleDVBT2] = atoi(++c);
modelTypeM |= eSatipModelTypeDVBT;
modelCountM[eSatipModuleDVBT] = modelCountM[eSatipModuleDVBT2];
else if (c = strstr(r, "DVBT-")) {
int count = atoi(c + 5);
for (int i = 1; i <= count; ++i)
frontendsM[eSatipFrontendDVBT].Add(new cSatipFrontend(i, "DVB-T"));
}
else if (strstr(r, "DVBT-")) {
modelTypeM |= eSatipModelTypeDVBT;
if (char *c = strstr(r, "-"))
modelCountM[eSatipModuleDVBT] = atoi(++c);
else if (c = strstr(r, "DVBT2-")) {
int count = atoi(c + 6);
for (int i = 1; i <= count; ++i)
frontendsM[eSatipFrontendDVBT2].Add(new cSatipFrontend(i, "DVB-T2"));
}
else if (strstr(r, "DVBC2-")) {
modelTypeM |= eSatipModelTypeDVBC2;
if (char *c = strstr(r, "-"))
modelCountM[eSatipModuleDVBC2] = atoi(++c);
modelTypeM |= eSatipModelTypeDVBC;
modelCountM[eSatipModuleDVBC] = modelCountM[eSatipModuleDVBC2];
else if (c = strstr(r, "DVBC-")) {
int count = atoi(c + 5);
for (int i = 1; i <= count; ++i)
frontendsM[eSatipFrontendDVBC].Add(new cSatipFrontend(i, "DVB-C"));
}
else if (strstr(r, "DVBC-")) {
modelTypeM |= eSatipModelTypeDVBC;
if (char *c = strstr(r, "-"))
modelCountM[eSatipModuleDVBC] = atoi(++c);
else if (c = strstr(r, "DVBC2-")) {
int count = atoi(c + 6);
for (int i = 1; i <= count; ++i)
frontendsM[eSatipFrontendDVBC2].Add(new cSatipFrontend(i, "DVB-C2"));
}
r = strtok_r(NULL, ",", &s);
}
@ -101,12 +148,88 @@ int cSatipServer::Compare(const cListObject &listObjectP) const
return result;
}
void cSatipServer::Use(bool onOffP)
bool cSatipServer::Assign(int sourceP, int systemP, int transponderP)
{
if (onOffP)
++useCountM;
else
--useCountM;
bool result = false;
if (cSource::IsType(sourceP, 'S'))
result = frontendsM[eSatipFrontendDVBS2].Assign(transponderP);
else if (cSource::IsType(sourceP, 'T')) {
if (systemP)
result = frontendsM[eSatipFrontendDVBT2].Assign(transponderP);
else
result = frontendsM[eSatipFrontendDVBT].Assign(transponderP) || frontendsM[eSatipFrontendDVBT2].Assign(transponderP);
}
else if (cSource::IsType(sourceP, 'C')) {
if (systemP)
result = frontendsM[eSatipFrontendDVBC2].Assign(transponderP);
else
result = frontendsM[eSatipFrontendDVBC].Assign(transponderP) || frontendsM[eSatipFrontendDVBC2].Assign(transponderP);
}
return result;
}
bool cSatipServer::Matches(int sourceP)
{
if (cSource::IsType(sourceP, 'S'))
return GetModulesDVBS2();
else if (cSource::IsType(sourceP, 'T'))
return GetModulesDVBT() || GetModulesDVBT2();
else if (cSource::IsType(sourceP, 'C'))
return GetModulesDVBC() || GetModulesDVBC2();
return false;
}
bool cSatipServer::Matches(int sourceP, int systemP, int transponderP)
{
bool result = false;
if (cSource::IsType(sourceP, 'S'))
result = frontendsM[eSatipFrontendDVBS2].Matches(transponderP);
else if (cSource::IsType(sourceP, 'T')) {
if (systemP)
result = frontendsM[eSatipFrontendDVBT2].Matches(transponderP);
else
result = frontendsM[eSatipFrontendDVBT].Matches(transponderP) || frontendsM[eSatipFrontendDVBT2].Matches(transponderP);
}
else if (cSource::IsType(sourceP, 'C')) {
if (systemP)
result = frontendsM[eSatipFrontendDVBC2].Matches(transponderP);
else
result = frontendsM[eSatipFrontendDVBC].Matches(transponderP) || frontendsM[eSatipFrontendDVBC2].Matches(transponderP);
}
return result;
}
void cSatipServer::Use(int transponderP, bool onOffP)
{
for (int i = 0; i < eSatipFrontendCount; ++i) {
if (frontendsM[i].Use(transponderP, onOffP))
return;
}
}
int cSatipServer::GetModulesDVBS2(void)
{
return frontendsM[eSatipFrontendDVBS2].Count();
}
int cSatipServer::GetModulesDVBT(void)
{
return frontendsM[eSatipFrontendDVBT].Count();
}
int cSatipServer::GetModulesDVBT2(void)
{
return frontendsM[eSatipFrontendDVBT2].Count();
}
int cSatipServer::GetModulesDVBC(void)
{
return frontendsM[eSatipFrontendDVBC].Count();
}
int cSatipServer::GetModulesDVBC2(void)
{
return frontendsM[eSatipFrontendDVBC2].Count();
}
// --- cSatipServers ----------------------------------------------------------
@ -114,49 +237,32 @@ void cSatipServer::Use(bool onOffP)
cSatipServer *cSatipServers::Find(cSatipServer *serverP)
{
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP)
if (s->Compare(*serverP) == 0)
return s;
}
return NULL;
}
cSatipServer *cSatipServers::Find(int sourceP, int transponderP, int systemP)
cSatipServer *cSatipServers::Find(int sourceP)
{
cSatipServer *result = NULL;
int model = 0;
if (cSource::IsType(sourceP, 'S'))
model |= cSatipServer::eSatipModelTypeDVBS2;
else if (cSource::IsType(sourceP, 'T')) {
if (systemP < 0)
model |= cSatipServer::eSatipModelTypeDVBT2 | cSatipServer::eSatipModelTypeDVBT;
else
model |= systemP ? cSatipServer::eSatipModelTypeDVBT2 : cSatipServer::eSatipModelTypeDVBT;
}
else if (cSource::IsType(sourceP, 'C'))
model |= cSatipServer::eSatipModelTypeDVBC;
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s->Match(model) && s->Used() && (s->Transponder() == transponderP))
if (s->Matches(sourceP))
return s;
}
return NULL;
}
cSatipServer *cSatipServers::Assign(int sourceP, int transponderP, int systemP)
{
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s->Matches(sourceP, systemP, transponderP))
return s;
}
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s->Match(model)) {
result = s;
if (!s->Used()) {
break;
}
}
}
return result;
}
void cSatipServers::SetTransponder(cSatipServer *serverP, int transponderP)
{
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP) {
s->SetTransponder(transponderP);
break;
}
if (s->Assign(sourceP, systemP, transponderP))
return s;
}
return NULL;
}
cSatipServer *cSatipServers::Update(cSatipServer *serverP)
@ -170,16 +276,28 @@ cSatipServer *cSatipServers::Update(cSatipServer *serverP)
return NULL;
}
void cSatipServers::Use(cSatipServer *serverP, bool onOffP)
void cSatipServers::Use(cSatipServer *serverP, int transponderP, bool onOffP)
{
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP) {
s->Use(onOffP);
s->Use(transponderP, onOffP);
break;
}
}
}
bool cSatipServers::IsQuirk(cSatipServer *serverP, int quirkP)
{
bool result = false;
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP) {
result = s->Quirk(quirkP);
break;
}
}
return result;
}
void cSatipServers::Cleanup(uint64_t intervalMsP)
{
for (cSatipServer *s = First(); s; s = Next(s)) {
@ -190,6 +308,18 @@ void cSatipServers::Cleanup(uint64_t intervalMsP)
}
}
cString cSatipServers::GetAddress(cSatipServer *serverP)
{
cString address = "";
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP) {
address = s->Address();
break;
}
}
return address;
}
cString cSatipServers::GetString(cSatipServer *serverP)
{
cString list = "";
@ -215,13 +345,15 @@ int cSatipServers::NumProvidedSystems(void)
int count = 0;
for (cSatipServer *s = First(); s; s = Next(s)) {
// DVB-S2: qpsk, 8psk, 16apsk, 32apsk
count += s->Satellite() * 4;
// DVB-T2: qpsk, qam16, qam64, qam256
count += s->GetModulesDVBS2() * 4;
// DVB-T: qpsk, qam16, qam64
count += s->Terrestrial2() ? s->Terrestrial2() * 4 : s->Terrestrial() * 3;
// DVB-C2: qam16, qam32, qam64, qam128, qam256
count += s->GetModulesDVBT() * 3;
// DVB-T2: qpsk, qam16, qam64, qam256
count += s->GetModulesDVBT2() * 4;
// DVB-C: qam64, qam128, qam256
count += s->Cable2() ? s->Cable2() * 5 : s->Cable() * 3;
count += s->GetModulesDVBC() * 3;
// DVB-C2: qam16, qam32, qam64, qam128, qam256
count += s->GetModulesDVBC2() * 5;
}
return count;
}

View File

@ -8,26 +8,54 @@
#ifndef __SATIP_SERVER_H
#define __SATIP_SERVER_H
class cSatipServer;
// --- cSatipFrontend ---------------------------------------------------------
class cSatipFrontend : public cListObject {
private:
int indexM;
int transponderM;
cString descriptionM;
bool usedM;
public:
cSatipFrontend(const int indexP, const char *descriptionP);
virtual ~cSatipFrontend();
void Use(bool onOffP) { usedM = onOffP; }
cString Description(void) { return descriptionM; }
bool IsUsed(void) { return usedM; }
int Index(void) { return indexM; }
int Transponder(void) { return transponderM; }
void SetTransponder(int transponderP) { transponderM = transponderP; }
};
// --- cSatipFrontends --------------------------------------------------------
class cSatipFrontends : public cList<cSatipFrontend> {
public:
bool Matches(int transponderP);
bool Assign(int transponderP);
bool Use(int transponderP, bool onOffP);
};
// --- cSatipServer -----------------------------------------------------------
class cSatipServer : public cListObject {
private:
enum eSatipModule {
eSatipModuleDVBS2 = 0,
eSatipModuleDVBT,
eSatipModuleDVBT2,
eSatipModuleDVBC,
eSatipModuleDVBC2,
eSatipModuleCount
enum eSatipFrontend {
eSatipFrontendDVBS2 = 0,
eSatipFrontendDVBT,
eSatipFrontendDVBT2,
eSatipFrontendDVBC,
eSatipFrontendDVBC2,
eSatipFrontendCount
};
cString addressM;
cString modelM;
cString descriptionM;
int modelCountM[eSatipModuleCount];
int modelTypeM;
cSatipFrontends frontendsM[eSatipFrontendCount];
int quirkM;
int useCountM;
int transponderM;
time_t createdM;
cTimeMs lastSeenM;
@ -40,33 +68,22 @@ public:
eSatipQuirkUseXCI = 0x08,
eSatipQuirkMask = 0x0F
};
enum eSatipModelType {
eSatipModelTypeNone = 0x00,
eSatipModelTypeDVBS2 = 0x01,
eSatipModelTypeDVBT = 0x02,
eSatipModelTypeDVBT2 = 0x04,
eSatipModelTypeDVBC = 0x08,
eSatipModelTypeDVBC2 = 0x10,
eSatipModelTypeMask = 0xFF
};
cSatipServer(const char *addressP, const char *modelP, const char *descriptionP);
virtual ~cSatipServer();
virtual int Compare(const cListObject &listObjectP) const;
void Use(bool onOffP);
void SetTransponder(const int transponderP) { transponderM = transponderP; }
int Transponder(void) { return transponderM; }
bool Used(void) { return !!useCountM; }
bool Assign(int sourceP, int systemP, int transponderP);
bool Matches(int sourceP);
bool Matches(int sourceP, int systemP, int transponderP);
void Use(int transponderP, bool onOffP);
int GetModulesDVBS2(void);
int GetModulesDVBT(void);
int GetModulesDVBT2(void);
int GetModulesDVBC(void);
int GetModulesDVBC2(void);
const char *Address() { return *addressM; }
const char *Model(void) { return *modelM; }
const char *Description() { return *descriptionM; }
bool Quirk(int quirkP) { return ((quirkP & eSatipQuirkMask) & quirkM); }
int ModelType(void) { return modelTypeM; }
bool Match(int modelP) { return ((modelP & eSatipModelTypeMask) & modelTypeM); }
int Cable() { return Match(eSatipModelTypeDVBC) ? modelCountM[eSatipModuleDVBC] : 0; }
int Cable2() { return Match(eSatipModelTypeDVBC2) ? modelCountM[eSatipModuleDVBC2] : 0; }
int Satellite() { return Match(eSatipModelTypeDVBS2) ? modelCountM[eSatipModuleDVBS2] : 0; }
int Terrestrial() { return Match(eSatipModelTypeDVBT) ? modelCountM[eSatipModuleDVBT] : 0; }
int Terrestrial2() { return Match(eSatipModelTypeDVBT2) ? modelCountM[eSatipModuleDVBT2] : 0; }
void Update(void) { lastSeenM.Set(); }
uint64_t LastSeen(void) { return lastSeenM.Elapsed(); }
time_t Created(void) { return createdM; }
@ -77,11 +94,13 @@ public:
class cSatipServers : public cList<cSatipServer> {
public:
cSatipServer *Find(cSatipServer *serverP);
cSatipServer *Find(int sourceP, int transponderP, int systemP);
void SetTransponder(cSatipServer *serverP, int transponderP);
cSatipServer *Find(int sourceP);
cSatipServer *Assign(int sourceP, int transponderP, int systemP);
cSatipServer *Update(cSatipServer *serverP);
void Use(cSatipServer *serverP, bool onOffP);
void Use(cSatipServer *serverP, int transponderP, bool onOffP);
bool IsQuirk(cSatipServer *serverP, int quirkP);
void Cleanup(uint64_t intervalMsP = 0);
cString GetAddress(cSatipServer *serverP);
cString GetString(cSatipServer *serverP);
cString List(void);
int NumProvidedSystems(void);

31
tuner.c
View File

@ -25,8 +25,8 @@ cSatipTuner::cSatipTuner(cSatipDeviceIf &deviceP, unsigned int packetLenP)
rtcpM(*this),
streamAddrM(""),
streamParamM(""),
currentServerM(NULL),
nextServerM(NULL),
currentServerM(NULL, 0),
nextServerM(NULL, 0),
mutexM(),
reConnectM(),
keepAliveM(),
@ -119,7 +119,7 @@ void cSatipTuner::Action(void)
// Read reception statistics via DESCRIBE and RTCP
if (hasLockM || ReadReceptionStatus()) {
// Quirk for devices without valid reception data
if (currentServerM && currentServerM->Quirk(cSatipServer::eSatipQuirkForceLock)) {
if (currentServerM.IsQuirk(cSatipServer::eSatipQuirkForceLock)) {
hasLockM = true;
signalStrengthM = eDefaultSignalStrength;
signalQualityM = eDefaultSignalQuality;
@ -201,11 +201,11 @@ bool cSatipTuner::Connect(void)
rtcpM.Flush();
if (rtspM.Setup(*uri, rtpM.Port(), rtcpM.Port())) {
keepAliveM.Set(timeoutM);
if (nextServerM) {
cSatipDiscover::GetInstance()->UseServer(nextServerM, true);
if (nextServerM.IsValid()) {
currentServerM = nextServerM;
nextServerM = NULL;
nextServerM.Reset();
}
currentServerM.Use(true);
return true;
}
}
@ -237,8 +237,7 @@ bool cSatipTuner::Disconnect(void)
signalQualityM = -1;
frontendIdM = -1;
if (currentServerM)
cSatipDiscover::GetInstance()->UseServer(currentServerM, false);
currentServerM.Use(false);
statusUpdateM.Set(0);
timeoutM = eMinKeepAliveIntervalMs;
pmtPidM = -1;
@ -335,7 +334,7 @@ void cSatipTuner::SetSessionTimeout(const char *sessionP, int timeoutP)
cMutexLock MutexLock(&mutexM);
debug1("%s (%s, %d) [device %d]", __PRETTY_FUNCTION__, sessionP, timeoutP, deviceIdM);
sessionM = sessionP;
if (nextServerM && nextServerM->Quirk(cSatipServer::eSatipQuirkSessionId) && !isempty(*sessionM) && startswith(*sessionM, "0"))
if (nextServerM.IsQuirk(cSatipServer::eSatipQuirkSessionId) && !isempty(*sessionM) && startswith(*sessionM, "0"))
rtspM.SetSession(SkipZeroes(*sessionM));
timeoutM = (timeoutP > eMinKeepAliveIntervalMs) ? timeoutP : eMinKeepAliveIntervalMs;
}
@ -346,15 +345,15 @@ int cSatipTuner::GetId(void)
return deviceIdM;
}
bool cSatipTuner::SetSource(cSatipServer *serverP, const char *parameterP, const int indexP)
bool cSatipTuner::SetSource(cSatipServer *serverP, const int transponderP, const char *parameterP, const int indexP)
{
debug1("%s (%s, %d) [device %d]", __PRETTY_FUNCTION__, parameterP, indexP, deviceIdM);
debug1("%s (%d, %s, %d) [device %d]", __PRETTY_FUNCTION__, transponderP, parameterP, indexP, deviceIdM);
cMutexLock MutexLock(&mutexM);
if (serverP) {
nextServerM = cSatipDiscover::GetInstance()->GetServer(serverP);
if (nextServerM && !isempty(nextServerM->Address()) && !isempty(parameterP)) {
nextServerM.Set(serverP, transponderP);
if (!isempty(*nextServerM.GetAddress()) && !isempty(parameterP)) {
// Update stream address and parameter
streamAddrM = rtspM.RtspUnescapeString(nextServerM->Address());
streamAddrM = rtspM.RtspUnescapeString(*nextServerM.GetAddress());
streamParamM = rtspM.RtspUnescapeString(parameterP);
// Reconnect
RequestState(tsSet, smExternal);
@ -395,8 +394,8 @@ bool cSatipTuner::UpdatePids(bool forceP)
if (((forceP && pidsM.Size()) || (pidUpdateCacheM.TimedOut() && (addPidsM.Size() || delPidsM.Size()))) &&
!isempty(*streamAddrM) && (streamIdM > 0)) {
cString uri = cString::sprintf("rtsp://%s/stream=%d", *streamAddrM, streamIdM);
bool useci = (SatipConfig.GetCIExtension() && !!(currentServerM && currentServerM->Quirk(cSatipServer::eSatipQuirkUseXCI)));
bool usedummy = !!(currentServerM && currentServerM->Quirk(cSatipServer::eSatipQuirkPlayPids));
bool useci = (SatipConfig.GetCIExtension() && currentServerM.IsQuirk(cSatipServer::eSatipQuirkUseXCI));
bool usedummy = currentServerM.IsQuirk(cSatipServer::eSatipQuirkPlayPids);
if (forceP || usedummy) {
if (pidsM.Size())
uri = cString::sprintf("%s?pids=%s", *uri, *pidsM.ListPids());

27
tuner.h
View File

@ -13,6 +13,7 @@
#include <vdr/tools.h>
#include "deviceif.h"
#include "discover.h"
#include "rtp.h"
#include "rtcp.h"
#include "rtsp.h"
@ -76,6 +77,26 @@ public:
}
};
class cSatipTunerServer
{
private:
cSatipServer *serverM;
int transponderM;
public:
cSatipTunerServer(cSatipServer *serverP, const int transponderP) : serverM(serverP), transponderM(transponderP) {}
~cSatipTunerServer() {}
cSatipTunerServer(const cSatipTunerServer &objP) { serverM = NULL; transponderM = 0; }
cSatipTunerServer& operator= (const cSatipTunerServer &objP) { serverM = objP.serverM; transponderM = objP.transponderM; return *this; }
bool IsValid(void) { return !!serverM; }
bool IsQuirk(int quirkP) { return (serverM && cSatipDiscover::GetInstance()->IsServerQuirk(serverM, quirkP)); }
void Use(bool onOffP) { if (serverM) cSatipDiscover::GetInstance()->UseServer(serverM, transponderM, onOffP); }
void Set(cSatipServer *serverP, const int transponderP) { serverM = serverP; transponderM = transponderP; }
void Reset(void) { serverM = NULL; transponderM = 0; }
cString GetAddress(void) { return serverM ? cSatipDiscover::GetInstance()->GetServerAddress(serverM) : ""; }
cString GetInfo(void) { return cString::sprintf("server=%s transponder=%d", serverM ? "assigned" : "null", transponderM); }
};
class cSatipTuner : public cThread, public cSatipTunerStatistics, public cSatipTunerIf
{
private:
@ -100,8 +121,8 @@ private:
cSatipRtcp rtcpM;
cString streamAddrM;
cString streamParamM;
cSatipServer *currentServerM;
cSatipServer *nextServerM;
cSatipTunerServer currentServerM;
cSatipTunerServer nextServerM;
cMutex mutexM;
cTimeMs reConnectM;
cTimeMs keepAliveM;
@ -140,7 +161,7 @@ public:
cSatipTuner(cSatipDeviceIf &deviceP, unsigned int packetLenP);
virtual ~cSatipTuner();
bool IsTuned(void) const { return (currentStateM >= tsTuned); }
bool SetSource(cSatipServer *serverP, const char *parameterP, const int indexP);
bool SetSource(cSatipServer *serverP, const int transponderP, const char *parameterP, const int indexP);
bool SetPid(int pidP, int typeP, bool onP);
bool Open(void);
bool Close(void);