1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
/*
* Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "voice_engine/channel_proxy.h"
#include <utility>
#include "api/call/audio_sink.h"
#include "call/rtp_transport_controller_send_interface.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_minmax.h"
#include "voice_engine/channel.h"
namespace webrtc {
namespace voe {
ChannelProxy::ChannelProxy() : channel_owner_(nullptr) {}
ChannelProxy::ChannelProxy(const ChannelOwner& channel_owner) :
channel_owner_(channel_owner) {
RTC_CHECK(channel_owner_.channel());
module_process_thread_checker_.DetachFromThread();
}
ChannelProxy::~ChannelProxy() {}
bool ChannelProxy::SetEncoder(int payload_type,
std::unique_ptr<AudioEncoder> encoder) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
return channel()->SetEncoder(payload_type, std::move(encoder));
}
void ChannelProxy::ModifyEncoder(
rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->ModifyEncoder(modifier);
}
void ChannelProxy::SetRTCPStatus(bool enable) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->SetRTCPStatus(enable);
}
void ChannelProxy::SetLocalMID(const char* mid) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->SetLocalMID(mid);
}
void ChannelProxy::SetLocalSSRC(uint32_t ssrc) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
int error = channel()->SetLocalSSRC(ssrc);
RTC_DCHECK_EQ(0, error);
}
void ChannelProxy::SetRTCP_CNAME(const std::string& c_name) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
// Note: VoERTP_RTCP::SetRTCP_CNAME() accepts a char[256] array.
std::string c_name_limited = c_name.substr(0, 255);
int error = channel()->SetRTCP_CNAME(c_name_limited.c_str());
RTC_DCHECK_EQ(0, error);
}
void ChannelProxy::SetNACKStatus(bool enable, int max_packets) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->SetNACKStatus(enable, max_packets);
}
void ChannelProxy::SetSendAudioLevelIndicationStatus(bool enable, int id) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
int error = channel()->SetSendAudioLevelIndicationStatus(enable, id);
RTC_DCHECK_EQ(0, error);
}
void ChannelProxy::SetReceiveAudioLevelIndicationStatus(bool enable, int id,
bool isLevelSsrc) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
int error = channel()->SetReceiveAudioLevelIndicationStatus(enable, id,
isLevelSsrc);
RTC_DCHECK_EQ(0, error);
}
void ChannelProxy::SetReceiveCsrcAudioLevelIndicationStatus(bool enable, int id) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
int error = channel()->SetReceiveCsrcAudioLevelIndicationStatus(enable, id);
RTC_DCHECK_EQ(0, error);
}
void ChannelProxy::SetSendMIDStatus(bool enable, int id) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
int error = channel()->SetSendMIDStatus(enable, id);
RTC_DCHECK_EQ(0, error);
}
void ChannelProxy::EnableSendTransportSequenceNumber(int id) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->EnableSendTransportSequenceNumber(id);
}
void ChannelProxy::EnableReceiveTransportSequenceNumber(int id) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->EnableReceiveTransportSequenceNumber(id);
}
void ChannelProxy::RegisterSenderCongestionControlObjects(
RtpTransportControllerSendInterface* transport,
RtcpBandwidthObserver* bandwidth_observer) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->RegisterSenderCongestionControlObjects(transport,
bandwidth_observer);
}
void ChannelProxy::RegisterReceiverCongestionControlObjects(
PacketRouter* packet_router) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->RegisterReceiverCongestionControlObjects(packet_router);
}
void ChannelProxy::ResetSenderCongestionControlObjects() {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->ResetSenderCongestionControlObjects();
}
void ChannelProxy::ResetReceiverCongestionControlObjects() {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->ResetReceiverCongestionControlObjects();
}
bool ChannelProxy::GetRTCPPacketTypeCounters(RtcpPacketTypeCounter& stats)
{
//Called on STS Thread to get stats
//RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
return channel()->GetRTCPPacketTypeCounters(stats) == 0;
}
bool ChannelProxy::GetRTCPReceiverStatistics(int64_t* timestamp,
uint32_t* jitterMs,
uint32_t* cumulativeLost,
uint32_t* packetsReceived,
uint64_t* bytesReceived,
double* packetsFractionLost,
int64_t* rtt) const {
// No thread check necessary, we are synchronizing on the lock in StatsProxy
return channel()->GetRTCPReceiverStatistics(timestamp,
jitterMs,
cumulativeLost,
packetsReceived,
bytesReceived,
packetsFractionLost,
rtt);
}
CallStatistics ChannelProxy::GetRTCPStatistics() const {
// Since we (Mozilla) need to collect stats on STS, we can't
// use the thread-checker (which will want to be called on MainThread)
// without refactor of ExecuteStatsQuery_s().
// However, GetRTPStatistics internally locks in the SSRC()
// and statistician methods.
// RTC_DCHECK(thread_checker_.CalledOnValidThread());
CallStatistics stats = {0};
int error = channel()->GetRTPStatistics(stats);
RTC_DCHECK_EQ(0, error);
return stats;
}
int ChannelProxy::GetRTPStatistics(unsigned int& averageJitterMs,
unsigned int& cumulativeLost) const {
// Since we (Mozilla) need to collect stats on STS, we can't
// use the thread-checker (which will want to be called on MainThread)
// without refactor of ExecuteStatsQuery_s().
// However, GetRTPStatistics internally locks in the SSRC()
// and statistician methods. PlayoutFrequency() should also be safe.
// statistics_proxy_->GetStats() also locks
CallStatistics stats;
int result = channel()->GetRTPStatistics(stats);
int32_t playoutFrequency = channel()->GetPlayoutFrequency() / 1000;
if (playoutFrequency) {
averageJitterMs = stats.jitterSamples / playoutFrequency;
}
cumulativeLost = stats.cumulativeLost;
return result;
}
std::vector<ReportBlock> ChannelProxy::GetRemoteRTCPReportBlocks() const {
//Called on STS Thread to get stats
//RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
std::vector<webrtc::ReportBlock> blocks;
int error = channel()->GetRemoteRTCPReportBlocks(&blocks);
RTC_DCHECK_EQ(0, error);
return blocks;
}
NetworkStatistics ChannelProxy::GetNetworkStatistics() const {
//Called on STS Thread to get stats
//RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
NetworkStatistics stats = {0};
int error = channel()->GetNetworkStatistics(stats);
RTC_DCHECK_EQ(0, error);
return stats;
}
AudioDecodingCallStats ChannelProxy::GetDecodingCallStatistics() const {
//Called on STS Thread to get stats
//RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
AudioDecodingCallStats stats;
channel()->GetDecodingCallStatistics(&stats);
return stats;
}
ANAStats ChannelProxy::GetANAStatistics() const {
//Called on STS Thread to get stats
//RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
return channel()->GetANAStatistics();
}
int ChannelProxy::GetSpeechOutputLevel() const {
//Called on STS Thread to get stats
//RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
return channel()->GetSpeechOutputLevel();
}
int ChannelProxy::GetSpeechOutputLevelFullRange() const {
//Called on STS Thread to get stats
//RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
return channel()->GetSpeechOutputLevelFullRange();
}
double ChannelProxy::GetTotalOutputEnergy() const {
//Called on STS Thread to get stats
//RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
return channel()->GetTotalOutputEnergy();
}
double ChannelProxy::GetTotalOutputDuration() const {
//Called on STS Thread to get stats
//RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
return channel()->GetTotalOutputDuration();
}
uint32_t ChannelProxy::GetDelayEstimate() const {
//Called on STS Thread to get stats
//RTC_DCHECK(worker_thread_checker_.CalledOnValidThread() ||
// module_process_thread_checker_.CalledOnValidThread());
return channel()->GetDelayEstimate();
}
bool ChannelProxy::SetSendTelephoneEventPayloadType(int payload_type,
int payload_frequency) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
return channel()->SetSendTelephoneEventPayloadType(payload_type,
payload_frequency) == 0;
}
bool ChannelProxy::SendTelephoneEventOutband(int event, int duration_ms) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
return channel()->SendTelephoneEventOutband(event, duration_ms) == 0;
}
void ChannelProxy::SetBitrate(int bitrate_bps, int64_t probing_interval_ms) {
// This method can be called on the worker thread, module process thread
// or on a TaskQueue via VideoSendStreamImpl::OnEncoderConfigurationChanged.
// TODO(solenberg): Figure out a good way to check this or enforce calling
// rules.
// RTC_DCHECK(worker_thread_checker_.CalledOnValidThread() ||
// module_process_thread_checker_.CalledOnValidThread());
channel()->SetBitRate(bitrate_bps, probing_interval_ms);
}
void ChannelProxy::SetReceiveCodecs(
const std::map<int, SdpAudioFormat>& codecs) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->SetReceiveCodecs(codecs);
}
void ChannelProxy::SetSink(std::unique_ptr<AudioSinkInterface> sink) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->SetSink(std::move(sink));
}
void ChannelProxy::SetInputMute(bool muted) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->SetInputMute(muted);
}
void ChannelProxy::RegisterTransport(Transport* transport) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->RegisterTransport(transport);
}
void ChannelProxy::OnRtpPacket(const RtpPacketReceived& packet) {
// May be called on either worker thread or network thread.
channel()->OnRtpPacket(packet);
}
bool ChannelProxy::ReceivedRTCPPacket(const uint8_t* packet, size_t length) {
// May be called on either worker thread or network thread.
return channel()->ReceivedRTCPPacket(packet, length) == 0;
}
const rtc::scoped_refptr<AudioDecoderFactory>&
ChannelProxy::GetAudioDecoderFactory() const {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
return channel()->GetAudioDecoderFactory();
}
void ChannelProxy::SetChannelOutputVolumeScaling(float scaling) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->SetChannelOutputVolumeScaling(scaling);
}
void ChannelProxy::SetRtcEventLog(RtcEventLog* event_log) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->SetRtcEventLog(event_log);
}
AudioMixer::Source::AudioFrameInfo ChannelProxy::GetAudioFrameWithInfo(
int sample_rate_hz,
AudioFrame* audio_frame) {
RTC_DCHECK_RUNS_SERIALIZED(&audio_thread_race_checker_);
return channel()->GetAudioFrameWithInfo(sample_rate_hz, audio_frame);
}
int ChannelProxy::PreferredSampleRate() const {
RTC_DCHECK_RUNS_SERIALIZED(&audio_thread_race_checker_);
return channel()->PreferredSampleRate();
}
void ChannelProxy::SetTransportOverhead(int transport_overhead_per_packet) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->SetTransportOverhead(transport_overhead_per_packet);
}
void ChannelProxy::AssociateSendChannel(
const ChannelProxy& send_channel_proxy) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->set_associate_send_channel(send_channel_proxy.channel_owner_);
}
void ChannelProxy::DisassociateSendChannel() {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->set_associate_send_channel(ChannelOwner(nullptr));
}
void ChannelProxy::GetRtpRtcp(RtpRtcp** rtp_rtcp,
RtpReceiver** rtp_receiver) const {
RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread());
RTC_DCHECK(rtp_rtcp);
RTC_DCHECK(rtp_receiver);
int error = channel()->GetRtpRtcp(rtp_rtcp, rtp_receiver);
RTC_DCHECK_EQ(0, error);
}
uint32_t ChannelProxy::GetPlayoutTimestamp() const {
RTC_DCHECK_RUNS_SERIALIZED(&video_capture_thread_race_checker_);
unsigned int timestamp = 0;
int error = channel()->GetPlayoutTimestamp(timestamp);
RTC_DCHECK(!error || timestamp == 0);
return timestamp;
}
void ChannelProxy::SetMinimumPlayoutDelay(int delay_ms) {
RTC_DCHECK(module_process_thread_checker_.CalledOnValidThread());
// Limit to range accepted by both VoE and ACM, so we're at least getting as
// close as possible, instead of failing.
delay_ms = rtc::SafeClamp(delay_ms, 0, 10000);
int error = channel()->SetMinimumPlayoutDelay(delay_ms);
if (0 != error) {
RTC_LOG(LS_WARNING) << "Error setting minimum playout delay.";
}
}
void ChannelProxy::SetRtcpRttStats(RtcpRttStats* rtcp_rtt_stats) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->SetRtcpRttStats(rtcp_rtt_stats);
}
bool ChannelProxy::GetRecCodec(CodecInst* codec_inst) const {
//Called on STS Thread to get stats
//RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
return channel()->GetRecCodec(*codec_inst) == 0;
}
void ChannelProxy::OnTwccBasedUplinkPacketLossRate(float packet_loss_rate) {
//Called on STS Thread as a result of delivering a packet.
//OnTwccBasedUplinkPacketLossRate does its work using
//AudioCodingModuleImpl::ModifyEncoder, which takes a lock, so this should
//be safe.
//RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->OnTwccBasedUplinkPacketLossRate(packet_loss_rate);
}
void ChannelProxy::OnRecoverableUplinkPacketLossRate(
float recoverable_packet_loss_rate) {
//Called on STS Thread as a result of delivering a packet.
//OnRecoverableUplinkPacketLossRate does its work using
//AudioCodingModuleImpl::ModifyEncoder, which takes a lock, so this should
//be safe.
//RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->OnRecoverableUplinkPacketLossRate(recoverable_packet_loss_rate);
}
std::vector<RtpSource> ChannelProxy::GetSources() const {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
return channel()->GetSources();
}
void ChannelProxy::SetRtpPacketObserver(RtpPacketObserver* observer) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->SetRtpPacketObserver(observer);
}
void ChannelProxy::SetRtcpEventObserver(RtcpEventObserver* observer) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
channel()->SetRtcpEventObserver(observer);
}
Channel* ChannelProxy::channel() const {
RTC_DCHECK(channel_owner_.channel());
return channel_owner_.channel();
}
} // namespace voe
} // namespace webrtc
|