Misc. small cleanups.
* Better param names * Avoid using negative values for (bogus) placeholder channel counts (mostly in tests). Since channels will be changing to size_t, negative values will be illegal; it's sufficient to use 0 in these cases. * Use arraysize() * Use size_t for counting frames, samples, blocks, buffers, and bytes -- most of these are already size_t in most places, this just fixes some stragglers * reinterpret_cast<int64_t>(void*) is not necessarily safe; use uintptr_t instead * Remove unnecessary code, e.g. dead code, needlessly long/repetitive code, or function overrides that exactly match the base definition * Fix indenting * Use uint32_t for timestamps (matching how it's already a uint32_t in most places) * Spelling * RTC_CHECK_EQ(expected, actual) * Rewrap * Use .empty() * Be more pedantic about matching int/int32_t/ * Remove pointless consts on input parameters to functions * Add missing sanity checks All this was found in the course of constructing https://codereview.webrtc.org/1316523002/ , and is being landed separately first. BUG=none TEST=none Review URL: https://codereview.webrtc.org/1534193008 Cr-Commit-Position: refs/heads/master@{#11191}
This commit is contained in:
@ -83,7 +83,8 @@ size_t AudioEncoderPcm::Max10MsFramesInAPacket() const {
|
||||
}
|
||||
|
||||
int AudioEncoderPcm::GetTargetBitrate() const {
|
||||
return 8 * BytesPerSample() * SampleRateHz() * NumChannels();
|
||||
return static_cast<int>(
|
||||
8 * BytesPerSample() * SampleRateHz() * NumChannels());
|
||||
}
|
||||
|
||||
AudioEncoder::EncodedInfo AudioEncoderPcm::EncodeInternal(
|
||||
@ -122,7 +123,7 @@ size_t AudioEncoderPcmA::EncodeCall(const int16_t* audio,
|
||||
return WebRtcG711_EncodeA(audio, input_len, encoded);
|
||||
}
|
||||
|
||||
int AudioEncoderPcmA::BytesPerSample() const {
|
||||
size_t AudioEncoderPcmA::BytesPerSample() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -135,7 +136,7 @@ size_t AudioEncoderPcmU::EncodeCall(const int16_t* audio,
|
||||
return WebRtcG711_EncodeU(audio, input_len, encoded);
|
||||
}
|
||||
|
||||
int AudioEncoderPcmU::BytesPerSample() const {
|
||||
size_t AudioEncoderPcmU::BytesPerSample() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -54,7 +54,7 @@ class AudioEncoderPcm : public AudioEncoder {
|
||||
size_t input_len,
|
||||
uint8_t* encoded) = 0;
|
||||
|
||||
virtual int BytesPerSample() const = 0;
|
||||
virtual size_t BytesPerSample() const = 0;
|
||||
|
||||
private:
|
||||
const int sample_rate_hz_;
|
||||
@ -83,7 +83,7 @@ class AudioEncoderPcmA final : public AudioEncoderPcm {
|
||||
size_t input_len,
|
||||
uint8_t* encoded) override;
|
||||
|
||||
int BytesPerSample() const override;
|
||||
size_t BytesPerSample() const override;
|
||||
|
||||
private:
|
||||
static const int kSampleRateHz = 8000;
|
||||
@ -105,7 +105,7 @@ class AudioEncoderPcmU final : public AudioEncoderPcm {
|
||||
size_t input_len,
|
||||
uint8_t* encoded) override;
|
||||
|
||||
int BytesPerSample() const override;
|
||||
size_t BytesPerSample() const override;
|
||||
|
||||
private:
|
||||
static const int kSampleRateHz = 8000;
|
||||
|
||||
@ -92,7 +92,7 @@ float IsacSpeedTest::DecodeABlock(const uint8_t* bit_stream,
|
||||
value = WebRtcIsacfix_Decode(ISACFIX_main_inst_, bit_stream, encoded_bytes,
|
||||
out_data, &audio_type);
|
||||
clocks = clock() - clocks;
|
||||
EXPECT_EQ(output_length_sample_, value);
|
||||
EXPECT_EQ(output_length_sample_, static_cast<size_t>(value));
|
||||
return 1000.0 * clocks / CLOCKS_PER_SEC;
|
||||
}
|
||||
|
||||
|
||||
@ -137,15 +137,14 @@ AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal(
|
||||
uint8_t* encoded) {
|
||||
if (input_buffer_.empty())
|
||||
first_timestamp_in_buffer_ = rtp_timestamp;
|
||||
RTC_DCHECK_EQ(static_cast<size_t>(SamplesPer10msFrame()), audio.size());
|
||||
RTC_DCHECK_EQ(SamplesPer10msFrame(), audio.size());
|
||||
input_buffer_.insert(input_buffer_.end(), audio.cbegin(), audio.cend());
|
||||
if (input_buffer_.size() <
|
||||
(static_cast<size_t>(Num10msFramesPerPacket()) * SamplesPer10msFrame())) {
|
||||
(Num10msFramesPerPacket() * SamplesPer10msFrame())) {
|
||||
return EncodedInfo();
|
||||
}
|
||||
RTC_CHECK_EQ(
|
||||
input_buffer_.size(),
|
||||
static_cast<size_t>(Num10msFramesPerPacket()) * SamplesPer10msFrame());
|
||||
RTC_CHECK_EQ(input_buffer_.size(),
|
||||
Num10msFramesPerPacket() * SamplesPer10msFrame());
|
||||
int status = WebRtcOpus_Encode(
|
||||
inst_, &input_buffer_[0],
|
||||
rtc::CheckedDivExact(input_buffer_.size(),
|
||||
@ -214,11 +213,11 @@ void AudioEncoderOpus::SetTargetBitrate(int bits_per_second) {
|
||||
RTC_CHECK_EQ(0, WebRtcOpus_SetBitRate(inst_, config_.bitrate_bps));
|
||||
}
|
||||
|
||||
int AudioEncoderOpus::Num10msFramesPerPacket() const {
|
||||
return rtc::CheckedDivExact(config_.frame_size_ms, 10);
|
||||
size_t AudioEncoderOpus::Num10msFramesPerPacket() const {
|
||||
return static_cast<size_t>(rtc::CheckedDivExact(config_.frame_size_ms, 10));
|
||||
}
|
||||
|
||||
int AudioEncoderOpus::SamplesPer10msFrame() const {
|
||||
size_t AudioEncoderOpus::SamplesPer10msFrame() const {
|
||||
return rtc::CheckedDivExact(kSampleRateHz, 100) * config_.num_channels;
|
||||
}
|
||||
|
||||
|
||||
@ -85,8 +85,8 @@ class AudioEncoderOpus final : public AudioEncoder {
|
||||
bool dtx_enabled() const { return config_.dtx_enabled; }
|
||||
|
||||
private:
|
||||
int Num10msFramesPerPacket() const;
|
||||
int SamplesPer10msFrame() const;
|
||||
size_t Num10msFramesPerPacket() const;
|
||||
size_t SamplesPer10msFrame() const;
|
||||
bool RecreateEncoderInstance(const Config& config);
|
||||
|
||||
Config config_;
|
||||
|
||||
@ -77,7 +77,7 @@ float OpusSpeedTest::DecodeABlock(const uint8_t* bit_stream,
|
||||
value = WebRtcOpus_Decode(opus_decoder_, bit_stream, encoded_bytes, out_data,
|
||||
&audio_type);
|
||||
clocks = clock() - clocks;
|
||||
EXPECT_EQ(output_length_sample_, value);
|
||||
EXPECT_EQ(output_length_sample_, static_cast<size_t>(value));
|
||||
return 1000.0 * clocks / CLOCKS_PER_SEC;
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ size_t AudioEncoderPcm16B::EncodeCall(const int16_t* audio,
|
||||
return WebRtcPcm16b_Encode(audio, input_len, encoded);
|
||||
}
|
||||
|
||||
int AudioEncoderPcm16B::BytesPerSample() const {
|
||||
size_t AudioEncoderPcm16B::BytesPerSample() const {
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ class AudioEncoderPcm16B final : public AudioEncoderPcm {
|
||||
size_t input_len,
|
||||
uint8_t* encoded) override;
|
||||
|
||||
int BytesPerSample() const override;
|
||||
size_t BytesPerSample() const override;
|
||||
|
||||
private:
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderPcm16B);
|
||||
|
||||
@ -23,8 +23,10 @@ AudioCodecSpeedTest::AudioCodecSpeedTest(int block_duration_ms,
|
||||
: block_duration_ms_(block_duration_ms),
|
||||
input_sampling_khz_(input_sampling_khz),
|
||||
output_sampling_khz_(output_sampling_khz),
|
||||
input_length_sample_(block_duration_ms_ * input_sampling_khz_),
|
||||
output_length_sample_(block_duration_ms_ * output_sampling_khz_),
|
||||
input_length_sample_(
|
||||
static_cast<size_t>(block_duration_ms_ * input_sampling_khz_)),
|
||||
output_length_sample_(
|
||||
static_cast<size_t>(block_duration_ms_ * output_sampling_khz_)),
|
||||
data_pointer_(0),
|
||||
loop_length_samples_(0),
|
||||
max_bytes_(0),
|
||||
@ -65,8 +67,7 @@ void AudioCodecSpeedTest::SetUp() {
|
||||
memcpy(&in_data_[loop_length_samples_], &in_data_[0],
|
||||
input_length_sample_ * channels_ * sizeof(int16_t));
|
||||
|
||||
max_bytes_ =
|
||||
static_cast<size_t>(input_length_sample_ * channels_ * sizeof(int16_t));
|
||||
max_bytes_ = input_length_sample_ * channels_ * sizeof(int16_t);
|
||||
out_data_.reset(new int16_t[output_length_sample_ * channels_]);
|
||||
bit_stream_.reset(new uint8_t[max_bytes_]);
|
||||
|
||||
|
||||
@ -55,10 +55,10 @@ class AudioCodecSpeedTest : public testing::TestWithParam<coding_param> {
|
||||
int output_sampling_khz_;
|
||||
|
||||
// Number of samples-per-channel in a frame.
|
||||
int input_length_sample_;
|
||||
size_t input_length_sample_;
|
||||
|
||||
// Expected output number of samples-per-channel in a frame.
|
||||
int output_length_sample_;
|
||||
size_t output_length_sample_;
|
||||
|
||||
rtc::scoped_ptr<int16_t[]> in_data_;
|
||||
rtc::scoped_ptr<int16_t[]> out_data_;
|
||||
|
||||
Reference in New Issue
Block a user