nisse | 0f15f92 | 2017-06-21 01:05:22 -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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "call/rtp_stream_receiver_controller.h" |
eladalon | 5daecca | 2017-08-04 06:34:54 -0700 | [diff] [blame] | 12 | |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 13 | #include "absl/memory/memory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "rtc_base/logging.h" |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 15 | |
| 16 | namespace webrtc { |
| 17 | |
| 18 | RtpStreamReceiverController::Receiver::Receiver( |
| 19 | RtpStreamReceiverController* controller, |
| 20 | uint32_t ssrc, |
| 21 | RtpPacketSinkInterface* sink) |
| 22 | : controller_(controller), sink_(sink) { |
eladalon | 5daecca | 2017-08-04 06:34:54 -0700 | [diff] [blame] | 23 | const bool sink_added = controller_->AddSink(ssrc, sink_); |
| 24 | if (!sink_added) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 25 | RTC_LOG(LS_ERROR) |
| 26 | << "RtpStreamReceiverController::Receiver::Receiver: Sink " |
| 27 | << "could not be added for SSRC=" << ssrc << "."; |
eladalon | 5daecca | 2017-08-04 06:34:54 -0700 | [diff] [blame] | 28 | } |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | RtpStreamReceiverController::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 Anton | ed09dc6 | 2018-03-29 12:59:17 -0700 | [diff] [blame] | 38 | RtpStreamReceiverController::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 | |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 44 | RtpStreamReceiverController::~RtpStreamReceiverController() = default; |
| 45 | |
| 46 | std::unique_ptr<RtpStreamReceiverInterface> |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 47 | RtpStreamReceiverController::CreateReceiver(uint32_t ssrc, |
| 48 | RtpPacketSinkInterface* sink) { |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 49 | return absl::make_unique<Receiver>(this, ssrc, sink); |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | bool RtpStreamReceiverController::OnRtpPacket(const RtpPacketReceived& packet) { |
| 53 | rtc::CritScope cs(&lock_); |
| 54 | return demuxer_.OnRtpPacket(packet); |
| 55 | } |
| 56 | |
eladalon | 5daecca | 2017-08-04 06:34:54 -0700 | [diff] [blame] | 57 | bool RtpStreamReceiverController::AddSink(uint32_t ssrc, |
nisse | 0f15f92 | 2017-06-21 01:05:22 -0700 | [diff] [blame] | 58 | RtpPacketSinkInterface* sink) { |
| 59 | rtc::CritScope cs(&lock_); |
| 60 | return demuxer_.AddSink(ssrc, sink); |
| 61 | } |
| 62 | |
| 63 | size_t RtpStreamReceiverController::RemoveSink( |
| 64 | const RtpPacketSinkInterface* sink) { |
| 65 | rtc::CritScope cs(&lock_); |
| 66 | return demuxer_.RemoveSink(sink); |
| 67 | } |
| 68 | |
| 69 | } // namespace webrtc |