blob: b1c1c458326ac9ad92f2e59383f04137c89c6295 [file] [log] [blame]
Niels Möllerb222f492018-10-03 16:50:08 +02001/*
2 * Copyright (c) 2015 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 "audio/channel_receive_proxy.h"
12
13#include <utility>
14
15#include "api/call/audio_sink.h"
16#include "audio/channel_send_proxy.h"
17#include "call/rtp_transport_controller_send_interface.h"
18#include "rtc_base/checks.h"
19#include "rtc_base/logging.h"
20#include "rtc_base/numerics/safe_minmax.h"
21
22namespace webrtc {
23namespace voe {
24ChannelReceiveProxy::ChannelReceiveProxy() {}
25
Niels Möller530ead42018-10-04 14:28:39 +020026ChannelReceiveProxy::ChannelReceiveProxy(
27 std::unique_ptr<ChannelReceive> channel)
Niels Möllerb222f492018-10-03 16:50:08 +020028 : channel_(std::move(channel)) {
29 RTC_DCHECK(channel_);
30 module_process_thread_checker_.DetachFromThread();
31}
32
33ChannelReceiveProxy::~ChannelReceiveProxy() {}
34
35void ChannelReceiveProxy::SetLocalSSRC(uint32_t ssrc) {
36 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
37 int error = channel_->SetLocalSSRC(ssrc);
38 RTC_DCHECK_EQ(0, error);
39}
40
41void ChannelReceiveProxy::SetNACKStatus(bool enable, int max_packets) {
42 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
43 channel_->SetNACKStatus(enable, max_packets);
44}
45
Niels Möller530ead42018-10-04 14:28:39 +020046CallReceiveStatistics ChannelReceiveProxy::GetRTCPStatistics() const {
Niels Möllerb222f492018-10-03 16:50:08 +020047 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
Niels Möller530ead42018-10-04 14:28:39 +020048 CallReceiveStatistics stats = {0};
Niels Möllerb222f492018-10-03 16:50:08 +020049 int error = channel_->GetRTPStatistics(stats);
50 RTC_DCHECK_EQ(0, error);
51 return stats;
52}
53
Niels Möllerb222f492018-10-03 16:50:08 +020054bool ChannelReceiveProxy::ReceivedRTCPPacket(const uint8_t* packet,
55 size_t length) {
56 // May be called on either worker thread or network thread.
57 return channel_->ReceivedRTCPPacket(packet, length) == 0;
58}
59
60void ChannelReceiveProxy::RegisterReceiverCongestionControlObjects(
61 PacketRouter* packet_router) {
62 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
63 channel_->RegisterReceiverCongestionControlObjects(packet_router);
64}
65
66void ChannelReceiveProxy::ResetReceiverCongestionControlObjects() {
67 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
68 channel_->ResetReceiverCongestionControlObjects();
69}
70
71NetworkStatistics ChannelReceiveProxy::GetNetworkStatistics() const {
72 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
73 NetworkStatistics stats = {0};
74 int error = channel_->GetNetworkStatistics(stats);
75 RTC_DCHECK_EQ(0, error);
76 return stats;
77}
78
79AudioDecodingCallStats ChannelReceiveProxy::GetDecodingCallStatistics() const {
80 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
81 AudioDecodingCallStats stats;
82 channel_->GetDecodingCallStatistics(&stats);
83 return stats;
84}
85
86int ChannelReceiveProxy::GetSpeechOutputLevelFullRange() const {
87 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
88 return channel_->GetSpeechOutputLevelFullRange();
89}
90
91double ChannelReceiveProxy::GetTotalOutputEnergy() const {
92 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
93 return channel_->GetTotalOutputEnergy();
94}
95
96double ChannelReceiveProxy::GetTotalOutputDuration() const {
97 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
98 return channel_->GetTotalOutputDuration();
99}
100
101uint32_t ChannelReceiveProxy::GetDelayEstimate() const {
102 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread() ||
103 module_process_thread_checker_.CalledOnValidThread());
104 return channel_->GetDelayEstimate();
105}
106
107void ChannelReceiveProxy::SetReceiveCodecs(
108 const std::map<int, SdpAudioFormat>& codecs) {
109 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
110 channel_->SetReceiveCodecs(codecs);
111}
112
113void ChannelReceiveProxy::SetSink(AudioSinkInterface* sink) {
114 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
115 channel_->SetSink(sink);
116}
117
118void ChannelReceiveProxy::OnRtpPacket(const RtpPacketReceived& packet) {
119 // May be called on either worker thread or network thread.
120 channel_->OnRtpPacket(packet);
121}
122
123void ChannelReceiveProxy::SetChannelOutputVolumeScaling(float scaling) {
124 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
125 channel_->SetChannelOutputVolumeScaling(scaling);
126}
127
128AudioMixer::Source::AudioFrameInfo ChannelReceiveProxy::GetAudioFrameWithInfo(
129 int sample_rate_hz,
130 AudioFrame* audio_frame) {
131 RTC_DCHECK_RUNS_SERIALIZED(&audio_thread_race_checker_);
132 return channel_->GetAudioFrameWithInfo(sample_rate_hz, audio_frame);
133}
134
135int ChannelReceiveProxy::PreferredSampleRate() const {
136 RTC_DCHECK_RUNS_SERIALIZED(&audio_thread_race_checker_);
137 return channel_->PreferredSampleRate();
138}
139
140void ChannelReceiveProxy::AssociateSendChannel(
141 const ChannelSendProxy& send_channel_proxy) {
142 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
143 channel_->SetAssociatedSendChannel(send_channel_proxy.GetChannel());
144}
145
146void ChannelReceiveProxy::DisassociateSendChannel() {
147 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
148 channel_->SetAssociatedSendChannel(nullptr);
149}
150
151absl::optional<Syncable::Info> ChannelReceiveProxy::GetSyncInfo() const {
152 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread());
153 return channel_->GetSyncInfo();
154}
155
156uint32_t ChannelReceiveProxy::GetPlayoutTimestamp() const {
157 RTC_DCHECK_RUNS_SERIALIZED(&video_capture_thread_race_checker_);
158 unsigned int timestamp = 0;
159 int error = channel_->GetPlayoutTimestamp(timestamp);
160 RTC_DCHECK(!error || timestamp == 0);
161 return timestamp;
162}
163
164void ChannelReceiveProxy::SetMinimumPlayoutDelay(int delay_ms) {
165 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread());
166 // Limit to range accepted by both VoE and ACM, so we're at least getting as
167 // close as possible, instead of failing.
168 delay_ms = rtc::SafeClamp(delay_ms, 0, 10000);
169 int error = channel_->SetMinimumPlayoutDelay(delay_ms);
170 if (0 != error) {
171 RTC_LOG(LS_WARNING) << "Error setting minimum playout delay.";
172 }
173}
174
175bool ChannelReceiveProxy::GetRecCodec(CodecInst* codec_inst) const {
176 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
177 return channel_->GetRecCodec(*codec_inst) == 0;
178}
179
180std::vector<RtpSource> ChannelReceiveProxy::GetSources() const {
181 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
182 return channel_->GetSources();
183}
184
185void ChannelReceiveProxy::StartPlayout() {
186 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
187 int error = channel_->StartPlayout();
188 RTC_DCHECK_EQ(0, error);
189}
190
191void ChannelReceiveProxy::StopPlayout() {
192 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
193 int error = channel_->StopPlayout();
194 RTC_DCHECK_EQ(0, error);
195}
196} // namespace voe
197} // namespace webrtc