Fixed reconnection.

This commit is contained in:
Rolf Ahrenberg 2014-12-16 22:35:49 +02:00
parent 8ea561a021
commit 01d2afcfc2
4 changed files with 58 additions and 36 deletions

82
rtsp.c
View File

@ -15,45 +15,17 @@
cSatipRtsp::cSatipRtsp(cSatipTunerIf &tunerP) cSatipRtsp::cSatipRtsp(cSatipTunerIf &tunerP)
: tunerM(tunerP), : tunerM(tunerP),
handleM(curl_easy_init()), handleM(NULL),
headerListM(NULL) headerListM(NULL)
{ {
debug1("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId()); debug1("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
Create();
if (handleM) {
CURLcode res = CURLE_OK;
// Verbose output
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_VERBOSE, 1L);
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGFUNCTION, cSatipRtsp::DebugCallback);
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGDATA, this);
// No progress meter and no signaling
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_NOPROGRESS, 1L);
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_NOSIGNAL, 1L);
// Set timeouts
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_TIMEOUT_MS, (long)eConnectTimeoutMs);
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_CONNECTTIMEOUT_MS, (long)eConnectTimeoutMs);
// Set user-agent
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_USERAGENT, *cString::sprintf("vdr-%s/%s (device %d)", PLUGIN_NAME_I18N, VERSION, tunerM.GetId()));
}
} }
cSatipRtsp::~cSatipRtsp() cSatipRtsp::~cSatipRtsp()
{ {
debug1("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId()); debug1("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
Destroy();
if (handleM) {
// Cleanup curl stuff
if (headerListM) {
curl_slist_free_all(headerListM);
headerListM = NULL;
}
curl_easy_cleanup(handleM);
handleM = NULL;
}
} }
size_t cSatipRtsp::HeaderCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP) size_t cSatipRtsp::HeaderCallback(void *ptrP, size_t sizeP, size_t nmembP, void *dataP)
@ -143,6 +115,54 @@ cString cSatipRtsp::RtspUnescapeString(const char *strP)
return cString(strP); return cString(strP);
} }
void cSatipRtsp::Create(void)
{
debug1("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
if (!handleM)
handleM = curl_easy_init();
if (handleM) {
CURLcode res = CURLE_OK;
// Verbose output
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_VERBOSE, 1L);
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGFUNCTION, cSatipRtsp::DebugCallback);
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGDATA, this);
// No progress meter and no signaling
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_NOPROGRESS, 1L);
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_NOSIGNAL, 1L);
// Set timeouts
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_TIMEOUT_MS, (long)eConnectTimeoutMs);
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_CONNECTTIMEOUT_MS, (long)eConnectTimeoutMs);
// Set user-agent
SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_USERAGENT, *cString::sprintf("vdr-%s/%s (device %d)", PLUGIN_NAME_I18N, VERSION, tunerM.GetId()));
}
}
void cSatipRtsp::Destroy(void)
{
debug1("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
if (handleM) {
// Cleanup curl stuff
if (headerListM) {
curl_slist_free_all(headerListM);
headerListM = NULL;
}
curl_easy_cleanup(handleM);
handleM = NULL;
}
}
void cSatipRtsp::Reset(void)
{
debug1("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId());
Destroy();
Create();
}
bool cSatipRtsp::Options(const char *uriP) bool cSatipRtsp::Options(const char *uriP)
{ {
debug1("%s (%s) [device %d]", __PRETTY_FUNCTION__, uriP, tunerM.GetId()); debug1("%s (%s) [device %d]", __PRETTY_FUNCTION__, uriP, tunerM.GetId());

3
rtsp.h
View File

@ -31,6 +31,8 @@ private:
CURL *handleM; CURL *handleM;
struct curl_slist *headerListM; struct curl_slist *headerListM;
void Create(void);
void Destroy(void);
bool ValidateLatestResponse(long *rcP); bool ValidateLatestResponse(long *rcP);
// to prevent copy constructor and assignment // to prevent copy constructor and assignment
@ -42,6 +44,7 @@ public:
virtual ~cSatipRtsp(); virtual ~cSatipRtsp();
cString RtspUnescapeString(const char *strP); cString RtspUnescapeString(const char *strP);
void Reset(void);
bool Options(const char *uriP); bool Options(const char *uriP);
bool Setup(const char *uriP, int rtpPortP, int rtcpPortP); bool Setup(const char *uriP, int rtpPortP, int rtcpPortP);
bool SetSession(const char *sessionP); bool SetSession(const char *sessionP);

View File

@ -104,15 +104,12 @@ void cSatipTuner::Action(void)
break; break;
case tsSet: case tsSet:
debug4("%s: tsSet [device %d]", __PRETTY_FUNCTION__, deviceIdM); debug4("%s: tsSet [device %d]", __PRETTY_FUNCTION__, deviceIdM);
reConnectM.Set(eConnectTimeoutMs);
if (Connect()) { if (Connect()) {
RequestState(tsTuned, smInternal); RequestState(tsTuned, smInternal);
UpdatePids(true); UpdatePids(true);
} }
else { else
error("Tuning failed - retuning [device %d]", deviceIdM);
Disconnect(); Disconnect();
}
break; break;
case tsTuned: case tsTuned:
debug4("%s: tsTuned [device %d]", __PRETTY_FUNCTION__, deviceIdM); debug4("%s: tsTuned [device %d]", __PRETTY_FUNCTION__, deviceIdM);
@ -212,6 +209,8 @@ bool cSatipTuner::Connect(void)
return true; return true;
} }
} }
else
rtspM.Reset();
streamIdM = -1; streamIdM = -1;
error("Connect failed [device %d]", deviceIdM); error("Connect failed [device %d]", deviceIdM);
} }

View File

@ -68,7 +68,7 @@ private:
eDummyPid = 100, eDummyPid = 100,
eDefaultSignalStrength = 15, eDefaultSignalStrength = 15,
eDefaultSignalQuality = 224, eDefaultSignalQuality = 224,
eSleepTimeoutMs = 500, // in milliseconds eSleepTimeoutMs = 1000, // in milliseconds
eStatusUpdateTimeoutMs = 1000, // in milliseconds eStatusUpdateTimeoutMs = 1000, // in milliseconds
ePidUpdateIntervalMs = 250, // in milliseconds ePidUpdateIntervalMs = 250, // in milliseconds
eConnectTimeoutMs = 5000, // in milliseconds eConnectTimeoutMs = 5000, // in milliseconds