Convert channel counts to size_t.

IIRC, this was originally requested by ajm during review of the other size_t conversions I did over the past year, and I agreed it made sense, but wanted to do it separately since those changes were already gargantuan.

BUG=chromium:81439
TEST=none
R=henrik.lundin@webrtc.org, henrika@webrtc.org, kjellander@webrtc.org, minyue@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org

Review URL: https://codereview.webrtc.org/1316523002 .

Cr-Commit-Position: refs/heads/master@{#11229}
This commit is contained in:
Peter Kasting
2016-01-12 16:26:35 -08:00
parent 92e677a1f8
commit 6955870806
190 changed files with 892 additions and 868 deletions

View File

@ -17,7 +17,7 @@ namespace webrtc {
AudioDecoderOpus::AudioDecoderOpus(size_t num_channels)
: channels_(num_channels) {
RTC_DCHECK(num_channels == 1 || num_channels == 2);
WebRtcOpus_DecoderCreate(&dec_state_, static_cast<int>(channels_));
WebRtcOpus_DecoderCreate(&dec_state_, channels_);
WebRtcOpus_DecoderInit(dec_state_);
}

View File

@ -114,7 +114,7 @@ int AudioEncoderOpus::SampleRateHz() const {
return kSampleRateHz;
}
int AudioEncoderOpus::NumChannels() const {
size_t AudioEncoderOpus::NumChannels() const {
return config_.num_channels;
}
@ -147,8 +147,7 @@ AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal(
Num10msFramesPerPacket() * SamplesPer10msFrame());
int status = WebRtcOpus_Encode(
inst_, &input_buffer_[0],
rtc::CheckedDivExact(input_buffer_.size(),
static_cast<size_t>(config_.num_channels)),
rtc::CheckedDivExact(input_buffer_.size(), config_.num_channels),
rtc::saturated_cast<int16_t>(max_encoded_bytes), encoded);
RTC_CHECK_GE(status, 0); // Fails only if fed invalid data.
input_buffer_.clear();

View File

@ -31,7 +31,7 @@ class AudioEncoderOpus final : public AudioEncoder {
struct Config {
bool IsOk() const;
int frame_size_ms = 20;
int num_channels = 1;
size_t num_channels = 1;
int payload_type = 120;
ApplicationMode application = kVoip;
int bitrate_bps = 64000;
@ -56,7 +56,7 @@ class AudioEncoderOpus final : public AudioEncoder {
size_t MaxEncodedBytes() const override;
int SampleRateHz() const override;
int NumChannels() const override;
size_t NumChannels() const override;
size_t Num10MsFramesInNextPacket() const override;
size_t Max10MsFramesInAPacket() const override;
int GetTargetBitrate() const override;

View File

@ -9,6 +9,7 @@
*/
#include "testing/gtest/include/gtest/gtest.h"
#include "webrtc/base/format_macros.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/modules/audio_coding/codecs/opus/opus_interface.h"
#include "webrtc/test/testsupport/fileutils.h"
@ -21,7 +22,7 @@ using ::testing::TestWithParam;
namespace webrtc {
// Define coding parameter as <channels, bit_rate, filename, extension>.
typedef tuple<int, int, string, string> coding_param;
typedef tuple<size_t, int, string, string> coding_param;
typedef struct mode mode;
struct mode {
@ -47,7 +48,7 @@ class OpusFecTest : public TestWithParam<coding_param> {
int sampling_khz_;
size_t block_length_sample_;
int channels_;
size_t channels_;
int bit_rate_;
size_t data_pointer_;
@ -68,7 +69,7 @@ class OpusFecTest : public TestWithParam<coding_param> {
void OpusFecTest::SetUp() {
channels_ = get<0>(GetParam());
bit_rate_ = get<1>(GetParam());
printf("Coding %d channel signal at %d bps.\n", channels_, bit_rate_);
printf("Coding %" PRIuS " channel signal at %d bps.\n", channels_, bit_rate_);
in_filename_ = test::ResourcePath(get<2>(GetParam()), get<3>(GetParam()));

View File

@ -17,7 +17,7 @@
struct WebRtcOpusEncInst {
OpusEncoder* encoder;
int channels;
size_t channels;
int in_dtx_mode;
// When Opus is in DTX mode, we use |zero_counts| to count consecutive zeros
// to break long zero segment so as to prevent DTX from going wrong. We use
@ -30,7 +30,7 @@ struct WebRtcOpusEncInst {
struct WebRtcOpusDecInst {
OpusDecoder* decoder;
int prev_decoded_samples;
int channels;
size_t channels;
int in_dtx_mode;
};

View File

@ -42,7 +42,7 @@ enum {
};
int16_t WebRtcOpus_EncoderCreate(OpusEncInst** inst,
int32_t channels,
size_t channels,
int32_t application) {
int opus_app;
if (!inst)
@ -67,7 +67,7 @@ int16_t WebRtcOpus_EncoderCreate(OpusEncInst** inst,
assert(state->zero_counts);
int error;
state->encoder = opus_encoder_create(48000, channels, opus_app,
state->encoder = opus_encoder_create(48000, (int)channels, opus_app,
&error);
if (error != OPUS_OK || !state->encoder) {
WebRtcOpus_EncoderFree(state);
@ -99,7 +99,7 @@ int WebRtcOpus_Encode(OpusEncInst* inst,
uint8_t* encoded) {
int res;
size_t i;
int c;
size_t c;
int16_t buffer[2 * 48 * kWebRtcOpusMaxEncodeFrameSizeMs];
@ -107,7 +107,7 @@ int WebRtcOpus_Encode(OpusEncInst* inst,
return -1;
}
const int channels = inst->channels;
const size_t channels = inst->channels;
int use_buffer = 0;
// Break long consecutive zeros by forcing a "1" every |kZeroBreakCount|
@ -248,7 +248,7 @@ int16_t WebRtcOpus_SetComplexity(OpusEncInst* inst, int32_t complexity) {
}
}
int16_t WebRtcOpus_DecoderCreate(OpusDecInst** inst, int channels) {
int16_t WebRtcOpus_DecoderCreate(OpusDecInst** inst, size_t channels) {
int error;
OpusDecInst* state;
@ -260,7 +260,7 @@ int16_t WebRtcOpus_DecoderCreate(OpusDecInst** inst, int channels) {
}
/* Create new memory, always at 48000 Hz. */
state->decoder = opus_decoder_create(48000, channels, &error);
state->decoder = opus_decoder_create(48000, (int)channels, &error);
if (error == OPUS_OK && state->decoder != NULL) {
/* Creation of memory all ok. */
state->channels = channels;
@ -289,7 +289,7 @@ int16_t WebRtcOpus_DecoderFree(OpusDecInst* inst) {
}
}
int WebRtcOpus_DecoderChannels(OpusDecInst* inst) {
size_t WebRtcOpus_DecoderChannels(OpusDecInst* inst) {
return inst->channels;
}

View File

@ -43,7 +43,7 @@ typedef struct WebRtcOpusDecInst OpusDecInst;
* -1 - Error
*/
int16_t WebRtcOpus_EncoderCreate(OpusEncInst** inst,
int32_t channels,
size_t channels,
int32_t application);
int16_t WebRtcOpus_EncoderFree(OpusEncInst* inst);
@ -195,7 +195,7 @@ int16_t WebRtcOpus_DisableDtx(OpusEncInst* inst);
*/
int16_t WebRtcOpus_SetComplexity(OpusEncInst* inst, int32_t complexity);
int16_t WebRtcOpus_DecoderCreate(OpusDecInst** inst, int channels);
int16_t WebRtcOpus_DecoderCreate(OpusDecInst** inst, size_t channels);
int16_t WebRtcOpus_DecoderFree(OpusDecInst* inst);
/****************************************************************************
@ -203,7 +203,7 @@ int16_t WebRtcOpus_DecoderFree(OpusDecInst* inst);
*
* This function returns the number of channels created for Opus decoder.
*/
int WebRtcOpus_DecoderChannels(OpusDecInst* inst);
size_t WebRtcOpus_DecoderChannels(OpusDecInst* inst);
/****************************************************************************
* WebRtcOpus_DecoderInit(...)

View File

@ -42,7 +42,9 @@ class OpusTest : public TestWithParam<::testing::tuple<int, int>> {
// After preparation, |speech_data_.GetNextBlock()| returns a pointer to a
// block of |block_length_ms| milliseconds. The data is looped every
// |loop_length_ms| milliseconds.
void PrepareSpeechData(int channel, int block_length_ms, int loop_length_ms);
void PrepareSpeechData(size_t channel,
int block_length_ms,
int loop_length_ms);
int EncodeDecode(WebRtcOpusEncInst* encoder,
rtc::ArrayView<const int16_t> input_audio,
@ -53,7 +55,7 @@ class OpusTest : public TestWithParam<::testing::tuple<int, int>> {
void SetMaxPlaybackRate(WebRtcOpusEncInst* encoder,
opus_int32 expect, int32_t set);
void CheckAudioBounded(const int16_t* audio, size_t samples, int channels,
void CheckAudioBounded(const int16_t* audio, size_t samples, size_t channels,
uint16_t bound) const;
WebRtcOpusEncInst* opus_encoder_;
@ -62,7 +64,7 @@ class OpusTest : public TestWithParam<::testing::tuple<int, int>> {
AudioLoop speech_data_;
uint8_t bitstream_[kMaxBytes];
size_t encoded_bytes_;
int channels_;
size_t channels_;
int application_;
};
@ -70,11 +72,11 @@ OpusTest::OpusTest()
: opus_encoder_(NULL),
opus_decoder_(NULL),
encoded_bytes_(0),
channels_(::testing::get<0>(GetParam())),
channels_(static_cast<size_t>(::testing::get<0>(GetParam()))),
application_(::testing::get<1>(GetParam())) {
}
void OpusTest::PrepareSpeechData(int channel, int block_length_ms,
void OpusTest::PrepareSpeechData(size_t channel, int block_length_ms,
int loop_length_ms) {
const std::string file_name =
webrtc::test::ResourcePath((channel == 1) ?
@ -99,9 +101,9 @@ void OpusTest::SetMaxPlaybackRate(WebRtcOpusEncInst* encoder,
}
void OpusTest::CheckAudioBounded(const int16_t* audio, size_t samples,
int channels, uint16_t bound) const {
size_t channels, uint16_t bound) const {
for (size_t i = 0; i < samples; ++i) {
for (int c = 0; c < channels; ++c) {
for (size_t c = 0; c < channels; ++c) {
ASSERT_GE(audio[i * channels + c], -bound);
ASSERT_LE(audio[i * channels + c], bound);
}
@ -115,7 +117,7 @@ int OpusTest::EncodeDecode(WebRtcOpusEncInst* encoder,
int16_t* audio_type) {
int encoded_bytes_int = WebRtcOpus_Encode(
encoder, input_audio.data(),
rtc::CheckedDivExact(input_audio.size(), static_cast<size_t>(channels_)),
rtc::CheckedDivExact(input_audio.size(), channels_),
kMaxBytes, bitstream_);
EXPECT_GE(encoded_bytes_int, 0);
encoded_bytes_ = static_cast<size_t>(encoded_bytes_int);
@ -588,8 +590,7 @@ TEST_P(OpusTest, OpusDurationEstimation) {
auto speech_block = speech_data_.GetNextBlock();
int encoded_bytes_int = WebRtcOpus_Encode(
opus_encoder_, speech_block.data(),
rtc::CheckedDivExact(speech_block.size(),
2 * static_cast<size_t>(channels_)),
rtc::CheckedDivExact(speech_block.size(), 2 * channels_),
kMaxBytes, bitstream_);
EXPECT_GE(encoded_bytes_int, 0);
EXPECT_EQ(kOpus10msFrameSamples,
@ -601,7 +602,7 @@ TEST_P(OpusTest, OpusDurationEstimation) {
speech_block = speech_data_.GetNextBlock();
encoded_bytes_int = WebRtcOpus_Encode(
opus_encoder_, speech_block.data(),
rtc::CheckedDivExact(speech_block.size(), static_cast<size_t>(channels_)),
rtc::CheckedDivExact(speech_block.size(), channels_),
kMaxBytes, bitstream_);
EXPECT_GE(encoded_bytes_int, 0);
EXPECT_EQ(kOpus20msFrameSamples,
@ -643,8 +644,7 @@ TEST_P(OpusTest, OpusDecodeRepacketized) {
auto speech_block = speech_data_.GetNextBlock();
encoded_bytes_ =
WebRtcOpus_Encode(opus_encoder_, speech_block.data(),
rtc::CheckedDivExact(speech_block.size(),
static_cast<size_t>(channels_)),
rtc::CheckedDivExact(speech_block.size(), channels_),
kMaxBytes, bitstream_);
EXPECT_EQ(OPUS_OK, opus_repacketizer_cat(rp, bitstream_, encoded_bytes_));
}