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

550 lines
18 KiB
C
Raw Normal View History

/*
* server.c: SAT>IP plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include <vdr/sources.h>
#include "config.h"
#include "common.h"
2014-12-05 22:14:40 +01:00
#include "log.h"
#include "server.h"
2015-01-15 22:33:51 +01:00
// --- cSatipFrontend ---------------------------------------------------------
cSatipFrontend::cSatipFrontend(const int indexP, const char *descriptionP)
: indexM(indexP),
transponderM(0),
deviceIdM(-1),
descriptionM(descriptionP)
2015-01-15 22:33:51 +01:00
{
}
cSatipFrontend::~cSatipFrontend()
{
}
// --- cSatipFrontends --------------------------------------------------------
bool cSatipFrontends::Matches(int deviceIdP, int transponderP)
2015-01-15 22:33:51 +01:00
{
for (cSatipFrontend *f = First(); f; f = Next(f)) {
2015-02-16 18:42:18 +01:00
if (f->Attached() && (f->DeviceId() == deviceIdP) && (f->Transponder() == transponderP))
2015-01-15 22:33:51 +01:00
return true;
}
return false;
}
bool cSatipFrontends::Assign(int deviceIdP, int transponderP)
2015-01-15 22:33:51 +01:00
{
2015-02-16 18:42:18 +01:00
cSatipFrontend *tmp = NULL;
2015-01-15 22:33:51 +01:00
// Prefer any unused one
for (cSatipFrontend *f = First(); f; f = Next(f)) {
2015-02-16 18:42:18 +01:00
if (!f->Attached() || (f->DeviceId() == deviceIdP)) {
2015-01-15 22:33:51 +01:00
tmp = f;
break;
}
}
if (tmp) {
tmp->SetTransponder(transponderP);
return true;
}
return false;
}
bool cSatipFrontends::Attach(int deviceIdP, int transponderP)
2015-01-15 22:33:51 +01:00
{
for (cSatipFrontend *f = First(); f; f = Next(f)) {
if (f->Transponder() == transponderP) {
f->Attach(deviceIdP);
debug9("%s (%d, %d) %s/#%d", __PRETTY_FUNCTION__, deviceIdP, transponderP, *f->Description(), f->Index());
return true;
}
}
return false;
}
bool cSatipFrontends::Detach(int deviceIdP, int transponderP)
{
for (cSatipFrontend *f = First(); f; f = Next(f)) {
if (f->Transponder() == transponderP) {
f->Detach(deviceIdP);
debug9("%s (%d, %d) %s/#%d", __PRETTY_FUNCTION__, deviceIdP, transponderP, *f->Description(), f->Index());
2015-01-15 22:33:51 +01:00
return true;
}
}
return false;
}
// --- cSatipServer -----------------------------------------------------------
cSatipServer::cSatipServer(const char *srcAddressP, const char *addressP, const int portP, const char *modelP, const char *filtersP, const char *descriptionP, const int quirkP)
: srcAddressM((srcAddressP && *srcAddressP) ? srcAddressP : ""),
addressM((addressP && *addressP) ? addressP : "0.0.0.0"),
modelM((modelP && *modelP) ? modelP : "DVBS-1"),
2016-07-23 21:40:01 +02:00
filtersM((filtersP && *filtersP) ? filtersP : ""),
descriptionM(!isempty(descriptionP) ? descriptionP : "MyBrokenHardware"),
quirksM(""),
portM(portP),
quirkM(quirkP),
hasCiM(false),
activeM(true),
createdM(time(NULL)),
lastSeenM(0)
{
2016-07-23 21:40:01 +02:00
memset(sourceFiltersM, 0, sizeof(sourceFiltersM));
if (!isempty(*filtersM)) {
char *s, *p = strdup(*filtersM);
char *r = strtok_r(p, ",", &s);
unsigned int i = 0;
while (r) {
int t = cSource::FromString(skipspace(r));
if (t && i < ELEMENTS(sourceFiltersM))
sourceFiltersM[i++] = t;
r = strtok_r(NULL, ",", &s);
}
if (i) {
filtersM = "";
for (unsigned int j = 0; j < i; ++j)
filtersM = cString::sprintf("%s%s%s", *filtersM, isempty(*filtersM) ? "" : ",", *cSource::ToString(sourceFiltersM[j]));
debug3("%s filters=%s", __PRETTY_FUNCTION__, *filtersM);
}
FREE_POINTER(p);
}
if (!SatipConfig.GetDisableServerQuirks()) {
// These devices contain a session id bug:
// Inverto Airscreen Server IDL 400 ?
// Elgato EyeTV Netstream 4Sat ?
if (strstr(*descriptionM, "GSSBOX") || // Grundig Sat Systems GSS.box DSI 400
strstr(*descriptionM, "DIGIBIT") || // Telestar Digibit R1
strstr(*descriptionM, "Multibox-") || // Inverto IDL-400s: Multibox-<MMAACC>:SAT>IP
strstr(*descriptionM, "Triax SatIP Converter") // Triax TSS 400
)
quirkM |= eSatipQuirkSessionId;
2016-06-20 17:14:38 +02:00
// These devices contain support for RTP over TCP:
if (strstr(*descriptionM, "minisatip") || // minisatip server
strstr(*descriptionM, "DVBViewer") // DVBViewer Media Server
)
2016-06-20 17:14:38 +02:00
quirkM |= eSatipQuirkRtpOverTcp;
// These devices contain a play (add/delpids) parameter bug:
if (strstr(*descriptionM, "FRITZ!WLAN Repeater DVB-C") || // FRITZ!WLAN Repeater DVB-C
strstr(*descriptionM, "fritzdvbc") // FRITZ!WLAN Repeater DVB-C (old firmware)
)
quirkM |= eSatipQuirkPlayPids;
// These devices contain a frontend locking bug:
if (strstr(*descriptionM, "FRITZ!WLAN Repeater DVB-C") || // FRITZ!WLAN Repeater DVB-C
strstr(*descriptionM, "fritzdvbc") || // FRITZ!WLAN Repeater DVB-C (old firmware)
strstr(*descriptionM, "Schwaiger Sat>IP Server") // Schwaiger MS41IP
)
quirkM |= eSatipQuirkForceLock;
// These devices support the X_PMT protocol extension:
if (strstr(*descriptionM, "OctopusNet") || // Digital Devices OctopusNet
strstr(*descriptionM, "minisatip") // minisatip server
)
quirkM |= eSatipQuirkCiXpmt;
// These devices support the TNR protocol extension:
if (strstr(*descriptionM, "DVBViewer") // DVBViewer Media Server
)
quirkM |= eSatipQuirkCiTnr;
// These devices don't support auto-detection of pilot tones:
if (strstr(*descriptionM, "GSSBOX") || // Grundig Sat Systems GSS.box DSI 400
strstr(*descriptionM, "DIGIBIT") || // Telestar Digibit R1
strstr(*descriptionM, "Multibox-") || // Inverto IDL-400s: Multibox-<MMAACC>:SAT>IP
strstr(*descriptionM, "Triax SatIP Converter") || // Triax TSS 400
strstr(*descriptionM, "KATHREIN SatIP Server") // Kathrein ExIP 414/E
2016-11-10 15:47:30 +01:00
)
quirkM |= eSatipQuirkForcePilot;
// These devices require TEARDOWN before new PLAY command:
if (strstr(*descriptionM, "FRITZ!WLAN Repeater DVB-C") || // FRITZ!WLAN Repeater DVB-C
strstr(*descriptionM, "fritzdvbc") // FRITZ!WLAN Repeater DVB-C (old firmware)
)
quirkM |= eSatipQuirkTearAndPlay;
}
if ((quirkM & eSatipQuirkMask) & eSatipQuirkSessionId)
quirksM = cString::sprintf("%s%sSessionId", *quirksM, isempty(*quirksM) ? "" : ",");
if ((quirkM & eSatipQuirkMask) & eSatipQuirkPlayPids)
quirksM = cString::sprintf("%s%sPlayPids", *quirksM, isempty(*quirksM) ? "" : ",");
if ((quirkM & eSatipQuirkMask) & eSatipQuirkForceLock)
quirksM = cString::sprintf("%s%sForceLock", *quirksM, isempty(*quirksM) ? "" : ",");
if ((quirkM & eSatipQuirkMask) & eSatipQuirkRtpOverTcp)
quirksM = cString::sprintf("%s%sRtpOverTcp", *quirksM, isempty(*quirksM) ? "" : ",");
if ((quirkM & eSatipQuirkMask) & eSatipQuirkCiXpmt)
quirksM = cString::sprintf("%s%sCiXpmt", *quirksM, isempty(*quirksM) ? "" : ",");
if ((quirkM & eSatipQuirkMask) & eSatipQuirkCiTnr)
quirksM = cString::sprintf("%s%sCiTnr", *quirksM, isempty(*quirksM) ? "" : ",");
2016-11-10 15:47:30 +01:00
if ((quirkM & eSatipQuirkMask) & eSatipQuirkForcePilot)
quirksM = cString::sprintf("%s%sForcePilot", *quirksM, isempty(*quirksM) ? "" : ",");
debug3("%s description=%s quirks=%s", __PRETTY_FUNCTION__, *descriptionM, *quirksM);
// These devices support external CI
if (strstr(*descriptionM, "OctopusNet") || // Digital Devices OctopusNet
strstr(*descriptionM, "minisatip") || // minisatip server
strstr(*descriptionM, "DVBViewer") // DVBViewer Media Server
) {
hasCiM = true;
}
char *s, *p = strdup(*modelM);
char *r = strtok_r(p, ",", &s);
while (r) {
2015-01-15 22:33:51 +01:00
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"));
}
2015-01-15 22:33:51 +01:00
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"));
}
2015-01-15 22:33:51 +01:00
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"));
2014-10-30 21:10:09 +01:00
}
2015-01-15 22:33:51 +01:00
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"));
}
2015-01-15 22:33:51 +01:00
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"));
}
2020-01-03 21:05:18 +01:00
else if (c = strstr(r, "ATSC-")) {
int count = atoi(c + 5);
for (int i = 1; i <= count; ++i)
frontendsM[eSatipFrontendATSC].Add(new cSatipFrontend(i, "ATSC"));
}
r = strtok_r(NULL, ",", &s);
}
2016-07-23 21:40:01 +02:00
FREE_POINTER(p);
}
cSatipServer::~cSatipServer()
{
}
int cSatipServer::Compare(const cListObject &listObjectP) const
{
const cSatipServer *s = (const cSatipServer *)&listObjectP;
int result = strcasecmp(*addressM, *s->addressM);
if (!result) {
result = strcasecmp(*modelM, *s->modelM);
if (!result)
result = strcasecmp(*descriptionM, *s->descriptionM);
}
return result;
}
2016-07-23 21:40:01 +02:00
bool cSatipServer::IsValidSource(int sourceP)
{
if (sourceFiltersM[0]) {
for (unsigned int i = 0; i < ELEMENTS(sourceFiltersM); ++i) {
if (sourceP == sourceFiltersM[i]) {
return true;
}
}
return false;
}
return true;
}
bool cSatipServer::Assign(int deviceIdP, int sourceP, int systemP, int transponderP)
{
bool result = false;
if (IsValidSource(sourceP)) {
if (cSource::IsType(sourceP, 'S'))
result = frontendsM[eSatipFrontendDVBS2].Assign(deviceIdP, transponderP);
else if (cSource::IsType(sourceP, 'T')) {
if (systemP)
result = frontendsM[eSatipFrontendDVBT2].Assign(deviceIdP, transponderP);
else
result = frontendsM[eSatipFrontendDVBT].Assign(deviceIdP, transponderP) || frontendsM[eSatipFrontendDVBT2].Assign(deviceIdP, transponderP);
}
else if (cSource::IsType(sourceP, 'C')) {
if (systemP)
result = frontendsM[eSatipFrontendDVBC2].Assign(deviceIdP, transponderP);
else
result = frontendsM[eSatipFrontendDVBC].Assign(deviceIdP, transponderP) || frontendsM[eSatipFrontendDVBC2].Assign(deviceIdP, transponderP);
}
2020-01-03 21:05:18 +01:00
else if (cSource::IsType(sourceP, 'A'))
result = frontendsM[eSatipFrontendATSC].Assign(deviceIdP, transponderP);
}
return result;
}
2015-01-15 22:33:51 +01:00
bool cSatipServer::Matches(int sourceP)
{
2016-07-23 21:40:01 +02:00
if (IsValidSource(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();
2020-01-03 21:05:18 +01:00
else if (cSource::IsType(sourceP, 'A'))
return GetModulesATSC();
2016-07-23 21:40:01 +02:00
}
2015-01-15 22:33:51 +01:00
return false;
}
bool cSatipServer::Matches(int deviceIdP, int sourceP, int systemP, int transponderP)
2015-01-15 22:33:51 +01:00
{
bool result = false;
2016-07-23 21:40:01 +02:00
if (IsValidSource(sourceP)) {
if (cSource::IsType(sourceP, 'S'))
result = frontendsM[eSatipFrontendDVBS2].Matches(deviceIdP, transponderP);
else if (cSource::IsType(sourceP, 'T')) {
if (systemP)
result = frontendsM[eSatipFrontendDVBT2].Matches(deviceIdP, transponderP);
else
result = frontendsM[eSatipFrontendDVBT].Matches(deviceIdP, transponderP) || frontendsM[eSatipFrontendDVBT2].Matches(deviceIdP, transponderP);
}
else if (cSource::IsType(sourceP, 'C')) {
if (systemP)
result = frontendsM[eSatipFrontendDVBC2].Matches(deviceIdP, transponderP);
else
result = frontendsM[eSatipFrontendDVBC].Matches(deviceIdP, transponderP) || frontendsM[eSatipFrontendDVBC2].Matches(deviceIdP, transponderP);
}
2020-01-03 21:05:18 +01:00
else if (cSource::IsType(sourceP, 'A'))
result = frontendsM[eSatipFrontendATSC].Matches(deviceIdP, transponderP);
2015-01-15 22:33:51 +01:00
}
return result;
}
void cSatipServer::Attach(int deviceIdP, int transponderP)
2015-01-15 22:33:51 +01:00
{
for (int i = 0; i < eSatipFrontendCount; ++i) {
if (frontendsM[i].Attach(deviceIdP, transponderP))
return;
}
}
void cSatipServer::Detach(int deviceIdP, int transponderP)
{
for (int i = 0; i < eSatipFrontendCount; ++i) {
if (frontendsM[i].Detach(deviceIdP, transponderP))
2015-01-15 22:33:51 +01:00
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)
{
2015-01-15 22:33:51 +01:00
return frontendsM[eSatipFrontendDVBC2].Count();
}
2020-01-03 21:05:18 +01:00
int cSatipServer::GetModulesATSC(void)
{
return frontendsM[eSatipFrontendATSC].Count();
}
// --- cSatipServers ----------------------------------------------------------
cSatipServer *cSatipServers::Find(cSatipServer *serverP)
{
for (cSatipServer *s = First(); s; s = Next(s)) {
2015-01-15 22:33:51 +01:00
if (s->Compare(*serverP) == 0)
return s;
}
return NULL;
}
2015-01-15 22:33:51 +01:00
cSatipServer *cSatipServers::Find(int sourceP)
{
for (cSatipServer *s = First(); s; s = Next(s)) {
2015-01-15 22:33:51 +01:00
if (s->Matches(sourceP))
return s;
}
2015-01-15 22:33:51 +01:00
return NULL;
}
cSatipServer *cSatipServers::Assign(int deviceIdP, int sourceP, int transponderP, int systemP)
{
2016-06-23 14:36:51 +02:00
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s->IsActive() && s->Matches(deviceIdP, sourceP, systemP, transponderP))
2015-01-15 22:33:51 +01:00
return s;
}
2016-06-23 14:36:51 +02:00
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s->IsActive() && s->Assign(deviceIdP, sourceP, systemP, transponderP))
2015-01-15 22:33:51 +01:00
return s;
}
2015-01-15 22:33:51 +01:00
return NULL;
}
cSatipServer *cSatipServers::Update(cSatipServer *serverP)
{
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s->Compare(*serverP) == 0) {
s->Update();
return s;
}
}
return NULL;
}
void cSatipServers::Activate(cSatipServer *serverP, bool onOffP)
{
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP) {
s->Activate(onOffP);
break;
}
}
}
void cSatipServers::Attach(cSatipServer *serverP, int deviceIdP, int transponderP)
{
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP) {
s->Attach(deviceIdP, transponderP);
break;
}
}
}
void cSatipServers::Detach(cSatipServer *serverP, int deviceIdP, int transponderP)
2015-01-15 22:33:51 +01:00
{
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP) {
s->Detach(deviceIdP, transponderP);
2015-01-15 22:33:51 +01:00
break;
}
}
}
bool cSatipServers::IsQuirk(cSatipServer *serverP, int quirkP)
{
2015-01-15 22:33:51 +01:00
bool result = false;
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP) {
2015-01-15 22:33:51 +01:00
result = s->Quirk(quirkP);
break;
}
}
2015-01-15 22:33:51 +01:00
return result;
}
bool cSatipServers::HasCI(cSatipServer *serverP)
{
bool result = false;
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP) {
result = s->HasCI();
break;
}
}
return result;
}
void cSatipServers::Cleanup(uint64_t intervalMsP)
{
for (cSatipServer *s = First(); s; s = Next(s)) {
if (!intervalMsP || (s->LastSeen() > intervalMsP)) {
2014-12-16 22:09:31 +01:00
info("Removing server %s (%s %s)", s->Description(), s->Address(), s->Model());
Del(s);
}
}
}
cString cSatipServers::GetSrcAddress(cSatipServer *serverP)
{
cString address = "";
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP) {
address = s->SrcAddress();
break;
}
}
return address;
}
2015-01-15 22:33:51 +01:00
cString cSatipServers::GetAddress(cSatipServer *serverP)
{
cString address = "";
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP) {
address = s->Address();
break;
}
}
return address;
}
int cSatipServers::GetPort(cSatipServer *serverP)
{
int port = SATIP_DEFAULT_RTSP_PORT;
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP) {
port = s->Port();
break;
}
}
return port;
}
cString cSatipServers::GetString(cSatipServer *serverP)
{
cString list = "";
for (cSatipServer *s = First(); s; s = Next(s)) {
if (s == serverP) {
list = cString::sprintf("%s|%s|%s", s->Address(), s->Model(), s->Description());
break;
}
}
return list;
}
cString cSatipServers::List(void)
{
cString list = "";
for (cSatipServer *s = First(); s; s = Next(s))
if (isempty(s->SrcAddress()))
list = cString::sprintf("%s%c %s|%s|%s\n", *list, s->IsActive() ? '+' : '-', s->Address(), s->Model(), s->Description());
else
list = cString::sprintf("%s%c %s@%s|%s|%s\n", *list, s->IsActive() ? '+' : '-', s->SrcAddress(), s->Address(), s->Model(), s->Description());
return list;
}
int cSatipServers::NumProvidedSystems(void)
{
int count = 0;
for (cSatipServer *s = First(); s; s = Next(s)) {
// DVB-S2: qpsk, 8psk, 16apsk, 32apsk
2015-01-15 22:33:51 +01:00
count += s->GetModulesDVBS2() * 4;
// DVB-T: qpsk, qam16, qam64
2015-01-15 22:33:51 +01:00
count += s->GetModulesDVBT() * 3;
// DVB-T2: qpsk, qam16, qam64, qam256
count += s->GetModulesDVBT2() * 4;
// DVB-C: qam64, qam128, qam256
2015-01-15 22:33:51 +01:00
count += s->GetModulesDVBC() * 3;
// DVB-C2: qam16, qam32, qam64, qam128, qam256
count += s->GetModulesDVBC2() * 5;
2020-01-03 21:05:18 +01:00
// ATSC: 8vbs, 16vbs, qam256
count += s->GetModulesATSC() * 3;
}
return count;
}