Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc

Issue 1967503002: Audio codec usage statistics (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Minor fixes Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/audio_coding/acm2/audio_coding_module_impl.h" 11 #include "webrtc/modules/audio_coding/acm2/audio_coding_module_impl.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #include <vector> 15 #include <vector>
16 16
17 #include "webrtc/base/checks.h" 17 #include "webrtc/base/checks.h"
18 #include "webrtc/base/safe_conversions.h" 18 #include "webrtc/base/safe_conversions.h"
19 #include "webrtc/engine_configurations.h" 19 #include "webrtc/engine_configurations.h"
20 #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" 20 #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h"
21 #include "webrtc/modules/audio_coding/acm2/acm_common_defs.h" 21 #include "webrtc/modules/audio_coding/acm2/acm_common_defs.h"
22 #include "webrtc/modules/audio_coding/acm2/acm_resampler.h" 22 #include "webrtc/modules/audio_coding/acm2/acm_resampler.h"
23 #include "webrtc/modules/audio_coding/acm2/call_statistics.h" 23 #include "webrtc/modules/audio_coding/acm2/call_statistics.h"
24 #include "webrtc/system_wrappers/include/logging.h" 24 #include "webrtc/system_wrappers/include/logging.h"
25 #include "webrtc/system_wrappers/include/metrics.h" 25 #include "webrtc/system_wrappers/include/metrics.h"
26 #include "webrtc/system_wrappers/include/rw_lock_wrapper.h" 26 #include "webrtc/system_wrappers/include/rw_lock_wrapper.h"
27 #include "webrtc/system_wrappers/include/trace.h" 27 #include "webrtc/system_wrappers/include/trace.h"
28 #include "webrtc/typedefs.h" 28 #include "webrtc/typedefs.h"
29 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
29 30
30 namespace webrtc { 31 namespace webrtc {
31 32
33 namespace {
34
35 // Adds a codec usage sample to the histogram.
36 void UpdateCodecTypeHistogram(size_t codec_type) {
37 RTC_HISTOGRAM_ENUMERATION(
38 "WebRTC.Audio.Encoder.CodecType", codec_type,
39 static_cast<size_t>(
40 webrtc::AudioEncoder::CodecType::kMaxLoggedAudioCodecNames));
41 }
42
43 } // namespace
44
32 namespace acm2 { 45 namespace acm2 {
33 46
34 struct EncoderFactory { 47 struct EncoderFactory {
35 AudioEncoder* external_speech_encoder = nullptr; 48 AudioEncoder* external_speech_encoder = nullptr;
36 CodecManager codec_manager; 49 CodecManager codec_manager;
37 RentACodec rent_a_codec; 50 RentACodec rent_a_codec;
38 }; 51 };
39 52
40 namespace { 53 namespace {
41 54
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 expected_in_ts_(0xD87F3F9F), 191 expected_in_ts_(0xD87F3F9F),
179 receiver_(config), 192 receiver_(config),
180 bitrate_logger_("WebRTC.Audio.TargetBitrateInKbps"), 193 bitrate_logger_("WebRTC.Audio.TargetBitrateInKbps"),
181 encoder_factory_(new EncoderFactory), 194 encoder_factory_(new EncoderFactory),
182 encoder_stack_(nullptr), 195 encoder_stack_(nullptr),
183 previous_pltype_(255), 196 previous_pltype_(255),
184 receiver_initialized_(false), 197 receiver_initialized_(false),
185 first_10ms_data_(false), 198 first_10ms_data_(false),
186 first_frame_(true), 199 first_frame_(true),
187 packetization_callback_(NULL), 200 packetization_callback_(NULL),
188 vad_callback_(NULL) { 201 vad_callback_(NULL),
202 codec_histogram_bins_log_(),
203 number_of_consecutive_empty_packets_(0) {
189 if (InitializeReceiverSafe() < 0) { 204 if (InitializeReceiverSafe() < 0) {
190 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, 205 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
191 "Cannot initialize receiver"); 206 "Cannot initialize receiver");
192 } 207 }
193 WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id_, "Created"); 208 WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id_, "Created");
194 } 209 }
195 210
196 AudioCodingModuleImpl::~AudioCodingModuleImpl() = default; 211 AudioCodingModuleImpl::~AudioCodingModuleImpl() = default;
197 212
198 int32_t AudioCodingModuleImpl::Encode(const InputData& input_data) { 213 int32_t AudioCodingModuleImpl::Encode(const InputData& input_data) {
(...skipping 25 matching lines...) Expand all
224 input_data.length_per_channel), 239 input_data.length_per_channel),
225 &encode_buffer_); 240 &encode_buffer_);
226 241
227 bitrate_logger_.MaybeLog(encoder_stack_->GetTargetBitrate() / 1000); 242 bitrate_logger_.MaybeLog(encoder_stack_->GetTargetBitrate() / 1000);
228 if (encode_buffer_.size() == 0 && !encoded_info.send_even_if_empty) { 243 if (encode_buffer_.size() == 0 && !encoded_info.send_even_if_empty) {
229 // Not enough data. 244 // Not enough data.
230 return 0; 245 return 0;
231 } 246 }
232 previous_pltype = previous_pltype_; // Read it while we have the critsect. 247 previous_pltype = previous_pltype_; // Read it while we have the critsect.
233 248
249 // Log codec type to histogram once every 500 packets.
250 if (encoded_info.encoded_bytes == 0) {
251 ++number_of_consecutive_empty_packets_;
252 } else {
253 size_t codec_type = static_cast<size_t>(encoded_info.encoder_type);
254 codec_histogram_bins_log_[codec_type] +=
255 number_of_consecutive_empty_packets_ + 1;
256 number_of_consecutive_empty_packets_ = 0;
257 if (codec_histogram_bins_log_[codec_type] >= 500) {
258 codec_histogram_bins_log_[codec_type] -= 500;
259 UpdateCodecTypeHistogram(codec_type);
260 }
261 }
262
234 RTPFragmentationHeader my_fragmentation; 263 RTPFragmentationHeader my_fragmentation;
235 ConvertEncodedInfoToFragmentationHeader(encoded_info, &my_fragmentation); 264 ConvertEncodedInfoToFragmentationHeader(encoded_info, &my_fragmentation);
236 FrameType frame_type; 265 FrameType frame_type;
237 if (encode_buffer_.size() == 0 && encoded_info.send_even_if_empty) { 266 if (encode_buffer_.size() == 0 && encoded_info.send_even_if_empty) {
238 frame_type = kEmptyFrame; 267 frame_type = kEmptyFrame;
239 encoded_info.payload_type = previous_pltype; 268 encoded_info.payload_type = previous_pltype;
240 } else { 269 } else {
241 RTC_DCHECK_GT(encode_buffer_.size(), 0u); 270 RTC_DCHECK_GT(encode_buffer_.size(), 0u);
242 frame_type = encoded_info.speech ? kAudioFrameSpeech : kAudioFrameCN; 271 frame_type = encoded_info.speech ? kAudioFrameSpeech : kAudioFrameCN;
243 } 272 }
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 return receiver_.LeastRequiredDelayMs(); 967 return receiver_.LeastRequiredDelayMs();
939 } 968 }
940 969
941 void AudioCodingModuleImpl::GetDecodingCallStatistics( 970 void AudioCodingModuleImpl::GetDecodingCallStatistics(
942 AudioDecodingCallStats* call_stats) const { 971 AudioDecodingCallStats* call_stats) const {
943 receiver_.GetDecodingCallStatistics(call_stats); 972 receiver_.GetDecodingCallStatistics(call_stats);
944 } 973 }
945 974
946 } // namespace acm2 975 } // namespace acm2
947 } // namespace webrtc 976 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698