mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-17 07:37:51 +01:00
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}
This commit is contained in:
parent
9829af4bfc
commit
7c324cac50
4 changed files with 48 additions and 130 deletions
|
@ -25,8 +25,7 @@ class CriticalSectionWrapper;
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class AudioEncoderDecoderIsacT : public AudioEncoder, public AudioDecoder {
|
class AudioEncoderDecoderIsacT : public AudioEncoder, public AudioDecoder {
|
||||||
public:
|
public:
|
||||||
// For constructing an encoder in instantaneous mode. Allowed combinations
|
// Allowed combinations of sample rate, frame size, and bit rate are
|
||||||
// are
|
|
||||||
// - 16000 Hz, 30 ms, 10000-32000 bps
|
// - 16000 Hz, 30 ms, 10000-32000 bps
|
||||||
// - 16000 Hz, 60 ms, 10000-32000 bps
|
// - 16000 Hz, 60 ms, 10000-32000 bps
|
||||||
// - 32000 Hz, 30 ms, 10000-56000 bps (if T has super-wideband support)
|
// - 32000 Hz, 30 ms, 10000-56000 bps (if T has super-wideband support)
|
||||||
|
@ -34,34 +33,24 @@ class AudioEncoderDecoderIsacT : public AudioEncoder, public AudioDecoder {
|
||||||
struct Config {
|
struct Config {
|
||||||
Config();
|
Config();
|
||||||
bool IsOk() const;
|
bool IsOk() const;
|
||||||
|
|
||||||
int payload_type;
|
int payload_type;
|
||||||
int sample_rate_hz;
|
int sample_rate_hz;
|
||||||
int frame_size_ms;
|
int frame_size_ms;
|
||||||
int bit_rate; // Limit on the short-term average bit rate, in bits/second.
|
int bit_rate; // Limit on the short-term average bit rate, in bits/s.
|
||||||
int max_bit_rate;
|
|
||||||
int max_payload_size_bytes;
|
int max_payload_size_bytes;
|
||||||
};
|
int max_bit_rate;
|
||||||
|
|
||||||
// For constructing an encoder in channel-adaptive mode. Allowed combinations
|
// If true, the encoder will dynamically adjust frame size and bit rate;
|
||||||
// are
|
// the configured values are then merely the starting point.
|
||||||
// - 16000 Hz, 30 ms, 10000-32000 bps
|
bool adaptive_mode;
|
||||||
// - 16000 Hz, 60 ms, 10000-32000 bps
|
|
||||||
// - 32000 Hz, 30 ms, 10000-56000 bps (if T has super-wideband support)
|
// In adaptive mode, prevent adaptive changes to the frame size. (Not used
|
||||||
// - 48000 Hz, 30 ms, 10000-56000 bps (if T has super-wideband support)
|
// in nonadaptive mode.)
|
||||||
struct ConfigAdaptive {
|
bool enforce_frame_size;
|
||||||
ConfigAdaptive();
|
|
||||||
bool IsOk() const;
|
|
||||||
int payload_type;
|
|
||||||
int sample_rate_hz;
|
|
||||||
int initial_frame_size_ms;
|
|
||||||
int initial_bit_rate;
|
|
||||||
int max_bit_rate;
|
|
||||||
bool enforce_frame_size; // Prevent adaptive changes to the frame size?
|
|
||||||
int max_payload_size_bytes;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit AudioEncoderDecoderIsacT(const Config& config);
|
explicit AudioEncoderDecoderIsacT(const Config& config);
|
||||||
explicit AudioEncoderDecoderIsacT(const ConfigAdaptive& config);
|
|
||||||
~AudioEncoderDecoderIsacT() override;
|
~AudioEncoderDecoderIsacT() override;
|
||||||
|
|
||||||
// AudioEncoder public methods.
|
// AudioEncoder public methods.
|
||||||
|
|
|
@ -22,16 +22,17 @@
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
const int kIsacPayloadType = 103;
|
const int kIsacPayloadType = 103;
|
||||||
const int kDefaultBitRate = 32000;
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
AudioEncoderDecoderIsacT<T>::Config::Config()
|
AudioEncoderDecoderIsacT<T>::Config::Config()
|
||||||
: payload_type(kIsacPayloadType),
|
: payload_type(kIsacPayloadType),
|
||||||
sample_rate_hz(16000),
|
sample_rate_hz(16000),
|
||||||
frame_size_ms(30),
|
frame_size_ms(30),
|
||||||
bit_rate(kDefaultBitRate),
|
bit_rate(32000),
|
||||||
|
max_payload_size_bytes(-1),
|
||||||
max_bit_rate(-1),
|
max_bit_rate(-1),
|
||||||
max_payload_size_bytes(-1) {
|
adaptive_mode(false),
|
||||||
|
enforce_frame_size(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -47,7 +48,7 @@ bool AudioEncoderDecoderIsacT<T>::Config::IsOk() const {
|
||||||
if (max_payload_size_bytes > 400)
|
if (max_payload_size_bytes > 400)
|
||||||
return false;
|
return false;
|
||||||
return (frame_size_ms == 30 || frame_size_ms == 60) &&
|
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 32000:
|
||||||
case 48000:
|
case 48000:
|
||||||
if (max_bit_rate > 160000)
|
if (max_bit_rate > 160000)
|
||||||
|
@ -55,47 +56,7 @@ bool AudioEncoderDecoderIsacT<T>::Config::IsOk() const {
|
||||||
if (max_payload_size_bytes > 600)
|
if (max_payload_size_bytes > 600)
|
||||||
return false;
|
return false;
|
||||||
return T::has_swb &&
|
return T::has_swb &&
|
||||||
(frame_size_ms == 30 &&
|
(frame_size_ms == 30 && bit_rate >= 10000 && bit_rate <= 56000);
|
||||||
((bit_rate >= 10000 && bit_rate <= 56000) || bit_rate == 0));
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
AudioEncoderDecoderIsacT<T>::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 <typename T>
|
|
||||||
bool AudioEncoderDecoderIsacT<T>::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:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -110,11 +71,15 @@ AudioEncoderDecoderIsacT<T>::AudioEncoderDecoderIsacT(const Config& config)
|
||||||
packet_in_progress_(false) {
|
packet_in_progress_(false) {
|
||||||
CHECK(config.IsOk());
|
CHECK(config.IsOk());
|
||||||
CHECK_EQ(0, T::Create(&isac_state_));
|
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::SetEncSampRate(isac_state_, config.sample_rate_hz));
|
||||||
CHECK_EQ(0, T::Control(isac_state_, config.bit_rate == 0 ? kDefaultBitRate
|
if (config.adaptive_mode) {
|
||||||
: config.bit_rate,
|
CHECK_EQ(0, T::ControlBwe(isac_state_, config.bit_rate,
|
||||||
config.frame_size_ms));
|
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
|
// 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.
|
// still set to 32000 Hz, since there is no full-band mode in the decoder.
|
||||||
CHECK_EQ(0, T::SetDecSampRate(isac_state_,
|
CHECK_EQ(0, T::SetDecSampRate(isac_state_,
|
||||||
|
@ -124,29 +89,7 @@ AudioEncoderDecoderIsacT<T>::AudioEncoderDecoderIsacT(const Config& config)
|
||||||
T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes));
|
T::SetMaxPayloadSize(isac_state_, config.max_payload_size_bytes));
|
||||||
if (config.max_bit_rate != -1)
|
if (config.max_bit_rate != -1)
|
||||||
CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate));
|
CHECK_EQ(0, T::SetMaxRate(isac_state_, config.max_bit_rate));
|
||||||
}
|
CHECK_EQ(0, T::DecoderInit(isac_state_));
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
AudioEncoderDecoderIsacT<T>::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 <typename T>
|
template <typename T>
|
||||||
|
|
|
@ -293,51 +293,34 @@ void ACMGenericCodec::ResetAudioEncoder() {
|
||||||
#endif
|
#endif
|
||||||
#ifdef WEBRTC_CODEC_ISACFX
|
#ifdef WEBRTC_CODEC_ISACFX
|
||||||
} else if (!STR_CASE_CMP(codec_inst.plname, "ISAC")) {
|
} else if (!STR_CASE_CMP(codec_inst.plname, "ISAC")) {
|
||||||
DCHECK_EQ(codec_inst.plfreq, 16000);
|
|
||||||
is_isac_ = true;
|
is_isac_ = true;
|
||||||
AudioEncoderDecoderIsacFix* enc_dec;
|
AudioEncoderDecoderIsacFix::Config config;
|
||||||
if (codec_inst.rate == -1) {
|
config.payload_type = codec_inst.pltype;
|
||||||
// Adaptive mode.
|
config.sample_rate_hz = codec_inst.plfreq;
|
||||||
AudioEncoderDecoderIsacFix::ConfigAdaptive config;
|
config.frame_size_ms = rtc::CheckedDivExact(codec_inst.pacsize, 16);
|
||||||
config.payload_type = codec_inst.pltype;
|
if (codec_inst.rate != -1)
|
||||||
enc_dec = new AudioEncoderDecoderIsacFix(config);
|
|
||||||
} else {
|
|
||||||
// Channel independent mode.
|
|
||||||
AudioEncoderDecoderIsacFix::Config config;
|
|
||||||
config.bit_rate = codec_inst.rate;
|
config.bit_rate = codec_inst.rate;
|
||||||
config.frame_size_ms = codec_inst.pacsize / 16;
|
config.max_payload_size_bytes = max_payload_size_bytes_;
|
||||||
config.payload_type = codec_inst.pltype;
|
config.max_bit_rate = max_rate_bps_;
|
||||||
enc_dec = new AudioEncoderDecoderIsacFix(config);
|
config.adaptive_mode = (codec_inst.rate == -1);
|
||||||
}
|
auto* enc_dec = new AudioEncoderDecoderIsacFix(config);
|
||||||
decoder_proxy_.SetDecoder(enc_dec);
|
decoder_proxy_.SetDecoder(enc_dec);
|
||||||
audio_encoder_.reset(enc_dec);
|
audio_encoder_.reset(enc_dec);
|
||||||
#endif
|
#endif
|
||||||
#ifdef WEBRTC_CODEC_ISAC
|
#ifdef WEBRTC_CODEC_ISAC
|
||||||
} else if (!STR_CASE_CMP(codec_inst.plname, "ISAC")) {
|
} else if (!STR_CASE_CMP(codec_inst.plname, "ISAC")) {
|
||||||
is_isac_ = true;
|
is_isac_ = true;
|
||||||
AudioEncoderDecoderIsac* enc_dec;
|
AudioEncoderDecoderIsac::Config config;
|
||||||
if (codec_inst.rate == -1) {
|
config.payload_type = codec_inst.pltype;
|
||||||
// Adaptive mode.
|
config.sample_rate_hz = codec_inst.plfreq;
|
||||||
AudioEncoderDecoderIsac::ConfigAdaptive config;
|
config.frame_size_ms =
|
||||||
config.sample_rate_hz = codec_inst.plfreq;
|
rtc::CheckedDivExact(1000 * codec_inst.pacsize, config.sample_rate_hz);
|
||||||
config.initial_frame_size_ms = rtc::CheckedDivExact(
|
if (codec_inst.rate != -1)
|
||||||
1000 * codec_inst.pacsize, config.sample_rate_hz);
|
|
||||||
config.max_payload_size_bytes = max_payload_size_bytes_;
|
|
||||||
config.max_bit_rate = max_rate_bps_;
|
|
||||||
config.payload_type = codec_inst.pltype;
|
|
||||||
enc_dec = new AudioEncoderDecoderIsac(config);
|
|
||||||
} else {
|
|
||||||
// Channel independent mode.
|
|
||||||
AudioEncoderDecoderIsac::Config config;
|
|
||||||
config.sample_rate_hz = codec_inst.plfreq;
|
|
||||||
config.bit_rate = codec_inst.rate;
|
config.bit_rate = codec_inst.rate;
|
||||||
config.frame_size_ms = rtc::CheckedDivExact(1000 * codec_inst.pacsize,
|
config.max_payload_size_bytes = max_payload_size_bytes_;
|
||||||
config.sample_rate_hz);
|
config.max_bit_rate = max_rate_bps_;
|
||||||
config.max_payload_size_bytes = max_payload_size_bytes_;
|
config.adaptive_mode = (codec_inst.rate == -1);
|
||||||
config.max_bit_rate = max_rate_bps_;
|
auto* enc_dec = new AudioEncoderDecoderIsac(config);
|
||||||
config.payload_type = codec_inst.pltype;
|
|
||||||
enc_dec = new AudioEncoderDecoderIsac(config);
|
|
||||||
}
|
|
||||||
decoder_proxy_.SetDecoder(enc_dec);
|
decoder_proxy_.SetDecoder(enc_dec);
|
||||||
audio_encoder_.reset(enc_dec);
|
audio_encoder_.reset(enc_dec);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -361,6 +361,7 @@ class AudioDecoderIsacFloatTest : public AudioDecoderTest {
|
||||||
AudioEncoderDecoderIsac::Config config;
|
AudioEncoderDecoderIsac::Config config;
|
||||||
config.payload_type = payload_type_;
|
config.payload_type = payload_type_;
|
||||||
config.sample_rate_hz = codec_input_rate_hz_;
|
config.sample_rate_hz = codec_input_rate_hz_;
|
||||||
|
config.adaptive_mode = false;
|
||||||
config.frame_size_ms =
|
config.frame_size_ms =
|
||||||
1000 * static_cast<int>(frame_size_) / codec_input_rate_hz_;
|
1000 * static_cast<int>(frame_size_) / codec_input_rate_hz_;
|
||||||
|
|
||||||
|
@ -380,6 +381,7 @@ class AudioDecoderIsacSwbTest : public AudioDecoderTest {
|
||||||
AudioEncoderDecoderIsac::Config config;
|
AudioEncoderDecoderIsac::Config config;
|
||||||
config.payload_type = payload_type_;
|
config.payload_type = payload_type_;
|
||||||
config.sample_rate_hz = codec_input_rate_hz_;
|
config.sample_rate_hz = codec_input_rate_hz_;
|
||||||
|
config.adaptive_mode = false;
|
||||||
config.frame_size_ms =
|
config.frame_size_ms =
|
||||||
1000 * static_cast<int>(frame_size_) / codec_input_rate_hz_;
|
1000 * static_cast<int>(frame_size_) / codec_input_rate_hz_;
|
||||||
|
|
||||||
|
@ -399,6 +401,7 @@ class AudioDecoderIsacFixTest : public AudioDecoderTest {
|
||||||
AudioEncoderDecoderIsacFix::Config config;
|
AudioEncoderDecoderIsacFix::Config config;
|
||||||
config.payload_type = payload_type_;
|
config.payload_type = payload_type_;
|
||||||
config.sample_rate_hz = codec_input_rate_hz_;
|
config.sample_rate_hz = codec_input_rate_hz_;
|
||||||
|
config.adaptive_mode = false;
|
||||||
config.frame_size_ms =
|
config.frame_size_ms =
|
||||||
1000 * static_cast<int>(frame_size_) / codec_input_rate_hz_;
|
1000 * static_cast<int>(frame_size_) / codec_input_rate_hz_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue