blob: a5d73f5784f08f7654c6ad5233a9ad622e2ee526 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "rtc_base/logging.h"
14#include "rtc_base/ptr_util.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
38RtpStreamReceiverController::RtpStreamReceiverController() = default;
39RtpStreamReceiverController::~RtpStreamReceiverController() = default;
40
41std::unique_ptr<RtpStreamReceiverInterface>
42RtpStreamReceiverController::CreateReceiver(
43 uint32_t ssrc,
44 RtpPacketSinkInterface* sink) {
45 return rtc::MakeUnique<Receiver>(this, ssrc, sink);
46}
47
48bool RtpStreamReceiverController::OnRtpPacket(const RtpPacketReceived& packet) {
49 rtc::CritScope cs(&lock_);
50 return demuxer_.OnRtpPacket(packet);
51}
52
eladalon5daecca2017-08-04 06:34:54 -070053bool RtpStreamReceiverController::AddSink(uint32_t ssrc,
nisse0f15f922017-06-21 01:05:22 -070054 RtpPacketSinkInterface* sink) {
55 rtc::CritScope cs(&lock_);
56 return demuxer_.AddSink(ssrc, sink);
57}
58
59size_t RtpStreamReceiverController::RemoveSink(
60 const RtpPacketSinkInterface* sink) {
61 rtc::CritScope cs(&lock_);
62 return demuxer_.RemoveSink(sink);
63}
64
65} // namespace webrtc