Set the stream delay to zero if too low.

- Return a stream warning instead of an error.
- Add a few delay offset tests.

BUG=
TEST=audioproc_unittest

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@2316 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/src/modules/audio_processing/audio_processing_impl.cc b/src/modules/audio_processing/audio_processing_impl.cc
index 27a5ada..74363ee 100644
--- a/src/modules/audio_processing/audio_processing_impl.cc
+++ b/src/modules/audio_processing/audio_processing_impl.cc
@@ -450,21 +450,23 @@
 }
 
 int AudioProcessingImpl::set_stream_delay_ms(int delay) {
+  Error retval = kNoError;
   was_stream_delay_set_ = true;
   delay += delay_offset_ms_;
 
   if (delay < 0) {
-    return kBadParameterError;
+    delay = 0;
+    retval = kBadStreamParameterWarning;
   }
 
   // TODO(ajm): the max is rather arbitrarily chosen; investigate.
   if (delay > 500) {
-    stream_delay_ms_ = 500;
-    return kBadStreamParameterWarning;
+    delay = 500;
+    retval = kBadStreamParameterWarning;
   }
 
   stream_delay_ms_ = delay;
-  return kNoError;
+  return retval;
 }
 
 int AudioProcessingImpl::stream_delay_ms() const {
diff --git a/src/modules/audio_processing/test/unit_test.cc b/src/modules/audio_processing/test/unit_test.cc
index b33314d..0465ebc 100644
--- a/src/modules/audio_processing/test/unit_test.cc
+++ b/src/modules/audio_processing/test/unit_test.cc
@@ -606,16 +606,26 @@
   EXPECT_EQ(apm_->kNoError, apm_->ProcessStream(frame_));
 }
 
-TEST_F(ApmTest, DelayOffset) {
+TEST_F(ApmTest, DefaultDelayOffsetIsZero) {
+  EXPECT_EQ(0, apm_->delay_offset_ms());
+  EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(50));
+  EXPECT_EQ(50, apm_->stream_delay_ms());
+}
+
+TEST_F(ApmTest, DelayOffsetWithLimitsIsSetProperly) {
+  // High limit of 500 ms.
   apm_->set_delay_offset_ms(100);
   EXPECT_EQ(100, apm_->delay_offset_ms());
   EXPECT_EQ(apm_->kBadStreamParameterWarning, apm_->set_stream_delay_ms(450));
+  EXPECT_EQ(500, apm_->stream_delay_ms());
   EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(100));
   EXPECT_EQ(200, apm_->stream_delay_ms());
 
+  // Low limit of 0 ms.
   apm_->set_delay_offset_ms(-50);
   EXPECT_EQ(-50, apm_->delay_offset_ms());
-  EXPECT_EQ(apm_->kBadParameterError, apm_->set_stream_delay_ms(20));
+  EXPECT_EQ(apm_->kBadStreamParameterWarning, apm_->set_stream_delay_ms(20));
+  EXPECT_EQ(0, apm_->stream_delay_ms());
   EXPECT_EQ(apm_->kNoError, apm_->set_stream_delay_ms(100));
   EXPECT_EQ(50, apm_->stream_delay_ms());
 }