OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/speech_recognition_audio_sink.h" | 5 #include "content/renderer/media/speech_recognition_audio_sink.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "content/renderer/media/media_stream_audio_source.h" | 9 #include "content/renderer/media/media_stream_audio_source.h" |
10 #include "content/renderer/media/mock_media_constraint_factory.h" | 10 #include "content/renderer/media/mock_media_constraint_factory.h" |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 blink_track->initialize(blink::WebString::fromUTF8("dummy_track"), | 285 blink_track->initialize(blink::WebString::fromUTF8("dummy_track"), |
286 blink_audio_source); | 286 blink_audio_source); |
287 blink_track->setExtraData(native_track.release()); | 287 blink_track->setExtraData(native_track.release()); |
288 } | 288 } |
289 | 289 |
290 // Emulates an audio capture device capturing data from the source. | 290 // Emulates an audio capture device capturing data from the source. |
291 inline void CaptureAudio(const uint32 buffers) { | 291 inline void CaptureAudio(const uint32 buffers) { |
292 for (uint32 i = 0; i < buffers; ++i) | 292 for (uint32 i = 0; i < buffers; ++i) |
293 native_track()->Capture(source_data(), | 293 native_track()->Capture(source_data(), |
294 base::TimeDelta::FromMilliseconds(0), 1, false, | 294 base::TimeDelta::FromMilliseconds(0), 1, false, |
295 false); | 295 false, false); |
296 } | 296 } |
297 | 297 |
298 // Used to simulate a problem with sockets. | 298 // Used to simulate a problem with sockets. |
299 void SetFailureModeOnForeignSocket(bool in_failure_mode) { | 299 void SetFailureModeOnForeignSocket(bool in_failure_mode) { |
300 recognizer()->sending_socket()->SetFailureMode(in_failure_mode); | 300 recognizer()->sending_socket()->SetFailureMode(in_failure_mode); |
301 } | 301 } |
302 | 302 |
303 // Helper method for verifying captured audio data has been consumed. | 303 // Helper method for verifying captured audio data has been consumed. |
304 inline void AssertConsumedBuffers(const uint32 buffer_index) { | 304 inline void AssertConsumedBuffers(const uint32 buffer_index) { |
305 ASSERT_EQ(buffer_index, recognizer()->GetAudioInputBuffer()->params.size); | 305 ASSERT_EQ(buffer_index, recognizer()->GetAudioInputBuffer()->params.size); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 const uint32 kBuffersPerNotification = Initialize(44100, 441, 16000, 1600); | 505 const uint32 kBuffersPerNotification = Initialize(44100, 441, 16000, 1600); |
506 AssertConsumedBuffers(0U); | 506 AssertConsumedBuffers(0U); |
507 CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U); | 507 CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U); |
508 EXPECT_CALL(*this, StoppedCallback()).Times(1); | 508 EXPECT_CALL(*this, StoppedCallback()).Times(1); |
509 | 509 |
510 native_track()->Stop(); | 510 native_track()->Stop(); |
511 CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U); | 511 CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U); |
512 } | 512 } |
513 | 513 |
514 } // namespace content | 514 } // namespace content |
OLD | NEW |