Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 "pc/audio_rtp_receiver.h" |
| 12 | |
| 13 | #include <stddef.h> |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 14 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 15 | #include <string> |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 16 | #include <utility> |
| 17 | #include <vector> |
| 18 | |
Artem Titov | d15a575 | 2021-02-10 13:31:24 | [diff] [blame] | 19 | #include "api/sequence_checker.h" |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 20 | #include "pc/audio_track.h" |
Markus Handell | a1b8201 | 2021-05-26 16:56:30 | [diff] [blame] | 21 | #include "pc/media_stream_track_proxy.h" |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 22 | #include "rtc_base/checks.h" |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 26 | AudioRtpReceiver::AudioRtpReceiver( |
| 27 | rtc::Thread* worker_thread, |
| 28 | std::string receiver_id, |
| 29 | std::vector<std::string> stream_ids, |
| 30 | bool is_unified_plan, |
Harald Alvestrand | c0d44d9 | 2022-12-13 12:57:24 | [diff] [blame] | 31 | cricket::VoiceMediaReceiveChannelInterface* voice_channel /*= nullptr*/) |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 32 | : AudioRtpReceiver(worker_thread, |
| 33 | receiver_id, |
Henrik Boström | c335b0e | 2021-04-08 05:25:38 | [diff] [blame] | 34 | CreateStreamsFromIds(std::move(stream_ids)), |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 35 | is_unified_plan, |
| 36 | voice_channel) {} |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 37 | |
| 38 | AudioRtpReceiver::AudioRtpReceiver( |
| 39 | rtc::Thread* worker_thread, |
| 40 | const std::string& receiver_id, |
Henrik Boström | c335b0e | 2021-04-08 05:25:38 | [diff] [blame] | 41 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams, |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 42 | bool is_unified_plan, |
Harald Alvestrand | c0d44d9 | 2022-12-13 12:57:24 | [diff] [blame] | 43 | cricket::VoiceMediaReceiveChannelInterface* voice_channel /*= nullptr*/) |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 44 | : worker_thread_(worker_thread), |
| 45 | id_(receiver_id), |
Tommi | 87f7090 | 2021-04-27 12:43:08 | [diff] [blame] | 46 | source_(rtc::make_ref_counted<RemoteAudioSource>( |
Henrik Boström | c335b0e | 2021-04-08 05:25:38 | [diff] [blame] | 47 | worker_thread, |
| 48 | is_unified_plan |
| 49 | ? RemoteAudioSource::OnAudioChannelGoneAction::kSurvive |
| 50 | : RemoteAudioSource::OnAudioChannelGoneAction::kEnd)), |
Harald Alvestrand | 1ee3325 | 2020-09-24 13:31:15 | [diff] [blame] | 51 | track_(AudioTrackProxyWithInternal<AudioTrack>::Create( |
| 52 | rtc::Thread::Current(), |
| 53 | AudioTrack::Create(receiver_id, source_))), |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 54 | media_channel_(voice_channel), |
| 55 | cached_track_enabled_(track_->internal()->enabled()), |
Ruslan Burakov | 428dcb2 | 2019-04-18 15:49:49 | [diff] [blame] | 56 | attachment_id_(GenerateUniqueId()), |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 57 | worker_thread_safety_(PendingTaskSafetyFlag::CreateDetachedInactive()) { |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 58 | RTC_DCHECK(worker_thread_); |
| 59 | RTC_DCHECK(track_->GetSource()->remote()); |
| 60 | track_->RegisterObserver(this); |
| 61 | track_->GetSource()->RegisterAudioObserver(this); |
| 62 | SetStreams(streams); |
| 63 | } |
| 64 | |
| 65 | AudioRtpReceiver::~AudioRtpReceiver() { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 66 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 67 | RTC_DCHECK(!media_channel_); |
| 68 | |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 69 | track_->GetSource()->UnregisterAudioObserver(this); |
| 70 | track_->UnregisterObserver(this); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void AudioRtpReceiver::OnChanged() { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 74 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 75 | const bool enabled = track_->internal()->enabled(); |
| 76 | if (cached_track_enabled_ == enabled) |
| 77 | return; |
| 78 | cached_track_enabled_ = enabled; |
Danil Chapovalov | a30439b | 2022-07-07 08:08:49 | [diff] [blame] | 79 | worker_thread_->PostTask(SafeTask(worker_thread_safety_, [this, enabled]() { |
| 80 | RTC_DCHECK_RUN_ON(worker_thread_); |
| 81 | Reconfigure(enabled); |
| 82 | })); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 83 | } |
| 84 | |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 85 | void AudioRtpReceiver::SetOutputVolume_w(double volume) { |
Danil Chapovalov | 6e7c268 | 2022-07-25 13:58:28 | [diff] [blame] | 86 | RTC_DCHECK_RUN_ON(worker_thread_); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 87 | RTC_DCHECK_GE(volume, 0.0); |
| 88 | RTC_DCHECK_LE(volume, 10.0); |
Tommi | 20d8d91 | 2022-02-08 20:12:15 | [diff] [blame] | 89 | |
| 90 | if (!media_channel_) |
| 91 | return; |
| 92 | |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 93 | signaled_ssrc_ ? media_channel_->SetOutputVolume(*signaled_ssrc_, volume) |
| 94 | : media_channel_->SetDefaultOutputVolume(volume); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | void AudioRtpReceiver::OnSetVolume(double volume) { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 98 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 99 | RTC_DCHECK_GE(volume, 0); |
| 100 | RTC_DCHECK_LE(volume, 10); |
Tony Herre | f05f282 | 2021-11-22 18:10:19 | [diff] [blame] | 101 | |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 102 | bool track_enabled = track_->internal()->enabled(); |
Danil Chapovalov | 9e09a1f | 2022-09-08 16:38:10 | [diff] [blame] | 103 | worker_thread_->BlockingCall([&]() { |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 104 | RTC_DCHECK_RUN_ON(worker_thread_); |
| 105 | // Update the cached_volume_ even when stopped, to allow clients to set |
| 106 | // the volume before starting/restarting, eg see crbug.com/1272566. |
| 107 | cached_volume_ = volume; |
| 108 | // When the track is disabled, the volume of the source, which is the |
| 109 | // corresponding WebRtc Voice Engine channel will be 0. So we do not |
| 110 | // allow setting the volume to the source when the track is disabled. |
| 111 | if (track_enabled) |
| 112 | SetOutputVolume_w(volume); |
| 113 | }); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 114 | } |
| 115 | |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 116 | rtc::scoped_refptr<DtlsTransportInterface> AudioRtpReceiver::dtls_transport() |
| 117 | const { |
| 118 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
| 119 | return dtls_transport_; |
| 120 | } |
| 121 | |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 122 | std::vector<std::string> AudioRtpReceiver::stream_ids() const { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 123 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 124 | std::vector<std::string> stream_ids(streams_.size()); |
| 125 | for (size_t i = 0; i < streams_.size(); ++i) |
| 126 | stream_ids[i] = streams_[i]->id(); |
| 127 | return stream_ids; |
| 128 | } |
| 129 | |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 130 | std::vector<rtc::scoped_refptr<MediaStreamInterface>> |
| 131 | AudioRtpReceiver::streams() const { |
| 132 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
| 133 | return streams_; |
| 134 | } |
| 135 | |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 136 | RtpParameters AudioRtpReceiver::GetParameters() const { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 137 | RTC_DCHECK_RUN_ON(worker_thread_); |
| 138 | if (!media_channel_) |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 139 | return RtpParameters(); |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 140 | auto current_ssrc = ssrc(); |
| 141 | return current_ssrc.has_value() |
Philipp Hancke | 5866e1a | 2023-08-25 13:28:47 | [diff] [blame] | 142 | ? media_channel_->GetRtpReceiverParameters(current_ssrc.value()) |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 143 | : media_channel_->GetDefaultRtpReceiveParameters(); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 144 | } |
| 145 | |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 146 | void AudioRtpReceiver::SetFrameDecryptor( |
| 147 | rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor) { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 148 | RTC_DCHECK_RUN_ON(worker_thread_); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 149 | frame_decryptor_ = std::move(frame_decryptor); |
| 150 | // Special Case: Set the frame decryptor to any value on any existing channel. |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 151 | if (media_channel_ && signaled_ssrc_) { |
| 152 | media_channel_->SetFrameDecryptor(*signaled_ssrc_, frame_decryptor_); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 153 | } |
| 154 | } |
| 155 | |
| 156 | rtc::scoped_refptr<FrameDecryptorInterface> |
| 157 | AudioRtpReceiver::GetFrameDecryptor() const { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 158 | RTC_DCHECK_RUN_ON(worker_thread_); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 159 | return frame_decryptor_; |
| 160 | } |
| 161 | |
| 162 | void AudioRtpReceiver::Stop() { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 163 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
Tommi | 20d8d91 | 2022-02-08 20:12:15 | [diff] [blame] | 164 | source_->SetState(MediaSourceInterface::kEnded); |
Harald Alvestrand | 1ee3325 | 2020-09-24 13:31:15 | [diff] [blame] | 165 | track_->internal()->set_ended(); |
| 166 | } |
| 167 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 168 | void AudioRtpReceiver::RestartMediaChannel(std::optional<uint32_t> ssrc) { |
Danil Chapovalov | 6e7c268 | 2022-07-25 13:58:28 | [diff] [blame] | 169 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 170 | bool enabled = track_->internal()->enabled(); |
Tommi | 20d8d91 | 2022-02-08 20:12:15 | [diff] [blame] | 171 | MediaSourceInterface::SourceState state = source_->state(); |
Danil Chapovalov | 9e09a1f | 2022-09-08 16:38:10 | [diff] [blame] | 172 | worker_thread_->BlockingCall([&]() { |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 173 | RTC_DCHECK_RUN_ON(worker_thread_); |
| 174 | RestartMediaChannel_w(std::move(ssrc), enabled, state); |
| 175 | }); |
Tommi | 20d8d91 | 2022-02-08 20:12:15 | [diff] [blame] | 176 | source_->SetState(MediaSourceInterface::kLive); |
Saurav Das | 7262fc2 | 2019-09-11 23:23:05 | [diff] [blame] | 177 | } |
| 178 | |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 179 | void AudioRtpReceiver::RestartMediaChannel_w( |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 180 | std::optional<uint32_t> ssrc, |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 181 | bool track_enabled, |
| 182 | MediaSourceInterface::SourceState state) { |
Danil Chapovalov | 6e7c268 | 2022-07-25 13:58:28 | [diff] [blame] | 183 | RTC_DCHECK_RUN_ON(worker_thread_); |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 184 | if (!media_channel_) |
| 185 | return; // Can't restart. |
| 186 | |
Tommi | ed3832b | 2022-03-22 10:54:09 | [diff] [blame] | 187 | // Make sure the safety flag is marked as `alive` for cases where the media |
| 188 | // channel was provided via the ctor and not an explicit call to |
| 189 | // SetMediaChannel. |
| 190 | worker_thread_safety_->SetAlive(); |
| 191 | |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 192 | if (state != MediaSourceInterface::kInitializing) { |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 193 | if (signaled_ssrc_ == ssrc) |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 194 | return; |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 195 | source_->Stop(media_channel_, signaled_ssrc_); |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 196 | } |
| 197 | |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 198 | signaled_ssrc_ = std::move(ssrc); |
| 199 | source_->Start(media_channel_, signaled_ssrc_); |
| 200 | if (signaled_ssrc_) { |
| 201 | media_channel_->SetBaseMinimumPlayoutDelayMs(*signaled_ssrc_, |
| 202 | delay_.GetMs()); |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | Reconfigure(track_enabled); |
| 206 | } |
| 207 | |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 208 | void AudioRtpReceiver::SetupMediaChannel(uint32_t ssrc) { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 209 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
Saurav Das | 7262fc2 | 2019-09-11 23:23:05 | [diff] [blame] | 210 | RestartMediaChannel(ssrc); |
| 211 | } |
| 212 | |
| 213 | void AudioRtpReceiver::SetupUnsignaledMediaChannel() { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 214 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 215 | RestartMediaChannel(std::nullopt); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 216 | } |
| 217 | |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 218 | std::optional<uint32_t> AudioRtpReceiver::ssrc() const { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 219 | RTC_DCHECK_RUN_ON(worker_thread_); |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 220 | if (!signaled_ssrc_.has_value() && media_channel_) { |
Henrik Boström | 175f06f | 2023-01-05 07:53:16 | [diff] [blame] | 221 | return media_channel_->GetUnsignaledSsrc(); |
| 222 | } |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 223 | return signaled_ssrc_; |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 224 | } |
| 225 | |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 226 | void AudioRtpReceiver::set_stream_ids(std::vector<std::string> stream_ids) { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 227 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 228 | SetStreams(CreateStreamsFromIds(std::move(stream_ids))); |
| 229 | } |
| 230 | |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 231 | void AudioRtpReceiver::set_transport( |
| 232 | rtc::scoped_refptr<DtlsTransportInterface> dtls_transport) { |
| 233 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
| 234 | dtls_transport_ = std::move(dtls_transport); |
| 235 | } |
| 236 | |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 237 | void AudioRtpReceiver::SetStreams( |
| 238 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 239 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 240 | // Remove remote track from any streams that are going away. |
| 241 | for (const auto& existing_stream : streams_) { |
| 242 | bool removed = true; |
| 243 | for (const auto& stream : streams) { |
| 244 | if (existing_stream->id() == stream->id()) { |
| 245 | RTC_DCHECK_EQ(existing_stream.get(), stream.get()); |
| 246 | removed = false; |
| 247 | break; |
| 248 | } |
| 249 | } |
| 250 | if (removed) { |
Harald Alvestrand | 2f7ad28 | 2022-04-21 11:35:43 | [diff] [blame] | 251 | existing_stream->RemoveTrack(audio_track()); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | // Add remote track to any streams that are new. |
| 255 | for (const auto& stream : streams) { |
| 256 | bool added = true; |
| 257 | for (const auto& existing_stream : streams_) { |
| 258 | if (stream->id() == existing_stream->id()) { |
| 259 | RTC_DCHECK_EQ(stream.get(), existing_stream.get()); |
| 260 | added = false; |
| 261 | break; |
| 262 | } |
| 263 | } |
| 264 | if (added) { |
Harald Alvestrand | 2f7ad28 | 2022-04-21 11:35:43 | [diff] [blame] | 265 | stream->AddTrack(audio_track()); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | streams_ = streams; |
| 269 | } |
| 270 | |
| 271 | std::vector<RtpSource> AudioRtpReceiver::GetSources() const { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 272 | RTC_DCHECK_RUN_ON(worker_thread_); |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 273 | auto current_ssrc = ssrc(); |
| 274 | if (!media_channel_ || !current_ssrc.has_value()) { |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 275 | return {}; |
| 276 | } |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 277 | return media_channel_->GetSources(current_ssrc.value()); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 278 | } |
| 279 | |
Harald Alvestrand | b0e7057 | 2024-04-23 14:04:18 | [diff] [blame] | 280 | void AudioRtpReceiver::SetFrameTransformer( |
Harald Alvestrand | a654437 | 2023-11-13 09:33:56 | [diff] [blame] | 281 | rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 282 | RTC_DCHECK_RUN_ON(worker_thread_); |
| 283 | if (media_channel_) { |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 284 | media_channel_->SetDepacketizerToDecoderFrameTransformer( |
| 285 | signaled_ssrc_.value_or(0), frame_transformer); |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 286 | } |
| 287 | frame_transformer_ = std::move(frame_transformer); |
Marina Ciocea | 3e9af7f | 2020-04-01 05:46:16 | [diff] [blame] | 288 | } |
| 289 | |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 290 | void AudioRtpReceiver::Reconfigure(bool track_enabled) { |
Danil Chapovalov | 6e7c268 | 2022-07-25 13:58:28 | [diff] [blame] | 291 | RTC_DCHECK_RUN_ON(worker_thread_); |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 292 | RTC_DCHECK(media_channel_); |
Marina Ciocea | 3e9af7f | 2020-04-01 05:46:16 | [diff] [blame] | 293 | |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 294 | SetOutputVolume_w(track_enabled ? cached_volume_ : 0); |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 295 | |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 296 | if (signaled_ssrc_ && frame_decryptor_) { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 297 | // Reattach the frame decryptor if we were reconfigured. |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 298 | media_channel_->SetFrameDecryptor(*signaled_ssrc_, frame_decryptor_); |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | if (frame_transformer_) { |
| 302 | media_channel_->SetDepacketizerToDecoderFrameTransformer( |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 303 | signaled_ssrc_.value_or(0), frame_transformer_); |
Marina Ciocea | 3e9af7f | 2020-04-01 05:46:16 | [diff] [blame] | 304 | } |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | void AudioRtpReceiver::SetObserver(RtpReceiverObserverInterface* observer) { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 308 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 309 | observer_ = observer; |
| 310 | // Deliver any notifications the observer may have missed by being set late. |
| 311 | if (received_first_packet_ && observer_) { |
| 312 | observer_->OnFirstPacketReceived(media_type()); |
| 313 | } |
| 314 | } |
| 315 | |
Ruslan Burakov | 4bac79e | 2019-04-03 17:55:33 | [diff] [blame] | 316 | void AudioRtpReceiver::SetJitterBufferMinimumDelay( |
Florent Castelli | 8037fc6 | 2024-08-29 13:00:40 | [diff] [blame] | 317 | std::optional<double> delay_seconds) { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 318 | RTC_DCHECK_RUN_ON(worker_thread_); |
| 319 | delay_.Set(delay_seconds); |
Henrik Boström | 4df20ba | 2023-01-09 12:57:15 | [diff] [blame] | 320 | if (media_channel_ && signaled_ssrc_) |
| 321 | media_channel_->SetBaseMinimumPlayoutDelayMs(*signaled_ssrc_, |
| 322 | delay_.GetMs()); |
Ruslan Burakov | 4bac79e | 2019-04-03 17:55:33 | [diff] [blame] | 323 | } |
| 324 | |
Harald Alvestrand | 36fafc8 | 2022-12-08 08:47:42 | [diff] [blame] | 325 | void AudioRtpReceiver::SetMediaChannel( |
| 326 | cricket::MediaReceiveChannelInterface* media_channel) { |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 327 | RTC_DCHECK_RUN_ON(worker_thread_); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 328 | RTC_DCHECK(media_channel == nullptr || |
| 329 | media_channel->media_type() == media_type()); |
Tommi | 6589def | 2022-02-17 22:36:47 | [diff] [blame] | 330 | if (!media_channel && media_channel_) |
| 331 | SetOutputVolume_w(0.0); |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 332 | |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 333 | media_channel ? worker_thread_safety_->SetAlive() |
| 334 | : worker_thread_safety_->SetNotAlive(); |
Harald Alvestrand | c0d44d9 | 2022-12-13 12:57:24 | [diff] [blame] | 335 | media_channel_ = |
| 336 | static_cast<cricket::VoiceMediaReceiveChannelInterface*>(media_channel); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | void AudioRtpReceiver::NotifyFirstPacketReceived() { |
Tommi | 4ccdf932 | 2021-05-17 12:50:10 | [diff] [blame] | 340 | RTC_DCHECK_RUN_ON(&signaling_thread_checker_); |
Ruslan Burakov | 501bfba | 2019-02-11 09:29:19 | [diff] [blame] | 341 | if (observer_) { |
| 342 | observer_->OnFirstPacketReceived(media_type()); |
| 343 | } |
| 344 | received_first_packet_ = true; |
| 345 | } |
| 346 | |
| 347 | } // namespace webrtc |