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

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: 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..235612ebe69038924a78c2973c4d4895975cebd7 100644
--- a/webrtc/modules/audio_coding/codecs/audio_encoder.cc
+++ b/webrtc/modules/audio_coding/codecs/audio_encoder.cc
@@ -10,11 +10,57 @@
#include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
+#include <cstring>
+#include <cstdlib>
+
#include "webrtc/base/checks.h"
#include "webrtc/base/trace_event.h"
+#include "webrtc/system_wrappers/include/metrics.h"
namespace webrtc {
+namespace {
+enum HistogramAudioCodecType {
hlundin-webrtc 2016/05/11 08:27:26 Can you use enum class here, or is there something
+ kUnknown = 0,
+ kOpus = 1,
+ kIsac = 2,
+ kG711 = 3,
+ kG722 = 4,
+ kIlbc = 5,
+ kAudioMax = 64
+};
+
+// On every call to Encode(), the codec used is logged to the
+// histogram with this probability. If Encode() is called every 10ms,
+// the logging will be done approximately once every 5s.
+const float kProbabilityToLogCodecType = 1.0 / 500.0;
kwiberg-webrtc 2016/05/11 00:47:00 constexpr?
aleloi 2016/05/11 11:16:13 Thanks, fixed in next cl
+
+// Translates the name of a codec returned by GetCodecName() into
+// one of the codec ID:s in CodecID
kwiberg-webrtc 2016/05/11 00:47:00 "ID:s" -> "IDs". What is CodecID?
aleloi 2016/05/11 11:16:13 CodecID was HistogramAudioCodecType earlier. I cha
+HistogramAudioCodecType CodecNameToHistogramCodecType(const char* codec_name) {
+ if (strcmp("Opus", codec_name) == 0)
kwiberg-webrtc 2016/05/11 00:47:00 codec_name can be null, but the behavior of strcmp
hlundin-webrtc 2016/05/11 08:27:26 We should make sure that the naming is consistent
aleloi 2016/05/11 11:16:13 Thanks, fixed in next cl. I took the names from th
hlundin-webrtc 2016/05/11 13:03:55 Acknowledged.
+ return kOpus;
+ else if (strcmp("iSac", codec_name) == 0)
kwiberg-webrtc 2016/05/11 00:47:00 iSAC
aleloi 2016/05/11 11:16:13 Thanks, fixed in next CL
+ return kIsac;
+ else if (strcmp("g711", codec_name) == 0)
+ return kG711;
+ else if (strcmp("g722", codec_name) == 0)
+ return kG722;
+ else if (strcmp("iLBC", codec_name) == 0)
+ return kIlbc;
+ else
+ return kUnknown;
+}
kwiberg-webrtc 2016/05/11 00:47:00 Hmm. You end up having to basically maintain two c
aleloi 2016/05/11 11:16:13 Is there a reason for declaring the 'histogram_id'
kwiberg-webrtc 2016/05/11 12:00:41 static const means it's a global constant that doe
+
+// 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;
@@ -36,6 +82,9 @@ AudioEncoder::EncodedInfo AudioEncoder::Encode(
RTC_CHECK_EQ(audio.size(),
static_cast<size_t>(NumChannels() * SampleRateHz() / 100));
+ if (rand() / RAND_MAX < kProbabilityToLogCodecType)
kwiberg-webrtc 2016/05/11 00:47:00 std::rand Also, since std::rand() returns an int,
the sun 2016/05/11 08:18:43 We shouldn't be using std::rand() since: a) it rel
kwiberg-webrtc 2016/05/11 08:52:24 Yeah, that's suboptimal because locking.
the sun 2016/05/11 10:35:01 Two sites: Encode() and dtor.
hlundin-webrtc 2016/05/11 10:37:20 dtor only if we care about the "remainder" (fracti
kwiberg-webrtc 2016/05/11 10:46:21 Short-lived codecs will have a different bias than
hlundin-webrtc 2016/05/11 11:01:37 Are some codecs expected to live shorter than othe
aleloi 2016/05/11 11:16:13 I talked with solenberg@ about using randomness. I
kwiberg-webrtc 2016/05/11 12:00:41 Not an issue. rand's state is global.
+ 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 +109,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