nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [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 | |
| 13 | #include "webrtc/call/rtx_receive_stream.h" |
| 14 | #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" |
nisse | 3864499 | 2017-08-30 04:16:40 -0700 | [diff] [blame] | 15 | #include "webrtc/rtc_base/logging.h" |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | |
nisse | 8e7eee0 | 2017-09-08 05:51:54 -0700 | [diff] [blame] | 19 | RtxReceiveStream::RtxReceiveStream(RtpPacketSinkInterface* media_sink, |
| 20 | std::map<int, int> associated_payload_types, |
| 21 | uint32_t media_ssrc) |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 22 | : media_sink_(media_sink), |
nisse | 3864499 | 2017-08-30 04:16:40 -0700 | [diff] [blame] | 23 | associated_payload_types_(std::move(associated_payload_types)), |
nisse | 8e7eee0 | 2017-09-08 05:51:54 -0700 | [diff] [blame] | 24 | media_ssrc_(media_ssrc) { |
nisse | 3864499 | 2017-08-30 04:16:40 -0700 | [diff] [blame] | 25 | if (associated_payload_types_.empty()) { |
| 26 | LOG(LS_WARNING) |
| 27 | << "RtxReceiveStream created with empty payload type mapping."; |
| 28 | } |
| 29 | } |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 30 | |
nisse | 76e62b0 | 2017-05-31 02:24:52 -0700 | [diff] [blame] | 31 | RtxReceiveStream::~RtxReceiveStream() = default; |
| 32 | |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 33 | void RtxReceiveStream::OnRtpPacket(const RtpPacketReceived& rtx_packet) { |
| 34 | rtc::ArrayView<const uint8_t> payload = rtx_packet.payload(); |
| 35 | |
| 36 | if (payload.size() < kRtxHeaderSize) { |
| 37 | return; |
| 38 | } |
| 39 | |
nisse | 3864499 | 2017-08-30 04:16:40 -0700 | [diff] [blame] | 40 | auto it = associated_payload_types_.find(rtx_packet.PayloadType()); |
| 41 | if (it == associated_payload_types_.end()) { |
| 42 | LOG(LS_VERBOSE) << "Unknown payload type " |
| 43 | << static_cast<int>(rtx_packet.PayloadType()) |
| 44 | << " on rtx ssrc " << rtx_packet.Ssrc(); |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 45 | return; |
| 46 | } |
| 47 | RtpPacketReceived media_packet; |
| 48 | media_packet.CopyHeaderFrom(rtx_packet); |
| 49 | |
| 50 | media_packet.SetSsrc(media_ssrc_); |
| 51 | media_packet.SetSequenceNumber((payload[0] << 8) + payload[1]); |
| 52 | media_packet.SetPayloadType(it->second); |
nisse | 3864499 | 2017-08-30 04:16:40 -0700 | [diff] [blame] | 53 | media_packet.set_recovered(true); |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 54 | |
| 55 | // Skip the RTX header. |
| 56 | rtc::ArrayView<const uint8_t> rtx_payload = |
| 57 | payload.subview(kRtxHeaderSize); |
| 58 | |
| 59 | uint8_t* media_payload = media_packet.AllocatePayload(rtx_payload.size()); |
| 60 | RTC_DCHECK(media_payload != nullptr); |
| 61 | |
| 62 | memcpy(media_payload, rtx_payload.data(), rtx_payload.size()); |
| 63 | |
| 64 | media_sink_->OnRtpPacket(media_packet); |
| 65 | } |
| 66 | |
| 67 | } // namespace webrtc |