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 11c4ac2f5a..c1348565fa 100644 --- a/webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h +++ b/webrtc/modules/audio_coding/codecs/opus/interface/opus_interface.h @@ -42,8 +42,11 @@ int16_t WebRtcOpus_EncoderFree(OpusEncInst* inst); * Return value : >0 - Length (in bytes) of coded data * -1 - Error */ -int16_t WebRtcOpus_Encode(OpusEncInst* inst, int16_t* audio_in, int16_t samples, - int16_t length_encoded_buffer, uint8_t* encoded); +int16_t WebRtcOpus_Encode(OpusEncInst* inst, + const int16_t* audio_in, + int16_t samples, + int16_t length_encoded_buffer, + uint8_t* encoded); /**************************************************************************** * WebRtcOpus_SetBitRate(...) @@ -190,10 +193,10 @@ int16_t WebRtcOpus_DecoderInitSlave(OpusDecInst* inst); int16_t WebRtcOpus_DecodeNew(OpusDecInst* inst, const uint8_t* encoded, int16_t encoded_bytes, int16_t* decoded, int16_t* audio_type); -int16_t WebRtcOpus_Decode(OpusDecInst* inst, const int16_t* encoded, +int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, int16_t encoded_bytes, int16_t* decoded, int16_t* audio_type); -int16_t WebRtcOpus_DecodeSlave(OpusDecInst* inst, const int16_t* encoded, +int16_t WebRtcOpus_DecodeSlave(OpusDecInst* inst, const uint8_t* encoded, int16_t encoded_bytes, int16_t* decoded, int16_t* audio_type); diff --git a/webrtc/modules/audio_coding/codecs/opus/opus_interface.c b/webrtc/modules/audio_coding/codecs/opus/opus_interface.c index af581aaa82..0c2644ba3b 100644 --- a/webrtc/modules/audio_coding/codecs/opus/opus_interface.c +++ b/webrtc/modules/audio_coding/codecs/opus/opus_interface.c @@ -63,17 +63,21 @@ int16_t WebRtcOpus_EncoderFree(OpusEncInst* inst) { } } -int16_t WebRtcOpus_Encode(OpusEncInst* inst, int16_t* audio_in, int16_t samples, - int16_t length_encoded_buffer, uint8_t* encoded) { - opus_int16* audio = (opus_int16*) audio_in; - unsigned char* coded = encoded; +int16_t 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) { return -1; } - res = opus_encode(inst->encoder, audio, samples, coded, + res = opus_encode(inst->encoder, + (const opus_int16*)audio_in, + samples, + encoded, length_encoded_buffer); if (res > 0) { @@ -222,13 +226,11 @@ int16_t WebRtcOpus_DecoderInitSlave(OpusDecInst* inst) { /* |frame_size| is set to maximum Opus frame size in the normal case, and * is set to the number of samples needed for PLC in case of losses. * It is up to the caller to make sure the value is correct. */ -static int DecodeNative(OpusDecoder* inst, const int16_t* encoded, +static int DecodeNative(OpusDecoder* inst, const uint8_t* encoded, int16_t encoded_bytes, int frame_size, int16_t* decoded, int16_t* audio_type) { - unsigned char* coded = (unsigned char*) encoded; - opus_int16* audio = (opus_int16*) decoded; - - int res = opus_decode(inst, coded, encoded_bytes, audio, frame_size, 0); + int res = opus_decode( + inst, encoded, encoded_bytes, (opus_int16*)decoded, frame_size, 0); /* TODO(tlegrand): set to DTX for zero-length packets? */ *audio_type = 0; @@ -239,13 +241,11 @@ static int DecodeNative(OpusDecoder* inst, const int16_t* encoded, return -1; } -static int DecodeFec(OpusDecoder* inst, const int16_t* encoded, +static int DecodeFec(OpusDecoder* inst, const uint8_t* encoded, int16_t encoded_bytes, int frame_size, int16_t* decoded, int16_t* audio_type) { - unsigned char* coded = (unsigned char*) encoded; - opus_int16* audio = (opus_int16*) decoded; - - int res = opus_decode(inst, coded, encoded_bytes, audio, frame_size, 1); + int res = opus_decode( + inst, encoded, encoded_bytes, (opus_int16*)decoded, frame_size, 1); /* TODO(tlegrand): set to DTX for zero-length packets? */ *audio_type = 0; @@ -259,12 +259,12 @@ static int DecodeFec(OpusDecoder* inst, const int16_t* encoded, int16_t WebRtcOpus_DecodeNew(OpusDecInst* inst, const uint8_t* encoded, int16_t encoded_bytes, int16_t* decoded, int16_t* audio_type) { - int16_t* coded = (int16_t*)encoded; - int decoded_samples; - - decoded_samples = DecodeNative(inst->decoder_left, coded, encoded_bytes, - kWebRtcOpusMaxFrameSizePerChannel, - decoded, audio_type); + int decoded_samples = DecodeNative(inst->decoder_left, + encoded, + encoded_bytes, + kWebRtcOpusMaxFrameSizePerChannel, + decoded, + audio_type); if (decoded_samples < 0) { return -1; } @@ -275,7 +275,7 @@ int16_t WebRtcOpus_DecodeNew(OpusDecInst* inst, const uint8_t* encoded, return decoded_samples; } -int16_t WebRtcOpus_Decode(OpusDecInst* inst, const int16_t* encoded, +int16_t WebRtcOpus_Decode(OpusDecInst* inst, const uint8_t* encoded, int16_t encoded_bytes, int16_t* decoded, int16_t* audio_type) { int decoded_samples; @@ -310,7 +310,7 @@ int16_t WebRtcOpus_Decode(OpusDecInst* inst, const int16_t* encoded, return decoded_samples; } -int16_t WebRtcOpus_DecodeSlave(OpusDecInst* inst, const int16_t* encoded, +int16_t WebRtcOpus_DecodeSlave(OpusDecInst* inst, const uint8_t* encoded, int16_t encoded_bytes, int16_t* decoded, int16_t* audio_type) { int decoded_samples; @@ -439,7 +439,6 @@ int16_t WebRtcOpus_DecodePlcSlave(OpusDecInst* inst, int16_t* decoded, int16_t WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded, int16_t encoded_bytes, int16_t* decoded, int16_t* audio_type) { - int16_t* coded = (int16_t*)encoded; int decoded_samples; int fec_samples; @@ -449,7 +448,7 @@ int16_t WebRtcOpus_DecodeFec(OpusDecInst* inst, const uint8_t* encoded, fec_samples = opus_packet_get_samples_per_frame(encoded, 48000); - decoded_samples = DecodeFec(inst->decoder_left, coded, encoded_bytes, + decoded_samples = DecodeFec(inst->decoder_left, encoded, encoded_bytes, fec_samples, decoded, audio_type); if (decoded_samples < 0) { return -1; diff --git a/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc b/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc index 4a0d49fda0..e76dcdcd55 100644 --- a/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc +++ b/webrtc/modules/audio_coding/codecs/opus/opus_unittest.cc @@ -131,7 +131,6 @@ TEST_F(OpusTest, OpusEncodeDecodeMono) { int16_t audio_type; int16_t output_data_decode_new[kOpusMaxFrameSamples]; int16_t output_data_decode[kOpusMaxFrameSamples]; - int16_t* coded = reinterpret_cast(bitstream_); encoded_bytes = WebRtcOpus_Encode(opus_mono_encoder_, speech_data_, kOpus20msFrameSamples, kMaxBytes, bitstream_); @@ -140,7 +139,7 @@ TEST_F(OpusTest, OpusEncodeDecodeMono) { encoded_bytes, output_data_decode_new, &audio_type)); EXPECT_EQ(kOpus20msFrameSamples, - WebRtcOpus_Decode(opus_mono_decoder_, coded, + WebRtcOpus_Decode(opus_mono_decoder_, bitstream_, encoded_bytes, output_data_decode, &audio_type)); @@ -175,7 +174,6 @@ TEST_F(OpusTest, OpusEncodeDecodeStereo) { int16_t output_data_decode_new[kOpusMaxFrameSamples]; int16_t output_data_decode[kOpusMaxFrameSamples]; int16_t output_data_decode_slave[kOpusMaxFrameSamples]; - int16_t* coded = reinterpret_cast(bitstream_); encoded_bytes = WebRtcOpus_Encode(opus_stereo_encoder_, speech_data_, kOpus20msFrameSamples, kMaxBytes, bitstream_); @@ -184,11 +182,11 @@ TEST_F(OpusTest, OpusEncodeDecodeStereo) { encoded_bytes, output_data_decode_new, &audio_type)); EXPECT_EQ(kOpus20msFrameSamples, - WebRtcOpus_Decode(opus_stereo_decoder_, coded, + WebRtcOpus_Decode(opus_stereo_decoder_, bitstream_, encoded_bytes, output_data_decode, &audio_type)); EXPECT_EQ(kOpus20msFrameSamples, - WebRtcOpus_DecodeSlave(opus_stereo_decoder_, coded, + WebRtcOpus_DecodeSlave(opus_stereo_decoder_, bitstream_, encoded_bytes, output_data_decode_slave, &audio_type)); @@ -259,7 +257,6 @@ TEST_F(OpusTest, OpusDecodeInit) { int16_t output_data_decode_new[kOpusMaxFrameSamples]; int16_t output_data_decode[kOpusMaxFrameSamples]; int16_t output_data_decode_slave[kOpusMaxFrameSamples]; - int16_t* coded = reinterpret_cast(bitstream_); encoded_bytes = WebRtcOpus_Encode(opus_stereo_encoder_, speech_data_, kOpus20msFrameSamples, kMaxBytes, bitstream_); @@ -268,11 +265,11 @@ TEST_F(OpusTest, OpusDecodeInit) { encoded_bytes, output_data_decode_new, &audio_type)); EXPECT_EQ(kOpus20msFrameSamples, - WebRtcOpus_Decode(opus_stereo_decoder_, coded, + WebRtcOpus_Decode(opus_stereo_decoder_, bitstream_, encoded_bytes, output_data_decode, &audio_type)); EXPECT_EQ(kOpus20msFrameSamples, - WebRtcOpus_DecodeSlave(opus_stereo_decoder_, coded, + WebRtcOpus_DecodeSlave(opus_stereo_decoder_, bitstream_, encoded_bytes, output_data_decode_slave, &audio_type)); @@ -293,11 +290,11 @@ TEST_F(OpusTest, OpusDecodeInit) { encoded_bytes, output_data_decode_new, &audio_type)); EXPECT_EQ(kOpus20msFrameSamples, - WebRtcOpus_Decode(opus_stereo_decoder_, coded, + WebRtcOpus_Decode(opus_stereo_decoder_, bitstream_, encoded_bytes, output_data_decode, &audio_type)); EXPECT_EQ(kOpus20msFrameSamples, - WebRtcOpus_DecodeSlave(opus_stereo_decoder_, coded, + WebRtcOpus_DecodeSlave(opus_stereo_decoder_, bitstream_, encoded_bytes, output_data_decode_slave, &audio_type)); @@ -399,7 +396,6 @@ TEST_F(OpusTest, OpusDecodePlcMono) { int16_t audio_type; int16_t output_data_decode_new[kOpusMaxFrameSamples]; int16_t output_data_decode[kOpusMaxFrameSamples]; - int16_t* coded = reinterpret_cast(bitstream_); encoded_bytes = WebRtcOpus_Encode(opus_mono_encoder_, speech_data_, kOpus20msFrameSamples, kMaxBytes, bitstream_); @@ -408,7 +404,7 @@ TEST_F(OpusTest, OpusDecodePlcMono) { encoded_bytes, output_data_decode_new, &audio_type)); EXPECT_EQ(kOpus20msFrameSamples, - WebRtcOpus_Decode(opus_mono_decoder_, coded, + WebRtcOpus_Decode(opus_mono_decoder_, bitstream_, encoded_bytes, output_data_decode, &audio_type)); @@ -451,7 +447,6 @@ TEST_F(OpusTest, OpusDecodePlcStereo) { int16_t output_data_decode_new[kOpusMaxFrameSamples]; int16_t output_data_decode[kOpusMaxFrameSamples]; int16_t output_data_decode_slave[kOpusMaxFrameSamples]; - int16_t* coded = reinterpret_cast(bitstream_); encoded_bytes = WebRtcOpus_Encode(opus_stereo_encoder_, speech_data_, kOpus20msFrameSamples, kMaxBytes, bitstream_); @@ -460,11 +455,11 @@ TEST_F(OpusTest, OpusDecodePlcStereo) { encoded_bytes, output_data_decode_new, &audio_type)); EXPECT_EQ(kOpus20msFrameSamples, - WebRtcOpus_Decode(opus_stereo_decoder_, coded, + WebRtcOpus_Decode(opus_stereo_decoder_, bitstream_, encoded_bytes, output_data_decode, &audio_type)); EXPECT_EQ(kOpus20msFrameSamples, - WebRtcOpus_DecodeSlave(opus_stereo_decoder_, coded, + WebRtcOpus_DecodeSlave(opus_stereo_decoder_, bitstream_, encoded_bytes, output_data_decode_slave, &audio_type));