diff --git a/jni/redphone/AudioCodec.cpp b/jni/redphone/AudioCodec.cpp index 52cd1f28a9..629d1c1055 100644 --- a/jni/redphone/AudioCodec.cpp +++ b/jni/redphone/AudioCodec.cpp @@ -102,12 +102,14 @@ int AudioCodec::encode(short *rawData, char* encodedData, int maxEncodedDataLen) return speex_bits_write(&enc_bits, encodedData, maxEncodedDataLen); } -int AudioCodec::decode(char* encodedData, int encodedDataLen, short *rawData) { - int rawDataOffset = 0; +int AudioCodec::decode(char* encodedData, int encodedDataLen, short *rawData, size_t decodeMaxSize) { + uint32_t rawDataOffset = 0; speex_bits_read_from(&dec_bits, encodedData, encodedDataLen); - while (speex_decode_int(dec, &dec_bits, rawData + rawDataOffset) == 0) { // TODO bounds? + while ((rawDataOffset + dec_frame_size <= decodeMaxSize) && + (speex_decode_int(dec, &dec_bits, rawData + rawDataOffset) == 0)) + { WebRtcAecm_BufferFarend(aecm, rawData + rawDataOffset, dec_frame_size); rawDataOffset += dec_frame_size; } diff --git a/jni/redphone/AudioCodec.h b/jni/redphone/AudioCodec.h index 9aec5a3d4e..e3397078db 100644 --- a/jni/redphone/AudioCodec.h +++ b/jni/redphone/AudioCodec.h @@ -36,7 +36,7 @@ public: int init(); int encode(short *rawData, char* encodedData, int encodedDataLen); - int decode(char* encodedData, int encodedDataLen, short* rawData); + int decode(char* encodedData, int encodedDataLen, short* rawData, size_t decodeMaxSize); int conceal(int frames, short *rawData); }; diff --git a/jni/redphone/WebRtcCodec.h b/jni/redphone/WebRtcCodec.h index 8de82c2f5c..08972cd12b 100644 --- a/jni/redphone/WebRtcCodec.h +++ b/jni/redphone/WebRtcCodec.h @@ -17,10 +17,11 @@ public: {} int Decode(const uint8_t* encoded, size_t encoded_len, - int16_t* decoded, SpeechType* speech_type) + int16_t* decoded, size_t decodedMaxSize, + SpeechType* speech_type) { *speech_type = kSpeech; - return codec.decode((char*)encoded, encoded_len, decoded); + return codec.decode((char*)encoded, encoded_len, decoded, decodedMaxSize); } bool HasDecodePlc() const { diff --git a/jni/webrtc/modules/audio_coding/neteq/audio_decoder.cc b/jni/webrtc/modules/audio_coding/neteq/audio_decoder.cc index 0fdaa44be2..7b11dc1d88 100644 --- a/jni/webrtc/modules/audio_coding/neteq/audio_decoder.cc +++ b/jni/webrtc/modules/audio_coding/neteq/audio_decoder.cc @@ -19,8 +19,9 @@ namespace webrtc { int AudioDecoder::DecodeRedundant(const uint8_t* encoded, size_t encoded_len, int16_t* decoded, + size_t maxDecodedSize, SpeechType* speech_type) { - return Decode(encoded, encoded_len, decoded, speech_type); + return Decode(encoded, encoded_len, decoded, maxDecodedSize, speech_type); } bool AudioDecoder::HasDecodePlc() const { return false; } @@ -56,48 +57,6 @@ NetEqDecoder AudioDecoder::codec_type() const { return codec_type_; } bool AudioDecoder::CodecSupported(NetEqDecoder codec_type) { switch (codec_type) { case kDecoderPCMu: - case kDecoderPCMa: - case kDecoderPCMu_2ch: - case kDecoderPCMa_2ch: -#ifdef WEBRTC_CODEC_ILBC - case kDecoderILBC: -#endif -#if defined(WEBRTC_CODEC_ISACFX) || defined(WEBRTC_CODEC_ISAC) - case kDecoderISAC: -#endif -#ifdef WEBRTC_CODEC_ISAC - case kDecoderISACswb: - case kDecoderISACfb: -#endif -#ifdef WEBRTC_CODEC_PCM16 - case kDecoderPCM16B: - case kDecoderPCM16Bwb: - case kDecoderPCM16Bswb32kHz: - case kDecoderPCM16Bswb48kHz: - case kDecoderPCM16B_2ch: - case kDecoderPCM16Bwb_2ch: - case kDecoderPCM16Bswb32kHz_2ch: - case kDecoderPCM16Bswb48kHz_2ch: - case kDecoderPCM16B_5ch: -#endif -#ifdef WEBRTC_CODEC_G722 - case kDecoderG722: - case kDecoderG722_2ch: -#endif -#ifdef WEBRTC_CODEC_CELT - case kDecoderCELT_32: - case kDecoderCELT_32_2ch: -#endif -#ifdef WEBRTC_CODEC_OPUS - case kDecoderOpus: - case kDecoderOpus_2ch: -#endif - case kDecoderRED: - case kDecoderAVT: - case kDecoderCNGnb: - case kDecoderCNGwb: - case kDecoderCNGswb32kHz: - case kDecoderCNGswb48kHz: case kDecoderArbitrary: { return true; } @@ -182,65 +141,6 @@ AudioDecoder* AudioDecoder::CreateAudioDecoder(NetEqDecoder codec_type) { switch (codec_type) { case kDecoderPCMu: return new AudioDecoderPcmU; - case kDecoderPCMa: - return new AudioDecoderPcmA; - case kDecoderPCMu_2ch: - return new AudioDecoderPcmUMultiCh(2); - case kDecoderPCMa_2ch: - return new AudioDecoderPcmAMultiCh(2); -#ifdef WEBRTC_CODEC_ILBC - case kDecoderILBC: - return new AudioDecoderIlbc; -#endif -#if defined(WEBRTC_CODEC_ISACFX) - case kDecoderISAC: - return new AudioDecoderIsacFix; -#elif defined(WEBRTC_CODEC_ISAC) - case kDecoderISAC: - return new AudioDecoderIsac; -#endif -#ifdef WEBRTC_CODEC_ISAC - case kDecoderISACswb: - return new AudioDecoderIsacSwb; - case kDecoderISACfb: - return new AudioDecoderIsacFb; -#endif -#ifdef WEBRTC_CODEC_PCM16 - case kDecoderPCM16B: - case kDecoderPCM16Bwb: - case kDecoderPCM16Bswb32kHz: - case kDecoderPCM16Bswb48kHz: - return new AudioDecoderPcm16B(codec_type); - case kDecoderPCM16B_2ch: - case kDecoderPCM16Bwb_2ch: - case kDecoderPCM16Bswb32kHz_2ch: - case kDecoderPCM16Bswb48kHz_2ch: - case kDecoderPCM16B_5ch: - return new AudioDecoderPcm16BMultiCh(codec_type); -#endif -#ifdef WEBRTC_CODEC_G722 - case kDecoderG722: - return new AudioDecoderG722; - case kDecoderG722_2ch: - return new AudioDecoderG722Stereo; -#endif -#ifdef WEBRTC_CODEC_CELT - case kDecoderCELT_32: - case kDecoderCELT_32_2ch: - return new AudioDecoderCelt(codec_type); -#endif -#ifdef WEBRTC_CODEC_OPUS - case kDecoderOpus: - case kDecoderOpus_2ch: - return new AudioDecoderOpus(codec_type); -#endif - case kDecoderCNGnb: - case kDecoderCNGwb: - case kDecoderCNGswb32kHz: - case kDecoderCNGswb48kHz: - return new AudioDecoderCng(codec_type); - case kDecoderRED: - case kDecoderAVT: case kDecoderArbitrary: default: { return NULL; diff --git a/jni/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc b/jni/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc index 6c7269a35f..2eec4d9964 100644 --- a/jni/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc +++ b/jni/webrtc/modules/audio_coding/neteq/audio_decoder_impl.cc @@ -41,7 +41,8 @@ namespace webrtc { // PCMu int AudioDecoderPcmU::Decode(const uint8_t* encoded, size_t encoded_len, - int16_t* decoded, SpeechType* speech_type) { + int16_t* decoded, size_t decodedSize, + SpeechType* speech_type) { int16_t temp_type = 1; // Default is speech. int16_t ret = WebRtcG711_DecodeU( state_, reinterpret_cast(const_cast(encoded)), diff --git a/jni/webrtc/modules/audio_coding/neteq/audio_decoder_impl.h b/jni/webrtc/modules/audio_coding/neteq/audio_decoder_impl.h index 265d660bd7..05d7b6157f 100644 --- a/jni/webrtc/modules/audio_coding/neteq/audio_decoder_impl.h +++ b/jni/webrtc/modules/audio_coding/neteq/audio_decoder_impl.h @@ -28,7 +28,8 @@ class AudioDecoderPcmU : public AudioDecoder { public: AudioDecoderPcmU() : AudioDecoder(kDecoderPCMu) {} virtual int Decode(const uint8_t* encoded, size_t encoded_len, - int16_t* decoded, SpeechType* speech_type); + int16_t* decoded, size_t decodedSize, + SpeechType* speech_type); virtual int Init() { return 0; } virtual int PacketDuration(const uint8_t* encoded, size_t encoded_len); diff --git a/jni/webrtc/modules/audio_coding/neteq/interface/audio_decoder.h b/jni/webrtc/modules/audio_coding/neteq/interface/audio_decoder.h index 9a2fb8b464..c4bce0439a 100644 --- a/jni/webrtc/modules/audio_coding/neteq/interface/audio_decoder.h +++ b/jni/webrtc/modules/audio_coding/neteq/interface/audio_decoder.h @@ -76,12 +76,14 @@ class AudioDecoder { // the return value. If the decoder produced comfort noise, |speech_type| // is set to kComfortNoise, otherwise it is kSpeech. virtual int Decode(const uint8_t* encoded, size_t encoded_len, - int16_t* decoded, SpeechType* speech_type) = 0; + int16_t* decoded, size_t decoded_size, + SpeechType* speech_type) = 0; // Same as Decode(), but interfaces to the decoders redundant decode function. // The default implementation simply calls the regular Decode() method. virtual int DecodeRedundant(const uint8_t* encoded, size_t encoded_len, - int16_t* decoded, SpeechType* speech_type); + int16_t* decoded, size_t decoded_size, + SpeechType* speech_type); // Indicates if the decoder implements the DecodePlc method. virtual bool HasDecodePlc() const; diff --git a/jni/webrtc/modules/audio_coding/neteq/neteq_impl.cc b/jni/webrtc/modules/audio_coding/neteq/neteq_impl.cc index a184fc3354..2bb4f28bfa 100644 --- a/jni/webrtc/modules/audio_coding/neteq/neteq_impl.cc +++ b/jni/webrtc/modules/audio_coding/neteq/neteq_impl.cc @@ -1253,7 +1253,7 @@ int NetEqImpl::DecodeLoop(PacketList* packet_list, Operations* operation, ", len=" << packet->payload_length; decode_length = decoder->DecodeRedundant( packet->payload, packet->payload_length, - &decoded_buffer_[*decoded_length], speech_type); + &decoded_buffer_[*decoded_length], decoded_buffer_length_ - *decoded_length, speech_type); } else { LOG(LS_VERBOSE) << "Decoding packet: ts=" << packet->header.timestamp << ", sn=" << packet->header.sequenceNumber << @@ -1263,6 +1263,7 @@ int NetEqImpl::DecodeLoop(PacketList* packet_list, Operations* operation, decode_length = decoder->Decode(packet->payload, packet->payload_length, &decoded_buffer_[*decoded_length], + decoded_buffer_length_ - *decoded_length, speech_type); } @@ -1591,7 +1592,7 @@ void NetEqImpl::DoCodecInternalCng() { if (decoder) { const uint8_t* dummy_payload = NULL; AudioDecoder::SpeechType speech_type; - length = decoder->Decode(dummy_payload, 0, decoded_buffer, &speech_type); + length = decoder->Decode(dummy_payload, 0, decoded_buffer, kMaxFrameSize, &speech_type); } assert(mute_factor_array_.get()); normal_->Process(decoded_buffer, length, last_mode_, mute_factor_array_.get(), diff --git a/libs/armeabi-v7a/libnative-utils.so b/libs/armeabi-v7a/libnative-utils.so index 1fa3ef17b5..f2a473f0af 100755 Binary files a/libs/armeabi-v7a/libnative-utils.so and b/libs/armeabi-v7a/libnative-utils.so differ diff --git a/libs/armeabi-v7a/libredphone-audio.so b/libs/armeabi-v7a/libredphone-audio.so index c08d1a5733..1d26fbae46 100755 Binary files a/libs/armeabi-v7a/libredphone-audio.so and b/libs/armeabi-v7a/libredphone-audio.so differ diff --git a/libs/armeabi/libnative-utils.so b/libs/armeabi/libnative-utils.so index e8f6ea4496..c4756720d8 100755 Binary files a/libs/armeabi/libnative-utils.so and b/libs/armeabi/libnative-utils.so differ diff --git a/libs/armeabi/libredphone-audio.so b/libs/armeabi/libredphone-audio.so index d607b23f1d..36452cba49 100755 Binary files a/libs/armeabi/libredphone-audio.so and b/libs/armeabi/libredphone-audio.so differ diff --git a/libs/x86/libnative-utils.so b/libs/x86/libnative-utils.so index a4b0567b87..df1067971e 100755 Binary files a/libs/x86/libnative-utils.so and b/libs/x86/libnative-utils.so differ diff --git a/libs/x86/libredphone-audio.so b/libs/x86/libredphone-audio.so index 0aa7c7189c..574a0c4bb5 100755 Binary files a/libs/x86/libredphone-audio.so and b/libs/x86/libredphone-audio.so differ