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

Side by Side Diff: media/audio/win/audio_low_latency_input_win_unittest.cc

Issue 2784433002: Ensures that audio tasks cannot run after AudioManager is deleted. (Closed)
Patch Set: cleanup Created 3 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "media/audio/win/audio_low_latency_input_win.h" 5 #include "media/audio/win/audio_low_latency_input_win.h"
6 6
7 #include <mmsystem.h> 7 #include <mmsystem.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <windows.h> 10 #include <windows.h>
11 11
12 #include <memory> 12 #include <memory>
13 13
14 #include "base/environment.h" 14 #include "base/environment.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h"
17 #include "base/message_loop/message_loop.h" 18 #include "base/message_loop/message_loop.h"
18 #include "base/path_service.h" 19 #include "base/path_service.h"
19 #include "base/run_loop.h" 20 #include "base/run_loop.h"
20 #include "base/single_thread_task_runner.h" 21 #include "base/single_thread_task_runner.h"
21 #include "base/strings/stringprintf.h" 22 #include "base/strings/stringprintf.h"
22 #include "base/test/test_timeouts.h" 23 #include "base/test/test_timeouts.h"
23 #include "base/win/scoped_com_initializer.h" 24 #include "base/win/scoped_com_initializer.h"
24 #include "media/audio/audio_device_description.h" 25 #include "media/audio/audio_device_description.h"
25 #include "media/audio/audio_io.h" 26 #include "media/audio/audio_io.h"
26 #include "media/audio/audio_manager.h" 27 #include "media/audio/audio_manager.h"
27 #include "media/audio/audio_unittest_util.h" 28 #include "media/audio/audio_unittest_util.h"
29 #include "media/audio/test_audio_thread.h"
28 #include "media/audio/win/core_audio_util_win.h" 30 #include "media/audio/win/core_audio_util_win.h"
29 #include "media/base/seekable_buffer.h" 31 #include "media/base/seekable_buffer.h"
30 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
31 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
32 34
33 using ::testing::_; 35 using ::testing::_;
34 using ::testing::AnyNumber; 36 using ::testing::AnyNumber;
35 using ::testing::AtLeast; 37 using ::testing::AtLeast;
36 using ::testing::Gt; 38 using ::testing::Gt;
37 using ::testing::NotNull; 39 using ::testing::NotNull;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 private: 254 private:
253 AudioInputStream* stream_; 255 AudioInputStream* stream_;
254 256
255 DISALLOW_COPY_AND_ASSIGN(ScopedAudioInputStream); 257 DISALLOW_COPY_AND_ASSIGN(ScopedAudioInputStream);
256 }; 258 };
257 259
258 class WinAudioInputTest : public ::testing::Test { 260 class WinAudioInputTest : public ::testing::Test {
259 public: 261 public:
260 WinAudioInputTest() { 262 WinAudioInputTest() {
261 audio_manager_ = 263 audio_manager_ =
262 AudioManager::CreateForTesting(message_loop_.task_runner()); 264 AudioManager::CreateForTesting(base::MakeUnique<TestAudioThread>());
263 base::RunLoop().RunUntilIdle(); 265 base::RunLoop().RunUntilIdle();
264 } 266 }
265 ~WinAudioInputTest() override { 267 ~WinAudioInputTest() override { audio_manager_->Shutdown(); }
266 audio_manager_.reset();
267 base::RunLoop().RunUntilIdle();
268 }
269 268
270 protected: 269 protected:
271 base::MessageLoop message_loop_; 270 base::MessageLoop message_loop_;
272 ScopedAudioManagerPtr audio_manager_; 271 std::unique_ptr<AudioManager> audio_manager_;
273 }; 272 };
274 273
275 // Verify that we can retrieve the current hardware/mixing sample rate 274 // Verify that we can retrieve the current hardware/mixing sample rate
276 // for all available input devices. 275 // for all available input devices.
277 TEST_F(WinAudioInputTest, WASAPIAudioInputStreamHardwareSampleRate) { 276 TEST_F(WinAudioInputTest, WASAPIAudioInputStreamHardwareSampleRate) {
278 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager_.get())); 277 ABORT_AUDIO_TEST_IF_NOT(HasCoreAudioAndInputDevices(audio_manager_.get()));
279 278
280 // Retrieve a list of all available input devices. 279 // Retrieve a list of all available input devices.
281 media::AudioDeviceDescriptions device_descriptions; 280 media::AudioDeviceDescriptions device_descriptions;
282 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions); 281 audio_manager_->GetAudioInputDeviceDescriptions(&device_descriptions);
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 ais->Start(&file_sink); 550 ais->Start(&file_sink);
552 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); 551 base::PlatformThread::Sleep(TestTimeouts::action_timeout());
553 // base::PlatformThread::Sleep(base::TimeDelta::FromMinutes(10)); 552 // base::PlatformThread::Sleep(base::TimeDelta::FromMinutes(10));
554 ais->Stop(); 553 ais->Stop();
555 VLOG(0) << ">> Recording has stopped."; 554 VLOG(0) << ">> Recording has stopped.";
556 ais.Close(); 555 ais.Close();
557 } 556 }
558 } 557 }
559 558
560 } // namespace media 559 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698