Set NetEq playout mode through the Config struct
This change opens up the possibility to set the playout mode when
creating the NetEq object. The old methods SetPlayoutMode and
PlayoutMode are still available, but are deprecated.
BUG=3520
R=turaj@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/23869004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@7381 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/modules/audio_coding/neteq/interface/neteq.h b/webrtc/modules/audio_coding/neteq/interface/neteq.h
index 7196bc1..925cb23 100644
--- a/webrtc/modules/audio_coding/neteq/interface/neteq.h
+++ b/webrtc/modules/audio_coding/neteq/interface/neteq.h
@@ -74,13 +74,15 @@
max_packets_in_buffer(50),
// |max_delay_ms| has the same effect as calling SetMaximumDelay().
max_delay_ms(2000),
- background_noise_mode(kBgnOff) {}
+ background_noise_mode(kBgnOff),
+ playout_mode(kPlayoutOn) {}
int sample_rate_hz; // Initial vale. Will change with input data.
bool enable_audio_classifier;
int max_packets_in_buffer;
int max_delay_ms;
BackgroundNoiseMode background_noise_mode;
+ NetEqPlayoutMode playout_mode;
};
enum ReturnCodes {
@@ -202,9 +204,13 @@
virtual int CurrentDelay() = 0;
// Sets the playout mode to |mode|.
+ // Deprecated. Set the mode in the Config struct passed to the constructor.
+ // TODO(henrik.lundin) Delete.
virtual void SetPlayoutMode(NetEqPlayoutMode mode) = 0;
// Returns the current playout mode.
+ // Deprecated.
+ // TODO(henrik.lundin) Delete.
virtual NetEqPlayoutMode PlayoutMode() const = 0;
// Writes the current network statistics to |stats|. The statistics are reset
diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.cc b/webrtc/modules/audio_coding/neteq/neteq_impl.cc
index d714733..edf618e 100644
--- a/webrtc/modules/audio_coding/neteq/neteq_impl.cc
+++ b/webrtc/modules/audio_coding/neteq/neteq_impl.cc
@@ -91,6 +91,7 @@
error_code_(0),
decoder_error_code_(0),
background_noise_mode_(config.background_noise_mode),
+ playout_mode_(config.playout_mode),
decoded_packet_sequence_number_(-1),
decoded_packet_timestamp_(0) {
int fs = config.sample_rate_hz;
@@ -278,18 +279,21 @@
return delay_manager_->least_required_delay_ms();
}
+// Deprecated.
+// TODO(henrik.lundin) Delete.
void NetEqImpl::SetPlayoutMode(NetEqPlayoutMode mode) {
CriticalSectionScoped lock(crit_sect_.get());
- if (!decision_logic_.get() || mode != decision_logic_->playout_mode()) {
- // The reset() method calls delete for the old object.
- CreateDecisionLogic(mode);
+ if (mode != playout_mode_) {
+ playout_mode_ = mode;
+ CreateDecisionLogic();
}
}
+// Deprecated.
+// TODO(henrik.lundin) Delete.
NetEqPlayoutMode NetEqImpl::PlayoutMode() const {
CriticalSectionScoped lock(crit_sect_.get());
- assert(decision_logic_.get());
- return decision_logic_->playout_mode();
+ return playout_mode_;
}
int NetEqImpl::NetworkStatistics(NetEqNetworkStatistics* stats) {
@@ -1904,7 +1908,7 @@
// Create DecisionLogic if it is not created yet, then communicate new sample
// rate and output size to DecisionLogic object.
if (!decision_logic_.get()) {
- CreateDecisionLogic(kPlayoutOn);
+ CreateDecisionLogic();
}
decision_logic_->SetSampleRate(fs_hz_, output_size_samples_);
}
@@ -1926,9 +1930,9 @@
}
}
-void NetEqImpl::CreateDecisionLogic(NetEqPlayoutMode mode) {
+void NetEqImpl::CreateDecisionLogic() {
decision_logic_.reset(DecisionLogic::Create(fs_hz_, output_size_samples_,
- mode,
+ playout_mode_,
decoder_database_.get(),
*packet_buffer_.get(),
delay_manager_.get(),
diff --git a/webrtc/modules/audio_coding/neteq/neteq_impl.h b/webrtc/modules/audio_coding/neteq/neteq_impl.h
index cfe6a40..fc2284d 100644
--- a/webrtc/modules/audio_coding/neteq/neteq_impl.h
+++ b/webrtc/modules/audio_coding/neteq/neteq_impl.h
@@ -138,9 +138,13 @@
virtual int CurrentDelay() OVERRIDE { return kNotImplemented; }
// Sets the playout mode to |mode|.
+ // Deprecated.
+ // TODO(henrik.lundin) Delete.
virtual void SetPlayoutMode(NetEqPlayoutMode mode) OVERRIDE;
// Returns the current playout mode.
+ // Deprecated.
+ // TODO(henrik.lundin) Delete.
virtual NetEqPlayoutMode PlayoutMode() const OVERRIDE;
// Writes the current network statistics to |stats|. The statistics are reset
@@ -327,9 +331,8 @@
virtual void UpdatePlcComponents(int fs_hz, size_t channels)
EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
- // Creates DecisionLogic object for the given mode.
- virtual void CreateDecisionLogic(NetEqPlayoutMode mode)
- EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ // Creates DecisionLogic object with the mode given by |playout_mode_|.
+ virtual void CreateDecisionLogic() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
const scoped_ptr<CriticalSectionWrapper> crit_sect_;
const scoped_ptr<BufferLevelFilter> buffer_level_filter_
@@ -383,6 +386,7 @@
int error_code_ GUARDED_BY(crit_sect_); // Store last error code.
int decoder_error_code_ GUARDED_BY(crit_sect_);
const BackgroundNoiseMode background_noise_mode_ GUARDED_BY(crit_sect_);
+ NetEqPlayoutMode playout_mode_ GUARDED_BY(crit_sect_);
// These values are used by NACK module to estimate time-to-play of
// a missing packet. Occasionally, NetEq might decide to decode more
diff --git a/webrtc/modules/audio_coding/neteq/neteq_unittest.cc b/webrtc/modules/audio_coding/neteq/neteq_unittest.cc
index 256c557..4a7dbec 100644
--- a/webrtc/modules/audio_coding/neteq/neteq_unittest.cc
+++ b/webrtc/modules/audio_coding/neteq/neteq_unittest.cc
@@ -442,12 +442,16 @@
}
}
-// TODO(hlundin): Re-enable test once the statistics interface is up and again.
-TEST_F(NetEqDecodingTest, TestFrameWaitingTimeStatistics) {
- // Use fax mode to avoid time-scaling. This is to simplify the testing of
- // packet waiting times in the packet buffer.
- neteq_->SetPlayoutMode(kPlayoutFax);
- ASSERT_EQ(kPlayoutFax, neteq_->PlayoutMode());
+// Use fax mode to avoid time-scaling. This is to simplify the testing of
+// packet waiting times in the packet buffer.
+class NetEqDecodingTestFaxMode : public NetEqDecodingTest {
+ protected:
+ NetEqDecodingTestFaxMode() : NetEqDecodingTest() {
+ config_.playout_mode = kPlayoutFax;
+ }
+};
+
+TEST_F(NetEqDecodingTestFaxMode, TestFrameWaitingTimeStatistics) {
// Insert 30 dummy packets at once. Each packet contains 10 ms 16 kHz audio.
size_t num_frames = 30;
const int kSamples = 10 * 16;