summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/webrtc/modules/audio_coding/main/source/audio_coding_module_impl.cc
diff options
context:
space:
mode:
authorAndras Becsi <andras.becsi@digia.com>2013-12-11 21:33:03 +0100
committerAndras Becsi <andras.becsi@digia.com>2013-12-13 12:34:07 +0100
commitf2a33ff9cbc6d19943f1c7fbddd1f23d23975577 (patch)
tree0586a32aa390ade8557dfd6b4897f43a07449578 /chromium/third_party/webrtc/modules/audio_coding/main/source/audio_coding_module_impl.cc
parent5362912cdb5eea702b68ebe23702468d17c3017a (diff)
Update Chromium to branch 1650 (31.0.1650.63)
Change-Id: I57d8c832eaec1eb2364e0a8e7352a6dd354db99f Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'chromium/third_party/webrtc/modules/audio_coding/main/source/audio_coding_module_impl.cc')
-rw-r--r--chromium/third_party/webrtc/modules/audio_coding/main/source/audio_coding_module_impl.cc208
1 files changed, 55 insertions, 153 deletions
diff --git a/chromium/third_party/webrtc/modules/audio_coding/main/source/audio_coding_module_impl.cc b/chromium/third_party/webrtc/modules/audio_coding/main/source/audio_coding_module_impl.cc
index f35ec04c2fc..f5f84505fe3 100644
--- a/chromium/third_party/webrtc/modules/audio_coding/main/source/audio_coding_module_impl.cc
+++ b/chromium/third_party/webrtc/modules/audio_coding/main/source/audio_coding_module_impl.cc
@@ -17,7 +17,7 @@
#include "webrtc/engine_configurations.h"
#include "webrtc/modules/audio_coding/main/source/acm_codec_database.h"
-#include "webrtc/modules/audio_coding/main/source/acm_common_defs.h"
+#include "webrtc/modules/audio_coding/main/acm2/acm_common_defs.h"
#include "webrtc/modules/audio_coding/main/source/acm_dtmf_detection.h"
#include "webrtc/modules/audio_coding/main/source/acm_generic_codec.h"
#include "webrtc/modules/audio_coding/main/source/acm_resampler.h"
@@ -32,6 +32,8 @@
namespace webrtc {
+namespace acm1 {
+
enum {
kACMToneEnd = 999
};
@@ -574,7 +576,7 @@ int AudioCodingModuleImpl::ProcessSingleStream() {
}
case kActiveNormalEncoded:
case kPassiveNormalEncoded: {
- current_payload_type = (uint8_t) send_codec_inst_.pltype;
+ current_payload_type = static_cast<uint8_t>(send_codec_inst_.pltype);
frame_type = kAudioFrameSpeech;
break;
}
@@ -662,8 +664,8 @@ int AudioCodingModuleImpl::ProcessSingleStream() {
fragmentation_.fragmentationLength[1]);
// Update the fragmentation time difference vector, in number of
// timestamps.
- uint16_t time_since_last = uint16_t(
- rtp_timestamp - last_fec_timestamp_);
+ uint16_t time_since_last = static_cast<uint16_t>(rtp_timestamp -
+ last_fec_timestamp_);
// Update fragmentation vectors.
fragmentation_.fragmentationPlType[1] =
@@ -736,7 +738,7 @@ int AudioCodingModuleImpl::ProcessSingleStream() {
if (vad_callback_ != NULL) {
// Callback with VAD decision.
- vad_callback_->InFrameType(((int16_t) encoding_type));
+ vad_callback_->InFrameType(static_cast<int16_t>(encoding_type));
}
}
return length_bytes;
@@ -1060,7 +1062,6 @@ int32_t AudioCodingModuleImpl::RegisterSendCodec(
}
ACMGenericCodec* codec_ptr = codecs_[codec_id];
- int16_t status;
WebRtcACMCodecParams codec_params;
memcpy(&(codec_params.codec_inst), &send_codec, sizeof(CodecInst));
@@ -1068,12 +1069,7 @@ int32_t AudioCodingModuleImpl::RegisterSendCodec(
codec_params.enable_dtx = dtx_enabled_;
codec_params.vad_mode = vad_mode_;
// Force initialization.
- status = codec_ptr->InitEncoder(&codec_params, true);
-
- // Check if VAD was turned on, or if error is reported.
- if (status == 1) {
- vad_enabled_ = true;
- } else if (status < 0) {
+ if (codec_ptr->InitEncoder(&codec_params, true) < 0) {
// Could not initialize the encoder.
// Check if already have a registered codec.
@@ -1090,17 +1086,18 @@ int32_t AudioCodingModuleImpl::RegisterSendCodec(
return -1;
}
+ // Update states.
+ dtx_enabled_ = codec_params.enable_dtx;
+ vad_enabled_ = codec_params.enable_vad;
+ vad_mode_ = codec_params.vad_mode;
+
// Everything is fine so we can replace the previous codec with this one.
if (send_codec_registered_) {
// If we change codec we start fresh with FEC.
// This is not strictly required by the standard.
is_first_red_ = true;
- if (codec_ptr->SetVAD(dtx_enabled_, vad_enabled_, vad_mode_) < 0) {
- // SetVAD failed.
- vad_enabled_ = false;
- dtx_enabled_ = false;
- }
+ codec_ptr->SetVAD(&dtx_enabled_, &vad_enabled_, &vad_mode_);
}
current_send_codec_idx_ = codec_id;
@@ -1265,64 +1262,6 @@ int32_t AudioCodingModuleImpl::RegisterTransportCallback(
return 0;
}
-// Used by the module to deliver messages to the codec module/application
-// AVT(DTMF).
-int32_t AudioCodingModuleImpl::RegisterIncomingMessagesCallback(
-#ifndef WEBRTC_DTMF_DETECTION
- AudioCodingFeedback* /* incoming_message */,
- const ACMCountries /* cpt */) {
- return -1;
-#else
- AudioCodingFeedback* incoming_message,
- const ACMCountries cpt) {
- int16_t status = 0;
-
- // Enter the critical section for callback.
- {
- CriticalSectionScoped lock(callback_crit_sect_);
- dtmf_callback_ = incoming_message;
- }
- // Enter the ACM critical section to set up the DTMF class.
- {
- CriticalSectionScoped lock(acm_crit_sect_);
- // Check if the call is to disable or enable the callback.
- if (incoming_message == NULL) {
- // Callback is disabled, delete DTMF-detector class.
- if (dtmf_detector_ != NULL) {
- delete dtmf_detector_;
- dtmf_detector_ = NULL;
- }
- status = 0;
- } else {
- status = 0;
- if (dtmf_detector_ == NULL) {
- dtmf_detector_ = new ACMDTMFDetection;
- if (dtmf_detector_ == NULL) {
- status = -1;
- }
- }
- if (status >= 0) {
- status = dtmf_detector_->Enable(cpt);
- if (status < 0) {
- // Failed to initialize if DTMF-detection was not enabled before,
- // delete the class, and set the callback to NULL and return -1.
- delete dtmf_detector_;
- dtmf_detector_ = NULL;
- }
- }
- }
- }
- // Check if we failed in setting up the DTMF-detector class.
- if ((status < 0)) {
- // We failed, we cannot have the callback.
- CriticalSectionScoped lock(callback_crit_sect_);
- dtmf_callback_ = NULL;
- }
-
- return status;
-#endif
-}
-
// Add 10MS of raw (PCM) audio data to the encoder.
int32_t AudioCodingModuleImpl::Add10MsData(
const AudioFrame& audio_frame) {
@@ -1436,8 +1375,8 @@ int AudioCodingModuleImpl::PreprocessToAddData(const AudioFrame& in_frame,
assert((secondary_encoder_.get() != NULL) ?
secondary_send_codec_inst_.plfreq == send_codec_inst_.plfreq : true);
- bool resample = ((int32_t) in_frame.sample_rate_hz_
- != send_codec_inst_.plfreq);
+ bool resample = static_cast<int32_t>(in_frame.sample_rate_hz_) !=
+ send_codec_inst_.plfreq;
// This variable is true if primary codec and secondary codec (if exists)
// are both mono and input is stereo.
@@ -1489,8 +1428,8 @@ int AudioCodingModuleImpl::PreprocessToAddData(const AudioFrame& in_frame,
// Calculate the timestamp of this frame.
if (last_in_timestamp_ > in_frame.timestamp_) {
// A wrap around has happened.
- timestamp_diff = ((uint32_t) 0xFFFFFFFF - last_in_timestamp_)
- + in_frame.timestamp_;
+ timestamp_diff = (static_cast<uint32_t>(0xFFFFFFFF) - last_in_timestamp_)
+ + in_frame.timestamp_;
} else {
timestamp_diff = in_frame.timestamp_ - last_in_timestamp_;
}
@@ -1556,15 +1495,13 @@ AudioCodingModuleImpl::SetFECStatus(
/////////////////////////////////////////
// (VAD) Voice Activity Detection
//
-int32_t AudioCodingModuleImpl::SetVAD(const bool enable_dtx,
- const bool enable_vad,
- const ACMVADMode mode) {
+int32_t AudioCodingModuleImpl::SetVAD(bool enable_dtx, bool enable_vad,
+ ACMVADMode mode) {
CriticalSectionScoped lock(acm_crit_sect_);
return SetVADSafe(enable_dtx, enable_vad, mode);
}
-int AudioCodingModuleImpl::SetVADSafe(bool enable_dtx,
- bool enable_vad,
+int AudioCodingModuleImpl::SetVADSafe(bool enable_dtx, bool enable_vad,
ACMVADMode mode) {
// Sanity check of the mode.
if ((mode != VADNormal) && (mode != VADLowBitrate)
@@ -1579,7 +1516,10 @@ int AudioCodingModuleImpl::SetVADSafe(bool enable_dtx,
// sending.
if ((enable_dtx || enable_vad) && stereo_send_) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
- "VAD/DTX not supported for stereo sending");
+ "VAD/DTX not supported for stereo sending.");
+ dtx_enabled_ = false;
+ vad_enabled_ = false;
+ vad_mode_ = mode;
return -1;
}
@@ -1588,37 +1528,31 @@ int AudioCodingModuleImpl::SetVADSafe(bool enable_dtx,
if ((enable_dtx || enable_vad) && secondary_encoder_.get() != NULL) {
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
"VAD/DTX not supported when dual-streaming is enabled.");
+ dtx_enabled_ = false;
+ vad_enabled_ = false;
+ vad_mode_ = mode;
return -1;
}
+ // Store VAD/DTX settings. Values can be changed in the call to "SetVAD"
+ // below.
+ dtx_enabled_ = enable_dtx;
+ vad_enabled_ = enable_vad;
+ vad_mode_ = mode;
+
// If a send codec is registered, set VAD/DTX for the codec.
if (HaveValidEncoder("SetVAD")) {
- int16_t status = codecs_[current_send_codec_idx_]->SetVAD(enable_dtx,
- enable_vad,
- mode);
- if (status == 1) {
- // Vad was enabled.
- vad_enabled_ = true;
- dtx_enabled_ = enable_dtx;
- vad_mode_ = mode;
-
- return 0;
- } else if (status < 0) {
+ if (codecs_[current_send_codec_idx_]->SetVAD(&dtx_enabled_, &vad_enabled_,
+ &vad_mode_) < 0) {
// SetVAD failed.
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
"SetVAD failed");
-
- vad_enabled_ = false;
dtx_enabled_ = false;
-
+ vad_enabled_ = false;
return -1;
}
}
- vad_enabled_ = enable_vad;
- dtx_enabled_ = enable_dtx;
- vad_mode_ = mode;
-
return 0;
}
@@ -2205,13 +2139,7 @@ int AudioCodingModuleImpl::InitStereoSlave() {
return 0;
}
-// Minimum playout delay (Used for lip-sync).
int AudioCodingModuleImpl::SetMinimumPlayoutDelay(int time_ms) {
- if ((time_ms < 0) || (time_ms > 10000)) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
- "Delay must be in the range of 0-10000 milliseconds.");
- return -1;
- }
{
CriticalSectionScoped lock(acm_crit_sect_);
// Don't let the extra delay modified while accumulating buffers in NetEq.
@@ -2221,6 +2149,10 @@ int AudioCodingModuleImpl::SetMinimumPlayoutDelay(int time_ms) {
return neteq_.SetMinimumDelay(time_ms);
}
+int AudioCodingModuleImpl::SetMaximumPlayoutDelay(int time_ms) {
+ return neteq_.SetMaximumDelay(time_ms);
+}
+
// Get Dtmf playout status.
bool AudioCodingModuleImpl::DtmfPlayoutStatus() const {
#ifndef WEBRTC_CODEC_AVT
@@ -2381,7 +2313,7 @@ int32_t AudioCodingModuleImpl::PlayoutData10Ms(
}
// Set the payload data length from the resampler.
- audio_frame->samples_per_channel_ = (uint16_t) temp_len;
+ audio_frame->samples_per_channel_ = static_cast<uint16_t>(temp_len);
// Set the sampling frequency.
audio_frame->sample_rate_hz_ = desired_freq_hz;
} else {
@@ -2455,11 +2387,12 @@ int32_t AudioCodingModuleImpl::PlayoutData10Ms(
if (dtmf_callback_ != NULL) {
if (tone != kACMToneEnd) {
// just a tone
- dtmf_callback_->IncomingDtmf((uint8_t) tone, false);
+ dtmf_callback_->IncomingDtmf(static_cast<uint8_t>(tone), false);
} else if ((tone == kACMToneEnd) && (last_detected_tone != kACMToneEnd)) {
// The tone is "END" and the previously detected tone is
// not "END," so call fir an end.
- dtmf_callback_->IncomingDtmf((uint8_t) last_detected_tone, true);
+ dtmf_callback_->IncomingDtmf(static_cast<uint8_t>(last_detected_tone),
+ true);
}
}
}
@@ -2472,26 +2405,11 @@ int32_t AudioCodingModuleImpl::PlayoutData10Ms(
}
/////////////////////////////////////////
-// (CNG) Comfort Noise Generation
-// Generate comfort noise when receiving DTX packets
-//
-
-// Get VAD aggressiveness on the incoming stream
-ACMVADMode AudioCodingModuleImpl::ReceiveVADMode() const {
- return neteq_.vad_mode();
-}
-
-// Configure VAD aggressiveness on the incoming stream.
-int16_t AudioCodingModuleImpl::SetReceiveVADMode(const ACMVADMode mode) {
- return neteq_.SetVADMode(mode);
-}
-
-/////////////////////////////////////////
// Statistics
//
int32_t AudioCodingModuleImpl::NetworkStatistics(
- ACMNetworkStatistics* statistics) const {
+ ACMNetworkStatistics* statistics) {
int32_t status;
status = neteq_.NetworkStatistics(statistics);
return status;
@@ -2660,7 +2578,7 @@ int16_t AudioCodingModuleImpl::DecoderListIDByPlName(
assert(registered_pltypes_[id] >= 0);
assert(registered_pltypes_[id] <= 255);
codecs_[id]->DecoderParams(
- &codec_params, (uint8_t) registered_pltypes_[id]);
+ &codec_params, static_cast<uint8_t>(registered_pltypes_[id]));
if (!STR_CASE_CMP(codec_params.codec_inst.plname, name)) {
// Check if the given sampling frequency matches.
// A zero sampling frequency means we matching the names
@@ -2731,8 +2649,7 @@ int32_t AudioCodingModuleImpl::IsInternalDTXReplacedWithWebRtc(
return 0;
}
-int32_t AudioCodingModuleImpl::SetISACMaxRate(
- const uint32_t max_bit_per_sec) {
+int AudioCodingModuleImpl::SetISACMaxRate(int max_bit_per_sec) {
CriticalSectionScoped lock(acm_crit_sect_);
if (!HaveValidEncoder("SetISACMaxRate")) {
@@ -2742,8 +2659,7 @@ int32_t AudioCodingModuleImpl::SetISACMaxRate(
return codecs_[current_send_codec_idx_]->SetISACMaxRate(max_bit_per_sec);
}
-int32_t AudioCodingModuleImpl::SetISACMaxPayloadSize(
- const uint16_t max_size_bytes) {
+int AudioCodingModuleImpl::SetISACMaxPayloadSize(int max_size_bytes) {
CriticalSectionScoped lock(acm_crit_sect_);
if (!HaveValidEncoder("SetISACMaxPayloadSize")) {
@@ -2755,9 +2671,9 @@ int32_t AudioCodingModuleImpl::SetISACMaxPayloadSize(
}
int32_t AudioCodingModuleImpl::ConfigISACBandwidthEstimator(
- const uint8_t frame_size_ms,
- const uint16_t rate_bit_per_sec,
- const bool enforce_frame_size) {
+ int frame_size_ms,
+ int rate_bit_per_sec,
+ bool enforce_frame_size) {
CriticalSectionScoped lock(acm_crit_sect_);
if (!HaveValidEncoder("ConfigISACBandwidthEstimator")) {
@@ -2768,21 +2684,6 @@ int32_t AudioCodingModuleImpl::ConfigISACBandwidthEstimator(
frame_size_ms, rate_bit_per_sec, enforce_frame_size);
}
-int32_t AudioCodingModuleImpl::SetBackgroundNoiseMode(
- const ACMBackgroundNoiseMode mode) {
- if ((mode < On) || (mode > Off)) {
- WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
- "The specified background noise is out of range.\n");
- return -1;
- }
- return neteq_.SetBackgroundNoiseMode(mode);
-}
-
-int32_t AudioCodingModuleImpl::BackgroundNoiseMode(
- ACMBackgroundNoiseMode* mode) {
- return neteq_.BackgroundNoiseMode(*mode);
-}
-
int32_t AudioCodingModuleImpl::PlayoutTimestamp(
uint32_t* timestamp) {
WEBRTC_TRACE(webrtc::kTraceStream, webrtc::kTraceAudioCoding, id_,
@@ -2818,8 +2719,7 @@ bool AudioCodingModuleImpl::HaveValidEncoder(const char* caller_name) const {
return true;
}
-int32_t AudioCodingModuleImpl::UnregisterReceiveCodec(
- const int16_t payload_type) {
+int AudioCodingModuleImpl::UnregisterReceiveCodec(uint8_t payload_type) {
CriticalSectionScoped lock(acm_crit_sect_);
int id;
@@ -3126,4 +3026,6 @@ void AudioCodingModuleImpl::DisableNack() {
nack_enabled_ = false;
}
+} // namespace acm1
+
} // namespace webrtc