turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_coding/acm2/acm_receiver.h" |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 12 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 15 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 16 | #include <cstdint> |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
Niels Möller | 2edab4c | 2018-10-22 09:48:08 +0200 | [diff] [blame] | 19 | #include "absl/strings/match.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 20 | #include "api/audio/audio_frame.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "api/audio_codecs/audio_decoder.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "modules/audio_coding/acm2/acm_resampler.h" |
| 23 | #include "modules/audio_coding/acm2/call_statistics.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "modules/audio_coding/neteq/include/neteq.h" |
| 25 | #include "rtc_base/checks.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "rtc_base/logging.h" |
Karl Wiberg | e40468b | 2017-11-22 10:42:26 +0100 | [diff] [blame] | 27 | #include "rtc_base/numerics/safe_conversions.h" |
Jonas Olsson | abbe841 | 2018-04-03 13:40:05 +0200 | [diff] [blame] | 28 | #include "rtc_base/strings/audio_format_to_string.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #include "system_wrappers/include/clock.h" |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 30 | |
| 31 | namespace webrtc { |
| 32 | |
turaj@webrtc.org | 6d5d248 | 2013-10-06 04:47:28 +0000 | [diff] [blame] | 33 | namespace acm2 { |
| 34 | |
henrik.lundin@webrtc.org | 0bc9b5a | 2014-04-29 08:09:31 +0000 | [diff] [blame] | 35 | AcmReceiver::AcmReceiver(const AudioCodingModule::Config& config) |
kwiberg | 6f0f616 | 2016-09-20 03:07:46 -0700 | [diff] [blame] | 36 | : last_audio_buffer_(new int16_t[AudioFrame::kMaxDataSizeSamples]), |
Alessio Bazzica | 8f319a3 | 2019-07-24 16:47:02 +0000 | [diff] [blame] | 37 | neteq_(NetEq::Create(config.neteq_config, |
| 38 | config.clock, |
| 39 | config.decoder_factory)), |
henrik.lundin@webrtc.org | 0bc9b5a | 2014-04-29 08:09:31 +0000 | [diff] [blame] | 40 | clock_(config.clock), |
henrik.lundin | 678c903 | 2015-11-02 08:31:23 -0800 | [diff] [blame] | 41 | resampled_last_output_frame_(true) { |
Henrik Lundin | 02ed201 | 2017-06-08 09:03:55 +0200 | [diff] [blame] | 42 | RTC_DCHECK(clock_); |
Henrik Lundin | 76c1067 | 2018-05-07 13:47:28 +0200 | [diff] [blame] | 43 | memset(last_audio_buffer_.get(), 0, |
| 44 | sizeof(int16_t) * AudioFrame::kMaxDataSizeSamples); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Henrik Lundin | 6af9399 | 2017-06-14 14:13:02 +0200 | [diff] [blame] | 47 | AcmReceiver::~AcmReceiver() = default; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 48 | |
| 49 | int AcmReceiver::SetMinimumDelay(int delay_ms) { |
| 50 | if (neteq_->SetMinimumDelay(delay_ms)) |
| 51 | return 0; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 52 | RTC_LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 53 | return -1; |
| 54 | } |
| 55 | |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 56 | int AcmReceiver::SetMaximumDelay(int delay_ms) { |
| 57 | if (neteq_->SetMaximumDelay(delay_ms)) |
| 58 | return 0; |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 59 | RTC_LOG(LERROR) << "AcmReceiver::SetExtraDelay " << delay_ms; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 60 | return -1; |
| 61 | } |
| 62 | |
Ruslan Burakov | 9bee67c | 2019-02-05 13:49:26 +0100 | [diff] [blame] | 63 | bool AcmReceiver::SetBaseMinimumDelayMs(int delay_ms) { |
| 64 | return neteq_->SetBaseMinimumDelayMs(delay_ms); |
| 65 | } |
| 66 | |
| 67 | int AcmReceiver::GetBaseMinimumDelayMs() const { |
| 68 | return neteq_->GetBaseMinimumDelayMs(); |
| 69 | } |
| 70 | |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 71 | absl::optional<int> AcmReceiver::last_packet_sample_rate_hz() const { |
Tommi | 9090e0b | 2016-01-20 13:39:36 +0100 | [diff] [blame] | 72 | rtc::CritScope lock(&crit_sect_); |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 73 | if (!last_decoder_) { |
| 74 | return absl::nullopt; |
| 75 | } |
| 76 | return last_decoder_->second.clockrate_hz; |
henrik.lundin | 057fb89 | 2015-11-23 08:19:52 -0800 | [diff] [blame] | 77 | } |
| 78 | |
henrik.lundin | d89814b | 2015-11-23 06:49:25 -0800 | [diff] [blame] | 79 | int AcmReceiver::last_output_sample_rate_hz() const { |
| 80 | return neteq_->last_output_sample_rate_hz(); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Niels Möller | afb5dbb | 2019-02-15 15:21:47 +0100 | [diff] [blame] | 83 | int AcmReceiver::InsertPacket(const RTPHeader& rtp_header, |
kwiberg | ee2bac2 | 2015-11-11 10:34:00 -0800 | [diff] [blame] | 84 | rtc::ArrayView<const uint8_t> incoming_payload) { |
henrik.lundin | b8c55b1 | 2017-05-10 07:38:01 -0700 | [diff] [blame] | 85 | if (incoming_payload.empty()) { |
Niels Möller | afb5dbb | 2019-02-15 15:21:47 +0100 | [diff] [blame] | 86 | neteq_->InsertEmptyPacket(rtp_header); |
henrik.lundin | b8c55b1 | 2017-05-10 07:38:01 -0700 | [diff] [blame] | 87 | return 0; |
| 88 | } |
| 89 | |
Niels Möller | afb5dbb | 2019-02-15 15:21:47 +0100 | [diff] [blame] | 90 | int payload_type = rtp_header.payloadType; |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 91 | auto format = neteq_->GetDecoderFormat(payload_type); |
| 92 | if (format && absl::EqualsIgnoreCase(format->name, "red")) { |
| 93 | // This is a RED packet. Get the format of the audio codec. |
| 94 | payload_type = incoming_payload[0] & 0x7f; |
| 95 | format = neteq_->GetDecoderFormat(payload_type); |
| 96 | } |
| 97 | if (!format) { |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 98 | RTC_LOG_F(LS_ERROR) << "Payload-type " << payload_type |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 99 | << " is not registered."; |
| 100 | return -1; |
| 101 | } |
| 102 | |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 103 | { |
Tommi | 9090e0b | 2016-01-20 13:39:36 +0100 | [diff] [blame] | 104 | rtc::CritScope lock(&crit_sect_); |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 105 | if (absl::EqualsIgnoreCase(format->name, "cn")) { |
| 106 | if (last_decoder_ && last_decoder_->second.num_channels > 1) { |
kwiberg | 6f0f616 | 2016-09-20 03:07:46 -0700 | [diff] [blame] | 107 | // This is a CNG and the audio codec is not mono, so skip pushing in |
| 108 | // packets into NetEq. |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 109 | return 0; |
kwiberg | 6f0f616 | 2016-09-20 03:07:46 -0700 | [diff] [blame] | 110 | } |
| 111 | } else { |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 112 | RTC_DCHECK(format); |
| 113 | last_decoder_ = std::make_pair(payload_type, *format); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 114 | } |
henrik.lundin@webrtc.org | a90abde | 2014-06-09 18:35:11 +0000 | [diff] [blame] | 115 | } // |crit_sect_| is released. |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 116 | |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 117 | uint32_t receive_timestamp = NowInTimestamp(format->clockrate_hz); |
Niels Möller | afb5dbb | 2019-02-15 15:21:47 +0100 | [diff] [blame] | 118 | if (neteq_->InsertPacket(rtp_header, incoming_payload, receive_timestamp) < |
| 119 | 0) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 120 | RTC_LOG(LERROR) << "AcmReceiver::InsertPacket " |
Niels Möller | afb5dbb | 2019-02-15 15:21:47 +0100 | [diff] [blame] | 121 | << static_cast<int>(rtp_header.payloadType) |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 122 | << " Failed to insert packet"; |
henrik.lundin@webrtc.org | eecf5e6 | 2014-06-24 13:11:22 +0000 | [diff] [blame] | 123 | return -1; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 124 | } |
| 125 | return 0; |
| 126 | } |
| 127 | |
henrik.lundin | 834a6ea | 2016-05-13 03:45:24 -0700 | [diff] [blame] | 128 | int AcmReceiver::GetAudio(int desired_freq_hz, |
| 129 | AudioFrame* audio_frame, |
| 130 | bool* muted) { |
henrik.lundin | 6348978 | 2016-09-20 01:47:12 -0700 | [diff] [blame] | 131 | RTC_DCHECK(muted); |
henrik.lundin@webrtc.org | 913f7b8 | 2014-10-21 06:54:23 +0000 | [diff] [blame] | 132 | // Accessing members, take the lock. |
Tommi | 9090e0b | 2016-01-20 13:39:36 +0100 | [diff] [blame] | 133 | rtc::CritScope lock(&crit_sect_); |
henrik.lundin@webrtc.org | 913f7b8 | 2014-10-21 06:54:23 +0000 | [diff] [blame] | 134 | |
henrik.lundin | 834a6ea | 2016-05-13 03:45:24 -0700 | [diff] [blame] | 135 | if (neteq_->GetAudio(audio_frame, muted) != NetEq::kOK) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 136 | RTC_LOG(LERROR) << "AcmReceiver::GetAudio - NetEq Failed."; |
henrik.lundin@webrtc.org | eecf5e6 | 2014-06-24 13:11:22 +0000 | [diff] [blame] | 137 | return -1; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 138 | } |
| 139 | |
henrik.lundin | d89814b | 2015-11-23 06:49:25 -0800 | [diff] [blame] | 140 | const int current_sample_rate_hz = neteq_->last_output_sample_rate_hz(); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 141 | |
| 142 | // Update if resampling is required. |
henrik.lundin | d89814b | 2015-11-23 06:49:25 -0800 | [diff] [blame] | 143 | const bool need_resampling = |
| 144 | (desired_freq_hz != -1) && (current_sample_rate_hz != desired_freq_hz); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 145 | |
henrik.lundin@webrtc.org | 913f7b8 | 2014-10-21 06:54:23 +0000 | [diff] [blame] | 146 | if (need_resampling && !resampled_last_output_frame_) { |
| 147 | // Prime the resampler with the last frame. |
| 148 | int16_t temp_output[AudioFrame::kMaxDataSizeSamples]; |
henrik.lundin | d89814b | 2015-11-23 06:49:25 -0800 | [diff] [blame] | 149 | int samples_per_channel_int = resampler_.Resample10Msec( |
| 150 | last_audio_buffer_.get(), current_sample_rate_hz, desired_freq_hz, |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 151 | audio_frame->num_channels_, AudioFrame::kMaxDataSizeSamples, |
| 152 | temp_output); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 153 | if (samples_per_channel_int < 0) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 154 | RTC_LOG(LERROR) << "AcmReceiver::GetAudio - " |
| 155 | "Resampling last_audio_buffer_ failed."; |
henrik.lundin@webrtc.org | 913f7b8 | 2014-10-21 06:54:23 +0000 | [diff] [blame] | 156 | return -1; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
henrik.lundin@webrtc.org | 913f7b8 | 2014-10-21 06:54:23 +0000 | [diff] [blame] | 160 | // TODO(henrik.lundin) Glitches in the output may appear if the output rate |
| 161 | // from NetEq changes. See WebRTC issue 3923. |
| 162 | if (need_resampling) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 163 | // TODO(yujo): handle this more efficiently for muted frames. |
henrik.lundin | d89814b | 2015-11-23 06:49:25 -0800 | [diff] [blame] | 164 | int samples_per_channel_int = resampler_.Resample10Msec( |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 165 | audio_frame->data(), current_sample_rate_hz, desired_freq_hz, |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 166 | audio_frame->num_channels_, AudioFrame::kMaxDataSizeSamples, |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 167 | audio_frame->mutable_data()); |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 168 | if (samples_per_channel_int < 0) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 169 | RTC_LOG(LERROR) |
| 170 | << "AcmReceiver::GetAudio - Resampling audio_buffer_ failed."; |
henrik.lundin@webrtc.org | 913f7b8 | 2014-10-21 06:54:23 +0000 | [diff] [blame] | 171 | return -1; |
| 172 | } |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 173 | audio_frame->samples_per_channel_ = |
| 174 | static_cast<size_t>(samples_per_channel_int); |
| 175 | audio_frame->sample_rate_hz_ = desired_freq_hz; |
| 176 | RTC_DCHECK_EQ( |
| 177 | audio_frame->sample_rate_hz_, |
kwiberg | d3edd77 | 2017-03-01 18:52:48 -0800 | [diff] [blame] | 178 | rtc::dchecked_cast<int>(audio_frame->samples_per_channel_ * 100)); |
henrik.lundin@webrtc.org | 913f7b8 | 2014-10-21 06:54:23 +0000 | [diff] [blame] | 179 | resampled_last_output_frame_ = true; |
| 180 | } else { |
| 181 | resampled_last_output_frame_ = false; |
| 182 | // We might end up here ONLY if codec is changed. |
henrik.lundin@webrtc.org | 913f7b8 | 2014-10-21 06:54:23 +0000 | [diff] [blame] | 183 | } |
| 184 | |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 185 | // Store current audio in |last_audio_buffer_| for next time. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 186 | memcpy(last_audio_buffer_.get(), audio_frame->data(), |
henrik.lundin | 6d8e011 | 2016-03-04 10:34:21 -0800 | [diff] [blame] | 187 | sizeof(int16_t) * audio_frame->samples_per_channel_ * |
| 188 | audio_frame->num_channels_); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 189 | |
henrik.lundin | 6348978 | 2016-09-20 01:47:12 -0700 | [diff] [blame] | 190 | call_stats_.DecodedByNetEq(audio_frame->speech_type_, *muted); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 191 | return 0; |
| 192 | } |
| 193 | |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 194 | void AcmReceiver::SetCodecs(const std::map<int, SdpAudioFormat>& codecs) { |
| 195 | neteq_->SetCodecs(codecs); |
| 196 | } |
| 197 | |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 198 | void AcmReceiver::FlushBuffers() { |
| 199 | neteq_->FlushBuffers(); |
| 200 | } |
| 201 | |
kwiberg | 6b19b56 | 2016-09-20 04:02:25 -0700 | [diff] [blame] | 202 | void AcmReceiver::RemoveAllCodecs() { |
Tommi | 9090e0b | 2016-01-20 13:39:36 +0100 | [diff] [blame] | 203 | rtc::CritScope lock(&crit_sect_); |
kwiberg | 6b19b56 | 2016-09-20 04:02:25 -0700 | [diff] [blame] | 204 | neteq_->RemoveAllPayloadTypes(); |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 205 | last_decoder_ = absl::nullopt; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Danil Chapovalov | b602123 | 2018-06-19 13:26:36 +0200 | [diff] [blame] | 208 | absl::optional<uint32_t> AcmReceiver::GetPlayoutTimestamp() { |
henrik.lundin | 9a410dd | 2016-04-06 01:39:22 -0700 | [diff] [blame] | 209 | return neteq_->GetPlayoutTimestamp(); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 210 | } |
| 211 | |
henrik.lundin | b3f1c5d | 2016-08-22 15:39:53 -0700 | [diff] [blame] | 212 | int AcmReceiver::FilteredCurrentDelayMs() const { |
| 213 | return neteq_->FilteredCurrentDelayMs(); |
| 214 | } |
| 215 | |
Henrik Lundin | abbff89 | 2017-11-29 09:14:04 +0100 | [diff] [blame] | 216 | int AcmReceiver::TargetDelayMs() const { |
| 217 | return neteq_->TargetDelayMs(); |
| 218 | } |
| 219 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 220 | absl::optional<std::pair<int, SdpAudioFormat>> AcmReceiver::LastDecoder() |
| 221 | const { |
Tommi | 9090e0b | 2016-01-20 13:39:36 +0100 | [diff] [blame] | 222 | rtc::CritScope lock(&crit_sect_); |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 223 | if (!last_decoder_) { |
| 224 | return absl::nullopt; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 225 | } |
Fredrik Solenberg | f693bfa | 2018-12-11 12:22:10 +0100 | [diff] [blame] | 226 | RTC_DCHECK_NE(-1, last_decoder_->first); // Payload type should be valid. |
| 227 | return last_decoder_; |
ossu | e280cde | 2016-10-12 11:04:10 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Niels Möller | ed44f54 | 2019-07-30 15:15:59 +0200 | [diff] [blame] | 230 | void AcmReceiver::GetNetworkStatistics(NetworkStatistics* acm_stat) const { |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 231 | NetEqNetworkStatistics neteq_stat; |
| 232 | // NetEq function always returns zero, so we don't check the return value. |
| 233 | neteq_->NetworkStatistics(&neteq_stat); |
| 234 | |
| 235 | acm_stat->currentBufferSize = neteq_stat.current_buffer_size_ms; |
| 236 | acm_stat->preferredBufferSize = neteq_stat.preferred_buffer_size_ms; |
turaj@webrtc.org | 532f3dc | 2013-09-19 00:12:23 +0000 | [diff] [blame] | 237 | acm_stat->jitterPeaksFound = neteq_stat.jitter_peaks_found ? true : false; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 238 | acm_stat->currentPacketLossRate = neteq_stat.packet_loss_rate; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 239 | acm_stat->currentExpandRate = neteq_stat.expand_rate; |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 240 | acm_stat->currentSpeechExpandRate = neteq_stat.speech_expand_rate; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 241 | acm_stat->currentPreemptiveRate = neteq_stat.preemptive_rate; |
| 242 | acm_stat->currentAccelerateRate = neteq_stat.accelerate_rate; |
minyue@webrtc.org | c0bd7be | 2015-02-18 15:24:13 +0000 | [diff] [blame] | 243 | acm_stat->currentSecondaryDecodedRate = neteq_stat.secondary_decoded_rate; |
minyue-webrtc | 0c3ca75 | 2017-08-23 15:59:38 +0200 | [diff] [blame] | 244 | acm_stat->currentSecondaryDiscardedRate = neteq_stat.secondary_discarded_rate; |
henrik.lundin@webrtc.org | 20c71fd | 2014-04-22 10:11:21 +0000 | [diff] [blame] | 245 | acm_stat->addedSamples = neteq_stat.added_zero_samples; |
Henrik Lundin | 1bb8cf8 | 2015-08-25 13:08:04 +0200 | [diff] [blame] | 246 | acm_stat->meanWaitingTimeMs = neteq_stat.mean_waiting_time_ms; |
| 247 | acm_stat->medianWaitingTimeMs = neteq_stat.median_waiting_time_ms; |
| 248 | acm_stat->minWaitingTimeMs = neteq_stat.min_waiting_time_ms; |
| 249 | acm_stat->maxWaitingTimeMs = neteq_stat.max_waiting_time_ms; |
Steve Anton | 2dbc69f | 2017-08-24 17:15:13 -0700 | [diff] [blame] | 250 | |
| 251 | NetEqLifetimeStatistics neteq_lifetime_stat = neteq_->GetLifetimeStatistics(); |
| 252 | acm_stat->totalSamplesReceived = neteq_lifetime_stat.total_samples_received; |
| 253 | acm_stat->concealedSamples = neteq_lifetime_stat.concealed_samples; |
Ivo Creusen | 8d8ffdb | 2019-04-30 09:45:21 +0200 | [diff] [blame] | 254 | acm_stat->silentConcealedSamples = |
| 255 | neteq_lifetime_stat.silent_concealed_samples; |
Gustaf Ullberg | 9a2e906 | 2017-09-18 09:28:20 +0200 | [diff] [blame] | 256 | acm_stat->concealmentEvents = neteq_lifetime_stat.concealment_events; |
Gustaf Ullberg | b0a0207 | 2017-10-02 12:00:34 +0200 | [diff] [blame] | 257 | acm_stat->jitterBufferDelayMs = neteq_lifetime_stat.jitter_buffer_delay_ms; |
Chen Xing | 0acffb5 | 2019-01-15 15:46:29 +0100 | [diff] [blame] | 258 | acm_stat->jitterBufferEmittedCount = |
| 259 | neteq_lifetime_stat.jitter_buffer_emitted_count; |
Jakob Ivarsson | 352ce5c | 2018-11-27 12:52:16 +0100 | [diff] [blame] | 260 | acm_stat->delayedPacketOutageSamples = |
| 261 | neteq_lifetime_stat.delayed_packet_outage_samples; |
Jakob Ivarsson | 232b3fd | 2019-03-06 09:18:40 +0100 | [diff] [blame] | 262 | acm_stat->relativePacketArrivalDelayMs = |
| 263 | neteq_lifetime_stat.relative_packet_arrival_delay_ms; |
Henrik Lundin | 44125fa | 2019-04-29 17:00:46 +0200 | [diff] [blame] | 264 | acm_stat->interruptionCount = neteq_lifetime_stat.interruption_count; |
| 265 | acm_stat->totalInterruptionDurationMs = |
| 266 | neteq_lifetime_stat.total_interruption_duration_ms; |
Ivo Creusen | 8d8ffdb | 2019-04-30 09:45:21 +0200 | [diff] [blame] | 267 | acm_stat->insertedSamplesForDeceleration = |
| 268 | neteq_lifetime_stat.inserted_samples_for_deceleration; |
| 269 | acm_stat->removedSamplesForAcceleration = |
| 270 | neteq_lifetime_stat.removed_samples_for_acceleration; |
| 271 | acm_stat->fecPacketsReceived = neteq_lifetime_stat.fec_packets_received; |
| 272 | acm_stat->fecPacketsDiscarded = neteq_lifetime_stat.fec_packets_discarded; |
Ruslan Burakov | 8af8896 | 2018-11-22 17:21:10 +0100 | [diff] [blame] | 273 | |
| 274 | NetEqOperationsAndState neteq_operations_and_state = |
| 275 | neteq_->GetOperationsAndState(); |
| 276 | acm_stat->packetBufferFlushes = |
| 277 | neteq_operations_and_state.packet_buffer_flushes; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 278 | } |
| 279 | |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 280 | int AcmReceiver::EnableNack(size_t max_nack_list_size) { |
henrik.lundin | 48ed930 | 2015-10-29 05:36:24 -0700 | [diff] [blame] | 281 | neteq_->EnableNack(max_nack_list_size); |
| 282 | return 0; |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void AcmReceiver::DisableNack() { |
henrik.lundin | 48ed930 | 2015-10-29 05:36:24 -0700 | [diff] [blame] | 286 | neteq_->DisableNack(); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | std::vector<uint16_t> AcmReceiver::GetNackList( |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 290 | int64_t round_trip_time_ms) const { |
henrik.lundin | 48ed930 | 2015-10-29 05:36:24 -0700 | [diff] [blame] | 291 | return neteq_->GetNackList(round_trip_time_ms); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | void AcmReceiver::ResetInitialDelay() { |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 295 | neteq_->SetMinimumDelay(0); |
| 296 | // TODO(turajs): Should NetEq Buffer be flushed? |
| 297 | } |
| 298 | |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 299 | uint32_t AcmReceiver::NowInTimestamp(int decoder_sampling_rate) const { |
| 300 | // Down-cast the time to (32-6)-bit since we only care about |
| 301 | // the least significant bits. (32-6) bits cover 2^(32-6) = 67108864 ms. |
| 302 | // We masked 6 most significant bits of 32-bit so there is no overflow in |
| 303 | // the conversion from milliseconds to timestamp. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 304 | const uint32_t now_in_ms = |
| 305 | static_cast<uint32_t>(clock_->TimeInMilliseconds() & 0x03ffffff); |
| 306 | return static_cast<uint32_t>((decoder_sampling_rate / 1000) * now_in_ms); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 307 | } |
| 308 | |
wu@webrtc.org | 24301a6 | 2013-12-13 19:17:43 +0000 | [diff] [blame] | 309 | void AcmReceiver::GetDecodingCallStatistics( |
| 310 | AudioDecodingCallStats* stats) const { |
Tommi | 9090e0b | 2016-01-20 13:39:36 +0100 | [diff] [blame] | 311 | rtc::CritScope lock(&crit_sect_); |
wu@webrtc.org | 24301a6 | 2013-12-13 19:17:43 +0000 | [diff] [blame] | 312 | *stats = call_stats_.GetDecodingStatistics(); |
| 313 | } |
| 314 | |
turaj@webrtc.org | 6d5d248 | 2013-10-06 04:47:28 +0000 | [diff] [blame] | 315 | } // namespace acm2 |
| 316 | |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 317 | } // namespace webrtc |