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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 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/codecs/audio_encoder.h" 11 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
12 12
13 #include <cstring>
14
13 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
14 #include "webrtc/base/trace_event.h" 16 #include "webrtc/base/trace_event.h"
17 #include "webrtc/system_wrappers/include/metrics.h"
15 18
16 namespace webrtc { 19 namespace webrtc {
17 20
21 namespace {
22
23 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
24
25 // Translates the name of a codec returned by GetCodecName() into
26 // one of the codec IDs in the table 'histogram_id' below.
27 size_t CodecNameToHistogramCodecType(const char* codec_name) {
28 const std::pair<const char*, size_t> histogram_id[] = {
29 {"Opus", 1},
30 {"iSAC", 2},
31 {"g711", 3},
32 {"g722", 4},
33 {"iLBC", 5}
34 };
35 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.
36 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.
37 return codec.second;
38 return 0;
39 }
40
41 // Adds a codec usage sample to the histogram.
42 void UpdateCodecTypeHistogram(const char* codec_name) {
43 RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.Encoder.CodecType",
44 CodecNameToHistogramCodecType(codec_name),
45 kAudioMax);
46 }
47
48 } // namespace
49
18 AudioEncoder::EncodedInfo::EncodedInfo() = default; 50 AudioEncoder::EncodedInfo::EncodedInfo() = default;
19 AudioEncoder::EncodedInfo::EncodedInfo(const EncodedInfo&) = default; 51 AudioEncoder::EncodedInfo::EncodedInfo(const EncodedInfo&) = default;
20 AudioEncoder::EncodedInfo::EncodedInfo(EncodedInfo&&) = default; 52 AudioEncoder::EncodedInfo::EncodedInfo(EncodedInfo&&) = default;
21 AudioEncoder::EncodedInfo::~EncodedInfo() = default; 53 AudioEncoder::EncodedInfo::~EncodedInfo() = default;
22 AudioEncoder::EncodedInfo& AudioEncoder::EncodedInfo::operator=( 54 AudioEncoder::EncodedInfo& AudioEncoder::EncodedInfo::operator=(
23 const EncodedInfo&) = default; 55 const EncodedInfo&) = default;
24 AudioEncoder::EncodedInfo& AudioEncoder::EncodedInfo::operator=(EncodedInfo&&) = 56 AudioEncoder::EncodedInfo& AudioEncoder::EncodedInfo::operator=(EncodedInfo&&) =
25 default; 57 default;
26 58
59 AudioEncoder::AudioEncoder() {
60 encoded_packets = 0;
61 }
62
27 int AudioEncoder::RtpTimestampRateHz() const { 63 int AudioEncoder::RtpTimestampRateHz() const {
28 return SampleRateHz(); 64 return SampleRateHz();
29 } 65 }
30 66
31 AudioEncoder::EncodedInfo AudioEncoder::Encode( 67 AudioEncoder::EncodedInfo AudioEncoder::Encode(
32 uint32_t rtp_timestamp, 68 uint32_t rtp_timestamp,
33 rtc::ArrayView<const int16_t> audio, 69 rtc::ArrayView<const int16_t> audio,
34 rtc::Buffer* encoded) { 70 rtc::Buffer* encoded) {
35 TRACE_EVENT0("webrtc", "AudioEncoder::Encode"); 71 TRACE_EVENT0("webrtc", "AudioEncoder::Encode");
36 RTC_CHECK_EQ(audio.size(), 72 RTC_CHECK_EQ(audio.size(),
37 static_cast<size_t>(NumChannels() * SampleRateHz() / 100)); 73 static_cast<size_t>(NumChannels() * SampleRateHz() / 100));
38 74
75 encoded_packets++;
76 if (encoded_packets % 500 == 0) {
77 encoded_packets = 0;
78 UpdateCodecTypeHistogram(GetCodecName());
79 }
80
39 const size_t old_size = encoded->size(); 81 const size_t old_size = encoded->size();
40 EncodedInfo info = EncodeImpl(rtp_timestamp, audio, encoded); 82 EncodedInfo info = EncodeImpl(rtp_timestamp, audio, encoded);
41 RTC_CHECK_EQ(encoded->size() - old_size, info.encoded_bytes); 83 RTC_CHECK_EQ(encoded->size() - old_size, info.encoded_bytes);
42 return info; 84 return info;
43 } 85 }
44 86
45 bool AudioEncoder::SetFec(bool enable) { 87 bool AudioEncoder::SetFec(bool enable) {
46 return !enable; 88 return !enable;
47 } 89 }
48 90
49 bool AudioEncoder::SetDtx(bool enable) { 91 bool AudioEncoder::SetDtx(bool enable) {
50 return !enable; 92 return !enable;
51 } 93 }
52 94
53 bool AudioEncoder::SetApplication(Application application) { 95 bool AudioEncoder::SetApplication(Application application) {
54 return false; 96 return false;
55 } 97 }
56 98
57 void AudioEncoder::SetMaxPlaybackRate(int frequency_hz) {} 99 void AudioEncoder::SetMaxPlaybackRate(int frequency_hz) {}
58 100
59 void AudioEncoder::SetProjectedPacketLossRate(double fraction) {} 101 void AudioEncoder::SetProjectedPacketLossRate(double fraction) {}
60 102
61 void AudioEncoder::SetTargetBitrate(int target_bps) {} 103 void AudioEncoder::SetTargetBitrate(int target_bps) {}
62 104
105 const char* AudioEncoder::GetCodecName() const {
106 return nullptr;
107 }
108
63 size_t AudioEncoder::MaxEncodedBytes() const { 109 size_t AudioEncoder::MaxEncodedBytes() const {
64 RTC_CHECK(false); 110 RTC_CHECK(false);
65 return 0; 111 return 0;
66 } 112 }
67
68 } // namespace webrtc 113 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698