blob: 16463525c729de224d6a1dfb9befe76d4617a25f [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
11#include <utility>
12
13#include "webrtc/call/rtx_receive_stream.h"
14#include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h"
nisse38644992017-08-30 04:16:40 -070015#include "webrtc/rtc_base/logging.h"
nisseeed52bf2017-05-19 06:15:19 -070016
17namespace webrtc {
18
nisse8e7eee02017-09-08 05:51:54 -070019RtxReceiveStream::RtxReceiveStream(RtpPacketSinkInterface* media_sink,
20 std::map<int, int> associated_payload_types,
21 uint32_t media_ssrc)
nisseeed52bf2017-05-19 06:15:19 -070022 : media_sink_(media_sink),
nisse38644992017-08-30 04:16:40 -070023 associated_payload_types_(std::move(associated_payload_types)),
nisse8e7eee02017-09-08 05:51:54 -070024 media_ssrc_(media_ssrc) {
nisse38644992017-08-30 04:16:40 -070025 if (associated_payload_types_.empty()) {
26 LOG(LS_WARNING)
27 << "RtxReceiveStream created with empty payload type mapping.";
28 }
29}
nisseeed52bf2017-05-19 06:15:19 -070030
nisse76e62b02017-05-31 02:24:52 -070031RtxReceiveStream::~RtxReceiveStream() = default;
32
nisseeed52bf2017-05-19 06:15:19 -070033void 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
nisse38644992017-08-30 04:16:40 -070040 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();
nisseeed52bf2017-05-19 06:15:19 -070045 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);
nisse38644992017-08-30 04:16:40 -070053 media_packet.set_recovered(true);
nisseeed52bf2017-05-19 06:15:19 -070054
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