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

Side by Side Diff: content/renderer/media/speech_recognition_audio_sink_unittest.cc

Issue 649613002: Binding media stream audio track to speech recognition - bugfix (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | tools/valgrind/drmemory/suppressions_full.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // in the production code (minus the mocks). 109 // in the production code (minus the mocks).
110 class FakeSpeechRecognizer { 110 class FakeSpeechRecognizer {
111 public: 111 public:
112 FakeSpeechRecognizer() : is_responsive_(true) { } 112 FakeSpeechRecognizer() : is_responsive_(true) { }
113 113
114 void Initialize( 114 void Initialize(
115 const blink::WebMediaStreamTrack& track, 115 const blink::WebMediaStreamTrack& track,
116 const media::AudioParameters& sink_params, 116 const media::AudioParameters& sink_params,
117 base::SharedMemoryHandle* foreign_memory_handle) { 117 base::SharedMemoryHandle* foreign_memory_handle) {
118 // Shared memory is allocated, mapped and shared. 118 // Shared memory is allocated, mapped and shared.
119 uint32 shared_memory_size = 119 const uint32 kSharedMemorySize =
120 sizeof(media::AudioInputBufferParameters) + 120 sizeof(media::AudioInputBufferParameters) +
121 media::AudioBus::CalculateMemorySize(sink_params); 121 media::AudioBus::CalculateMemorySize(sink_params);
122 shared_memory_.reset(new base::SharedMemory()); 122 shared_memory_.reset(new base::SharedMemory());
123 ASSERT_TRUE(shared_memory_->CreateAndMapAnonymous(shared_memory_size)); 123 ASSERT_TRUE(shared_memory_->CreateAndMapAnonymous(kSharedMemorySize));
124 memset(shared_memory_->memory(), 0, kSharedMemorySize);
124 ASSERT_TRUE(shared_memory_->ShareToProcess(base::GetCurrentProcessHandle(), 125 ASSERT_TRUE(shared_memory_->ShareToProcess(base::GetCurrentProcessHandle(),
125 foreign_memory_handle)); 126 foreign_memory_handle));
126 127
127 // Wrap the shared memory for the audio bus. 128 // Wrap the shared memory for the audio bus.
128 media::AudioInputBuffer* buffer = 129 media::AudioInputBuffer* buffer =
129 static_cast<media::AudioInputBuffer*>(shared_memory_->memory()); 130 static_cast<media::AudioInputBuffer*>(shared_memory_->memory());
130 audio_track_bus_ = media::AudioBus::WrapMemory(sink_params, buffer->audio); 131 audio_track_bus_ = media::AudioBus::WrapMemory(sink_params, buffer->audio);
131 132
132 // Reference to the counter used to synchronize. 133 // Reference to the counter used to synchronize.
133 buffer_index_ = &(buffer->params.size); 134 buffer_index_ = &(buffer->params.size);
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 const uint32 kBuffersPerNotification = Initialize(44100, 441, 16000, 1600); 477 const uint32 kBuffersPerNotification = Initialize(44100, 441, 16000, 1600);
477 AssertConsumedBuffers(0U); 478 AssertConsumedBuffers(0U);
478 CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U); 479 CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U);
479 EXPECT_CALL(*this, StoppedCallback()).Times(1); 480 EXPECT_CALL(*this, StoppedCallback()).Times(1);
480 481
481 native_track()->Stop(); 482 native_track()->Stop();
482 CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U); 483 CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U);
483 } 484 }
484 485
485 } // namespace content 486 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | tools/valgrind/drmemory/suppressions_full.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698