blob: 993a4fc76e2f280cb703db8429e86b2173afe9b1 [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 Bonadei317a1f02019-09-17 17:06:18 +020013#include <memory>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "rtc_base/logging.h"
nisse0f15f922017-06-21 01:05:22 -070016
17namespace webrtc {
18
19RtpStreamReceiverController::Receiver::Receiver(
20 RtpStreamReceiverController* controller,
21 uint32_t ssrc,
22 RtpPacketSinkInterface* sink)
23 : controller_(controller), sink_(sink) {
eladalon5daecca2017-08-04 06:34:54 -070024 const bool sink_added = controller_->AddSink(ssrc, sink_);
25 if (!sink_added) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010026 RTC_LOG(LS_ERROR)
27 << "RtpStreamReceiverController::Receiver::Receiver: Sink "
Jonas Olssonb2b20312020-01-14 12:11:31 +010028 "could not be added for SSRC="
29 << ssrc << ".";
eladalon5daecca2017-08-04 06:34:54 -070030 }
nisse0f15f922017-06-21 01:05:22 -070031}
32
33RtpStreamReceiverController::Receiver::~Receiver() {
Niels Möller25e268a2022-07-06 10:02:23 +020034 // This may fail, if corresponding AddSink in the constructor failed.
nisse0f15f922017-06-21 01:05:22 -070035 controller_->RemoveSink(sink_);
36}
37
Tomas Gunnarssone091fd22021-01-17 16:14:52 +010038RtpStreamReceiverController::RtpStreamReceiverController() {}
Steve Antoned09dc62018-03-29 12:59:17 -070039
nisse0f15f922017-06-21 01:05:22 -070040RtpStreamReceiverController::~RtpStreamReceiverController() = default;
41
42std::unique_ptr<RtpStreamReceiverInterface>
Yves Gerey665174f2018-06-19 15:03:05 +020043RtpStreamReceiverController::CreateReceiver(uint32_t ssrc,
44 RtpPacketSinkInterface* sink) {
Mirko Bonadei317a1f02019-09-17 17:06:18 +020045 return std::make_unique<Receiver>(this, ssrc, sink);
nisse0f15f922017-06-21 01:05:22 -070046}
47
48bool RtpStreamReceiverController::OnRtpPacket(const RtpPacketReceived& packet) {
Tomas Gunnarssone091fd22021-01-17 16:14:52 +010049 RTC_DCHECK_RUN_ON(&demuxer_sequence_);
nisse0f15f922017-06-21 01:05:22 -070050 return demuxer_.OnRtpPacket(packet);
51}
52
Per K5e5d0172022-12-22 13:43:41 +010053void RtpStreamReceiverController::OnRecoveredPacket(
54 const RtpPacketReceived& packet) {
55 RTC_DCHECK_RUN_ON(&demuxer_sequence_);
56 demuxer_.OnRtpPacket(packet);
57}
58
eladalon5daecca2017-08-04 06:34:54 -070059bool RtpStreamReceiverController::AddSink(uint32_t ssrc,
nisse0f15f922017-06-21 01:05:22 -070060 RtpPacketSinkInterface* sink) {
Tomas Gunnarssone091fd22021-01-17 16:14:52 +010061 RTC_DCHECK_RUN_ON(&demuxer_sequence_);
nisse0f15f922017-06-21 01:05:22 -070062 return demuxer_.AddSink(ssrc, sink);
63}
64
Niels Möller25e268a2022-07-06 10:02:23 +020065bool RtpStreamReceiverController::RemoveSink(
nisse0f15f922017-06-21 01:05:22 -070066 const RtpPacketSinkInterface* sink) {
Tomas Gunnarssone091fd22021-01-17 16:14:52 +010067 RTC_DCHECK_RUN_ON(&demuxer_sequence_);
nisse0f15f922017-06-21 01:05:22 -070068 return demuxer_.RemoveSink(sink);
69}
70
71} // namespace webrtc