Index: content/renderer/media/speech_recognition_audio_sink_unittest.cc |
diff --git a/content/renderer/media/speech_recognition_audio_sink_unittest.cc b/content/renderer/media/speech_recognition_audio_sink_unittest.cc |
index facb90ca75563a374cd1415b49734e5c47f82f39..9db69b854c3f17f9d5df871aacece8813b81955c 100644 |
--- a/content/renderer/media/speech_recognition_audio_sink_unittest.cc |
+++ b/content/renderer/media/speech_recognition_audio_sink_unittest.cc |
@@ -128,18 +128,18 @@ class FakeSpeechRecognizer { |
// Wrap the shared memory for the audio bus. |
media::AudioInputBuffer* buffer = |
static_cast<media::AudioInputBuffer*>(shared_memory_->memory()); |
+ |
audio_track_bus_ = media::AudioBus::WrapMemory(sink_params, buffer->audio); |
audio_track_bus_->Zero(); |
// Reference to the counter used to synchronize. |
- buffer_index_ = &(buffer->params.size); |
- *buffer_index_ = 0U; |
+ buffer->params.size = 0U; |
// Create a shared buffer for the |MockSyncSocket|s. |
shared_buffer_.reset(new MockSyncSocket::SharedBuffer()); |
// Local socket will receive signals from the producer. |
- local_socket_.reset(new MockSyncSocket(shared_buffer_.get())); |
+ receiving_socket_.reset(new MockSyncSocket(shared_buffer_.get())); |
// We automatically trigger a Receive when data is sent over the socket. |
foreign_socket_ = new MockSyncSocket( |
@@ -148,19 +148,20 @@ class FakeSpeechRecognizer { |
base::Unretained(this))); |
// This is usually done to pair the sockets. Here it's not effective. |
- base::SyncSocket::CreatePair(local_socket_.get(), foreign_socket_); |
+ base::SyncSocket::CreatePair(receiving_socket_.get(), foreign_socket_); |
} |
// Emulates a single iteraton of a thread receiving on the socket. |
// This would normally be done on a receiving thread's task on the browser. |
void EmulateReceiveThreadLoopIteration() { |
- // When not responsive do nothing as if the process is busy. |
if (!is_responsive_) |
return; |
- local_socket_->Receive(buffer_index_, sizeof(*buffer_index_)); |
+ const int kSize = sizeof(media::AudioInputBufferParameters().size); |
+ receiving_socket_->Receive(&(GetAudioInputBuffer()->params.size), kSize); |
+ |
// Notify the producer that the audio buffer has been consumed. |
- ++(*buffer_index_); |
+ GetAudioInputBuffer()->params.size++; |
} |
// Used to simulate an unresponsive behaviour of the consumer. |
@@ -168,9 +169,13 @@ class FakeSpeechRecognizer { |
is_responsive_ = is_responsive; |
} |
+ media::AudioInputBuffer * GetAudioInputBuffer() const { |
+ return static_cast<media::AudioInputBuffer*>(shared_memory_->memory()); |
+ } |
+ |
MockSyncSocket* foreign_socket() { return foreign_socket_; } |
media::AudioBus* audio_bus() const { return audio_track_bus_.get(); } |
- uint32 buffer_index() { return *buffer_index_; } |
+ |
private: |
bool is_responsive_; |
@@ -180,15 +185,12 @@ class FakeSpeechRecognizer { |
// Fake sockets and their shared buffer. |
scoped_ptr<MockSyncSocket::SharedBuffer> shared_buffer_; |
- scoped_ptr<MockSyncSocket> local_socket_; |
+ scoped_ptr<MockSyncSocket> receiving_socket_; |
MockSyncSocket* foreign_socket_; |
no longer working on chromium
2014/10/13 12:28:56
change this foreign_socket_ to send_socket_ corres
burnik
2014/10/13 12:37:06
Done.
|
// Audio bus wrapping the shared memory from the renderer. |
scoped_ptr<media::AudioBus> audio_track_bus_; |
- // Used for synchronization of sent/received buffers. |
- uint32* buffer_index_; |
- |
DISALLOW_COPY_AND_ASSIGN(FakeSpeechRecognizer); |
}; |
@@ -300,7 +302,7 @@ class SpeechRecognitionAudioSinkTest : public testing::Test { |
// Helper method for verifying captured audio data has been consumed. |
inline void AssertConsumedBuffers(const uint32 buffer_index) { |
- ASSERT_EQ(buffer_index, recognizer_->buffer_index()); |
+ ASSERT_EQ(buffer_index, recognizer()->GetAudioInputBuffer()->params.size); |
} |
// Helper method for providing audio data to producer and verifying it was |
@@ -327,7 +329,7 @@ class SpeechRecognitionAudioSinkTest : public testing::Test { |
for (uint32 i = 1U; i <= consumptions; ++i) { |
CaptureAudio(kBuffersPerNotification); |
- ASSERT_EQ(i, recognizer_->buffer_index()) |
+ ASSERT_EQ(i, recognizer()->GetAudioInputBuffer()->params.size) |
<< "Tested at rates: " |
<< "In(" << input_sample_rate << ", " << input_frames_per_buffer |
<< ") " |
@@ -474,6 +476,30 @@ TEST_F(SpeechRecognitionAudioSinkTest, SyncSocketFailsSendingData) { |
CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U); |
} |
+// A very unlikely scenario in which the peer is not synchronizing for a long |
+// time (e.g. 300 ms) which results in dropping cached buffers and restarting. |
+// We check that the FIFO overflow does not occur and that the producer is able |
+// to resume. |
+TEST_F(SpeechRecognitionAudioSinkTest, RepeatedSycnhronizationLag) { |
+ const uint32 kBuffersPerNotification = Initialize(44100, 441, 16000, 1600); |
+ |
+ // Start with no problems on the socket. |
+ AssertConsumedBuffers(0U); |
+ CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U); |
+ |
+ // Consumer gets out of sync. |
+ recognizer()->SimulateResponsiveness(false); |
+ CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U); |
+ CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U); |
+ CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U); |
+ |
+ // Consumer recovers. |
+ recognizer()->SimulateResponsiveness(true); |
+ CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 2U); |
+ CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 3U); |
+ CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 4U); |
+} |
+ |
// Checks that an OnStoppedCallback is issued when the track is stopped. |
TEST_F(SpeechRecognitionAudioSinkTest, OnReadyStateChangedOccured) { |
const uint32 kBuffersPerNotification = Initialize(44100, 441, 16000, 1600); |