From 88bdec8c3ab768c9cdb31b4216f82dba815ea516 Mon Sep 17 00:00:00 2001 From: "kwiberg@webrtc.org" Date: Tue, 16 Dec 2014 12:49:37 +0000 Subject: AudioEncoder subclass for iSACfix This patch refactors AudioEncoderDecoderIsac so that it can share almost all code with the very similar AudioEncoderDecoderIsacFix. BUG=3926 R=henrik.lundin@webrtc.org, kjellander@webrtc.org Review URL: https://webrtc-codereview.appspot.com/29259004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7912 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../codecs/isac/audio_encoder_isac_t_impl.h | 226 +++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h new file mode 100644 index 0000000000..7c13e87288 --- /dev/null +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -0,0 +1,226 @@ +/* + * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ +#define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ + +#include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_isac.h" + +#include "webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h" +#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" + +namespace webrtc { + +const int kIsacPayloadType = 103; + +inline int DivExact(int a, int b) { + CHECK_EQ(a % b, 0); + return a / b; +} + +template +AudioEncoderDecoderIsacT::Config::Config() + : payload_type(kIsacPayloadType), + sample_rate_hz(16000), + frame_size_ms(30), + bit_rate(32000) { +} + +template +bool AudioEncoderDecoderIsacT::Config::IsOk() const { + switch (sample_rate_hz) { + case 16000: + return (frame_size_ms == 30 || frame_size_ms == 60) && + bit_rate >= 10000 && bit_rate <= 32000; + case 32000: + return T::has_32kHz && + (frame_size_ms == 30 && bit_rate >= 10000 && bit_rate <= 56000); + default: + return false; + } +} + +template +AudioEncoderDecoderIsacT::ConfigAdaptive::ConfigAdaptive() + : payload_type(kIsacPayloadType), + sample_rate_hz(16000), + initial_frame_size_ms(30), + initial_bit_rate(32000), + enforce_frame_size(false) { +} + +template +bool AudioEncoderDecoderIsacT::ConfigAdaptive::IsOk() const { + static const int max_rate = T::has_32kHz ? 56000 : 32000; + return sample_rate_hz == 16000 && + (initial_frame_size_ms == 30 || initial_frame_size_ms == 60) && + initial_bit_rate >= 10000 && initial_bit_rate <= max_rate; +} + +template +AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) + : payload_type_(config.payload_type), + lock_(CriticalSectionWrapper::CreateCriticalSection()), + packet_in_progress_(false) { + CHECK(config.IsOk()); + CHECK_EQ(0, T::Create(&isac_state_)); + CHECK_EQ(0, T::EncoderInit(isac_state_, 1)); + CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); + CHECK_EQ(0, T::Control(isac_state_, config.bit_rate, config.frame_size_ms)); + CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); +} + +template +AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT( + const ConfigAdaptive& config) + : payload_type_(config.payload_type), + lock_(CriticalSectionWrapper::CreateCriticalSection()), + packet_in_progress_(false) { + CHECK(config.IsOk()); + CHECK_EQ(0, T::Create(&isac_state_)); + CHECK_EQ(0, T::EncoderInit(isac_state_, 0)); + CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); + CHECK_EQ(0, T::ControlBwe(isac_state_, config.initial_bit_rate, + config.initial_frame_size_ms, + config.enforce_frame_size)); + CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); +} + +template +AudioEncoderDecoderIsacT::~AudioEncoderDecoderIsacT() { + CHECK_EQ(0, T::Free(isac_state_)); +} + +template +int AudioEncoderDecoderIsacT::sample_rate_hz() const { + CriticalSectionScoped cs(lock_.get()); + return T::EncSampRate(isac_state_); +} + +template +int AudioEncoderDecoderIsacT::num_channels() const { + return 1; +} + +template +int AudioEncoderDecoderIsacT::Num10MsFramesInNextPacket() const { + CriticalSectionScoped cs(lock_.get()); + const int samples_in_next_packet = T::GetNewFrameLen(isac_state_); + return DivExact(samples_in_next_packet, DivExact(sample_rate_hz(), 100)); +} + +template +int AudioEncoderDecoderIsacT::Max10MsFramesInAPacket() const { + return 6; // iSAC puts at most 60 ms in a packet. +} + +template +bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t timestamp, + const int16_t* audio, + size_t max_encoded_bytes, + uint8_t* encoded, + EncodedInfo* info) { + if (!packet_in_progress_) { + // Starting a new packet; remember the timestamp for later. + packet_in_progress_ = true; + packet_timestamp_ = timestamp; + } + int r; + { + CriticalSectionScoped cs(lock_.get()); + r = T::Encode(isac_state_, audio, encoded); + } + if (r < 0) { + // An error occurred; propagate it to the caller. + packet_in_progress_ = false; + return false; + } + + // T::Encode doesn't allow us to tell it the size of the output + // buffer. All we can do is check for an overrun after the fact. + CHECK(static_cast(r) <= max_encoded_bytes); + + info->encoded_bytes = r; + if (r > 0) { + // Got enough input to produce a packet. Return the saved timestamp from + // the first chunk of input that went into the packet. + packet_in_progress_ = false; + info->encoded_timestamp = packet_timestamp_; + info->payload_type = payload_type_; + } + return true; +} + +template +int AudioEncoderDecoderIsacT::Decode(const uint8_t* encoded, + size_t encoded_len, + int16_t* decoded, + SpeechType* speech_type) { + CriticalSectionScoped cs(lock_.get()); + int16_t temp_type = 1; // Default is speech. + int16_t ret = + T::Decode(isac_state_, encoded, static_cast(encoded_len), + decoded, &temp_type); + *speech_type = ConvertSpeechType(temp_type); + return ret; +} + +template +int AudioEncoderDecoderIsacT::DecodeRedundant(const uint8_t* encoded, + size_t encoded_len, + int16_t* decoded, + SpeechType* speech_type) { + CriticalSectionScoped cs(lock_.get()); + int16_t temp_type = 1; // Default is speech. + int16_t ret = + T::DecodeRcu(isac_state_, encoded, static_cast(encoded_len), + decoded, &temp_type); + *speech_type = ConvertSpeechType(temp_type); + return ret; +} + +template +bool AudioEncoderDecoderIsacT::HasDecodePlc() const { + return true; +} + +template +int AudioEncoderDecoderIsacT::DecodePlc(int num_frames, int16_t* decoded) { + CriticalSectionScoped cs(lock_.get()); + return T::DecodePlc(isac_state_, decoded, num_frames); +} + +template +int AudioEncoderDecoderIsacT::Init() { + CriticalSectionScoped cs(lock_.get()); + return T::DecoderInit(isac_state_); +} + +template +int AudioEncoderDecoderIsacT::IncomingPacket(const uint8_t* payload, + size_t payload_len, + uint16_t rtp_sequence_number, + uint32_t rtp_timestamp, + uint32_t arrival_timestamp) { + CriticalSectionScoped cs(lock_.get()); + return T::UpdateBwEstimate( + isac_state_, payload, static_cast(payload_len), + rtp_sequence_number, rtp_timestamp, arrival_timestamp); +} + +template +int AudioEncoderDecoderIsacT::ErrorCode() { + CriticalSectionScoped cs(lock_.get()); + return T::GetErrorCode(isac_state_); +} + +} // namespace webrtc + +#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ -- cgit v1.2.3 From eed7a22bbfd8906d3ffd47c9a7c7f7f9308172d7 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Thu, 18 Dec 2014 09:52:36 +0000 Subject: Make an AudioEncoder subclass for iSAC redundant encoding Adding unit test, too. BUG=3926 R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/36559005 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7946 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../codecs/isac/audio_encoder_isac_t_impl.h | 48 ++++++++++++++++++---- 1 file changed, 40 insertions(+), 8 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 7c13e87288..9d36663320 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -68,7 +68,8 @@ template AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) : payload_type_(config.payload_type), lock_(CriticalSectionWrapper::CreateCriticalSection()), - packet_in_progress_(false) { + packet_in_progress_(false), + first_output_frame_(true) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); CHECK_EQ(0, T::EncoderInit(isac_state_, 1)); @@ -82,7 +83,8 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT( const ConfigAdaptive& config) : payload_type_(config.payload_type), lock_(CriticalSectionWrapper::CreateCriticalSection()), - packet_in_progress_(false) { + packet_in_progress_(false), + first_output_frame_(true) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); CHECK_EQ(0, T::EncoderInit(isac_state_, 0)); @@ -148,13 +150,43 @@ bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t timestamp, CHECK(static_cast(r) <= max_encoded_bytes); info->encoded_bytes = r; - if (r > 0) { - // Got enough input to produce a packet. Return the saved timestamp from - // the first chunk of input that went into the packet. - packet_in_progress_ = false; - info->encoded_timestamp = packet_timestamp_; - info->payload_type = payload_type_; + if (r == 0) + return true; + + // Got enough input to produce a packet. Return the saved timestamp from + // the first chunk of input that went into the packet. + packet_in_progress_ = false; + info->encoded_timestamp = packet_timestamp_; + info->payload_type = payload_type_; + + if (!T::has_redundant_encoder) + return true; + + if (first_output_frame_) { + // Do not emit the first output frame when using redundant encoding. + info->encoded_bytes = 0; + first_output_frame_ = false; + } else { + // Call the encoder's method to get redundant encoding. + const size_t primary_length = info->encoded_bytes; + int16_t secondary_len; + { + CriticalSectionScoped cs(lock_.get()); + secondary_len = T::GetRedPayload(isac_state_, &encoded[primary_length]); + } + DCHECK_GE(secondary_len, 0); + // |info| will be implicitly cast to an EncodedInfoLeaf struct, effectively + // discarding the (empty) vector of redundant information. This is + // intentional. + info->redundant.push_back(*info); + EncodedInfoLeaf secondary_info; + secondary_info.payload_type = info->payload_type; + secondary_info.encoded_bytes = secondary_len; + secondary_info.encoded_timestamp = last_encoded_timestamp_; + info->redundant.push_back(secondary_info); + info->encoded_bytes += secondary_len; // Sum of primary and secondary. } + last_encoded_timestamp_ = packet_timestamp_; return true; } -- cgit v1.2.3 From b6fab2b1cdcc8fd93ab8ac3dad19ee213a31a89e Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Mon, 26 Jan 2015 11:08:53 +0000 Subject: Introduce rtc::CheckedDivExact Use the new method to replace local ones in AudioEncoder{Opus,Isac}. COAUTHOR:kwiberg@webrtc.org R=andrew@webrtc.org Review URL: https://webrtc-codereview.appspot.com/34779004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@8148 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 9d36663320..6fc4dc6aa4 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -20,11 +20,6 @@ namespace webrtc { const int kIsacPayloadType = 103; -inline int DivExact(int a, int b) { - CHECK_EQ(a % b, 0); - return a / b; -} - template AudioEncoderDecoderIsacT::Config::Config() : payload_type(kIsacPayloadType), @@ -115,7 +110,8 @@ template int AudioEncoderDecoderIsacT::Num10MsFramesInNextPacket() const { CriticalSectionScoped cs(lock_.get()); const int samples_in_next_packet = T::GetNewFrameLen(isac_state_); - return DivExact(samples_in_next_packet, DivExact(sample_rate_hz(), 100)); + return rtc::CheckedDivExact(samples_in_next_packet, + rtc::CheckedDivExact(sample_rate_hz(), 100)); } template -- cgit v1.2.3 From 478cedc055f95bd160b53a4d7b69d8b3dd023ec7 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Tue, 27 Jan 2015 18:24:45 +0000 Subject: Add new methods to AudioEncoder interface The following three methods are added: rtp_timestamp_rate_hz() SetTargetBitrate() SetProjectedPacketLossRate() Default implementations are provided, and a few overrides are implemented. AudioEncoderCopyRed and AudioEncoderCng propagate the new methods to the underlying speech codec. BUG=3926 COAUTHOR:kwiberg@webrtc.org R=tina.legrand@webrtc.org Review URL: https://webrtc-codereview.appspot.com/34049004 Cr-Commit-Position: refs/heads/master@{#8171} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8171 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 6fc4dc6aa4..5b337c1656 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -120,7 +120,7 @@ int AudioEncoderDecoderIsacT::Max10MsFramesInAPacket() const { } template -bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t timestamp, +bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, const int16_t* audio, size_t max_encoded_bytes, uint8_t* encoded, @@ -128,7 +128,7 @@ bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t timestamp, if (!packet_in_progress_) { // Starting a new packet; remember the timestamp for later. packet_in_progress_ = true; - packet_timestamp_ = timestamp; + packet_timestamp_ = rtp_timestamp; } int r; { -- cgit v1.2.3 From bdebccf384db689931ba3df9afbcd59c85ddb8e2 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Thu, 29 Jan 2015 14:10:32 +0000 Subject: Fix a number of things in AudioEncoderDecoderIsac* - Add max_bit_rate and max_payload_size_bytes to config structs. - Fix support for 48 kHz sample rate. - Fix iSAC-RED. - Add method UpdateDecoderSampleRate(). - Update locking structure with a separate lock for local member variables used by the encoder methods. BUG=3926 COAUTHOR:kwiberg@webrtc.org R=minyue@webrtc.org Review URL: https://webrtc-codereview.appspot.com/41659004 Cr-Commit-Position: refs/heads/master@{#8204} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8204 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../codecs/isac/audio_encoder_isac_t_impl.h | 137 ++++++++++++++++----- 1 file changed, 107 insertions(+), 30 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 5b337c1656..b45fb265fd 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -13,29 +13,49 @@ #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_isac.h" +#include + +#include "webrtc/base/checks.h" #include "webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h" #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" namespace webrtc { const int kIsacPayloadType = 103; +const int kInvalidPayloadType = -1; template AudioEncoderDecoderIsacT::Config::Config() : payload_type(kIsacPayloadType), + red_payload_type(kInvalidPayloadType), sample_rate_hz(16000), frame_size_ms(30), - bit_rate(32000) { + bit_rate(32000), + max_bit_rate(-1), + max_payload_size_bytes(-1) { } template bool AudioEncoderDecoderIsacT::Config::IsOk() const { + if (max_bit_rate < 32000 && max_bit_rate != -1) + return false; + if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) + return false; switch (sample_rate_hz) { case 16000: + if (max_bit_rate > 53400) + return false; + if (max_payload_size_bytes > 400) + return false; return (frame_size_ms == 30 || frame_size_ms == 60) && bit_rate >= 10000 && bit_rate <= 32000; case 32000: - return T::has_32kHz && + case 48000: + if (max_bit_rate > 160000) + return false; + if (max_payload_size_bytes > 600) + return false; + return T::has_swb && (frame_size_ms == 30 && bit_rate >= 10000 && bit_rate <= 56000); default: return false; @@ -45,41 +65,76 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { template AudioEncoderDecoderIsacT::ConfigAdaptive::ConfigAdaptive() : payload_type(kIsacPayloadType), + red_payload_type(kInvalidPayloadType), sample_rate_hz(16000), initial_frame_size_ms(30), initial_bit_rate(32000), - enforce_frame_size(false) { + max_bit_rate(-1), + enforce_frame_size(false), + max_payload_size_bytes(-1) { } template bool AudioEncoderDecoderIsacT::ConfigAdaptive::IsOk() const { - static const int max_rate = T::has_32kHz ? 56000 : 32000; - return sample_rate_hz == 16000 && - (initial_frame_size_ms == 30 || initial_frame_size_ms == 60) && - initial_bit_rate >= 10000 && initial_bit_rate <= max_rate; + if (max_bit_rate < 32000 && max_bit_rate != -1) + return false; + if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) + return false; + switch (sample_rate_hz) { + case 16000: + if (max_bit_rate > 53400) + return false; + if (max_payload_size_bytes > 400) + return false; + return (initial_frame_size_ms == 30 || initial_frame_size_ms == 60) && + initial_bit_rate >= 10000 && initial_bit_rate <= 32000; + case 32000: + case 48000: + if (max_bit_rate > 160000) + return false; + if (max_payload_size_bytes > 600) + return false; + return T::has_swb && + (initial_frame_size_ms == 30 && initial_bit_rate >= 10000 && + initial_bit_rate <= 56000); + default: + return false; + } } template AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) : payload_type_(config.payload_type), + red_payload_type_(config.red_payload_type), + state_lock_(CriticalSectionWrapper::CreateCriticalSection()), lock_(CriticalSectionWrapper::CreateCriticalSection()), packet_in_progress_(false), - first_output_frame_(true) { + redundant_length_bytes_(0) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); CHECK_EQ(0, T::EncoderInit(isac_state_, 1)); CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); CHECK_EQ(0, T::Control(isac_state_, config.bit_rate, config.frame_size_ms)); - CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); + // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is + // still set to 32000 Hz, since there is no full-band mode in the decoder. + CHECK_EQ(0, T::SetDecSampRate(isac_state_, + std::min(config.sample_rate_hz, 32000))); + if (config.max_payload_size_bytes != -1) + CHECK_EQ(0, + T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); + if (config.max_bit_rate != -1) + CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate)); } template AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT( const ConfigAdaptive& config) : payload_type_(config.payload_type), + red_payload_type_(config.red_payload_type), + state_lock_(CriticalSectionWrapper::CreateCriticalSection()), lock_(CriticalSectionWrapper::CreateCriticalSection()), packet_in_progress_(false), - first_output_frame_(true) { + redundant_length_bytes_(0) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); CHECK_EQ(0, T::EncoderInit(isac_state_, 0)); @@ -88,6 +143,11 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT( config.initial_frame_size_ms, config.enforce_frame_size)); CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); + if (config.max_payload_size_bytes != -1) + CHECK_EQ(0, + T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); + if (config.max_bit_rate != -1) + CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate)); } template @@ -95,9 +155,15 @@ AudioEncoderDecoderIsacT::~AudioEncoderDecoderIsacT() { CHECK_EQ(0, T::Free(isac_state_)); } +template +void AudioEncoderDecoderIsacT::UpdateDecoderSampleRate(int sample_rate_hz) { + CriticalSectionScoped cs(state_lock_.get()); + CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz)); +} + template int AudioEncoderDecoderIsacT::sample_rate_hz() const { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped cs(state_lock_.get()); return T::EncSampRate(isac_state_); } @@ -108,7 +174,7 @@ int AudioEncoderDecoderIsacT::num_channels() const { template int AudioEncoderDecoderIsacT::Num10MsFramesInNextPacket() const { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped cs(state_lock_.get()); const int samples_in_next_packet = T::GetNewFrameLen(isac_state_); return rtc::CheckedDivExact(samples_in_next_packet, rtc::CheckedDivExact(sample_rate_hz(), 100)); @@ -125,6 +191,7 @@ bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, size_t max_encoded_bytes, uint8_t* encoded, EncodedInfo* info) { + CriticalSectionScoped cs(lock_.get()); if (!packet_in_progress_) { // Starting a new packet; remember the timestamp for later. packet_in_progress_ = true; @@ -132,7 +199,7 @@ bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, } int r; { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped cs(state_lock_.get()); r = T::Encode(isac_state_, audio, encoded); } if (r < 0) { @@ -158,30 +225,40 @@ bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, if (!T::has_redundant_encoder) return true; - if (first_output_frame_) { + if (redundant_length_bytes_ == 0) { // Do not emit the first output frame when using redundant encoding. info->encoded_bytes = 0; - first_output_frame_ = false; } else { - // Call the encoder's method to get redundant encoding. + // When a redundant payload from the last Encode call is available, the + // resulting payload consists of the primary encoding followed by the + // redundant encoding from last time. const size_t primary_length = info->encoded_bytes; - int16_t secondary_len; - { - CriticalSectionScoped cs(lock_.get()); - secondary_len = T::GetRedPayload(isac_state_, &encoded[primary_length]); - } - DCHECK_GE(secondary_len, 0); + memcpy(&encoded[primary_length], redundant_payload_, + redundant_length_bytes_); + // The EncodedInfo struct |info| will have one root node and two leaves. // |info| will be implicitly cast to an EncodedInfoLeaf struct, effectively // discarding the (empty) vector of redundant information. This is // intentional. info->redundant.push_back(*info); EncodedInfoLeaf secondary_info; secondary_info.payload_type = info->payload_type; - secondary_info.encoded_bytes = secondary_len; + secondary_info.encoded_bytes = redundant_length_bytes_; secondary_info.encoded_timestamp = last_encoded_timestamp_; info->redundant.push_back(secondary_info); - info->encoded_bytes += secondary_len; // Sum of primary and secondary. + info->encoded_bytes += + redundant_length_bytes_; // Sum of primary and secondary. + DCHECK_NE(red_payload_type_, kInvalidPayloadType) + << "Config.red_payload_type must be set for " + "AudioEncoderDecoderIsacRed."; + info->payload_type = red_payload_type_; + } + { + CriticalSectionScoped cs(state_lock_.get()); + // Call the encoder's method to get redundant encoding. + redundant_length_bytes_ = T::GetRedPayload(isac_state_, redundant_payload_); } + DCHECK_LE(redundant_length_bytes_, sizeof(redundant_payload_)); + DCHECK_GE(redundant_length_bytes_, 0u); last_encoded_timestamp_ = packet_timestamp_; return true; } @@ -191,7 +268,7 @@ int AudioEncoderDecoderIsacT::Decode(const uint8_t* encoded, size_t encoded_len, int16_t* decoded, SpeechType* speech_type) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped cs(state_lock_.get()); int16_t temp_type = 1; // Default is speech. int16_t ret = T::Decode(isac_state_, encoded, static_cast(encoded_len), @@ -205,7 +282,7 @@ int AudioEncoderDecoderIsacT::DecodeRedundant(const uint8_t* encoded, size_t encoded_len, int16_t* decoded, SpeechType* speech_type) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped cs(state_lock_.get()); int16_t temp_type = 1; // Default is speech. int16_t ret = T::DecodeRcu(isac_state_, encoded, static_cast(encoded_len), @@ -221,13 +298,13 @@ bool AudioEncoderDecoderIsacT::HasDecodePlc() const { template int AudioEncoderDecoderIsacT::DecodePlc(int num_frames, int16_t* decoded) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped cs(state_lock_.get()); return T::DecodePlc(isac_state_, decoded, num_frames); } template int AudioEncoderDecoderIsacT::Init() { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped cs(state_lock_.get()); return T::DecoderInit(isac_state_); } @@ -237,7 +314,7 @@ int AudioEncoderDecoderIsacT::IncomingPacket(const uint8_t* payload, uint16_t rtp_sequence_number, uint32_t rtp_timestamp, uint32_t arrival_timestamp) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped cs(state_lock_.get()); return T::UpdateBwEstimate( isac_state_, payload, static_cast(payload_len), rtp_sequence_number, rtp_timestamp, arrival_timestamp); @@ -245,7 +322,7 @@ int AudioEncoderDecoderIsacT::IncomingPacket(const uint8_t* payload, template int AudioEncoderDecoderIsacT::ErrorCode() { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped cs(state_lock_.get()); return T::GetErrorCode(isac_state_); } -- cgit v1.2.3 From c420a86f4c407d41876afe5b7d47b8d060e18b68 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Mon, 2 Feb 2015 10:36:30 +0000 Subject: Change name for local CriticalSectionScoped variable Tools were complaining about (harmless) shadowing of variable names. This is a follow-up to https://webrtc-codereview.appspot.com/41659004/#msg8 BUG=3926 TBR=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/37099004 Cr-Commit-Position: refs/heads/master@{#8225} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8225 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index b45fb265fd..17e533fe48 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -191,7 +191,7 @@ bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, size_t max_encoded_bytes, uint8_t* encoded, EncodedInfo* info) { - CriticalSectionScoped cs(lock_.get()); + CriticalSectionScoped cs_lock(lock_.get()); if (!packet_in_progress_) { // Starting a new packet; remember the timestamp for later. packet_in_progress_ = true; -- cgit v1.2.3 From fbc347f2ef68a70ed4babd7f8cb29beecacfb994 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Mon, 16 Feb 2015 14:28:20 +0000 Subject: Re-land r8342 "Switch to using AudioEncoderIsac instead of ACMISAC"" This reverts r8372, with a bug fix: allowing zero rate in AudioEncoderIsac::Config. Without this fix, setting the rate to zero triggered a CHECK. Existing callers assumed that zero was a valid value. Setting the rate to zero will result in the default rate 32000 being set. BUG=4228,chromium:458638 COAUTHOR=kwiberg@webrtc.org R=tina.legrand@webrtc.org TBR=tina.legrand@webrtc.org CC=jmarusic@webrtc.org Review URL: https://webrtc-codereview.appspot.com/39159004 Cr-Commit-Position: refs/heads/master@{#8378} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8378 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 17e533fe48..39daa00a85 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -23,6 +23,7 @@ namespace webrtc { const int kIsacPayloadType = 103; const int kInvalidPayloadType = -1; +const int kDefaultBitRate = 32000; template AudioEncoderDecoderIsacT::Config::Config() @@ -30,7 +31,7 @@ AudioEncoderDecoderIsacT::Config::Config() red_payload_type(kInvalidPayloadType), sample_rate_hz(16000), frame_size_ms(30), - bit_rate(32000), + bit_rate(kDefaultBitRate), max_bit_rate(-1), max_payload_size_bytes(-1) { } @@ -48,7 +49,7 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { if (max_payload_size_bytes > 400) return false; return (frame_size_ms == 30 || frame_size_ms == 60) && - bit_rate >= 10000 && bit_rate <= 32000; + ((bit_rate >= 10000 && bit_rate <= 32000) || bit_rate == 0); case 32000: case 48000: if (max_bit_rate > 160000) @@ -56,7 +57,8 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { if (max_payload_size_bytes > 600) return false; return T::has_swb && - (frame_size_ms == 30 && bit_rate >= 10000 && bit_rate <= 56000); + (frame_size_ms == 30 && + ((bit_rate >= 10000 && bit_rate <= 56000) || bit_rate == 0)); default: return false; } @@ -68,7 +70,7 @@ AudioEncoderDecoderIsacT::ConfigAdaptive::ConfigAdaptive() red_payload_type(kInvalidPayloadType), sample_rate_hz(16000), initial_frame_size_ms(30), - initial_bit_rate(32000), + initial_bit_rate(kDefaultBitRate), max_bit_rate(-1), enforce_frame_size(false), max_payload_size_bytes(-1) { @@ -114,7 +116,9 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) CHECK_EQ(0, T::Create(&isac_state_)); CHECK_EQ(0, T::EncoderInit(isac_state_, 1)); CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); - CHECK_EQ(0, T::Control(isac_state_, config.bit_rate, config.frame_size_ms)); + CHECK_EQ(0, T::Control(isac_state_, config.bit_rate == 0 ? kDefaultBitRate + : config.bit_rate, + config.frame_size_ms)); // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is // still set to 32000 Hz, since there is no full-band mode in the decoder. CHECK_EQ(0, T::SetDecSampRate(isac_state_, -- cgit v1.2.3 From 05211277798ca4791fbdc508e24d7fd06d5ee6ff Mon Sep 17 00:00:00 2001 From: "kwiberg@webrtc.org" Date: Wed, 18 Feb 2015 12:00:32 +0000 Subject: AudioEncoder: Rename virtual accessors to CamelCase Although sample_rate_hz(), num_channels(), and rtp_timestamp_rate_hz() are simple accessors for almost all implementations of AudioEncoder, they are virtual and not guaranteed to be just simple accessors. Thus, it makes more sense to use the normal CamelCase naming scheme. BUG=4235 R=henrik.lundin@webrtc.org Review URL: https://webrtc-codereview.appspot.com/34239004 Cr-Commit-Position: refs/heads/master@{#8407} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8407 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 39daa00a85..095bb7b313 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -166,13 +166,13 @@ void AudioEncoderDecoderIsacT::UpdateDecoderSampleRate(int sample_rate_hz) { } template -int AudioEncoderDecoderIsacT::sample_rate_hz() const { +int AudioEncoderDecoderIsacT::SampleRateHz() const { CriticalSectionScoped cs(state_lock_.get()); return T::EncSampRate(isac_state_); } template -int AudioEncoderDecoderIsacT::num_channels() const { +int AudioEncoderDecoderIsacT::NumChannels() const { return 1; } @@ -181,7 +181,7 @@ int AudioEncoderDecoderIsacT::Num10MsFramesInNextPacket() const { CriticalSectionScoped cs(state_lock_.get()); const int samples_in_next_packet = T::GetNewFrameLen(isac_state_); return rtc::CheckedDivExact(samples_in_next_packet, - rtc::CheckedDivExact(sample_rate_hz(), 100)); + rtc::CheckedDivExact(SampleRateHz(), 100)); } template -- cgit v1.2.3 From 78619e2714185c77900400ba95ff7ac13c82cd41 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Wed, 18 Feb 2015 14:50:57 +0000 Subject: Revert of r8378 "Switch to using AudioEncoderIsac instead of ACMISAC" This is a speculative revert to try to isolate a memory issue. BUG=chromium:459483,4228 R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/39189004 Cr-Commit-Position: refs/heads/master@{#8412} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8412 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 095bb7b313..91353d973f 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -23,7 +23,6 @@ namespace webrtc { const int kIsacPayloadType = 103; const int kInvalidPayloadType = -1; -const int kDefaultBitRate = 32000; template AudioEncoderDecoderIsacT::Config::Config() @@ -31,7 +30,7 @@ AudioEncoderDecoderIsacT::Config::Config() red_payload_type(kInvalidPayloadType), sample_rate_hz(16000), frame_size_ms(30), - bit_rate(kDefaultBitRate), + bit_rate(32000), max_bit_rate(-1), max_payload_size_bytes(-1) { } @@ -49,7 +48,7 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { if (max_payload_size_bytes > 400) return false; return (frame_size_ms == 30 || frame_size_ms == 60) && - ((bit_rate >= 10000 && bit_rate <= 32000) || bit_rate == 0); + bit_rate >= 10000 && bit_rate <= 32000; case 32000: case 48000: if (max_bit_rate > 160000) @@ -57,8 +56,7 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { if (max_payload_size_bytes > 600) return false; return T::has_swb && - (frame_size_ms == 30 && - ((bit_rate >= 10000 && bit_rate <= 56000) || bit_rate == 0)); + (frame_size_ms == 30 && bit_rate >= 10000 && bit_rate <= 56000); default: return false; } @@ -70,7 +68,7 @@ AudioEncoderDecoderIsacT::ConfigAdaptive::ConfigAdaptive() red_payload_type(kInvalidPayloadType), sample_rate_hz(16000), initial_frame_size_ms(30), - initial_bit_rate(kDefaultBitRate), + initial_bit_rate(32000), max_bit_rate(-1), enforce_frame_size(false), max_payload_size_bytes(-1) { @@ -116,9 +114,7 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) CHECK_EQ(0, T::Create(&isac_state_)); CHECK_EQ(0, T::EncoderInit(isac_state_, 1)); CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); - CHECK_EQ(0, T::Control(isac_state_, config.bit_rate == 0 ? kDefaultBitRate - : config.bit_rate, - config.frame_size_ms)); + CHECK_EQ(0, T::Control(isac_state_, config.bit_rate, config.frame_size_ms)); // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is // still set to 32000 Hz, since there is no full-band mode in the decoder. CHECK_EQ(0, T::SetDecSampRate(isac_state_, -- cgit v1.2.3 From be96bfb1791b53675b80089d701e47baea19ad8c Mon Sep 17 00:00:00 2001 From: "kwiberg@webrtc.org" Date: Thu, 19 Feb 2015 15:10:20 +0000 Subject: Re-land "Switch to using AudioEncoderIsac instead of ACMISAC" It should work now, after the fix in r8431. Previously committed in r8342, reverted in r8372, committed in r8378, and reverted in r8412. COAUTHOR=henrik.lundin@webrtc.org BUG=4228 TBR=henrik.lundin@webrtc.org Review URL: https://webrtc-codereview.appspot.com/34279004 Cr-Commit-Position: refs/heads/master@{#8433} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8433 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 91353d973f..095bb7b313 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -23,6 +23,7 @@ namespace webrtc { const int kIsacPayloadType = 103; const int kInvalidPayloadType = -1; +const int kDefaultBitRate = 32000; template AudioEncoderDecoderIsacT::Config::Config() @@ -30,7 +31,7 @@ AudioEncoderDecoderIsacT::Config::Config() red_payload_type(kInvalidPayloadType), sample_rate_hz(16000), frame_size_ms(30), - bit_rate(32000), + bit_rate(kDefaultBitRate), max_bit_rate(-1), max_payload_size_bytes(-1) { } @@ -48,7 +49,7 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { if (max_payload_size_bytes > 400) return false; return (frame_size_ms == 30 || frame_size_ms == 60) && - bit_rate >= 10000 && bit_rate <= 32000; + ((bit_rate >= 10000 && bit_rate <= 32000) || bit_rate == 0); case 32000: case 48000: if (max_bit_rate > 160000) @@ -56,7 +57,8 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { if (max_payload_size_bytes > 600) return false; return T::has_swb && - (frame_size_ms == 30 && bit_rate >= 10000 && bit_rate <= 56000); + (frame_size_ms == 30 && + ((bit_rate >= 10000 && bit_rate <= 56000) || bit_rate == 0)); default: return false; } @@ -68,7 +70,7 @@ AudioEncoderDecoderIsacT::ConfigAdaptive::ConfigAdaptive() red_payload_type(kInvalidPayloadType), sample_rate_hz(16000), initial_frame_size_ms(30), - initial_bit_rate(32000), + initial_bit_rate(kDefaultBitRate), max_bit_rate(-1), enforce_frame_size(false), max_payload_size_bytes(-1) { @@ -114,7 +116,9 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) CHECK_EQ(0, T::Create(&isac_state_)); CHECK_EQ(0, T::EncoderInit(isac_state_, 1)); CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); - CHECK_EQ(0, T::Control(isac_state_, config.bit_rate, config.frame_size_ms)); + CHECK_EQ(0, T::Control(isac_state_, config.bit_rate == 0 ? kDefaultBitRate + : config.bit_rate, + config.frame_size_ms)); // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is // still set to 32000 Hz, since there is no full-band mode in the decoder. CHECK_EQ(0, T::SetDecSampRate(isac_state_, -- cgit v1.2.3 From b9c18d56438eefb71ff68d47880d2b49fd380bc7 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Tue, 24 Feb 2015 15:58:17 +0000 Subject: Set decoder output frequency in AudioDecoder::Decode call This CL changes the way the decoder sample rate is set and updated. In practice, it only concerns the iSAC (float) codec. One single iSAC decoder instance is used for both wideband and super-wideband decoding, and the instance must be told to switch output frequency if the payload type changes. This used to be done through a call to UpdateDecoderSampleRate, but is now instead done in the Decode call as an extra parameter. R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/34349004 Cr-Commit-Position: refs/heads/master@{#8476} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8476 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 095bb7b313..d9cec82cf6 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -109,6 +109,7 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) : payload_type_(config.payload_type), red_payload_type_(config.red_payload_type), state_lock_(CriticalSectionWrapper::CreateCriticalSection()), + decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), packet_in_progress_(false), redundant_length_bytes_(0) { @@ -136,6 +137,7 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT( : payload_type_(config.payload_type), red_payload_type_(config.red_payload_type), state_lock_(CriticalSectionWrapper::CreateCriticalSection()), + decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), packet_in_progress_(false), redundant_length_bytes_(0) { @@ -159,12 +161,6 @@ AudioEncoderDecoderIsacT::~AudioEncoderDecoderIsacT() { CHECK_EQ(0, T::Free(isac_state_)); } -template -void AudioEncoderDecoderIsacT::UpdateDecoderSampleRate(int sample_rate_hz) { - CriticalSectionScoped cs(state_lock_.get()); - CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz)); -} - template int AudioEncoderDecoderIsacT::SampleRateHz() const { CriticalSectionScoped cs(state_lock_.get()); @@ -270,9 +266,16 @@ bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, template int AudioEncoderDecoderIsacT::Decode(const uint8_t* encoded, size_t encoded_len, + int sample_rate_hz, int16_t* decoded, SpeechType* speech_type) { CriticalSectionScoped cs(state_lock_.get()); + CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000) + << "Unsupported sample rate " << sample_rate_hz; + if (sample_rate_hz != decoder_sample_rate_hz_) { + CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz)); + decoder_sample_rate_hz_ = sample_rate_hz; + } int16_t temp_type = 1; // Default is speech. int16_t ret = T::Decode(isac_state_, encoded, static_cast(encoded_len), @@ -284,6 +287,7 @@ int AudioEncoderDecoderIsacT::Decode(const uint8_t* encoded, template int AudioEncoderDecoderIsacT::DecodeRedundant(const uint8_t* encoded, size_t encoded_len, + int /*sample_rate_hz*/, int16_t* decoded, SpeechType* speech_type) { CriticalSectionScoped cs(state_lock_.get()); -- cgit v1.2.3 From 903182bd8e782b162900b99bc7e25c35edebdb67 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Tue, 24 Feb 2015 21:17:50 +0000 Subject: Revert r8476 "Set decoder output frequency in AudioDecoder::Decode call" This change uncovered issue 4143, evading the Memcheck suppression since the signature is changed in the Decode function. A fix for this is in the making; see https://review.webrtc.org/36309004. This CL will be re-landed once the fix is in place. BUG=4143 TBR=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/42089004 Cr-Commit-Position: refs/heads/master@{#8488} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8488 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index d9cec82cf6..095bb7b313 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -109,7 +109,6 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) : payload_type_(config.payload_type), red_payload_type_(config.red_payload_type), state_lock_(CriticalSectionWrapper::CreateCriticalSection()), - decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), packet_in_progress_(false), redundant_length_bytes_(0) { @@ -137,7 +136,6 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT( : payload_type_(config.payload_type), red_payload_type_(config.red_payload_type), state_lock_(CriticalSectionWrapper::CreateCriticalSection()), - decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), packet_in_progress_(false), redundant_length_bytes_(0) { @@ -161,6 +159,12 @@ AudioEncoderDecoderIsacT::~AudioEncoderDecoderIsacT() { CHECK_EQ(0, T::Free(isac_state_)); } +template +void AudioEncoderDecoderIsacT::UpdateDecoderSampleRate(int sample_rate_hz) { + CriticalSectionScoped cs(state_lock_.get()); + CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz)); +} + template int AudioEncoderDecoderIsacT::SampleRateHz() const { CriticalSectionScoped cs(state_lock_.get()); @@ -266,16 +270,9 @@ bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, template int AudioEncoderDecoderIsacT::Decode(const uint8_t* encoded, size_t encoded_len, - int sample_rate_hz, int16_t* decoded, SpeechType* speech_type) { CriticalSectionScoped cs(state_lock_.get()); - CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000) - << "Unsupported sample rate " << sample_rate_hz; - if (sample_rate_hz != decoder_sample_rate_hz_) { - CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz)); - decoder_sample_rate_hz_ = sample_rate_hz; - } int16_t temp_type = 1; // Default is speech. int16_t ret = T::Decode(isac_state_, encoded, static_cast(encoded_len), @@ -287,7 +284,6 @@ int AudioEncoderDecoderIsacT::Decode(const uint8_t* encoded, template int AudioEncoderDecoderIsacT::DecodeRedundant(const uint8_t* encoded, size_t encoded_len, - int /*sample_rate_hz*/, int16_t* decoded, SpeechType* speech_type) { CriticalSectionScoped cs(state_lock_.get()); -- cgit v1.2.3 From 1eda4e3db60f484d179cee359e150c4f0c9c7c67 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Wed, 25 Feb 2015 10:02:29 +0000 Subject: Reland r8476 "Set decoder output frequency in AudioDecoder::Decode call" This should be safe to land now that issue 4143 was resolved (in r8492). This change effectively reverts 8488. TBR=kwiberg@webrtc.org Original commit message: This CL changes the way the decoder sample rate is set and updated. In practice, it only concerns the iSAC (float) codec. One single iSAC decoder instance is used for both wideband and super-wideband decoding, and the instance must be told to switch output frequency if the payload type changes. This used to be done through a call to UpdateDecoderSampleRate, but is now instead done in the Decode call as an extra parameter. Review URL: https://webrtc-codereview.appspot.com/39289004 Cr-Commit-Position: refs/heads/master@{#8496} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8496 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 095bb7b313..d9cec82cf6 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -109,6 +109,7 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) : payload_type_(config.payload_type), red_payload_type_(config.red_payload_type), state_lock_(CriticalSectionWrapper::CreateCriticalSection()), + decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), packet_in_progress_(false), redundant_length_bytes_(0) { @@ -136,6 +137,7 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT( : payload_type_(config.payload_type), red_payload_type_(config.red_payload_type), state_lock_(CriticalSectionWrapper::CreateCriticalSection()), + decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), packet_in_progress_(false), redundant_length_bytes_(0) { @@ -159,12 +161,6 @@ AudioEncoderDecoderIsacT::~AudioEncoderDecoderIsacT() { CHECK_EQ(0, T::Free(isac_state_)); } -template -void AudioEncoderDecoderIsacT::UpdateDecoderSampleRate(int sample_rate_hz) { - CriticalSectionScoped cs(state_lock_.get()); - CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz)); -} - template int AudioEncoderDecoderIsacT::SampleRateHz() const { CriticalSectionScoped cs(state_lock_.get()); @@ -270,9 +266,16 @@ bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, template int AudioEncoderDecoderIsacT::Decode(const uint8_t* encoded, size_t encoded_len, + int sample_rate_hz, int16_t* decoded, SpeechType* speech_type) { CriticalSectionScoped cs(state_lock_.get()); + CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000) + << "Unsupported sample rate " << sample_rate_hz; + if (sample_rate_hz != decoder_sample_rate_hz_) { + CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz)); + decoder_sample_rate_hz_ = sample_rate_hz; + } int16_t temp_type = 1; // Default is speech. int16_t ret = T::Decode(isac_state_, encoded, static_cast(encoded_len), @@ -284,6 +287,7 @@ int AudioEncoderDecoderIsacT::Decode(const uint8_t* encoded, template int AudioEncoderDecoderIsacT::DecodeRedundant(const uint8_t* encoded, size_t encoded_len, + int /*sample_rate_hz*/, int16_t* decoded, SpeechType* speech_type) { CriticalSectionScoped cs(state_lock_.get()); -- cgit v1.2.3 From b1f0de30be3397eba3d423b71abc5c50db2a1665 Mon Sep 17 00:00:00 2001 From: "jmarusic@webrtc.org" Date: Thu, 26 Feb 2015 15:38:10 +0000 Subject: AudioEncoder: change Encode and EncodeInternal return type to void After code cleanup done on issues: https://webrtc-codereview.appspot.com/34259004/ https://webrtc-codereview.appspot.com/43409004/ https://webrtc-codereview.appspot.com/34309004/ https://webrtc-codereview.appspot.com/34309004/ https://webrtc-codereview.appspot.com/36209004/ https://webrtc-codereview.appspot.com/40899004/ https://webrtc-codereview.appspot.com/39279004/ https://webrtc-codereview.appspot.com/42099005/ and the similar work done for AudioEncoderDecoderIsacT, methods AudioEncoder::Encode and AudioEncoder::EncodeInternal will always succeed. Therefore, there is no need for them to return bool value that represents success or failure. R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/38279004 Cr-Commit-Position: refs/heads/master@{#8518} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8518 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index d9cec82cf6..7ac51b6e38 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -186,7 +186,7 @@ int AudioEncoderDecoderIsacT::Max10MsFramesInAPacket() const { } template -bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, +void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, const int16_t* audio, size_t max_encoded_bytes, uint8_t* encoded, @@ -202,11 +202,7 @@ bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, CriticalSectionScoped cs(state_lock_.get()); r = T::Encode(isac_state_, audio, encoded); } - if (r < 0) { - // An error occurred; propagate it to the caller. - packet_in_progress_ = false; - return false; - } + CHECK_GE(r, 0); // T::Encode doesn't allow us to tell it the size of the output // buffer. All we can do is check for an overrun after the fact. @@ -214,7 +210,7 @@ bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, info->encoded_bytes = r; if (r == 0) - return true; + return; // Got enough input to produce a packet. Return the saved timestamp from // the first chunk of input that went into the packet. @@ -223,7 +219,7 @@ bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, info->payload_type = payload_type_; if (!T::has_redundant_encoder) - return true; + return; if (redundant_length_bytes_ == 0) { // Do not emit the first output frame when using redundant encoding. @@ -260,7 +256,6 @@ bool AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, DCHECK_LE(redundant_length_bytes_, sizeof(redundant_payload_)); DCHECK_GE(redundant_length_bytes_, 0u); last_encoded_timestamp_ = packet_timestamp_; - return true; } template -- cgit v1.2.3 From 1fc28f2305947dda3a8aa83cb86190af3edd16fb Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Tue, 3 Mar 2015 19:30:45 +0000 Subject: Collapse AudioEncoderDecoderIsacRed into AudioEncoderDecoderIsac With this change, support for iSAC-RED is incorporated into the regular AudioEncoderDecoderIsac class. COAUTHOR=kwiberg@webrtc.org R=jmarusic@webrtc.org Review URL: https://webrtc-codereview.appspot.com/43549004 Cr-Commit-Position: refs/heads/master@{#8577} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8577 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../codecs/isac/audio_encoder_isac_t_impl.h | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 7ac51b6e38..024efa1413 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -33,7 +33,8 @@ AudioEncoderDecoderIsacT::Config::Config() frame_size_ms(30), bit_rate(kDefaultBitRate), max_bit_rate(-1), - max_payload_size_bytes(-1) { + max_payload_size_bytes(-1), + use_red(false) { } template @@ -42,6 +43,8 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { return false; if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) return false; + if (use_red && red_payload_type == kInvalidPayloadType) + return false; switch (sample_rate_hz) { case 16000: if (max_bit_rate > 53400) @@ -73,7 +76,8 @@ AudioEncoderDecoderIsacT::ConfigAdaptive::ConfigAdaptive() initial_bit_rate(kDefaultBitRate), max_bit_rate(-1), enforce_frame_size(false), - max_payload_size_bytes(-1) { + max_payload_size_bytes(-1), + use_red(false) { } template @@ -82,6 +86,8 @@ bool AudioEncoderDecoderIsacT::ConfigAdaptive::IsOk() const { return false; if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) return false; + if (use_red && red_payload_type == kInvalidPayloadType) + return false; switch (sample_rate_hz) { case 16000: if (max_bit_rate > 53400) @@ -108,10 +114,13 @@ template AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) : payload_type_(config.payload_type), red_payload_type_(config.red_payload_type), + use_red_(config.use_red), state_lock_(CriticalSectionWrapper::CreateCriticalSection()), decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), packet_in_progress_(false), + redundant_payload_( + use_red_ ? new uint8_t[kSufficientEncodeBufferSizeBytes] : nullptr), redundant_length_bytes_(0) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); @@ -136,10 +145,13 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT( const ConfigAdaptive& config) : payload_type_(config.payload_type), red_payload_type_(config.red_payload_type), + use_red_(config.use_red), state_lock_(CriticalSectionWrapper::CreateCriticalSection()), decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), packet_in_progress_(false), + redundant_payload_( + use_red_ ? new uint8_t[kSufficientEncodeBufferSizeBytes] : nullptr), redundant_length_bytes_(0) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); @@ -218,7 +230,7 @@ void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, info->encoded_timestamp = packet_timestamp_; info->payload_type = payload_type_; - if (!T::has_redundant_encoder) + if (!use_red_) return; if (redundant_length_bytes_ == 0) { @@ -229,7 +241,7 @@ void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, // resulting payload consists of the primary encoding followed by the // redundant encoding from last time. const size_t primary_length = info->encoded_bytes; - memcpy(&encoded[primary_length], redundant_payload_, + memcpy(&encoded[primary_length], redundant_payload_.get(), redundant_length_bytes_); // The EncodedInfo struct |info| will have one root node and two leaves. // |info| will be implicitly cast to an EncodedInfoLeaf struct, effectively @@ -251,9 +263,9 @@ void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, { CriticalSectionScoped cs(state_lock_.get()); // Call the encoder's method to get redundant encoding. - redundant_length_bytes_ = T::GetRedPayload(isac_state_, redundant_payload_); + redundant_length_bytes_ = + T::GetRedPayload(isac_state_, redundant_payload_.get()); } - DCHECK_LE(redundant_length_bytes_, sizeof(redundant_payload_)); DCHECK_GE(redundant_length_bytes_, 0u); last_encoded_timestamp_ = packet_timestamp_; } -- cgit v1.2.3 From bcef431902ad4addbd8fce8b1289b35cdfec1416 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Tue, 3 Mar 2015 20:13:11 +0000 Subject: Revert r8577 "Collapse AudioEncoderDecoderIsacRed into ..." Some of the build bots seems to have reacted to this change. TBR=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/42169004 Cr-Commit-Position: refs/heads/master@{#8578} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8578 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../codecs/isac/audio_encoder_isac_t_impl.h | 24 ++++++---------------- 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 024efa1413..7ac51b6e38 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -33,8 +33,7 @@ AudioEncoderDecoderIsacT::Config::Config() frame_size_ms(30), bit_rate(kDefaultBitRate), max_bit_rate(-1), - max_payload_size_bytes(-1), - use_red(false) { + max_payload_size_bytes(-1) { } template @@ -43,8 +42,6 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { return false; if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) return false; - if (use_red && red_payload_type == kInvalidPayloadType) - return false; switch (sample_rate_hz) { case 16000: if (max_bit_rate > 53400) @@ -76,8 +73,7 @@ AudioEncoderDecoderIsacT::ConfigAdaptive::ConfigAdaptive() initial_bit_rate(kDefaultBitRate), max_bit_rate(-1), enforce_frame_size(false), - max_payload_size_bytes(-1), - use_red(false) { + max_payload_size_bytes(-1) { } template @@ -86,8 +82,6 @@ bool AudioEncoderDecoderIsacT::ConfigAdaptive::IsOk() const { return false; if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) return false; - if (use_red && red_payload_type == kInvalidPayloadType) - return false; switch (sample_rate_hz) { case 16000: if (max_bit_rate > 53400) @@ -114,13 +108,10 @@ template AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) : payload_type_(config.payload_type), red_payload_type_(config.red_payload_type), - use_red_(config.use_red), state_lock_(CriticalSectionWrapper::CreateCriticalSection()), decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), packet_in_progress_(false), - redundant_payload_( - use_red_ ? new uint8_t[kSufficientEncodeBufferSizeBytes] : nullptr), redundant_length_bytes_(0) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); @@ -145,13 +136,10 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT( const ConfigAdaptive& config) : payload_type_(config.payload_type), red_payload_type_(config.red_payload_type), - use_red_(config.use_red), state_lock_(CriticalSectionWrapper::CreateCriticalSection()), decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), packet_in_progress_(false), - redundant_payload_( - use_red_ ? new uint8_t[kSufficientEncodeBufferSizeBytes] : nullptr), redundant_length_bytes_(0) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); @@ -230,7 +218,7 @@ void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, info->encoded_timestamp = packet_timestamp_; info->payload_type = payload_type_; - if (!use_red_) + if (!T::has_redundant_encoder) return; if (redundant_length_bytes_ == 0) { @@ -241,7 +229,7 @@ void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, // resulting payload consists of the primary encoding followed by the // redundant encoding from last time. const size_t primary_length = info->encoded_bytes; - memcpy(&encoded[primary_length], redundant_payload_.get(), + memcpy(&encoded[primary_length], redundant_payload_, redundant_length_bytes_); // The EncodedInfo struct |info| will have one root node and two leaves. // |info| will be implicitly cast to an EncodedInfoLeaf struct, effectively @@ -263,9 +251,9 @@ void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, { CriticalSectionScoped cs(state_lock_.get()); // Call the encoder's method to get redundant encoding. - redundant_length_bytes_ = - T::GetRedPayload(isac_state_, redundant_payload_.get()); + redundant_length_bytes_ = T::GetRedPayload(isac_state_, redundant_payload_); } + DCHECK_LE(redundant_length_bytes_, sizeof(redundant_payload_)); DCHECK_GE(redundant_length_bytes_, 0u); last_encoded_timestamp_ = packet_timestamp_; } -- cgit v1.2.3 From 1d25c8719989fdbd30a845921e5bf0bd60535ad8 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Wed, 4 Mar 2015 08:55:21 +0000 Subject: Reland r8577 "Collapse AudioEncoderDecoderIsacRed into ..." This effectively reverts r8578. TBR=jmarusic@webrtc.org Original commit message: Collapse AudioEncoderDecoderIsacRed into AudioEncoderDecoderIsac With this change, support for iSAC-RED is incorporated into the regular AudioEncoderDecoderIsac class. COAUTHOR=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/44539004 Cr-Commit-Position: refs/heads/master@{#8589} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8589 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../codecs/isac/audio_encoder_isac_t_impl.h | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 7ac51b6e38..024efa1413 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -33,7 +33,8 @@ AudioEncoderDecoderIsacT::Config::Config() frame_size_ms(30), bit_rate(kDefaultBitRate), max_bit_rate(-1), - max_payload_size_bytes(-1) { + max_payload_size_bytes(-1), + use_red(false) { } template @@ -42,6 +43,8 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { return false; if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) return false; + if (use_red && red_payload_type == kInvalidPayloadType) + return false; switch (sample_rate_hz) { case 16000: if (max_bit_rate > 53400) @@ -73,7 +76,8 @@ AudioEncoderDecoderIsacT::ConfigAdaptive::ConfigAdaptive() initial_bit_rate(kDefaultBitRate), max_bit_rate(-1), enforce_frame_size(false), - max_payload_size_bytes(-1) { + max_payload_size_bytes(-1), + use_red(false) { } template @@ -82,6 +86,8 @@ bool AudioEncoderDecoderIsacT::ConfigAdaptive::IsOk() const { return false; if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) return false; + if (use_red && red_payload_type == kInvalidPayloadType) + return false; switch (sample_rate_hz) { case 16000: if (max_bit_rate > 53400) @@ -108,10 +114,13 @@ template AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) : payload_type_(config.payload_type), red_payload_type_(config.red_payload_type), + use_red_(config.use_red), state_lock_(CriticalSectionWrapper::CreateCriticalSection()), decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), packet_in_progress_(false), + redundant_payload_( + use_red_ ? new uint8_t[kSufficientEncodeBufferSizeBytes] : nullptr), redundant_length_bytes_(0) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); @@ -136,10 +145,13 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT( const ConfigAdaptive& config) : payload_type_(config.payload_type), red_payload_type_(config.red_payload_type), + use_red_(config.use_red), state_lock_(CriticalSectionWrapper::CreateCriticalSection()), decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), packet_in_progress_(false), + redundant_payload_( + use_red_ ? new uint8_t[kSufficientEncodeBufferSizeBytes] : nullptr), redundant_length_bytes_(0) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); @@ -218,7 +230,7 @@ void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, info->encoded_timestamp = packet_timestamp_; info->payload_type = payload_type_; - if (!T::has_redundant_encoder) + if (!use_red_) return; if (redundant_length_bytes_ == 0) { @@ -229,7 +241,7 @@ void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, // resulting payload consists of the primary encoding followed by the // redundant encoding from last time. const size_t primary_length = info->encoded_bytes; - memcpy(&encoded[primary_length], redundant_payload_, + memcpy(&encoded[primary_length], redundant_payload_.get(), redundant_length_bytes_); // The EncodedInfo struct |info| will have one root node and two leaves. // |info| will be implicitly cast to an EncodedInfoLeaf struct, effectively @@ -251,9 +263,9 @@ void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, { CriticalSectionScoped cs(state_lock_.get()); // Call the encoder's method to get redundant encoding. - redundant_length_bytes_ = T::GetRedPayload(isac_state_, redundant_payload_); + redundant_length_bytes_ = + T::GetRedPayload(isac_state_, redundant_payload_.get()); } - DCHECK_LE(redundant_length_bytes_, sizeof(redundant_payload_)); DCHECK_GE(redundant_length_bytes_, 0u); last_encoded_timestamp_ = packet_timestamp_; } -- cgit v1.2.3 From 51ccf376387266225cd8c78e63238b725860f0af Mon Sep 17 00:00:00 2001 From: "jmarusic@webrtc.org" Date: Tue, 10 Mar 2015 15:41:26 +0000 Subject: AudioEncoder: add method MaxEncodedBytes Added method AudioEncoder::MaxEncodedBytes() and provided implementations in derived encoders. This method returns the number of bytes that can be produced by the encoder at each Encode() call. Unit tests were updated to use the new method. Buffer allocation was not changed in AudioCodingModuleImpl::Encode(). It will be done after additional investigation. Other refactoring work that was done, that may not be obvious why: 1. Moved some code into AudioEncoderCng::EncodePassive() to make it more consistent with EncodeActive(). 2. Changed the order of NumChannels() and RtpTimestampRateHz() declarations in AudioEncoderG722 and AudioEncoderCopyRed classes. It just bothered me that the order was not the same as in AudioEncoder class and its other derived classes. R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/40259005 Cr-Commit-Position: refs/heads/master@{#8671} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8671 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 024efa1413..b9c3e98e8e 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -184,6 +184,11 @@ int AudioEncoderDecoderIsacT::NumChannels() const { return 1; } +template +size_t AudioEncoderDecoderIsacT::MaxEncodedBytes() const { + return kSufficientEncodeBufferSizeBytes; +} + template int AudioEncoderDecoderIsacT::Num10MsFramesInNextPacket() const { CriticalSectionScoped cs(state_lock_.get()); -- cgit v1.2.3 From 0c5b137e7eca6afcc1737ed66fad4302f43dad92 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Fri, 13 Mar 2015 08:27:57 +0000 Subject: Remove support for iSAC RCU The current way that iSAC RCU is packetized and sent as a RED packet, with the same payload type for primary and redundant payloads, does not follow the specification for RED. As it is now, it is impossible for a receiver to know if an incoming RED packet with iSAC payloads inside consists of two "primary" (but time-shifted) payloads, or one primary and one RCU payload. The RED standard stipulates that the former option is the correct interpretation, while our implementation currently applies the latter. This CL removes support for iSAC RCU from Audio Coding Module, but leaves it in the iSAC codec itself (i.e., in the C implementation). BUG=4402 COAUTHOR=kwiberg@webrtc.org R=tina.legrand@webrtc.org Review URL: https://webrtc-codereview.appspot.com/45569004 Cr-Commit-Position: refs/heads/master@{#8713} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8713 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../codecs/isac/audio_encoder_isac_t_impl.h | 81 ++-------------------- 1 file changed, 4 insertions(+), 77 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index b9c3e98e8e..a1ffa809ba 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -22,19 +22,16 @@ namespace webrtc { const int kIsacPayloadType = 103; -const int kInvalidPayloadType = -1; const int kDefaultBitRate = 32000; template AudioEncoderDecoderIsacT::Config::Config() : payload_type(kIsacPayloadType), - red_payload_type(kInvalidPayloadType), sample_rate_hz(16000), frame_size_ms(30), bit_rate(kDefaultBitRate), max_bit_rate(-1), - max_payload_size_bytes(-1), - use_red(false) { + max_payload_size_bytes(-1) { } template @@ -43,8 +40,6 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { return false; if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) return false; - if (use_red && red_payload_type == kInvalidPayloadType) - return false; switch (sample_rate_hz) { case 16000: if (max_bit_rate > 53400) @@ -70,14 +65,12 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { template AudioEncoderDecoderIsacT::ConfigAdaptive::ConfigAdaptive() : payload_type(kIsacPayloadType), - red_payload_type(kInvalidPayloadType), sample_rate_hz(16000), initial_frame_size_ms(30), initial_bit_rate(kDefaultBitRate), max_bit_rate(-1), enforce_frame_size(false), - max_payload_size_bytes(-1), - use_red(false) { + max_payload_size_bytes(-1) { } template @@ -86,8 +79,6 @@ bool AudioEncoderDecoderIsacT::ConfigAdaptive::IsOk() const { return false; if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) return false; - if (use_red && red_payload_type == kInvalidPayloadType) - return false; switch (sample_rate_hz) { case 16000: if (max_bit_rate > 53400) @@ -113,15 +104,10 @@ bool AudioEncoderDecoderIsacT::ConfigAdaptive::IsOk() const { template AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) : payload_type_(config.payload_type), - red_payload_type_(config.red_payload_type), - use_red_(config.use_red), state_lock_(CriticalSectionWrapper::CreateCriticalSection()), decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), - packet_in_progress_(false), - redundant_payload_( - use_red_ ? new uint8_t[kSufficientEncodeBufferSizeBytes] : nullptr), - redundant_length_bytes_(0) { + packet_in_progress_(false) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); CHECK_EQ(0, T::EncoderInit(isac_state_, 1)); @@ -144,15 +130,10 @@ template AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT( const ConfigAdaptive& config) : payload_type_(config.payload_type), - red_payload_type_(config.red_payload_type), - use_red_(config.use_red), state_lock_(CriticalSectionWrapper::CreateCriticalSection()), decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), - packet_in_progress_(false), - redundant_payload_( - use_red_ ? new uint8_t[kSufficientEncodeBufferSizeBytes] : nullptr), - redundant_length_bytes_(0) { + packet_in_progress_(false) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); CHECK_EQ(0, T::EncoderInit(isac_state_, 0)); @@ -234,45 +215,6 @@ void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, packet_in_progress_ = false; info->encoded_timestamp = packet_timestamp_; info->payload_type = payload_type_; - - if (!use_red_) - return; - - if (redundant_length_bytes_ == 0) { - // Do not emit the first output frame when using redundant encoding. - info->encoded_bytes = 0; - } else { - // When a redundant payload from the last Encode call is available, the - // resulting payload consists of the primary encoding followed by the - // redundant encoding from last time. - const size_t primary_length = info->encoded_bytes; - memcpy(&encoded[primary_length], redundant_payload_.get(), - redundant_length_bytes_); - // The EncodedInfo struct |info| will have one root node and two leaves. - // |info| will be implicitly cast to an EncodedInfoLeaf struct, effectively - // discarding the (empty) vector of redundant information. This is - // intentional. - info->redundant.push_back(*info); - EncodedInfoLeaf secondary_info; - secondary_info.payload_type = info->payload_type; - secondary_info.encoded_bytes = redundant_length_bytes_; - secondary_info.encoded_timestamp = last_encoded_timestamp_; - info->redundant.push_back(secondary_info); - info->encoded_bytes += - redundant_length_bytes_; // Sum of primary and secondary. - DCHECK_NE(red_payload_type_, kInvalidPayloadType) - << "Config.red_payload_type must be set for " - "AudioEncoderDecoderIsacRed."; - info->payload_type = red_payload_type_; - } - { - CriticalSectionScoped cs(state_lock_.get()); - // Call the encoder's method to get redundant encoding. - redundant_length_bytes_ = - T::GetRedPayload(isac_state_, redundant_payload_.get()); - } - DCHECK_GE(redundant_length_bytes_, 0u); - last_encoded_timestamp_ = packet_timestamp_; } template @@ -296,21 +238,6 @@ int AudioEncoderDecoderIsacT::Decode(const uint8_t* encoded, return ret; } -template -int AudioEncoderDecoderIsacT::DecodeRedundant(const uint8_t* encoded, - size_t encoded_len, - int /*sample_rate_hz*/, - int16_t* decoded, - SpeechType* speech_type) { - CriticalSectionScoped cs(state_lock_.get()); - int16_t temp_type = 1; // Default is speech. - int16_t ret = - T::DecodeRcu(isac_state_, encoded, static_cast(encoded_len), - decoded, &temp_type); - *speech_type = ConvertSpeechType(temp_type); - return ret; -} - template bool AudioEncoderDecoderIsacT::HasDecodePlc() const { return true; -- cgit v1.2.3 From 7f7d7e3427cc70e1b8b050283ef031e28c83699a Mon Sep 17 00:00:00 2001 From: "minyue@webrtc.org" Date: Mon, 16 Mar 2015 12:30:37 +0000 Subject: Prevent crash in NetEQ when decoder overflow. NetEQ can crash when decoder gives too many output samples than it can handle. A practical case this happens is when multiple opus packets are combined. The best solution is to pass the max size to the ACM decode function and let it return a failure if the max size if too small. BUG=4361 R=henrik.lundin@webrtc.org Review URL: https://webrtc-codereview.appspot.com/45619004 Cr-Commit-Position: refs/heads/master@{#8730} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8730 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index a1ffa809ba..87d71ab384 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -218,11 +218,11 @@ void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, } template -int AudioEncoderDecoderIsacT::Decode(const uint8_t* encoded, - size_t encoded_len, - int sample_rate_hz, - int16_t* decoded, - SpeechType* speech_type) { +int AudioEncoderDecoderIsacT::DecodeInternal(const uint8_t* encoded, + size_t encoded_len, + int sample_rate_hz, + int16_t* decoded, + SpeechType* speech_type) { CriticalSectionScoped cs(state_lock_.get()); CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000) << "Unsupported sample rate " << sample_rate_hz; @@ -232,8 +232,8 @@ int AudioEncoderDecoderIsacT::Decode(const uint8_t* encoded, } int16_t temp_type = 1; // Default is speech. int16_t ret = - T::Decode(isac_state_, encoded, static_cast(encoded_len), - decoded, &temp_type); + T::DecodeInternal(isac_state_, encoded, static_cast(encoded_len), + decoded, &temp_type); *speech_type = ConvertSpeechType(temp_type); return ret; } -- cgit v1.2.3 From 0cb612b43bc1ef42cde8cb3887dc48917d5a58dd Mon Sep 17 00:00:00 2001 From: "jmarusic@webrtc.org" Date: Tue, 17 Mar 2015 12:12:17 +0000 Subject: We changed Encode() and EncodeInternal() return type from bool to void in this issue: https://webrtc-codereview.appspot.com/38279004/ Now we don't have to pass EncodedInfo as output parameter, but can return it instead. This also adds the benefit of making clear that EncodeInternal() needs to fill in this info. R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/43839004 Cr-Commit-Position: refs/heads/master@{#8749} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8749 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../codecs/isac/audio_encoder_isac_t_impl.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 87d71ab384..02acfa6dd4 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -184,11 +184,11 @@ int AudioEncoderDecoderIsacT::Max10MsFramesInAPacket() const { } template -void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, - const int16_t* audio, - size_t max_encoded_bytes, - uint8_t* encoded, - EncodedInfo* info) { +AudioEncoder::EncodedInfo AudioEncoderDecoderIsacT::EncodeInternal( + uint32_t rtp_timestamp, + const int16_t* audio, + size_t max_encoded_bytes, + uint8_t* encoded) { CriticalSectionScoped cs_lock(lock_.get()); if (!packet_in_progress_) { // Starting a new packet; remember the timestamp for later. @@ -206,15 +206,17 @@ void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, // buffer. All we can do is check for an overrun after the fact. CHECK(static_cast(r) <= max_encoded_bytes); - info->encoded_bytes = r; if (r == 0) - return; + return kZeroEncodedBytes; // Got enough input to produce a packet. Return the saved timestamp from // the first chunk of input that went into the packet. packet_in_progress_ = false; - info->encoded_timestamp = packet_timestamp_; - info->payload_type = payload_type_; + EncodedInfo info; + info.encoded_bytes = r; + info.encoded_timestamp = packet_timestamp_; + info.payload_type = payload_type_; + return info; } template -- cgit v1.2.3 From 019955d77015fed0b2dcec0cc62a8bdd63e0481e Mon Sep 17 00:00:00 2001 From: "tommi@webrtc.org" Date: Wed, 18 Mar 2015 06:38:04 +0000 Subject: Revert 8749 "We changed Encode() and EncodeInternal() return typ..." The reason is that this cl adds a static initializer so we can't roll webrtc into Chromium. See audio_encoder.cc and 'sizes' regression here: http://build.chromium.org/p/chromium/builders/Linux%20x64/builds/186 > We changed Encode() and EncodeInternal() return type from bool to void in this issue: > https://webrtc-codereview.appspot.com/38279004/ > Now we don't have to pass EncodedInfo as output parameter, but can return it instead. This also adds the benefit of making clear that EncodeInternal() needs to fill in this info. > > R=kwiberg@webrtc.org > > Review URL: https://webrtc-codereview.appspot.com/43839004 TBR=jmarusic@webrtc.org Review URL: https://webrtc-codereview.appspot.com/49449004 Cr-Commit-Position: refs/heads/master@{#8772} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8772 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../codecs/isac/audio_encoder_isac_t_impl.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 02acfa6dd4..87d71ab384 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -184,11 +184,11 @@ int AudioEncoderDecoderIsacT::Max10MsFramesInAPacket() const { } template -AudioEncoder::EncodedInfo AudioEncoderDecoderIsacT::EncodeInternal( - uint32_t rtp_timestamp, - const int16_t* audio, - size_t max_encoded_bytes, - uint8_t* encoded) { +void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, + const int16_t* audio, + size_t max_encoded_bytes, + uint8_t* encoded, + EncodedInfo* info) { CriticalSectionScoped cs_lock(lock_.get()); if (!packet_in_progress_) { // Starting a new packet; remember the timestamp for later. @@ -206,17 +206,15 @@ AudioEncoder::EncodedInfo AudioEncoderDecoderIsacT::EncodeInternal( // buffer. All we can do is check for an overrun after the fact. CHECK(static_cast(r) <= max_encoded_bytes); + info->encoded_bytes = r; if (r == 0) - return kZeroEncodedBytes; + return; // Got enough input to produce a packet. Return the saved timestamp from // the first chunk of input that went into the packet. packet_in_progress_ = false; - EncodedInfo info; - info.encoded_bytes = r; - info.encoded_timestamp = packet_timestamp_; - info.payload_type = payload_type_; - return info; + info->encoded_timestamp = packet_timestamp_; + info->payload_type = payload_type_; } template -- cgit v1.2.3 From 9afaee74ab1ef36c8b4ea4c22f4c5aebf2359da2 Mon Sep 17 00:00:00 2001 From: "jmarusic@webrtc.org" Date: Thu, 19 Mar 2015 08:50:26 +0000 Subject: Reland 8749: AudioEncoder: return EncodedInfo from Encode() and EncodeInternal() Old review at: https://webrtc-codereview.appspot.com/43839004/ R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/45769004 Cr-Commit-Position: refs/heads/master@{#8788} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8788 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../codecs/isac/audio_encoder_isac_t_impl.h | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 87d71ab384..1bfb4168fa 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -184,11 +184,11 @@ int AudioEncoderDecoderIsacT::Max10MsFramesInAPacket() const { } template -void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, - const int16_t* audio, - size_t max_encoded_bytes, - uint8_t* encoded, - EncodedInfo* info) { +AudioEncoder::EncodedInfo AudioEncoderDecoderIsacT::EncodeInternal( + uint32_t rtp_timestamp, + const int16_t* audio, + size_t max_encoded_bytes, + uint8_t* encoded) { CriticalSectionScoped cs_lock(lock_.get()); if (!packet_in_progress_) { // Starting a new packet; remember the timestamp for later. @@ -206,15 +206,17 @@ void AudioEncoderDecoderIsacT::EncodeInternal(uint32_t rtp_timestamp, // buffer. All we can do is check for an overrun after the fact. CHECK(static_cast(r) <= max_encoded_bytes); - info->encoded_bytes = r; if (r == 0) - return; + return EncodedInfo(); // Got enough input to produce a packet. Return the saved timestamp from // the first chunk of input that went into the packet. packet_in_progress_ = false; - info->encoded_timestamp = packet_timestamp_; - info->payload_type = payload_type_; + EncodedInfo info; + info.encoded_bytes = r; + info.encoded_timestamp = packet_timestamp_; + info.payload_type = payload_type_; + return info; } template -- cgit v1.2.3 From 09b6ff9460872bb8e652194a2e9dce1674e5f299 Mon Sep 17 00:00:00 2001 From: "henrik.lundin@webrtc.org" Date: Mon, 23 Mar 2015 12:23:51 +0000 Subject: Disable PLC for iSAC A codec's packet-loss concealer is called once from NetEq before decoding the first packet after a packet loss. The purpose is not to use the PLC output, but to prepare the state of the decoder such that it may recover faster after the loss. However, this effect is not achieved by calling iSAC's PLC. Also, there are some problems with the fixed-point implementation of the PLC (see the associated bug). BUG=4423 R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/42849004 Cr-Commit-Position: refs/heads/master@{#8827} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8827 4adac7df-926f-26a2-2b94-8c16560cd09d --- webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 1bfb4168fa..db30444203 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -242,7 +242,7 @@ int AudioEncoderDecoderIsacT::DecodeInternal(const uint8_t* encoded, template bool AudioEncoderDecoderIsacT::HasDecodePlc() const { - return true; + return false; } template -- cgit v1.2.3 From 582f80e95c87c7763b29dd4c9c68edca12f843b0 Mon Sep 17 00:00:00 2001 From: Henrik Lundin Date: Mon, 30 Mar 2015 15:01:40 +0200 Subject: Clamp decoder sample rate to 32000 in iSAC We want to crate the illusion that iSAC supports 48000 Hz decoding, while in fact it outputs 32000 Hz. This is the iSAC fullband mode. Currently this is (also) handled by higher layers, but in future changes this will not be the case. R=tina.legrand@webrtc.org Review URL: https://webrtc-codereview.appspot.com/47809004 Cr-Commit-Position: refs/heads/master@{#8889} --- webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index db30444203..e81686a96c 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -226,6 +226,10 @@ int AudioEncoderDecoderIsacT::DecodeInternal(const uint8_t* encoded, int16_t* decoded, SpeechType* speech_type) { CriticalSectionScoped cs(state_lock_.get()); + // We want to crate the illusion that iSAC supports 48000 Hz decoding, while + // in fact it outputs 32000 Hz. This is the iSAC fullband mode. + if (sample_rate_hz == 48000) + sample_rate_hz = 32000; CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000) << "Unsupported sample rate " << sample_rate_hz; if (sample_rate_hz != decoder_sample_rate_hz_) { -- cgit v1.2.3 From 7c324cac50ac38122b3f3b26455bc55ad834bfc0 Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Thu, 16 Apr 2015 06:00:22 +0200 Subject: AudioEncoderDecoderIsac: Merge the two config structs This patch merges the Config and ConfigAdaptive structs, so that iSAC has just one config struct like the other codecs. Future CLs will make use of this. COAUTHOR=henrik.lundin@webrtc.org BUG=4228 R=tina.legrand@webrtc.org Review URL: https://webrtc-codereview.appspot.com/45979004 Cr-Commit-Position: refs/heads/master@{#9015} --- .../codecs/isac/audio_encoder_isac_t_impl.h | 87 ++++------------------ 1 file changed, 15 insertions(+), 72 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index e81686a96c..186d31811f 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -22,16 +22,17 @@ namespace webrtc { const int kIsacPayloadType = 103; -const int kDefaultBitRate = 32000; template AudioEncoderDecoderIsacT::Config::Config() : payload_type(kIsacPayloadType), sample_rate_hz(16000), frame_size_ms(30), - bit_rate(kDefaultBitRate), + bit_rate(32000), + max_payload_size_bytes(-1), max_bit_rate(-1), - max_payload_size_bytes(-1) { + adaptive_mode(false), + enforce_frame_size(false) { } template @@ -47,7 +48,7 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { if (max_payload_size_bytes > 400) return false; return (frame_size_ms == 30 || frame_size_ms == 60) && - ((bit_rate >= 10000 && bit_rate <= 32000) || bit_rate == 0); + (bit_rate >= 10000 && bit_rate <= 32000); case 32000: case 48000: if (max_bit_rate > 160000) @@ -55,47 +56,7 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { if (max_payload_size_bytes > 600) return false; return T::has_swb && - (frame_size_ms == 30 && - ((bit_rate >= 10000 && bit_rate <= 56000) || bit_rate == 0)); - default: - return false; - } -} - -template -AudioEncoderDecoderIsacT::ConfigAdaptive::ConfigAdaptive() - : payload_type(kIsacPayloadType), - sample_rate_hz(16000), - initial_frame_size_ms(30), - initial_bit_rate(kDefaultBitRate), - max_bit_rate(-1), - enforce_frame_size(false), - max_payload_size_bytes(-1) { -} - -template -bool AudioEncoderDecoderIsacT::ConfigAdaptive::IsOk() const { - if (max_bit_rate < 32000 && max_bit_rate != -1) - return false; - if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) - return false; - switch (sample_rate_hz) { - case 16000: - if (max_bit_rate > 53400) - return false; - if (max_payload_size_bytes > 400) - return false; - return (initial_frame_size_ms == 30 || initial_frame_size_ms == 60) && - initial_bit_rate >= 10000 && initial_bit_rate <= 32000; - case 32000: - case 48000: - if (max_bit_rate > 160000) - return false; - if (max_payload_size_bytes > 600) - return false; - return T::has_swb && - (initial_frame_size_ms == 30 && initial_bit_rate >= 10000 && - initial_bit_rate <= 56000); + (frame_size_ms == 30 && bit_rate >= 10000 && bit_rate <= 56000); default: return false; } @@ -110,11 +71,15 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) packet_in_progress_(false) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); - CHECK_EQ(0, T::EncoderInit(isac_state_, 1)); + CHECK_EQ(0, T::EncoderInit(isac_state_, config.adaptive_mode ? 0 : 1)); CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); - CHECK_EQ(0, T::Control(isac_state_, config.bit_rate == 0 ? kDefaultBitRate - : config.bit_rate, - config.frame_size_ms)); + if (config.adaptive_mode) { + CHECK_EQ(0, T::ControlBwe(isac_state_, config.bit_rate, + config.frame_size_ms, config.enforce_frame_size)); + + } else { + CHECK_EQ(0, T::Control(isac_state_, config.bit_rate, config.frame_size_ms)); + } // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is // still set to 32000 Hz, since there is no full-band mode in the decoder. CHECK_EQ(0, T::SetDecSampRate(isac_state_, @@ -124,29 +89,7 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); if (config.max_bit_rate != -1) CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate)); -} - -template -AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT( - const ConfigAdaptive& config) - : payload_type_(config.payload_type), - state_lock_(CriticalSectionWrapper::CreateCriticalSection()), - decoder_sample_rate_hz_(0), - lock_(CriticalSectionWrapper::CreateCriticalSection()), - packet_in_progress_(false) { - CHECK(config.IsOk()); - CHECK_EQ(0, T::Create(&isac_state_)); - CHECK_EQ(0, T::EncoderInit(isac_state_, 0)); - CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); - CHECK_EQ(0, T::ControlBwe(isac_state_, config.initial_bit_rate, - config.initial_frame_size_ms, - config.enforce_frame_size)); - CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); - if (config.max_payload_size_bytes != -1) - CHECK_EQ(0, - T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); - if (config.max_bit_rate != -1) - CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate)); + CHECK_EQ(0, T::DecoderInit(isac_state_)); } template -- cgit v1.2.3 From 599beb86871dacf9e7e714366c073940c591ef25 Mon Sep 17 00:00:00 2001 From: Ted Nakamura Date: Fri, 17 Apr 2015 14:14:07 -0700 Subject: Revert "AudioEncoderDecoderIsac: Merge the two config structs" Reason for revert - breaks Hangouts This reverts commit 7c324cac50ac38122b3f3b26455bc55ad834bfc0. BUG=chromium:478161 Review URL: https://webrtc-codereview.appspot.com/43209004 Cr-Commit-Position: refs/heads/master@{#9030} --- .../codecs/isac/audio_encoder_isac_t_impl.h | 87 ++++++++++++++++++---- 1 file changed, 72 insertions(+), 15 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 186d31811f..e81686a96c 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -22,17 +22,16 @@ namespace webrtc { const int kIsacPayloadType = 103; +const int kDefaultBitRate = 32000; template AudioEncoderDecoderIsacT::Config::Config() : payload_type(kIsacPayloadType), sample_rate_hz(16000), frame_size_ms(30), - bit_rate(32000), - max_payload_size_bytes(-1), + bit_rate(kDefaultBitRate), max_bit_rate(-1), - adaptive_mode(false), - enforce_frame_size(false) { + max_payload_size_bytes(-1) { } template @@ -48,7 +47,7 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { if (max_payload_size_bytes > 400) return false; return (frame_size_ms == 30 || frame_size_ms == 60) && - (bit_rate >= 10000 && bit_rate <= 32000); + ((bit_rate >= 10000 && bit_rate <= 32000) || bit_rate == 0); case 32000: case 48000: if (max_bit_rate > 160000) @@ -56,7 +55,47 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { if (max_payload_size_bytes > 600) return false; return T::has_swb && - (frame_size_ms == 30 && bit_rate >= 10000 && bit_rate <= 56000); + (frame_size_ms == 30 && + ((bit_rate >= 10000 && bit_rate <= 56000) || bit_rate == 0)); + default: + return false; + } +} + +template +AudioEncoderDecoderIsacT::ConfigAdaptive::ConfigAdaptive() + : payload_type(kIsacPayloadType), + sample_rate_hz(16000), + initial_frame_size_ms(30), + initial_bit_rate(kDefaultBitRate), + max_bit_rate(-1), + enforce_frame_size(false), + max_payload_size_bytes(-1) { +} + +template +bool AudioEncoderDecoderIsacT::ConfigAdaptive::IsOk() const { + if (max_bit_rate < 32000 && max_bit_rate != -1) + return false; + if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) + return false; + switch (sample_rate_hz) { + case 16000: + if (max_bit_rate > 53400) + return false; + if (max_payload_size_bytes > 400) + return false; + return (initial_frame_size_ms == 30 || initial_frame_size_ms == 60) && + initial_bit_rate >= 10000 && initial_bit_rate <= 32000; + case 32000: + case 48000: + if (max_bit_rate > 160000) + return false; + if (max_payload_size_bytes > 600) + return false; + return T::has_swb && + (initial_frame_size_ms == 30 && initial_bit_rate >= 10000 && + initial_bit_rate <= 56000); default: return false; } @@ -71,15 +110,11 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) packet_in_progress_(false) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); - CHECK_EQ(0, T::EncoderInit(isac_state_, config.adaptive_mode ? 0 : 1)); + CHECK_EQ(0, T::EncoderInit(isac_state_, 1)); CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); - if (config.adaptive_mode) { - CHECK_EQ(0, T::ControlBwe(isac_state_, config.bit_rate, - config.frame_size_ms, config.enforce_frame_size)); - - } else { - CHECK_EQ(0, T::Control(isac_state_, config.bit_rate, config.frame_size_ms)); - } + CHECK_EQ(0, T::Control(isac_state_, config.bit_rate == 0 ? kDefaultBitRate + : config.bit_rate, + config.frame_size_ms)); // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is // still set to 32000 Hz, since there is no full-band mode in the decoder. CHECK_EQ(0, T::SetDecSampRate(isac_state_, @@ -89,7 +124,29 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); if (config.max_bit_rate != -1) CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate)); - CHECK_EQ(0, T::DecoderInit(isac_state_)); +} + +template +AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT( + const ConfigAdaptive& config) + : payload_type_(config.payload_type), + state_lock_(CriticalSectionWrapper::CreateCriticalSection()), + decoder_sample_rate_hz_(0), + lock_(CriticalSectionWrapper::CreateCriticalSection()), + packet_in_progress_(false) { + CHECK(config.IsOk()); + CHECK_EQ(0, T::Create(&isac_state_)); + CHECK_EQ(0, T::EncoderInit(isac_state_, 0)); + CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); + CHECK_EQ(0, T::ControlBwe(isac_state_, config.initial_bit_rate, + config.initial_frame_size_ms, + config.enforce_frame_size)); + CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); + if (config.max_payload_size_bytes != -1) + CHECK_EQ(0, + T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); + if (config.max_bit_rate != -1) + CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate)); } template -- cgit v1.2.3 From d3e8eda8398640fac1b51f6f986f4fbb3fb5dd21 Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Thu, 23 Apr 2015 14:07:06 +0200 Subject: (Re-land) AudioEncoderDecoderIsac: Merge the two config structs This reverts commit 599beb86, which in turn reverted 7c324cac. What makes it work this time is that we don't remove the option of setting bit_rate to 0 in order to ask for the default value. COAUTHOR=henrik.lundin@webrtc.org BUG=4228, chromium:478161 R=henrik.lundin@webrtc.org Review URL: https://webrtc-codereview.appspot.com/48199004 Cr-Commit-Position: refs/heads/master@{#9068} --- .../codecs/isac/audio_encoder_isac_t_impl.h | 84 ++++------------------ 1 file changed, 15 insertions(+), 69 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index e81686a96c..c5982f5be6 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -30,8 +30,10 @@ AudioEncoderDecoderIsacT::Config::Config() sample_rate_hz(16000), frame_size_ms(30), bit_rate(kDefaultBitRate), + max_payload_size_bytes(-1), max_bit_rate(-1), - max_payload_size_bytes(-1) { + adaptive_mode(false), + enforce_frame_size(false) { } template @@ -47,7 +49,7 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { if (max_payload_size_bytes > 400) return false; return (frame_size_ms == 30 || frame_size_ms == 60) && - ((bit_rate >= 10000 && bit_rate <= 32000) || bit_rate == 0); + (bit_rate == 0 || (bit_rate >= 10000 && bit_rate <= 32000)); case 32000: case 48000: if (max_bit_rate > 160000) @@ -56,46 +58,7 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { return false; return T::has_swb && (frame_size_ms == 30 && - ((bit_rate >= 10000 && bit_rate <= 56000) || bit_rate == 0)); - default: - return false; - } -} - -template -AudioEncoderDecoderIsacT::ConfigAdaptive::ConfigAdaptive() - : payload_type(kIsacPayloadType), - sample_rate_hz(16000), - initial_frame_size_ms(30), - initial_bit_rate(kDefaultBitRate), - max_bit_rate(-1), - enforce_frame_size(false), - max_payload_size_bytes(-1) { -} - -template -bool AudioEncoderDecoderIsacT::ConfigAdaptive::IsOk() const { - if (max_bit_rate < 32000 && max_bit_rate != -1) - return false; - if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) - return false; - switch (sample_rate_hz) { - case 16000: - if (max_bit_rate > 53400) - return false; - if (max_payload_size_bytes > 400) - return false; - return (initial_frame_size_ms == 30 || initial_frame_size_ms == 60) && - initial_bit_rate >= 10000 && initial_bit_rate <= 32000; - case 32000: - case 48000: - if (max_bit_rate > 160000) - return false; - if (max_payload_size_bytes > 600) - return false; - return T::has_swb && - (initial_frame_size_ms == 30 && initial_bit_rate >= 10000 && - initial_bit_rate <= 56000); + (bit_rate == 0 || (bit_rate >= 10000 && bit_rate <= 56000))); default: return false; } @@ -110,11 +73,16 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) packet_in_progress_(false) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); - CHECK_EQ(0, T::EncoderInit(isac_state_, 1)); + CHECK_EQ(0, T::EncoderInit(isac_state_, config.adaptive_mode ? 0 : 1)); CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); - CHECK_EQ(0, T::Control(isac_state_, config.bit_rate == 0 ? kDefaultBitRate - : config.bit_rate, - config.frame_size_ms)); + const int bit_rate = config.bit_rate == 0 ? kDefaultBitRate : config.bit_rate; + if (config.adaptive_mode) { + CHECK_EQ(0, T::ControlBwe(isac_state_, bit_rate, + config.frame_size_ms, config.enforce_frame_size)); + + } else { + CHECK_EQ(0, T::Control(isac_state_, bit_rate, config.frame_size_ms)); + } // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is // still set to 32000 Hz, since there is no full-band mode in the decoder. CHECK_EQ(0, T::SetDecSampRate(isac_state_, @@ -124,29 +92,7 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); if (config.max_bit_rate != -1) CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate)); -} - -template -AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT( - const ConfigAdaptive& config) - : payload_type_(config.payload_type), - state_lock_(CriticalSectionWrapper::CreateCriticalSection()), - decoder_sample_rate_hz_(0), - lock_(CriticalSectionWrapper::CreateCriticalSection()), - packet_in_progress_(false) { - CHECK(config.IsOk()); - CHECK_EQ(0, T::Create(&isac_state_)); - CHECK_EQ(0, T::EncoderInit(isac_state_, 0)); - CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); - CHECK_EQ(0, T::ControlBwe(isac_state_, config.initial_bit_rate, - config.initial_frame_size_ms, - config.enforce_frame_size)); - CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); - if (config.max_payload_size_bytes != -1) - CHECK_EQ(0, - T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); - if (config.max_bit_rate != -1) - CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate)); + CHECK_EQ(0, T::DecoderInit(isac_state_)); } template -- cgit v1.2.3 From 88de4792d0555567d877998e4fc71b4ec44a3d0d Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Tue, 28 Apr 2015 14:58:43 +0200 Subject: AudioEncoderIsac: Print error code if CHECK for successful encoding fails This will hopefully make the crash in bug 4577 easier to understand if it happens again. BUG=4577 R=henrik.lundin@webrtc.org Review URL: https://webrtc-codereview.appspot.com/52389004 Cr-Commit-Position: refs/heads/master@{#9100} --- webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index c5982f5be6..65c5b90300 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -145,8 +145,9 @@ AudioEncoder::EncodedInfo AudioEncoderDecoderIsacT::EncodeInternal( { CriticalSectionScoped cs(state_lock_.get()); r = T::Encode(isac_state_, audio, encoded); + CHECK_GE(r, 0) << "Encode failed (error code " + << T::GetErrorCode(isac_state_) << ")"; } - CHECK_GE(r, 0); // T::Encode doesn't allow us to tell it the size of the output // buffer. All we can do is check for an overrun after the fact. -- cgit v1.2.3 From 83ad33a8aed1fb00e422b6abd33c3e8942821c24 Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Tue, 9 Jun 2015 17:19:57 -0700 Subject: 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 R=andrew@webrtc.org, kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/54629004 Cr-Commit-Position: refs/heads/master@{#9405} --- webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 65c5b90300..befb3558be 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -184,7 +184,7 @@ int AudioEncoderDecoderIsacT::DecodeInternal(const uint8_t* encoded, decoder_sample_rate_hz_ = sample_rate_hz; } int16_t temp_type = 1; // Default is speech. - int16_t ret = + int ret = T::DecodeInternal(isac_state_, encoded, static_cast(encoded_len), decoded, &temp_type); *speech_type = ConvertSpeechType(temp_type); -- cgit v1.2.3 From cb180976dd0e9672cde4523d87b5f4857478b5e9 Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Thu, 11 Jun 2015 12:42:27 -0700 Subject: Revert "Upconvert various types to int." This reverts commit 83ad33a8aed1fb00e422b6abd33c3e8942821c24. BUG=499241 TBR=hlundin Review URL: https://codereview.webrtc.org/1179953003 Cr-Commit-Position: refs/heads/master@{#9418} --- webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index befb3558be..65c5b90300 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -184,7 +184,7 @@ int AudioEncoderDecoderIsacT::DecodeInternal(const uint8_t* encoded, decoder_sample_rate_hz_ = sample_rate_hz; } int16_t temp_type = 1; // Default is speech. - int ret = + int16_t ret = T::DecodeInternal(isac_state_, encoded, static_cast(encoded_len), decoded, &temp_type); *speech_type = ConvertSpeechType(temp_type); -- cgit v1.2.3 From aba07ef6d92bf1ded7ad1af49b54a8e6652dfcbb Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Thu, 11 Jun 2015 18:19:24 -0700 Subject: Reland "Upconvert various types to int.", isac portion. This reverts portions of commit cb180976dd0e9672cde4523d87b5f4857478b5e9, which reverted commit 83ad33a8aed1fb00e422b6abd33c3e8942821c24. Specifically, the files in webrtc/modules/audio_coding/codecs/isac/ 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/1179093002 Cr-Commit-Position: refs/heads/master@{#9422} --- webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 65c5b90300..befb3558be 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -184,7 +184,7 @@ int AudioEncoderDecoderIsacT::DecodeInternal(const uint8_t* encoded, decoder_sample_rate_hz_ = sample_rate_hz; } int16_t temp_type = 1; // Default is speech. - int16_t ret = + int ret = T::DecodeInternal(isac_state_, encoded, static_cast(encoded_len), decoded, &temp_type); *speech_type = ConvertSpeechType(temp_type); -- cgit v1.2.3 From 3e89dbf45835896c8fd89f235f396d03bc2e6065 Mon Sep 17 00:00:00 2001 From: Henrik Lundin Date: Thu, 18 Jun 2015 14:58:34 +0200 Subject: Add AudioEncoder::GetTargetBitrate The GetTargetBitrate implementation will return the target bitrate of the codec. This may differ from the desired target bitrate, as set by SetTargetBitrate, depending on implementation. Tests are updated to exercise the new functionality. R=kwiberg@webrtc.org Review URL: https://codereview.webrtc.org/1184313002. Cr-Commit-Position: refs/heads/master@{#9461} --- .../audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index befb3558be..d2b20e3b94 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -70,16 +70,18 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) state_lock_(CriticalSectionWrapper::CreateCriticalSection()), decoder_sample_rate_hz_(0), lock_(CriticalSectionWrapper::CreateCriticalSection()), - packet_in_progress_(false) { + packet_in_progress_(false), + target_bitrate_bps_(config.adaptive_mode ? -1 : (config.bit_rate == 0 + ? kDefaultBitRate + : config.bit_rate)) { CHECK(config.IsOk()); CHECK_EQ(0, T::Create(&isac_state_)); CHECK_EQ(0, T::EncoderInit(isac_state_, config.adaptive_mode ? 0 : 1)); CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); const int bit_rate = config.bit_rate == 0 ? kDefaultBitRate : config.bit_rate; if (config.adaptive_mode) { - CHECK_EQ(0, T::ControlBwe(isac_state_, bit_rate, - config.frame_size_ms, config.enforce_frame_size)); - + CHECK_EQ(0, T::ControlBwe(isac_state_, bit_rate, config.frame_size_ms, + config.enforce_frame_size)); } else { CHECK_EQ(0, T::Control(isac_state_, bit_rate, config.frame_size_ms)); } @@ -129,6 +131,11 @@ int AudioEncoderDecoderIsacT::Max10MsFramesInAPacket() const { return 6; // iSAC puts at most 60 ms in a packet. } +template +int AudioEncoderDecoderIsacT::GetTargetBitrate() const { + return target_bitrate_bps_; +} + template AudioEncoder::EncodedInfo AudioEncoderDecoderIsacT::EncodeInternal( uint32_t rtp_timestamp, -- cgit v1.2.3 From 608c3cfe77c165965ea04fcd0a2a71aad05a1d16 Mon Sep 17 00:00:00 2001 From: kwiberg Date: Mon, 24 Aug 2015 02:03:23 -0700 Subject: iSAC: Make separate AudioEncoder and AudioDecoder objects The only shared state is now the bandwidth estimation info. This reduces the amount and complexity of the locking substantially. Review URL: https://codereview.webrtc.org/1208993010 Cr-Commit-Position: refs/heads/master@{#9762} --- .../codecs/isac/audio_encoder_isac_t_impl.h | 132 +++++++++++++-------- 1 file changed, 81 insertions(+), 51 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index d2b20e3b94..ce70db455b 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -17,7 +17,6 @@ #include "webrtc/base/checks.h" #include "webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h" -#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" namespace webrtc { @@ -25,8 +24,9 @@ const int kIsacPayloadType = 103; const int kDefaultBitRate = 32000; template -AudioEncoderDecoderIsacT::Config::Config() - : payload_type(kIsacPayloadType), +AudioEncoderIsacT::Config::Config() + : bwinfo(nullptr), + payload_type(kIsacPayloadType), sample_rate_hz(16000), frame_size_ms(30), bit_rate(kDefaultBitRate), @@ -37,11 +37,13 @@ AudioEncoderDecoderIsacT::Config::Config() } template -bool AudioEncoderDecoderIsacT::Config::IsOk() const { +bool AudioEncoderIsacT::Config::IsOk() const { if (max_bit_rate < 32000 && max_bit_rate != -1) return false; if (max_payload_size_bytes < 120 && max_payload_size_bytes != -1) return false; + if (adaptive_mode && !bwinfo) + return false; switch (sample_rate_hz) { case 16000: if (max_bit_rate > 53400) @@ -65,11 +67,9 @@ bool AudioEncoderDecoderIsacT::Config::IsOk() const { } template -AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) +AudioEncoderIsacT::AudioEncoderIsacT(const Config& config) : payload_type_(config.payload_type), - state_lock_(CriticalSectionWrapper::CreateCriticalSection()), - decoder_sample_rate_hz_(0), - lock_(CriticalSectionWrapper::CreateCriticalSection()), + bwinfo_(config.bwinfo), packet_in_progress_(false), target_bitrate_bps_(config.adaptive_mode ? -1 : (config.bit_rate == 0 ? kDefaultBitRate @@ -85,80 +85,82 @@ AudioEncoderDecoderIsacT::AudioEncoderDecoderIsacT(const Config& config) } else { CHECK_EQ(0, T::Control(isac_state_, bit_rate, config.frame_size_ms)); } - // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is - // still set to 32000 Hz, since there is no full-band mode in the decoder. - CHECK_EQ(0, T::SetDecSampRate(isac_state_, - std::min(config.sample_rate_hz, 32000))); if (config.max_payload_size_bytes != -1) CHECK_EQ(0, T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); if (config.max_bit_rate != -1) CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate)); - CHECK_EQ(0, T::DecoderInit(isac_state_)); + + // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is + // still set to 32000 Hz, since there is no full-band mode in the decoder. + const int decoder_sample_rate_hz = std::min(config.sample_rate_hz, 32000); + + // Set the decoder sample rate even though we just use the encoder. This + // doesn't appear to be necessary to produce a valid encoding, but without it + // we get an encoding that isn't bit-for-bit identical with what a combined + // encoder+decoder object produces. + CHECK_EQ(0, T::SetDecSampRate(isac_state_, decoder_sample_rate_hz)); } template -AudioEncoderDecoderIsacT::~AudioEncoderDecoderIsacT() { +AudioEncoderIsacT::~AudioEncoderIsacT() { CHECK_EQ(0, T::Free(isac_state_)); } template -int AudioEncoderDecoderIsacT::SampleRateHz() const { - CriticalSectionScoped cs(state_lock_.get()); +int AudioEncoderIsacT::SampleRateHz() const { return T::EncSampRate(isac_state_); } template -int AudioEncoderDecoderIsacT::NumChannels() const { +int AudioEncoderIsacT::NumChannels() const { return 1; } template -size_t AudioEncoderDecoderIsacT::MaxEncodedBytes() const { +size_t AudioEncoderIsacT::MaxEncodedBytes() const { return kSufficientEncodeBufferSizeBytes; } template -int AudioEncoderDecoderIsacT::Num10MsFramesInNextPacket() const { - CriticalSectionScoped cs(state_lock_.get()); +int AudioEncoderIsacT::Num10MsFramesInNextPacket() const { const int samples_in_next_packet = T::GetNewFrameLen(isac_state_); return rtc::CheckedDivExact(samples_in_next_packet, rtc::CheckedDivExact(SampleRateHz(), 100)); } template -int AudioEncoderDecoderIsacT::Max10MsFramesInAPacket() const { +int AudioEncoderIsacT::Max10MsFramesInAPacket() const { return 6; // iSAC puts at most 60 ms in a packet. } template -int AudioEncoderDecoderIsacT::GetTargetBitrate() const { +int AudioEncoderIsacT::GetTargetBitrate() const { return target_bitrate_bps_; } template -AudioEncoder::EncodedInfo AudioEncoderDecoderIsacT::EncodeInternal( +AudioEncoder::EncodedInfo AudioEncoderIsacT::EncodeInternal( uint32_t rtp_timestamp, const int16_t* audio, size_t max_encoded_bytes, uint8_t* encoded) { - CriticalSectionScoped cs_lock(lock_.get()); if (!packet_in_progress_) { // Starting a new packet; remember the timestamp for later. packet_in_progress_ = true; packet_timestamp_ = rtp_timestamp; } - int r; - { - CriticalSectionScoped cs(state_lock_.get()); - r = T::Encode(isac_state_, audio, encoded); - CHECK_GE(r, 0) << "Encode failed (error code " - << T::GetErrorCode(isac_state_) << ")"; + if (bwinfo_) { + IsacBandwidthInfo bwinfo = bwinfo_->Get(); + T::SetBandwidthInfo(isac_state_, &bwinfo); } + int r = T::Encode(isac_state_, audio, encoded); + CHECK_GE(r, 0) << "Encode failed (error code " << T::GetErrorCode(isac_state_) + << ")"; // T::Encode doesn't allow us to tell it the size of the output // buffer. All we can do is check for an overrun after the fact. - CHECK(static_cast(r) <= max_encoded_bytes); + CHECK_LE(static_cast(r), max_encoded_bytes); if (r == 0) return EncodedInfo(); @@ -174,12 +176,33 @@ AudioEncoder::EncodedInfo AudioEncoderDecoderIsacT::EncodeInternal( } template -int AudioEncoderDecoderIsacT::DecodeInternal(const uint8_t* encoded, - size_t encoded_len, - int sample_rate_hz, - int16_t* decoded, - SpeechType* speech_type) { - CriticalSectionScoped cs(state_lock_.get()); +AudioDecoderIsacT::AudioDecoderIsacT() + : AudioDecoderIsacT(nullptr) { +} + +template +AudioDecoderIsacT::AudioDecoderIsacT(LockedIsacBandwidthInfo* bwinfo) + : bwinfo_(bwinfo), decoder_sample_rate_hz_(-1) { + CHECK_EQ(0, T::Create(&isac_state_)); + CHECK_EQ(0, T::DecoderInit(isac_state_)); + if (bwinfo_) { + IsacBandwidthInfo bwinfo; + T::GetBandwidthInfo(isac_state_, &bwinfo); + bwinfo_->Set(bwinfo); + } +} + +template +AudioDecoderIsacT::~AudioDecoderIsacT() { + CHECK_EQ(0, T::Free(isac_state_)); +} + +template +int AudioDecoderIsacT::DecodeInternal(const uint8_t* encoded, + size_t encoded_len, + int sample_rate_hz, + int16_t* decoded, + SpeechType* speech_type) { // We want to crate the illusion that iSAC supports 48000 Hz decoding, while // in fact it outputs 32000 Hz. This is the iSAC fullband mode. if (sample_rate_hz == 48000) @@ -199,40 +222,47 @@ int AudioEncoderDecoderIsacT::DecodeInternal(const uint8_t* encoded, } template -bool AudioEncoderDecoderIsacT::HasDecodePlc() const { +bool AudioDecoderIsacT::HasDecodePlc() const { return false; } template -int AudioEncoderDecoderIsacT::DecodePlc(int num_frames, int16_t* decoded) { - CriticalSectionScoped cs(state_lock_.get()); +int AudioDecoderIsacT::DecodePlc(int num_frames, int16_t* decoded) { return T::DecodePlc(isac_state_, decoded, num_frames); } template -int AudioEncoderDecoderIsacT::Init() { - CriticalSectionScoped cs(state_lock_.get()); +int AudioDecoderIsacT::Init() { return T::DecoderInit(isac_state_); } template -int AudioEncoderDecoderIsacT::IncomingPacket(const uint8_t* payload, - size_t payload_len, - uint16_t rtp_sequence_number, - uint32_t rtp_timestamp, - uint32_t arrival_timestamp) { - CriticalSectionScoped cs(state_lock_.get()); - return T::UpdateBwEstimate( +int AudioDecoderIsacT::IncomingPacket(const uint8_t* payload, + size_t payload_len, + uint16_t rtp_sequence_number, + uint32_t rtp_timestamp, + uint32_t arrival_timestamp) { + int ret = T::UpdateBwEstimate( isac_state_, payload, static_cast(payload_len), rtp_sequence_number, rtp_timestamp, arrival_timestamp); + if (bwinfo_) { + IsacBandwidthInfo bwinfo; + T::GetBandwidthInfo(isac_state_, &bwinfo); + bwinfo_->Set(bwinfo); + } + return ret; } template -int AudioEncoderDecoderIsacT::ErrorCode() { - CriticalSectionScoped cs(state_lock_.get()); +int AudioDecoderIsacT::ErrorCode() { return T::GetErrorCode(isac_state_); } +template +size_t AudioDecoderIsacT::Channels() const { + return 1; +} + } // namespace webrtc #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ -- cgit v1.2.3 From dce40cf804019a9898b6ab8d8262466b697c56e0 Mon Sep 17 00:00:00 2001 From: Peter Kasting Date: Mon, 24 Aug 2015 14:52:23 -0700 Subject: Update a ton of audio code to use size_t more correctly and in general reduce use of int16_t/uint16_t. This is the upshot of a recommendation by henrik.lundin and kwiberg on an original small change ( https://webrtc-codereview.appspot.com/42569004/#ps1 ) to stop using int16_t just because values could fit in it, and is similar in nature to a previous "mass change to use size_t more" ( https://webrtc-codereview.appspot.com/23129004/ ) which also needed to be split up for review but to land all at once, since, like adding "const", such changes tend to cause a lot of transitive effects. This was be reviewed and approved in pieces: https://codereview.webrtc.org/1224093003 https://codereview.webrtc.org/1224123002 https://codereview.webrtc.org/1224163002 https://codereview.webrtc.org/1225133003 https://codereview.webrtc.org/1225173002 https://codereview.webrtc.org/1227163003 https://codereview.webrtc.org/1227203003 https://codereview.webrtc.org/1227213002 https://codereview.webrtc.org/1227893002 https://codereview.webrtc.org/1228793004 https://codereview.webrtc.org/1228803003 https://codereview.webrtc.org/1228823002 https://codereview.webrtc.org/1228823003 https://codereview.webrtc.org/1228843002 https://codereview.webrtc.org/1230693002 https://codereview.webrtc.org/1231713002 The change is being landed as TBR to all the folks who reviewed the above. BUG=chromium:81439 TEST=none R=andrew@webrtc.org, pbos@webrtc.org TBR=aluebs, andrew, asapersson, henrika, hlundin, jan.skoglund, kwiberg, minyue, pbos, pthatcher Review URL: https://codereview.webrtc.org/1230503003 . Cr-Commit-Position: refs/heads/master@{#9768} --- .../audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index ce70db455b..93fbde9c48 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -123,14 +123,15 @@ size_t AudioEncoderIsacT::MaxEncodedBytes() const { } template -int AudioEncoderIsacT::Num10MsFramesInNextPacket() const { +size_t AudioEncoderIsacT::Num10MsFramesInNextPacket() const { const int samples_in_next_packet = T::GetNewFrameLen(isac_state_); - return rtc::CheckedDivExact(samples_in_next_packet, - rtc::CheckedDivExact(SampleRateHz(), 100)); + return static_cast( + rtc::CheckedDivExact(samples_in_next_packet, + rtc::CheckedDivExact(SampleRateHz(), 100))); } template -int AudioEncoderIsacT::Max10MsFramesInAPacket() const { +size_t AudioEncoderIsacT::Max10MsFramesInAPacket() const { return 6; // iSAC puts at most 60 ms in a packet. } @@ -215,8 +216,7 @@ int AudioDecoderIsacT::DecodeInternal(const uint8_t* encoded, } int16_t temp_type = 1; // Default is speech. int ret = - T::DecodeInternal(isac_state_, encoded, static_cast(encoded_len), - decoded, &temp_type); + T::DecodeInternal(isac_state_, encoded, encoded_len, decoded, &temp_type); *speech_type = ConvertSpeechType(temp_type); return ret; } @@ -227,7 +227,7 @@ bool AudioDecoderIsacT::HasDecodePlc() const { } template -int AudioDecoderIsacT::DecodePlc(int num_frames, int16_t* decoded) { +size_t AudioDecoderIsacT::DecodePlc(size_t num_frames, int16_t* decoded) { return T::DecodePlc(isac_state_, decoded, num_frames); } @@ -243,7 +243,7 @@ int AudioDecoderIsacT::IncomingPacket(const uint8_t* payload, uint32_t rtp_timestamp, uint32_t arrival_timestamp) { int ret = T::UpdateBwEstimate( - isac_state_, payload, static_cast(payload_len), + isac_state_, payload, payload_len, rtp_sequence_number, rtp_timestamp, arrival_timestamp); if (bwinfo_) { IsacBandwidthInfo bwinfo; -- cgit v1.2.3 From 4376648df021fd82f25a38694e33678f802d06ea Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Thu, 27 Aug 2015 15:22:11 +0200 Subject: AudioDecoder: Replace Init() with Reset() The Init() method was previously used to initialize and reset decoders, and returned an error code. The new Reset() method is used for reset only; the constructor is now responsible for fully initializing the AudioDecoder. Reset() doesn't return an error code; it turned out that none of the functions it ended up calling could actually fail, so this CL removes their error return codes as well. R=henrik.lundin@webrtc.org Review URL: https://codereview.webrtc.org/1319683002 . Cr-Commit-Position: refs/heads/master@{#9798} --- webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 93fbde9c48..98f3ed9652 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -185,7 +185,7 @@ template AudioDecoderIsacT::AudioDecoderIsacT(LockedIsacBandwidthInfo* bwinfo) : bwinfo_(bwinfo), decoder_sample_rate_hz_(-1) { CHECK_EQ(0, T::Create(&isac_state_)); - CHECK_EQ(0, T::DecoderInit(isac_state_)); + T::DecoderInit(isac_state_); if (bwinfo_) { IsacBandwidthInfo bwinfo; T::GetBandwidthInfo(isac_state_, &bwinfo); @@ -232,8 +232,8 @@ size_t AudioDecoderIsacT::DecodePlc(size_t num_frames, int16_t* decoded) { } template -int AudioDecoderIsacT::Init() { - return T::DecoderInit(isac_state_); +void AudioDecoderIsacT::Reset() { + T::DecoderInit(isac_state_); } template -- cgit v1.2.3 From a567bf329239480529835ccb34a6d9cc8cbbf715 Mon Sep 17 00:00:00 2001 From: kwiberg Date: Thu, 27 Aug 2015 11:17:35 -0700 Subject: Rename local variable to avoid shadowing See comment here: https://codereview.webrtc.org/1208993010/diff/180001/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h#newcode189 TBR=minyue@webrtc.org Review URL: https://codereview.webrtc.org/1315333003 Cr-Commit-Position: refs/heads/master@{#9800} --- webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 98f3ed9652..28e9b8e83f 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -187,9 +187,9 @@ AudioDecoderIsacT::AudioDecoderIsacT(LockedIsacBandwidthInfo* bwinfo) CHECK_EQ(0, T::Create(&isac_state_)); T::DecoderInit(isac_state_); if (bwinfo_) { - IsacBandwidthInfo bwinfo; - T::GetBandwidthInfo(isac_state_, &bwinfo); - bwinfo_->Set(bwinfo); + IsacBandwidthInfo bi; + T::GetBandwidthInfo(isac_state_, &bi); + bwinfo_->Set(bi); } } -- cgit v1.2.3 From 12cfc9b4dacd6942377df1f29a64bdbec591920e Mon Sep 17 00:00:00 2001 From: kwiberg Date: Tue, 8 Sep 2015 05:57:53 -0700 Subject: Fold AudioEncoderMutable into AudioEncoder It makes more sense to combine the two interfaces, since there wasn't a clear line separating them. The result is a combined interface with just over a dozen methods, half of which need to be implemented by every subclass, while the other half have sensible (and trivial) default implementations and are implemented only by the few subclasses that need non-default behavior. Review URL: https://codereview.webrtc.org/1322973004 Cr-Commit-Position: refs/heads/master@{#9894} --- .../codecs/isac/audio_encoder_isac_t_impl.h | 140 +++++++++++++-------- 1 file changed, 85 insertions(+), 55 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 28e9b8e83f..ad09c3f90d 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -20,20 +20,20 @@ namespace webrtc { -const int kIsacPayloadType = 103; -const int kDefaultBitRate = 32000; - template -AudioEncoderIsacT::Config::Config() - : bwinfo(nullptr), - payload_type(kIsacPayloadType), - sample_rate_hz(16000), - frame_size_ms(30), - bit_rate(kDefaultBitRate), - max_payload_size_bytes(-1), - max_bit_rate(-1), - adaptive_mode(false), - enforce_frame_size(false) { +typename AudioEncoderIsacT::Config CreateIsacConfig( + const CodecInst& codec_inst, + LockedIsacBandwidthInfo* bwinfo) { + typename AudioEncoderIsacT::Config config; + config.bwinfo = bwinfo; + config.payload_type = codec_inst.pltype; + config.sample_rate_hz = codec_inst.plfreq; + config.frame_size_ms = + rtc::CheckedDivExact(1000 * codec_inst.pacsize, config.sample_rate_hz); + config.adaptive_mode = (codec_inst.rate == -1); + if (codec_inst.rate != -1) + config.bit_rate = codec_inst.rate; + return config; } template @@ -67,46 +67,25 @@ bool AudioEncoderIsacT::Config::IsOk() const { } template -AudioEncoderIsacT::AudioEncoderIsacT(const Config& config) - : payload_type_(config.payload_type), - bwinfo_(config.bwinfo), - packet_in_progress_(false), - target_bitrate_bps_(config.adaptive_mode ? -1 : (config.bit_rate == 0 - ? kDefaultBitRate - : config.bit_rate)) { - CHECK(config.IsOk()); - CHECK_EQ(0, T::Create(&isac_state_)); - CHECK_EQ(0, T::EncoderInit(isac_state_, config.adaptive_mode ? 0 : 1)); - CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); - const int bit_rate = config.bit_rate == 0 ? kDefaultBitRate : config.bit_rate; - if (config.adaptive_mode) { - CHECK_EQ(0, T::ControlBwe(isac_state_, bit_rate, config.frame_size_ms, - config.enforce_frame_size)); - } else { - CHECK_EQ(0, T::Control(isac_state_, bit_rate, config.frame_size_ms)); - } - if (config.max_payload_size_bytes != -1) - CHECK_EQ(0, - T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); - if (config.max_bit_rate != -1) - CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate)); - - // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is - // still set to 32000 Hz, since there is no full-band mode in the decoder. - const int decoder_sample_rate_hz = std::min(config.sample_rate_hz, 32000); - - // Set the decoder sample rate even though we just use the encoder. This - // doesn't appear to be necessary to produce a valid encoding, but without it - // we get an encoding that isn't bit-for-bit identical with what a combined - // encoder+decoder object produces. - CHECK_EQ(0, T::SetDecSampRate(isac_state_, decoder_sample_rate_hz)); +AudioEncoderIsacT::AudioEncoderIsacT(const Config& config) { + RecreateEncoderInstance(config); } +template +AudioEncoderIsacT::AudioEncoderIsacT(const CodecInst& codec_inst, + LockedIsacBandwidthInfo* bwinfo) + : AudioEncoderIsacT(CreateIsacConfig(codec_inst, bwinfo)) {} + template AudioEncoderIsacT::~AudioEncoderIsacT() { CHECK_EQ(0, T::Free(isac_state_)); } +template +size_t AudioEncoderIsacT::MaxEncodedBytes() const { + return kSufficientEncodeBufferSizeBytes; +} + template int AudioEncoderIsacT::SampleRateHz() const { return T::EncSampRate(isac_state_); @@ -117,11 +96,6 @@ int AudioEncoderIsacT::NumChannels() const { return 1; } -template -size_t AudioEncoderIsacT::MaxEncodedBytes() const { - return kSufficientEncodeBufferSizeBytes; -} - template size_t AudioEncoderIsacT::Num10MsFramesInNextPacket() const { const int samples_in_next_packet = T::GetNewFrameLen(isac_state_); @@ -137,7 +111,9 @@ size_t AudioEncoderIsacT::Max10MsFramesInAPacket() const { template int AudioEncoderIsacT::GetTargetBitrate() const { - return target_bitrate_bps_; + if (config_.adaptive_mode) + return -1; + return config_.bit_rate == 0 ? kDefaultBitRate : config_.bit_rate; } template @@ -172,15 +148,69 @@ AudioEncoder::EncodedInfo AudioEncoderIsacT::EncodeInternal( EncodedInfo info; info.encoded_bytes = r; info.encoded_timestamp = packet_timestamp_; - info.payload_type = payload_type_; + info.payload_type = config_.payload_type; return info; } template -AudioDecoderIsacT::AudioDecoderIsacT() - : AudioDecoderIsacT(nullptr) { +void AudioEncoderIsacT::Reset() { + RecreateEncoderInstance(config_); } +template +void AudioEncoderIsacT::SetMaxPayloadSize(int max_payload_size_bytes) { + auto conf = config_; + conf.max_payload_size_bytes = max_payload_size_bytes; + RecreateEncoderInstance(conf); +} + +template +void AudioEncoderIsacT::SetMaxBitrate(int max_rate_bps) { + auto conf = config_; + conf.max_bit_rate = max_rate_bps; + RecreateEncoderInstance(conf); +} + +template +void AudioEncoderIsacT::RecreateEncoderInstance(const Config& config) { + CHECK(config.IsOk()); + packet_in_progress_ = false; + bwinfo_ = config.bwinfo; + if (isac_state_) + CHECK_EQ(0, T::Free(isac_state_)); + CHECK_EQ(0, T::Create(&isac_state_)); + CHECK_EQ(0, T::EncoderInit(isac_state_, config.adaptive_mode ? 0 : 1)); + CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); + const int bit_rate = config.bit_rate == 0 ? kDefaultBitRate : config.bit_rate; + if (config.adaptive_mode) { + CHECK_EQ(0, T::ControlBwe(isac_state_, bit_rate, config.frame_size_ms, + config.enforce_frame_size)); + } else { + CHECK_EQ(0, T::Control(isac_state_, bit_rate, config.frame_size_ms)); + } + if (config.max_payload_size_bytes != -1) + CHECK_EQ(0, + T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); + if (config.max_bit_rate != -1) + CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate)); + + // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is + // still set to 32000 Hz, since there is no full-band mode in the decoder. + const int decoder_sample_rate_hz = std::min(config.sample_rate_hz, 32000); + + // Set the decoder sample rate even though we just use the encoder. This + // doesn't appear to be necessary to produce a valid encoding, but without it + // we get an encoding that isn't bit-for-bit identical with what a combined + // encoder+decoder object produces. + CHECK_EQ(0, T::SetDecSampRate(isac_state_, decoder_sample_rate_hz)); + + config_ = config; +} + +template +AudioDecoderIsacT::AudioDecoderIsacT() + : AudioDecoderIsacT(nullptr) {} + template AudioDecoderIsacT::AudioDecoderIsacT(LockedIsacBandwidthInfo* bwinfo) : bwinfo_(bwinfo), decoder_sample_rate_hz_(-1) { -- cgit v1.2.3 From c99ebc1490ec689f5932d7731a215ca02ab30af6 Mon Sep 17 00:00:00 2001 From: kwiberg Date: Wed, 9 Sep 2015 00:54:07 -0700 Subject: Remove AudioEncoder methods SetMaxBitrate and SetMaxPayloadSize And the corresponding ACM methods SetISACMaxRate and SetISACMaxPayloadSize. They were only used in tests. Review URL: https://codereview.webrtc.org/1311533010 Cr-Commit-Position: refs/heads/master@{#9903} --- .../audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index ad09c3f90d..3cc635c612 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -157,20 +157,6 @@ void AudioEncoderIsacT::Reset() { RecreateEncoderInstance(config_); } -template -void AudioEncoderIsacT::SetMaxPayloadSize(int max_payload_size_bytes) { - auto conf = config_; - conf.max_payload_size_bytes = max_payload_size_bytes; - RecreateEncoderInstance(conf); -} - -template -void AudioEncoderIsacT::SetMaxBitrate(int max_rate_bps) { - auto conf = config_; - conf.max_bit_rate = max_rate_bps; - RecreateEncoderInstance(conf); -} - template void AudioEncoderIsacT::RecreateEncoderInstance(const Config& config) { CHECK(config.IsOk()); -- cgit v1.2.3 From 91d6edef35e7275879c30ce16ecb8b6dc73c6e4a Mon Sep 17 00:00:00 2001 From: henrikg Date: Thu, 17 Sep 2015 00:24:34 -0700 Subject: Add RTC_ prefix to (D)CHECKs and related macros. We must remove dependency on Chromium, i.e. we can't use Chromium's base/logging.h. That means we need to define these macros in WebRTC also when doing Chromium builds. And this causes redefinition. Alternative solutions: * Check if we already have defined e.g. CHECK, and don't define them in that case. This makes us depend on include order in Chromium, which is not acceptable. * Don't allow using the macros in WebRTC headers. Error prone since if someone adds it there by mistake it may compile fine, but later break if a header in added or order is changed in Chromium. That will be confusing and hard to enforce. * Ensure that headers that are included by an embedder don't include our macros. This would require some heavy refactoring to be maintainable and enforcable. * Changes in Chromium for this is obviously not an option. BUG=chromium:468375 NOTRY=true Review URL: https://codereview.webrtc.org/1335923002 Cr-Commit-Position: refs/heads/master@{#9964} --- .../codecs/isac/audio_encoder_isac_t_impl.h | 40 +++++++++++----------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 3cc635c612..4122ee0bc5 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -78,7 +78,7 @@ AudioEncoderIsacT::AudioEncoderIsacT(const CodecInst& codec_inst, template AudioEncoderIsacT::~AudioEncoderIsacT() { - CHECK_EQ(0, T::Free(isac_state_)); + RTC_CHECK_EQ(0, T::Free(isac_state_)); } template @@ -132,12 +132,12 @@ AudioEncoder::EncodedInfo AudioEncoderIsacT::EncodeInternal( T::SetBandwidthInfo(isac_state_, &bwinfo); } int r = T::Encode(isac_state_, audio, encoded); - CHECK_GE(r, 0) << "Encode failed (error code " << T::GetErrorCode(isac_state_) - << ")"; + RTC_CHECK_GE(r, 0) << "Encode failed (error code " + << T::GetErrorCode(isac_state_) << ")"; // T::Encode doesn't allow us to tell it the size of the output // buffer. All we can do is check for an overrun after the fact. - CHECK_LE(static_cast(r), max_encoded_bytes); + RTC_CHECK_LE(static_cast(r), max_encoded_bytes); if (r == 0) return EncodedInfo(); @@ -159,26 +159,26 @@ void AudioEncoderIsacT::Reset() { template void AudioEncoderIsacT::RecreateEncoderInstance(const Config& config) { - CHECK(config.IsOk()); + RTC_CHECK(config.IsOk()); packet_in_progress_ = false; bwinfo_ = config.bwinfo; if (isac_state_) - CHECK_EQ(0, T::Free(isac_state_)); - CHECK_EQ(0, T::Create(&isac_state_)); - CHECK_EQ(0, T::EncoderInit(isac_state_, config.adaptive_mode ? 0 : 1)); - CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); + RTC_CHECK_EQ(0, T::Free(isac_state_)); + RTC_CHECK_EQ(0, T::Create(&isac_state_)); + RTC_CHECK_EQ(0, T::EncoderInit(isac_state_, config.adaptive_mode ? 0 : 1)); + RTC_CHECK_EQ(0, T::SetEncSampRate(isac_state_, config.sample_rate_hz)); const int bit_rate = config.bit_rate == 0 ? kDefaultBitRate : config.bit_rate; if (config.adaptive_mode) { - CHECK_EQ(0, T::ControlBwe(isac_state_, bit_rate, config.frame_size_ms, - config.enforce_frame_size)); + RTC_CHECK_EQ(0, T::ControlBwe(isac_state_, bit_rate, config.frame_size_ms, + config.enforce_frame_size)); } else { - CHECK_EQ(0, T::Control(isac_state_, bit_rate, config.frame_size_ms)); + RTC_CHECK_EQ(0, T::Control(isac_state_, bit_rate, config.frame_size_ms)); } if (config.max_payload_size_bytes != -1) - CHECK_EQ(0, - T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); + RTC_CHECK_EQ( + 0, T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes)); if (config.max_bit_rate != -1) - CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate)); + RTC_CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate)); // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is // still set to 32000 Hz, since there is no full-band mode in the decoder. @@ -188,7 +188,7 @@ void AudioEncoderIsacT::RecreateEncoderInstance(const Config& config) { // doesn't appear to be necessary to produce a valid encoding, but without it // we get an encoding that isn't bit-for-bit identical with what a combined // encoder+decoder object produces. - CHECK_EQ(0, T::SetDecSampRate(isac_state_, decoder_sample_rate_hz)); + RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, decoder_sample_rate_hz)); config_ = config; } @@ -200,7 +200,7 @@ AudioDecoderIsacT::AudioDecoderIsacT() template AudioDecoderIsacT::AudioDecoderIsacT(LockedIsacBandwidthInfo* bwinfo) : bwinfo_(bwinfo), decoder_sample_rate_hz_(-1) { - CHECK_EQ(0, T::Create(&isac_state_)); + RTC_CHECK_EQ(0, T::Create(&isac_state_)); T::DecoderInit(isac_state_); if (bwinfo_) { IsacBandwidthInfo bi; @@ -211,7 +211,7 @@ AudioDecoderIsacT::AudioDecoderIsacT(LockedIsacBandwidthInfo* bwinfo) template AudioDecoderIsacT::~AudioDecoderIsacT() { - CHECK_EQ(0, T::Free(isac_state_)); + RTC_CHECK_EQ(0, T::Free(isac_state_)); } template @@ -224,10 +224,10 @@ int AudioDecoderIsacT::DecodeInternal(const uint8_t* encoded, // in fact it outputs 32000 Hz. This is the iSAC fullband mode. if (sample_rate_hz == 48000) sample_rate_hz = 32000; - CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000) + RTC_CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000) << "Unsupported sample rate " << sample_rate_hz; if (sample_rate_hz != decoder_sample_rate_hz_) { - CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz)); + RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz)); decoder_sample_rate_hz_ = sample_rate_hz; } int16_t temp_type = 1; // Default is speech. -- cgit v1.2.3 From 740436899825b96e12469c417c0ea82fd8a22edf Mon Sep 17 00:00:00 2001 From: Karl Wiberg Date: Tue, 22 Sep 2015 19:31:40 +0200 Subject: Move AudioDecoderIsac* to its own files Currently, it's sitting in AudioEncoderIsac*'s files, which is less than obvious. This CL puts the encoder and decoder in separate files together with the C implementation; CLs are afoot to make it so for the other built-in codecs as well. BUG=webrtc:4557 R=henrik.lundin@webrtc.org Review URL: https://codereview.webrtc.org/1339253003 . Cr-Commit-Position: refs/heads/master@{#10018} --- .../codecs/isac/audio_encoder_isac_t_impl.h | 89 ---------------------- 1 file changed, 89 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index 4122ee0bc5..fbc1ba9139 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -13,10 +13,7 @@ #include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_isac.h" -#include - #include "webrtc/base/checks.h" -#include "webrtc/modules/audio_coding/codecs/isac/main/interface/isac.h" namespace webrtc { @@ -193,92 +190,6 @@ void AudioEncoderIsacT::RecreateEncoderInstance(const Config& config) { config_ = config; } -template -AudioDecoderIsacT::AudioDecoderIsacT() - : AudioDecoderIsacT(nullptr) {} - -template -AudioDecoderIsacT::AudioDecoderIsacT(LockedIsacBandwidthInfo* bwinfo) - : bwinfo_(bwinfo), decoder_sample_rate_hz_(-1) { - RTC_CHECK_EQ(0, T::Create(&isac_state_)); - T::DecoderInit(isac_state_); - if (bwinfo_) { - IsacBandwidthInfo bi; - T::GetBandwidthInfo(isac_state_, &bi); - bwinfo_->Set(bi); - } -} - -template -AudioDecoderIsacT::~AudioDecoderIsacT() { - RTC_CHECK_EQ(0, T::Free(isac_state_)); -} - -template -int AudioDecoderIsacT::DecodeInternal(const uint8_t* encoded, - size_t encoded_len, - int sample_rate_hz, - int16_t* decoded, - SpeechType* speech_type) { - // We want to crate the illusion that iSAC supports 48000 Hz decoding, while - // in fact it outputs 32000 Hz. This is the iSAC fullband mode. - if (sample_rate_hz == 48000) - sample_rate_hz = 32000; - RTC_CHECK(sample_rate_hz == 16000 || sample_rate_hz == 32000) - << "Unsupported sample rate " << sample_rate_hz; - if (sample_rate_hz != decoder_sample_rate_hz_) { - RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, sample_rate_hz)); - decoder_sample_rate_hz_ = sample_rate_hz; - } - int16_t temp_type = 1; // Default is speech. - int ret = - T::DecodeInternal(isac_state_, encoded, encoded_len, decoded, &temp_type); - *speech_type = ConvertSpeechType(temp_type); - return ret; -} - -template -bool AudioDecoderIsacT::HasDecodePlc() const { - return false; -} - -template -size_t AudioDecoderIsacT::DecodePlc(size_t num_frames, int16_t* decoded) { - return T::DecodePlc(isac_state_, decoded, num_frames); -} - -template -void AudioDecoderIsacT::Reset() { - T::DecoderInit(isac_state_); -} - -template -int AudioDecoderIsacT::IncomingPacket(const uint8_t* payload, - size_t payload_len, - uint16_t rtp_sequence_number, - uint32_t rtp_timestamp, - uint32_t arrival_timestamp) { - int ret = T::UpdateBwEstimate( - isac_state_, payload, payload_len, - rtp_sequence_number, rtp_timestamp, arrival_timestamp); - if (bwinfo_) { - IsacBandwidthInfo bwinfo; - T::GetBandwidthInfo(isac_state_, &bwinfo); - bwinfo_->Set(bwinfo); - } - return ret; -} - -template -int AudioDecoderIsacT::ErrorCode() { - return T::GetErrorCode(isac_state_); -} - -template -size_t AudioDecoderIsacT::Channels() const { - return 1; -} - } // namespace webrtc #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ -- cgit v1.2.3 From bd7de0c6eff510f9ec95b13a16862ca55871c47d Mon Sep 17 00:00:00 2001 From: "henrik.lundin" Date: Wed, 14 Oct 2015 06:05:52 -0700 Subject: Delete full-band mode from the iSAC codec This mode is no longer used. BUG=4210 Review URL: https://codereview.webrtc.org/1392173004 Cr-Commit-Position: refs/heads/master@{#10275} --- .../modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index fbc1ba9139..c7b1f20b3a 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -50,7 +50,6 @@ bool AudioEncoderIsacT::Config::IsOk() const { return (frame_size_ms == 30 || frame_size_ms == 60) && (bit_rate == 0 || (bit_rate >= 10000 && bit_rate <= 32000)); case 32000: - case 48000: if (max_bit_rate > 160000) return false; if (max_payload_size_bytes > 600) @@ -177,15 +176,11 @@ void AudioEncoderIsacT::RecreateEncoderInstance(const Config& config) { if (config.max_bit_rate != -1) RTC_CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate)); - // When config.sample_rate_hz is set to 48000 Hz (iSAC-fb), the decoder is - // still set to 32000 Hz, since there is no full-band mode in the decoder. - const int decoder_sample_rate_hz = std::min(config.sample_rate_hz, 32000); - // Set the decoder sample rate even though we just use the encoder. This // doesn't appear to be necessary to produce a valid encoding, but without it // we get an encoding that isn't bit-for-bit identical with what a combined // encoder+decoder object produces. - RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, decoder_sample_rate_hz)); + RTC_CHECK_EQ(0, T::SetDecSampRate(isac_state_, config.sample_rate_hz)); config_ = config; } -- cgit v1.2.3 From 74640895fafbb90a6630a6a91b80da0a7cff229c Mon Sep 17 00:00:00 2001 From: Henrik Kjellander Date: Thu, 29 Oct 2015 11:31:02 +0100 Subject: audio_coding: rename interface -> include BUG=webrtc:5095 R=henrik.lundin@webrtc.org TBR=tommi@webrtc.org Review URL: https://codereview.webrtc.org/1417173004 . Cr-Commit-Position: refs/heads/master@{#10444} --- webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h') diff --git a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h index c7b1f20b3a..279f80d6fc 100644 --- a/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h +++ b/webrtc/modules/audio_coding/codecs/isac/audio_encoder_isac_t_impl.h @@ -11,7 +11,7 @@ #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_IMPL_H_ -#include "webrtc/modules/audio_coding/codecs/isac/main/interface/audio_encoder_isac.h" +#include "webrtc/modules/audio_coding/codecs/isac/main/include/audio_encoder_isac.h" #include "webrtc/base/checks.h" -- cgit v1.2.3