Added UMA logging for audio codec usage. A histogram statistic named "WebRTC.Audio.Encoder.CodecType" has been created.
Review-Url: https://codereview.webrtc.org/1967503002 Cr-Commit-Position: refs/heads/master@{#12760}
This commit is contained in:
parent
970567cab2
commit
8bce67b745
@ -29,6 +29,18 @@
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
namespace {
|
||||
|
||||
// Adds a codec usage sample to the histogram.
|
||||
void UpdateCodecTypeHistogram(size_t codec_type) {
|
||||
RTC_HISTOGRAM_ENUMERATION(
|
||||
"WebRTC.Audio.Encoder.CodecType", static_cast<int>(codec_type),
|
||||
static_cast<int>(
|
||||
webrtc::AudioEncoder::CodecType::kMaxLoggedAudioCodecTypes));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace acm2 {
|
||||
|
||||
struct EncoderFactory {
|
||||
@ -185,7 +197,9 @@ AudioCodingModuleImpl::AudioCodingModuleImpl(
|
||||
first_10ms_data_(false),
|
||||
first_frame_(true),
|
||||
packetization_callback_(NULL),
|
||||
vad_callback_(NULL) {
|
||||
vad_callback_(NULL),
|
||||
codec_histogram_bins_log_(),
|
||||
number_of_consecutive_empty_packets_(0) {
|
||||
if (InitializeReceiverSafe() < 0) {
|
||||
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
|
||||
"Cannot initialize receiver");
|
||||
@ -231,6 +245,20 @@ 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_;
|
||||
} else {
|
||||
size_t codec_type = static_cast<size_t>(encoded_info.encoder_type);
|
||||
codec_histogram_bins_log_[codec_type] +=
|
||||
number_of_consecutive_empty_packets_ + 1;
|
||||
number_of_consecutive_empty_packets_ = 0;
|
||||
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;
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include "webrtc/modules/audio_coding/acm2/acm_receiver.h"
|
||||
#include "webrtc/modules/audio_coding/acm2/acm_resampler.h"
|
||||
#include "webrtc/modules/audio_coding/acm2/codec_manager.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -298,6 +299,10 @@ class AudioCodingModuleImpl final : public AudioCodingModule {
|
||||
AudioPacketizationCallback* packetization_callback_
|
||||
GUARDED_BY(callback_crit_sect_);
|
||||
ACMVADCallback* vad_callback_ GUARDED_BY(callback_crit_sect_);
|
||||
|
||||
int codec_histogram_bins_log_[static_cast<size_t>(
|
||||
AudioEncoder::CodecType::kMaxLoggedAudioCodecTypes)];
|
||||
int number_of_consecutive_empty_packets_;
|
||||
};
|
||||
|
||||
} // namespace acm2
|
||||
|
||||
@ -25,12 +25,32 @@ namespace webrtc {
|
||||
// type must have an implementation of this class.
|
||||
class AudioEncoder {
|
||||
public:
|
||||
// Used for UMA logging of codec usage. The same codecs, with the
|
||||
// same values, must be listed in
|
||||
// src/tools/metrics/histograms/histograms.xml in chromium to log
|
||||
// correct values.
|
||||
enum class CodecType {
|
||||
kOther = 0, // Codec not specified, and/or not listed in this enum
|
||||
kOpus = 1,
|
||||
kIsac = 2,
|
||||
kPcmA = 3,
|
||||
kPcmU = 4,
|
||||
kG722 = 5,
|
||||
kIlbc = 6,
|
||||
|
||||
// Number of histogram bins in the UMA logging of codec types. The
|
||||
// total number of different codecs that are logged cannot exceed this
|
||||
// number.
|
||||
kMaxLoggedAudioCodecTypes
|
||||
};
|
||||
|
||||
struct EncodedInfoLeaf {
|
||||
size_t encoded_bytes = 0;
|
||||
uint32_t encoded_timestamp = 0;
|
||||
int payload_type = 0;
|
||||
bool send_even_if_empty = false;
|
||||
bool speech = true;
|
||||
CodecType encoder_type = CodecType::kOther;
|
||||
};
|
||||
|
||||
// This is the main struct for auxiliary encoding information. Each encoded
|
||||
|
||||
@ -96,6 +96,7 @@ AudioEncoder::EncodedInfo AudioEncoderPcm::EncodeImpl(
|
||||
encoded.data());
|
||||
});
|
||||
speech_buffer_.clear();
|
||||
info.encoder_type = GetCodecType();
|
||||
return info;
|
||||
}
|
||||
|
||||
@ -116,6 +117,10 @@ size_t AudioEncoderPcmA::BytesPerSample() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
AudioEncoder::CodecType AudioEncoderPcmA::GetCodecType() const {
|
||||
return AudioEncoder::CodecType::kPcmA;
|
||||
}
|
||||
|
||||
AudioEncoderPcmU::AudioEncoderPcmU(const CodecInst& codec_inst)
|
||||
: AudioEncoderPcmU(CreateConfig<AudioEncoderPcmU>(codec_inst)) {}
|
||||
|
||||
@ -129,4 +134,8 @@ size_t AudioEncoderPcmU::BytesPerSample() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
AudioEncoder::CodecType AudioEncoderPcmU::GetCodecType() const {
|
||||
return AudioEncoder::CodecType::kPcmU;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -55,6 +55,10 @@ class AudioEncoderPcm : public AudioEncoder {
|
||||
|
||||
virtual size_t BytesPerSample() const = 0;
|
||||
|
||||
// Used to set EncodedInfoLeaf::encoder_type in
|
||||
// AudioEncoderPcm::EncodeImpl
|
||||
virtual AudioEncoder::CodecType GetCodecType() const = 0;
|
||||
|
||||
private:
|
||||
const int sample_rate_hz_;
|
||||
const size_t num_channels_;
|
||||
@ -84,6 +88,8 @@ class AudioEncoderPcmA final : public AudioEncoderPcm {
|
||||
|
||||
size_t BytesPerSample() const override;
|
||||
|
||||
AudioEncoder::CodecType GetCodecType() const override;
|
||||
|
||||
private:
|
||||
static const int kSampleRateHz = 8000;
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderPcmA);
|
||||
@ -106,6 +112,8 @@ class AudioEncoderPcmU final : public AudioEncoderPcm {
|
||||
|
||||
size_t BytesPerSample() const override;
|
||||
|
||||
AudioEncoder::CodecType GetCodecType() const override;
|
||||
|
||||
private:
|
||||
static const int kSampleRateHz = 8000;
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderPcmU);
|
||||
|
||||
@ -145,6 +145,7 @@ AudioEncoder::EncodedInfo AudioEncoderG722::EncodeImpl(
|
||||
});
|
||||
info.encoded_timestamp = first_timestamp_in_buffer_;
|
||||
info.payload_type = payload_type_;
|
||||
info.encoder_type = CodecType::kG722;
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@ -127,6 +127,7 @@ AudioEncoder::EncodedInfo AudioEncoderIlbc::EncodeImpl(
|
||||
info.encoded_bytes = encoded_bytes;
|
||||
info.encoded_timestamp = first_timestamp_in_buffer_;
|
||||
info.payload_type = config_.payload_type;
|
||||
info.encoder_type = CodecType::kIlbc;
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@ -145,6 +145,7 @@ AudioEncoder::EncodedInfo AudioEncoderIsacT<T>::EncodeImpl(
|
||||
info.encoded_bytes = encoded_bytes;
|
||||
info.encoded_timestamp = packet_timestamp_;
|
||||
info.payload_type = config_.payload_type;
|
||||
info.encoder_type = CodecType::kIsac;
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@ -212,6 +212,7 @@ AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeImpl(
|
||||
info.payload_type = config_.payload_type;
|
||||
info.send_even_if_empty = true; // Allows Opus to send empty packets.
|
||||
info.speech = (info.encoded_bytes > 0);
|
||||
info.encoder_type = CodecType::kOpus;
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@ -26,6 +26,10 @@ size_t AudioEncoderPcm16B::BytesPerSample() const {
|
||||
return 2;
|
||||
}
|
||||
|
||||
AudioEncoder::CodecType AudioEncoderPcm16B::GetCodecType() const {
|
||||
return CodecType::kOther;
|
||||
}
|
||||
|
||||
namespace {
|
||||
AudioEncoderPcm16B::Config CreateConfig(const CodecInst& codec_inst) {
|
||||
AudioEncoderPcm16B::Config config;
|
||||
|
||||
@ -39,6 +39,8 @@ class AudioEncoderPcm16B final : public AudioEncoderPcm {
|
||||
|
||||
size_t BytesPerSample() const override;
|
||||
|
||||
AudioEncoder::CodecType GetCodecType() const override;
|
||||
|
||||
private:
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderPcm16B);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user