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

Side by Side Diff: media/audio/virtual_audio_input_stream_unittest.cc

Issue 66183002: Replace MessageLoopProxy with SingleThreadTaskRunner for the rest of media/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
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 <list> 5 #include <list>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/rand_util.h" 9 #include "base/rand_util.h"
11 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
12 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
13 #include "media/audio/audio_io.h" 12 #include "media/audio/audio_io.h"
14 #include "media/audio/simple_sources.h" 13 #include "media/audio/simple_sources.h"
15 #include "media/audio/virtual_audio_input_stream.h" 14 #include "media/audio/virtual_audio_input_stream.h"
16 #include "media/audio/virtual_audio_output_stream.h" 15 #include "media/audio/virtual_audio_output_stream.h"
17 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 18
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } // namespace 97 } // namespace
99 98
100 class VirtualAudioInputStreamTest : public testing::TestWithParam<bool> { 99 class VirtualAudioInputStreamTest : public testing::TestWithParam<bool> {
101 public: 100 public:
102 VirtualAudioInputStreamTest() 101 VirtualAudioInputStreamTest()
103 : audio_thread_(new base::Thread("AudioThread")), 102 : audio_thread_(new base::Thread("AudioThread")),
104 worker_thread_(new base::Thread("AudioWorkerThread")), 103 worker_thread_(new base::Thread("AudioWorkerThread")),
105 stream_(NULL), 104 stream_(NULL),
106 closed_stream_(false, false) { 105 closed_stream_(false, false) {
107 audio_thread_->Start(); 106 audio_thread_->Start();
108 audio_message_loop_ = audio_thread_->message_loop_proxy(); 107 audio_task_runner_ = audio_thread_->message_loop_proxy();
109 } 108 }
110 109
111 virtual ~VirtualAudioInputStreamTest() { 110 virtual ~VirtualAudioInputStreamTest() {
112 SyncWithAudioThread(); 111 SyncWithAudioThread();
113 112
114 DCHECK(output_streams_.empty()); 113 DCHECK(output_streams_.empty());
115 DCHECK(stopped_output_streams_.empty()); 114 DCHECK(stopped_output_streams_.empty());
116 } 115 }
117 116
118 void Create() { 117 void Create() {
119 const bool worker_is_separate_thread = GetParam(); 118 const bool worker_is_separate_thread = GetParam();
120 stream_ = new VirtualAudioInputStream( 119 stream_ = new VirtualAudioInputStream(
121 kParams, GetWorkerLoop(worker_is_separate_thread), 120 kParams, GetWorkerTaskRunner(worker_is_separate_thread),
122 base::Bind(&base::DeletePointer<VirtualAudioInputStream>)); 121 base::Bind(&base::DeletePointer<VirtualAudioInputStream>));
123 stream_->Open(); 122 stream_->Open();
124 } 123 }
125 124
126 void Start() { 125 void Start() {
127 EXPECT_CALL(input_callback_, OnClose(_)); 126 EXPECT_CALL(input_callback_, OnClose(_));
128 EXPECT_CALL(input_callback_, OnData(_, NotNull(), _, _, _)) 127 EXPECT_CALL(input_callback_, OnData(_, NotNull(), _, _, _))
129 .Times(AtLeast(1)); 128 .Times(AtLeast(1));
130 129
131 ASSERT_TRUE(!!stream_); 130 ASSERT_TRUE(!!stream_);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 void RestartAllStoppedOutputStreams() { 201 void RestartAllStoppedOutputStreams() {
203 typedef std::list<AudioOutputStream*>::const_iterator ConstIter; 202 typedef std::list<AudioOutputStream*>::const_iterator ConstIter;
204 for (ConstIter it = stopped_output_streams_.begin(); 203 for (ConstIter it = stopped_output_streams_.begin();
205 it != stopped_output_streams_.end(); ++it) { 204 it != stopped_output_streams_.end(); ++it) {
206 (*it)->Start(&source_); 205 (*it)->Start(&source_);
207 output_streams_.push_back(*it); 206 output_streams_.push_back(*it);
208 } 207 }
209 stopped_output_streams_.clear(); 208 stopped_output_streams_.clear();
210 } 209 }
211 210
212 const scoped_refptr<base::MessageLoopProxy>& audio_message_loop() const { 211 const scoped_refptr<base::SingleThreadTaskRunner>& audio_task_runner() const {
213 return audio_message_loop_; 212 return audio_task_runner_;
214 } 213 }
215 214
216 const scoped_refptr<base::MessageLoopProxy>& GetWorkerLoop( 215 const scoped_refptr<base::SingleThreadTaskRunner>& GetWorkerTaskRunner(
217 bool worker_is_separate_thread) { 216 bool worker_is_separate_thread) {
218 if (worker_is_separate_thread) { 217 if (worker_is_separate_thread) {
219 if (!worker_thread_->IsRunning()) { 218 if (!worker_thread_->IsRunning()) {
220 worker_thread_->Start(); 219 worker_thread_->Start();
221 worker_message_loop_ = worker_thread_->message_loop_proxy(); 220 worker_task_runner_ = worker_thread_->message_loop_proxy();
222 } 221 }
223 return worker_message_loop_; 222 return worker_task_runner_;
224 } else { 223 } else {
225 return audio_message_loop_; 224 return audio_task_runner_;
226 } 225 }
227 } 226 }
228 227
229 private: 228 private:
230 void SyncWithAudioThread() { 229 void SyncWithAudioThread() {
231 base::WaitableEvent done(false, false); 230 base::WaitableEvent done(false, false);
232 audio_message_loop_->PostTask( 231 audio_task_runner_->PostTask(
233 FROM_HERE, 232 FROM_HERE,
234 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); 233 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
235 done.Wait(); 234 done.Wait();
236 } 235 }
237 236
238 scoped_ptr<base::Thread> audio_thread_; 237 scoped_ptr<base::Thread> audio_thread_;
239 scoped_refptr<base::MessageLoopProxy> audio_message_loop_; 238 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner_;
240 scoped_ptr<base::Thread> worker_thread_; 239 scoped_ptr<base::Thread> worker_thread_;
241 scoped_refptr<base::MessageLoopProxy> worker_message_loop_; 240 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_;
242 241
243 VirtualAudioInputStream* stream_; 242 VirtualAudioInputStream* stream_;
244 MockInputCallback input_callback_; 243 MockInputCallback input_callback_;
245 base::WaitableEvent closed_stream_; 244 base::WaitableEvent closed_stream_;
246 245
247 std::list<AudioOutputStream*> output_streams_; 246 std::list<AudioOutputStream*> output_streams_;
248 std::list<AudioOutputStream*> stopped_output_streams_; 247 std::list<AudioOutputStream*> stopped_output_streams_;
249 TestAudioSource source_; 248 TestAudioSource source_;
250 249
251 DISALLOW_COPY_AND_ASSIGN(VirtualAudioInputStreamTest); 250 DISALLOW_COPY_AND_ASSIGN(VirtualAudioInputStreamTest);
252 }; 251 };
253 252
254 #define RUN_ON_AUDIO_THREAD(method) \ 253 #define RUN_ON_AUDIO_THREAD(method) \
255 audio_message_loop()->PostTask( \ 254 audio_task_runner()->PostTask( \
256 FROM_HERE, base::Bind(&VirtualAudioInputStreamTest::method, \ 255 FROM_HERE, base::Bind(&VirtualAudioInputStreamTest::method, \
257 base::Unretained(this))) 256 base::Unretained(this)))
258 257
259 TEST_P(VirtualAudioInputStreamTest, CreateAndClose) { 258 TEST_P(VirtualAudioInputStreamTest, CreateAndClose) {
260 RUN_ON_AUDIO_THREAD(Create); 259 RUN_ON_AUDIO_THREAD(Create);
261 RUN_ON_AUDIO_THREAD(Close); 260 RUN_ON_AUDIO_THREAD(Close);
262 WaitUntilClosed(); 261 WaitUntilClosed();
263 } 262 }
264 263
265 TEST_P(VirtualAudioInputStreamTest, NoOutputs) { 264 TEST_P(VirtualAudioInputStreamTest, NoOutputs) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 348 }
350 RUN_ON_AUDIO_THREAD(Close); 349 RUN_ON_AUDIO_THREAD(Close);
351 WaitUntilClosed(); 350 WaitUntilClosed();
352 } 351 }
353 352
354 INSTANTIATE_TEST_CASE_P(SingleVersusMultithreaded, 353 INSTANTIATE_TEST_CASE_P(SingleVersusMultithreaded,
355 VirtualAudioInputStreamTest, 354 VirtualAudioInputStreamTest,
356 ::testing::Values(false, true)); 355 ::testing::Values(false, true));
357 356
358 } // namespace media 357 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698