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 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 11 | #include "call/rtx_receive_stream.h" |
| 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <string.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 14 | |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 15 | #include <utility> |
| 16 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 17 | #include "api/array_view.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "modules/rtp_rtcp/include/receive_statistics.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 19 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/rtp_rtcp/source/rtp_packet_received.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 21 | #include "rtc_base/checks.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "rtc_base/logging.h" |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 26 | RtxReceiveStream::RtxReceiveStream( |
| 27 | RtpPacketSinkInterface* media_sink, |
| 28 | std::map<int, int> associated_payload_types, |
| 29 | uint32_t media_ssrc, |
| 30 | ReceiveStatistics* rtp_receive_statistics /* = nullptr */) |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 31 | : media_sink_(media_sink), |
nisse | 3864499 | 2017-08-30 04:16:40 -0700 | [diff] [blame] | 32 | associated_payload_types_(std::move(associated_payload_types)), |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 33 | media_ssrc_(media_ssrc), |
| 34 | rtp_receive_statistics_(rtp_receive_statistics) { |
nisse | 3864499 | 2017-08-30 04:16:40 -0700 | [diff] [blame] | 35 | if (associated_payload_types_.empty()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 36 | RTC_LOG(LS_WARNING) |
nisse | 3864499 | 2017-08-30 04:16:40 -0700 | [diff] [blame] | 37 | << "RtxReceiveStream created with empty payload type mapping."; |
| 38 | } |
| 39 | } |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 40 | |
nisse | 76e62b0 | 2017-05-31 02:24:52 -0700 | [diff] [blame] | 41 | RtxReceiveStream::~RtxReceiveStream() = default; |
| 42 | |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 43 | void RtxReceiveStream::OnRtpPacket(const RtpPacketReceived& rtx_packet) { |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 44 | if (rtp_receive_statistics_) { |
Niels Möller | 1f3206c | 2018-09-14 08:26:32 +0200 | [diff] [blame] | 45 | rtp_receive_statistics_->OnRtpPacket(rtx_packet); |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 46 | } |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 47 | rtc::ArrayView<const uint8_t> payload = rtx_packet.payload(); |
| 48 | |
| 49 | if (payload.size() < kRtxHeaderSize) { |
| 50 | return; |
| 51 | } |
| 52 | |
nisse | 3864499 | 2017-08-30 04:16:40 -0700 | [diff] [blame] | 53 | auto it = associated_payload_types_.find(rtx_packet.PayloadType()); |
| 54 | if (it == associated_payload_types_.end()) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 55 | RTC_LOG(LS_VERBOSE) << "Unknown payload type " |
| 56 | << static_cast<int>(rtx_packet.PayloadType()) |
| 57 | << " on rtx ssrc " << rtx_packet.Ssrc(); |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 58 | return; |
| 59 | } |
| 60 | RtpPacketReceived media_packet; |
| 61 | media_packet.CopyHeaderFrom(rtx_packet); |
| 62 | |
| 63 | media_packet.SetSsrc(media_ssrc_); |
| 64 | media_packet.SetSequenceNumber((payload[0] << 8) + payload[1]); |
| 65 | media_packet.SetPayloadType(it->second); |
nisse | 3864499 | 2017-08-30 04:16:40 -0700 | [diff] [blame] | 66 | media_packet.set_recovered(true); |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 67 | |
| 68 | // Skip the RTX header. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 69 | rtc::ArrayView<const uint8_t> rtx_payload = payload.subview(kRtxHeaderSize); |
nisse | eed52bf | 2017-05-19 06:15:19 -0700 | [diff] [blame] | 70 | |
| 71 | uint8_t* media_payload = media_packet.AllocatePayload(rtx_payload.size()); |
| 72 | RTC_DCHECK(media_payload != nullptr); |
| 73 | |
| 74 | memcpy(media_payload, rtx_payload.data(), rtx_payload.size()); |
| 75 | |
| 76 | media_sink_->OnRtpPacket(media_packet); |
| 77 | } |
| 78 | |
| 79 | } // namespace webrtc |