From bba780707848ad36066739c60d7b28cd752fb92f Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Thu, 11 Jun 2015 19:02:46 -0700 Subject: [PATCH] Reland "Upconvert various types to int.", misc. codecs portion. This reverts portions of commit cb180976dd0e9672cde4523d87b5f4857478b5e9, which reverted commit 83ad33a8aed1fb00e422b6abd33c3e8942821c24. Specifically, the files in webrtc/modules/audio_coding/codecs/ that are not in ilbc/ or isac/, as well as webrtc/modules/audio_coding/main/test/opus_test.cc, are relanded. The original commit message is below: Upconvert various types to int. Per comments from HL/kwiberg on https://webrtc-codereview.appspot.com/42569004 , when there is existing usage of mixed types (int16_t, int, etc.), we'd prefer to standardize on larger types like int and phase out use of int16_t. Specifically, "Using int16 just because we're sure all reasonable values will fit in 16 bits isn't usually meaningful in C." This converts some existing uses of int16_t (and, in a few cases, other types such as uint16_t) to int (or, in a few places, int32_t). Other locations will be converted to size_t in a separate change. BUG=none TBR=kwiberg Review URL: https://codereview.webrtc.org/1179093003 Cr-Commit-Position: refs/heads/master@{#9424} --- .../codecs/cng/include/webrtc_cng.h | 10 +++---- .../audio_coding/codecs/cng/webrtc_cng.c | 18 +++++++------ .../audio_coding/codecs/g722/g722_interface.c | 4 +-- .../codecs/g722/include/g722_interface.h | 4 +-- .../codecs/opus/audio_encoder_opus.cc | 2 +- .../codecs/opus/interface/opus_interface.h | 26 +++++++++---------- .../audio_coding/codecs/opus/opus_fec_test.cc | 10 +++---- .../audio_coding/codecs/opus/opus_interface.c | 26 +++++++++---------- .../audio_coding/main/test/opus_test.cc | 16 ++++-------- 9 files changed, 56 insertions(+), 60 deletions(-) diff --git a/webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h b/webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h index b016f4017f..1ec5d67d1c 100644 --- a/webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h +++ b/webrtc/modules/audio_coding/codecs/cng/include/webrtc_cng.h @@ -68,8 +68,8 @@ int16_t WebRtcCng_CreateDec(CNG_dec_inst** cng_inst); * -1 - Error */ -int16_t WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, uint16_t fs, int16_t interval, - int16_t quality); +int WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, int fs, int16_t interval, + int16_t quality); int16_t WebRtcCng_InitDec(CNG_dec_inst* cng_inst); /**************************************************************************** @@ -103,9 +103,9 @@ int16_t WebRtcCng_FreeDec(CNG_dec_inst* cng_inst); * Return value : 0 - Ok * -1 - Error */ -int16_t WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech, - int16_t nrOfSamples, uint8_t* SIDdata, - int16_t* bytesOut, int16_t forceSID); +int WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech, + int16_t nrOfSamples, uint8_t* SIDdata, + int16_t* bytesOut, int16_t forceSID); /**************************************************************************** * WebRtcCng_UpdateSid(...) diff --git a/webrtc/modules/audio_coding/codecs/cng/webrtc_cng.c b/webrtc/modules/audio_coding/codecs/cng/webrtc_cng.c index cb7aa4567d..1f6974a456 100644 --- a/webrtc/modules/audio_coding/codecs/cng/webrtc_cng.c +++ b/webrtc/modules/audio_coding/codecs/cng/webrtc_cng.c @@ -36,7 +36,7 @@ typedef struct WebRtcCngDecoder_ { typedef struct WebRtcCngEncoder_ { int16_t enc_nrOfCoefs; - uint16_t enc_sampfreq; + int enc_sampfreq; int16_t enc_interval; int16_t enc_msSinceSID; int32_t enc_Energy; @@ -142,8 +142,8 @@ int16_t WebRtcCng_CreateDec(CNG_dec_inst** cng_inst) { * Return value : 0 - Ok * -1 - Error */ -int16_t WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, uint16_t fs, int16_t interval, - int16_t quality) { +int WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, int fs, int16_t interval, + int16_t quality) { int i; WebRtcCngEncoder* inst = (WebRtcCngEncoder*) cng_inst; memset(inst, 0, sizeof(WebRtcCngEncoder)); @@ -227,9 +227,9 @@ int16_t WebRtcCng_FreeDec(CNG_dec_inst* cng_inst) { * Return value : 0 - Ok * -1 - Error */ -int16_t WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech, - int16_t nrOfSamples, uint8_t* SIDdata, - int16_t* bytesOut, int16_t forceSID) { +int WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech, + int16_t nrOfSamples, uint8_t* SIDdata, + int16_t* bytesOut, int16_t forceSID) { WebRtcCngEncoder* inst = (WebRtcCngEncoder*) cng_inst; int16_t arCoefs[WEBRTC_CNG_MAX_LPC_ORDER + 1]; @@ -388,10 +388,12 @@ int16_t WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech, inst->enc_msSinceSID = 0; *bytesOut = inst->enc_nrOfCoefs + 1; - inst->enc_msSinceSID += (1000 * nrOfSamples) / inst->enc_sampfreq; + inst->enc_msSinceSID += + (int16_t)((1000 * nrOfSamples) / inst->enc_sampfreq); return inst->enc_nrOfCoefs + 1; } else { - inst->enc_msSinceSID += (1000 * nrOfSamples) / inst->enc_sampfreq; + inst->enc_msSinceSID += + (int16_t)((1000 * nrOfSamples) / inst->enc_sampfreq); *bytesOut = 0; return 0; } diff --git a/webrtc/modules/audio_coding/codecs/g722/g722_interface.c b/webrtc/modules/audio_coding/codecs/g722/g722_interface.c index 25d75ee6e9..1edf58dc1d 100644 --- a/webrtc/modules/audio_coding/codecs/g722/g722_interface.c +++ b/webrtc/modules/audio_coding/codecs/g722/g722_interface.c @@ -39,7 +39,7 @@ int16_t WebRtcG722_EncoderInit(G722EncInst *G722enc_inst) } } -int16_t WebRtcG722_FreeEncoder(G722EncInst *G722enc_inst) +int WebRtcG722_FreeEncoder(G722EncInst *G722enc_inst) { // Free encoder memory return WebRtc_g722_encode_release((G722EncoderState*) G722enc_inst); @@ -79,7 +79,7 @@ int16_t WebRtcG722_DecoderInit(G722DecInst *G722dec_inst) } } -int16_t WebRtcG722_FreeDecoder(G722DecInst *G722dec_inst) +int WebRtcG722_FreeDecoder(G722DecInst *G722dec_inst) { // Free encoder memory return WebRtc_g722_decode_release((G722DecoderState*) G722dec_inst); diff --git a/webrtc/modules/audio_coding/codecs/g722/include/g722_interface.h b/webrtc/modules/audio_coding/codecs/g722/include/g722_interface.h index 711b991d9c..46ff3b0f01 100644 --- a/webrtc/modules/audio_coding/codecs/g722/include/g722_interface.h +++ b/webrtc/modules/audio_coding/codecs/g722/include/g722_interface.h @@ -73,7 +73,7 @@ int16_t WebRtcG722_EncoderInit(G722EncInst *G722enc_inst); * Return value : 0 - Ok * -1 - Error */ -int16_t WebRtcG722_FreeEncoder(G722EncInst *G722enc_inst); +int WebRtcG722_FreeEncoder(G722EncInst *G722enc_inst); @@ -142,7 +142,7 @@ int16_t WebRtcG722_DecoderInit(G722DecInst *G722dec_inst); * -1 - Error */ -int16_t WebRtcG722_FreeDecoder(G722DecInst *G722dec_inst); +int WebRtcG722_FreeDecoder(G722DecInst *G722dec_inst); /**************************************************************************** diff --git a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc index 17fa5b24b8..328698380a 100644 --- a/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc +++ b/webrtc/modules/audio_coding/codecs/opus/audio_encoder_opus.cc @@ -198,7 +198,7 @@ AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal( CHECK_EQ(input_buffer_.size(), static_cast(num_10ms_frames_per_packet_) * samples_per_10ms_frame_); - int16_t status = WebRtcOpus_Encode( + int status = WebRtcOpus_Encode( inst_, &input_buffer_[0], rtc::CheckedDivExact(CastInt16(input_buffer_.size()), static_cast(num_channels_)), diff --git a/webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h b/webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h index dccc7ca712..925cd85df4 100644 --- a/webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h +++ b/webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h @@ -64,11 +64,11 @@ int16_t WebRtcOpus_EncoderFree(OpusEncInst* inst); * Return value : >=0 - Length (in bytes) of coded data * -1 - Error */ -int16_t WebRtcOpus_Encode(OpusEncInst* inst, - const int16_t* audio_in, - int16_t samples, - int16_t length_encoded_buffer, - uint8_t* encoded); +int WebRtcOpus_Encode(OpusEncInst* inst, + const int16_t* audio_in, + int16_t samples, + int16_t length_encoded_buffer, + uint8_t* encoded); /**************************************************************************** * WebRtcOpus_SetBitRate(...) @@ -236,9 +236,9 @@ int16_t WebRtcOpus_DecoderInit(OpusDecInst* inst); * Return value : >0 - Samples per channel in decoded vector * -1 - Error */ -int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, - int16_t encoded_bytes, int16_t* decoded, - int16_t* audio_type); +int WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, + int16_t encoded_bytes, int16_t* decoded, + int16_t* audio_type); /**************************************************************************** * WebRtcOpus_DecodePlc(...) @@ -254,8 +254,8 @@ int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, * Return value : >0 - number of samples in decoded PLC vector * -1 - Error */ -int16_t WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded, - int16_t number_of_lost_frames); +int WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded, + int number_of_lost_frames); /**************************************************************************** * WebRtcOpus_DecodeFec(...) @@ -275,9 +275,9 @@ int16_t WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded, * 0 - No FEC data in the packet * -1 - Error */ -int16_t WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded, - int16_t encoded_bytes, int16_t* decoded, - int16_t* audio_type); +int WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded, + int16_t encoded_bytes, int16_t* decoded, + int16_t* audio_type); /**************************************************************************** * WebRtcOpus_DurationEst(...) diff --git a/webrtc/modules/audio_coding/codecs/opus/opus_fec_test.cc b/webrtc/modules/audio_coding/codecs/opus/opus_fec_test.cc index aaaced16d5..f0ef70a3ba 100644 --- a/webrtc/modules/audio_coding/codecs/opus/opus_fec_test.cc +++ b/webrtc/modules/audio_coding/codecs/opus/opus_fec_test.cc @@ -131,10 +131,10 @@ OpusFecTest::OpusFecTest() } void OpusFecTest::EncodeABlock() { - int16_t value = WebRtcOpus_Encode(opus_encoder_, - &in_data_[data_pointer_], - block_length_sample_, - max_bytes_, &bit_stream_[0]); + int value = WebRtcOpus_Encode(opus_encoder_, + &in_data_[data_pointer_], + block_length_sample_, + max_bytes_, &bit_stream_[0]); EXPECT_GT(value, 0); encoded_bytes_ = value; @@ -142,7 +142,7 @@ void OpusFecTest::EncodeABlock() { void OpusFecTest::DecodeABlock(bool lost_previous, bool lost_current) { int16_t audio_type; - int16_t value_1 = 0, value_2 = 0; + int value_1 = 0, value_2 = 0; if (lost_previous) { // Decode previous frame. diff --git a/webrtc/modules/audio_coding/codecs/opus/opus_interface.c b/webrtc/modules/audio_coding/codecs/opus/opus_interface.c index 527de10132..e2506166a9 100644 --- a/webrtc/modules/audio_coding/codecs/opus/opus_interface.c +++ b/webrtc/modules/audio_coding/codecs/opus/opus_interface.c @@ -78,11 +78,11 @@ int16_t WebRtcOpus_EncoderFree(OpusEncInst* inst) { } } -int16_t WebRtcOpus_Encode(OpusEncInst* inst, - const int16_t* audio_in, - int16_t samples, - int16_t length_encoded_buffer, - uint8_t* encoded) { +int WebRtcOpus_Encode(OpusEncInst* inst, + const int16_t* audio_in, + int16_t samples, + int16_t length_encoded_buffer, + uint8_t* encoded) { int res; if (samples > 48 * kWebRtcOpusMaxEncodeFrameSizeMs) { @@ -291,9 +291,9 @@ static int DecodeNative(OpusDecInst* inst, const uint8_t* encoded, return res; } -int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, - int16_t encoded_bytes, int16_t* decoded, - int16_t* audio_type) { +int WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, + int16_t encoded_bytes, int16_t* decoded, + int16_t* audio_type) { int decoded_samples; if (encoded_bytes == 0) { @@ -318,8 +318,8 @@ int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, return decoded_samples; } -int16_t WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded, - int16_t number_of_lost_frames) { +int WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded, + int number_of_lost_frames) { int16_t audio_type = 0; int decoded_samples; int plc_samples; @@ -339,9 +339,9 @@ int16_t WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded, return decoded_samples; } -int16_t WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded, - int16_t encoded_bytes, int16_t* decoded, - int16_t* audio_type) { +int WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded, + int16_t encoded_bytes, int16_t* decoded, + int16_t* audio_type) { int decoded_samples; int fec_samples; diff --git a/webrtc/modules/audio_coding/main/test/opus_test.cc b/webrtc/modules/audio_coding/main/test/opus_test.cc index a407fc5d36..c61d25ad19 100644 --- a/webrtc/modules/audio_coding/main/test/opus_test.cc +++ b/webrtc/modules/audio_coding/main/test/opus_test.cc @@ -273,17 +273,11 @@ void OpusTest::Run(TestPackStereo* channel, int channels, int bitrate, int16_t bitstream_len_byte; uint8_t bitstream[kMaxBytes]; for (int i = 0; i < loop_encode; i++) { - if (channels == 1) { - bitstream_len_byte = WebRtcOpus_Encode( - opus_mono_encoder_, &audio[read_samples], - frame_length, kMaxBytes, bitstream); - ASSERT_GE(bitstream_len_byte, 0); - } else { - bitstream_len_byte = WebRtcOpus_Encode( - opus_stereo_encoder_, &audio[read_samples], - frame_length, kMaxBytes, bitstream); - ASSERT_GE(bitstream_len_byte, 0); - } + int bitstream_len_byte_int = WebRtcOpus_Encode( + (channels == 1) ? opus_mono_encoder_ : opus_stereo_encoder_, + &audio[read_samples], frame_length, kMaxBytes, bitstream); + ASSERT_GE(bitstream_len_byte_int, 0); + bitstream_len_byte = static_cast(bitstream_len_byte_int); // Simulate packet loss by setting |packet_loss_| to "true" in // |percent_loss| percent of the loops.