|
| 1 | +From 86caa772245508b11bc038006df5a8867dda2fc9 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Chen Li1 < [email protected]> |
| 3 | +Date: Fri, 16 Oct 2020 10:22:37 +0800 |
| 4 | +Subject: [PATCH] Add Rtp demuxer |
| 5 | + |
| 6 | +--- |
| 7 | + erizo/src/erizo/LibNiceConnection.cpp | 2 +- |
| 8 | + erizo/src/erizo/WebRtcConnection.cpp | 34 ++++++++++++++++++++------- |
| 9 | + erizo/src/erizo/WebRtcConnection.h | 2 ++ |
| 10 | + erizo/src/erizo/rtp/RtpExtensionProcessor.cpp | 30 +++++++++++++++++++++++ |
| 11 | + erizo/src/erizo/rtp/RtpExtensionProcessor.h | 9 +++++++ |
| 12 | + 5 files changed, 67 insertions(+), 10 deletions(-) |
| 13 | + |
| 14 | +diff --git a/erizo/src/erizo/LibNiceConnection.cpp b/erizo/src/erizo/LibNiceConnection.cpp |
| 15 | +index 3c4d777..bc38c22 100644 |
| 16 | +--- a/erizo/src/erizo/LibNiceConnection.cpp |
| 17 | ++++ b/erizo/src/erizo/LibNiceConnection.cpp |
| 18 | +@@ -407,7 +407,7 @@ void LibNiceConnection::updateComponentState(unsigned int component_id, IceState |
| 19 | + } |
| 20 | + } |
| 21 | + } else if (state == IceState::FAILED) { |
| 22 | +- if (receivedLastCandidate_) { |
| 23 | ++ if (receivedLastCandidate_ || this->checkIceState() == IceState::READY) { |
| 24 | + ELOG_WARN("%s message: component failed, ice_config_.transport_name: %s, componentId: %u", |
| 25 | + toLog(), ice_config_.transport_name.c_str(), component_id); |
| 26 | + for (unsigned int i = 1; i <= ice_config_.ice_components; i++) { |
| 27 | +diff --git a/erizo/src/erizo/WebRtcConnection.cpp b/erizo/src/erizo/WebRtcConnection.cpp |
| 28 | +index 6eee9a8..5ff5156 100644 |
| 29 | +--- a/erizo/src/erizo/WebRtcConnection.cpp |
| 30 | ++++ b/erizo/src/erizo/WebRtcConnection.cpp |
| 31 | +@@ -310,6 +310,11 @@ bool WebRtcConnection::processRemoteSdp(std::string stream_id) { |
| 32 | + // update remote_sdp_'s ssrc map |
| 33 | + remote_sdp_->audio_ssrc_map = local_sdp_->audio_ssrc_map; |
| 34 | + remote_sdp_->video_ssrc_map = local_sdp_->video_ssrc_map; |
| 35 | ++ // Update extensions |
| 36 | ++ local_sdp_->setOfferSdp(remote_sdp_); |
| 37 | ++ extension_processor_.setSdpInfo(local_sdp_); |
| 38 | ++ local_sdp_->updateSupportedExtensionMap(extension_processor_.getSupportedExtensionMap()); |
| 39 | ++ |
| 40 | + |
| 41 | + if (first_remote_sdp_processed_) { |
| 42 | + setRemoteSdpsToMediaStreams(stream_id); |
| 43 | +@@ -317,9 +322,6 @@ bool WebRtcConnection::processRemoteSdp(std::string stream_id) { |
| 44 | + } |
| 45 | + |
| 46 | + bundle_ = remote_sdp_->isBundle; |
| 47 | +- local_sdp_->setOfferSdp(remote_sdp_); |
| 48 | +- extension_processor_.setSdpInfo(local_sdp_); |
| 49 | +- local_sdp_->updateSupportedExtensionMap(extension_processor_.getSupportedExtensionMap()); |
| 50 | + |
| 51 | + if (remote_sdp_->dtlsRole == ACTPASS) { |
| 52 | + local_sdp_->dtlsRole = ACTIVE; |
| 53 | +@@ -574,12 +576,26 @@ void WebRtcConnection::onTransportData(std::shared_ptr<DataPacket> packet, Trans |
| 54 | + } else { |
| 55 | + RtpHeader *head = reinterpret_cast<RtpHeader*> (buf); |
| 56 | + uint32_t ssrc = head->getSSRC(); |
| 57 | +- auto ridSsrc = this->extension_processor_.checkNewRid(packet); |
| 58 | +- if (!ridSsrc.first.empty()) { |
| 59 | +- // find a new rid |
| 60 | +- ELOG_DEBUG("%s message: Discovered New RID: %s, SSRC: %u", |
| 61 | +- toLog(), ridSsrc.first.c_str(), ridSsrc.second); |
| 62 | +- maybeNotifyWebRtcConnectionEvent(global_state_, std::to_string(ridSsrc.second), ridSsrc.first); |
| 63 | ++ this->extension_processor_.processRtpExtensions(packet); |
| 64 | ++ std::string mid = this->extension_processor_.lastMid(); |
| 65 | ++ std::string rid = this->extension_processor_.lastRid(); |
| 66 | ++ if (!mid.empty()) { |
| 67 | ++ std::string streamId = mid; |
| 68 | ++ if (!rid.empty()) { |
| 69 | ++ // Compose ID as js layer |
| 70 | ++ streamId = mid + ":" + rid; |
| 71 | ++ } |
| 72 | ++ |
| 73 | ++ if (mapping_ssrcs_.count(streamId) == 0) { |
| 74 | ++ // Set SSRC for mid/rsid |
| 75 | ++ forEachMediaStream([this, streamId, ssrc] (const std::shared_ptr<MediaStream> &media_stream) { |
| 76 | ++ if (media_stream->getId() == streamId) { |
| 77 | ++ media_stream->setVideoSourceSSRC(ssrc); |
| 78 | ++ media_stream->setVideoSourceSSRC(ssrc); |
| 79 | ++ mapping_ssrcs_[streamId] = ssrc; |
| 80 | ++ } |
| 81 | ++ }); |
| 82 | ++ } |
| 83 | + } |
| 84 | + forEachMediaStream([packet, transport, ssrc] (const std::shared_ptr<MediaStream> &media_stream) { |
| 85 | + if (media_stream->isSourceSSRC(ssrc) || media_stream->isSinkSSRC(ssrc)) { |
| 86 | +diff --git a/erizo/src/erizo/WebRtcConnection.h b/erizo/src/erizo/WebRtcConnection.h |
| 87 | +index 56e0bbb..4a9fa44 100644 |
| 88 | +--- a/erizo/src/erizo/WebRtcConnection.h |
| 89 | ++++ b/erizo/src/erizo/WebRtcConnection.h |
| 90 | +@@ -202,6 +202,8 @@ class WebRtcConnection: public TransportListener, public LogContext, |
| 91 | + bool first_remote_sdp_processed_; |
| 92 | + |
| 93 | + std::unique_ptr<BandwidthDistributionAlgorithm> distributor_; |
| 94 | ++ |
| 95 | ++ std::map<std::string, uint32_t> mapping_ssrcs_; |
| 96 | + }; |
| 97 | + |
| 98 | + } // namespace erizo |
| 99 | +diff --git a/erizo/src/erizo/rtp/RtpExtensionProcessor.cpp b/erizo/src/erizo/rtp/RtpExtensionProcessor.cpp |
| 100 | +index 6ea37e8..6e1ae73 100644 |
| 101 | +--- a/erizo/src/erizo/rtp/RtpExtensionProcessor.cpp |
| 102 | ++++ b/erizo/src/erizo/rtp/RtpExtensionProcessor.cpp |
| 103 | +@@ -19,6 +19,7 @@ RtpExtensionProcessor::RtpExtensionProcessor(const std::vector<erizo::ExtMap> ex |
| 104 | + translationMap_["urn:3gpp:video-orientation"] = VIDEO_ORIENTATION; |
| 105 | + translationMap_["http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"] = TRANSPORT_CC; |
| 106 | + translationMap_["http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"]= PLAYBACK_TIME; |
| 107 | ++ translationMap_["urn:ietf:params:rtp-hdrext:sdes:mid"]= MEDIA_ID; |
| 108 | + translationMap_["urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id"]= RTP_ID; |
| 109 | + translationMap_["urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"]= REPARIED_RTP_ID; |
| 110 | + ext_map_video_.fill(UNKNOWN); |
| 111 | +@@ -126,6 +127,9 @@ uint32_t RtpExtensionProcessor::processRtpExtensions(std::shared_ptr<DataPacket> |
| 112 | + const RtpHeader* head = reinterpret_cast<const RtpHeader*>(p->data); |
| 113 | + uint32_t len = p->length; |
| 114 | + std::array<RTPExtensions, kRtpExtSize> extMap; |
| 115 | ++ |
| 116 | ++ last_mid_.clear(); |
| 117 | ++ last_rid_.clear(); |
| 118 | + if (head->getExtension()) { |
| 119 | + switch (p->type) { |
| 120 | + case VIDEO_PACKET: |
| 121 | +@@ -158,6 +162,12 @@ uint32_t RtpExtensionProcessor::processRtpExtensions(std::shared_ptr<DataPacket> |
| 122 | + case VIDEO_ORIENTATION: |
| 123 | + processVideoOrientation(extBuffer); |
| 124 | + break; |
| 125 | ++ case MEDIA_ID: |
| 126 | ++ processMid(extBuffer); |
| 127 | ++ break; |
| 128 | ++ case RTP_ID: |
| 129 | ++ processRid(extBuffer); |
| 130 | ++ break; |
| 131 | + default: |
| 132 | + break; |
| 133 | + } |
| 134 | +@@ -196,6 +206,26 @@ uint32_t RtpExtensionProcessor::processAbsSendTime(char* buf) { |
| 135 | + return 0; |
| 136 | + } |
| 137 | + |
| 138 | ++uint32_t RtpExtensionProcessor::processMid(char* extBuffer) { |
| 139 | ++ uint8_t extByte = (uint8_t)(*extBuffer); |
| 140 | ++ uint8_t extLength = extByte & 0x0F; |
| 141 | ++ last_mid_.clear(); |
| 142 | ++ for (uint8_t i = 1; i <= extLength + 1; i++) { |
| 143 | ++ last_mid_.push_back(*(extBuffer + i)); |
| 144 | ++ } |
| 145 | ++ return 0; |
| 146 | ++} |
| 147 | ++ |
| 148 | ++uint32_t RtpExtensionProcessor::processRid(char* extBuffer) { |
| 149 | ++ uint8_t extByte = (uint8_t)(*extBuffer); |
| 150 | ++ uint8_t extLength = extByte & 0x0F; |
| 151 | ++ last_rid_.clear(); |
| 152 | ++ for (uint8_t i = 1; i <= extLength + 1; i++) { |
| 153 | ++ last_rid_.push_back(*(extBuffer + i)); |
| 154 | ++ } |
| 155 | ++ return 0; |
| 156 | ++} |
| 157 | ++ |
| 158 | + uint32_t RtpExtensionProcessor::stripExtension(char* buf, int len) { |
| 159 | + // TODO(pedro) |
| 160 | + return len; |
| 161 | +diff --git a/erizo/src/erizo/rtp/RtpExtensionProcessor.h b/erizo/src/erizo/rtp/RtpExtensionProcessor.h |
| 162 | +index 1da8095..c7ab23b 100644 |
| 163 | +--- a/erizo/src/erizo/rtp/RtpExtensionProcessor.h |
| 164 | ++++ b/erizo/src/erizo/rtp/RtpExtensionProcessor.h |
| 165 | +@@ -20,6 +20,7 @@ enum RTPExtensions { |
| 166 | + VIDEO_ORIENTATION, // urn:3gpp:video-orientation |
| 167 | + TRANSPORT_CC, // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 |
| 168 | + PLAYBACK_TIME, // http:// www.webrtc.org/experiments/rtp-hdrext/playout-delay |
| 169 | ++ MEDIA_ID, // urn:ietf:params:rtp-hdrext:sdes:mid |
| 170 | + RTP_ID, // urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id |
| 171 | + REPARIED_RTP_ID // urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id |
| 172 | + }; |
| 173 | +@@ -50,14 +51,22 @@ class RtpExtensionProcessor{ |
| 174 | + } |
| 175 | + bool isValidExtension(std::string uri); |
| 176 | + |
| 177 | ++ std::string lastMid() { return last_mid_; } |
| 178 | ++ std::string lastRid() { return last_rid_; } |
| 179 | ++ |
| 180 | + private: |
| 181 | + std::vector<ExtMap> ext_mappings_; |
| 182 | + std::array<RTPExtensions, kRtpExtSize> ext_map_video_, ext_map_audio_; |
| 183 | + std::map<std::string, uint8_t> translationMap_; |
| 184 | + VideoRotation video_orientation_; |
| 185 | + std::map<std::string, uint32_t> rids_; |
| 186 | ++ std::string last_mid_; |
| 187 | ++ std::string last_rid_; |
| 188 | ++ |
| 189 | + uint32_t processAbsSendTime(char* buf); |
| 190 | + uint32_t processVideoOrientation(char* buf); |
| 191 | ++ uint32_t processMid(char* buf); |
| 192 | ++ uint32_t processRid(char* buf); |
| 193 | + uint32_t stripExtension(char* buf, int len); |
| 194 | + }; |
| 195 | + |
| 196 | +-- |
| 197 | +2.7.4 |
| 198 | + |
0 commit comments