Renaming SetOpusMaxBandwidth to SetOpusMaxPlaybackRate

This is to maintain the consistency with the Opus codec option "maxplaybackrate" defined in http://tools.ietf.org/html/draft-spittka-payload-rtp-opus-03

BUG=
R=tina.legrand@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7038 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
minyue@webrtc.org 2014-09-03 12:28:06 +00:00
parent 0a214ffa8a
commit adee8f9242
17 changed files with 91 additions and 86 deletions

View File

@ -73,25 +73,29 @@ int16_t WebRtcOpus_SetBitRate(OpusEncInst* inst, int32_t rate);
int16_t WebRtcOpus_SetPacketLossRate(OpusEncInst* inst, int32_t loss_rate);
/****************************************************************************
* WebRtcOpus_SetMaxBandwidth(...)
* WebRtcOpus_SetMaxPlaybackRate(...)
*
* Configures the maximum bandwidth for encoding. This can be taken as a hint
* about the maximum output bandwidth that the receiver is capable to render,
* due to hardware limitations. Sending signals with higher audio bandwidth
* results in higher than necessary network usage and encoding complexity.
* Configures the maximum playback rate for encoding. Due to hardware
* limitations, the receiver may render audio up to a playback rate. Opus
* encoder can use this information to optimize for network usage and encoding
* complexity. This will affect the audio bandwidth in the coded audio. However,
* the input/output sample rate is not affected.
*
* Input:
* - inst : Encoder context
* - bandwidth : Maximum encoding bandwidth in Hz.
* This parameter can take any value, but values
* other than Opus typical bandwidths: 4000, 6000,
* 8000, 12000, and 20000 will be rounded up (values
* greater than 20000 will be rounded down) to
* these values.
* - frequency_hz : Maximum playback rate in Hz.
* This parameter can take any value. The relation
* between the value and the Opus internal mode is
* as following:
* frequency_hz <= 8000 narrow band
* 8000 < frequency_hz <= 12000 medium band
* 12000 < frequency_hz <= 16000 wide band
* 16000 < frequency_hz <= 24000 super wide band
* frequency_hz > 24000 full band
* Return value : 0 - Success
* -1 - Error
*/
int16_t WebRtcOpus_SetMaxBandwidth(OpusEncInst* inst, int32_t bandwidth);
int16_t WebRtcOpus_SetMaxPlaybackRate(OpusEncInst* inst, int32_t frequency_hz);
/* TODO(minyue): Check whether an API to check the FEC and the packet loss rate
* is needed. It might not be very useful since there are not many use cases and

View File

@ -99,19 +99,19 @@ int16_t WebRtcOpus_SetPacketLossRate(OpusEncInst* inst, int32_t loss_rate) {
}
}
int16_t WebRtcOpus_SetMaxBandwidth(OpusEncInst* inst, int32_t bandwidth) {
int16_t WebRtcOpus_SetMaxPlaybackRate(OpusEncInst* inst, int32_t frequency_hz) {
opus_int32 set_bandwidth;
if (!inst)
return -1;
if (bandwidth <= 4000) {
if (frequency_hz <= 8000) {
set_bandwidth = OPUS_BANDWIDTH_NARROWBAND;
} else if (bandwidth <= 6000) {
} else if (frequency_hz <= 12000) {
set_bandwidth = OPUS_BANDWIDTH_MEDIUMBAND;
} else if (bandwidth <= 8000) {
} else if (frequency_hz <= 16000) {
set_bandwidth = OPUS_BANDWIDTH_WIDEBAND;
} else if (bandwidth <= 12000) {
} else if (frequency_hz <= 24000) {
set_bandwidth = OPUS_BANDWIDTH_SUPERWIDEBAND;
} else {
set_bandwidth = OPUS_BANDWIDTH_FULLBAND;

View File

@ -30,7 +30,7 @@ class OpusTest : public ::testing::Test {
OpusTest();
virtual void SetUp();
void TestSetMaxBandwidth(opus_int32 expect, int32_t set);
void TestSetMaxPlaybackRate(opus_int32 expect, int32_t set);
WebRtcOpusEncInst* opus_mono_encoder_;
WebRtcOpusEncInst* opus_stereo_encoder_;
@ -66,15 +66,15 @@ void OpusTest::SetUp() {
input_file = NULL;
}
void OpusTest::TestSetMaxBandwidth(opus_int32 expect, int32_t set) {
void OpusTest::TestSetMaxPlaybackRate(opus_int32 expect, int32_t set) {
opus_int32 bandwidth;
// Test mono encoder.
EXPECT_EQ(0, WebRtcOpus_SetMaxBandwidth(opus_mono_encoder_, set));
EXPECT_EQ(0, WebRtcOpus_SetMaxPlaybackRate(opus_mono_encoder_, set));
opus_encoder_ctl(opus_mono_encoder_->encoder,
OPUS_GET_MAX_BANDWIDTH(&bandwidth));
EXPECT_EQ(expect, bandwidth);
// Test stereo encoder.
EXPECT_EQ(0, WebRtcOpus_SetMaxBandwidth(opus_stereo_encoder_, set));
EXPECT_EQ(0, WebRtcOpus_SetMaxPlaybackRate(opus_stereo_encoder_, set));
opus_encoder_ctl(opus_stereo_encoder_->encoder,
OPUS_GET_MAX_BANDWIDTH(&bandwidth));
EXPECT_EQ(expect, bandwidth);
@ -355,22 +355,25 @@ TEST_F(OpusTest, OpusSetPacketLossRate) {
EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_stereo_encoder_));
}
TEST_F(OpusTest, OpusSetMaxBandwidth) {
TEST_F(OpusTest, OpusSetMaxPlaybackRate) {
// Test without creating encoder memory.
EXPECT_EQ(-1, WebRtcOpus_SetMaxBandwidth(opus_mono_encoder_, 20000));
EXPECT_EQ(-1, WebRtcOpus_SetMaxBandwidth(opus_stereo_encoder_, 20000));
EXPECT_EQ(-1, WebRtcOpus_SetMaxPlaybackRate(opus_mono_encoder_, 20000));
EXPECT_EQ(-1, WebRtcOpus_SetMaxPlaybackRate(opus_stereo_encoder_, 20000));
// Create encoder memory, try with different bitrates.
EXPECT_EQ(0, WebRtcOpus_EncoderCreate(&opus_mono_encoder_, 1));
EXPECT_EQ(0, WebRtcOpus_EncoderCreate(&opus_stereo_encoder_, 2));
TestSetMaxBandwidth(OPUS_BANDWIDTH_FULLBAND, 24000);
TestSetMaxBandwidth(OPUS_BANDWIDTH_FULLBAND, 14000);
TestSetMaxBandwidth(OPUS_BANDWIDTH_SUPERWIDEBAND, 10000);
TestSetMaxBandwidth(OPUS_BANDWIDTH_WIDEBAND, 7000);
TestSetMaxBandwidth(OPUS_BANDWIDTH_MEDIUMBAND, 6000);
TestSetMaxBandwidth(OPUS_BANDWIDTH_NARROWBAND, 4000);
TestSetMaxBandwidth(OPUS_BANDWIDTH_NARROWBAND, 3000);
TestSetMaxPlaybackRate(OPUS_BANDWIDTH_FULLBAND, 48000);
TestSetMaxPlaybackRate(OPUS_BANDWIDTH_FULLBAND, 24001);
TestSetMaxPlaybackRate(OPUS_BANDWIDTH_SUPERWIDEBAND, 24000);
TestSetMaxPlaybackRate(OPUS_BANDWIDTH_SUPERWIDEBAND, 16001);
TestSetMaxPlaybackRate(OPUS_BANDWIDTH_WIDEBAND, 16000);
TestSetMaxPlaybackRate(OPUS_BANDWIDTH_WIDEBAND, 12001);
TestSetMaxPlaybackRate(OPUS_BANDWIDTH_MEDIUMBAND, 12000);
TestSetMaxPlaybackRate(OPUS_BANDWIDTH_MEDIUMBAND, 8001);
TestSetMaxPlaybackRate(OPUS_BANDWIDTH_NARROWBAND, 8000);
TestSetMaxPlaybackRate(OPUS_BANDWIDTH_NARROWBAND, 4000);
// Free memory.
EXPECT_EQ(0, WebRtcOpus_EncoderFree(opus_mono_encoder_));

View File

@ -1000,9 +1000,9 @@ int16_t ACMGenericCodec::REDPayloadISAC(const int32_t /* isac_rate */,
return -1;
}
int ACMGenericCodec::SetOpusMaxBandwidth(int /* max_bandwidth */) {
int ACMGenericCodec::SetOpusMaxPlaybackRate(int /* frequency_hz */) {
WEBRTC_TRACE(webrtc::kTraceWarning, webrtc::kTraceAudioCoding, unique_id_,
"The send-codec is not Opus, failed to set maximum bandwidth.");
"The send-codec is not Opus, failed to set maximum playback rate.");
return -1;
}

View File

@ -538,21 +538,20 @@ class ACMGenericCodec {
int16_t* payload_len_bytes);
///////////////////////////////////////////////////////////////////////////
// int SetOpusMaxBandwidth()
// Sets maximum required encoding bandwidth for Opus. This is to tell Opus
// that it is enough to code the input audio up to a bandwidth. A use case of
// this is when the receiver cannot render the full band. Opus can take this
// information to optimize the bit rate and increase the computation
// efficiency.
// int SetOpusMaxPlaybackRate()
// Sets maximum playback rate the receiver will render, if the codec is Opus.
// This is to tell Opus that it is enough to code the input audio up to a
// bandwidth. Opus can take this information to optimize the bit rate and
// increase the computation efficiency.
//
// Input:
// -max_bandwidth : maximum required bandwidth.
// -frequency_hz : maximum playback rate in Hz.
//
// Return value:
// -1 if failed or on codecs other than Opus
// 0 if succeeded.
//
virtual int SetOpusMaxBandwidth(int /* max_bandwidth */);
virtual int SetOpusMaxPlaybackRate(int /* frequency_hz */);
///////////////////////////////////////////////////////////////////////////
// HasFrameToEncode()

View File

@ -263,9 +263,9 @@ int ACMOpus::SetPacketLossRate(int loss_rate) {
return -1;
}
int ACMOpus::SetOpusMaxBandwidth(int max_bandwidth) {
// Ask the encoder to change the maximum required bandwidth.
return WebRtcOpus_SetMaxBandwidth(encoder_inst_ptr_, max_bandwidth);
int ACMOpus::SetOpusMaxPlaybackRate(int frequency_hz) {
// Informs Opus encoder of the maximum playback rate the receiver will render.
return WebRtcOpus_SetMaxPlaybackRate(encoder_inst_ptr_, frequency_hz);
}
#endif // WEBRTC_CODEC_OPUS

View File

@ -38,7 +38,7 @@ class ACMOpus : public ACMGenericCodec {
virtual int SetPacketLossRate(int loss_rate) OVERRIDE;
virtual int SetOpusMaxBandwidth(int max_bandwidth) OVERRIDE;
virtual int SetOpusMaxPlaybackRate(int frequency_hz) OVERRIDE;
protected:
void DestructEncoderSafe();

View File

@ -1911,13 +1911,13 @@ int AudioCodingModuleImpl::ConfigISACBandwidthEstimator(
frame_size_ms, rate_bit_per_sec, enforce_frame_size);
}
// Informs Opus encoder about the maximum audio bandwidth needs to be encoded.
int AudioCodingModuleImpl::SetOpusMaxBandwidth(int bandwidth_hz) {
// Informs Opus encoder of the maximum playback rate the receiver will render.
int AudioCodingModuleImpl::SetOpusMaxPlaybackRate(int frequency_hz) {
CriticalSectionScoped lock(acm_crit_sect_);
if (!HaveValidEncoder("SetOpusMaxBandwidth")) {
if (!HaveValidEncoder("SetOpusMaxPlaybackRate")) {
return -1;
}
return codecs_[current_send_codec_idx_]->SetOpusMaxBandwidth(bandwidth_hz);
return codecs_[current_send_codec_idx_]->SetOpusMaxPlaybackRate(frequency_hz);
}
int AudioCodingModuleImpl::PlayoutTimestamp(uint32_t* timestamp) {

View File

@ -232,9 +232,9 @@ class AudioCodingModuleImpl : public AudioCodingModule {
int rate_bit_per_sec,
bool enforce_frame_size = false);
// If current send codec is Opus, informs it about the maximum audio
// bandwidth needs to be encoded.
int SetOpusMaxBandwidth(int bandwidth_hz);
// If current send codec is Opus, informs it about the maximum playback rate
// the receiver will render.
int SetOpusMaxPlaybackRate(int frequency_hz);
int UnregisterReceiveCodec(uint8_t payload_type);

View File

@ -916,21 +916,20 @@ class AudioCodingModule: public Module {
bool enforce_frame_size = false) = 0;
///////////////////////////////////////////////////////////////////////////
// int SetOpusMaxBandwidth()
// If current send codec is Opus, informs it about maximum audio bandwidth
// needs to be encoded. A use case of this is when the receiver can only play
// audio up to frequency limit. Opus can use this information to optimize
// the bit rate and increase the computation efficiency.
// int SetOpusMaxPlaybackRate()
// If current send codec is Opus, informs it about maximum playback rate the
// receiver will render. Opus can use this information to optimize the bit
// rate and increase the computation efficiency.
//
// Input:
// -banbwidth_hz : maximum bandwidth in Hz.
// -frequency_hz : maximum playback rate in Hz.
//
// Return value:
// -1 if current send codec is not Opus or
// error occurred in setting the bandwidth,
// error occurred in setting the maximum playback rate,
// 0 maximum bandwidth is set successfully.
//
virtual int SetOpusMaxBandwidth(int banbwidth_hz) = 0;
virtual int SetOpusMaxPlaybackRate(int frequency_hz) = 0;
///////////////////////////////////////////////////////////////////////////
// statistics

View File

@ -1751,14 +1751,14 @@ Channel::SetSendCNPayloadType(int type, PayloadFrequencies frequency)
return 0;
}
int Channel::SetOpusMaxBandwidth(int bandwidth_hz) {
int Channel::SetOpusMaxPlaybackRate(int frequency_hz) {
WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, _channelId),
"Channel::SetOpusMaxBandwidth()");
"Channel::SetOpusMaxPlaybackRate()");
if (audio_coding_->SetOpusMaxBandwidth(bandwidth_hz) != 0) {
if (audio_coding_->SetOpusMaxPlaybackRate(frequency_hz) != 0) {
_engineStatisticsPtr->SetLastError(
VE_AUDIO_CODING_MODULE_ERROR, kTraceError,
"SetOpusMaxBandwidth() failed to set maximum encoding bandwidth");
"SetOpusMaxPlaybackRate() failed to set maximum playback rate");
return -1;
}
return 0;

View File

@ -208,7 +208,7 @@ public:
int32_t SetRecPayloadType(const CodecInst& codec);
int32_t GetRecPayloadType(CodecInst& codec);
int32_t SetSendCNPayloadType(int type, PayloadFrequencies frequency);
int SetOpusMaxBandwidth(int bandwidth_hz);
int SetOpusMaxPlaybackRate(int frequency_hz);
// VoE dual-streaming.
int SetSecondarySendCodec(const CodecInst& codec, int red_payload_type);

View File

@ -126,11 +126,11 @@ public:
virtual int GetVADStatus(int channel, bool& enabled, VadModes& mode,
bool& disabledDTX) = 0;
// Sets the maximum audio bandwidth needs to be encoded in Hz,
// |bandwidth_hz|, for the Opus encoder on a specific |channel|.
// TODO(minyue): Make SetOpusMaxBandwidth() pure virtual when
// If send codec is Opus on a specified |channel|, sets the maximum playback
// rate the receiver will render: |frequency_hz| (in Hz).
// TODO(minyue): Make SetOpusMaxPlaybackRate() pure virtual when
// fakewebrtcvoiceengine in talk is ready.
virtual int SetOpusMaxBandwidth(int channel, int bandwidth_hz) {
virtual int SetOpusMaxPlaybackRate(int channel, int frequency_hz) {
return -1;
}

View File

@ -130,30 +130,30 @@ TEST_F(CodecTest, VoiceActivityDetectionCanBeTurnedOff) {
EXPECT_EQ(webrtc::kVadConventional, vad_mode);
}
TEST_F(CodecTest, OpusMaxBandwidthCanBeSet) {
TEST_F(CodecTest, OpusMaxPlaybackRateCanBeSet) {
for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) {
voe_codec_->GetCodec(i, codec_instance_);
if (_stricmp("opus", codec_instance_.plname)) {
continue;
}
voe_codec_->SetSendCodec(channel_, codec_instance_);
// SetOpusMaxBandwidth can handle any integer as the bandwidth. Following
// SetOpusMaxPlaybackRate can handle any integer as the bandwidth. Following
// tests some most commonly used numbers.
EXPECT_EQ(0, voe_codec_->SetOpusMaxBandwidth(channel_, 24000));
EXPECT_EQ(0, voe_codec_->SetOpusMaxBandwidth(channel_, 16000));
EXPECT_EQ(0, voe_codec_->SetOpusMaxBandwidth(channel_, 8000));
EXPECT_EQ(0, voe_codec_->SetOpusMaxBandwidth(channel_, 4000));
EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 48000));
EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 32000));
EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 16000));
EXPECT_EQ(0, voe_codec_->SetOpusMaxPlaybackRate(channel_, 8000));
}
}
TEST_F(CodecTest, OpusMaxBandwidthCannotBeSetForNonOpus) {
TEST_F(CodecTest, OpusMaxPlaybackRateCannotBeSetForNonOpus) {
for (int i = 0; i < voe_codec_->NumOfCodecs(); ++i) {
voe_codec_->GetCodec(i, codec_instance_);
if (!_stricmp("opus", codec_instance_.plname)) {
continue;
}
voe_codec_->SetSendCodec(channel_, codec_instance_);
EXPECT_EQ(-1, voe_codec_->SetOpusMaxBandwidth(channel_, 16000));
EXPECT_EQ(-1, voe_codec_->SetOpusMaxPlaybackRate(channel_, 16000));
}
}

View File

@ -445,7 +445,7 @@ void RunTest(std::string out_path) {
printf("%i. Remove a file-playing channel \n", option_index++);
printf("%i. Toggle Opus stereo (Opus must be selected again to apply "
"the setting) \n", option_index++);
printf("%i. Set Opus maximum audio bandwidth \n", option_index++);
printf("%i. Set Opus maximum playback rate \n", option_index++);
printf("%i. Set bit rate (only take effect on codecs that allow the "
"change) \n", option_index++);
@ -761,10 +761,10 @@ void RunTest(std::string out_path) {
printf("\n Opus mono enabled (select Opus again to apply the "
"setting). \n");
} else if (option_selection == option_index++) {
printf("\n Input bandwidth in Hz: ");
printf("\n Input maxium playback rate in Hz: ");
int max_playback_rate;
ASSERT_EQ(1, scanf("%i", &max_playback_rate));
res = codec->SetOpusMaxBandwidth(chan, max_playback_rate);
res = codec->SetOpusMaxPlaybackRate(chan, max_playback_rate);
VALIDATE;
} else if (option_selection == option_index++) {
res = codec->GetSendCodec(chan, cinst);

View File

@ -418,10 +418,10 @@ int VoECodecImpl::GetVADStatus(int channel, bool& enabled, VadModes& mode,
return 0;
}
int VoECodecImpl::SetOpusMaxBandwidth(int channel, int bandwidth_hz) {
int VoECodecImpl::SetOpusMaxPlaybackRate(int channel, int frequency_hz) {
WEBRTC_TRACE(kTraceApiCall, kTraceVoice, VoEId(_shared->instance_id(), -1),
"SetOpusMaxBandwidth(channel=%d, bandwidth_hz=%d)", channel,
bandwidth_hz);
"SetOpusMaxPlaybackRate(channel=%d, frequency_hz=%d)", channel,
frequency_hz);
if (!_shared->statistics().Initialized()) {
_shared->SetLastError(VE_NOT_INITED, kTraceError);
return -1;
@ -430,10 +430,10 @@ int VoECodecImpl::SetOpusMaxBandwidth(int channel, int bandwidth_hz) {
voe::Channel* channelPtr = ch.channel();
if (channelPtr == NULL) {
_shared->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError,
"SetOpusMaxBandwidth failed to locate channel");
"SetOpusMaxPlaybackRate failed to locate channel");
return -1;
}
return channelPtr->SetOpusMaxBandwidth(bandwidth_hz);
return channelPtr->SetOpusMaxPlaybackRate(frequency_hz);
}
void VoECodecImpl::ACMToExternalCodecRepresentation(CodecInst& toInst,

View File

@ -54,7 +54,7 @@ public:
VadModes& mode,
bool& disabledDTX);
virtual int SetOpusMaxBandwidth(int channel, int bandwidth_hz);
virtual int SetOpusMaxPlaybackRate(int channel, int frequency_hz);
// Dual-streaming
virtual int SetSecondarySendCodec(int channel, const CodecInst& codec,