Added cSatipDiscoverIf().

This commit is contained in:
Rolf Ahrenberg 2014-11-29 15:37:21 +02:00
parent cdb2e0e3b4
commit eea0aa33bd
7 changed files with 90 additions and 58 deletions

View File

@ -119,7 +119,7 @@ int cSatipDiscover::DebugCallback(CURL *handleP, curl_infotype typeP, char *data
cSatipDiscover::cSatipDiscover() cSatipDiscover::cSatipDiscover()
: cThread("SAT>IP discover"), : cThread("SAT>IP discover"),
mutexM(), mutexM(),
msearchM(), msearchM(*this),
probeUrlListM(), probeUrlListM(),
handleM(curl_easy_init()), handleM(curl_easy_init()),
sleepM(), sleepM(),
@ -190,14 +190,6 @@ void cSatipDiscover::Action(void)
debug("cSatipDiscover::%s(): exiting", __FUNCTION__); debug("cSatipDiscover::%s(): exiting", __FUNCTION__);
} }
void cSatipDiscover::Probe(const char *urlP)
{
debug("cSatipDiscover::%s(%s)", __FUNCTION__, urlP);
cMutexLock MutexLock(&mutexM);
probeUrlListM.Insert(strdup(urlP));
sleepM.Signal();
}
void cSatipDiscover::Fetch(const char *urlP) void cSatipDiscover::Fetch(const char *urlP)
{ {
debug("cSatipDiscover::%s(%s)", __FUNCTION__, urlP); debug("cSatipDiscover::%s(%s)", __FUNCTION__, urlP);
@ -312,3 +304,12 @@ int cSatipDiscover::NumProvidedSystems(void)
cMutexLock MutexLock(&mutexM); cMutexLock MutexLock(&mutexM);
return serversM.NumProvidedSystems(); return serversM.NumProvidedSystems();
} }
void cSatipDiscover::SetUrl(const char *urlP)
{
//debug("cSatipDiscover::%s(%s)", __FUNCTION__, urlP);
mutexM.Lock();
probeUrlListM.Insert(strdup(urlP));
mutexM.Unlock();
sleepM.Signal();
}

View File

@ -13,6 +13,7 @@
#include <vdr/thread.h> #include <vdr/thread.h>
#include <vdr/tools.h> #include <vdr/tools.h>
#include "discoverif.h"
#include "msearch.h" #include "msearch.h"
#include "server.h" #include "server.h"
#include "socket.h" #include "socket.h"
@ -35,7 +36,7 @@ public:
class cSatipDiscoverServers : public cList<cSatipDiscoverServer> { class cSatipDiscoverServers : public cList<cSatipDiscoverServer> {
}; };
class cSatipDiscover : public cThread { class cSatipDiscover : public cThread, public cSatipDiscoverIf {
private: private:
enum { enum {
eSleepTimeoutMs = 500, // in milliseconds eSleepTimeoutMs = 500, // in milliseconds
@ -71,7 +72,6 @@ public:
static bool Initialize(cSatipDiscoverServers *serversP); static bool Initialize(cSatipDiscoverServers *serversP);
static void Destroy(void); static void Destroy(void);
virtual ~cSatipDiscover(); virtual ~cSatipDiscover();
void Probe(const char *urlP);
void TriggerScan(void) { probeIntervalM.Set(0); } void TriggerScan(void) { probeIntervalM.Set(0); }
int GetServerCount(void); int GetServerCount(void);
cSatipServer *GetServer(int sourceP, int transponderP = 0, int systemP = -1); cSatipServer *GetServer(int sourceP, int transponderP = 0, int systemP = -1);
@ -82,6 +82,10 @@ public:
void UseServer(cSatipServer *serverP, bool onOffP); void UseServer(cSatipServer *serverP, bool onOffP);
cString GetServerList(void); cString GetServerList(void);
int NumProvidedSystems(void); int NumProvidedSystems(void);
// for internal discover interface
public:
virtual void SetUrl(const char *urlP);
}; };
#endif // __SATIP_DISCOVER_H #endif // __SATIP_DISCOVER_H

22
discoverif.h Normal file
View File

@ -0,0 +1,22 @@
/*
* discoverif.h: SAT>IP plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#ifndef __SATIP_DISCOVERIF_H
#define __SATIP_DISCOVERIF_H
class cSatipDiscoverIf {
public:
cSatipDiscoverIf() {}
virtual ~cSatipDiscoverIf() {}
virtual void SetUrl(const char *urlP) = 0;
private:
cSatipDiscoverIf(const cSatipDiscoverIf&);
cSatipDiscoverIf& operator=(const cSatipDiscoverIf&);
};
#endif // __SATIP_DISCOVERIF_H

View File

@ -17,8 +17,9 @@ const char *cSatipMsearch::bcastMessageS = "M-SEARCH * HTTP/1.1\r\n"
"ST: urn:ses-com:device:SatIPServer:1\r\n" \ "ST: urn:ses-com:device:SatIPServer:1\r\n" \
"MX: 2\r\n\r\n"; "MX: 2\r\n\r\n";
cSatipMsearch::cSatipMsearch(void) cSatipMsearch::cSatipMsearch(cSatipDiscoverIf &discoverP)
: bufferLenM(eProbeBufferSize), : discoverM(discoverP),
bufferLenM(eProbeBufferSize),
bufferM(MALLOC(unsigned char, bufferLenM)), bufferM(MALLOC(unsigned char, bufferLenM)),
registeredM(false) registeredM(false)
{ {
@ -53,43 +54,45 @@ void cSatipMsearch::Process(void)
{ {
//debug("cSatipMsearch::%s()", __FUNCTION__); //debug("cSatipMsearch::%s()", __FUNCTION__);
if (bufferM) { if (bufferM) {
int length = Read(bufferM, bufferLenM); int length;
if (length > 0) { while ((length = Read(bufferM, bufferLenM)) > 0) {
bufferM[min(length, int(bufferLenM - 1))] = 0; bufferM[min(length, int(bufferLenM - 1))] = 0;
//debug("cSatipMsearch::%s(): len=%d buf=%s", __FUNCTION__, length, bufferM); //debug("cSatipMsearch::%s(): len=%d buf=%s", __FUNCTION__, length, bufferM);
bool status = false, valid = false; bool status = false, valid = false;
char *s, *p = reinterpret_cast<char *>(bufferM), *location = NULL; char *s, *p = reinterpret_cast<char *>(bufferM), *location = NULL;
char *r = strtok_r(p, "\r\n", &s); char *r = strtok_r(p, "\r\n", &s);
while (r) { while (r) {
//debug("cSatipMsearch::%s(): %s", __FUNCTION__, r); //debug("cSatipMsearch::%s(): %s", __FUNCTION__, r);
// Check the status code // Check the status code
// HTTP/1.1 200 OK // HTTP/1.1 200 OK
if (!status && startswith(r, "HTTP/1.1 200 OK")) if (!status && startswith(r, "HTTP/1.1 200 OK"))
status = true; status = true;
if (status) { if (status) {
// Check the location data // Check the location data
// LOCATION: http://192.168.0.115:8888/octonet.xml // LOCATION: http://192.168.0.115:8888/octonet.xml
if (startswith(r, "LOCATION:")) { if (startswith(r, "LOCATION:")) {
location = compactspace(r + 9); location = compactspace(r + 9);
debug("cSatipMsearch::%s(): location='%s'", __FUNCTION__, location); debug("cSatipMsearch::%s(): location='%s'", __FUNCTION__, location);
} }
// Check the source type // Check the source type
// ST: urn:ses-com:device:SatIPServer:1 // ST: urn:ses-com:device:SatIPServer:1
else if (startswith(r, "ST:")) { else if (startswith(r, "ST:")) {
char *st = compactspace(r + 3); char *st = compactspace(r + 3);
if (strstr(st, "urn:ses-com:device:SatIPServer:1")) if (strstr(st, "urn:ses-com:device:SatIPServer:1"))
valid = true; valid = true;
debug("cSatipMsearch::%s(): st='%s'", __FUNCTION__, st); debug("cSatipMsearch::%s(): st='%s'", __FUNCTION__, st);
} }
// Check whether all the required data is found // Check whether all the required data is found
if (valid && !isempty(location)) { if (valid && !isempty(location)) {
cSatipDiscover::GetInstance()->Probe(location); discoverM.SetUrl(location);
break; break;
}
} }
r = strtok_r(NULL, "\r\n", &s);
} }
r = strtok_r(NULL, "\r\n", &s); }
} if (errno != EAGAIN && errno != EWOULDBLOCK)
} error("Error %d reading in %s", errno, *ToString());
} }
} }

View File

@ -8,6 +8,7 @@
#ifndef __SATIP_MSEARCH_H_ #ifndef __SATIP_MSEARCH_H_
#define __SATIP_MSEARCH_H_ #define __SATIP_MSEARCH_H_
#include "discoverif.h"
#include "socket.h" #include "socket.h"
#include "pollerif.h" #include "pollerif.h"
@ -19,12 +20,13 @@ private:
}; };
static const char *bcastAddressS; static const char *bcastAddressS;
static const char *bcastMessageS; static const char *bcastMessageS;
cSatipDiscoverIf &discoverM;
unsigned int bufferLenM; unsigned int bufferLenM;
unsigned char *bufferM; unsigned char *bufferM;
bool registeredM; bool registeredM;
public: public:
cSatipMsearch(void); cSatipMsearch(cSatipDiscoverIf &discoverP);
virtual ~cSatipMsearch(); virtual ~cSatipMsearch();
void Probe(void); void Probe(void);

16
rtcp.c
View File

@ -81,14 +81,14 @@ void cSatipRtcp::Process(void)
{ {
//debug("cSatipRtcp::%s() [device %d]", __FUNCTION__, tunerM.GetId()); //debug("cSatipRtcp::%s() [device %d]", __FUNCTION__, tunerM.GetId());
if (bufferM) { if (bufferM) {
int length; int length;
while ((length = Read(bufferM, bufferLenM)) > 0) { while ((length = Read(bufferM, bufferLenM)) > 0) {
int offset = GetApplicationOffset(&length); int offset = GetApplicationOffset(&length);
if (offset >= 0) if (offset >= 0)
tunerM.ProcessApplicationData(bufferM + offset, length); tunerM.ProcessApplicationData(bufferM + offset, length);
} }
if (errno != EAGAIN && errno != EWOULDBLOCK) if (errno != EAGAIN && errno != EWOULDBLOCK)
error("Error %d reading from RTCP socket [device %d]", errno, tunerM.GetId()); error("Error %d reading in %s", errno, *ToString());
} }
} }

2
rtp.c
View File

@ -118,7 +118,7 @@ void cSatipRtp::Process(void)
tunerM.ProcessVideoData(bufferM + headerlen, length - headerlen); tunerM.ProcessVideoData(bufferM + headerlen, length - headerlen);
} }
if (errno != EAGAIN && errno != EWOULDBLOCK) if (errno != EAGAIN && errno != EWOULDBLOCK)
error("Error %d reading from RTP socket [device %d]", errno, tunerM.GetId()); error("Error %d reading in %s", errno, *ToString());
} }
} }