blob: a77e472ec1107a22320e20e13ccba685430dd0e0 [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/neteq.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "modules/audio_coding/acm2/acm_resampler.h"
24#include "modules/audio_coding/acm2/call_statistics.h"
Ivo Creusen68c65722019-11-26 12:29:05 +010025#include "modules/audio_coding/neteq/default_neteq_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "rtc_base/checks.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "rtc_base/logging.h"
Karl Wiberge40468b2017-11-22 10:42:26 +010028#include "rtc_base/numerics/safe_conversions.h"
Jonas Olssonabbe8412018-04-03 13:40:05 +020029#include "rtc_base/strings/audio_format_to_string.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "system_wrappers/include/clock.h"
turaj@webrtc.org7959e162013-09-12 18:30:26 +000031
32namespace webrtc {
33
turaj@webrtc.org6d5d2482013-10-06 04:47:28 +000034namespace acm2 {
35
Ivo Creusen3ce44a32019-10-31 14:38:11 +010036namespace {
37
38std::unique_ptr<NetEq> CreateNetEq(
Ivo Creusenc3d1f9b2019-11-01 11:47:51 +010039 NetEqFactory* neteq_factory,
Ivo Creusen3ce44a32019-10-31 14:38:11 +010040 const NetEq::Config& config,
41 Clock* clock,
42 const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory) {
Ivo Creusenc3d1f9b2019-11-01 11:47:51 +010043 if (neteq_factory) {
Ivo Creusen68c65722019-11-26 12:29:05 +010044 return neteq_factory->CreateNetEq(config, decoder_factory, clock);
Ivo Creusenc3d1f9b2019-11-01 11:47:51 +010045 }
Ivo Creusen68c65722019-11-26 12:29:05 +010046 return DefaultNetEqFactory().CreateNetEq(config, decoder_factory, clock);
Ivo Creusen3ce44a32019-10-31 14:38:11 +010047}
48
49} // namespace
50
Henrik Lundin35417322023-01-31 08:40:56 +000051AcmReceiver::Config::Config(
52 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory)
53 : clock(*Clock::GetRealTimeClock()), decoder_factory(decoder_factory) {
54 // Post-decode VAD is disabled by default in NetEq, however, Audio
55 // Conference Mixer relies on VAD decisions and fails without them.
56 neteq_config.enable_post_decode_vad = true;
57}
58
Henrik Lundin35417322023-01-31 08:40:56 +000059AcmReceiver::Config::Config(const Config&) = default;
60AcmReceiver::Config::~Config() = default;
61
62AcmReceiver::AcmReceiver(const Config& config)
kwiberg6f0f6162016-09-20 03:07:46 -070063 : last_audio_buffer_(new int16_t[AudioFrame::kMaxDataSizeSamples]),
Ivo Creusenc3d1f9b2019-11-01 11:47:51 +010064 neteq_(CreateNetEq(config.neteq_factory,
65 config.neteq_config,
Henrik Lundin35417322023-01-31 08:40:56 +000066 &config.clock,
Ivo Creusen3ce44a32019-10-31 14:38:11 +010067 config.decoder_factory)),
henrik.lundin@webrtc.org0bc9b5a2014-04-29 08:09:31 +000068 clock_(config.clock),
henrik.lundin678c9032015-11-02 08:31:23 -080069 resampled_last_output_frame_(true) {
Henrik Lundin76c10672018-05-07 13:47:28 +020070 memset(last_audio_buffer_.get(), 0,
71 sizeof(int16_t) * AudioFrame::kMaxDataSizeSamples);
turaj@webrtc.org7959e162013-09-12 18:30:26 +000072}
73
Henrik Lundin6af93992017-06-14 14:13:02 +020074AcmReceiver::~AcmReceiver() = default;
turaj@webrtc.org7959e162013-09-12 18:30:26 +000075
76int AcmReceiver::SetMinimumDelay(int delay_ms) {
77 if (neteq_->SetMinimumDelay(delay_ms))
78 return 0;
Harald Alvestrand5f341302021-11-24 10:01:32 +000079 RTC_LOG(LS_ERROR) << "AcmReceiver::SetExtraDelay " << delay_ms;
turaj@webrtc.org7959e162013-09-12 18:30:26 +000080 return -1;
81}
82
turaj@webrtc.org7959e162013-09-12 18:30:26 +000083int AcmReceiver::SetMaximumDelay(int delay_ms) {
84 if (neteq_->SetMaximumDelay(delay_ms))
85 return 0;
Harald Alvestrand5f341302021-11-24 10:01:32 +000086 RTC_LOG(LS_ERROR) << "AcmReceiver::SetExtraDelay " << delay_ms;
turaj@webrtc.org7959e162013-09-12 18:30:26 +000087 return -1;
88}
89
Ruslan Burakov9bee67c2019-02-05 13:49:26 +010090bool AcmReceiver::SetBaseMinimumDelayMs(int delay_ms) {
91 return neteq_->SetBaseMinimumDelayMs(delay_ms);
92}
93
94int AcmReceiver::GetBaseMinimumDelayMs() const {
95 return neteq_->GetBaseMinimumDelayMs();
96}
97
Danil Chapovalovb6021232018-06-19 13:26:36 +020098absl::optional<int> AcmReceiver::last_packet_sample_rate_hz() const {
Markus Handell0df0fae2020-07-07 15:53:34 +020099 MutexLock lock(&mutex_);
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +0100100 if (!last_decoder_) {
101 return absl::nullopt;
102 }
Karl Wiberg4b644112019-10-11 09:37:42 +0200103 return last_decoder_->sample_rate_hz;
henrik.lundin057fb892015-11-23 08:19:52 -0800104}
105
henrik.lundind89814b2015-11-23 06:49:25 -0800106int AcmReceiver::last_output_sample_rate_hz() const {
107 return neteq_->last_output_sample_rate_hz();
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000108}
109
Niels Möllerafb5dbb2019-02-15 15:21:47 +0100110int AcmReceiver::InsertPacket(const RTPHeader& rtp_header,
kwibergee2bac22015-11-11 10:34:00 -0800111 rtc::ArrayView<const uint8_t> incoming_payload) {
henrik.lundinb8c55b12017-05-10 07:38:01 -0700112 if (incoming_payload.empty()) {
Niels Möllerafb5dbb2019-02-15 15:21:47 +0100113 neteq_->InsertEmptyPacket(rtp_header);
henrik.lundinb8c55b12017-05-10 07:38:01 -0700114 return 0;
115 }
116
Niels Möllerafb5dbb2019-02-15 15:21:47 +0100117 int payload_type = rtp_header.payloadType;
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +0100118 auto format = neteq_->GetDecoderFormat(payload_type);
Karl Wiberg4b644112019-10-11 09:37:42 +0200119 if (format && absl::EqualsIgnoreCase(format->sdp_format.name, "red")) {
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +0100120 // This is a RED packet. Get the format of the audio codec.
121 payload_type = incoming_payload[0] & 0x7f;
122 format = neteq_->GetDecoderFormat(payload_type);
123 }
124 if (!format) {
Jonas Olssona4d87372019-07-05 19:08:33 +0200125 RTC_LOG_F(LS_ERROR) << "Payload-type " << payload_type
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +0100126 << " is not registered.";
127 return -1;
128 }
129
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000130 {
Markus Handell0df0fae2020-07-07 15:53:34 +0200131 MutexLock lock(&mutex_);
Karl Wiberg4b644112019-10-11 09:37:42 +0200132 if (absl::EqualsIgnoreCase(format->sdp_format.name, "cn")) {
133 if (last_decoder_ && last_decoder_->num_channels > 1) {
kwiberg6f0f6162016-09-20 03:07:46 -0700134 // This is a CNG and the audio codec is not mono, so skip pushing in
135 // packets into NetEq.
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000136 return 0;
kwiberg6f0f6162016-09-20 03:07:46 -0700137 }
138 } else {
Karl Wiberg4b644112019-10-11 09:37:42 +0200139 last_decoder_ = DecoderInfo{/*payload_type=*/payload_type,
140 /*sample_rate_hz=*/format->sample_rate_hz,
141 /*num_channels=*/format->num_channels,
142 /*sdp_format=*/std::move(format->sdp_format)};
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000143 }
Artem Titovd00ce742021-07-28 20:00:17 +0200144 } // `mutex_` is released.
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000145
Karl Wiberg45eb1352019-10-10 14:23:00 +0200146 if (neteq_->InsertPacket(rtp_header, incoming_payload) < 0) {
Harald Alvestrand5f341302021-11-24 10:01:32 +0000147 RTC_LOG(LS_ERROR) << "AcmReceiver::InsertPacket "
148 << static_cast<int>(rtp_header.payloadType)
149 << " Failed to insert packet";
henrik.lundin@webrtc.orgeecf5e62014-06-24 13:11:22 +0000150 return -1;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000151 }
152 return 0;
153}
154
henrik.lundin834a6ea2016-05-13 03:45:24 -0700155int AcmReceiver::GetAudio(int desired_freq_hz,
156 AudioFrame* audio_frame,
157 bool* muted) {
henrik.lundin63489782016-09-20 01:47:12 -0700158 RTC_DCHECK(muted);
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000159
Tommi3cc68ec2021-06-09 19:30:41 +0200160 int current_sample_rate_hz = 0;
161 if (neteq_->GetAudio(audio_frame, muted, &current_sample_rate_hz) !=
162 NetEq::kOK) {
Harald Alvestrand5f341302021-11-24 10:01:32 +0000163 RTC_LOG(LS_ERROR) << "AcmReceiver::GetAudio - NetEq Failed.";
henrik.lundin@webrtc.orgeecf5e62014-06-24 13:11:22 +0000164 return -1;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000165 }
166
Tommi3cc68ec2021-06-09 19:30:41 +0200167 RTC_DCHECK_NE(current_sample_rate_hz, 0);
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000168
169 // Update if resampling is required.
henrik.lundind89814b2015-11-23 06:49:25 -0800170 const bool need_resampling =
171 (desired_freq_hz != -1) && (current_sample_rate_hz != desired_freq_hz);
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000172
Tommi3cc68ec2021-06-09 19:30:41 +0200173 // Accessing members, take the lock.
174 MutexLock lock(&mutex_);
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000175 if (need_resampling && !resampled_last_output_frame_) {
176 // Prime the resampler with the last frame.
177 int16_t temp_output[AudioFrame::kMaxDataSizeSamples];
henrik.lundind89814b2015-11-23 06:49:25 -0800178 int samples_per_channel_int = resampler_.Resample10Msec(
179 last_audio_buffer_.get(), current_sample_rate_hz, desired_freq_hz,
henrik.lundin6d8e0112016-03-04 10:34:21 -0800180 audio_frame->num_channels_, AudioFrame::kMaxDataSizeSamples,
181 temp_output);
Peter Kastingdce40cf2015-08-24 14:52:23 -0700182 if (samples_per_channel_int < 0) {
Harald Alvestrand5f341302021-11-24 10:01:32 +0000183 RTC_LOG(LS_ERROR) << "AcmReceiver::GetAudio - "
184 "Resampling last_audio_buffer_ failed.";
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000185 return -1;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000186 }
187 }
188
Tommi3cc68ec2021-06-09 19:30:41 +0200189 // TODO(bugs.webrtc.org/3923) Glitches in the output may appear if the output
190 // rate from NetEq changes.
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000191 if (need_resampling) {
yujo36b1a5f2017-06-12 12:45:32 -0700192 // TODO(yujo): handle this more efficiently for muted frames.
henrik.lundind89814b2015-11-23 06:49:25 -0800193 int samples_per_channel_int = resampler_.Resample10Msec(
yujo36b1a5f2017-06-12 12:45:32 -0700194 audio_frame->data(), current_sample_rate_hz, desired_freq_hz,
henrik.lundin6d8e0112016-03-04 10:34:21 -0800195 audio_frame->num_channels_, AudioFrame::kMaxDataSizeSamples,
yujo36b1a5f2017-06-12 12:45:32 -0700196 audio_frame->mutable_data());
Peter Kastingdce40cf2015-08-24 14:52:23 -0700197 if (samples_per_channel_int < 0) {
Harald Alvestrand5f341302021-11-24 10:01:32 +0000198 RTC_LOG(LS_ERROR)
Mirko Bonadei675513b2017-11-09 11:09:25 +0100199 << "AcmReceiver::GetAudio - Resampling audio_buffer_ failed.";
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000200 return -1;
201 }
henrik.lundin6d8e0112016-03-04 10:34:21 -0800202 audio_frame->samples_per_channel_ =
203 static_cast<size_t>(samples_per_channel_int);
204 audio_frame->sample_rate_hz_ = desired_freq_hz;
205 RTC_DCHECK_EQ(
206 audio_frame->sample_rate_hz_,
kwibergd3edd772017-03-01 18:52:48 -0800207 rtc::dchecked_cast<int>(audio_frame->samples_per_channel_ * 100));
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000208 resampled_last_output_frame_ = true;
209 } else {
210 resampled_last_output_frame_ = false;
211 // We might end up here ONLY if codec is changed.
henrik.lundin@webrtc.org913f7b82014-10-21 06:54:23 +0000212 }
213
Artem Titovd00ce742021-07-28 20:00:17 +0200214 // Store current audio in `last_audio_buffer_` for next time.
yujo36b1a5f2017-06-12 12:45:32 -0700215 memcpy(last_audio_buffer_.get(), audio_frame->data(),
henrik.lundin6d8e0112016-03-04 10:34:21 -0800216 sizeof(int16_t) * audio_frame->samples_per_channel_ *
217 audio_frame->num_channels_);
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000218
henrik.lundin63489782016-09-20 01:47:12 -0700219 call_stats_.DecodedByNetEq(audio_frame->speech_type_, *muted);
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000220 return 0;
221}
222
kwiberg1c07c702017-03-27 07:15:49 -0700223void AcmReceiver::SetCodecs(const std::map<int, SdpAudioFormat>& codecs) {
224 neteq_->SetCodecs(codecs);
225}
226
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000227void AcmReceiver::FlushBuffers() {
228 neteq_->FlushBuffers();
229}
230
kwiberg6b19b562016-09-20 04:02:25 -0700231void AcmReceiver::RemoveAllCodecs() {
Markus Handell0df0fae2020-07-07 15:53:34 +0200232 MutexLock lock(&mutex_);
kwiberg6b19b562016-09-20 04:02:25 -0700233 neteq_->RemoveAllPayloadTypes();
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +0100234 last_decoder_ = absl::nullopt;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000235}
236
Danil Chapovalovb6021232018-06-19 13:26:36 +0200237absl::optional<uint32_t> AcmReceiver::GetPlayoutTimestamp() {
henrik.lundin9a410dd2016-04-06 01:39:22 -0700238 return neteq_->GetPlayoutTimestamp();
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000239}
240
henrik.lundinb3f1c5d2016-08-22 15:39:53 -0700241int AcmReceiver::FilteredCurrentDelayMs() const {
242 return neteq_->FilteredCurrentDelayMs();
243}
244
Henrik Lundinabbff892017-11-29 09:14:04 +0100245int AcmReceiver::TargetDelayMs() const {
246 return neteq_->TargetDelayMs();
247}
248
Jonas Olssona4d87372019-07-05 19:08:33 +0200249absl::optional<std::pair<int, SdpAudioFormat>> AcmReceiver::LastDecoder()
250 const {
Markus Handell0df0fae2020-07-07 15:53:34 +0200251 MutexLock lock(&mutex_);
Fredrik Solenbergf693bfa2018-12-11 12:22:10 +0100252 if (!last_decoder_) {
253 return absl::nullopt;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000254 }
Karl Wiberg4b644112019-10-11 09:37:42 +0200255 RTC_DCHECK_NE(-1, last_decoder_->payload_type);
256 return std::make_pair(last_decoder_->payload_type, last_decoder_->sdp_format);
ossue280cde2016-10-12 11:04:10 -0700257}
258
Niels Möller6b4d9622020-09-14 10:47:50 +0200259void AcmReceiver::GetNetworkStatistics(
260 NetworkStatistics* acm_stat,
261 bool get_and_clear_legacy_stats /* = true */) const {
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000262 NetEqNetworkStatistics neteq_stat;
Niels Möller6b4d9622020-09-14 10:47:50 +0200263 if (get_and_clear_legacy_stats) {
264 // NetEq function always returns zero, so we don't check the return value.
265 neteq_->NetworkStatistics(&neteq_stat);
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000266
Niels Möller6b4d9622020-09-14 10:47:50 +0200267 acm_stat->currentExpandRate = neteq_stat.expand_rate;
268 acm_stat->currentSpeechExpandRate = neteq_stat.speech_expand_rate;
269 acm_stat->currentPreemptiveRate = neteq_stat.preemptive_rate;
270 acm_stat->currentAccelerateRate = neteq_stat.accelerate_rate;
271 acm_stat->currentSecondaryDecodedRate = neteq_stat.secondary_decoded_rate;
272 acm_stat->currentSecondaryDiscardedRate =
273 neteq_stat.secondary_discarded_rate;
Niels Möller6b4d9622020-09-14 10:47:50 +0200274 acm_stat->meanWaitingTimeMs = neteq_stat.mean_waiting_time_ms;
Niels Möller6b4d9622020-09-14 10:47:50 +0200275 acm_stat->maxWaitingTimeMs = neteq_stat.max_waiting_time_ms;
276 } else {
277 neteq_stat = neteq_->CurrentNetworkStatistics();
Niels Möller6b4d9622020-09-14 10:47:50 +0200278 acm_stat->currentExpandRate = 0;
279 acm_stat->currentSpeechExpandRate = 0;
280 acm_stat->currentPreemptiveRate = 0;
281 acm_stat->currentAccelerateRate = 0;
282 acm_stat->currentSecondaryDecodedRate = 0;
283 acm_stat->currentSecondaryDiscardedRate = 0;
Niels Möller6b4d9622020-09-14 10:47:50 +0200284 acm_stat->meanWaitingTimeMs = -1;
Niels Möller6b4d9622020-09-14 10:47:50 +0200285 acm_stat->maxWaitingTimeMs = 1;
286 }
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000287 acm_stat->currentBufferSize = neteq_stat.current_buffer_size_ms;
288 acm_stat->preferredBufferSize = neteq_stat.preferred_buffer_size_ms;
turaj@webrtc.org532f3dc2013-09-19 00:12:23 +0000289 acm_stat->jitterPeaksFound = neteq_stat.jitter_peaks_found ? true : false;
Steve Anton2dbc69f2017-08-24 17:15:13 -0700290
291 NetEqLifetimeStatistics neteq_lifetime_stat = neteq_->GetLifetimeStatistics();
292 acm_stat->totalSamplesReceived = neteq_lifetime_stat.total_samples_received;
293 acm_stat->concealedSamples = neteq_lifetime_stat.concealed_samples;
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200294 acm_stat->silentConcealedSamples =
295 neteq_lifetime_stat.silent_concealed_samples;
Gustaf Ullberg9a2e9062017-09-18 09:28:20 +0200296 acm_stat->concealmentEvents = neteq_lifetime_stat.concealment_events;
Gustaf Ullbergb0a02072017-10-02 12:00:34 +0200297 acm_stat->jitterBufferDelayMs = neteq_lifetime_stat.jitter_buffer_delay_ms;
Artem Titove618cc92020-03-11 11:18:54 +0100298 acm_stat->jitterBufferTargetDelayMs =
299 neteq_lifetime_stat.jitter_buffer_target_delay_ms;
Ivo Creusen1a84b562022-07-19 16:33:10 +0200300 acm_stat->jitterBufferMinimumDelayMs =
301 neteq_lifetime_stat.jitter_buffer_minimum_delay_ms;
Chen Xing0acffb52019-01-15 15:46:29 +0100302 acm_stat->jitterBufferEmittedCount =
303 neteq_lifetime_stat.jitter_buffer_emitted_count;
Jakob Ivarsson352ce5c2018-11-27 12:52:16 +0100304 acm_stat->delayedPacketOutageSamples =
305 neteq_lifetime_stat.delayed_packet_outage_samples;
Jakob Ivarsson232b3fd2019-03-06 09:18:40 +0100306 acm_stat->relativePacketArrivalDelayMs =
307 neteq_lifetime_stat.relative_packet_arrival_delay_ms;
Henrik Lundin44125fa2019-04-29 17:00:46 +0200308 acm_stat->interruptionCount = neteq_lifetime_stat.interruption_count;
309 acm_stat->totalInterruptionDurationMs =
310 neteq_lifetime_stat.total_interruption_duration_ms;
Ivo Creusen8d8ffdb2019-04-30 09:45:21 +0200311 acm_stat->insertedSamplesForDeceleration =
312 neteq_lifetime_stat.inserted_samples_for_deceleration;
313 acm_stat->removedSamplesForAcceleration =
314 neteq_lifetime_stat.removed_samples_for_acceleration;
315 acm_stat->fecPacketsReceived = neteq_lifetime_stat.fec_packets_received;
316 acm_stat->fecPacketsDiscarded = neteq_lifetime_stat.fec_packets_discarded;
Jakob Ivarsson1a5a8132022-05-25 22:00:14 +0200317 acm_stat->packetsDiscarded = neteq_lifetime_stat.packets_discarded;
Ruslan Burakov8af88962018-11-22 17:21:10 +0100318
319 NetEqOperationsAndState neteq_operations_and_state =
320 neteq_->GetOperationsAndState();
321 acm_stat->packetBufferFlushes =
322 neteq_operations_and_state.packet_buffer_flushes;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000323}
324
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000325int AcmReceiver::EnableNack(size_t max_nack_list_size) {
henrik.lundin48ed9302015-10-29 05:36:24 -0700326 neteq_->EnableNack(max_nack_list_size);
327 return 0;
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000328}
329
330void AcmReceiver::DisableNack() {
henrik.lundin48ed9302015-10-29 05:36:24 -0700331 neteq_->DisableNack();
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000332}
333
334std::vector<uint16_t> AcmReceiver::GetNackList(
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000335 int64_t round_trip_time_ms) const {
henrik.lundin48ed9302015-10-29 05:36:24 -0700336 return neteq_->GetNackList(round_trip_time_ms);
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000337}
338
339void AcmReceiver::ResetInitialDelay() {
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000340 neteq_->SetMinimumDelay(0);
341 // TODO(turajs): Should NetEq Buffer be flushed?
342}
343
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000344uint32_t AcmReceiver::NowInTimestamp(int decoder_sampling_rate) const {
345 // Down-cast the time to (32-6)-bit since we only care about
346 // the least significant bits. (32-6) bits cover 2^(32-6) = 67108864 ms.
347 // We masked 6 most significant bits of 32-bit so there is no overflow in
348 // the conversion from milliseconds to timestamp.
Yves Gerey665174f2018-06-19 15:03:05 +0200349 const uint32_t now_in_ms =
Henrik Lundin35417322023-01-31 08:40:56 +0000350 static_cast<uint32_t>(clock_.TimeInMilliseconds() & 0x03ffffff);
Yves Gerey665174f2018-06-19 15:03:05 +0200351 return static_cast<uint32_t>((decoder_sampling_rate / 1000) * now_in_ms);
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000352}
353
wu@webrtc.org24301a62013-12-13 19:17:43 +0000354void AcmReceiver::GetDecodingCallStatistics(
355 AudioDecodingCallStats* stats) const {
Markus Handell0df0fae2020-07-07 15:53:34 +0200356 MutexLock lock(&mutex_);
wu@webrtc.org24301a62013-12-13 19:17:43 +0000357 *stats = call_stats_.GetDecodingStatistics();
358}
359
turaj@webrtc.org6d5d2482013-10-06 04:47:28 +0000360} // namespace acm2
361
turaj@webrtc.org7959e162013-09-12 18:30:26 +0000362} // namespace webrtc