turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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/include/audio_coding_module.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 <assert.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 14 | |
Jonathan Yu | 36344a0 | 2017-07-30 01:55:34 -0700 | [diff] [blame] | 15 | #include <algorithm> |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 16 | #include <cstdint> |
Jonathan Yu | 36344a0 | 2017-07-30 01:55:34 -0700 | [diff] [blame] | 17 | |
Niels Möller | 2edab4c | 2018-10-22 09:48:08 +0200 | [diff] [blame] | 18 | #include "absl/strings/match.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 19 | #include "api/array_view.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/audio_coding/acm2/acm_receiver.h" |
| 21 | #include "modules/audio_coding/acm2/acm_resampler.h" |
Fredrik Solenberg | bbf21a3 | 2018-04-12 22:44:09 +0200 | [diff] [blame] | 22 | #include "modules/include/module_common_types.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 23 | #include "modules/include/module_common_types_public.h" |
| 24 | #include "rtc_base/buffer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 26 | #include "rtc_base/critical_section.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 27 | #include "rtc_base/logging.h" |
Karl Wiberg | e40468b | 2017-11-22 10:42:26 +0100 | [diff] [blame] | 28 | #include "rtc_base/numerics/safe_conversions.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 29 | #include "rtc_base/thread_annotations.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "system_wrappers/include/metrics.h" |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 31 | |
| 32 | namespace webrtc { |
| 33 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 34 | namespace { |
| 35 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 36 | class AudioCodingModuleImpl final : public AudioCodingModule { |
| 37 | public: |
| 38 | explicit AudioCodingModuleImpl(const AudioCodingModule::Config& config); |
| 39 | ~AudioCodingModuleImpl() override; |
| 40 | |
| 41 | ///////////////////////////////////////// |
| 42 | // Sender |
| 43 | // |
| 44 | |
kwiberg | 24c7c12 | 2016-09-28 11:57:10 -0700 | [diff] [blame] | 45 | void ModifyEncoder(rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> |
| 46 | modifier) override; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 47 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 48 | // Register a transport callback which will be |
| 49 | // called to deliver the encoded buffers. |
| 50 | int RegisterTransportCallback(AudioPacketizationCallback* transport) override; |
| 51 | |
| 52 | // Add 10 ms of raw (PCM) audio data to the encoder. |
| 53 | int Add10MsData(const AudioFrame& audio_frame) override; |
| 54 | |
| 55 | ///////////////////////////////////////// |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 56 | // (FEC) Forward Error Correction (codec internal) |
| 57 | // |
| 58 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 59 | // Set target packet loss rate |
| 60 | int SetPacketLossRate(int loss_rate) override; |
| 61 | |
| 62 | ///////////////////////////////////////// |
| 63 | // (VAD) Voice Activity Detection |
| 64 | // and |
| 65 | // (CNG) Comfort Noise Generation |
| 66 | // |
| 67 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 68 | int RegisterVADCallback(ACMVADCallback* vad_callback) override; |
| 69 | |
| 70 | ///////////////////////////////////////// |
| 71 | // Receiver |
| 72 | // |
| 73 | |
| 74 | // Initialize receiver, resets codec database etc. |
| 75 | int InitializeReceiver() override; |
| 76 | |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 77 | void SetReceiveCodecs(const std::map<int, SdpAudioFormat>& codecs) override; |
| 78 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 79 | // Incoming packet from network parsed and ready for decode. |
| 80 | int IncomingPacket(const uint8_t* incoming_payload, |
| 81 | const size_t payload_length, |
Niels Möller | afb5dbb | 2019-02-15 15:21:47 +0100 | [diff] [blame] | 82 | const RTPHeader& rtp_info) override; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 83 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 84 | // Get 10 milliseconds of raw audio data to play out, and |
| 85 | // automatic resample to the requested frequency if > 0. |
| 86 | int PlayoutData10Ms(int desired_freq_hz, |
| 87 | AudioFrame* audio_frame, |
| 88 | bool* muted) override; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 89 | |
| 90 | ///////////////////////////////////////// |
| 91 | // Statistics |
| 92 | // |
| 93 | |
| 94 | int GetNetworkStatistics(NetworkStatistics* statistics) override; |
| 95 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 96 | void GetDecodingCallStatistics(AudioDecodingCallStats* stats) const override; |
| 97 | |
ivoc | e1198e0 | 2017-09-08 08:13:19 -0700 | [diff] [blame] | 98 | ANAStats GetANAStats() const override; |
| 99 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 100 | private: |
| 101 | struct InputData { |
| 102 | uint32_t input_timestamp; |
| 103 | const int16_t* audio; |
| 104 | size_t length_per_channel; |
| 105 | size_t audio_channel; |
| 106 | // If a re-mix is required (up or down), this buffer will store a re-mixed |
| 107 | // version of the input. |
| 108 | int16_t buffer[WEBRTC_10MS_PCM_AUDIO]; |
| 109 | }; |
| 110 | |
| 111 | // This member class writes values to the named UMA histogram, but only if |
| 112 | // the value has changed since the last time (and always for the first call). |
| 113 | class ChangeLogger { |
| 114 | public: |
| 115 | explicit ChangeLogger(const std::string& histogram_name) |
| 116 | : histogram_name_(histogram_name) {} |
| 117 | // Logs the new value if it is different from the last logged value, or if |
| 118 | // this is the first call. |
| 119 | void MaybeLog(int value); |
| 120 | |
| 121 | private: |
| 122 | int last_value_ = 0; |
| 123 | int first_time_ = true; |
| 124 | const std::string histogram_name_; |
| 125 | }; |
| 126 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 127 | int Add10MsDataInternal(const AudioFrame& audio_frame, InputData* input_data) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 128 | RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_crit_sect_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 129 | int Encode(const InputData& input_data) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 130 | RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_crit_sect_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 131 | |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 132 | int InitializeReceiverSafe() RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_crit_sect_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 133 | |
| 134 | bool HaveValidEncoder(const char* caller_name) const |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 135 | RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_crit_sect_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 136 | |
| 137 | // Preprocessing of input audio, including resampling and down-mixing if |
| 138 | // required, before pushing audio into encoder's buffer. |
| 139 | // |
| 140 | // in_frame: input audio-frame |
| 141 | // ptr_out: pointer to output audio_frame. If no preprocessing is required |
| 142 | // |ptr_out| will be pointing to |in_frame|, otherwise pointing to |
| 143 | // |preprocess_frame_|. |
| 144 | // |
| 145 | // Return value: |
| 146 | // -1: if encountering an error. |
| 147 | // 0: otherwise. |
| 148 | int PreprocessToAddData(const AudioFrame& in_frame, |
| 149 | const AudioFrame** ptr_out) |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 150 | RTC_EXCLUSIVE_LOCKS_REQUIRED(acm_crit_sect_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 151 | |
| 152 | // Change required states after starting to receive the codec corresponding |
| 153 | // to |index|. |
| 154 | int UpdateUponReceivingCodec(int index); |
| 155 | |
| 156 | rtc::CriticalSection acm_crit_sect_; |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 157 | rtc::Buffer encode_buffer_ RTC_GUARDED_BY(acm_crit_sect_); |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 158 | uint32_t expected_codec_ts_ RTC_GUARDED_BY(acm_crit_sect_); |
| 159 | uint32_t expected_in_ts_ RTC_GUARDED_BY(acm_crit_sect_); |
| 160 | acm2::ACMResampler resampler_ RTC_GUARDED_BY(acm_crit_sect_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 161 | acm2::AcmReceiver receiver_; // AcmReceiver has it's own internal lock. |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 162 | ChangeLogger bitrate_logger_ RTC_GUARDED_BY(acm_crit_sect_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 163 | |
Karl Wiberg | 49c33ce | 2018-11-12 14:21:58 +0100 | [diff] [blame] | 164 | // Current encoder stack, provided by a call to RegisterEncoder. |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 165 | std::unique_ptr<AudioEncoder> encoder_stack_ RTC_GUARDED_BY(acm_crit_sect_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 166 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 167 | // This is to keep track of CN instances where we can send DTMFs. |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 168 | uint8_t previous_pltype_ RTC_GUARDED_BY(acm_crit_sect_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 169 | |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 170 | bool receiver_initialized_ RTC_GUARDED_BY(acm_crit_sect_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 171 | |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 172 | AudioFrame preprocess_frame_ RTC_GUARDED_BY(acm_crit_sect_); |
| 173 | bool first_10ms_data_ RTC_GUARDED_BY(acm_crit_sect_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 174 | |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 175 | bool first_frame_ RTC_GUARDED_BY(acm_crit_sect_); |
| 176 | uint32_t last_timestamp_ RTC_GUARDED_BY(acm_crit_sect_); |
| 177 | uint32_t last_rtp_timestamp_ RTC_GUARDED_BY(acm_crit_sect_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 178 | |
| 179 | rtc::CriticalSection callback_crit_sect_; |
| 180 | AudioPacketizationCallback* packetization_callback_ |
danilchap | 56359be | 2017-09-07 07:53:45 -0700 | [diff] [blame] | 181 | RTC_GUARDED_BY(callback_crit_sect_); |
| 182 | ACMVADCallback* vad_callback_ RTC_GUARDED_BY(callback_crit_sect_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 183 | |
| 184 | int codec_histogram_bins_log_[static_cast<size_t>( |
| 185 | AudioEncoder::CodecType::kMaxLoggedAudioCodecTypes)]; |
| 186 | int number_of_consecutive_empty_packets_; |
| 187 | }; |
| 188 | |
| 189 | // Adds a codec usage sample to the histogram. |
| 190 | void UpdateCodecTypeHistogram(size_t codec_type) { |
| 191 | RTC_HISTOGRAM_ENUMERATION( |
| 192 | "WebRTC.Audio.Encoder.CodecType", static_cast<int>(codec_type), |
| 193 | static_cast<int>( |
| 194 | webrtc::AudioEncoder::CodecType::kMaxLoggedAudioCodecTypes)); |
| 195 | } |
| 196 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 197 | // Stereo-to-mono can be used as in-place. |
| 198 | int DownMix(const AudioFrame& frame, |
| 199 | size_t length_out_buff, |
| 200 | int16_t* out_buff) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 201 | RTC_DCHECK_EQ(frame.num_channels_, 2); |
| 202 | RTC_DCHECK_GE(length_out_buff, frame.samples_per_channel_); |
| 203 | |
| 204 | if (!frame.muted()) { |
| 205 | const int16_t* frame_data = frame.data(); |
| 206 | for (size_t n = 0; n < frame.samples_per_channel_; ++n) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 207 | out_buff[n] = |
| 208 | static_cast<int16_t>((static_cast<int32_t>(frame_data[2 * n]) + |
| 209 | static_cast<int32_t>(frame_data[2 * n + 1])) >> |
| 210 | 1); |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 211 | } |
| 212 | } else { |
Jonathan Yu | 36344a0 | 2017-07-30 01:55:34 -0700 | [diff] [blame] | 213 | std::fill(out_buff, out_buff + frame.samples_per_channel_, 0); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 214 | } |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | // Mono-to-stereo can be used as in-place. |
| 219 | int UpMix(const AudioFrame& frame, size_t length_out_buff, int16_t* out_buff) { |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 220 | RTC_DCHECK_EQ(frame.num_channels_, 1); |
| 221 | RTC_DCHECK_GE(length_out_buff, 2 * frame.samples_per_channel_); |
| 222 | |
| 223 | if (!frame.muted()) { |
| 224 | const int16_t* frame_data = frame.data(); |
| 225 | for (size_t n = frame.samples_per_channel_; n != 0; --n) { |
| 226 | size_t i = n - 1; |
| 227 | int16_t sample = frame_data[i]; |
| 228 | out_buff[2 * i + 1] = sample; |
| 229 | out_buff[2 * i] = sample; |
| 230 | } |
| 231 | } else { |
Jonathan Yu | 36344a0 | 2017-07-30 01:55:34 -0700 | [diff] [blame] | 232 | std::fill(out_buff, out_buff + frame.samples_per_channel_ * 2, 0); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 233 | } |
| 234 | return 0; |
| 235 | } |
| 236 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 237 | void AudioCodingModuleImpl::ChangeLogger::MaybeLog(int value) { |
| 238 | if (value != last_value_ || first_time_) { |
| 239 | first_time_ = false; |
| 240 | last_value_ = value; |
| 241 | RTC_HISTOGRAM_COUNTS_SPARSE_100(histogram_name_, value); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | AudioCodingModuleImpl::AudioCodingModuleImpl( |
| 246 | const AudioCodingModule::Config& config) |
solenberg | c7b4a45 | 2017-09-28 07:37:11 -0700 | [diff] [blame] | 247 | : expected_codec_ts_(0xD87F3F9F), |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 248 | expected_in_ts_(0xD87F3F9F), |
| 249 | receiver_(config), |
| 250 | bitrate_logger_("WebRTC.Audio.TargetBitrateInKbps"), |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 251 | encoder_stack_(nullptr), |
| 252 | previous_pltype_(255), |
| 253 | receiver_initialized_(false), |
| 254 | first_10ms_data_(false), |
| 255 | first_frame_(true), |
| 256 | packetization_callback_(NULL), |
| 257 | vad_callback_(NULL), |
| 258 | codec_histogram_bins_log_(), |
| 259 | number_of_consecutive_empty_packets_(0) { |
| 260 | if (InitializeReceiverSafe() < 0) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 261 | RTC_LOG(LS_ERROR) << "Cannot initialize receiver"; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 262 | } |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 263 | RTC_LOG(LS_INFO) << "Created"; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | AudioCodingModuleImpl::~AudioCodingModuleImpl() = default; |
| 267 | |
| 268 | int32_t AudioCodingModuleImpl::Encode(const InputData& input_data) { |
| 269 | AudioEncoder::EncodedInfo encoded_info; |
| 270 | uint8_t previous_pltype; |
| 271 | |
| 272 | // Check if there is an encoder before. |
| 273 | if (!HaveValidEncoder("Process")) |
| 274 | return -1; |
| 275 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 276 | if (!first_frame_) { |
deadbeef | fcada90 | 2016-08-24 12:45:13 -0700 | [diff] [blame] | 277 | RTC_DCHECK(IsNewerTimestamp(input_data.input_timestamp, last_timestamp_)) |
ossu | 63fb95a | 2016-07-06 09:34:22 -0700 | [diff] [blame] | 278 | << "Time should not move backwards"; |
| 279 | } |
| 280 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 281 | // Scale the timestamp to the codec's RTP timestamp rate. |
| 282 | uint32_t rtp_timestamp = |
Karl Wiberg | 053c371 | 2019-05-16 15:24:17 +0200 | [diff] [blame] | 283 | first_frame_ |
| 284 | ? input_data.input_timestamp |
| 285 | : last_rtp_timestamp_ + |
| 286 | rtc::dchecked_cast<uint32_t>(rtc::CheckedDivExact( |
| 287 | int64_t{input_data.input_timestamp - last_timestamp_} * |
| 288 | encoder_stack_->RtpTimestampRateHz(), |
| 289 | int64_t{encoder_stack_->SampleRateHz()})); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 290 | last_timestamp_ = input_data.input_timestamp; |
| 291 | last_rtp_timestamp_ = rtp_timestamp; |
| 292 | first_frame_ = false; |
| 293 | |
| 294 | // Clear the buffer before reuse - encoded data will get appended. |
| 295 | encode_buffer_.Clear(); |
| 296 | encoded_info = encoder_stack_->Encode( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 297 | rtp_timestamp, |
| 298 | rtc::ArrayView<const int16_t>( |
| 299 | input_data.audio, |
| 300 | input_data.audio_channel * input_data.length_per_channel), |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 301 | &encode_buffer_); |
| 302 | |
| 303 | bitrate_logger_.MaybeLog(encoder_stack_->GetTargetBitrate() / 1000); |
| 304 | if (encode_buffer_.size() == 0 && !encoded_info.send_even_if_empty) { |
| 305 | // Not enough data. |
| 306 | return 0; |
| 307 | } |
| 308 | previous_pltype = previous_pltype_; // Read it while we have the critsect. |
| 309 | |
| 310 | // Log codec type to histogram once every 500 packets. |
| 311 | if (encoded_info.encoded_bytes == 0) { |
| 312 | ++number_of_consecutive_empty_packets_; |
| 313 | } else { |
| 314 | size_t codec_type = static_cast<size_t>(encoded_info.encoder_type); |
| 315 | codec_histogram_bins_log_[codec_type] += |
| 316 | number_of_consecutive_empty_packets_ + 1; |
| 317 | number_of_consecutive_empty_packets_ = 0; |
| 318 | if (codec_histogram_bins_log_[codec_type] >= 500) { |
| 319 | codec_histogram_bins_log_[codec_type] -= 500; |
| 320 | UpdateCodecTypeHistogram(codec_type); |
| 321 | } |
| 322 | } |
| 323 | |
Niels Möller | 87e2d78 | 2019-03-07 10:18:23 +0100 | [diff] [blame] | 324 | AudioFrameType frame_type; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 325 | if (encode_buffer_.size() == 0 && encoded_info.send_even_if_empty) { |
Niels Möller | c936cb6 | 2019-03-19 14:10:16 +0100 | [diff] [blame] | 326 | frame_type = AudioFrameType::kEmptyFrame; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 327 | encoded_info.payload_type = previous_pltype; |
| 328 | } else { |
kwiberg | af476c7 | 2016-11-28 15:21:39 -0800 | [diff] [blame] | 329 | RTC_DCHECK_GT(encode_buffer_.size(), 0); |
Niels Möller | c936cb6 | 2019-03-19 14:10:16 +0100 | [diff] [blame] | 330 | frame_type = encoded_info.speech ? AudioFrameType::kAudioFrameSpeech |
| 331 | : AudioFrameType::kAudioFrameCN; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | { |
| 335 | rtc::CritScope lock(&callback_crit_sect_); |
| 336 | if (packetization_callback_) { |
| 337 | packetization_callback_->SendData( |
| 338 | frame_type, encoded_info.payload_type, encoded_info.encoded_timestamp, |
Niels Möller | c35b6e6 | 2019-04-25 16:31:18 +0200 | [diff] [blame] | 339 | encode_buffer_.data(), encode_buffer_.size()); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | if (vad_callback_) { |
| 343 | // Callback with VAD decision. |
| 344 | vad_callback_->InFrameType(frame_type); |
| 345 | } |
| 346 | } |
| 347 | previous_pltype_ = encoded_info.payload_type; |
| 348 | return static_cast<int32_t>(encode_buffer_.size()); |
| 349 | } |
| 350 | |
| 351 | ///////////////////////////////////////// |
| 352 | // Sender |
| 353 | // |
| 354 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 355 | void AudioCodingModuleImpl::ModifyEncoder( |
kwiberg | 24c7c12 | 2016-09-28 11:57:10 -0700 | [diff] [blame] | 356 | rtc::FunctionView<void(std::unique_ptr<AudioEncoder>*)> modifier) { |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 357 | rtc::CritScope lock(&acm_crit_sect_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 358 | modifier(&encoder_stack_); |
| 359 | } |
| 360 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 361 | // Register a transport callback which will be called to deliver |
| 362 | // the encoded buffers. |
| 363 | int AudioCodingModuleImpl::RegisterTransportCallback( |
| 364 | AudioPacketizationCallback* transport) { |
| 365 | rtc::CritScope lock(&callback_crit_sect_); |
| 366 | packetization_callback_ = transport; |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | // Add 10MS of raw (PCM) audio data to the encoder. |
| 371 | int AudioCodingModuleImpl::Add10MsData(const AudioFrame& audio_frame) { |
| 372 | InputData input_data; |
| 373 | rtc::CritScope lock(&acm_crit_sect_); |
| 374 | int r = Add10MsDataInternal(audio_frame, &input_data); |
| 375 | return r < 0 ? r : Encode(input_data); |
| 376 | } |
| 377 | |
| 378 | int AudioCodingModuleImpl::Add10MsDataInternal(const AudioFrame& audio_frame, |
| 379 | InputData* input_data) { |
| 380 | if (audio_frame.samples_per_channel_ == 0) { |
| 381 | assert(false); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 382 | RTC_LOG(LS_ERROR) << "Cannot Add 10 ms audio, payload length is zero"; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 383 | return -1; |
| 384 | } |
| 385 | |
| 386 | if (audio_frame.sample_rate_hz_ > 48000) { |
| 387 | assert(false); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 388 | RTC_LOG(LS_ERROR) << "Cannot Add 10 ms audio, input frequency not valid"; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 389 | return -1; |
| 390 | } |
| 391 | |
| 392 | // If the length and frequency matches. We currently just support raw PCM. |
| 393 | if (static_cast<size_t>(audio_frame.sample_rate_hz_ / 100) != |
| 394 | audio_frame.samples_per_channel_) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 395 | RTC_LOG(LS_ERROR) |
Alex Loiko | 300ec8c | 2017-05-30 17:23:28 +0200 | [diff] [blame] | 396 | << "Cannot Add 10 ms audio, input frequency and length doesn't match"; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 397 | return -1; |
| 398 | } |
| 399 | |
Alex Loiko | 6543881 | 2019-02-22 10:13:44 +0100 | [diff] [blame] | 400 | if (audio_frame.num_channels_ != 1 && audio_frame.num_channels_ != 2 && |
| 401 | audio_frame.num_channels_ != 4 && audio_frame.num_channels_ != 6 && |
| 402 | audio_frame.num_channels_ != 8) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 403 | RTC_LOG(LS_ERROR) << "Cannot Add 10 ms audio, invalid number of channels."; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 404 | return -1; |
| 405 | } |
| 406 | |
| 407 | // Do we have a codec registered? |
| 408 | if (!HaveValidEncoder("Add10MsData")) { |
| 409 | return -1; |
| 410 | } |
| 411 | |
| 412 | const AudioFrame* ptr_frame; |
| 413 | // Perform a resampling, also down-mix if it is required and can be |
| 414 | // performed before resampling (a down mix prior to resampling will take |
| 415 | // place if both primary and secondary encoders are mono and input is in |
| 416 | // stereo). |
| 417 | if (PreprocessToAddData(audio_frame, &ptr_frame) < 0) { |
| 418 | return -1; |
| 419 | } |
| 420 | |
| 421 | // Check whether we need an up-mix or down-mix? |
| 422 | const size_t current_num_channels = encoder_stack_->NumChannels(); |
| 423 | const bool same_num_channels = |
| 424 | ptr_frame->num_channels_ == current_num_channels; |
| 425 | |
| 426 | if (!same_num_channels) { |
| 427 | if (ptr_frame->num_channels_ == 1) { |
| 428 | if (UpMix(*ptr_frame, WEBRTC_10MS_PCM_AUDIO, input_data->buffer) < 0) |
| 429 | return -1; |
| 430 | } else { |
| 431 | if (DownMix(*ptr_frame, WEBRTC_10MS_PCM_AUDIO, input_data->buffer) < 0) |
| 432 | return -1; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | // When adding data to encoders this pointer is pointing to an audio buffer |
| 437 | // with correct number of channels. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 438 | const int16_t* ptr_audio = ptr_frame->data(); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 439 | |
| 440 | // For pushing data to primary, point the |ptr_audio| to correct buffer. |
| 441 | if (!same_num_channels) |
| 442 | ptr_audio = input_data->buffer; |
| 443 | |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 444 | // TODO(yujo): Skip encode of muted frames. |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 445 | input_data->input_timestamp = ptr_frame->timestamp_; |
| 446 | input_data->audio = ptr_audio; |
| 447 | input_data->length_per_channel = ptr_frame->samples_per_channel_; |
| 448 | input_data->audio_channel = current_num_channels; |
| 449 | |
| 450 | return 0; |
| 451 | } |
| 452 | |
| 453 | // Perform a resampling and down-mix if required. We down-mix only if |
| 454 | // encoder is mono and input is stereo. In case of dual-streaming, both |
| 455 | // encoders has to be mono for down-mix to take place. |
| 456 | // |*ptr_out| will point to the pre-processed audio-frame. If no pre-processing |
| 457 | // is required, |*ptr_out| points to |in_frame|. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 458 | // TODO(yujo): Make this more efficient for muted frames. |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 459 | int AudioCodingModuleImpl::PreprocessToAddData(const AudioFrame& in_frame, |
| 460 | const AudioFrame** ptr_out) { |
| 461 | const bool resample = |
| 462 | in_frame.sample_rate_hz_ != encoder_stack_->SampleRateHz(); |
| 463 | |
| 464 | // This variable is true if primary codec and secondary codec (if exists) |
| 465 | // are both mono and input is stereo. |
| 466 | // TODO(henrik.lundin): This condition should probably be |
| 467 | // in_frame.num_channels_ > encoder_stack_->NumChannels() |
| 468 | const bool down_mix = |
| 469 | in_frame.num_channels_ == 2 && encoder_stack_->NumChannels() == 1; |
| 470 | |
| 471 | if (!first_10ms_data_) { |
| 472 | expected_in_ts_ = in_frame.timestamp_; |
| 473 | expected_codec_ts_ = in_frame.timestamp_; |
| 474 | first_10ms_data_ = true; |
| 475 | } else if (in_frame.timestamp_ != expected_in_ts_) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 476 | RTC_LOG(LS_WARNING) << "Unexpected input timestamp: " << in_frame.timestamp_ |
| 477 | << ", expected: " << expected_in_ts_; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 478 | expected_codec_ts_ += |
| 479 | (in_frame.timestamp_ - expected_in_ts_) * |
| 480 | static_cast<uint32_t>( |
| 481 | static_cast<double>(encoder_stack_->SampleRateHz()) / |
| 482 | static_cast<double>(in_frame.sample_rate_hz_)); |
| 483 | expected_in_ts_ = in_frame.timestamp_; |
| 484 | } |
| 485 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 486 | if (!down_mix && !resample) { |
| 487 | // No pre-processing is required. |
ossu | 63fb95a | 2016-07-06 09:34:22 -0700 | [diff] [blame] | 488 | if (expected_in_ts_ == expected_codec_ts_) { |
| 489 | // If we've never resampled, we can use the input frame as-is |
| 490 | *ptr_out = &in_frame; |
| 491 | } else { |
| 492 | // Otherwise we'll need to alter the timestamp. Since in_frame is const, |
| 493 | // we'll have to make a copy of it. |
| 494 | preprocess_frame_.CopyFrom(in_frame); |
| 495 | preprocess_frame_.timestamp_ = expected_codec_ts_; |
| 496 | *ptr_out = &preprocess_frame_; |
| 497 | } |
| 498 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 499 | expected_in_ts_ += static_cast<uint32_t>(in_frame.samples_per_channel_); |
| 500 | expected_codec_ts_ += static_cast<uint32_t>(in_frame.samples_per_channel_); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | *ptr_out = &preprocess_frame_; |
| 505 | preprocess_frame_.num_channels_ = in_frame.num_channels_; |
| 506 | int16_t audio[WEBRTC_10MS_PCM_AUDIO]; |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 507 | const int16_t* src_ptr_audio = in_frame.data(); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 508 | if (down_mix) { |
| 509 | // If a resampling is required the output of a down-mix is written into a |
| 510 | // local buffer, otherwise, it will be written to the output frame. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 511 | int16_t* dest_ptr_audio = |
| 512 | resample ? audio : preprocess_frame_.mutable_data(); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 513 | if (DownMix(in_frame, WEBRTC_10MS_PCM_AUDIO, dest_ptr_audio) < 0) |
| 514 | return -1; |
| 515 | preprocess_frame_.num_channels_ = 1; |
| 516 | // Set the input of the resampler is the down-mixed signal. |
| 517 | src_ptr_audio = audio; |
| 518 | } |
| 519 | |
| 520 | preprocess_frame_.timestamp_ = expected_codec_ts_; |
| 521 | preprocess_frame_.samples_per_channel_ = in_frame.samples_per_channel_; |
| 522 | preprocess_frame_.sample_rate_hz_ = in_frame.sample_rate_hz_; |
| 523 | // If it is required, we have to do a resampling. |
| 524 | if (resample) { |
| 525 | // The result of the resampler is written to output frame. |
yujo | 36b1a5f | 2017-06-12 12:45:32 -0700 | [diff] [blame] | 526 | int16_t* dest_ptr_audio = preprocess_frame_.mutable_data(); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 527 | |
| 528 | int samples_per_channel = resampler_.Resample10Msec( |
| 529 | src_ptr_audio, in_frame.sample_rate_hz_, encoder_stack_->SampleRateHz(), |
| 530 | preprocess_frame_.num_channels_, AudioFrame::kMaxDataSizeSamples, |
| 531 | dest_ptr_audio); |
| 532 | |
| 533 | if (samples_per_channel < 0) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 534 | RTC_LOG(LS_ERROR) << "Cannot add 10 ms audio, resampling failed"; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 535 | return -1; |
| 536 | } |
| 537 | preprocess_frame_.samples_per_channel_ = |
| 538 | static_cast<size_t>(samples_per_channel); |
| 539 | preprocess_frame_.sample_rate_hz_ = encoder_stack_->SampleRateHz(); |
| 540 | } |
| 541 | |
| 542 | expected_codec_ts_ += |
| 543 | static_cast<uint32_t>(preprocess_frame_.samples_per_channel_); |
| 544 | expected_in_ts_ += static_cast<uint32_t>(in_frame.samples_per_channel_); |
| 545 | |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | ///////////////////////////////////////// |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 550 | // (FEC) Forward Error Correction (codec internal) |
| 551 | // |
| 552 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 553 | int AudioCodingModuleImpl::SetPacketLossRate(int loss_rate) { |
| 554 | rtc::CritScope lock(&acm_crit_sect_); |
| 555 | if (HaveValidEncoder("SetPacketLossRate")) { |
minyue | 4b9a2cb | 2016-11-30 06:49:59 -0800 | [diff] [blame] | 556 | encoder_stack_->OnReceivedUplinkPacketLossFraction(loss_rate / 100.0); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 557 | } |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | ///////////////////////////////////////// |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 562 | // Receiver |
| 563 | // |
| 564 | |
| 565 | int AudioCodingModuleImpl::InitializeReceiver() { |
| 566 | rtc::CritScope lock(&acm_crit_sect_); |
| 567 | return InitializeReceiverSafe(); |
| 568 | } |
| 569 | |
| 570 | // Initialize receiver, resets codec database etc. |
| 571 | int AudioCodingModuleImpl::InitializeReceiverSafe() { |
| 572 | // If the receiver is already initialized then we want to destroy any |
| 573 | // existing decoders. After a call to this function, we should have a clean |
| 574 | // start-up. |
kwiberg | 6b19b56 | 2016-09-20 04:02:25 -0700 | [diff] [blame] | 575 | if (receiver_initialized_) |
| 576 | receiver_.RemoveAllCodecs(); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 577 | receiver_.FlushBuffers(); |
| 578 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 579 | receiver_initialized_ = true; |
| 580 | return 0; |
| 581 | } |
| 582 | |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 583 | void AudioCodingModuleImpl::SetReceiveCodecs( |
| 584 | const std::map<int, SdpAudioFormat>& codecs) { |
| 585 | rtc::CritScope lock(&acm_crit_sect_); |
| 586 | receiver_.SetCodecs(codecs); |
| 587 | } |
| 588 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 589 | // Incoming packet from network parsed and ready for decode. |
| 590 | int AudioCodingModuleImpl::IncomingPacket(const uint8_t* incoming_payload, |
| 591 | const size_t payload_length, |
Niels Möller | afb5dbb | 2019-02-15 15:21:47 +0100 | [diff] [blame] | 592 | const RTPHeader& rtp_header) { |
henrik.lundin | b8c55b1 | 2017-05-10 07:38:01 -0700 | [diff] [blame] | 593 | RTC_DCHECK_EQ(payload_length == 0, incoming_payload == nullptr); |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 594 | return receiver_.InsertPacket( |
| 595 | rtp_header, |
| 596 | rtc::ArrayView<const uint8_t>(incoming_payload, payload_length)); |
| 597 | } |
| 598 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 599 | // Get 10 milliseconds of raw audio data to play out. |
| 600 | // Automatic resample to the requested frequency. |
| 601 | int AudioCodingModuleImpl::PlayoutData10Ms(int desired_freq_hz, |
| 602 | AudioFrame* audio_frame, |
| 603 | bool* muted) { |
| 604 | // GetAudio always returns 10 ms, at the requested sample rate. |
| 605 | if (receiver_.GetAudio(desired_freq_hz, audio_frame, muted) != 0) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 606 | RTC_LOG(LS_ERROR) << "PlayoutData failed, RecOut Failed"; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 607 | return -1; |
| 608 | } |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 609 | return 0; |
| 610 | } |
| 611 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 612 | ///////////////////////////////////////// |
| 613 | // Statistics |
| 614 | // |
| 615 | |
| 616 | // TODO(turajs) change the return value to void. Also change the corresponding |
| 617 | // NetEq function. |
| 618 | int AudioCodingModuleImpl::GetNetworkStatistics(NetworkStatistics* statistics) { |
| 619 | receiver_.GetNetworkStatistics(statistics); |
| 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | int AudioCodingModuleImpl::RegisterVADCallback(ACMVADCallback* vad_callback) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 624 | RTC_LOG(LS_VERBOSE) << "RegisterVADCallback()"; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 625 | rtc::CritScope lock(&callback_crit_sect_); |
| 626 | vad_callback_ = vad_callback; |
| 627 | return 0; |
| 628 | } |
| 629 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 630 | bool AudioCodingModuleImpl::HaveValidEncoder(const char* caller_name) const { |
| 631 | if (!encoder_stack_) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 632 | RTC_LOG(LS_ERROR) << caller_name << " failed: No send codec is registered."; |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 633 | return false; |
| 634 | } |
| 635 | return true; |
| 636 | } |
| 637 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 638 | void AudioCodingModuleImpl::GetDecodingCallStatistics( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 639 | AudioDecodingCallStats* call_stats) const { |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 640 | receiver_.GetDecodingCallStatistics(call_stats); |
| 641 | } |
| 642 | |
ivoc | e1198e0 | 2017-09-08 08:13:19 -0700 | [diff] [blame] | 643 | ANAStats AudioCodingModuleImpl::GetANAStats() const { |
| 644 | rtc::CritScope lock(&acm_crit_sect_); |
| 645 | if (encoder_stack_) |
| 646 | return encoder_stack_->GetANAStats(); |
| 647 | // If no encoder is set, return default stats. |
| 648 | return ANAStats(); |
| 649 | } |
| 650 | |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 651 | } // namespace |
| 652 | |
Karl Wiberg | 5817d3d | 2018-04-06 10:06:42 +0200 | [diff] [blame] | 653 | AudioCodingModule::Config::Config( |
| 654 | rtc::scoped_refptr<AudioDecoderFactory> decoder_factory) |
| 655 | : neteq_config(), |
| 656 | clock(Clock::GetRealTimeClock()), |
| 657 | decoder_factory(decoder_factory) { |
kwiberg | 36a4388 | 2016-08-29 05:33:32 -0700 | [diff] [blame] | 658 | // Post-decode VAD is disabled by default in NetEq, however, Audio |
| 659 | // Conference Mixer relies on VAD decisions and fails without them. |
| 660 | neteq_config.enable_post_decode_vad = true; |
| 661 | } |
| 662 | |
| 663 | AudioCodingModule::Config::Config(const Config&) = default; |
| 664 | AudioCodingModule::Config::~Config() = default; |
| 665 | |
Henrik Lundin | 64dad83 | 2015-05-11 12:44:23 +0200 | [diff] [blame] | 666 | AudioCodingModule* AudioCodingModule::Create(const Config& config) { |
kwiberg | c13ded5 | 2016-06-17 06:00:45 -0700 | [diff] [blame] | 667 | return new AudioCodingModuleImpl(config); |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 668 | } |
| 669 | |
turaj@webrtc.org | 7959e16 | 2013-09-12 18:30:26 +0000 | [diff] [blame] | 670 | } // namespace webrtc |