Adding option to change bitrate for Celt.

I have updated the code so that Celt rate can be changed to any value between 48 and 128 kbps.
Tests for both mono and stereo are updated.Updated tests for Celt mono.

Review URL: https://webrtc-codereview.appspot.com/391014

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1712 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
tina.legrand@webrtc.org 2012-02-17 00:38:33 +00:00
parent 133d1a18b7
commit 79e29e510f
6 changed files with 30 additions and 10 deletions

View File

@ -109,7 +109,7 @@ ACMCELT::ACMCELT(int16_t codecID)
: enc_inst_ptr_(NULL), : enc_inst_ptr_(NULL),
dec_inst_ptr_(NULL), dec_inst_ptr_(NULL),
sampling_freq_(32000), // Default sampling frequency. sampling_freq_(32000), // Default sampling frequency.
bitrate_(48000), // Default rate. bitrate_(64000), // Default rate.
channels_(1), // Default send mono. channels_(1), // Default send mono.
dec_channels_(1) { // Default receive mono. dec_channels_(1) { // Default receive mono.
// TODO(tlegrand): remove later when ACMGenericCodec has a new constructor. // TODO(tlegrand): remove later when ACMGenericCodec has a new constructor.
@ -162,7 +162,7 @@ int16_t ACMCELT::DecodeSafe(uint8_t* /* bitStream */,
} }
int16_t ACMCELT::InternalInitEncoder(WebRtcACMCodecParams* codecParams) { int16_t ACMCELT::InternalInitEncoder(WebRtcACMCodecParams* codecParams) {
// Set bitrate and check that it is withing the valid range. // Set bitrate and check that it is within the valid range.
int16_t status = SetBitRateSafe((codecParams->codecInstant).rate); int16_t status = SetBitRateSafe((codecParams->codecInstant).rate);
if (status < 0) { if (status < 0) {
return -1; return -1;
@ -302,7 +302,7 @@ bool ACMCELT::IsTrueStereoCodec() {
int16_t ACMCELT::SetBitRateSafe(const int32_t rate) { int16_t ACMCELT::SetBitRateSafe(const int32_t rate) {
// Check that rate is in the valid range. // Check that rate is in the valid range.
if ((rate >= 48000) && (rate <= 96000)) { if ((rate >= 48000) && (rate <= 128000)) {
bitrate_ = rate; bitrate_ = rate;
return 0; return 0;
} else { } else {

View File

@ -62,7 +62,7 @@ class ACMCELT : public ACMGenericCodec {
CELT_encinst_t_* enc_inst_ptr_; CELT_encinst_t_* enc_inst_ptr_;
CELT_decinst_t_* dec_inst_ptr_; CELT_decinst_t_* dec_inst_ptr_;
uint16_t sampling_freq_; uint16_t sampling_freq_;
uint16_t bitrate_; int32_t bitrate_;
uint16_t channels_; uint16_t channels_;
uint16_t dec_channels_; uint16_t dec_channels_;
}; };

View File

@ -117,7 +117,7 @@ const int kDynamicPayloadtypes[ACMCodecDB::kMaxNumCodecs] = {
defined(WEBRTC_CODEC_AMR) || defined(WEBRTC_CODEC_AMRWB) || \ defined(WEBRTC_CODEC_AMR) || defined(WEBRTC_CODEC_AMRWB) || \
defined(WEBRTC_CODEC_CELT) || defined(WEBRTC_CODEC_G729_1) || \ defined(WEBRTC_CODEC_CELT) || defined(WEBRTC_CODEC_G729_1) || \
defined(WEBRTC_CODEC_SPEEX) || defined(WEBRTC_CODEC_G722_1) || \ defined(WEBRTC_CODEC_SPEEX) || defined(WEBRTC_CODEC_G722_1) || \
defined(WEBRTC_CODEC_G722_1C)) defined(WEBRTC_CODEC_G722_1C) || defined(WEBRTC_CODEC_CELT))
static int count_database = 0; static int count_database = 0;
#endif #endif
@ -146,7 +146,7 @@ const CodecInst ACMCodecDB::database_[] = {
{kDynamicPayloadtypes[count_database++], "AMR-WB", 16000, 320, 1, 20000}, {kDynamicPayloadtypes[count_database++], "AMR-WB", 16000, 320, 1, 20000},
#endif #endif
#ifdef WEBRTC_CODEC_CELT #ifdef WEBRTC_CODEC_CELT
{kDynamicPayloadtypes[count_database++], "CELT", 32000, 320, 1, 48000}, {kDynamicPayloadtypes[count_database++], "CELT", 32000, 320, 1, 64000},
#endif #endif
#ifdef WEBRTC_CODEC_G722 #ifdef WEBRTC_CODEC_G722
{9, "G722", 16000, 320, 1, 64000}, {9, "G722", 16000, 320, 1, 64000},
@ -492,6 +492,9 @@ int ACMCodecDB::CodecNumber(const CodecInst* codec_inst, int* mirror_id) {
} else if (STR_CASE_CMP("speex", codec_inst->plname) == 0) { } else if (STR_CASE_CMP("speex", codec_inst->plname) == 0) {
return IsSpeexRateValid(codec_inst->rate) return IsSpeexRateValid(codec_inst->rate)
? codec_number : kInvalidRate; ? codec_number : kInvalidRate;
} else if (STR_CASE_CMP("celt", codec_inst->plname) == 0) {
return IsCeltRateValid(codec_inst->rate)
? codec_number : kInvalidRate;
} }
return IsRateValid(codec_number, codec_inst->rate) ? return IsRateValid(codec_number, codec_inst->rate) ?
@ -965,6 +968,7 @@ bool ACMCodecDB::IsG7291RateValid(int rate) {
} }
} }
} }
// Checks if the bitrate is valid for Speex. // Checks if the bitrate is valid for Speex.
bool ACMCodecDB::IsSpeexRateValid(int rate) { bool ACMCodecDB::IsSpeexRateValid(int rate) {
if (rate > 2000) { if (rate > 2000) {
@ -974,6 +978,15 @@ bool ACMCodecDB::IsSpeexRateValid(int rate) {
} }
} }
// Checks if the bitrate is valid for Celt.
bool ACMCodecDB::IsCeltRateValid(int rate) {
if ((rate >= 48000) && (rate <= 128000)) {
return true;
} else {
return false;
}
}
// Checks if the payload type is in the valid range. // Checks if the payload type is in the valid range.
bool ACMCodecDB::ValidPayloadType(int payload_type) { bool ACMCodecDB::ValidPayloadType(int payload_type) {
if ((payload_type < 0) || (payload_type > 127)) { if ((payload_type < 0) || (payload_type > 127)) {

View File

@ -282,6 +282,7 @@ class ACMCodecDB {
static bool IsAMRwbRateValid(int rate); static bool IsAMRwbRateValid(int rate);
static bool IsG7291RateValid(int rate); static bool IsG7291RateValid(int rate);
static bool IsSpeexRateValid(int rate); static bool IsSpeexRateValid(int rate);
static bool IsCeltRateValid(int rate);
// Check if the payload type is valid, meaning that it is in the valid range // Check if the payload type is valid, meaning that it is in the valid range
// of 0 to 127. // of 0 to 127.

View File

@ -660,6 +660,10 @@ void TestAllCodecs::Perform()
char codecCELT_32[] = "CELT"; char codecCELT_32[] = "CELT";
RegisterSendCodec('A', codecCELT_32, 32000, 48000, 320, 0); RegisterSendCodec('A', codecCELT_32, 32000, 48000, 320, 0);
Run(_channelA2B); Run(_channelA2B);
RegisterSendCodec('A', codecCELT_32, 32000, 64000, 320, 0);
Run(_channelA2B);
RegisterSendCodec('A', codecCELT_32, 32000, 128000, 320, 0);
Run(_channelA2B);
_outFileB.Close(); _outFileB.Close();
#endif #endif
if(_testMode != 0) { if(_testMode != 0) {
@ -669,8 +673,6 @@ void TestAllCodecs::Perform()
} }
/* Print out all codecs that were not tested in the run */ /* Print out all codecs that were not tested in the run */
if(_testMode != 0) { if(_testMode != 0) {
printf("The following codecs was not included in the test:\n"); printf("The following codecs was not included in the test:\n");
#ifndef WEBRTC_CODEC_GSMAMR #ifndef WEBRTC_CODEC_GSMAMR

View File

@ -434,6 +434,10 @@ void TestStereo::Perform()
char codecCELT[] = "CELT"; char codecCELT[] = "CELT";
RegisterSendCodec('A', codecCELT, 32000, 48000, 320, codec_channels); RegisterSendCodec('A', codecCELT, 32000, 48000, 320, codec_channels);
Run(_channelA2B, audio_channels, codec_channels); Run(_channelA2B, audio_channels, codec_channels);
RegisterSendCodec('A', codecCELT, 32000, 64000, 320, codec_channels);
Run(_channelA2B, audio_channels, codec_channels);
RegisterSendCodec('A', codecCELT, 32000, 128000, 320, codec_channels);
Run(_channelA2B, audio_channels, codec_channels);
_acmA->SetVAD(true, true, VADNormal); _acmA->SetVAD(true, true, VADNormal);
RegisterSendCodec('A', codecCELT, 32000, 48000, 320, codec_channels); RegisterSendCodec('A', codecCELT, 32000, 48000, 320, codec_channels);
Run(_channelA2B, audio_channels, codec_channels); Run(_channelA2B, audio_channels, codec_channels);
@ -516,7 +520,7 @@ void TestStereo::Perform()
_testCntr++; _testCntr++;
_channelA2B->SetCodecType(4); _channelA2B->SetCodecType(4);
OpenOutFile(_testCntr); OpenOutFile(_testCntr);
RegisterSendCodec('A', codecCELT, 32000, 48000, 320, codec_channels); RegisterSendCodec('A', codecCELT, 32000, 64000, 320, codec_channels);
Run(_channelA2B, audio_channels, codec_channels); Run(_channelA2B, audio_channels, codec_channels);
_outFileB.Close(); _outFileB.Close();
#endif #endif
@ -607,7 +611,7 @@ void TestStereo::Perform()
} }
_testCntr++; _testCntr++;
OpenOutFile(_testCntr); OpenOutFile(_testCntr);
RegisterSendCodec('A', codecCELT, 32000, 48000, 320, codec_channels); RegisterSendCodec('A', codecCELT, 32000, 64000, 320, codec_channels);
Run(_channelA2B, audio_channels, codec_channels); Run(_channelA2B, audio_channels, codec_channels);
_outFileB.Close(); _outFileB.Close();
#endif #endif