Reland "Upconvert various types to int.", misc. codecs portion.
This reverts portions of commitcb180976dd, which reverted commit83ad33a8ae. 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}
This commit is contained in:
		| @@ -68,8 +68,8 @@ int16_t WebRtcCng_CreateDec(CNG_dec_inst** cng_inst); | |||||||
|  *                      -1 - Error |  *                      -1 - Error | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| int16_t WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, uint16_t fs, int16_t interval, | int WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, int fs, int16_t interval, | ||||||
|                           int16_t quality); |                       int16_t quality); | ||||||
| int16_t WebRtcCng_InitDec(CNG_dec_inst* cng_inst); | 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 |  * Return value       :  0 - Ok | ||||||
|  *                      -1 - Error |  *                      -1 - Error | ||||||
|  */ |  */ | ||||||
| int16_t WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech, | int WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech, | ||||||
|                          int16_t nrOfSamples, uint8_t* SIDdata, |                      int16_t nrOfSamples, uint8_t* SIDdata, | ||||||
|                          int16_t* bytesOut, int16_t forceSID); |                      int16_t* bytesOut, int16_t forceSID); | ||||||
|  |  | ||||||
| /**************************************************************************** | /**************************************************************************** | ||||||
|  * WebRtcCng_UpdateSid(...) |  * WebRtcCng_UpdateSid(...) | ||||||
|   | |||||||
| @@ -36,7 +36,7 @@ typedef struct WebRtcCngDecoder_ { | |||||||
|  |  | ||||||
| typedef struct WebRtcCngEncoder_ { | typedef struct WebRtcCngEncoder_ { | ||||||
|   int16_t enc_nrOfCoefs; |   int16_t enc_nrOfCoefs; | ||||||
|   uint16_t enc_sampfreq; |   int enc_sampfreq; | ||||||
|   int16_t enc_interval; |   int16_t enc_interval; | ||||||
|   int16_t enc_msSinceSID; |   int16_t enc_msSinceSID; | ||||||
|   int32_t enc_Energy; |   int32_t enc_Energy; | ||||||
| @@ -142,8 +142,8 @@ int16_t WebRtcCng_CreateDec(CNG_dec_inst** cng_inst) { | |||||||
|  * Return value       :  0 - Ok |  * Return value       :  0 - Ok | ||||||
|  *                      -1 - Error |  *                      -1 - Error | ||||||
|  */ |  */ | ||||||
| int16_t WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, uint16_t fs, int16_t interval, | int WebRtcCng_InitEnc(CNG_enc_inst* cng_inst, int fs, int16_t interval, | ||||||
|                           int16_t quality) { |                       int16_t quality) { | ||||||
|   int i; |   int i; | ||||||
|   WebRtcCngEncoder* inst = (WebRtcCngEncoder*) cng_inst; |   WebRtcCngEncoder* inst = (WebRtcCngEncoder*) cng_inst; | ||||||
|   memset(inst, 0, sizeof(WebRtcCngEncoder)); |   memset(inst, 0, sizeof(WebRtcCngEncoder)); | ||||||
| @@ -227,9 +227,9 @@ int16_t WebRtcCng_FreeDec(CNG_dec_inst* cng_inst) { | |||||||
|  * Return value       :  0 - Ok |  * Return value       :  0 - Ok | ||||||
|  *                      -1 - Error |  *                      -1 - Error | ||||||
|  */ |  */ | ||||||
| int16_t WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech, | int WebRtcCng_Encode(CNG_enc_inst* cng_inst, int16_t* speech, | ||||||
|                          int16_t nrOfSamples, uint8_t* SIDdata, |                      int16_t nrOfSamples, uint8_t* SIDdata, | ||||||
|                          int16_t* bytesOut, int16_t forceSID) { |                      int16_t* bytesOut, int16_t forceSID) { | ||||||
|   WebRtcCngEncoder* inst = (WebRtcCngEncoder*) cng_inst; |   WebRtcCngEncoder* inst = (WebRtcCngEncoder*) cng_inst; | ||||||
|  |  | ||||||
|   int16_t arCoefs[WEBRTC_CNG_MAX_LPC_ORDER + 1]; |   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; |     inst->enc_msSinceSID = 0; | ||||||
|     *bytesOut = inst->enc_nrOfCoefs + 1; |     *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; |     return inst->enc_nrOfCoefs + 1; | ||||||
|   } else { |   } else { | ||||||
|     inst->enc_msSinceSID += (1000 * nrOfSamples) / inst->enc_sampfreq; |     inst->enc_msSinceSID += | ||||||
|  |         (int16_t)((1000 * nrOfSamples) / inst->enc_sampfreq); | ||||||
|     *bytesOut = 0; |     *bytesOut = 0; | ||||||
|     return 0; |     return 0; | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -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 |     // Free encoder memory | ||||||
|     return WebRtc_g722_encode_release((G722EncoderState*) G722enc_inst); |     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 |     // Free encoder memory | ||||||
|     return WebRtc_g722_decode_release((G722DecoderState*) G722dec_inst); |     return WebRtc_g722_decode_release((G722DecoderState*) G722dec_inst); | ||||||
|   | |||||||
| @@ -73,7 +73,7 @@ int16_t WebRtcG722_EncoderInit(G722EncInst *G722enc_inst); | |||||||
|  * Return value               :  0 - Ok |  * Return value               :  0 - Ok | ||||||
|  *                              -1 - Error |  *                              -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 |  *                              -1 - Error | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| int16_t WebRtcG722_FreeDecoder(G722DecInst *G722dec_inst); | int WebRtcG722_FreeDecoder(G722DecInst *G722dec_inst); | ||||||
|  |  | ||||||
|  |  | ||||||
| /**************************************************************************** | /**************************************************************************** | ||||||
|   | |||||||
| @@ -198,7 +198,7 @@ AudioEncoder::EncodedInfo AudioEncoderOpus::EncodeInternal( | |||||||
|   CHECK_EQ(input_buffer_.size(), |   CHECK_EQ(input_buffer_.size(), | ||||||
|            static_cast<size_t>(num_10ms_frames_per_packet_) * |            static_cast<size_t>(num_10ms_frames_per_packet_) * | ||||||
|            samples_per_10ms_frame_); |            samples_per_10ms_frame_); | ||||||
|   int16_t status = WebRtcOpus_Encode( |   int status = WebRtcOpus_Encode( | ||||||
|       inst_, &input_buffer_[0], |       inst_, &input_buffer_[0], | ||||||
|       rtc::CheckedDivExact(CastInt16(input_buffer_.size()), |       rtc::CheckedDivExact(CastInt16(input_buffer_.size()), | ||||||
|                            static_cast<int16_t>(num_channels_)), |                            static_cast<int16_t>(num_channels_)), | ||||||
|   | |||||||
| @@ -64,11 +64,11 @@ int16_t WebRtcOpus_EncoderFree(OpusEncInst* inst); | |||||||
|  * Return value                 : >=0 - Length (in bytes) of coded data |  * Return value                 : >=0 - Length (in bytes) of coded data | ||||||
|  *                                -1 - Error |  *                                -1 - Error | ||||||
|  */ |  */ | ||||||
| int16_t WebRtcOpus_Encode(OpusEncInst* inst, | int WebRtcOpus_Encode(OpusEncInst* inst, | ||||||
|                           const int16_t* audio_in, |                       const int16_t* audio_in, | ||||||
|                           int16_t samples, |                       int16_t samples, | ||||||
|                           int16_t length_encoded_buffer, |                       int16_t length_encoded_buffer, | ||||||
|                           uint8_t* encoded); |                       uint8_t* encoded); | ||||||
|  |  | ||||||
| /**************************************************************************** | /**************************************************************************** | ||||||
|  * WebRtcOpus_SetBitRate(...) |  * WebRtcOpus_SetBitRate(...) | ||||||
| @@ -236,9 +236,9 @@ int16_t WebRtcOpus_DecoderInit(OpusDecInst* inst); | |||||||
|  * Return value              : >0 - Samples per channel in decoded vector |  * Return value              : >0 - Samples per channel in decoded vector | ||||||
|  *                             -1 - Error |  *                             -1 - Error | ||||||
|  */ |  */ | ||||||
| int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, | int WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, | ||||||
|                           int16_t encoded_bytes, int16_t* decoded, |                       int16_t encoded_bytes, int16_t* decoded, | ||||||
|                           int16_t* audio_type); |                       int16_t* audio_type); | ||||||
|  |  | ||||||
| /**************************************************************************** | /**************************************************************************** | ||||||
|  * WebRtcOpus_DecodePlc(...) |  * 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 |  * Return value                   : >0 - number of samples in decoded PLC vector | ||||||
|  *                                  -1 - Error |  *                                  -1 - Error | ||||||
|  */ |  */ | ||||||
| int16_t WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded, | int WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded, | ||||||
|                              int16_t number_of_lost_frames); |                          int number_of_lost_frames); | ||||||
|  |  | ||||||
| /**************************************************************************** | /**************************************************************************** | ||||||
|  * WebRtcOpus_DecodeFec(...) |  * WebRtcOpus_DecodeFec(...) | ||||||
| @@ -275,9 +275,9 @@ int16_t WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded, | |||||||
|  *                              0 - No FEC data in the packet |  *                              0 - No FEC data in the packet | ||||||
|  *                             -1 - Error |  *                             -1 - Error | ||||||
|  */ |  */ | ||||||
| int16_t WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded, | int WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded, | ||||||
|                              int16_t encoded_bytes, int16_t* decoded, |                          int16_t encoded_bytes, int16_t* decoded, | ||||||
|                              int16_t* audio_type); |                          int16_t* audio_type); | ||||||
|  |  | ||||||
| /**************************************************************************** | /**************************************************************************** | ||||||
|  * WebRtcOpus_DurationEst(...) |  * WebRtcOpus_DurationEst(...) | ||||||
|   | |||||||
| @@ -131,10 +131,10 @@ OpusFecTest::OpusFecTest() | |||||||
| } | } | ||||||
|  |  | ||||||
| void OpusFecTest::EncodeABlock() { | void OpusFecTest::EncodeABlock() { | ||||||
|   int16_t value = WebRtcOpus_Encode(opus_encoder_, |   int value = WebRtcOpus_Encode(opus_encoder_, | ||||||
|                                     &in_data_[data_pointer_], |                                 &in_data_[data_pointer_], | ||||||
|                                     block_length_sample_, |                                 block_length_sample_, | ||||||
|                                     max_bytes_, &bit_stream_[0]); |                                 max_bytes_, &bit_stream_[0]); | ||||||
|   EXPECT_GT(value, 0); |   EXPECT_GT(value, 0); | ||||||
|  |  | ||||||
|   encoded_bytes_ = value; |   encoded_bytes_ = value; | ||||||
| @@ -142,7 +142,7 @@ void OpusFecTest::EncodeABlock() { | |||||||
|  |  | ||||||
| void OpusFecTest::DecodeABlock(bool lost_previous, bool lost_current) { | void OpusFecTest::DecodeABlock(bool lost_previous, bool lost_current) { | ||||||
|   int16_t audio_type; |   int16_t audio_type; | ||||||
|   int16_t value_1 = 0, value_2 = 0; |   int value_1 = 0, value_2 = 0; | ||||||
|  |  | ||||||
|   if (lost_previous) { |   if (lost_previous) { | ||||||
|     // Decode previous frame. |     // Decode previous frame. | ||||||
|   | |||||||
| @@ -78,11 +78,11 @@ int16_t WebRtcOpus_EncoderFree(OpusEncInst* inst) { | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
| int16_t WebRtcOpus_Encode(OpusEncInst* inst, | int WebRtcOpus_Encode(OpusEncInst* inst, | ||||||
|                           const int16_t* audio_in, |                       const int16_t* audio_in, | ||||||
|                           int16_t samples, |                       int16_t samples, | ||||||
|                           int16_t length_encoded_buffer, |                       int16_t length_encoded_buffer, | ||||||
|                           uint8_t* encoded) { |                       uint8_t* encoded) { | ||||||
|   int res; |   int res; | ||||||
|  |  | ||||||
|   if (samples > 48 * kWebRtcOpusMaxEncodeFrameSizeMs) { |   if (samples > 48 * kWebRtcOpusMaxEncodeFrameSizeMs) { | ||||||
| @@ -291,9 +291,9 @@ static int DecodeNative(OpusDecInst* inst, const uint8_t* encoded, | |||||||
|   return res; |   return res; | ||||||
| } | } | ||||||
|  |  | ||||||
| int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, | int WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, | ||||||
|                           int16_t encoded_bytes, int16_t* decoded, |                       int16_t encoded_bytes, int16_t* decoded, | ||||||
|                           int16_t* audio_type) { |                       int16_t* audio_type) { | ||||||
|   int decoded_samples; |   int decoded_samples; | ||||||
|  |  | ||||||
|   if (encoded_bytes == 0) { |   if (encoded_bytes == 0) { | ||||||
| @@ -318,8 +318,8 @@ int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, | |||||||
|   return decoded_samples; |   return decoded_samples; | ||||||
| } | } | ||||||
|  |  | ||||||
| int16_t WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded, | int WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded, | ||||||
|                              int16_t number_of_lost_frames) { |                          int number_of_lost_frames) { | ||||||
|   int16_t audio_type = 0; |   int16_t audio_type = 0; | ||||||
|   int decoded_samples; |   int decoded_samples; | ||||||
|   int plc_samples; |   int plc_samples; | ||||||
| @@ -339,9 +339,9 @@ int16_t WebRtcOpus_DecodePlc(OpusDecInst* inst, int16_t* decoded, | |||||||
|   return decoded_samples; |   return decoded_samples; | ||||||
| } | } | ||||||
|  |  | ||||||
| int16_t WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded, | int WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded, | ||||||
|                              int16_t encoded_bytes, int16_t* decoded, |                          int16_t encoded_bytes, int16_t* decoded, | ||||||
|                              int16_t* audio_type) { |                          int16_t* audio_type) { | ||||||
|   int decoded_samples; |   int decoded_samples; | ||||||
|   int fec_samples; |   int fec_samples; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -273,17 +273,11 @@ void OpusTest::Run(TestPackStereo* channel, int channels, int bitrate, | |||||||
|       int16_t bitstream_len_byte; |       int16_t bitstream_len_byte; | ||||||
|       uint8_t bitstream[kMaxBytes]; |       uint8_t bitstream[kMaxBytes]; | ||||||
|       for (int i = 0; i < loop_encode; i++) { |       for (int i = 0; i < loop_encode; i++) { | ||||||
|         if (channels == 1) { |         int bitstream_len_byte_int = WebRtcOpus_Encode( | ||||||
|           bitstream_len_byte = WebRtcOpus_Encode( |             (channels == 1) ? opus_mono_encoder_ : opus_stereo_encoder_, | ||||||
|               opus_mono_encoder_, &audio[read_samples], |             &audio[read_samples], frame_length, kMaxBytes, bitstream); | ||||||
|               frame_length, kMaxBytes, bitstream); |         ASSERT_GE(bitstream_len_byte_int, 0); | ||||||
|           ASSERT_GE(bitstream_len_byte, 0); |         bitstream_len_byte = static_cast<int16_t>(bitstream_len_byte_int); | ||||||
|         } else { |  | ||||||
|           bitstream_len_byte = WebRtcOpus_Encode( |  | ||||||
|               opus_stereo_encoder_, &audio[read_samples], |  | ||||||
|               frame_length, kMaxBytes, bitstream); |  | ||||||
|           ASSERT_GE(bitstream_len_byte, 0); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         // Simulate packet loss by setting |packet_loss_| to "true" in |         // Simulate packet loss by setting |packet_loss_| to "true" in | ||||||
|         // |percent_loss| percent of the loops. |         // |percent_loss| percent of the loops. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Peter Kasting
					Peter Kasting