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

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: Moved logging to AudioCodingModuleImpl 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
(...skipping 11 matching lines...) Expand all
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 29
30 namespace webrtc { 30 namespace webrtc {
31 31
32 namespace {
33
34 struct CodecNameIDPair {
hlundin-webrtc 2016/05/12 12:23:39 The style guide says you should write CodecNameIdP
35 const char* name;
36 size_t id;
37 };
kwiberg-webrtc 2016/05/12 13:01:51 Please document. Alternatively, move this definiti
38
39
40 // Ensures that every element of passed array har .id field less than
hlundin-webrtc 2016/05/12 12:23:39 har?
41 // kMaxCodecNames and that count starts from '1' with 1-step
42 // increments
43 template<int N>
44 constexpr bool idSLessThanMaxCodecNames(const CodecNameIDPair (&array) [N],
hlundin-webrtc 2016/05/12 12:23:39 Name formatting...
45 size_t index) {
46 return (index >= N) ||
47 (array[index].id < acm2::AudioCodingModuleImpl::kMaxAudioCodecNames &&
48 array[index].id == index + 1 &&
49 idSLessThanMaxCodecNames(array, index + 1));
50 }
kwiberg-webrtc 2016/05/12 13:01:51 This is a lot of hard-to-read code, and it doesn't
aleloi 2016/05/12 13:25:46 I claim it does check that ID:s are different and
kwiberg-webrtc 2016/05/12 23:30:21 Oh, I see. I didn't read it carefully, just enough
51
52 // Translates the name of a codec returned by GetCodecName() into
kwiberg-webrtc 2016/05/12 13:01:51 That's no longer where the names come from.
aleloi 2016/05/12 13:25:47 Acknowledged.
53 // one of the codec IDs in the table 'histogram_id' below.
54 size_t CodecNameToHistogramCodecType(const char* codec_name) {
55 constexpr CodecNameIDPair histogram_id[] = {
kwiberg-webrtc 2016/05/12 13:01:51 static constexpr. Otherwise the compiler might put
aleloi 2016/05/12 13:25:46 Done.
56 {"Opus", 1},
kwiberg-webrtc 2016/05/12 13:01:51 Add a comment before the first entry explaining wh
aleloi 2016/05/12 13:25:47 Done.
57 {"iSAC", 2},
58 {"g711A", 3},
59 {"g711U", 4},
60 {"g722", 5},
61 {"iLBC", 6}
kwiberg-webrtc 2016/05/12 13:01:51 Use a trailing comma here too. Otherwise, the diff
aleloi 2016/05/12 13:25:47 I didn't know that was allowed in C++! Always lear
kwiberg-webrtc 2016/05/12 23:30:21 I've never actually checked what the standard says
62 };
63
64 static_assert(idSLessThanMaxCodecNames(histogram_id, 0),
65 "Cannot guarantee that codec ID does not exceed boundary.");
66
67 for (const auto & codec : histogram_id) {
kwiberg-webrtc 2016/05/12 13:01:51 No space between auto and &. (Did you run git cl f
aleloi 2016/05/12 13:25:47 Nope, forgot!
68 if (codec_name != nullptr && strcmp(codec.name, codec_name) == 0)
ossu 2016/05/12 12:50:14 You should check codec_name before entering the lo
kwiberg-webrtc 2016/05/12 13:01:51 Pointers are true iff they're not null, so just
aleloi 2016/05/12 13:25:46 Done.
aleloi 2016/05/12 13:25:47 I followed ossu's recommendation and moved the che
kwiberg-webrtc 2016/05/12 23:30:21 OK. You're not alone in inexplicably preferring th
69 return codec.id;
70 }
71 return 0;
72 }
73
74 // Adds a codec usage sample to the histogram.
75 void UpdateCodecTypeHistogram(size_t codec_type) {
76 RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.Encoder.CodecType",
77 codec_type,
78 acm2::AudioCodingModuleImpl::kMaxAudioCodecNames);
79 }
80 } // namespace
81
82
32 namespace acm2 { 83 namespace acm2 {
33 84
34 struct EncoderFactory { 85 struct EncoderFactory {
35 AudioEncoder* external_speech_encoder = nullptr; 86 AudioEncoder* external_speech_encoder = nullptr;
36 CodecManager codec_manager; 87 CodecManager codec_manager;
37 RentACodec rent_a_codec; 88 RentACodec rent_a_codec;
38 }; 89 };
39 90
40 namespace { 91 namespace {
41 92
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 expected_in_ts_(0xD87F3F9F), 229 expected_in_ts_(0xD87F3F9F),
179 receiver_(config), 230 receiver_(config),
180 bitrate_logger_("WebRTC.Audio.TargetBitrateInKbps"), 231 bitrate_logger_("WebRTC.Audio.TargetBitrateInKbps"),
181 encoder_factory_(new EncoderFactory), 232 encoder_factory_(new EncoderFactory),
182 encoder_stack_(nullptr), 233 encoder_stack_(nullptr),
183 previous_pltype_(255), 234 previous_pltype_(255),
184 receiver_initialized_(false), 235 receiver_initialized_(false),
185 first_10ms_data_(false), 236 first_10ms_data_(false),
186 first_frame_(true), 237 first_frame_(true),
187 packetization_callback_(NULL), 238 packetization_callback_(NULL),
188 vad_callback_(NULL) { 239 vad_callback_(NULL),
240 codec_histogram_bins_log(),
kwiberg-webrtc 2016/05/12 13:01:51 Don't you need to fill this with zeros?
aleloi 2016/05/12 13:25:47 It gets filled with zeroes with codec_histogram_bi
kwiberg-webrtc 2016/05/12 23:30:21 Right. Thanks!
241 number_of_consecutive_empty_packets(0) {
189 if (InitializeReceiverSafe() < 0) { 242 if (InitializeReceiverSafe() < 0) {
190 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, 243 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
191 "Cannot initialize receiver"); 244 "Cannot initialize receiver");
192 } 245 }
193 WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id_, "Created"); 246 WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id_, "Created");
194 } 247 }
195 248
196 AudioCodingModuleImpl::~AudioCodingModuleImpl() = default; 249 AudioCodingModuleImpl::~AudioCodingModuleImpl() = default;
197 250
198 int32_t AudioCodingModuleImpl::Encode(const InputData& input_data) { 251 int32_t AudioCodingModuleImpl::Encode(const InputData& input_data) {
(...skipping 25 matching lines...) Expand all
224 input_data.length_per_channel), 277 input_data.length_per_channel),
225 &encode_buffer_); 278 &encode_buffer_);
226 279
227 bitrate_logger_.MaybeLog(encoder_stack_->GetTargetBitrate() / 1000); 280 bitrate_logger_.MaybeLog(encoder_stack_->GetTargetBitrate() / 1000);
228 if (encode_buffer_.size() == 0 && !encoded_info.send_even_if_empty) { 281 if (encode_buffer_.size() == 0 && !encoded_info.send_even_if_empty) {
229 // Not enough data. 282 // Not enough data.
230 return 0; 283 return 0;
231 } 284 }
232 previous_pltype = previous_pltype_; // Read it while we have the critsect. 285 previous_pltype = previous_pltype_; // Read it while we have the critsect.
233 286
287 // Log codec type to histogram once every 500 packets.
288 if (encoded_info.encoded_bytes == 0) {
289 number_of_consecutive_empty_packets += 1;
ossu 2016/05/12 12:50:14 I'd prefer ++number_of_consecutive_empty_packets.
aleloi 2016/05/12 13:25:47 Done.
290 }
291 else {
ossu 2016/05/12 12:50:14 else on the same line as the closing curly seems t
aleloi 2016/05/12 13:25:47 Done.
292 size_t codec_type =
ossu 2016/05/12 12:50:14 So the codec id is looked up based on its name onc
kwiberg-webrtc 2016/05/12 13:01:51 I'm guessing we'd need quite a lot of entries befo
aleloi 2016/05/12 13:25:47 We only do trivial operations in the lookup. A map
kwiberg-webrtc 2016/05/12 23:30:21 Yes. std::map will also do a lot of cache-unfriend
293 CodecNameToHistogramCodecType(encoded_info.encoder_name);
294 codec_histogram_bins_log[codec_type] += 1;
295 number_of_consecutive_empty_packets = 0;
kwiberg-webrtc 2016/05/12 13:01:51 Here you zero number_of_consecutive_empty_packets
aleloi 2016/05/12 13:25:47 Acknowledged.
296 if (codec_histogram_bins_log[codec_type] >= 500) {
297 codec_histogram_bins_log[codec_type] -= 500;
298 UpdateCodecTypeHistogram(codec_type);
299 }
300 }
301
234 RTPFragmentationHeader my_fragmentation; 302 RTPFragmentationHeader my_fragmentation;
235 ConvertEncodedInfoToFragmentationHeader(encoded_info, &my_fragmentation); 303 ConvertEncodedInfoToFragmentationHeader(encoded_info, &my_fragmentation);
236 FrameType frame_type; 304 FrameType frame_type;
237 if (encode_buffer_.size() == 0 && encoded_info.send_even_if_empty) { 305 if (encode_buffer_.size() == 0 && encoded_info.send_even_if_empty) {
238 frame_type = kEmptyFrame; 306 frame_type = kEmptyFrame;
239 encoded_info.payload_type = previous_pltype; 307 encoded_info.payload_type = previous_pltype;
240 } else { 308 } else {
241 RTC_DCHECK_GT(encode_buffer_.size(), 0u); 309 RTC_DCHECK_GT(encode_buffer_.size(), 0u);
242 frame_type = encoded_info.speech ? kAudioFrameSpeech : kAudioFrameCN; 310 frame_type = encoded_info.speech ? kAudioFrameSpeech : kAudioFrameCN;
243 } 311 }
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 return receiver_.LeastRequiredDelayMs(); 1006 return receiver_.LeastRequiredDelayMs();
939 } 1007 }
940 1008
941 void AudioCodingModuleImpl::GetDecodingCallStatistics( 1009 void AudioCodingModuleImpl::GetDecodingCallStatistics(
942 AudioDecodingCallStats* call_stats) const { 1010 AudioDecodingCallStats* call_stats) const {
943 receiver_.GetDecodingCallStatistics(call_stats); 1011 receiver_.GetDecodingCallStatistics(call_stats);
944 } 1012 }
945 1013
946 } // namespace acm2 1014 } // namespace acm2
947 } // namespace webrtc 1015 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698