nisse | eed52bf | 2017-05-19 13:15:19 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include <utility> |
| 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 13 | #include "call/rtx_receive_stream.h" |
| 14 | #include "modules/rtp_rtcp/include/receive_statistics.h" |
| 15 | #include "modules/rtp_rtcp/source/rtp_packet_received.h" |
| 16 | #include "rtc_base/logging.h" |
nisse | eed52bf | 2017-05-19 13:15:19 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
nisse | ca5706d | 2017-09-11 09:32:16 | [diff] [blame] | 20 | RtxReceiveStream::RtxReceiveStream( |
| 21 | RtpPacketSinkInterface* media_sink, |
| 22 | std::map<int, int> associated_payload_types, |
| 23 | uint32_t media_ssrc, |
| 24 | ReceiveStatistics* rtp_receive_statistics /* = nullptr */) |
nisse | eed52bf | 2017-05-19 13:15:19 | [diff] [blame] | 25 | : media_sink_(media_sink), |
nisse | 3864499 | 2017-08-30 11:16:40 | [diff] [blame] | 26 | associated_payload_types_(std::move(associated_payload_types)), |
nisse | ca5706d | 2017-09-11 09:32:16 | [diff] [blame] | 27 | media_ssrc_(media_ssrc), |
| 28 | rtp_receive_statistics_(rtp_receive_statistics) { |
nisse | 3864499 | 2017-08-30 11:16:40 | [diff] [blame] | 29 | if (associated_payload_types_.empty()) { |
| 30 | LOG(LS_WARNING) |
| 31 | << "RtxReceiveStream created with empty payload type mapping."; |
| 32 | } |
| 33 | } |
nisse | eed52bf | 2017-05-19 13:15:19 | [diff] [blame] | 34 | |
nisse | 76e62b0 | 2017-05-31 09:24:52 | [diff] [blame] | 35 | RtxReceiveStream::~RtxReceiveStream() = default; |
| 36 | |
nisse | eed52bf | 2017-05-19 13:15:19 | [diff] [blame] | 37 | void RtxReceiveStream::OnRtpPacket(const RtpPacketReceived& rtx_packet) { |
nisse | ca5706d | 2017-09-11 09:32:16 | [diff] [blame] | 38 | if (rtp_receive_statistics_) { |
| 39 | RTPHeader header; |
| 40 | rtx_packet.GetHeader(&header); |
| 41 | rtp_receive_statistics_->IncomingPacket(header, rtx_packet.size(), |
| 42 | false /* retransmitted */); |
| 43 | } |
nisse | eed52bf | 2017-05-19 13:15:19 | [diff] [blame] | 44 | rtc::ArrayView<const uint8_t> payload = rtx_packet.payload(); |
| 45 | |
| 46 | if (payload.size() < kRtxHeaderSize) { |
| 47 | return; |
| 48 | } |
| 49 | |
nisse | 3864499 | 2017-08-30 11:16:40 | [diff] [blame] | 50 | auto it = associated_payload_types_.find(rtx_packet.PayloadType()); |
| 51 | if (it == associated_payload_types_.end()) { |
| 52 | LOG(LS_VERBOSE) << "Unknown payload type " |
| 53 | << static_cast<int>(rtx_packet.PayloadType()) |
| 54 | << " on rtx ssrc " << rtx_packet.Ssrc(); |
nisse | eed52bf | 2017-05-19 13:15:19 | [diff] [blame] | 55 | return; |
| 56 | } |
| 57 | RtpPacketReceived media_packet; |
| 58 | media_packet.CopyHeaderFrom(rtx_packet); |
| 59 | |
| 60 | media_packet.SetSsrc(media_ssrc_); |
| 61 | media_packet.SetSequenceNumber((payload[0] << 8) + payload[1]); |
| 62 | media_packet.SetPayloadType(it->second); |
nisse | 3864499 | 2017-08-30 11:16:40 | [diff] [blame] | 63 | media_packet.set_recovered(true); |
nisse | eed52bf | 2017-05-19 13:15:19 | [diff] [blame] | 64 | |
| 65 | // Skip the RTX header. |
| 66 | rtc::ArrayView<const uint8_t> rtx_payload = |
| 67 | payload.subview(kRtxHeaderSize); |
| 68 | |
| 69 | uint8_t* media_payload = media_packet.AllocatePayload(rtx_payload.size()); |
| 70 | RTC_DCHECK(media_payload != nullptr); |
| 71 | |
| 72 | memcpy(media_payload, rtx_payload.data(), rtx_payload.size()); |
| 73 | |
| 74 | media_sink_->OnRtpPacket(media_packet); |
| 75 | } |
| 76 | |
| 77 | } // namespace webrtc |