blob: 9783fc8871ad7f2ca7e48104fbbe75d0e77e024b [file] [log] [blame]
turaj@webrtc.org7959e162013-09-12 18:30:26 +00001/*
2 * Copyright (c) 2013 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 "modules/audio_coding/acm2/acm_receiver.h"
turaj@webrtc.org7959e162013-09-12 18:30:26 +000012
Yves Gerey988cc082018-10-23 12:03:01 +020013#include <stdlib.h>
14#include <string.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
Yves Gerey988cc082018-10-23 12:03:01 +020016#include <cstdint>
turaj@webrtc.org7959e162013-09-12 18:30:26 +000017#include <vector>
18
Niels Möller2edab4c2018-10-22 09:48:08 +020019#include "absl/strings/match.h"
Yves Gerey988cc082018-10-23 12:03:01 +020020#include "api/audio/audio_frame.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "api/audio_codecs/audio_decoder.h"
Ivo Creusen3ce44a32019-10-31 14:38:11 +010022#include "api/neteq/custom_neteq_factory.h"
23#include "api/neteq/default_neteq_controller_factory.h"
24#include "api/neteq/neteq.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "modules/audio_coding/acm2/acm_resampler.h"
26#include "modules/audio_coding/acm2/call_statistics.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "rtc_base/checks.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "rtc_base/logging.h"
Karl Wiberge40468b2017-11-22 10:42:26 +010029#include "rtc_base/numerics/safe_conversions.h"
Jonas Olssonabbe8412018-04-03 13:40:05 +020030#include "rtc_base/strings/audio_format_to_string.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "system_wrappers/include/clock.h"
turaj@webrtc.org7959e162013-09-12 18:30:26 +000032
33namespace webrtc {
34
turaj@webrtc.org6d5d2482013-10-06 04:47:28 +000035namespace acm2 {
36
Ivo Creusen3ce44a32019-10-31 14:38:11 +010037namespace {
38
39std::unique_ptr<NetEq> CreateNetEq(
Ivo Creusenc3d1f9b2019-11-01 11:47:51 +010040 NetEqFactory* neteq_factory,
Ivo Creusen3ce44a32019-10-31 14:38:11 +010041 const NetEq::Config& config,
42 Clock* clock,
43 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) {
Ivo Creusenc3d1f9b2019-11-01 11:47:51 +010044 RTC_CHECK((neteq_factory == nullptr) || (decoder_factory.get() == nullptr))
45 << "Either a NetEqFactory or a AudioDecoderFactory should be injected, "
46 "supplying both is not supported. Please wrap the AudioDecoderFactory "
47 "inside the NetEqFactory when using both.";
48 if (neteq_factory) {
49 return neteq_factory->CreateNetEq(config, clock);
50 }
51 CustomNetEqFactory custom_factory(
Ivo Creusen3ce44a32019-10-31 14:38:11 +010052 decoder_factory, std::make_unique<DefaultNetEqControllerFactory>());
Ivo Creusenc3d1f9b2019-11-01 11:47:51 +010053 return custom_factory.CreateNetEq(config, clock);
Ivo Creusen3ce44a32019-10-31 14:38:11 +010054}
55
56} // namespace
57
henrik.lundin@webrtc.org0bc9b5a2014-04-29 08:09:31 +000058AcmReceiver::AcmReceiver(const AudioCodingModule::Config& config)
kwiberg6f0f6162016-09-20 03:07:46 -070059 : last_audio_buffer_(new int16_t[AudioFrame::kMaxDataSizeSamples]),
Ivo Creusenc3d1f9b2019-11-01 11:47:51 +010060 neteq_(CreateNetEq(config.neteq_factory,
61 config.neteq_config,
Ivo Creusen3ce44a32019-10-31 14:38:11 +010062 config.clock,
63 config.decoder_factory)),
henrik.lundin@webrtc.org0bc9b5a2014-04-29 08:09:31 +000064 clock_(config.clock),
henrik.lundin678c9032015-11-02 08:31:23 -080065 resampled_last_output_frame_(true) {
Henrik Lundin02ed2012017-06-08 09:03:55 +020066 RTC_DCHECK(clock_);
Henrik Lundin76c10672018-05-07 13:47:28 +020067 memset(last_audio_buffer_.get(), 0,
68 sizeof(int16_t) * AudioFrame::kMaxDataSizeSamples);
turaj@webrtc.org7959e162013-09-12 18:30:26 +000069}
70
Henrik Lundin6af93992017-06-14 14:13:02 +020071AcmReceiver::~AcmReceiver() = default;
turaj@webrtc.org7959e162013-09-12 18:30:26 +000072
73int AcmReceiver::SetMinimumDelay(int delay_ms) {
74 if (neteq_->SetMinimumDelay(delay_ms))
75 return 0;
Mirko Bonadei675513b2017-11-09 11:09:25 +010076 RTC_LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms;
turaj@webrtc.org7959e162013-09-12 18:30:26 +000077 return -1;
78}
79
turaj@webrtc.org7959e162013-09-12 18:30:26 +000080int AcmReceiver::SetMaximumDelay(int delay_ms) {
81 if (neteq_->SetMaximumDelay(delay_ms))
82 return 0;
Mirko Bonadei675513b2017-11-09 11:09:25 +010083 RTC_LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms;
turaj@webrtc.org7959e162013-09-12 18:30:26 +000084 return -1;
85}
86
Ruslan Burakov9bee67c2019-02-05 13:49:26 +010087bool AcmReceiver::SetBaseMinimumDelayMs(int delay_ms) {
88 return neteq_->SetBaseMinimumDelayMs(delay_ms);
89}
90
91int AcmReceiver::GetBaseMinimumDelayMs() const {
92 return neteq_->GetBaseMinimumDelayMs();
93}
94
Danil Chapovalovb6021232018-06-19 13:26:36 +020095absl::optional<int> AcmReceiver::last_packet_sample_rate_hz() const {
Tommi9090e0b2016-01-20 13:39:36 +010096 rtc::CritScope lock(&crit_sect_);
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +010097 if (!last_decoder_) {
98 return absl::nullopt;
99 }
Karl Wiberg4b644112019-10-11 09:37:42 +0200100 return last_decoder_->sample_rate_hz;
henrik.lundin057fb892015-11-23 08:19:52 -0800101}
102
henrik.lundind89814b2015-11-23 06:49:25 -0800103int AcmReceiver::last_output_sample_rate_hz() const {
104 return neteq_->last_output_sample_rate_hz();
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000105}
106
Niels Möllerafb5dbb2019-02-15 15:21:47 +0100107int AcmReceiver::InsertPacket(const RTPHeader& rtp_header,
kwibergee2bac22015-11-11 10:34:00 -0800108 rtc::ArrayView<const uint8_t> incoming_payload) {
henrik.lundinb8c55b12017-05-10 07:38:01 -0700109 if (incoming_payload.empty()) {
Niels Möllerafb5dbb2019-02-15 15:21:47 +0100110 neteq_->InsertEmptyPacket(rtp_header);
henrik.lundinb8c55b12017-05-10 07:38:01 -0700111 return 0;
112 }
113
Niels Möllerafb5dbb2019-02-15 15:21:47 +0100114 int payload_type = rtp_header.payloadType;
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +0100115 auto format = neteq_->GetDecoderFormat(payload_type);
Karl Wiberg4b644112019-10-11 09:37:42 +0200116 if (format && absl::EqualsIgnoreCase(format->sdp_format.name, "red")) {
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +0100117 // This is a RED packet. Get the format of the audio codec.
118 payload_type = incoming_payload[0] & 0x7f;
119 format = neteq_->GetDecoderFormat(payload_type);
120 }
121 if (!format) {
Jonas Olssona4d87372019-07-05 19:08:33 +0200122 RTC_LOG_F(LS_ERROR) << "Payload-type " << payload_type
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +0100123 << " is not registered.";
124 return -1;
125 }
126
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000127 {
Tommi9090e0b2016-01-20 13:39:36 +0100128 rtc::CritScope lock(&crit_sect_);
Karl Wiberg4b644112019-10-11 09:37:42 +0200129 if (absl::EqualsIgnoreCase(format->sdp_format.name, "cn")) {
130 if (last_decoder_ && last_decoder_->num_channels > 1) {
kwiberg6f0f6162016-09-20 03:07:46 -0700131 // This is a CNG and the audio codec is not mono, so skip pushing in
132 // packets into NetEq.
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000133 return 0;
kwiberg6f0f6162016-09-20 03:07:46 -0700134 }
135 } else {
Karl Wiberg4b644112019-10-11 09:37:42 +0200136 last_decoder_ = DecoderInfo{/*payload_type=*/payload_type,
137 /*sample_rate_hz=*/format->sample_rate_hz,
138 /*num_channels=*/format->num_channels,
139 /*sdp_format=*/std::move(format->sdp_format)};
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000140 }
henrik.lundin@webrtc.orga90abde2014-06-09 18:35:11 +0000141 } // |crit_sect_| is released.
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000142
Karl Wiberg45eb1352019-10-10 14:23:00 +0200143 if (neteq_->InsertPacket(rtp_header, incoming_payload) < 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100144 RTC_LOG(LERROR) << "AcmReceiver::InsertPacket "
Niels Möllerafb5dbb2019-02-15 15:21:47 +0100145 << static_cast<int>(rtp_header.payloadType)
Mirko Bonadei675513b2017-11-09 11:09:25 +0100146 << " Failed to insert packet";
henrik.lundin@webrtc.orgeecf5e62014-06-24 13:11:22 +0000147 return -1;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000148 }
149 return 0;
150}
151
henrik.lundin834a6ea2016-05-13 03:45:24 -0700152int AcmReceiver::GetAudio(int desired_freq_hz,
153 AudioFrame* audio_frame,
154 bool* muted) {
henrik.lundin63489782016-09-20 01:47:12 -0700155 RTC_DCHECK(muted);
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000156 // Accessing members, take the lock.
Tommi9090e0b2016-01-20 13:39:36 +0100157 rtc::CritScope lock(&crit_sect_);
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000158
henrik.lundin834a6ea2016-05-13 03:45:24 -0700159 if (neteq_->GetAudio(audio_frame, muted) != NetEq::kOK) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100160 RTC_LOG(LERROR) << "AcmReceiver::GetAudio - NetEq Failed.";
henrik.lundin@webrtc.orgeecf5e62014-06-24 13:11:22 +0000161 return -1;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000162 }
163
henrik.lundind89814b2015-11-23 06:49:25 -0800164 const int current_sample_rate_hz = neteq_->last_output_sample_rate_hz();
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000165
166 // Update if resampling is required.
henrik.lundind89814b2015-11-23 06:49:25 -0800167 const bool need_resampling =
168 (desired_freq_hz != -1) && (current_sample_rate_hz != desired_freq_hz);
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000169
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000170 if (need_resampling && !resampled_last_output_frame_) {
171 // Prime the resampler with the last frame.
172 int16_t temp_output[AudioFrame::kMaxDataSizeSamples];
henrik.lundind89814b2015-11-23 06:49:25 -0800173 int samples_per_channel_int = resampler_.Resample10Msec(
174 last_audio_buffer_.get(), current_sample_rate_hz, desired_freq_hz,
henrik.lundin6d8e0112016-03-04 10:34:21 -0800175 audio_frame->num_channels_, AudioFrame::kMaxDataSizeSamples,
176 temp_output);
Peter Kastingdce40cf2015-08-24 14:52:23 -0700177 if (samples_per_channel_int < 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100178 RTC_LOG(LERROR) << "AcmReceiver::GetAudio - "
179 "Resampling last_audio_buffer_ failed.";
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000180 return -1;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000181 }
182 }
183
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000184 // TODO(henrik.lundin) Glitches in the output may appear if the output rate
185 // from NetEq changes. See WebRTC issue 3923.
186 if (need_resampling) {
yujo36b1a5f2017-06-12 12:45:32 -0700187 // TODO(yujo): handle this more efficiently for muted frames.
henrik.lundind89814b2015-11-23 06:49:25 -0800188 int samples_per_channel_int = resampler_.Resample10Msec(
yujo36b1a5f2017-06-12 12:45:32 -0700189 audio_frame->data(), current_sample_rate_hz, desired_freq_hz,
henrik.lundin6d8e0112016-03-04 10:34:21 -0800190 audio_frame->num_channels_, AudioFrame::kMaxDataSizeSamples,
yujo36b1a5f2017-06-12 12:45:32 -0700191 audio_frame->mutable_data());
Peter Kastingdce40cf2015-08-24 14:52:23 -0700192 if (samples_per_channel_int < 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100193 RTC_LOG(LERROR)
194 << "AcmReceiver::GetAudio - Resampling audio_buffer_ failed.";
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000195 return -1;
196 }
henrik.lundin6d8e0112016-03-04 10:34:21 -0800197 audio_frame->samples_per_channel_ =
198 static_cast<size_t>(samples_per_channel_int);
199 audio_frame->sample_rate_hz_ = desired_freq_hz;
200 RTC_DCHECK_EQ(
201 audio_frame->sample_rate_hz_,
kwibergd3edd772017-03-01 18:52:48 -0800202 rtc::dchecked_cast<int>(audio_frame->samples_per_channel_ * 100));
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000203 resampled_last_output_frame_ = true;
204 } else {
205 resampled_last_output_frame_ = false;
206 // We might end up here ONLY if codec is changed.
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000207 }
208
henrik.lundin6d8e0112016-03-04 10:34:21 -0800209 // Store current audio in |last_audio_buffer_| for next time.
yujo36b1a5f2017-06-12 12:45:32 -0700210 memcpy(last_audio_buffer_.get(), audio_frame->data(),
henrik.lundin6d8e0112016-03-04 10:34:21 -0800211 sizeof(int16_t) * audio_frame->samples_per_channel_ *
212 audio_frame->num_channels_);
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000213
henrik.lundin63489782016-09-20 01:47:12 -0700214 call_stats_.DecodedByNetEq(audio_frame->speech_type_, *muted);
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000215 return 0;
216}
217
kwiberg1c07c702017-03-27 07:15:49 -0700218void AcmReceiver::SetCodecs(const std::map<int, SdpAudioFormat>& codecs) {
219 neteq_->SetCodecs(codecs);
220}
221
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000222void AcmReceiver::FlushBuffers() {
223 neteq_->FlushBuffers();
224}
225
kwiberg6b19b562016-09-20 04:02:25 -0700226void AcmReceiver::RemoveAllCodecs() {
Tommi9090e0b2016-01-20 13:39:36 +0100227 rtc::CritScope lock(&crit_sect_);
kwiberg6b19b562016-09-20 04:02:25 -0700228 neteq_->RemoveAllPayloadTypes();
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +0100229 last_decoder_ = absl::nullopt;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000230}
231
Danil Chapovalovb6021232018-06-19 13:26:36 +0200232absl::optional<uint32_t> AcmReceiver::GetPlayoutTimestamp() {
henrik.lundin9a410dd2016-04-06 01:39:22 -0700233 return neteq_->GetPlayoutTimestamp();
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000234}
235
henrik.lundinb3f1c5d2016-08-22 15:39:53 -0700236int AcmReceiver::FilteredCurrentDelayMs() const {
237 return neteq_->FilteredCurrentDelayMs();
238}
239
Henrik Lundinabbff892017-11-29 09:14:04 +0100240int AcmReceiver::TargetDelayMs() const {
241 return neteq_->TargetDelayMs();
242}
243
Jonas Olssona4d87372019-07-05 19:08:33 +0200244absl::optional<std::pair<int, SdpAudioFormat>> AcmReceiver::LastDecoder()
245 const {
Tommi9090e0b2016-01-20 13:39:36 +0100246 rtc::CritScope lock(&crit_sect_);
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +0100247 if (!last_decoder_) {
248 return absl::nullopt;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000249 }
Karl Wiberg4b644112019-10-11 09:37:42 +0200250 RTC_DCHECK_NE(-1, last_decoder_->payload_type);
251 return std::make_pair(last_decoder_->payload_type, last_decoder_->sdp_format);
ossue280cde2016-10-12 11:04:10 -0700252}
253
Niels Möllered44f542019-07-30 15:15:59 +0200254void AcmReceiver::GetNetworkStatistics(NetworkStatistics* acm_stat) const {
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000255 NetEqNetworkStatistics neteq_stat;
256 // NetEq function always returns zero, so we don't check the return value.
257 neteq_->NetworkStatistics(&neteq_stat);
258
259 acm_stat->currentBufferSize = neteq_stat.current_buffer_size_ms;
260 acm_stat->preferredBufferSize = neteq_stat.preferred_buffer_size_ms;
turaj@webrtc.org532f3dc2013-09-19 00:12:23 +0000261 acm_stat->jitterPeaksFound = neteq_stat.jitter_peaks_found ? true : false;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000262 acm_stat->currentPacketLossRate = neteq_stat.packet_loss_rate;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000263 acm_stat->currentExpandRate = neteq_stat.expand_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000264 acm_stat->currentSpeechExpandRate = neteq_stat.speech_expand_rate;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000265 acm_stat->currentPreemptiveRate = neteq_stat.preemptive_rate;
266 acm_stat->currentAccelerateRate = neteq_stat.accelerate_rate;
minyue@webrtc.orgc0bd7be2015-02-18 15:24:13 +0000267 acm_stat->currentSecondaryDecodedRate = neteq_stat.secondary_decoded_rate;
minyue-webrtc0c3ca752017-08-23 15:59:38 +0200268 acm_stat->currentSecondaryDiscardedRate = neteq_stat.secondary_discarded_rate;
henrik.lundin@webrtc.org20c71fd2014-04-22 10:11:21 +0000269 acm_stat->addedSamples = neteq_stat.added_zero_samples;
Henrik Lundin1bb8cf82015-08-25 13:08:04 +0200270 acm_stat->meanWaitingTimeMs = neteq_stat.mean_waiting_time_ms;
271 acm_stat->medianWaitingTimeMs = neteq_stat.median_waiting_time_ms;
272 acm_stat->minWaitingTimeMs = neteq_stat.min_waiting_time_ms;
273 acm_stat->maxWaitingTimeMs = neteq_stat.max_waiting_time_ms;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700274
275 NetEqLifetimeStatistics neteq_lifetime_stat = neteq_->GetLifetimeStatistics();
276 acm_stat->totalSamplesReceived = neteq_lifetime_stat.total_samples_received;
277 acm_stat->concealedSamples = neteq_lifetime_stat.concealed_samples;
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200278 acm_stat->silentConcealedSamples =
279 neteq_lifetime_stat.silent_concealed_samples;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200280 acm_stat->concealmentEvents = neteq_lifetime_stat.concealment_events;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200281 acm_stat->jitterBufferDelayMs = neteq_lifetime_stat.jitter_buffer_delay_ms;
Chen Xing0acffb52019-01-15 15:46:29 +0100282 acm_stat->jitterBufferEmittedCount =
283 neteq_lifetime_stat.jitter_buffer_emitted_count;
Jakob Ivarsson352ce5c2018-11-27 12:52:16 +0100284 acm_stat->delayedPacketOutageSamples =
285 neteq_lifetime_stat.delayed_packet_outage_samples;
Jakob Ivarsson232b3fd2019-03-06 09:18:40 +0100286 acm_stat->relativePacketArrivalDelayMs =
287 neteq_lifetime_stat.relative_packet_arrival_delay_ms;
Henrik Lundin44125fa2019-04-29 17:00:46 +0200288 acm_stat->interruptionCount = neteq_lifetime_stat.interruption_count;
289 acm_stat->totalInterruptionDurationMs =
290 neteq_lifetime_stat.total_interruption_duration_ms;
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200291 acm_stat->insertedSamplesForDeceleration =
292 neteq_lifetime_stat.inserted_samples_for_deceleration;
293 acm_stat->removedSamplesForAcceleration =
294 neteq_lifetime_stat.removed_samples_for_acceleration;
295 acm_stat->fecPacketsReceived = neteq_lifetime_stat.fec_packets_received;
296 acm_stat->fecPacketsDiscarded = neteq_lifetime_stat.fec_packets_discarded;
Ruslan Burakov8af88962018-11-22 17:21:10 +0100297
298 NetEqOperationsAndState neteq_operations_and_state =
299 neteq_->GetOperationsAndState();
300 acm_stat->packetBufferFlushes =
301 neteq_operations_and_state.packet_buffer_flushes;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000302}
303
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000304int AcmReceiver::EnableNack(size_t max_nack_list_size) {
henrik.lundin48ed9302015-10-29 05:36:24 -0700305 neteq_->EnableNack(max_nack_list_size);
306 return 0;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000307}
308
309void AcmReceiver::DisableNack() {
henrik.lundin48ed9302015-10-29 05:36:24 -0700310 neteq_->DisableNack();
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000311}
312
313std::vector<uint16_t> AcmReceiver::GetNackList(
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000314 int64_t round_trip_time_ms) const {
henrik.lundin48ed9302015-10-29 05:36:24 -0700315 return neteq_->GetNackList(round_trip_time_ms);
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000316}
317
318void AcmReceiver::ResetInitialDelay() {
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000319 neteq_->SetMinimumDelay(0);
320 // TODO(turajs): Should NetEq Buffer be flushed?
321}
322
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000323uint32_t AcmReceiver::NowInTimestamp(int decoder_sampling_rate) const {
324 // Down-cast the time to (32-6)-bit since we only care about
325 // the least significant bits. (32-6) bits cover 2^(32-6) = 67108864 ms.
326 // We masked 6 most significant bits of 32-bit so there is no overflow in
327 // the conversion from milliseconds to timestamp.
Yves Gerey665174f2018-06-19 15:03:05 +0200328 const uint32_t now_in_ms =
329 static_cast<uint32_t>(clock_->TimeInMilliseconds() & 0x03ffffff);
330 return static_cast<uint32_t>((decoder_sampling_rate / 1000) * now_in_ms);
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000331}
332
wu@webrtc.org24301a62013-12-13 19:17:43 +0000333void AcmReceiver::GetDecodingCallStatistics(
334 AudioDecodingCallStats* stats) const {
Tommi9090e0b2016-01-20 13:39:36 +0100335 rtc::CritScope lock(&crit_sect_);
wu@webrtc.org24301a62013-12-13 19:17:43 +0000336 *stats = call_stats_.GetDecodingStatistics();
337}
338
turaj@webrtc.org6d5d2482013-10-06 04:47:28 +0000339} // namespace acm2
340
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000341} // namespace webrtc