Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1393)

Unified Diff: webrtc/modules/audio_device/fine_audio_buffer_unittest.cc

Issue 1254883002: Refactor the AudioDevice for iOS and improve the performance and stability (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Improved error handling and added support for BT headsets Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/audio_device/fine_audio_buffer_unittest.cc
diff --git a/webrtc/modules/audio_device/android/fine_audio_buffer_unittest.cc b/webrtc/modules/audio_device/fine_audio_buffer_unittest.cc
similarity index 59%
rename from webrtc/modules/audio_device/android/fine_audio_buffer_unittest.cc
rename to webrtc/modules/audio_device/fine_audio_buffer_unittest.cc
index 4cff883129f18ec8c2735cca9292929891315bd1..6666364c9e38180d9ce95e1d9972a4e3e4738cc6 100644
--- a/webrtc/modules/audio_device/android/fine_audio_buffer_unittest.cc
+++ b/webrtc/modules/audio_device/fine_audio_buffer_unittest.cc
@@ -8,7 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-#include "webrtc/modules/audio_device/android/fine_audio_buffer.h"
+#include "webrtc/modules/audio_device/fine_audio_buffer.h"
#include <limits.h>
#include <memory>
@@ -19,6 +19,7 @@
#include "webrtc/modules/audio_device/mock_audio_device_buffer.h"
using ::testing::_;
+using ::testing::AtLeast;
using ::testing::InSequence;
using ::testing::Return;
@@ -40,10 +41,10 @@ bool VerifyBuffer(const int8_t* buffer, int buffer_number, int size) {
return true;
}
-// This function replaces GetPlayoutData when it's called (which is done
-// implicitly when calling GetBufferData). It writes the sequence
-// 0,1,..SCHAR_MAX-1,0,1,... to the buffer. Note that this is likely a buffer of
-// different size than the one VerifyBuffer verifies.
+// This function replaces the real AudioDeviceBuffer::GetPlayoutData when it's
+// called (which is done implicitly when calling GetBufferData). It writes the
+// sequence 0,1,..SCHAR_MAX-1,0,1,... to the buffer. Note that this is likely a
+// buffer of different size than the one VerifyBuffer verifies.
// |iteration| is the number of calls made to UpdateBuffer prior to this call.
// |samples_per_10_ms| is the number of samples that should be written to the
// buffer (|arg0|).
@@ -57,10 +58,33 @@ ACTION_P2(UpdateBuffer, iteration, samples_per_10_ms) {
return samples_per_10_ms;
}
+// Writes a periodic ramp pattern to the supplied |buffer|. See UpdateBuffer()
+// for details.
+void UpdateInputBuffer(int8_t* buffer, int iteration, int size) {
+ int start_value = (iteration * size) % SCHAR_MAX;
+ for (int i = 0; i < size; ++i) {
+ buffer[i] = (i + start_value) % SCHAR_MAX;
+ }
+}
+
+// Action macro which verifies that the recorded 10ms chunk of audio data
+// (in |arg0|) contains the correct reference values even if they have been
+// supplied using a buffer size that is smaller or larger than 10ms.
+// See VerifyBuffer() for details.
+ACTION_P2(VerifyInputBuffer, iteration, samples_per_10_ms) {
+ const int8_t* buffer = static_cast<const int8_t*>(arg0);
+ int bytes_per_10_ms = samples_per_10_ms * static_cast<int>(sizeof(int16_t));
+ int start_value = (iteration * bytes_per_10_ms) % SCHAR_MAX;
+ for (int i = 0; i < bytes_per_10_ms; ++i) {
+ EXPECT_EQ(buffer[i], (i + start_value) % SCHAR_MAX);
+ }
+ return 0;
+}
+
void RunFineBufferTest(int sample_rate, int frame_size_in_samples) {
const int kSamplesPer10Ms = sample_rate * 10 / 1000;
- const int kFrameSizeBytes = frame_size_in_samples *
- static_cast<int>(sizeof(int16_t));
+ const int kFrameSizeBytes =
+ frame_size_in_samples * static_cast<int>(sizeof(int16_t));
const int kNumberOfFrames = 5;
// Ceiling of integer division: 1 + ((x - 1) / y)
const int kNumberOfUpdateBufferCalls =
@@ -77,15 +101,32 @@ void RunFineBufferTest(int sample_rate, int frame_size_in_samples) {
.RetiresOnSaturation();
}
}
+ {
+ InSequence s;
+ for (int j = 0; j < kNumberOfUpdateBufferCalls - 1; ++j) {
+ EXPECT_CALL(audio_device_buffer, SetRecordedBuffer(_, kSamplesPer10Ms))
+ .WillOnce(VerifyInputBuffer(j, kSamplesPer10Ms))
+ .RetiresOnSaturation();
+ }
+ }
+ EXPECT_CALL(audio_device_buffer, SetVQEData(_, _, _))
+ .Times(kNumberOfUpdateBufferCalls - 1);
+ EXPECT_CALL(audio_device_buffer, DeliverRecordedData())
+ .Times(kNumberOfUpdateBufferCalls - 1)
+ .WillRepeatedly(Return(kSamplesPer10Ms));
+
FineAudioBuffer fine_buffer(&audio_device_buffer, kFrameSizeBytes,
sample_rate);
rtc::scoped_ptr<int8_t[]> out_buffer;
- out_buffer.reset(
- new int8_t[fine_buffer.RequiredBufferSizeBytes()]);
+ out_buffer.reset(new int8_t[fine_buffer.RequiredPlayoutBufferSizeBytes()]);
+ rtc::scoped_ptr<int8_t[]> in_buffer;
+ in_buffer.reset(new int8_t[kFrameSizeBytes]);
for (int i = 0; i < kNumberOfFrames; ++i) {
- fine_buffer.GetBufferData(out_buffer.get());
+ fine_buffer.GetPlayoutData(out_buffer.get());
EXPECT_TRUE(VerifyBuffer(out_buffer.get(), i, kFrameSizeBytes));
+ UpdateInputBuffer(in_buffer.get(), i, kFrameSizeBytes);
+ fine_buffer.DeliverRecordedData(in_buffer.get(), kFrameSizeBytes, 0, 0);
}
}

Powered by Google App Engine
This is Rietveld 408576698