OLD | NEW |
---|---|
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 #include <cstdlib> | |
15 | |
13 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
14 #include "webrtc/base/trace_event.h" | 17 #include "webrtc/base/trace_event.h" |
18 #include "webrtc/system_wrappers/include/metrics.h" | |
15 | 19 |
16 namespace webrtc { | 20 namespace webrtc { |
17 | 21 |
22 namespace { | |
23 enum HistogramAudioCodecType { | |
hlundin-webrtc
2016/05/11 08:27:26
Can you use enum class here, or is there something
| |
24 kUnknown = 0, | |
25 kOpus = 1, | |
26 kIsac = 2, | |
27 kG711 = 3, | |
28 kG722 = 4, | |
29 kIlbc = 5, | |
30 kAudioMax = 64 | |
31 }; | |
32 | |
33 // On every call to Encode(), the codec used is logged to the | |
34 // histogram with this probability. If Encode() is called every 10ms, | |
35 // the logging will be done approximately once every 5s. | |
36 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
| |
37 | |
38 // Translates the name of a codec returned by GetCodecName() into | |
39 // 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
| |
40 HistogramAudioCodecType CodecNameToHistogramCodecType(const char* codec_name) { | |
41 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.
| |
42 return kOpus; | |
43 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
| |
44 return kIsac; | |
45 else if (strcmp("g711", codec_name) == 0) | |
46 return kG711; | |
47 else if (strcmp("g722", codec_name) == 0) | |
48 return kG722; | |
49 else if (strcmp("iLBC", codec_name) == 0) | |
50 return kIlbc; | |
51 else | |
52 return kUnknown; | |
53 } | |
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
| |
54 | |
55 // Adds a codec usage sample to the histogram. | |
56 void UpdateCodecTypeHistogram(const char* codec_name) { | |
57 RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.Encoder.CodecType", | |
58 CodecNameToHistogramCodecType(codec_name), | |
59 kAudioMax); | |
60 } | |
61 | |
62 } // namespace | |
63 | |
18 AudioEncoder::EncodedInfo::EncodedInfo() = default; | 64 AudioEncoder::EncodedInfo::EncodedInfo() = default; |
19 AudioEncoder::EncodedInfo::EncodedInfo(const EncodedInfo&) = default; | 65 AudioEncoder::EncodedInfo::EncodedInfo(const EncodedInfo&) = default; |
20 AudioEncoder::EncodedInfo::EncodedInfo(EncodedInfo&&) = default; | 66 AudioEncoder::EncodedInfo::EncodedInfo(EncodedInfo&&) = default; |
21 AudioEncoder::EncodedInfo::~EncodedInfo() = default; | 67 AudioEncoder::EncodedInfo::~EncodedInfo() = default; |
22 AudioEncoder::EncodedInfo& AudioEncoder::EncodedInfo::operator=( | 68 AudioEncoder::EncodedInfo& AudioEncoder::EncodedInfo::operator=( |
23 const EncodedInfo&) = default; | 69 const EncodedInfo&) = default; |
24 AudioEncoder::EncodedInfo& AudioEncoder::EncodedInfo::operator=(EncodedInfo&&) = | 70 AudioEncoder::EncodedInfo& AudioEncoder::EncodedInfo::operator=(EncodedInfo&&) = |
25 default; | 71 default; |
26 | 72 |
27 int AudioEncoder::RtpTimestampRateHz() const { | 73 int AudioEncoder::RtpTimestampRateHz() const { |
28 return SampleRateHz(); | 74 return SampleRateHz(); |
29 } | 75 } |
30 | 76 |
31 AudioEncoder::EncodedInfo AudioEncoder::Encode( | 77 AudioEncoder::EncodedInfo AudioEncoder::Encode( |
32 uint32_t rtp_timestamp, | 78 uint32_t rtp_timestamp, |
33 rtc::ArrayView<const int16_t> audio, | 79 rtc::ArrayView<const int16_t> audio, |
34 rtc::Buffer* encoded) { | 80 rtc::Buffer* encoded) { |
35 TRACE_EVENT0("webrtc", "AudioEncoder::Encode"); | 81 TRACE_EVENT0("webrtc", "AudioEncoder::Encode"); |
36 RTC_CHECK_EQ(audio.size(), | 82 RTC_CHECK_EQ(audio.size(), |
37 static_cast<size_t>(NumChannels() * SampleRateHz() / 100)); | 83 static_cast<size_t>(NumChannels() * SampleRateHz() / 100)); |
38 | 84 |
85 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.
| |
86 UpdateCodecTypeHistogram(GetCodecName()); | |
87 | |
39 const size_t old_size = encoded->size(); | 88 const size_t old_size = encoded->size(); |
40 EncodedInfo info = EncodeImpl(rtp_timestamp, audio, encoded); | 89 EncodedInfo info = EncodeImpl(rtp_timestamp, audio, encoded); |
41 RTC_CHECK_EQ(encoded->size() - old_size, info.encoded_bytes); | 90 RTC_CHECK_EQ(encoded->size() - old_size, info.encoded_bytes); |
42 return info; | 91 return info; |
43 } | 92 } |
44 | 93 |
45 bool AudioEncoder::SetFec(bool enable) { | 94 bool AudioEncoder::SetFec(bool enable) { |
46 return !enable; | 95 return !enable; |
47 } | 96 } |
48 | 97 |
49 bool AudioEncoder::SetDtx(bool enable) { | 98 bool AudioEncoder::SetDtx(bool enable) { |
50 return !enable; | 99 return !enable; |
51 } | 100 } |
52 | 101 |
53 bool AudioEncoder::SetApplication(Application application) { | 102 bool AudioEncoder::SetApplication(Application application) { |
54 return false; | 103 return false; |
55 } | 104 } |
56 | 105 |
57 void AudioEncoder::SetMaxPlaybackRate(int frequency_hz) {} | 106 void AudioEncoder::SetMaxPlaybackRate(int frequency_hz) {} |
58 | 107 |
59 void AudioEncoder::SetProjectedPacketLossRate(double fraction) {} | 108 void AudioEncoder::SetProjectedPacketLossRate(double fraction) {} |
60 | 109 |
61 void AudioEncoder::SetTargetBitrate(int target_bps) {} | 110 void AudioEncoder::SetTargetBitrate(int target_bps) {} |
62 | 111 |
112 const char* AudioEncoder::GetCodecName() const { | |
113 return nullptr; | |
114 } | |
115 | |
63 size_t AudioEncoder::MaxEncodedBytes() const { | 116 size_t AudioEncoder::MaxEncodedBytes() const { |
64 RTC_CHECK(false); | 117 RTC_CHECK(false); |
65 return 0; | 118 return 0; |
66 } | 119 } |
67 | |
68 } // namespace webrtc | 120 } // namespace webrtc |
OLD | NEW |