blob: e5e3804b71c5ee0a6282be87865a3579c6768b08 [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,
78 PacketRouter* packet_router) {
79 RTC_DCHECK(thread_checker_.CalledOnValidThread());
stefanbba9dec2016-02-01 04:39:55 -080080 channel()->RegisterSenderCongestionControlObjects(
Stefan Holmerb86d4e42015-12-07 10:26:18 +010081 rtp_packet_sender, transport_feedback_observer, packet_router);
82}
83
stefanbba9dec2016-02-01 04:39:55 -080084void ChannelProxy::RegisterReceiverCongestionControlObjects(
85 PacketRouter* packet_router) {
86 RTC_DCHECK(thread_checker_.CalledOnValidThread());
87 channel()->RegisterReceiverCongestionControlObjects(packet_router);
88}
89
90void ChannelProxy::ResetCongestionControlObjects() {
91 RTC_DCHECK(thread_checker_.CalledOnValidThread());
92 channel()->ResetCongestionControlObjects();
93}
94
solenberg358057b2015-11-27 10:46:42 -080095CallStatistics ChannelProxy::GetRTCPStatistics() const {
96 RTC_DCHECK(thread_checker_.CalledOnValidThread());
97 CallStatistics stats = {0};
98 int error = channel()->GetRTPStatistics(stats);
99 RTC_DCHECK_EQ(0, error);
100 return stats;
101}
102
103std::vector<ReportBlock> ChannelProxy::GetRemoteRTCPReportBlocks() const {
104 RTC_DCHECK(thread_checker_.CalledOnValidThread());
105 std::vector<webrtc::ReportBlock> blocks;
106 int error = channel()->GetRemoteRTCPReportBlocks(&blocks);
107 RTC_DCHECK_EQ(0, error);
108 return blocks;
109}
110
111NetworkStatistics ChannelProxy::GetNetworkStatistics() const {
112 RTC_DCHECK(thread_checker_.CalledOnValidThread());
113 NetworkStatistics stats = {0};
114 int error = channel()->GetNetworkStatistics(stats);
115 RTC_DCHECK_EQ(0, error);
116 return stats;
117}
118
119AudioDecodingCallStats ChannelProxy::GetDecodingCallStatistics() const {
120 RTC_DCHECK(thread_checker_.CalledOnValidThread());
121 AudioDecodingCallStats stats;
122 channel()->GetDecodingCallStatistics(&stats);
123 return stats;
124}
125
126int32_t ChannelProxy::GetSpeechOutputLevelFullRange() const {
127 RTC_DCHECK(thread_checker_.CalledOnValidThread());
128 uint32_t level = 0;
129 int error = channel()->GetSpeechOutputLevelFullRange(level);
130 RTC_DCHECK_EQ(0, error);
131 return static_cast<int32_t>(level);
132}
133
134uint32_t ChannelProxy::GetDelayEstimate() const {
135 RTC_DCHECK(thread_checker_.CalledOnValidThread());
136 return channel()->GetDelayEstimate();
137}
138
solenbergffbbcac2016-11-17 05:25:37 -0800139bool ChannelProxy::SetSendTelephoneEventPayloadType(int payload_type,
140 int payload_frequency) {
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100141 RTC_DCHECK(thread_checker_.CalledOnValidThread());
solenbergffbbcac2016-11-17 05:25:37 -0800142 return channel()->SetSendTelephoneEventPayloadType(payload_type,
143 payload_frequency) == 0;
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100144}
145
solenberg8842c3e2016-03-11 03:06:41 -0800146bool ChannelProxy::SendTelephoneEventOutband(int event, int duration_ms) {
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100147 RTC_DCHECK(thread_checker_.CalledOnValidThread());
solenberg8842c3e2016-03-11 03:06:41 -0800148 return channel()->SendTelephoneEventOutband(event, duration_ms) == 0;
Fredrik Solenbergb5727682015-12-04 15:22:19 +0100149}
150
minyue78b4d562016-11-30 04:47:39 -0800151void ChannelProxy::SetBitrate(int bitrate_bps, int64_t probing_interval_ms) {
mflodman86cc6ff2016-07-26 04:44:06 -0700152 // May be called on different threads and needs to be handled by the channel.
minyue78b4d562016-11-30 04:47:39 -0800153 channel()->SetBitRate(bitrate_bps, probing_interval_ms);
mflodman86cc6ff2016-07-26 04:44:06 -0700154}
155
kwibergd32bf752017-01-19 07:03:59 -0800156void ChannelProxy::SetRecPayloadType(int payload_type,
157 const SdpAudioFormat& format) {
158 RTC_DCHECK(thread_checker_.CalledOnValidThread());
159 const int result = channel()->SetRecPayloadType(payload_type, format);
160 RTC_DCHECK_EQ(0, result);
161}
162
kwibergb7f89d62016-02-17 10:04:18 -0800163void ChannelProxy::SetSink(std::unique_ptr<AudioSinkInterface> sink) {
Tommif888bb52015-12-12 01:37:01 +0100164 RTC_DCHECK(thread_checker_.CalledOnValidThread());
deadbeef2d110be2016-01-13 12:00:26 -0800165 channel()->SetSink(std::move(sink));
Tommif888bb52015-12-12 01:37:01 +0100166}
167
solenberg94218532016-06-16 10:53:22 -0700168void ChannelProxy::SetInputMute(bool muted) {
169 RTC_DCHECK(thread_checker_.CalledOnValidThread());
170 int error = channel()->SetInputMute(muted);
171 RTC_DCHECK_EQ(0, error);
172}
173
mflodman3d7db262016-04-29 00:57:13 -0700174void ChannelProxy::RegisterExternalTransport(Transport* transport) {
175 RTC_DCHECK(thread_checker_.CalledOnValidThread());
176 int error = channel()->RegisterExternalTransport(transport);
177 RTC_DCHECK_EQ(0, error);
178}
179
180void ChannelProxy::DeRegisterExternalTransport() {
181 RTC_DCHECK(thread_checker_.CalledOnValidThread());
182 channel()->DeRegisterExternalTransport();
183}
184
185bool ChannelProxy::ReceivedRTPPacket(const uint8_t* packet,
186 size_t length,
187 const PacketTime& packet_time) {
188 // May be called on either worker thread or network thread.
189 return channel()->ReceivedRTPPacket(packet, length, packet_time) == 0;
190}
191
192bool ChannelProxy::ReceivedRTCPPacket(const uint8_t* packet, size_t length) {
193 // May be called on either worker thread or network thread.
194 return channel()->ReceivedRTCPPacket(packet, length) == 0;
195}
196
ossu29b1a8d2016-06-13 07:34:51 -0700197const rtc::scoped_refptr<AudioDecoderFactory>&
solenberg217fb662016-06-17 08:30:54 -0700198 ChannelProxy::GetAudioDecoderFactory() const {
199 RTC_DCHECK(thread_checker_.CalledOnValidThread());
ossu29b1a8d2016-06-13 07:34:51 -0700200 return channel()->GetAudioDecoderFactory();
201}
202
solenberg217fb662016-06-17 08:30:54 -0700203void ChannelProxy::SetChannelOutputVolumeScaling(float scaling) {
204 RTC_DCHECK(thread_checker_.CalledOnValidThread());
205 int error = channel()->SetChannelOutputVolumeScaling(scaling);
206 RTC_DCHECK_EQ(0, error);
207}
208
ivoc14d5dbe2016-07-04 07:06:55 -0700209void ChannelProxy::SetRtcEventLog(RtcEventLog* event_log) {
210 RTC_DCHECK(thread_checker_.CalledOnValidThread());
211 channel()->SetRtcEventLog(event_log);
212}
213
minyue6b825df2016-10-31 04:08:32 -0700214void ChannelProxy::EnableAudioNetworkAdaptor(const std::string& config_string) {
215 RTC_DCHECK(thread_checker_.CalledOnValidThread());
216 bool ret = channel()->EnableAudioNetworkAdaptor(config_string);
217 RTC_DCHECK(ret);
218;}
219
220void ChannelProxy::DisableAudioNetworkAdaptor() {
221 RTC_DCHECK(thread_checker_.CalledOnValidThread());
222 channel()->DisableAudioNetworkAdaptor();
223}
224
225void ChannelProxy::SetReceiverFrameLengthRange(int min_frame_length_ms,
226 int max_frame_length_ms) {
227 RTC_DCHECK(thread_checker_.CalledOnValidThread());
228 channel()->SetReceiverFrameLengthRange(min_frame_length_ms,
229 max_frame_length_ms);
230}
231
aleloi6c278492016-10-20 14:24:39 -0700232AudioMixer::Source::AudioFrameInfo ChannelProxy::GetAudioFrameWithInfo(
233 int sample_rate_hz,
234 AudioFrame* audio_frame) {
aleloiaed581a2016-10-20 06:32:39 -0700235 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
aleloi6c278492016-10-20 14:24:39 -0700236 return channel()->GetAudioFrameWithInfo(sample_rate_hz, audio_frame);
aleloiaed581a2016-10-20 06:32:39 -0700237}
238
aleloi051f6782016-10-31 03:26:40 -0700239int ChannelProxy::NeededFrequency() const {
240 return static_cast<int>(channel()->NeededFrequency(-1));
241}
242
michaelt79e05882016-11-08 02:50:09 -0800243void ChannelProxy::SetTransportOverhead(int transport_overhead_per_packet) {
244 RTC_DCHECK(thread_checker_.CalledOnValidThread());
245 channel()->SetTransportOverhead(transport_overhead_per_packet);
246}
247
solenberg7602aab2016-11-14 11:30:07 -0800248void ChannelProxy::AssociateSendChannel(
249 const ChannelProxy& send_channel_proxy) {
250 RTC_DCHECK(thread_checker_.CalledOnValidThread());
251 channel()->set_associate_send_channel(send_channel_proxy.channel_owner_);
252}
253
254void ChannelProxy::DisassociateSendChannel() {
255 RTC_DCHECK(thread_checker_.CalledOnValidThread());
256 channel()->set_associate_send_channel(ChannelOwner(nullptr));
257}
258
solenberg3ebbcb52017-01-31 03:58:40 -0800259void ChannelProxy::GetRtpRtcp(RtpRtcp** rtp_rtcp,
260 RtpReceiver** rtp_receiver) const {
261 // Called on Call's module_process_thread_.
262 RTC_DCHECK(rtp_rtcp);
263 RTC_DCHECK(rtp_receiver);
264 int error = channel()->GetRtpRtcp(rtp_rtcp, rtp_receiver);
265 RTC_DCHECK_EQ(0, error);
266}
267
268void ChannelProxy::GetDelayEstimate(int* jitter_buffer_delay_ms,
269 int* playout_buffer_delay_ms) const {
270 // Called on Call's module_process_thread_.
271 RTC_DCHECK(jitter_buffer_delay_ms);
272 RTC_DCHECK(playout_buffer_delay_ms);
273 bool error = channel()->GetDelayEstimate(jitter_buffer_delay_ms,
274 playout_buffer_delay_ms);
275 RTC_DCHECK(error);
276}
277
278uint32_t ChannelProxy::GetPlayoutTimestamp() const {
279 // Called on video capture thread.
280 unsigned int timestamp = 0;
281 int error = channel()->GetPlayoutTimestamp(timestamp);
282 RTC_DCHECK(!error || timestamp == 0);
283 return timestamp;
284}
285
286void ChannelProxy::SetMinimumPlayoutDelay(int delay_ms) {
287 // Called on Call's module_process_thread_.
288 // Limit to range accepted by both VoE and ACM, so we're at least getting as
289 // close as possible, instead of failing.
290 delay_ms = std::max(0, std::min(delay_ms, 10000));
291 int error = channel()->SetMinimumPlayoutDelay(delay_ms);
292 RTC_DCHECK_EQ(0, error);
293}
294
michaelt9332b7d2016-11-30 07:51:13 -0800295void ChannelProxy::SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats) {
296 RTC_DCHECK(thread_checker_.CalledOnValidThread());
297 channel()->SetRtcpRttStats(rtcp_rtt_stats);
298}
299
solenbergbd9a77f2017-02-06 12:53:57 -0800300bool ChannelProxy::GetRecCodec(CodecInst* codec_inst) const {
301 RTC_DCHECK(thread_checker_.CalledOnValidThread());
302 return channel()->GetRecCodec(*codec_inst) == 0;
303}
304
305bool ChannelProxy::GetSendCodec(CodecInst* codec_inst) const {
306 RTC_DCHECK(thread_checker_.CalledOnValidThread());
307 return channel()->GetSendCodec(*codec_inst) == 0;
308}
309
310bool ChannelProxy::SetVADStatus(bool enable) {
311 RTC_DCHECK(thread_checker_.CalledOnValidThread());
312 return channel()->SetVADStatus(enable, VADNormal, false) == 0;
313}
314
315bool ChannelProxy::SetCodecFECStatus(bool enable) {
316 RTC_DCHECK(thread_checker_.CalledOnValidThread());
317 return channel()->SetCodecFECStatus(enable) == 0;
318}
319
320bool ChannelProxy::SetOpusDtx(bool enable) {
321 RTC_DCHECK(thread_checker_.CalledOnValidThread());
322 return channel()->SetOpusDtx(enable) == 0;
323}
324
325bool ChannelProxy::SetOpusMaxPlaybackRate(int frequency_hz) {
326 RTC_DCHECK(thread_checker_.CalledOnValidThread());
327 return channel()->SetOpusMaxPlaybackRate(frequency_hz) == 0;
328}
329
330bool ChannelProxy::SetSendCodec(const CodecInst& codec_inst) {
331 RTC_DCHECK(thread_checker_.CalledOnValidThread());
332 // Validation code copied from VoECodecImpl::SetSendCodec().
333 if ((STR_CASE_CMP(codec_inst.plname, "L16") == 0) &&
334 (codec_inst.pacsize >= 960)) {
335 return false;
336 }
337 if (!STR_CASE_CMP(codec_inst.plname, "CN") ||
338 !STR_CASE_CMP(codec_inst.plname, "TELEPHONE-EVENT") ||
339 !STR_CASE_CMP(codec_inst.plname, "RED")) {
340 return false;
341 }
342 if ((codec_inst.channels != 1) && (codec_inst.channels != 2)) {
343 return false;
344 }
345 if (!AudioCodingModule::IsCodecValid(codec_inst)) {
346 return false;
347 }
348 return channel()->SetSendCodec(codec_inst) == 0;
349}
350
351bool ChannelProxy::SetSendCNPayloadType(int type,
352 PayloadFrequencies frequency) {
353 RTC_DCHECK(thread_checker_.CalledOnValidThread());
354 // Validation code copied from VoECodecImpl::SetSendCNPayloadType().
355 if (type < 96 || type > 127) {
356 // Only allow dynamic range: 96 to 127
357 return false;
358 }
359 if ((frequency != kFreq16000Hz) && (frequency != kFreq32000Hz)) {
360 // It is not possible to modify the payload type for CN/8000.
361 // We only allow modification of the CN payload type for CN/16000
362 // and CN/32000.
363 return false;
364 }
365 return channel()->SetSendCNPayloadType(type, frequency) == 0;
366}
367
solenberg358057b2015-11-27 10:46:42 -0800368Channel* ChannelProxy::channel() const {
369 RTC_DCHECK(channel_owner_.channel());
370 return channel_owner_.channel();
371}
Stefan Holmerb86d4e42015-12-07 10:26:18 +0100372
solenberg13725082015-11-25 08:16:52 -0800373} // namespace voe
374} // namespace webrtc