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 "call/rtp_stream_receiver_controller.h"
12
13 #include <memory>
14
15 #include "rtc_base/logging.h"
16
17 namespace webrtc {
18
Receiver(RtpStreamReceiverController * controller,uint32_t ssrc,RtpPacketSinkInterface * sink)19 RtpStreamReceiverController::Receiver::Receiver(
20 RtpStreamReceiverController* controller,
21 uint32_t ssrc,
22 RtpPacketSinkInterface* sink)
23 : controller_(controller), sink_(sink) {
24 const bool sink_added = controller_->AddSink(ssrc, sink_);
25 if (!sink_added) {
26 RTC_LOG(LS_ERROR)
27 << "RtpStreamReceiverController::Receiver::Receiver: Sink "
28 "could not be added for SSRC="
29 << ssrc << ".";
30 }
31 }
32
~Receiver()33 RtpStreamReceiverController::Receiver::~Receiver() {
34 // Don't require return value > 0, since for RTX we currently may
35 // have multiple Receiver objects with the same sink.
36 // TODO(nisse): Consider adding a DCHECK when RtxReceiveStream is wired up.
37 controller_->RemoveSink(sink_);
38 }
39
RtpStreamReceiverController()40 RtpStreamReceiverController::RtpStreamReceiverController() {
41 // At this level the demuxer is only configured to demux by SSRC, so don't
42 // worry about MIDs (MIDs are handled by upper layers).
43 demuxer_.set_use_mid(false);
44 }
45
46 RtpStreamReceiverController::~RtpStreamReceiverController() = default;
47
48 std::unique_ptr<RtpStreamReceiverInterface>
CreateReceiver(uint32_t ssrc,RtpPacketSinkInterface * sink)49 RtpStreamReceiverController::CreateReceiver(uint32_t ssrc,
50 RtpPacketSinkInterface* sink) {
51 return std::make_unique<Receiver>(this, ssrc, sink);
52 }
53
OnRtpPacket(const RtpPacketReceived & packet)54 bool RtpStreamReceiverController::OnRtpPacket(const RtpPacketReceived& packet) {
55 rtc::CritScope cs(&lock_);
56 return demuxer_.OnRtpPacket(packet);
57 }
58
AddSink(uint32_t ssrc,RtpPacketSinkInterface * sink)59 bool RtpStreamReceiverController::AddSink(uint32_t ssrc,
60 RtpPacketSinkInterface* sink) {
61 rtc::CritScope cs(&lock_);
62 return demuxer_.AddSink(ssrc, sink);
63 }
64
RemoveSink(const RtpPacketSinkInterface * sink)65 size_t RtpStreamReceiverController::RemoveSink(
66 const RtpPacketSinkInterface* sink) {
67 rtc::CritScope cs(&lock_);
68 return demuxer_.RemoveSink(sink);
69 }
70
71 } // namespace webrtc
72