OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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/acm2/audio_coding_module_impl.h" | 11 #include "webrtc/modules/audio_coding/acm2/audio_coding_module_impl.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <stdlib.h> | 14 #include <stdlib.h> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/safe_conversions.h" | 18 #include "webrtc/base/safe_conversions.h" |
19 #include "webrtc/engine_configurations.h" | 19 #include "webrtc/engine_configurations.h" |
20 #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" | 20 #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" |
21 #include "webrtc/modules/audio_coding/acm2/acm_common_defs.h" | 21 #include "webrtc/modules/audio_coding/acm2/acm_common_defs.h" |
22 #include "webrtc/modules/audio_coding/acm2/acm_resampler.h" | 22 #include "webrtc/modules/audio_coding/acm2/acm_resampler.h" |
23 #include "webrtc/modules/audio_coding/acm2/call_statistics.h" | 23 #include "webrtc/modules/audio_coding/acm2/call_statistics.h" |
24 #include "webrtc/system_wrappers/include/logging.h" | 24 #include "webrtc/system_wrappers/include/logging.h" |
25 #include "webrtc/system_wrappers/include/metrics.h" | 25 #include "webrtc/system_wrappers/include/metrics.h" |
26 #include "webrtc/system_wrappers/include/rw_lock_wrapper.h" | 26 #include "webrtc/system_wrappers/include/rw_lock_wrapper.h" |
27 #include "webrtc/system_wrappers/include/trace.h" | 27 #include "webrtc/system_wrappers/include/trace.h" |
28 #include "webrtc/typedefs.h" | 28 #include "webrtc/typedefs.h" |
29 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" | |
29 | 30 |
30 namespace webrtc { | 31 namespace webrtc { |
31 | 32 |
33 namespace { | |
34 | |
35 // Adds a codec usage sample to the histogram. | |
36 void UpdateCodecTypeHistogram(size_t codec_type) { | |
37 RTC_HISTOGRAM_ENUMERATION( | |
38 "WebRTC.Audio.Encoder.CodecType", codec_type, | |
39 static_cast<size_t>( | |
40 webrtc::AudioEncoder::CodecType::kMaxLoggedAudioCodecNames)); | |
41 } | |
42 } // namespace | |
43 | |
32 namespace acm2 { | 44 namespace acm2 { |
33 | 45 |
34 struct EncoderFactory { | 46 struct EncoderFactory { |
35 AudioEncoder* external_speech_encoder = nullptr; | 47 AudioEncoder* external_speech_encoder = nullptr; |
36 CodecManager codec_manager; | 48 CodecManager codec_manager; |
37 RentACodec rent_a_codec; | 49 RentACodec rent_a_codec; |
38 }; | 50 }; |
39 | 51 |
40 namespace { | 52 namespace { |
41 | 53 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 expected_in_ts_(0xD87F3F9F), | 190 expected_in_ts_(0xD87F3F9F), |
179 receiver_(config), | 191 receiver_(config), |
180 bitrate_logger_("WebRTC.Audio.TargetBitrateInKbps"), | 192 bitrate_logger_("WebRTC.Audio.TargetBitrateInKbps"), |
181 encoder_factory_(new EncoderFactory), | 193 encoder_factory_(new EncoderFactory), |
182 encoder_stack_(nullptr), | 194 encoder_stack_(nullptr), |
183 previous_pltype_(255), | 195 previous_pltype_(255), |
184 receiver_initialized_(false), | 196 receiver_initialized_(false), |
185 first_10ms_data_(false), | 197 first_10ms_data_(false), |
186 first_frame_(true), | 198 first_frame_(true), |
187 packetization_callback_(NULL), | 199 packetization_callback_(NULL), |
188 vad_callback_(NULL) { | 200 vad_callback_(NULL), |
201 codec_histogram_bins_log_(), | |
202 number_of_consecutive_empty_packets_(0) { | |
189 if (InitializeReceiverSafe() < 0) { | 203 if (InitializeReceiverSafe() < 0) { |
190 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, | 204 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_, |
191 "Cannot initialize receiver"); | 205 "Cannot initialize receiver"); |
192 } | 206 } |
193 WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id_, "Created"); | 207 WEBRTC_TRACE(webrtc::kTraceMemory, webrtc::kTraceAudioCoding, id_, "Created"); |
194 } | 208 } |
195 | 209 |
196 AudioCodingModuleImpl::~AudioCodingModuleImpl() = default; | 210 AudioCodingModuleImpl::~AudioCodingModuleImpl() = default; |
197 | 211 |
198 int32_t AudioCodingModuleImpl::Encode(const InputData& input_data) { | 212 int32_t AudioCodingModuleImpl::Encode(const InputData& input_data) { |
(...skipping 25 matching lines...) Expand all Loading... | |
224 input_data.length_per_channel), | 238 input_data.length_per_channel), |
225 &encode_buffer_); | 239 &encode_buffer_); |
226 | 240 |
227 bitrate_logger_.MaybeLog(encoder_stack_->GetTargetBitrate() / 1000); | 241 bitrate_logger_.MaybeLog(encoder_stack_->GetTargetBitrate() / 1000); |
228 if (encode_buffer_.size() == 0 && !encoded_info.send_even_if_empty) { | 242 if (encode_buffer_.size() == 0 && !encoded_info.send_even_if_empty) { |
229 // Not enough data. | 243 // Not enough data. |
230 return 0; | 244 return 0; |
231 } | 245 } |
232 previous_pltype = previous_pltype_; // Read it while we have the critsect. | 246 previous_pltype = previous_pltype_; // Read it while we have the critsect. |
233 | 247 |
248 // Log codec type to histogram once every 500 packets. | |
249 if (encoded_info.encoded_bytes == 0) { | |
250 ++number_of_consecutive_empty_packets_; | |
251 } else { | |
252 size_t codec_type = static_cast<size_t>(encoded_info.encoder_type); | |
253 codec_histogram_bins_log_[codec_type] += | |
254 number_of_consecutive_empty_packets_; | |
ossu
2016/05/12 15:18:46
Well, now, this is clearly wrong. If we're not get
aleloi
2016/05/12 15:30:14
Acknowledged.
| |
255 number_of_consecutive_empty_packets_ = 0; | |
256 if (codec_histogram_bins_log_[codec_type] >= 500) { | |
257 codec_histogram_bins_log_[codec_type] -= 500; | |
258 UpdateCodecTypeHistogram(codec_type); | |
259 } | |
260 } | |
261 | |
234 RTPFragmentationHeader my_fragmentation; | 262 RTPFragmentationHeader my_fragmentation; |
235 ConvertEncodedInfoToFragmentationHeader(encoded_info, &my_fragmentation); | 263 ConvertEncodedInfoToFragmentationHeader(encoded_info, &my_fragmentation); |
236 FrameType frame_type; | 264 FrameType frame_type; |
237 if (encode_buffer_.size() == 0 && encoded_info.send_even_if_empty) { | 265 if (encode_buffer_.size() == 0 && encoded_info.send_even_if_empty) { |
238 frame_type = kEmptyFrame; | 266 frame_type = kEmptyFrame; |
239 encoded_info.payload_type = previous_pltype; | 267 encoded_info.payload_type = previous_pltype; |
240 } else { | 268 } else { |
241 RTC_DCHECK_GT(encode_buffer_.size(), 0u); | 269 RTC_DCHECK_GT(encode_buffer_.size(), 0u); |
242 frame_type = encoded_info.speech ? kAudioFrameSpeech : kAudioFrameCN; | 270 frame_type = encoded_info.speech ? kAudioFrameSpeech : kAudioFrameCN; |
243 } | 271 } |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
938 return receiver_.LeastRequiredDelayMs(); | 966 return receiver_.LeastRequiredDelayMs(); |
939 } | 967 } |
940 | 968 |
941 void AudioCodingModuleImpl::GetDecodingCallStatistics( | 969 void AudioCodingModuleImpl::GetDecodingCallStatistics( |
942 AudioDecodingCallStats* call_stats) const { | 970 AudioDecodingCallStats* call_stats) const { |
943 receiver_.GetDecodingCallStatistics(call_stats); | 971 receiver_.GetDecodingCallStatistics(call_stats); |
944 } | 972 } |
945 | 973 |
946 } // namespace acm2 | 974 } // namespace acm2 |
947 } // namespace webrtc | 975 } // namespace webrtc |
OLD | NEW |