mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Modify upstream webrtc NetEq to pass bounds information to speex
Just in case Closes #6334 // FREEBIE
This commit is contained in:
parent
057c348d08
commit
8e25689c24
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
};
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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<int16_t*>(const_cast<uint8_t*>(encoded)),
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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(),
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user