blob: 25978c7c597fcbcfa59dc157f26784f68e83e8fb [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
11#include "webrtc/voice_engine/channel_proxy.h"
12
Tommif888bb52015-12-12 01:37:01 +010013#include <utility>
14
kjellandera69d9732016-08-31 07:33:05 -070015#include "webrtc/api/call/audio_sink.h"
solenberg13725082015-11-25 08:16:52 -080016#include "webrtc/base/checks.h"
solenberg0335e6c2017-02-22 07:07:04 -080017#include "webrtc/base/logging.h"
nissecae45d02017-04-24 05:53:20 -070018#include "webrtc/call/rtp_transport_controller_send_interface.h"
solenberg13725082015-11-25 08:16:52 -080019#include "webrtc/voice_engine/channel.h"
20
21namespace webrtc {
22namespace voe {
23ChannelProxy::ChannelProxy() : channel_owner_(nullptr) {}
24
25ChannelProxy::ChannelProxy(const ChannelOwner& channel_owner) :
26 channel_owner_(channel_owner) {
27 RTC_CHECK(channel_owner_.channel());
solenberg08b19df2017-02-15 00:42:31 -080028 module_process_thread_checker_.DetachFromThread();
solenberg13725082015-11-25 08:16:52 -080029}
30
Tommif888bb52015-12-12 01:37:01 +010031ChannelProxy::~ChannelProxy() {}
32
ossu1ffbd6c2017-04-06 12:05:04 -070033bool ChannelProxy::SetEncoder(int payload_type,
34 std::unique_ptr<AudioEncoder> encoder) {
35 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
36 return channel()->SetEncoder(payload_type, std::move(encoder));
37}
38
ossu20a4b3f2017-04-27 02:08:52 -070039void ChannelProxy::ModifyEncoder(
40 rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) {
41 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
42 channel()->ModifyEncoder(modifier);
43}
44
solenberg13725082015-11-25 08:16:52 -080045void ChannelProxy::SetRTCPStatus(bool enable) {
solenberg08b19df2017-02-15 00:42:31 -080046 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -080047 channel()->SetRTCPStatus(enable);
solenberg13725082015-11-25 08:16:52 -080048}
49
50void ChannelProxy::SetLocalSSRC(uint32_t ssrc) {
solenberg08b19df2017-02-15 00:42:31 -080051 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -080052 int error = channel()->SetLocalSSRC(ssrc);
solenberg13725082015-11-25 08:16:52 -080053 RTC_DCHECK_EQ(0, error);
54}
55
56void ChannelProxy::SetRTCP_CNAME(const std::string& c_name) {
solenberg08b19df2017-02-15 00:42:31 -080057 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg13725082015-11-25 08:16:52 -080058 // Note: VoERTP_RTCP::SetRTCP_CNAME() accepts a char[256] array.
59 std::string c_name_limited = c_name.substr(0, 255);
solenberg358057b2015-11-27 10:46:42 -080060 int error = channel()->SetRTCP_CNAME(c_name_limited.c_str());
solenberg13725082015-11-25 08:16:52 -080061 RTC_DCHECK_EQ(0, error);
62}
solenberg358057b2015-11-27 10:46:42 -080063
solenberg971cab02016-06-14 10:02:41 -070064void ChannelProxy::SetNACKStatus(bool enable, int max_packets) {
solenberg08b19df2017-02-15 00:42:31 -080065 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg971cab02016-06-14 10:02:41 -070066 channel()->SetNACKStatus(enable, max_packets);
67}
68
solenberg358057b2015-11-27 10:46:42 -080069void ChannelProxy::SetSendAudioLevelIndicationStatus(bool enable, int id) {
solenberg08b19df2017-02-15 00:42:31 -080070 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -080071 int error = channel()->SetSendAudioLevelIndicationStatus(enable, id);
72 RTC_DCHECK_EQ(0, error);
73}
74
solenberg358057b2015-11-27 10:46:42 -080075void ChannelProxy::SetReceiveAudioLevelIndicationStatus(bool enable, int id) {
solenberg08b19df2017-02-15 00:42:31 -080076 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -080077 int error = channel()->SetReceiveAudioLevelIndicationStatus(enable, id);
78 RTC_DCHECK_EQ(0, error);
79}
80
stefan3313ec92016-01-21 06:32:43 -080081void ChannelProxy::EnableSendTransportSequenceNumber(int id) {
solenberg08b19df2017-02-15 00:42:31 -080082 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
stefan3313ec92016-01-21 06:32:43 -080083 channel()->EnableSendTransportSequenceNumber(id);
84}
85
86void ChannelProxy::EnableReceiveTransportSequenceNumber(int id) {
solenberg08b19df2017-02-15 00:42:31 -080087 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
stefan3313ec92016-01-21 06:32:43 -080088 channel()->EnableReceiveTransportSequenceNumber(id);
89}
90
stefanbba9dec2016-02-01 04:39:55 -080091void ChannelProxy::RegisterSenderCongestionControlObjects(
nisseb8f9a322017-03-27 05:36:15 -070092 RtpTransportControllerSendInterface* transport,
stefan7de8d642017-02-07 07:14:08 -080093 RtcpBandwidthObserver* bandwidth_observer) {
solenberg08b19df2017-02-15 00:42:31 -080094 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
nisseb8f9a322017-03-27 05:36:15 -070095 channel()->RegisterSenderCongestionControlObjects(transport,
96 bandwidth_observer);
Stefan Holmerb86d4e42015-12-07 10:26:18 +010097}
98
stefanbba9dec2016-02-01 04:39:55 -080099void ChannelProxy::RegisterReceiverCongestionControlObjects(
100 PacketRouter* packet_router) {
solenberg08b19df2017-02-15 00:42:31 -0800101 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
stefanbba9dec2016-02-01 04:39:55 -0800102 channel()->RegisterReceiverCongestionControlObjects(packet_router);
103}
104
nissefdbfdc92017-03-31 05:44:52 -0700105void ChannelProxy::ResetSenderCongestionControlObjects() {
solenberg08b19df2017-02-15 00:42:31 -0800106 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
nissefdbfdc92017-03-31 05:44:52 -0700107 channel()->ResetSenderCongestionControlObjects();
108}
109
110void ChannelProxy::ResetReceiverCongestionControlObjects() {
111 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
112 channel()->ResetReceiverCongestionControlObjects();
stefanbba9dec2016-02-01 04:39:55 -0800113}
114
solenberg358057b2015-11-27 10:46:42 -0800115CallStatistics ChannelProxy::GetRTCPStatistics() const {
solenberg08b19df2017-02-15 00:42:31 -0800116 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -0800117 CallStatistics stats = {0};
118 int error = channel()->GetRTPStatistics(stats);
119 RTC_DCHECK_EQ(0, error);
120 return stats;
121}
122
123std::vector<ReportBlock> ChannelProxy::GetRemoteRTCPReportBlocks() const {
solenberg08b19df2017-02-15 00:42:31 -0800124 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -0800125 std::vector<webrtc::ReportBlock> blocks;
126 int error = channel()->GetRemoteRTCPReportBlocks(&blocks);
127 RTC_DCHECK_EQ(0, error);
128 return blocks;
129}
130
131NetworkStatistics ChannelProxy::GetNetworkStatistics() const {
solenberg08b19df2017-02-15 00:42:31 -0800132 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -0800133 NetworkStatistics stats = {0};
134 int error = channel()->GetNetworkStatistics(stats);
135 RTC_DCHECK_EQ(0, error);
136 return stats;
137}
138
139AudioDecodingCallStats ChannelProxy::GetDecodingCallStatistics() const {
solenberg08b19df2017-02-15 00:42:31 -0800140 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -0800141 AudioDecodingCallStats stats;
142 channel()->GetDecodingCallStatistics(&stats);
143 return stats;
144}
145
solenberg8d73f8c2017-03-08 01:52:20 -0800146int ChannelProxy::GetSpeechOutputLevel() const {
solenberg796b8f92017-03-01 17:02:23 -0800147 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg8d73f8c2017-03-08 01:52:20 -0800148 return channel()->GetSpeechOutputLevel();
solenberg796b8f92017-03-01 17:02:23 -0800149}
150
solenberg8d73f8c2017-03-08 01:52:20 -0800151int ChannelProxy::GetSpeechOutputLevelFullRange() const {
solenberg08b19df2017-02-15 00:42:31 -0800152 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg8d73f8c2017-03-08 01:52:20 -0800153 return channel()->GetSpeechOutputLevelFullRange();
solenberg358057b2015-11-27 10:46:42 -0800154}
155
156uint32_t ChannelProxy::GetDelayEstimate() const {
solenberg08b19df2017-02-15 00:42:31 -0800157 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread() ||
158 module_process_thread_checker_.CalledOnValidThread());
solenberg358057b2015-11-27 10:46:42 -0800159 return channel()->GetDelayEstimate();
160}
161
solenbergffbbcac2016-11-17 05:25:37 -0800162bool ChannelProxy::SetSendTelephoneEventPayloadType(int payload_type,
163 int payload_frequency) {
solenberg08b19df2017-02-15 00:42:31 -0800164 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenbergffbbcac2016-11-17 05:25:37 -0800165 return channel()->SetSendTelephoneEventPayloadType(payload_type,
166 payload_frequency) == 0;
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100167}
168
solenberg8842c3e2016-03-11 03:06:41 -0800169bool ChannelProxy::SendTelephoneEventOutband(int event, int duration_ms) {
solenberg08b19df2017-02-15 00:42:31 -0800170 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg8842c3e2016-03-11 03:06:41 -0800171 return channel()->SendTelephoneEventOutband(event, duration_ms) == 0;
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100172}
173
minyue78b4d562016-11-30 04:47:39 -0800174void ChannelProxy::SetBitrate(int bitrate_bps, int64_t probing_interval_ms) {
tommi0f8b4032017-02-22 11:22:05 -0800175 // This method can be called on the worker thread, module process thread
176 // or on a TaskQueue via VideoSendStreamImpl::OnEncoderConfigurationChanged.
177 // TODO(solenberg): Figure out a good way to check this or enforce calling
178 // rules.
179 // RTC_DCHECK(worker_thread_checker_.CalledOnValidThread() ||
180 // module_process_thread_checker_.CalledOnValidThread());
minyue78b4d562016-11-30 04:47:39 -0800181 channel()->SetBitRate(bitrate_bps, probing_interval_ms);
mflodman86cc6ff2016-07-26 04:44:06 -0700182}
183
kwibergd32bf752017-01-19 07:03:59 -0800184void ChannelProxy::SetRecPayloadType(int payload_type,
185 const SdpAudioFormat& format) {
solenberg08b19df2017-02-15 00:42:31 -0800186 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
kwibergd32bf752017-01-19 07:03:59 -0800187 const int result = channel()->SetRecPayloadType(payload_type, format);
188 RTC_DCHECK_EQ(0, result);
189}
190
kwiberg1c07c702017-03-27 07:15:49 -0700191void ChannelProxy::SetReceiveCodecs(
192 const std::map<int, SdpAudioFormat>& codecs) {
193 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
194 channel()->SetReceiveCodecs(codecs);
195}
196
kwibergb7f89d62016-02-17 10:04:18 -0800197void ChannelProxy::SetSink(std::unique_ptr<AudioSinkInterface> sink) {
solenberg08b19df2017-02-15 00:42:31 -0800198 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
deadbeef2d110be2016-01-13 12:00:26 -0800199 channel()->SetSink(std::move(sink));
Tommif888bb52015-12-12 01:37:01 +0100200}
201
solenberg94218532016-06-16 10:53:22 -0700202void ChannelProxy::SetInputMute(bool muted) {
solenberg08b19df2017-02-15 00:42:31 -0800203 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg8d73f8c2017-03-08 01:52:20 -0800204 channel()->SetInputMute(muted);
solenberg94218532016-06-16 10:53:22 -0700205}
206
mflodman3d7db262016-04-29 00:57:13 -0700207void ChannelProxy::RegisterExternalTransport(Transport* transport) {
solenberg08b19df2017-02-15 00:42:31 -0800208 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
mflodman3d7db262016-04-29 00:57:13 -0700209 int error = channel()->RegisterExternalTransport(transport);
210 RTC_DCHECK_EQ(0, error);
211}
212
213void ChannelProxy::DeRegisterExternalTransport() {
solenberg08b19df2017-02-15 00:42:31 -0800214 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
mflodman3d7db262016-04-29 00:57:13 -0700215 channel()->DeRegisterExternalTransport();
216}
217
nisse657bab22017-02-21 06:28:10 -0800218void ChannelProxy::OnRtpPacket(const RtpPacketReceived& packet) {
mflodman3d7db262016-04-29 00:57:13 -0700219 // May be called on either worker thread or network thread.
nisse657bab22017-02-21 06:28:10 -0800220 channel()->OnRtpPacket(packet);
mflodman3d7db262016-04-29 00:57:13 -0700221}
222
223bool ChannelProxy::ReceivedRTCPPacket(const uint8_t* packet, size_t length) {
224 // May be called on either worker thread or network thread.
225 return channel()->ReceivedRTCPPacket(packet, length) == 0;
226}
227
ossu29b1a8d2016-06-13 07:34:51 -0700228const rtc::scoped_refptr<AudioDecoderFactory>&
solenberg217fb662016-06-17 08:30:54 -0700229 ChannelProxy::GetAudioDecoderFactory() const {
solenberg08b19df2017-02-15 00:42:31 -0800230 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
ossu29b1a8d2016-06-13 07:34:51 -0700231 return channel()->GetAudioDecoderFactory();
232}
233
solenberg217fb662016-06-17 08:30:54 -0700234void ChannelProxy::SetChannelOutputVolumeScaling(float scaling) {
solenberg08b19df2017-02-15 00:42:31 -0800235 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg8d73f8c2017-03-08 01:52:20 -0800236 channel()->SetChannelOutputVolumeScaling(scaling);
solenberg217fb662016-06-17 08:30:54 -0700237}
238
ivoc14d5dbe2016-07-04 07:06:55 -0700239void ChannelProxy::SetRtcEventLog(RtcEventLog* event_log) {
solenberg08b19df2017-02-15 00:42:31 -0800240 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
ivoc14d5dbe2016-07-04 07:06:55 -0700241 channel()->SetRtcEventLog(event_log);
242}
243
aleloi6c278492016-10-20 14:24:39 -0700244AudioMixer::Source::AudioFrameInfo ChannelProxy::GetAudioFrameWithInfo(
245 int sample_rate_hz,
246 AudioFrame* audio_frame) {
solenberg08b19df2017-02-15 00:42:31 -0800247 RTC_DCHECK_RUNS_SERIALIZED(&audio_thread_race_checker_);
aleloi6c278492016-10-20 14:24:39 -0700248 return channel()->GetAudioFrameWithInfo(sample_rate_hz, audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700249}
250
aleloi051f6782016-10-31 03:26:40 -0700251int ChannelProxy::NeededFrequency() const {
solenberg08b19df2017-02-15 00:42:31 -0800252 RTC_DCHECK_RUNS_SERIALIZED(&audio_thread_race_checker_);
aleloi051f6782016-10-31 03:26:40 -0700253 return static_cast<int>(channel()->NeededFrequency(-1));
254}
255
michaelt79e05882016-11-08 02:50:09 -0800256void ChannelProxy::SetTransportOverhead(int transport_overhead_per_packet) {
solenberg08b19df2017-02-15 00:42:31 -0800257 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
michaelt79e05882016-11-08 02:50:09 -0800258 channel()->SetTransportOverhead(transport_overhead_per_packet);
259}
260
solenberg7602aab2016-11-14 11:30:07 -0800261void ChannelProxy::AssociateSendChannel(
262 const ChannelProxy& send_channel_proxy) {
solenberg08b19df2017-02-15 00:42:31 -0800263 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg7602aab2016-11-14 11:30:07 -0800264 channel()->set_associate_send_channel(send_channel_proxy.channel_owner_);
265}
266
267void ChannelProxy::DisassociateSendChannel() {
solenberg08b19df2017-02-15 00:42:31 -0800268 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenberg7602aab2016-11-14 11:30:07 -0800269 channel()->set_associate_send_channel(ChannelOwner(nullptr));
270}
271
solenberg3ebbcb52017-01-31 03:58:40 -0800272void ChannelProxy::GetRtpRtcp(RtpRtcp** rtp_rtcp,
273 RtpReceiver** rtp_receiver) const {
solenberg08b19df2017-02-15 00:42:31 -0800274 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread());
solenberg3ebbcb52017-01-31 03:58:40 -0800275 RTC_DCHECK(rtp_rtcp);
276 RTC_DCHECK(rtp_receiver);
277 int error = channel()->GetRtpRtcp(rtp_rtcp, rtp_receiver);
278 RTC_DCHECK_EQ(0, error);
279}
280
solenberg3ebbcb52017-01-31 03:58:40 -0800281uint32_t ChannelProxy::GetPlayoutTimestamp() const {
solenberg08b19df2017-02-15 00:42:31 -0800282 RTC_DCHECK_RUNS_SERIALIZED(&video_capture_thread_race_checker_);
solenberg3ebbcb52017-01-31 03:58:40 -0800283 unsigned int timestamp = 0;
284 int error = channel()->GetPlayoutTimestamp(timestamp);
285 RTC_DCHECK(!error || timestamp == 0);
286 return timestamp;
287}
288
289void ChannelProxy::SetMinimumPlayoutDelay(int delay_ms) {
solenberg08b19df2017-02-15 00:42:31 -0800290 RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread());
solenberg3ebbcb52017-01-31 03:58:40 -0800291 // Limit to range accepted by both VoE and ACM, so we're at least getting as
292 // close as possible, instead of failing.
293 delay_ms = std::max(0, std::min(delay_ms, 10000));
294 int error = channel()->SetMinimumPlayoutDelay(delay_ms);
solenberg0335e6c2017-02-22 07:07:04 -0800295 if (0 != error) {
296 LOG(LS_WARNING) << "Error setting minimum playout delay.";
297 }
solenberg3ebbcb52017-01-31 03:58:40 -0800298}
299
michaelt9332b7d2016-11-30 07:51:13 -0800300void ChannelProxy::SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats) {
solenberg08b19df2017-02-15 00:42:31 -0800301 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
michaelt9332b7d2016-11-30 07:51:13 -0800302 channel()->SetRtcpRttStats(rtcp_rtt_stats);
303}
304
solenbergbd9a77f2017-02-06 12:53:57 -0800305bool ChannelProxy::GetRecCodec(CodecInst* codec_inst) const {
solenberg08b19df2017-02-15 00:42:31 -0800306 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
solenbergbd9a77f2017-02-06 12:53:57 -0800307 return channel()->GetRecCodec(*codec_inst) == 0;
308}
309
elad.alond12a8e12017-03-23 11:04:48 -0700310void ChannelProxy::OnTwccBasedUplinkPacketLossRate(float packet_loss_rate) {
elad.alon4e764512017-03-27 08:53:11 -0700311 // TODO(elad.alon): This fails in UT; fix and uncomment.
312 // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=7405
313 // RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
elad.alond12a8e12017-03-23 11:04:48 -0700314 channel()->OnTwccBasedUplinkPacketLossRate(packet_loss_rate);
315}
316
elad.alondadb4dc2017-03-23 15:29:50 -0700317void ChannelProxy::OnRecoverableUplinkPacketLossRate(
318 float recoverable_packet_loss_rate) {
319 // TODO(elad.alon): This fails in UT; fix and uncomment.
elad.alon4e764512017-03-27 08:53:11 -0700320 // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=7405
elad.alondadb4dc2017-03-23 15:29:50 -0700321 // RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
322 channel()->OnRecoverableUplinkPacketLossRate(recoverable_packet_loss_rate);
323}
324
kwiberg1c07c702017-03-27 07:15:49 -0700325void ChannelProxy::RegisterLegacyReceiveCodecs() {
326 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
327 channel()->RegisterLegacyReceiveCodecs();
328}
329
hbos8d609f62017-04-10 07:39:05 -0700330std::vector<RtpSource> ChannelProxy::GetSources() const {
331 RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
332 return channel()->GetSources();
333}
334
solenberg358057b2015-11-27 10:46:42 -0800335Channel* ChannelProxy::channel() const {
336 RTC_DCHECK(channel_owner_.channel());
337 return channel_owner_.channel();
338}
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100339
solenberg13725082015-11-25 08:16:52 -0800340} // namespace voe
341} // namespace webrtc