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

Unified Diff: webrtc/modules/audio_coding/codecs/audio_encoder.cc

Issue 1967503002: Audio codec usage statistics (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: CL attempt 2. Added/responded to most comments 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_coding/codecs/audio_encoder.cc
diff --git a/webrtc/modules/audio_coding/codecs/audio_encoder.cc b/webrtc/modules/audio_coding/codecs/audio_encoder.cc
index 2b08dd85940fc2210f3320abe3c9347b54589d53..43cc4c6234ffe0f06e12bd368d3718e9a72ee22c 100644
--- a/webrtc/modules/audio_coding/codecs/audio_encoder.cc
+++ b/webrtc/modules/audio_coding/codecs/audio_encoder.cc
@@ -10,11 +10,43 @@
#include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
+#include <cstring>
+
#include "webrtc/base/checks.h"
#include "webrtc/base/trace_event.h"
+#include "webrtc/system_wrappers/include/metrics.h"
namespace webrtc {
+namespace {
+
+constexpr int kAudioMax = 64;
hlundin-webrtc 2016/05/11 13:03:55 The name kAudioMax is a bit too generic. Can you c
aleloi 2016/05/11 14:05:56 I renamed it into kMaxCodecNames. Re static_asser
+
+// Translates the name of a codec returned by GetCodecName() into
+// one of the codec IDs in the table 'histogram_id' below.
+size_t CodecNameToHistogramCodecType(const char* codec_name) {
+ const std::pair<const char*, size_t> histogram_id[] = {
+ {"Opus", 1},
+ {"iSAC", 2},
+ {"g711", 3},
+ {"g722", 4},
+ {"iLBC", 5}
+ };
+ for (const auto & codec : histogram_id)
hlundin-webrtc 2016/05/11 13:03:55 I think I'll prefer braces on the for loop. Omitti
aleloi 2016/05/11 14:10:49 Done.
+ if (codec_name != NULL && strcmp(codec.first, codec_name) == 0)
hlundin-webrtc 2016/05/11 13:03:55 nullptr
hlundin-webrtc 2016/05/11 13:03:55 nullptr
aleloi 2016/05/11 14:10:49 Done.
+ return codec.second;
+ return 0;
+}
+
+// Adds a codec usage sample to the histogram.
+void UpdateCodecTypeHistogram(const char* codec_name) {
+ RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.Encoder.CodecType",
+ CodecNameToHistogramCodecType(codec_name),
+ kAudioMax);
+}
+
+} // namespace
+
AudioEncoder::EncodedInfo::EncodedInfo() = default;
AudioEncoder::EncodedInfo::EncodedInfo(const EncodedInfo&) = default;
AudioEncoder::EncodedInfo::EncodedInfo(EncodedInfo&&) = default;
@@ -24,6 +56,10 @@ AudioEncoder::EncodedInfo& AudioEncoder::EncodedInfo::operator=(
AudioEncoder::EncodedInfo& AudioEncoder::EncodedInfo::operator=(EncodedInfo&&) =
default;
+AudioEncoder::AudioEncoder() {
+ encoded_packets = 0;
+}
+
int AudioEncoder::RtpTimestampRateHz() const {
return SampleRateHz();
}
@@ -36,6 +72,12 @@ AudioEncoder::EncodedInfo AudioEncoder::Encode(
RTC_CHECK_EQ(audio.size(),
static_cast<size_t>(NumChannels() * SampleRateHz() / 100));
+ encoded_packets++;
+ if (encoded_packets % 500 == 0) {
+ encoded_packets = 0;
+ UpdateCodecTypeHistogram(GetCodecName());
+ }
+
const size_t old_size = encoded->size();
EncodedInfo info = EncodeImpl(rtp_timestamp, audio, encoded);
RTC_CHECK_EQ(encoded->size() - old_size, info.encoded_bytes);
@@ -60,9 +102,12 @@ void AudioEncoder::SetProjectedPacketLossRate(double fraction) {}
void AudioEncoder::SetTargetBitrate(int target_bps) {}
+const char* AudioEncoder::GetCodecName() const {
+ return nullptr;
+}
+
size_t AudioEncoder::MaxEncodedBytes() const {
RTC_CHECK(false);
return 0;
}
-
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698