OLD | NEW |
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/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 } | 80 } |
81 | 81 |
82 private: | 82 private: |
83 base::WaitableEvent data_pulled_; | 83 base::WaitableEvent data_pulled_; |
84 | 84 |
85 DISALLOW_COPY_AND_ASSIGN(TestAudioSource); | 85 DISALLOW_COPY_AND_ASSIGN(TestAudioSource); |
86 }; | 86 }; |
87 | 87 |
88 } // namespace | 88 } // namespace |
89 | 89 |
| 90 static void DeleteVirtualAudioOutputStream( |
| 91 VirtualAudioOutputStream* audio_stream) { |
| 92 delete audio_stream; |
| 93 } |
| 94 |
90 class VirtualAudioInputStreamTest : public testing::TestWithParam<bool> { | 95 class VirtualAudioInputStreamTest : public testing::TestWithParam<bool> { |
91 public: | 96 public: |
92 VirtualAudioInputStreamTest() | 97 VirtualAudioInputStreamTest() |
93 : audio_thread_(new base::Thread("AudioThread")), | 98 : audio_thread_(new base::Thread("AudioThread")), |
94 worker_thread_(new base::Thread("AudioWorkerThread")), | 99 worker_thread_(new base::Thread("AudioWorkerThread")), |
95 stream_(NULL), | 100 stream_(NULL), |
96 closed_stream_(false, false) { | 101 closed_stream_(false, false) { |
97 audio_thread_->Start(); | 102 audio_thread_->Start(); |
98 audio_task_runner_ = audio_thread_->message_loop_proxy(); | 103 audio_task_runner_ = audio_thread_->message_loop_proxy(); |
99 } | 104 } |
100 | 105 |
101 virtual ~VirtualAudioInputStreamTest() { | 106 virtual ~VirtualAudioInputStreamTest() { |
102 SyncWithAudioThread(); | 107 SyncWithAudioThread(); |
103 | 108 |
104 DCHECK(output_streams_.empty()); | 109 DCHECK(output_streams_.empty()); |
105 DCHECK(stopped_output_streams_.empty()); | 110 DCHECK(stopped_output_streams_.empty()); |
106 } | 111 } |
107 | 112 |
108 void Create() { | 113 void Create() { |
109 const bool worker_is_separate_thread = GetParam(); | 114 const bool worker_is_separate_thread = GetParam(); |
110 stream_ = new VirtualAudioInputStream( | 115 stream_ = new VirtualAudioInputStream( |
111 kParams, GetWorkerTaskRunner(worker_is_separate_thread), | 116 kParams, GetWorkerTaskRunner(worker_is_separate_thread), |
112 base::Bind(&base::DeletePointer<VirtualAudioInputStream>)); | 117 true); |
113 stream_->Open(); | 118 stream_->Open(); |
114 } | 119 } |
115 | 120 |
116 void Start() { | 121 void Start() { |
117 EXPECT_CALL(input_callback_, OnData(_, NotNull(), _, _)).Times(AtLeast(1)); | 122 EXPECT_CALL(input_callback_, OnData(_, NotNull(), _, _)).Times(AtLeast(1)); |
118 | 123 |
119 ASSERT_TRUE(!!stream_); | 124 ASSERT_TRUE(!!stream_); |
120 stream_->Start(&input_callback_); | 125 stream_->Start(&input_callback_); |
121 } | 126 } |
122 | 127 |
123 void CreateAndStartOneOutputStream() { | 128 void CreateAndStartOneOutputStream() { |
124 ASSERT_TRUE(!!stream_); | 129 ASSERT_TRUE(!!stream_); |
125 AudioOutputStream* const output_stream = new VirtualAudioOutputStream( | 130 AudioOutputStream* const output_stream = new VirtualAudioOutputStream( |
126 kParams, | 131 kParams, |
127 stream_, | 132 stream_, |
128 base::Bind(&base::DeletePointer<VirtualAudioOutputStream>)); | 133 base::Bind(&DeleteVirtualAudioOutputStream)); |
129 output_streams_.push_back(output_stream); | 134 output_streams_.push_back(output_stream); |
130 | 135 |
131 output_stream->Open(); | 136 output_stream->Open(); |
132 output_stream->Start(&source_); | 137 output_stream->Start(&source_); |
133 } | 138 } |
134 | 139 |
135 void Stop() { | 140 void Stop() { |
136 ASSERT_TRUE(!!stream_); | 141 ASSERT_TRUE(!!stream_); |
137 stream_->Stop(); | 142 stream_->Stop(); |
138 } | 143 } |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 } | 342 } |
338 RUN_ON_AUDIO_THREAD(Close); | 343 RUN_ON_AUDIO_THREAD(Close); |
339 WaitUntilClosed(); | 344 WaitUntilClosed(); |
340 } | 345 } |
341 | 346 |
342 INSTANTIATE_TEST_CASE_P(SingleVersusMultithreaded, | 347 INSTANTIATE_TEST_CASE_P(SingleVersusMultithreaded, |
343 VirtualAudioInputStreamTest, | 348 VirtualAudioInputStreamTest, |
344 ::testing::Values(false, true)); | 349 ::testing::Values(false, true)); |
345 | 350 |
346 } // namespace media | 351 } // namespace media |
OLD | NEW |