blob: a58b2e19557790c9248ae0133a714fa4d50729ae [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"
17#include "webrtc/voice_engine/channel.h"
18
19namespace webrtc {
20namespace voe {
21ChannelProxy::ChannelProxy() : channel_owner_(nullptr) {}
22
23ChannelProxy::ChannelProxy(const ChannelOwner& channel_owner) :
24 channel_owner_(channel_owner) {
25 RTC_CHECK(channel_owner_.channel());
26}
27
Tommif888bb52015-12-12 01:37:01 +010028ChannelProxy::~ChannelProxy() {}
29
solenberg13725082015-11-25 08:16:52 -080030void ChannelProxy::SetRTCPStatus(bool enable) {
solenberg358057b2015-11-27 10:46:42 -080031 channel()->SetRTCPStatus(enable);
solenberg13725082015-11-25 08:16:52 -080032}
33
34void ChannelProxy::SetLocalSSRC(uint32_t ssrc) {
solenberg358057b2015-11-27 10:46:42 -080035 RTC_DCHECK(thread_checker_.CalledOnValidThread());
36 int error = channel()->SetLocalSSRC(ssrc);
solenberg13725082015-11-25 08:16:52 -080037 RTC_DCHECK_EQ(0, error);
38}
39
40void ChannelProxy::SetRTCP_CNAME(const std::string& c_name) {
solenberg358057b2015-11-27 10:46:42 -080041 RTC_DCHECK(thread_checker_.CalledOnValidThread());
solenberg13725082015-11-25 08:16:52 -080042 // Note: VoERTP_RTCP::SetRTCP_CNAME() accepts a char[256] array.
43 std::string c_name_limited = c_name.substr(0, 255);
solenberg358057b2015-11-27 10:46:42 -080044 int error = channel()->SetRTCP_CNAME(c_name_limited.c_str());
solenberg13725082015-11-25 08:16:52 -080045 RTC_DCHECK_EQ(0, error);
46}
solenberg358057b2015-11-27 10:46:42 -080047
solenberg971cab02016-06-14 10:02:41 -070048void ChannelProxy::SetNACKStatus(bool enable, int max_packets) {
49 RTC_DCHECK(thread_checker_.CalledOnValidThread());
50 channel()->SetNACKStatus(enable, max_packets);
51}
52
solenberg358057b2015-11-27 10:46:42 -080053void ChannelProxy::SetSendAudioLevelIndicationStatus(bool enable, int id) {
54 RTC_DCHECK(thread_checker_.CalledOnValidThread());
55 int error = channel()->SetSendAudioLevelIndicationStatus(enable, id);
56 RTC_DCHECK_EQ(0, error);
57}
58
solenberg358057b2015-11-27 10:46:42 -080059void ChannelProxy::SetReceiveAudioLevelIndicationStatus(bool enable, int id) {
60 RTC_DCHECK(thread_checker_.CalledOnValidThread());
61 int error = channel()->SetReceiveAudioLevelIndicationStatus(enable, id);
62 RTC_DCHECK_EQ(0, error);
63}
64
stefan3313ec92016-01-21 06:32:43 -080065void ChannelProxy::EnableSendTransportSequenceNumber(int id) {
66 RTC_DCHECK(thread_checker_.CalledOnValidThread());
67 channel()->EnableSendTransportSequenceNumber(id);
68}
69
70void ChannelProxy::EnableReceiveTransportSequenceNumber(int id) {
71 RTC_DCHECK(thread_checker_.CalledOnValidThread());
72 channel()->EnableReceiveTransportSequenceNumber(id);
73}
74
stefanbba9dec2016-02-01 04:39:55 -080075void ChannelProxy::RegisterSenderCongestionControlObjects(
Stefan Holmerb86d4e42015-12-07 10:26:18 +010076 RtpPacketSender* rtp_packet_sender,
77 TransportFeedbackObserver* transport_feedback_observer,
stefan7de8d642017-02-07 07:14:08 -080078 PacketRouter* packet_router,
79 RtcpBandwidthObserver* bandwidth_observer) {
Stefan Holmerb86d4e42015-12-07 10:26:18 +010080 RTC_DCHECK(thread_checker_.CalledOnValidThread());
stefanbba9dec2016-02-01 04:39:55 -080081 channel()->RegisterSenderCongestionControlObjects(
stefan7de8d642017-02-07 07:14:08 -080082 rtp_packet_sender, transport_feedback_observer, packet_router,
83 bandwidth_observer);
Stefan Holmerb86d4e42015-12-07 10:26:18 +010084}
85
stefanbba9dec2016-02-01 04:39:55 -080086void ChannelProxy::RegisterReceiverCongestionControlObjects(
87 PacketRouter* packet_router) {
88 RTC_DCHECK(thread_checker_.CalledOnValidThread());
89 channel()->RegisterReceiverCongestionControlObjects(packet_router);
90}
91
92void ChannelProxy::ResetCongestionControlObjects() {
93 RTC_DCHECK(thread_checker_.CalledOnValidThread());
94 channel()->ResetCongestionControlObjects();
95}
96
solenberg358057b2015-11-27 10:46:42 -080097CallStatistics ChannelProxy::GetRTCPStatistics() const {
98 RTC_DCHECK(thread_checker_.CalledOnValidThread());
99 CallStatistics stats = {0};
100 int error = channel()->GetRTPStatistics(stats);
101 RTC_DCHECK_EQ(0, error);
102 return stats;
103}
104
105std::vector<ReportBlock> ChannelProxy::GetRemoteRTCPReportBlocks() const {
106 RTC_DCHECK(thread_checker_.CalledOnValidThread());
107 std::vector<webrtc::ReportBlock> blocks;
108 int error = channel()->GetRemoteRTCPReportBlocks(&blocks);
109 RTC_DCHECK_EQ(0, error);
110 return blocks;
111}
112
113NetworkStatistics ChannelProxy::GetNetworkStatistics() const {
114 RTC_DCHECK(thread_checker_.CalledOnValidThread());
115 NetworkStatistics stats = {0};
116 int error = channel()->GetNetworkStatistics(stats);
117 RTC_DCHECK_EQ(0, error);
118 return stats;
119}
120
121AudioDecodingCallStats ChannelProxy::GetDecodingCallStatistics() const {
122 RTC_DCHECK(thread_checker_.CalledOnValidThread());
123 AudioDecodingCallStats stats;
124 channel()->GetDecodingCallStatistics(&stats);
125 return stats;
126}
127
128int32_t ChannelProxy::GetSpeechOutputLevelFullRange() const {
129 RTC_DCHECK(thread_checker_.CalledOnValidThread());
130 uint32_t level = 0;
131 int error = channel()->GetSpeechOutputLevelFullRange(level);
132 RTC_DCHECK_EQ(0, error);
133 return static_cast<int32_t>(level);
134}
135
136uint32_t ChannelProxy::GetDelayEstimate() const {
137 RTC_DCHECK(thread_checker_.CalledOnValidThread());
138 return channel()->GetDelayEstimate();
139}
140
solenbergffbbcac2016-11-17 05:25:37 -0800141bool ChannelProxy::SetSendTelephoneEventPayloadType(int payload_type,
142 int payload_frequency) {
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100143 RTC_DCHECK(thread_checker_.CalledOnValidThread());
solenbergffbbcac2016-11-17 05:25:37 -0800144 return channel()->SetSendTelephoneEventPayloadType(payload_type,
145 payload_frequency) == 0;
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100146}
147
solenberg8842c3e2016-03-11 03:06:41 -0800148bool ChannelProxy::SendTelephoneEventOutband(int event, int duration_ms) {
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100149 RTC_DCHECK(thread_checker_.CalledOnValidThread());
solenberg8842c3e2016-03-11 03:06:41 -0800150 return channel()->SendTelephoneEventOutband(event, duration_ms) == 0;
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100151}
152
minyue78b4d562016-11-30 04:47:39 -0800153void ChannelProxy::SetBitrate(int bitrate_bps, int64_t probing_interval_ms) {
mflodman86cc6ff2016-07-26 04:44:06 -0700154 // May be called on different threads and needs to be handled by the channel.
minyue78b4d562016-11-30 04:47:39 -0800155 channel()->SetBitRate(bitrate_bps, probing_interval_ms);
mflodman86cc6ff2016-07-26 04:44:06 -0700156}
157
kwibergd32bf752017-01-19 07:03:59 -0800158void ChannelProxy::SetRecPayloadType(int payload_type,
159 const SdpAudioFormat& format) {
160 RTC_DCHECK(thread_checker_.CalledOnValidThread());
161 const int result = channel()->SetRecPayloadType(payload_type, format);
162 RTC_DCHECK_EQ(0, result);
163}
164
kwibergb7f89d62016-02-17 10:04:18 -0800165void ChannelProxy::SetSink(std::unique_ptr<AudioSinkInterface> sink) {
Tommif888bb52015-12-12 01:37:01 +0100166 RTC_DCHECK(thread_checker_.CalledOnValidThread());
deadbeef2d110be2016-01-13 12:00:26 -0800167 channel()->SetSink(std::move(sink));
Tommif888bb52015-12-12 01:37:01 +0100168}
169
solenberg94218532016-06-16 10:53:22 -0700170void ChannelProxy::SetInputMute(bool muted) {
171 RTC_DCHECK(thread_checker_.CalledOnValidThread());
172 int error = channel()->SetInputMute(muted);
173 RTC_DCHECK_EQ(0, error);
174}
175
mflodman3d7db262016-04-29 00:57:13 -0700176void ChannelProxy::RegisterExternalTransport(Transport* transport) {
177 RTC_DCHECK(thread_checker_.CalledOnValidThread());
178 int error = channel()->RegisterExternalTransport(transport);
179 RTC_DCHECK_EQ(0, error);
180}
181
182void ChannelProxy::DeRegisterExternalTransport() {
183 RTC_DCHECK(thread_checker_.CalledOnValidThread());
184 channel()->DeRegisterExternalTransport();
185}
186
187bool ChannelProxy::ReceivedRTPPacket(const uint8_t* packet,
188 size_t length,
189 const PacketTime& packet_time) {
190 // May be called on either worker thread or network thread.
191 return channel()->ReceivedRTPPacket(packet, length, packet_time) == 0;
192}
193
194bool ChannelProxy::ReceivedRTCPPacket(const uint8_t* packet, size_t length) {
195 // May be called on either worker thread or network thread.
196 return channel()->ReceivedRTCPPacket(packet, length) == 0;
197}
198
ossu29b1a8d2016-06-13 07:34:51 -0700199const rtc::scoped_refptr<AudioDecoderFactory>&
solenberg217fb662016-06-17 08:30:54 -0700200 ChannelProxy::GetAudioDecoderFactory() const {
201 RTC_DCHECK(thread_checker_.CalledOnValidThread());
ossu29b1a8d2016-06-13 07:34:51 -0700202 return channel()->GetAudioDecoderFactory();
203}
204
solenberg217fb662016-06-17 08:30:54 -0700205void ChannelProxy::SetChannelOutputVolumeScaling(float scaling) {
206 RTC_DCHECK(thread_checker_.CalledOnValidThread());
207 int error = channel()->SetChannelOutputVolumeScaling(scaling);
208 RTC_DCHECK_EQ(0, error);
209}
210
ivoc14d5dbe2016-07-04 07:06:55 -0700211void ChannelProxy::SetRtcEventLog(RtcEventLog* event_log) {
212 RTC_DCHECK(thread_checker_.CalledOnValidThread());
213 channel()->SetRtcEventLog(event_log);
214}
215
minyue6b825df2016-10-31 04:08:32 -0700216void ChannelProxy::EnableAudioNetworkAdaptor(const std::string& config_string) {
217 RTC_DCHECK(thread_checker_.CalledOnValidThread());
218 bool ret = channel()->EnableAudioNetworkAdaptor(config_string);
219 RTC_DCHECK(ret);
220;}
221
222void ChannelProxy::DisableAudioNetworkAdaptor() {
223 RTC_DCHECK(thread_checker_.CalledOnValidThread());
224 channel()->DisableAudioNetworkAdaptor();
225}
226
227void ChannelProxy::SetReceiverFrameLengthRange(int min_frame_length_ms,
228 int max_frame_length_ms) {
229 RTC_DCHECK(thread_checker_.CalledOnValidThread());
230 channel()->SetReceiverFrameLengthRange(min_frame_length_ms,
231 max_frame_length_ms);
232}
233
aleloi6c278492016-10-20 14:24:39 -0700234AudioMixer::Source::AudioFrameInfo ChannelProxy::GetAudioFrameWithInfo(
235 int sample_rate_hz,
236 AudioFrame* audio_frame) {
aleloiaed581a2016-10-20 06:32:39 -0700237 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
aleloi6c278492016-10-20 14:24:39 -0700238 return channel()->GetAudioFrameWithInfo(sample_rate_hz, audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700239}
240
aleloi051f6782016-10-31 03:26:40 -0700241int ChannelProxy::NeededFrequency() const {
242 return static_cast<int>(channel()->NeededFrequency(-1));
243}
244
michaelt79e05882016-11-08 02:50:09 -0800245void ChannelProxy::SetTransportOverhead(int transport_overhead_per_packet) {
246 RTC_DCHECK(thread_checker_.CalledOnValidThread());
247 channel()->SetTransportOverhead(transport_overhead_per_packet);
248}
249
solenberg7602aab2016-11-14 11:30:07 -0800250void ChannelProxy::AssociateSendChannel(
251 const ChannelProxy& send_channel_proxy) {
252 RTC_DCHECK(thread_checker_.CalledOnValidThread());
253 channel()->set_associate_send_channel(send_channel_proxy.channel_owner_);
254}
255
256void ChannelProxy::DisassociateSendChannel() {
257 RTC_DCHECK(thread_checker_.CalledOnValidThread());
258 channel()->set_associate_send_channel(ChannelOwner(nullptr));
259}
260
solenberg3ebbcb52017-01-31 03:58:40 -0800261void ChannelProxy::GetRtpRtcp(RtpRtcp** rtp_rtcp,
262 RtpReceiver** rtp_receiver) const {
263 // Called on Call's module_process_thread_.
264 RTC_DCHECK(rtp_rtcp);
265 RTC_DCHECK(rtp_receiver);
266 int error = channel()->GetRtpRtcp(rtp_rtcp, rtp_receiver);
267 RTC_DCHECK_EQ(0, error);
268}
269
270void ChannelProxy::GetDelayEstimate(int* jitter_buffer_delay_ms,
271 int* playout_buffer_delay_ms) const {
272 // Called on Call's module_process_thread_.
273 RTC_DCHECK(jitter_buffer_delay_ms);
274 RTC_DCHECK(playout_buffer_delay_ms);
275 bool error = channel()->GetDelayEstimate(jitter_buffer_delay_ms,
276 playout_buffer_delay_ms);
277 RTC_DCHECK(error);
278}
279
280uint32_t ChannelProxy::GetPlayoutTimestamp() const {
281 // Called on video capture thread.
282 unsigned int timestamp = 0;
283 int error = channel()->GetPlayoutTimestamp(timestamp);
284 RTC_DCHECK(!error || timestamp == 0);
285 return timestamp;
286}
287
288void ChannelProxy::SetMinimumPlayoutDelay(int delay_ms) {
289 // Called on Call's module_process_thread_.
290 // Limit to range accepted by both VoE and ACM, so we're at least getting as
291 // close as possible, instead of failing.
292 delay_ms = std::max(0, std::min(delay_ms, 10000));
293 int error = channel()->SetMinimumPlayoutDelay(delay_ms);
294 RTC_DCHECK_EQ(0, error);
295}
296
michaelt9332b7d2016-11-30 07:51:13 -0800297void ChannelProxy::SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats) {
298 RTC_DCHECK(thread_checker_.CalledOnValidThread());
299 channel()->SetRtcpRttStats(rtcp_rtt_stats);
300}
301
solenbergbd9a77f2017-02-06 12:53:57 -0800302bool ChannelProxy::GetRecCodec(CodecInst* codec_inst) const {
303 RTC_DCHECK(thread_checker_.CalledOnValidThread());
304 return channel()->GetRecCodec(*codec_inst) == 0;
305}
306
307bool ChannelProxy::GetSendCodec(CodecInst* codec_inst) const {
308 RTC_DCHECK(thread_checker_.CalledOnValidThread());
309 return channel()->GetSendCodec(*codec_inst) == 0;
310}
311
312bool ChannelProxy::SetVADStatus(bool enable) {
313 RTC_DCHECK(thread_checker_.CalledOnValidThread());
314 return channel()->SetVADStatus(enable, VADNormal, false) == 0;
315}
316
317bool ChannelProxy::SetCodecFECStatus(bool enable) {
318 RTC_DCHECK(thread_checker_.CalledOnValidThread());
319 return channel()->SetCodecFECStatus(enable) == 0;
320}
321
322bool ChannelProxy::SetOpusDtx(bool enable) {
323 RTC_DCHECK(thread_checker_.CalledOnValidThread());
324 return channel()->SetOpusDtx(enable) == 0;
325}
326
327bool ChannelProxy::SetOpusMaxPlaybackRate(int frequency_hz) {
328 RTC_DCHECK(thread_checker_.CalledOnValidThread());
329 return channel()->SetOpusMaxPlaybackRate(frequency_hz) == 0;
330}
331
332bool ChannelProxy::SetSendCodec(const CodecInst& codec_inst) {
333 RTC_DCHECK(thread_checker_.CalledOnValidThread());
334 // Validation code copied from VoECodecImpl::SetSendCodec().
335 if ((STR_CASE_CMP(codec_inst.plname, "L16") == 0) &&
336 (codec_inst.pacsize >= 960)) {
337 return false;
338 }
339 if (!STR_CASE_CMP(codec_inst.plname, "CN") ||
340 !STR_CASE_CMP(codec_inst.plname, "TELEPHONE-EVENT") ||
341 !STR_CASE_CMP(codec_inst.plname, "RED")) {
342 return false;
343 }
344 if ((codec_inst.channels != 1) && (codec_inst.channels != 2)) {
345 return false;
346 }
347 if (!AudioCodingModule::IsCodecValid(codec_inst)) {
348 return false;
349 }
350 return channel()->SetSendCodec(codec_inst) == 0;
351}
352
353bool ChannelProxy::SetSendCNPayloadType(int type,
354 PayloadFrequencies frequency) {
355 RTC_DCHECK(thread_checker_.CalledOnValidThread());
356 // Validation code copied from VoECodecImpl::SetSendCNPayloadType().
357 if (type < 96 || type > 127) {
358 // Only allow dynamic range: 96 to 127
359 return false;
360 }
361 if ((frequency != kFreq16000Hz) && (frequency != kFreq32000Hz)) {
362 // It is not possible to modify the payload type for CN/8000.
363 // We only allow modification of the CN payload type for CN/16000
364 // and CN/32000.
365 return false;
366 }
367 return channel()->SetSendCNPayloadType(type, frequency) == 0;
368}
369
solenberg358057b2015-11-27 10:46:42 -0800370Channel* ChannelProxy::channel() const {
371 RTC_DCHECK(channel_owner_.channel());
372 return channel_owner_.channel();
373}
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100374
solenberg13725082015-11-25 08:16:52 -0800375} // namespace voe
376} // namespace webrtc