From 01d2afcfc20b1958ed2308fc454195bc2c09ce1d Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Tue, 16 Dec 2014 22:35:49 +0200 Subject: [PATCH] Fixed reconnection. --- rtsp.c | 82 +++++++++++++++++++++++++++++++++++---------------------- rtsp.h | 3 +++ tuner.c | 7 +++-- tuner.h | 2 +- 4 files changed, 58 insertions(+), 36 deletions(-) diff --git a/rtsp.c b/rtsp.c index e239354..446580b 100644 --- a/rtsp.c +++ b/rtsp.c @@ -15,45 +15,17 @@ cSatipRtsp::cSatipRtsp(cSatipTunerIf &tunerP) : tunerM(tunerP), - handleM(curl_easy_init()), + handleM(NULL), headerListM(NULL) { debug1("%s [device %d]", __PRETTY_FUNCTION__, tunerM.GetId()); - - 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())); - } + Create(); } cSatipRtsp::~cSatipRtsp() { 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; - } + Destroy(); } 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); } +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) { debug1("%s (%s) [device %d]", __PRETTY_FUNCTION__, uriP, tunerM.GetId()); diff --git a/rtsp.h b/rtsp.h index b7e01bd..659c644 100644 --- a/rtsp.h +++ b/rtsp.h @@ -31,6 +31,8 @@ private: CURL *handleM; struct curl_slist *headerListM; + void Create(void); + void Destroy(void); bool ValidateLatestResponse(long *rcP); // to prevent copy constructor and assignment @@ -42,6 +44,7 @@ public: virtual ~cSatipRtsp(); cString RtspUnescapeString(const char *strP); + void Reset(void); bool Options(const char *uriP); bool Setup(const char *uriP, int rtpPortP, int rtcpPortP); bool SetSession(const char *sessionP); diff --git a/tuner.c b/tuner.c index d89d53f..e09bdbc 100644 --- a/tuner.c +++ b/tuner.c @@ -104,15 +104,12 @@ void cSatipTuner::Action(void) break; case tsSet: debug4("%s: tsSet [device %d]", __PRETTY_FUNCTION__, deviceIdM); - reConnectM.Set(eConnectTimeoutMs); if (Connect()) { RequestState(tsTuned, smInternal); UpdatePids(true); } - else { - error("Tuning failed - retuning [device %d]", deviceIdM); + else Disconnect(); - } break; case tsTuned: debug4("%s: tsTuned [device %d]", __PRETTY_FUNCTION__, deviceIdM); @@ -212,6 +209,8 @@ bool cSatipTuner::Connect(void) return true; } } + else + rtspM.Reset(); streamIdM = -1; error("Connect failed [device %d]", deviceIdM); } diff --git a/tuner.h b/tuner.h index a24d2be..e5fe551 100644 --- a/tuner.h +++ b/tuner.h @@ -68,7 +68,7 @@ private: eDummyPid = 100, eDefaultSignalStrength = 15, eDefaultSignalQuality = 224, - eSleepTimeoutMs = 500, // in milliseconds + eSleepTimeoutMs = 1000, // in milliseconds eStatusUpdateTimeoutMs = 1000, // in milliseconds ePidUpdateIntervalMs = 250, // in milliseconds eConnectTimeoutMs = 5000, // in milliseconds