2019-02-11 10:29:19 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright 2019 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "pc/audio_rtp_receiver.h"
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2022-02-23 13:44:59 +00:00
|
|
|
#include <string>
|
2019-02-11 10:29:19 +01:00
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2021-02-10 14:31:24 +01:00
|
|
|
#include "api/sequence_checker.h"
|
2019-02-11 10:29:19 +01:00
|
|
|
#include "pc/audio_track.h"
|
2021-05-26 18:56:30 +02:00
|
|
|
#include "pc/media_stream_track_proxy.h"
|
2019-02-11 10:29:19 +01:00
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "rtc_base/location.h"
|
2022-02-23 13:44:59 +00:00
|
|
|
#include "rtc_base/ref_counted_object.h"
|
2021-05-17 14:50:10 +02:00
|
|
|
#include "rtc_base/task_utils/to_queued_task.h"
|
2019-02-11 10:29:19 +01:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2022-02-17 23:36:47 +01:00
|
|
|
AudioRtpReceiver::AudioRtpReceiver(
|
|
|
|
|
rtc::Thread* worker_thread,
|
|
|
|
|
std::string receiver_id,
|
|
|
|
|
std::vector<std::string> stream_ids,
|
|
|
|
|
bool is_unified_plan,
|
|
|
|
|
cricket::VoiceMediaChannel* voice_channel /*= nullptr*/)
|
2019-02-11 10:29:19 +01:00
|
|
|
: AudioRtpReceiver(worker_thread,
|
|
|
|
|
receiver_id,
|
[Unified Plan] Don't end audio tracks when SSRC changes.
The RemoteAudioSource has an AudioDataProxy that acts as a sink, passing
along data from AudioRecvStreams to the RemoteAudioSource. If an SSRC is
changed (or other reconfiguration happens) with SDP, the recv stream and
proxy get recreated.
In Plan B, because remote tracks maps 1:1 with SSRCs, it made sense to
end remote track/audio source in response to this. In Plan B, a new
receiver, with a new track and a new proxy would be created for the new
SSRC.
In Unified Plan however, remote tracks correspond to m= sections. The
remote track should only end on port:0 (or RTCP BYE or timeout, etc),
not because the recv stream of an m= section is recreated. The code
already supports changing SSRC and this is working correctly, but
because ~AudioDataProxy() would end the source this would cause the
MediaStreamTrack of the receiver to end (even though the media engine
is still processing the remote audio stream correctly under the hood).
This issue only happened on audio tracks, and because of timing of
PostTasks the track would kEnd in Chromium *after* promise.then().
This CL fixes that issue by not ending the source when the proxy is
destroyed. Destroying a recv stream is a temporary action in Unified
Plan, unless stopped. Tests are added ensuring tracks are kLive.
I have manually verified that this CL fixes the issue and that both
audio and video is flowing through the entire pipeline:
https://jsfiddle.net/henbos/h21xec97/122/
Bug: chromium:1121454
Change-Id: Ic21ac8ea263ccf021b96a14d3e4e3b24eb756c86
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214136
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33645}
2021-04-08 07:25:38 +02:00
|
|
|
CreateStreamsFromIds(std::move(stream_ids)),
|
2022-02-17 23:36:47 +01:00
|
|
|
is_unified_plan,
|
|
|
|
|
voice_channel) {}
|
2019-02-11 10:29:19 +01:00
|
|
|
|
|
|
|
|
AudioRtpReceiver::AudioRtpReceiver(
|
|
|
|
|
rtc::Thread* worker_thread,
|
|
|
|
|
const std::string& receiver_id,
|
[Unified Plan] Don't end audio tracks when SSRC changes.
The RemoteAudioSource has an AudioDataProxy that acts as a sink, passing
along data from AudioRecvStreams to the RemoteAudioSource. If an SSRC is
changed (or other reconfiguration happens) with SDP, the recv stream and
proxy get recreated.
In Plan B, because remote tracks maps 1:1 with SSRCs, it made sense to
end remote track/audio source in response to this. In Plan B, a new
receiver, with a new track and a new proxy would be created for the new
SSRC.
In Unified Plan however, remote tracks correspond to m= sections. The
remote track should only end on port:0 (or RTCP BYE or timeout, etc),
not because the recv stream of an m= section is recreated. The code
already supports changing SSRC and this is working correctly, but
because ~AudioDataProxy() would end the source this would cause the
MediaStreamTrack of the receiver to end (even though the media engine
is still processing the remote audio stream correctly under the hood).
This issue only happened on audio tracks, and because of timing of
PostTasks the track would kEnd in Chromium *after* promise.then().
This CL fixes that issue by not ending the source when the proxy is
destroyed. Destroying a recv stream is a temporary action in Unified
Plan, unless stopped. Tests are added ensuring tracks are kLive.
I have manually verified that this CL fixes the issue and that both
audio and video is flowing through the entire pipeline:
https://jsfiddle.net/henbos/h21xec97/122/
Bug: chromium:1121454
Change-Id: Ic21ac8ea263ccf021b96a14d3e4e3b24eb756c86
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214136
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33645}
2021-04-08 07:25:38 +02:00
|
|
|
const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams,
|
2022-02-17 23:36:47 +01:00
|
|
|
bool is_unified_plan,
|
|
|
|
|
cricket::VoiceMediaChannel* voice_channel /*= nullptr*/)
|
2019-02-11 10:29:19 +01:00
|
|
|
: worker_thread_(worker_thread),
|
|
|
|
|
id_(receiver_id),
|
2021-04-27 14:43:08 +02:00
|
|
|
source_(rtc::make_ref_counted<RemoteAudioSource>(
|
[Unified Plan] Don't end audio tracks when SSRC changes.
The RemoteAudioSource has an AudioDataProxy that acts as a sink, passing
along data from AudioRecvStreams to the RemoteAudioSource. If an SSRC is
changed (or other reconfiguration happens) with SDP, the recv stream and
proxy get recreated.
In Plan B, because remote tracks maps 1:1 with SSRCs, it made sense to
end remote track/audio source in response to this. In Plan B, a new
receiver, with a new track and a new proxy would be created for the new
SSRC.
In Unified Plan however, remote tracks correspond to m= sections. The
remote track should only end on port:0 (or RTCP BYE or timeout, etc),
not because the recv stream of an m= section is recreated. The code
already supports changing SSRC and this is working correctly, but
because ~AudioDataProxy() would end the source this would cause the
MediaStreamTrack of the receiver to end (even though the media engine
is still processing the remote audio stream correctly under the hood).
This issue only happened on audio tracks, and because of timing of
PostTasks the track would kEnd in Chromium *after* promise.then().
This CL fixes that issue by not ending the source when the proxy is
destroyed. Destroying a recv stream is a temporary action in Unified
Plan, unless stopped. Tests are added ensuring tracks are kLive.
I have manually verified that this CL fixes the issue and that both
audio and video is flowing through the entire pipeline:
https://jsfiddle.net/henbos/h21xec97/122/
Bug: chromium:1121454
Change-Id: Ic21ac8ea263ccf021b96a14d3e4e3b24eb756c86
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/214136
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#33645}
2021-04-08 07:25:38 +02:00
|
|
|
worker_thread,
|
|
|
|
|
is_unified_plan
|
|
|
|
|
? RemoteAudioSource::OnAudioChannelGoneAction::kSurvive
|
|
|
|
|
: RemoteAudioSource::OnAudioChannelGoneAction::kEnd)),
|
2020-09-24 13:31:15 +00:00
|
|
|
track_(AudioTrackProxyWithInternal<AudioTrack>::Create(
|
|
|
|
|
rtc::Thread::Current(),
|
|
|
|
|
AudioTrack::Create(receiver_id, source_))),
|
2022-02-17 23:36:47 +01:00
|
|
|
media_channel_(voice_channel),
|
|
|
|
|
cached_track_enabled_(track_->internal()->enabled()),
|
2019-04-18 17:49:49 +02:00
|
|
|
attachment_id_(GenerateUniqueId()),
|
2021-05-17 14:50:10 +02:00
|
|
|
worker_thread_safety_(PendingTaskSafetyFlag::CreateDetachedInactive()) {
|
2019-02-11 10:29:19 +01:00
|
|
|
RTC_DCHECK(worker_thread_);
|
|
|
|
|
RTC_DCHECK(track_->GetSource()->remote());
|
|
|
|
|
track_->RegisterObserver(this);
|
|
|
|
|
track_->GetSource()->RegisterAudioObserver(this);
|
|
|
|
|
SetStreams(streams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AudioRtpReceiver::~AudioRtpReceiver() {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
|
|
|
|
RTC_DCHECK(!media_channel_);
|
|
|
|
|
|
2019-02-11 10:29:19 +01:00
|
|
|
track_->GetSource()->UnregisterAudioObserver(this);
|
|
|
|
|
track_->UnregisterObserver(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioRtpReceiver::OnChanged() {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
2022-02-17 23:36:47 +01:00
|
|
|
const bool enabled = track_->internal()->enabled();
|
|
|
|
|
if (cached_track_enabled_ == enabled)
|
|
|
|
|
return;
|
|
|
|
|
cached_track_enabled_ = enabled;
|
|
|
|
|
worker_thread_->PostTask(
|
|
|
|
|
ToQueuedTask(worker_thread_safety_, [this, enabled]() {
|
|
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
Reconfigure(enabled);
|
|
|
|
|
}));
|
2019-02-11 10:29:19 +01:00
|
|
|
}
|
|
|
|
|
|
2021-05-17 14:50:10 +02:00
|
|
|
// RTC_RUN_ON(worker_thread_)
|
|
|
|
|
void AudioRtpReceiver::SetOutputVolume_w(double volume) {
|
2019-02-11 10:29:19 +01:00
|
|
|
RTC_DCHECK_GE(volume, 0.0);
|
|
|
|
|
RTC_DCHECK_LE(volume, 10.0);
|
2022-02-08 21:12:15 +01:00
|
|
|
|
|
|
|
|
if (!media_channel_)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-05-17 14:50:10 +02:00
|
|
|
ssrc_ ? media_channel_->SetOutputVolume(*ssrc_, volume)
|
|
|
|
|
: media_channel_->SetDefaultOutputVolume(volume);
|
2019-02-11 10:29:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioRtpReceiver::OnSetVolume(double volume) {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
2019-02-11 10:29:19 +01:00
|
|
|
RTC_DCHECK_GE(volume, 0);
|
|
|
|
|
RTC_DCHECK_LE(volume, 10);
|
2021-05-17 14:50:10 +02:00
|
|
|
|
2022-02-17 23:36:47 +01:00
|
|
|
bool track_enabled = track_->internal()->enabled();
|
|
|
|
|
worker_thread_->Invoke<void>(RTC_FROM_HERE, [&]() {
|
|
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
// Update the cached_volume_ even when stopped, to allow clients to set
|
|
|
|
|
// the volume before starting/restarting, eg see crbug.com/1272566.
|
|
|
|
|
cached_volume_ = volume;
|
|
|
|
|
// When the track is disabled, the volume of the source, which is the
|
|
|
|
|
// corresponding WebRtc Voice Engine channel will be 0. So we do not
|
|
|
|
|
// allow setting the volume to the source when the track is disabled.
|
|
|
|
|
if (track_enabled)
|
|
|
|
|
SetOutputVolume_w(volume);
|
|
|
|
|
});
|
2019-02-11 10:29:19 +01:00
|
|
|
}
|
|
|
|
|
|
2021-05-17 14:50:10 +02:00
|
|
|
rtc::scoped_refptr<DtlsTransportInterface> AudioRtpReceiver::dtls_transport()
|
|
|
|
|
const {
|
|
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
|
|
|
|
return dtls_transport_;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-11 10:29:19 +01:00
|
|
|
std::vector<std::string> AudioRtpReceiver::stream_ids() const {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
2019-02-11 10:29:19 +01:00
|
|
|
std::vector<std::string> stream_ids(streams_.size());
|
|
|
|
|
for (size_t i = 0; i < streams_.size(); ++i)
|
|
|
|
|
stream_ids[i] = streams_[i]->id();
|
|
|
|
|
return stream_ids;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-17 14:50:10 +02:00
|
|
|
std::vector<rtc::scoped_refptr<MediaStreamInterface>>
|
|
|
|
|
AudioRtpReceiver::streams() const {
|
|
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
|
|
|
|
return streams_;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-11 10:29:19 +01:00
|
|
|
RtpParameters AudioRtpReceiver::GetParameters() const {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
if (!media_channel_)
|
2019-02-11 10:29:19 +01:00
|
|
|
return RtpParameters();
|
2021-05-17 14:50:10 +02:00
|
|
|
return ssrc_ ? media_channel_->GetRtpReceiveParameters(*ssrc_)
|
|
|
|
|
: media_channel_->GetDefaultRtpReceiveParameters();
|
2019-02-11 10:29:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioRtpReceiver::SetFrameDecryptor(
|
|
|
|
|
rtc::scoped_refptr<FrameDecryptorInterface> frame_decryptor) {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
2019-02-11 10:29:19 +01:00
|
|
|
frame_decryptor_ = std::move(frame_decryptor);
|
|
|
|
|
// Special Case: Set the frame decryptor to any value on any existing channel.
|
2021-05-17 14:50:10 +02:00
|
|
|
if (media_channel_ && ssrc_) {
|
|
|
|
|
media_channel_->SetFrameDecryptor(*ssrc_, frame_decryptor_);
|
2019-02-11 10:29:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtc::scoped_refptr<FrameDecryptorInterface>
|
|
|
|
|
AudioRtpReceiver::GetFrameDecryptor() const {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
2019-02-11 10:29:19 +01:00
|
|
|
return frame_decryptor_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioRtpReceiver::Stop() {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
2022-02-08 21:12:15 +01:00
|
|
|
source_->SetState(MediaSourceInterface::kEnded);
|
2022-02-17 23:36:47 +01:00
|
|
|
track_->internal()->set_ended();
|
2019-02-11 10:29:19 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-17 23:36:47 +01:00
|
|
|
void AudioRtpReceiver::SetSourceEnded() {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
2022-02-17 23:36:47 +01:00
|
|
|
source_->SetState(MediaSourceInterface::kEnded);
|
2020-09-24 13:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
2022-02-17 23:36:47 +01:00
|
|
|
// RTC_RUN_ON(&signaling_thread_checker_)
|
2019-09-11 16:23:05 -07:00
|
|
|
void AudioRtpReceiver::RestartMediaChannel(absl::optional<uint32_t> ssrc) {
|
2022-02-17 23:36:47 +01:00
|
|
|
bool enabled = track_->internal()->enabled();
|
2022-02-08 21:12:15 +01:00
|
|
|
MediaSourceInterface::SourceState state = source_->state();
|
2022-02-17 23:36:47 +01:00
|
|
|
worker_thread_->Invoke<void>(RTC_FROM_HERE, [&]() {
|
|
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
RestartMediaChannel_w(std::move(ssrc), enabled, state);
|
|
|
|
|
});
|
2022-02-08 21:12:15 +01:00
|
|
|
source_->SetState(MediaSourceInterface::kLive);
|
2019-09-11 16:23:05 -07:00
|
|
|
}
|
|
|
|
|
|
2022-02-17 23:36:47 +01:00
|
|
|
// RTC_RUN_ON(worker_thread_)
|
|
|
|
|
void AudioRtpReceiver::RestartMediaChannel_w(
|
|
|
|
|
absl::optional<uint32_t> ssrc,
|
|
|
|
|
bool track_enabled,
|
|
|
|
|
MediaSourceInterface::SourceState state) {
|
|
|
|
|
if (!media_channel_)
|
|
|
|
|
return; // Can't restart.
|
|
|
|
|
|
|
|
|
|
if (state != MediaSourceInterface::kInitializing) {
|
|
|
|
|
if (ssrc_ == ssrc)
|
|
|
|
|
return;
|
|
|
|
|
source_->Stop(media_channel_, ssrc_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ssrc_ = std::move(ssrc);
|
|
|
|
|
source_->Start(media_channel_, ssrc_);
|
|
|
|
|
if (ssrc_) {
|
|
|
|
|
media_channel_->SetBaseMinimumPlayoutDelayMs(*ssrc_, delay_.GetMs());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Reconfigure(track_enabled);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-11 10:29:19 +01:00
|
|
|
void AudioRtpReceiver::SetupMediaChannel(uint32_t ssrc) {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
2019-09-11 16:23:05 -07:00
|
|
|
RestartMediaChannel(ssrc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioRtpReceiver::SetupUnsignaledMediaChannel() {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
2019-09-11 16:23:05 -07:00
|
|
|
RestartMediaChannel(absl::nullopt);
|
2019-02-11 10:29:19 +01:00
|
|
|
}
|
|
|
|
|
|
2021-05-17 14:50:10 +02:00
|
|
|
uint32_t AudioRtpReceiver::ssrc() const {
|
|
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
return ssrc_.value_or(0);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-11 10:29:19 +01:00
|
|
|
void AudioRtpReceiver::set_stream_ids(std::vector<std::string> stream_ids) {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
2019-02-11 10:29:19 +01:00
|
|
|
SetStreams(CreateStreamsFromIds(std::move(stream_ids)));
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-17 14:50:10 +02:00
|
|
|
void AudioRtpReceiver::set_transport(
|
|
|
|
|
rtc::scoped_refptr<DtlsTransportInterface> dtls_transport) {
|
|
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
|
|
|
|
dtls_transport_ = std::move(dtls_transport);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-11 10:29:19 +01:00
|
|
|
void AudioRtpReceiver::SetStreams(
|
|
|
|
|
const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
2019-02-11 10:29:19 +01:00
|
|
|
// Remove remote track from any streams that are going away.
|
|
|
|
|
for (const auto& existing_stream : streams_) {
|
|
|
|
|
bool removed = true;
|
|
|
|
|
for (const auto& stream : streams) {
|
|
|
|
|
if (existing_stream->id() == stream->id()) {
|
|
|
|
|
RTC_DCHECK_EQ(existing_stream.get(), stream.get());
|
|
|
|
|
removed = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (removed) {
|
|
|
|
|
existing_stream->RemoveTrack(track_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Add remote track to any streams that are new.
|
|
|
|
|
for (const auto& stream : streams) {
|
|
|
|
|
bool added = true;
|
|
|
|
|
for (const auto& existing_stream : streams_) {
|
|
|
|
|
if (stream->id() == existing_stream->id()) {
|
|
|
|
|
RTC_DCHECK_EQ(stream.get(), existing_stream.get());
|
|
|
|
|
added = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (added) {
|
|
|
|
|
stream->AddTrack(track_);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
streams_ = streams;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<RtpSource> AudioRtpReceiver::GetSources() const {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
if (!media_channel_ || !ssrc_) {
|
2019-02-11 10:29:19 +01:00
|
|
|
return {};
|
|
|
|
|
}
|
2021-05-17 14:50:10 +02:00
|
|
|
return media_channel_->GetSources(*ssrc_);
|
2019-02-11 10:29:19 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-01 07:46:16 +02:00
|
|
|
void AudioRtpReceiver::SetDepacketizerToDecoderFrameTransformer(
|
|
|
|
|
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer) {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
if (media_channel_) {
|
|
|
|
|
media_channel_->SetDepacketizerToDecoderFrameTransformer(ssrc_.value_or(0),
|
|
|
|
|
frame_transformer);
|
|
|
|
|
}
|
|
|
|
|
frame_transformer_ = std::move(frame_transformer);
|
2020-04-01 07:46:16 +02:00
|
|
|
}
|
|
|
|
|
|
2021-05-17 14:50:10 +02:00
|
|
|
// RTC_RUN_ON(worker_thread_)
|
2022-02-17 23:36:47 +01:00
|
|
|
void AudioRtpReceiver::Reconfigure(bool track_enabled) {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK(media_channel_);
|
|
|
|
|
|
2022-02-17 23:36:47 +01:00
|
|
|
SetOutputVolume_w(track_enabled ? cached_volume_ : 0);
|
2021-05-17 14:50:10 +02:00
|
|
|
|
|
|
|
|
if (ssrc_ && frame_decryptor_) {
|
|
|
|
|
// Reattach the frame decryptor if we were reconfigured.
|
|
|
|
|
media_channel_->SetFrameDecryptor(*ssrc_, frame_decryptor_);
|
2019-02-11 10:29:19 +01:00
|
|
|
}
|
2021-05-17 14:50:10 +02:00
|
|
|
|
|
|
|
|
if (frame_transformer_) {
|
|
|
|
|
media_channel_->SetDepacketizerToDecoderFrameTransformer(
|
|
|
|
|
ssrc_.value_or(0), frame_transformer_);
|
2020-04-01 07:46:16 +02:00
|
|
|
}
|
2019-02-11 10:29:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioRtpReceiver::SetObserver(RtpReceiverObserverInterface* observer) {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
2019-02-11 10:29:19 +01:00
|
|
|
observer_ = observer;
|
|
|
|
|
// Deliver any notifications the observer may have missed by being set late.
|
|
|
|
|
if (received_first_packet_ && observer_) {
|
|
|
|
|
observer_->OnFirstPacketReceived(media_type());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-03 19:55:33 +02:00
|
|
|
void AudioRtpReceiver::SetJitterBufferMinimumDelay(
|
|
|
|
|
absl::optional<double> delay_seconds) {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
|
|
|
|
delay_.Set(delay_seconds);
|
|
|
|
|
if (media_channel_ && ssrc_)
|
|
|
|
|
media_channel_->SetBaseMinimumPlayoutDelayMs(*ssrc_, delay_.GetMs());
|
2019-04-03 19:55:33 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-11 10:29:19 +01:00
|
|
|
void AudioRtpReceiver::SetMediaChannel(cricket::MediaChannel* media_channel) {
|
2022-02-17 23:36:47 +01:00
|
|
|
RTC_DCHECK_RUN_ON(worker_thread_);
|
2019-02-11 10:29:19 +01:00
|
|
|
RTC_DCHECK(media_channel == nullptr ||
|
|
|
|
|
media_channel->media_type() == media_type());
|
2022-02-17 23:36:47 +01:00
|
|
|
if (!media_channel && media_channel_)
|
|
|
|
|
SetOutputVolume_w(0.0);
|
2021-05-17 14:50:10 +02:00
|
|
|
|
|
|
|
|
media_channel ? worker_thread_safety_->SetAlive()
|
|
|
|
|
: worker_thread_safety_->SetNotAlive();
|
2019-02-11 10:29:19 +01:00
|
|
|
media_channel_ = static_cast<cricket::VoiceMediaChannel*>(media_channel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AudioRtpReceiver::NotifyFirstPacketReceived() {
|
2021-05-17 14:50:10 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&signaling_thread_checker_);
|
2019-02-11 10:29:19 +01:00
|
|
|
if (observer_) {
|
|
|
|
|
observer_->OnFirstPacketReceived(media_type());
|
|
|
|
|
}
|
|
|
|
|
received_first_packet_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|