From f4051b59167ba06585528fd67c5741d08e3e70e7 Mon Sep 17 00:00:00 2001 From: Thulinma Date: Thu, 24 Sep 2020 18:01:51 +0200 Subject: [PATCH] Fixed RTSP input in newMeta build --- lib/sdp.cpp | 2 +- src/input/input_rtsp.cpp | 39 +++++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/lib/sdp.cpp b/lib/sdp.cpp index 95ea959a..6fff3dbe 100644 --- a/lib/sdp.cpp +++ b/lib/sdp.cpp @@ -225,7 +225,7 @@ namespace SDP{ // We simply request interleaved delivery over a trackNo-based identifier. // No need to set any internal state, parseTransport will handle it all. std::stringstream tStr; - tStr << "RTP/AVP/TCP;unicast;interleaved=" << ((trackNo - 1) * 2) << "-" << ((trackNo - 1) * 2 + 1); + tStr << "RTP/AVP/TCP;unicast;interleaved=" << (trackNo * 2) << "-" << (trackNo * 2 + 1); return tStr.str(); }else{ // A little more tricky: we need to find free ports and remember them. diff --git a/src/input/input_rtsp.cpp b/src/input/input_rtsp.cpp index 71d9a554..6ab3eb6a 100644 --- a/src/input/input_rtsp.cpp +++ b/src/input/input_rtsp.cpp @@ -169,8 +169,7 @@ namespace Mist{ continue; } if (!atLeastOne && tcpCon){ - INFO_MSG("Failed to set up transport for track %s, switching transports...", - M.getTrackIdentifier(it->first).c_str()); + INFO_MSG("Failed to set up transport for track %s, switching transports...", M.getTrackIdentifier(it->first).c_str()); TCPmode = !TCPmode; extraHeaders["Transport"] = it->second.generateTransport(it->first, url.host, TCPmode); sendCommand("SETUP", lastRequestedSetup, "", &extraHeaders); @@ -339,19 +338,16 @@ namespace Mist{ size_t trackNo = sdpState.getTrackNoForChannel(chan); EXTREME_MSG("Received %ub RTP packet #%u on channel %u, time %" PRIu32, len, pkt.getSequence(), chan, pkt.getTimeStamp()); - if ((trackNo == INVALID_TRACK_ID) && (chan % 2) != 1){ - WARN_MSG("Received packet for unknown track number on channel %u", chan); - } - if (trackNo != INVALID_TRACK_ID){ - sdpState.tracks[trackNo].sorter.rtpSeq = pkt.getSequence(); + if (trackNo == INVALID_TRACK_ID){ + if ((chan % 2) != 1){ + WARN_MSG("Received packet for unknown track number on channel %u", chan); + } + return true; } - if (trackNo != INVALID_TRACK_ID){ - if (!userSelect.count(trackNo)){ - userSelect[trackNo].reload(streamName, trackNo, COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK); - } - sdpState.handleIncomingRTP(trackNo, pkt); - } + //We override the rtpSeq number because in TCP mode packet loss is not a thing. + sdpState.tracks[trackNo].sorter.rtpSeq = pkt.getSequence(); + sdpState.handleIncomingRTP(trackNo, pkt); return true; @@ -399,7 +395,22 @@ namespace Mist{ char *pktData; size_t pktDataLen; pkt.getString("data", pktData, pktDataLen); - bufferLivePacket(pkt.getTime() + packetOffset, pkt.getInt("offset"), pkt.getTrackId(), pktData, + size_t idx = M.trackIDToIndex(pkt.getTrackId(), getpid()); + + if (idx == INVALID_TRACK_ID){ + INFO_MSG("Invalid index for track number %zu", pkt.getTrackId()); + }else{ + if (!userSelect.count(idx)){ + WARN_MSG("Reloading track %zu, index %zu", pkt.getTrackId(), idx); + userSelect[idx].reload(streamName, idx, COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK); + } + if (userSelect[idx].getStatus() == COMM_STATUS_REQDISCONNECT){ + Util::logExitReason("buffer requested shutdown"); + tcpCon.close(); + } + } + + bufferLivePacket(pkt.getTime() + packetOffset, pkt.getInt("offset"), idx, pktData, pktDataLen, 0, pkt.getFlag("keyframe")); }