blob: bea4c0692edd84aa4bcf668f2872a093205320da [file] [log] [blame]
solenberg13725082015-11-25 08:16:52 -08001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "voice_engine/channel_proxy.h"
solenberg13725082015-11-25 08:16:52 -080012
Tommif888bb52015-12-12 01:37:01 +010013#include <utility>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "api/call/audio_sink.h"
16#include "call/rtp_transport_controller_send_interface.h"
17#include "rtc_base/checks.h"
18#include "rtc_base/logging.h"
19#include "rtc_base/safe_minmax.h"
20#include "voice_engine/channel.h"
solenberg13725082015-11-25 08:16:52 -080021
22namespace webrtc {
23namespace voe {
24ChannelProxy::ChannelProxy() : channel_owner_(nullptr) {}
25
26ChannelProxy::ChannelProxy(const ChannelOwner& channel_owner) :
27 channel_owner_(channel_owner) {
28 RTC_CHECK(channel_owner_.channel());
solenberg08b19df2017-02-15 00:42:31 -080029 module_process_thread_checker_.DetachFromThread();
solenberg13725082015-11-25 08:16:52 -080030}
31
Tommif888bb52015-12-12 01:37:01 +010032ChannelProxy::~ChannelProxy() {}
33
ossu1ffbd6c2017-04-06 12:05:04 -070034bool ChannelProxy::SetEncoder(int payload_type,
35 std::unique_ptr<AudioEncoder> encoder) {
36 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
37 return channel()->SetEncoder(payload_type, std::move(encoder));
38}
39
ossu20a4b3f2017-04-27 02:08:52 -070040void ChannelProxy::ModifyEncoder(
41 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) {
42 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
43 channel()->ModifyEncoder(modifier);
44}
45
solenberg13725082015-11-25 08:16:52 -080046void ChannelProxy::SetRTCPStatus(bool enable) {
solenberg08b19df2017-02-15 00:42:31 -080047 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -080048 channel()->SetRTCPStatus(enable);
solenberg13725082015-11-25 08:16:52 -080049}
50
51void ChannelProxy::SetLocalSSRC(uint32_t ssrc) {
solenberg08b19df2017-02-15 00:42:31 -080052 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -080053 int error = channel()->SetLocalSSRC(ssrc);
solenberg13725082015-11-25 08:16:52 -080054 RTC_DCHECK_EQ(0, error);
55}
56
57void ChannelProxy::SetRTCP_CNAME(const std::string& c_name) {
solenberg08b19df2017-02-15 00:42:31 -080058 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg13725082015-11-25 08:16:52 -080059 // Note: VoERTP_RTCP::SetRTCP_CNAME() accepts a char[256] array.
60 std::string c_name_limited = c_name.substr(0, 255);
solenberg358057b2015-11-27 10:46:42 -080061 int error = channel()->SetRTCP_CNAME(c_name_limited.c_str());
solenberg13725082015-11-25 08:16:52 -080062 RTC_DCHECK_EQ(0, error);
63}
solenberg358057b2015-11-27 10:46:42 -080064
solenberg971cab02016-06-14 10:02:41 -070065void ChannelProxy::SetNACKStatus(bool enable, int max_packets) {
solenberg08b19df2017-02-15 00:42:31 -080066 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg971cab02016-06-14 10:02:41 -070067 channel()->SetNACKStatus(enable, max_packets);
68}
69
solenberg358057b2015-11-27 10:46:42 -080070void ChannelProxy::SetSendAudioLevelIndicationStatus(bool enable, int id) {
solenberg08b19df2017-02-15 00:42:31 -080071 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -080072 int error = channel()->SetSendAudioLevelIndicationStatus(enable, id);
73 RTC_DCHECK_EQ(0, error);
74}
75
solenberg358057b2015-11-27 10:46:42 -080076void ChannelProxy::SetReceiveAudioLevelIndicationStatus(bool enable, int id) {
solenberg08b19df2017-02-15 00:42:31 -080077 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -080078 int error = channel()->SetReceiveAudioLevelIndicationStatus(enable, id);
79 RTC_DCHECK_EQ(0, error);
80}
81
stefan3313ec92016-01-21 06:32:43 -080082void ChannelProxy::EnableSendTransportSequenceNumber(int id) {
solenberg08b19df2017-02-15 00:42:31 -080083 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
stefan3313ec92016-01-21 06:32:43 -080084 channel()->EnableSendTransportSequenceNumber(id);
85}
86
87void ChannelProxy::EnableReceiveTransportSequenceNumber(int id) {
solenberg08b19df2017-02-15 00:42:31 -080088 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
stefan3313ec92016-01-21 06:32:43 -080089 channel()->EnableReceiveTransportSequenceNumber(id);
90}
91
stefanbba9dec2016-02-01 04:39:55 -080092void ChannelProxy::RegisterSenderCongestionControlObjects(
nisseb8f9a322017-03-27 05:36:15 -070093 RtpTransportControllerSendInterface* transport,
stefan7de8d642017-02-07 07:14:08 -080094 RtcpBandwidthObserver* bandwidth_observer) {
solenberg08b19df2017-02-15 00:42:31 -080095 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
nisseb8f9a322017-03-27 05:36:15 -070096 channel()->RegisterSenderCongestionControlObjects(transport,
97 bandwidth_observer);
Stefan Holmerb86d4e42015-12-07 10:26:18 +010098}
99
stefanbba9dec2016-02-01 04:39:55 -0800100void ChannelProxy::RegisterReceiverCongestionControlObjects(
101 PacketRouter* packet_router) {
solenberg08b19df2017-02-15 00:42:31 -0800102 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
stefanbba9dec2016-02-01 04:39:55 -0800103 channel()->RegisterReceiverCongestionControlObjects(packet_router);
104}
105
nissefdbfdc92017-03-31 05:44:52 -0700106void ChannelProxy::ResetSenderCongestionControlObjects() {
solenberg08b19df2017-02-15 00:42:31 -0800107 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
nissefdbfdc92017-03-31 05:44:52 -0700108 channel()->ResetSenderCongestionControlObjects();
109}
110
111void ChannelProxy::ResetReceiverCongestionControlObjects() {
112 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
113 channel()->ResetReceiverCongestionControlObjects();
stefanbba9dec2016-02-01 04:39:55 -0800114}
115
solenberg358057b2015-11-27 10:46:42 -0800116CallStatistics ChannelProxy::GetRTCPStatistics() const {
solenberg08b19df2017-02-15 00:42:31 -0800117 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -0800118 CallStatistics stats = {0};
119 int error = channel()->GetRTPStatistics(stats);
120 RTC_DCHECK_EQ(0, error);
121 return stats;
122}
123
124std::vector<ReportBlock> ChannelProxy::GetRemoteRTCPReportBlocks() const {
solenberg08b19df2017-02-15 00:42:31 -0800125 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -0800126 std::vector<webrtc::ReportBlock> blocks;
127 int error = channel()->GetRemoteRTCPReportBlocks(&blocks);
128 RTC_DCHECK_EQ(0, error);
129 return blocks;
130}
131
132NetworkStatistics ChannelProxy::GetNetworkStatistics() const {
solenberg08b19df2017-02-15 00:42:31 -0800133 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -0800134 NetworkStatistics stats = {0};
135 int error = channel()->GetNetworkStatistics(stats);
136 RTC_DCHECK_EQ(0, error);
137 return stats;
138}
139
140AudioDecodingCallStats ChannelProxy::GetDecodingCallStatistics() const {
solenberg08b19df2017-02-15 00:42:31 -0800141 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -0800142 AudioDecodingCallStats stats;
143 channel()->GetDecodingCallStatistics(&stats);
144 return stats;
145}
146
ivoce1198e02017-09-08 08:13:19 -0700147ANAStats ChannelProxy::GetANAStatistics() const {
148 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
149 return channel()->GetANAStatistics();
150}
151
solenberg8d73f8c2017-03-08 01:52:20 -0800152int ChannelProxy::GetSpeechOutputLevel() const {
solenberg796b8f92017-03-01 17:02:23 -0800153 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg8d73f8c2017-03-08 01:52:20 -0800154 return channel()->GetSpeechOutputLevel();
solenberg796b8f92017-03-01 17:02:23 -0800155}
156
solenberg8d73f8c2017-03-08 01:52:20 -0800157int ChannelProxy::GetSpeechOutputLevelFullRange() const {
solenberg08b19df2017-02-15 00:42:31 -0800158 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg8d73f8c2017-03-08 01:52:20 -0800159 return channel()->GetSpeechOutputLevelFullRange();
solenberg358057b2015-11-27 10:46:42 -0800160}
161
zsteine76bd3a2017-07-14 12:17:49 -0700162double ChannelProxy::GetTotalOutputEnergy() const {
163 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
164 return channel()->GetTotalOutputEnergy();
165}
166
167double ChannelProxy::GetTotalOutputDuration() const {
168 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
169 return channel()->GetTotalOutputDuration();
170}
171
solenberg358057b2015-11-27 10:46:42 -0800172uint32_t ChannelProxy::GetDelayEstimate() const {
solenberg08b19df2017-02-15 00:42:31 -0800173 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread() ||
174 module_process_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -0800175 return channel()->GetDelayEstimate();
176}
177
solenbergffbbcac2016-11-17 05:25:37 -0800178bool ChannelProxy::SetSendTelephoneEventPayloadType(int payload_type,
179 int payload_frequency) {
solenberg08b19df2017-02-15 00:42:31 -0800180 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenbergffbbcac2016-11-17 05:25:37 -0800181 return channel()->SetSendTelephoneEventPayloadType(payload_type,
182 payload_frequency) == 0;
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100183}
184
solenberg8842c3e2016-03-11 03:06:41 -0800185bool ChannelProxy::SendTelephoneEventOutband(int event, int duration_ms) {
solenberg08b19df2017-02-15 00:42:31 -0800186 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg8842c3e2016-03-11 03:06:41 -0800187 return channel()->SendTelephoneEventOutband(event, duration_ms) == 0;
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100188}
189
minyue78b4d562016-11-30 04:47:39 -0800190void ChannelProxy::SetBitrate(int bitrate_bps, int64_t probing_interval_ms) {
tommi0f8b4032017-02-22 11:22:05 -0800191 // This method can be called on the worker thread, module process thread
192 // or on a TaskQueue via VideoSendStreamImpl::OnEncoderConfigurationChanged.
193 // TODO(solenberg): Figure out a good way to check this or enforce calling
194 // rules.
195 // RTC_DCHECK(worker_thread_checker_.CalledOnValidThread() ||
196 // module_process_thread_checker_.CalledOnValidThread());
minyue78b4d562016-11-30 04:47:39 -0800197 channel()->SetBitRate(bitrate_bps, probing_interval_ms);
mflodman86cc6ff2016-07-26 04:44:06 -0700198}
199
kwiberg1c07c702017-03-27 07:15:49 -0700200void ChannelProxy::SetReceiveCodecs(
201 const std::map<int, SdpAudioFormat>& codecs) {
202 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
203 channel()->SetReceiveCodecs(codecs);
204}
205
kwibergb7f89d62016-02-17 10:04:18 -0800206void ChannelProxy::SetSink(std::unique_ptr<AudioSinkInterface> sink) {
solenberg08b19df2017-02-15 00:42:31 -0800207 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
deadbeef2d110be2016-01-13 12:00:26 -0800208 channel()->SetSink(std::move(sink));
Tommif888bb52015-12-12 01:37:01 +0100209}
210
solenberg94218532016-06-16 10:53:22 -0700211void ChannelProxy::SetInputMute(bool muted) {
solenberg08b19df2017-02-15 00:42:31 -0800212 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg8d73f8c2017-03-08 01:52:20 -0800213 channel()->SetInputMute(muted);
solenberg94218532016-06-16 10:53:22 -0700214}
215
solenberg1c239d42017-09-29 06:00:28 -0700216void ChannelProxy::RegisterTransport(Transport* transport) {
solenberg08b19df2017-02-15 00:42:31 -0800217 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg1c239d42017-09-29 06:00:28 -0700218 channel()->RegisterTransport(transport);
mflodman3d7db262016-04-29 00:57:13 -0700219}
220
nisse657bab22017-02-21 06:28:10 -0800221void ChannelProxy::OnRtpPacket(const RtpPacketReceived& packet) {
mflodman3d7db262016-04-29 00:57:13 -0700222 // May be called on either worker thread or network thread.
nisse657bab22017-02-21 06:28:10 -0800223 channel()->OnRtpPacket(packet);
mflodman3d7db262016-04-29 00:57:13 -0700224}
225
226bool ChannelProxy::ReceivedRTCPPacket(const uint8_t* packet, size_t length) {
227 // May be called on either worker thread or network thread.
228 return channel()->ReceivedRTCPPacket(packet, length) == 0;
229}
230
ossu29b1a8d2016-06-13 07:34:51 -0700231const rtc::scoped_refptr<AudioDecoderFactory>&
solenberg217fb662016-06-17 08:30:54 -0700232 ChannelProxy::GetAudioDecoderFactory() const {
solenberg08b19df2017-02-15 00:42:31 -0800233 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
ossu29b1a8d2016-06-13 07:34:51 -0700234 return channel()->GetAudioDecoderFactory();
235}
236
solenberg217fb662016-06-17 08:30:54 -0700237void ChannelProxy::SetChannelOutputVolumeScaling(float scaling) {
solenberg08b19df2017-02-15 00:42:31 -0800238 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg8d73f8c2017-03-08 01:52:20 -0800239 channel()->SetChannelOutputVolumeScaling(scaling);
solenberg217fb662016-06-17 08:30:54 -0700240}
241
ivoc14d5dbe2016-07-04 07:06:55 -0700242void ChannelProxy::SetRtcEventLog(RtcEventLog* event_log) {
solenberg08b19df2017-02-15 00:42:31 -0800243 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
ivoc14d5dbe2016-07-04 07:06:55 -0700244 channel()->SetRtcEventLog(event_log);
245}
246
aleloi6c278492016-10-20 14:24:39 -0700247AudioMixer::Source::AudioFrameInfo ChannelProxy::GetAudioFrameWithInfo(
248 int sample_rate_hz,
249 AudioFrame* audio_frame) {
solenberg08b19df2017-02-15 00:42:31 -0800250 RTC_DCHECK_RUNS_SERIALIZED(&audio_thread_race_checker_);
aleloi6c278492016-10-20 14:24:39 -0700251 return channel()->GetAudioFrameWithInfo(sample_rate_hz, audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700252}
253
solenberg2397b9a2017-09-22 06:48:10 -0700254int ChannelProxy::PreferredSampleRate() const {
solenberg08b19df2017-02-15 00:42:31 -0800255 RTC_DCHECK_RUNS_SERIALIZED(&audio_thread_race_checker_);
solenberg2397b9a2017-09-22 06:48:10 -0700256 return channel()->PreferredSampleRate();
aleloi051f6782016-10-31 03:26:40 -0700257}
258
michaelt79e05882016-11-08 02:50:09 -0800259void ChannelProxy::SetTransportOverhead(int transport_overhead_per_packet) {
solenberg08b19df2017-02-15 00:42:31 -0800260 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
michaelt79e05882016-11-08 02:50:09 -0800261 channel()->SetTransportOverhead(transport_overhead_per_packet);
262}
263
solenberg7602aab2016-11-14 11:30:07 -0800264void ChannelProxy::AssociateSendChannel(
265 const ChannelProxy& send_channel_proxy) {
solenberg08b19df2017-02-15 00:42:31 -0800266 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg7602aab2016-11-14 11:30:07 -0800267 channel()->set_associate_send_channel(send_channel_proxy.channel_owner_);
268}
269
270void ChannelProxy::DisassociateSendChannel() {
solenberg08b19df2017-02-15 00:42:31 -0800271 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg7602aab2016-11-14 11:30:07 -0800272 channel()->set_associate_send_channel(ChannelOwner(nullptr));
273}
274
solenberg3ebbcb52017-01-31 03:58:40 -0800275void ChannelProxy::GetRtpRtcp(RtpRtcp** rtp_rtcp,
276 RtpReceiver** rtp_receiver) const {
solenberg08b19df2017-02-15 00:42:31 -0800277 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread());
solenberg3ebbcb52017-01-31 03:58:40 -0800278 RTC_DCHECK(rtp_rtcp);
279 RTC_DCHECK(rtp_receiver);
280 int error = channel()->GetRtpRtcp(rtp_rtcp, rtp_receiver);
281 RTC_DCHECK_EQ(0, error);
282}
283
solenberg3ebbcb52017-01-31 03:58:40 -0800284uint32_t ChannelProxy::GetPlayoutTimestamp() const {
solenberg08b19df2017-02-15 00:42:31 -0800285 RTC_DCHECK_RUNS_SERIALIZED(&video_capture_thread_race_checker_);
solenberg3ebbcb52017-01-31 03:58:40 -0800286 unsigned int timestamp = 0;
287 int error = channel()->GetPlayoutTimestamp(timestamp);
288 RTC_DCHECK(!error || timestamp == 0);
289 return timestamp;
290}
291
292void ChannelProxy::SetMinimumPlayoutDelay(int delay_ms) {
solenberg08b19df2017-02-15 00:42:31 -0800293 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread());
solenberg3ebbcb52017-01-31 03:58:40 -0800294 // Limit to range accepted by both VoE and ACM, so we're at least getting as
295 // close as possible, instead of failing.
kwiberg07038562017-06-12 11:40:47 -0700296 delay_ms = rtc::SafeClamp(delay_ms, 0, 10000);
solenberg3ebbcb52017-01-31 03:58:40 -0800297 int error = channel()->SetMinimumPlayoutDelay(delay_ms);
solenberg0335e6c2017-02-22 07:07:04 -0800298 if (0 != error) {
299 LOG(LS_WARNING) << "Error setting minimum playout delay.";
300 }
solenberg3ebbcb52017-01-31 03:58:40 -0800301}
302
michaelt9332b7d2016-11-30 07:51:13 -0800303void ChannelProxy::SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats) {
solenberg08b19df2017-02-15 00:42:31 -0800304 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
michaelt9332b7d2016-11-30 07:51:13 -0800305 channel()->SetRtcpRttStats(rtcp_rtt_stats);
306}
307
solenbergbd9a77f2017-02-06 12:53:57 -0800308bool ChannelProxy::GetRecCodec(CodecInst* codec_inst) const {
solenberg08b19df2017-02-15 00:42:31 -0800309 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenbergbd9a77f2017-02-06 12:53:57 -0800310 return channel()->GetRecCodec(*codec_inst) == 0;
311}
312
elad.alond12a8e12017-03-23 11:04:48 -0700313void ChannelProxy::OnTwccBasedUplinkPacketLossRate(float packet_loss_rate) {
eladalon27e812e2017-08-25 01:50:58 -0700314 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
elad.alond12a8e12017-03-23 11:04:48 -0700315 channel()->OnTwccBasedUplinkPacketLossRate(packet_loss_rate);
316}
317
elad.alondadb4dc2017-03-23 15:29:50 -0700318void ChannelProxy::OnRecoverableUplinkPacketLossRate(
319 float recoverable_packet_loss_rate) {
eladalon27e812e2017-08-25 01:50:58 -0700320 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
elad.alondadb4dc2017-03-23 15:29:50 -0700321 channel()->OnRecoverableUplinkPacketLossRate(recoverable_packet_loss_rate);
322}
323
hbos8d609f62017-04-10 07:39:05 -0700324std::vector<RtpSource> ChannelProxy::GetSources() const {
325 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
326 return channel()->GetSources();
327}
328
solenberg358057b2015-11-27 10:46:42 -0800329Channel* ChannelProxy::channel() const {
330 RTC_DCHECK(channel_owner_.channel());
331 return channel_owner_.channel();
332}
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100333
solenberg13725082015-11-25 08:16:52 -0800334} // namespace voe
335} // namespace webrtc