blob: 9e4a41bc8f6a860a49aa604a2e8b96b23ba6b01c [file] [log] [blame]
nisseeed52bf2017-05-19 06:15:19 -07001/*
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 Olssona4d87372019-07-05 19:08:33 +020011#include "call/rtx_receive_stream.h"
12
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <string.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020014
nisseeed52bf2017-05-19 06:15:19 -070015#include <utility>
16
Yves Gerey3e707812018-11-28 16:47:49 +010017#include "api/array_view.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/rtp_rtcp/include/receive_statistics.h"
Yves Gerey3e707812018-11-28 16:47:49 +010019#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/rtp_rtcp/source/rtp_packet_received.h"
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "rtc_base/checks.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "rtc_base/logging.h"
nisseeed52bf2017-05-19 06:15:19 -070023
24namespace webrtc {
25
nisseca5706d2017-09-11 02:32:16 -070026RtxReceiveStream::RtxReceiveStream(
27 RtpPacketSinkInterface* media_sink,
28 std::map<int, int> associated_payload_types,
29 uint32_t media_ssrc,
30 ReceiveStatistics* rtp_receive_statistics /* = nullptr */)
nisseeed52bf2017-05-19 06:15:19 -070031 : media_sink_(media_sink),
nisse38644992017-08-30 04:16:40 -070032 associated_payload_types_(std::move(associated_payload_types)),
nisseca5706d2017-09-11 02:32:16 -070033 media_ssrc_(media_ssrc),
34 rtp_receive_statistics_(rtp_receive_statistics) {
nisse38644992017-08-30 04:16:40 -070035 if (associated_payload_types_.empty()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010036 RTC_LOG(LS_WARNING)
nisse38644992017-08-30 04:16:40 -070037 << "RtxReceiveStream created with empty payload type mapping.";
38 }
39}
nisseeed52bf2017-05-19 06:15:19 -070040
nisse76e62b02017-05-31 02:24:52 -070041RtxReceiveStream::~RtxReceiveStream() = default;
42
nisseeed52bf2017-05-19 06:15:19 -070043void RtxReceiveStream::OnRtpPacket(const RtpPacketReceived& rtx_packet) {
nisseca5706d2017-09-11 02:32:16 -070044 if (rtp_receive_statistics_) {
Niels Möller1f3206c2018-09-14 08:26:32 +020045 rtp_receive_statistics_->OnRtpPacket(rtx_packet);
nisseca5706d2017-09-11 02:32:16 -070046 }
nisseeed52bf2017-05-19 06:15:19 -070047 rtc::ArrayView<const uint8_t> payload = rtx_packet.payload();
48
49 if (payload.size() < kRtxHeaderSize) {
50 return;
51 }
52
nisse38644992017-08-30 04:16:40 -070053 auto it = associated_payload_types_.find(rtx_packet.PayloadType());
54 if (it == associated_payload_types_.end()) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010055 RTC_LOG(LS_VERBOSE) << "Unknown payload type "
56 << static_cast<int>(rtx_packet.PayloadType())
57 << " on rtx ssrc " << rtx_packet.Ssrc();
nisseeed52bf2017-05-19 06:15:19 -070058 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);
nisse38644992017-08-30 04:16:40 -070066 media_packet.set_recovered(true);
Per Kjellandere19a3752019-12-03 14:41:59 +010067 media_packet.set_arrival_time_ms(rtx_packet.arrival_time_ms());
nisseeed52bf2017-05-19 06:15:19 -070068
69 // Skip the RTX header.
Yves Gerey665174f2018-06-19 15:03:05 +020070 rtc::ArrayView<const uint8_t> rtx_payload = payload.subview(kRtxHeaderSize);
nisseeed52bf2017-05-19 06:15:19 -070071
72 uint8_t* media_payload = media_packet.AllocatePayload(rtx_payload.size());
73 RTC_DCHECK(media_payload != nullptr);
74
75 memcpy(media_payload, rtx_payload.data(), rtx_payload.size());
76
77 media_sink_->OnRtpPacket(media_packet);
78}
79
80} // namespace webrtc