Adding SetOpusMaxBandwidth in VoE and ACM

This is a step to solve
https://code.google.com/p/webrtc/issues/detail?id=1906

In particular, we add an API in VoE and ACM to call Opus's API of setting maximum bandwidth.

TEST = added a test in voe_cmd_test and listened to the result

BUG=
R=henrika@google.com, henrika@webrtc.org, turaj@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6869 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
minyue@webrtc.org
2014-08-12 08:13:33 +00:00
parent c98ce3b34c
commit 6aac93bd9c
14 changed files with 136 additions and 0 deletions

View File

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

View File

@ -537,6 +537,23 @@ class ACMGenericCodec {
uint8_t* payload,
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.
//
// Input:
// -max_bandwidth : maximum required bandwidth.
//
// Return value:
// -1 if failed or on codecs other than Opus
// 0 if succeeded.
//
virtual int SetOpusMaxBandwidth(int /* max_bandwidth */);
///////////////////////////////////////////////////////////////////////////
// HasFrameToEncode()
// Returns true if there is enough audio buffered for encoding, such that

View File

@ -261,6 +261,11 @@ 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);
}
#endif // WEBRTC_CODEC_OPUS
} // namespace acm2

View File

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

View File

@ -1911,6 +1911,15 @@ 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) {
CriticalSectionScoped lock(acm_crit_sect_);
if (!HaveValidEncoder("SetOpusMaxBandwidth")) {
return -1;
}
return codecs_[current_send_codec_idx_]->SetOpusMaxBandwidth(bandwidth_hz);
}
int AudioCodingModuleImpl::PlayoutTimestamp(uint32_t* timestamp) {
return receiver_.GetPlayoutTimestamp(timestamp) ? 0 : -1;
}

View File

@ -232,6 +232,10 @@ 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);
int UnregisterReceiveCodec(uint8_t payload_type);
int EnableNack(size_t max_nack_list_size);

View File

@ -915,6 +915,23 @@ class AudioCodingModule: public Module {
int init_rate_bps,
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.
//
// Input:
// -banbwidth_hz : maximum bandwidth in Hz.
//
// Return value:
// -1 if current send codec is not Opus or
// error occurred in setting the bandwidth,
// 0 maximum bandwidth is set successfully.
//
virtual int SetOpusMaxBandwidth(int banbwidth_hz) = 0;
///////////////////////////////////////////////////////////////////////////
// statistics
//