Index: webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc |
diff --git a/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc b/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc |
index 1a1ae37a8a38da869caa30fc78539ccb49c11028..999558298e603f1b35ae37f4597daf61d7429e1c 100644 |
--- a/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc |
+++ b/webrtc/modules/audio_coding/acm2/audio_coding_module_impl.cc |
@@ -29,6 +29,57 @@ |
namespace webrtc { |
+namespace { |
+ |
+struct CodecNameIDPair { |
hlundin-webrtc
2016/05/12 12:23:39
The style guide says you should write CodecNameIdP
|
+ const char* name; |
+ size_t id; |
+}; |
kwiberg-webrtc
2016/05/12 13:01:51
Please document. Alternatively, move this definiti
|
+ |
+ |
+// Ensures that every element of passed array har .id field less than |
hlundin-webrtc
2016/05/12 12:23:39
har?
|
+// kMaxCodecNames and that count starts from '1' with 1-step |
+// increments |
+template<int N> |
+constexpr bool idSLessThanMaxCodecNames(const CodecNameIDPair (&array) [N], |
hlundin-webrtc
2016/05/12 12:23:39
Name formatting...
|
+ size_t index) { |
+ return (index >= N) || |
+ (array[index].id < acm2::AudioCodingModuleImpl::kMaxAudioCodecNames && |
+ array[index].id == index + 1 && |
+ idSLessThanMaxCodecNames(array, index + 1)); |
+} |
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
|
+ |
+// 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.
|
+// one of the codec IDs in the table 'histogram_id' below. |
+size_t CodecNameToHistogramCodecType(const char* codec_name) { |
+ 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.
|
+ {"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.
|
+ {"iSAC", 2}, |
+ {"g711A", 3}, |
+ {"g711U", 4}, |
+ {"g722", 5}, |
+ {"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
|
+ }; |
+ |
+ static_assert(idSLessThanMaxCodecNames(histogram_id, 0), |
+ "Cannot guarantee that codec ID does not exceed boundary."); |
+ |
+ 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!
|
+ 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
|
+ return codec.id; |
+ } |
+ return 0; |
+} |
+ |
+// Adds a codec usage sample to the histogram. |
+void UpdateCodecTypeHistogram(size_t codec_type) { |
+ RTC_HISTOGRAM_ENUMERATION("WebRTC.Audio.Encoder.CodecType", |
+ codec_type, |
+ acm2::AudioCodingModuleImpl::kMaxAudioCodecNames); |
+} |
+} // namespace |
+ |
+ |
namespace acm2 { |
struct EncoderFactory { |
@@ -185,7 +236,9 @@ AudioCodingModuleImpl::AudioCodingModuleImpl( |
first_10ms_data_(false), |
first_frame_(true), |
packetization_callback_(NULL), |
- vad_callback_(NULL) { |
+ vad_callback_(NULL), |
+ 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!
|
+ number_of_consecutive_empty_packets(0) { |
if (InitializeReceiverSafe() < 0) { |
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, |
"Cannot initialize receiver"); |
@@ -231,6 +284,21 @@ int32_t AudioCodingModuleImpl::Encode(const InputData& input_data) { |
} |
previous_pltype = previous_pltype_; // Read it while we have the critsect. |
+ // Log codec type to histogram once every 500 packets. |
+ if (encoded_info.encoded_bytes == 0) { |
+ 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.
|
+ } |
+ 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.
|
+ 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
|
+ CodecNameToHistogramCodecType(encoded_info.encoder_name); |
+ codec_histogram_bins_log[codec_type] += 1; |
+ 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.
|
+ if (codec_histogram_bins_log[codec_type] >= 500) { |
+ codec_histogram_bins_log[codec_type] -= 500; |
+ UpdateCodecTypeHistogram(codec_type); |
+ } |
+ } |
+ |
RTPFragmentationHeader my_fragmentation; |
ConvertEncodedInfoToFragmentationHeader(encoded_info, &my_fragmentation); |
FrameType frame_type; |