test_audio_thread.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "media/audio/test_audio_thread.h"
  5. #include "base/run_loop.h"
  6. #include "base/threading/thread_task_runner_handle.h"
  7. #include "build/build_config.h"
  8. namespace media {
  9. TestAudioThread::TestAudioThread() : TestAudioThread(false) {}
  10. TestAudioThread::TestAudioThread(bool use_real_thread) {
  11. if (use_real_thread) {
  12. thread_ = std::make_unique<base::Thread>("AudioThread");
  13. #if BUILDFLAG(IS_WIN)
  14. thread_->init_com_with_mta(true);
  15. #endif
  16. CHECK(thread_->Start());
  17. task_runner_ = thread_->task_runner();
  18. } else {
  19. task_runner_ = base::ThreadTaskRunnerHandle::Get();
  20. }
  21. }
  22. TestAudioThread::~TestAudioThread() {
  23. DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
  24. }
  25. void TestAudioThread::Stop() {
  26. DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
  27. if (thread_)
  28. thread_->Stop();
  29. else
  30. base::RunLoop().RunUntilIdle();
  31. }
  32. bool TestAudioThread::IsHung() const {
  33. DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
  34. return false;
  35. }
  36. base::SingleThreadTaskRunner* TestAudioThread::GetTaskRunner() {
  37. return task_runner_.get();
  38. }
  39. base::SingleThreadTaskRunner* TestAudioThread::GetWorkerTaskRunner() {
  40. return task_runner_.get();
  41. }
  42. } // namespace media