diff --git a/src/input/input_rtsp.cpp b/src/input/input_rtsp.cpp index 23964e06..9e05b910 100755 --- a/src/input/input_rtsp.cpp +++ b/src/input/input_rtsp.cpp @@ -102,7 +102,7 @@ namespace Mist{ } } sndH.SendRequest(tcpCon, "", true); - parsePacket(); + parsePacket(true); if (reAuth && needAuth && authRequest.size() && (username.size() || password.size()) && tcpCon){ INFO_MSG("Authenticating %s...", cmd.c_str()); @@ -150,17 +150,30 @@ namespace Mist{ return; } if (sdpState.tracks.size()){ + bool atLeastOne = false; for (std::map::iterator it = sdpState.tracks.begin(); it != sdpState.tracks.end(); ++it){ transportSet = false; extraHeaders.clear(); extraHeaders["Transport"] = it->second.generateTransport(it->first, url.host, TCPmode); sendCommand("SETUP", HTTP::URL(url.getUrl()+"/").link(it->second.control).getUrl(), "", &extraHeaders); - if (!tcpCon || !transportSet){ - FAIL_MSG("Could not setup track %s!", myMeta.tracks[it->first].getIdentifier().c_str()); - tcpCon.close(); - return; + if (tcpCon && transportSet){ + atLeastOne = true; + continue; } + if (!atLeastOne && tcpCon){ + INFO_MSG("Failed to set up transport for track %s, switching transports...", myMeta.tracks[it->first].getIdentifier().c_str()); + TCPmode = !TCPmode; + extraHeaders["Transport"] = it->second.generateTransport(it->first, url.host, TCPmode); + sendCommand("SETUP", HTTP::URL(url.getUrl()+"/").link(it->second.control).getUrl(), "", &extraHeaders); + } + if (tcpCon && transportSet){ + atLeastOne = true; + continue; + } + FAIL_MSG("Could not setup track %s!", myMeta.tracks[it->first].getIdentifier().c_str()); + tcpCon.close(); + return; } } INFO_MSG("Setup complete"); @@ -224,7 +237,7 @@ namespace Mist{ return "Unknown"; } - bool InputRTSP::parsePacket(){ + bool InputRTSP::parsePacket(bool mustHave){ uint32_t waitTime = 500; if (!TCPmode){waitTime = 50;} do{ @@ -233,7 +246,7 @@ namespace Mist{ if (!tcpCon.spool() && tcpCon && config->is_active && nProxy.userClient.isAlive()){ nProxy.userClient.keepAlive(); Util::sleep(waitTime); - if (!TCPmode){return true;} + if (!mustHave){return tcpCon;} } continue; } diff --git a/src/input/input_rtsp.h b/src/input/input_rtsp.h index 9f8bfa40..28765fda 100755 --- a/src/input/input_rtsp.h +++ b/src/input/input_rtsp.h @@ -29,7 +29,7 @@ namespace Mist{ void seek(int seekTime){} void sendCommand(const std::string &cmd, const std::string &cUrl, const std::string &body, const std::map *extraHeaders = 0, bool reAuth=true); - bool parsePacket(); + bool parsePacket(bool mustHave = false); bool handleUDP(); std::string streamMainLoop(); Socket::Connection tcpCon;