Let Add10MsData method do the encoding work as well
This change essentially makes the Process method a no-op. All it does
now is to return a stored value from the last encoding.
The purpose of this change is to forge the Add... and Process methods
into one and the same.
BUG=3520
COAUTHOR=kwiberg@webrtc.org
R=minyue@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/38229004
Cr-Commit-Position: refs/heads/master@{#8499}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8499 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc
index bf9bb01..ddc3681 100644
--- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc
+++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.cc
@@ -145,10 +145,10 @@
aux_rtp_header_(NULL),
receiver_initialized_(false),
first_10ms_data_(false),
+ last_encode_value_(0),
callback_crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
packetization_callback_(NULL),
vad_callback_(NULL) {
-
// Nullify send codec memory, set payload type and set codec name to
// invalid values.
const char no_name[] = "noCodecRegistered";
@@ -231,8 +231,12 @@
// (send_codec_inst_.plfreq / 1000);
}
-// Process any pending tasks such as timeouts.
int32_t AudioCodingModuleImpl::Process() {
+ CriticalSectionScoped lock(acm_crit_sect_);
+ return last_encode_value_;
+}
+
+int32_t AudioCodingModuleImpl::Encode() {
// Make room for 1 RED payload.
uint8_t stream[2 * MAX_PAYLOAD_SIZE_BYTE];
// TODO(turajs): |length_bytes| & |red_length_bytes| can be of type int if
@@ -758,8 +762,20 @@
}
// Add 10MS of raw (PCM) audio data to the encoder.
-int AudioCodingModuleImpl::Add10MsData(
- const AudioFrame& audio_frame) {
+int AudioCodingModuleImpl::Add10MsData(const AudioFrame& audio_frame) {
+ int r = Add10MsDataInternal(audio_frame);
+ if (r < 0) {
+ CriticalSectionScoped lock(acm_crit_sect_);
+ last_encode_value_ = -1;
+ } else {
+ int r_encode = Encode();
+ CriticalSectionScoped lock(acm_crit_sect_);
+ last_encode_value_ = r_encode;
+ }
+ return r;
+}
+
+int AudioCodingModuleImpl::Add10MsDataInternal(const AudioFrame& audio_frame) {
if (audio_frame.samples_per_channel_ <= 0) {
assert(false);
WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceAudioCoding, id_,
diff --git a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h
index 3fc00ac..191fa69 100644
--- a/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h
+++ b/webrtc/modules/audio_coding/main/acm2/audio_coding_module_impl.h
@@ -240,6 +240,9 @@
AudioDecodingCallStats* stats) const OVERRIDE;
private:
+ int Add10MsDataInternal(const AudioFrame& audio_frame);
+ int Encode();
+
ACMGenericCodec* CreateCodec(const CodecInst& codec);
int InitializeReceiverSafe() EXCLUSIVE_LOCKS_REQUIRED(acm_crit_sect_);
@@ -336,6 +339,7 @@
AudioFrame preprocess_frame_ GUARDED_BY(acm_crit_sect_);
bool first_10ms_data_ GUARDED_BY(acm_crit_sect_);
+ int last_encode_value_ GUARDED_BY(acm_crit_sect_);
CriticalSectionWrapper* callback_crit_sect_;
AudioPacketizationCallback* packetization_callback_