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

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

Issue 645363005: Fix for memory leaks in SpeechRecognitionAudioSinkTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and clean up 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.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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 shared_memory_.reset(new base::SharedMemory()); 122 shared_memory_.reset(new base::SharedMemory());
123 ASSERT_TRUE(shared_memory_->CreateAndMapAnonymous(kSharedMemorySize)); 123 ASSERT_TRUE(shared_memory_->CreateAndMapAnonymous(kSharedMemorySize));
124 memset(shared_memory_->memory(), 0, kSharedMemorySize); 124 memset(shared_memory_->memory(), 0, kSharedMemorySize);
125 ASSERT_TRUE(shared_memory_->ShareToProcess(base::GetCurrentProcessHandle(), 125 ASSERT_TRUE(shared_memory_->ShareToProcess(base::GetCurrentProcessHandle(),
126 foreign_memory_handle)); 126 foreign_memory_handle));
127 127
128 // Wrap the shared memory for the audio bus. 128 // Wrap the shared memory for the audio bus.
129 media::AudioInputBuffer* buffer = 129 media::AudioInputBuffer* buffer =
130 static_cast<media::AudioInputBuffer*>(shared_memory_->memory()); 130 static_cast<media::AudioInputBuffer*>(shared_memory_->memory());
131 audio_track_bus_ = media::AudioBus::WrapMemory(sink_params, buffer->audio); 131 audio_track_bus_ = media::AudioBus::WrapMemory(sink_params, buffer->audio);
132 audio_track_bus_->Zero();
132 133
133 // Reference to the counter used to synchronize. 134 // Reference to the counter used to synchronize.
134 buffer_index_ = &(buffer->params.size); 135 buffer_index_ = &(buffer->params.size);
135 *buffer_index_ = 0U; 136 *buffer_index_ = 0U;
136 137
137 // Create a shared buffer for the |MockSyncSocket|s. 138 // Create a shared buffer for the |MockSyncSocket|s.
138 shared_buffer_.reset(new MockSyncSocket::SharedBuffer()); 139 shared_buffer_.reset(new MockSyncSocket::SharedBuffer());
139 140
140 // Local socket will receive signals from the producer. 141 // Local socket will receive signals from the producer.
141 local_socket_.reset(new MockSyncSocket(shared_buffer_.get())); 142 local_socket_.reset(new MockSyncSocket(shared_buffer_.get()));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 kInputChannels, 215 kInputChannels,
215 input_sample_rate, 216 input_sample_rate,
216 kInputBitsPerSample, 217 kInputBitsPerSample,
217 input_frames_per_buffer); 218 input_frames_per_buffer);
218 sink_params_.Reset(kOutputFormat, 219 sink_params_.Reset(kOutputFormat,
219 kOutputChannelLayout, 220 kOutputChannelLayout,
220 kOutputChannels, 221 kOutputChannels,
221 output_sample_rate, 222 output_sample_rate,
222 kOutputBitsPerSample, 223 kOutputBitsPerSample,
223 output_frames_per_buffer); 224 output_frames_per_buffer);
224 source_data_.reset(new int16[input_frames_per_buffer * kInputChannels]); 225 source_data_.reset(new int16[input_frames_per_buffer * kInputChannels]{});
225 226
226 // Prepare the track and audio source. 227 // Prepare the track and audio source.
227 blink::WebMediaStreamTrack blink_track; 228 blink::WebMediaStreamTrack blink_track;
228 PrepareBlinkTrackOfType(MEDIA_DEVICE_AUDIO_CAPTURE, &blink_track); 229 PrepareBlinkTrackOfType(MEDIA_DEVICE_AUDIO_CAPTURE, &blink_track);
229 230
230 // Get the native track from the blink track and initialize. 231 // Get the native track from the blink track and initialize.
231 native_track_ = 232 native_track_ =
232 static_cast<WebRtcLocalAudioTrack*>(blink_track.extraData()); 233 static_cast<WebRtcLocalAudioTrack*>(blink_track.extraData());
233 native_track_->OnSetFormat(source_params_); 234 native_track_->OnSetFormat(source_params_);
234 235
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 312 }
312 313
313 // Helper method to capture and assert consumption at different sample rates 314 // Helper method to capture and assert consumption at different sample rates
314 // and audio buffer sizes. 315 // and audio buffer sizes.
315 inline void AssertConsumptionForAudioParameters( 316 inline void AssertConsumptionForAudioParameters(
316 const int input_sample_rate, 317 const int input_sample_rate,
317 const int input_frames_per_buffer, 318 const int input_frames_per_buffer,
318 const int output_sample_rate, 319 const int output_sample_rate,
319 const int output_frames_per_buffer, 320 const int output_frames_per_buffer,
320 const uint32 consumptions) { 321 const uint32 consumptions) {
321 const uint32 kBuffersPerNotification = 322 const uint32 kBuffersPerNotification = Initialize(input_sample_rate,
322 Initialize(input_sample_rate, input_frames_per_buffer, 323 input_frames_per_buffer,
323 output_sample_rate, output_frames_per_buffer); 324 output_sample_rate,
325 output_frames_per_buffer);
324 AssertConsumedBuffers(0U); 326 AssertConsumedBuffers(0U);
325 327
326 for (uint32 i = 1U; i <= consumptions; ++i) { 328 for (uint32 i = 1U; i <= consumptions; ++i) {
327 CaptureAudio(kBuffersPerNotification); 329 CaptureAudio(kBuffersPerNotification);
328 ASSERT_EQ(i, recognizer_->buffer_index()) 330 ASSERT_EQ(i, recognizer_->buffer_index())
329 << "Tested at rates: " 331 << "Tested at rates: "
330 << "In(" << input_sample_rate << ", " << input_frames_per_buffer 332 << "In(" << input_sample_rate << ", " << input_frames_per_buffer
331 << ") " 333 << ") "
332 << "Out(" << output_sample_rate << ", " << output_frames_per_buffer 334 << "Out(" << output_sample_rate << ", " << output_frames_per_buffer
333 << ")"; 335 << ")";
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 const uint32 kBuffersPerNotification = Initialize(44100, 441, 16000, 1600); 479 const uint32 kBuffersPerNotification = Initialize(44100, 441, 16000, 1600);
478 AssertConsumedBuffers(0U); 480 AssertConsumedBuffers(0U);
479 CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U); 481 CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U);
480 EXPECT_CALL(*this, StoppedCallback()).Times(1); 482 EXPECT_CALL(*this, StoppedCallback()).Times(1);
481 483
482 native_track()->Stop(); 484 native_track()->Stop();
483 CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U); 485 CaptureAudioAndAssertConsumedBuffers(kBuffersPerNotification, 1U);
484 } 486 }
485 487
486 } // namespace content 488 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | tools/valgrind/drmemory/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698