blob: 3fae021188b3c863bfad80770c33125e7e32ee44 [file] [log] [blame]
nisse0f15f922017-06-21 01:05:22 -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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "call/rtp_stream_receiver_controller.h"
eladalon5daecca2017-08-04 06:34:54 -070012
Karl Wiberg918f50c2018-07-05 11:40:33 +020013#include "absl/memory/memory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "rtc_base/logging.h"
nisse0f15f922017-06-21 01:05:22 -070015
16namespace webrtc {
17
18RtpStreamReceiverController::Receiver::Receiver(
19 RtpStreamReceiverController* controller,
20 uint32_t ssrc,
21 RtpPacketSinkInterface* sink)
22 : controller_(controller), sink_(sink) {
eladalon5daecca2017-08-04 06:34:54 -070023 const bool sink_added = controller_->AddSink(ssrc, sink_);
24 if (!sink_added) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010025 RTC_LOG(LS_ERROR)
26 << "RtpStreamReceiverController::Receiver::Receiver: Sink "
27 << "could not be added for SSRC=" << ssrc << ".";
eladalon5daecca2017-08-04 06:34:54 -070028 }
nisse0f15f922017-06-21 01:05:22 -070029}
30
31RtpStreamReceiverController::Receiver::~Receiver() {
32 // Don't require return value > 0, since for RTX we currently may
33 // have multiple Receiver objects with the same sink.
34 // TODO(nisse): Consider adding a DCHECK when RtxReceiveStream is wired up.
35 controller_->RemoveSink(sink_);
36}
37
Steve Antoned09dc62018-03-29 12:59:17 -070038RtpStreamReceiverController::RtpStreamReceiverController() {
39 // At this level the demuxer is only configured to demux by SSRC, so don't
40 // worry about MIDs (MIDs are handled by upper layers).
41 demuxer_.set_use_mid(false);
42}
43
nisse0f15f922017-06-21 01:05:22 -070044RtpStreamReceiverController::~RtpStreamReceiverController() = default;
45
46std::unique_ptr<RtpStreamReceiverInterface>
Yves Gerey665174f2018-06-19 15:03:05 +020047RtpStreamReceiverController::CreateReceiver(uint32_t ssrc,
48 RtpPacketSinkInterface* sink) {
Karl Wiberg918f50c2018-07-05 11:40:33 +020049 return absl::make_unique<Receiver>(this, ssrc, sink);
nisse0f15f922017-06-21 01:05:22 -070050}
51
52bool RtpStreamReceiverController::OnRtpPacket(const RtpPacketReceived& packet) {
53 rtc::CritScope cs(&lock_);
54 return demuxer_.OnRtpPacket(packet);
55}
56
eladalon5daecca2017-08-04 06:34:54 -070057bool RtpStreamReceiverController::AddSink(uint32_t ssrc,
nisse0f15f922017-06-21 01:05:22 -070058 RtpPacketSinkInterface* sink) {
59 rtc::CritScope cs(&lock_);
60 return demuxer_.AddSink(ssrc, sink);
61}
62
63size_t RtpStreamReceiverController::RemoveSink(
64 const RtpPacketSinkInterface* sink) {
65 rtc::CritScope cs(&lock_);
66 return demuxer_.RemoveSink(sink);
67}
68
69} // namespace webrtc