OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/synchronization/waitable_event.h" | 5 #include "base/synchronization/waitable_event.h" |
6 #include "base/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
7 #include "content/renderer/media/webrtc_audio_capturer.h" | 7 #include "content/renderer/media/webrtc_audio_capturer.h" |
8 #include "content/renderer/media/webrtc_local_audio_track.h" | 8 #include "content/renderer/media/webrtc_local_audio_track.h" |
9 #include "media/audio/audio_parameters.h" | 9 #include "media/audio/audio_parameters.h" |
10 #include "media/base/audio_bus.h" | 10 #include "media/base/audio_bus.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 } | 25 } |
26 | 26 |
27 // A simple thread that we use to fake the audio thread which provides data to | 27 // A simple thread that we use to fake the audio thread which provides data to |
28 // the |WebRtcAudioCapturer|. | 28 // the |WebRtcAudioCapturer|. |
29 class FakeAudioThread : public base::PlatformThread::Delegate { | 29 class FakeAudioThread : public base::PlatformThread::Delegate { |
30 public: | 30 public: |
31 explicit FakeAudioThread(const scoped_refptr<WebRtcAudioCapturer>& capturer) | 31 explicit FakeAudioThread(const scoped_refptr<WebRtcAudioCapturer>& capturer) |
32 : capturer_(capturer), | 32 : capturer_(capturer), |
33 thread_(), | 33 thread_(), |
34 closure_(false, false) { | 34 closure_(false, false) { |
35 DCHECK(capturer); | 35 DCHECK(capturer.get()); |
36 audio_bus_ = media::AudioBus::Create(capturer_->audio_parameters()); | 36 audio_bus_ = media::AudioBus::Create(capturer_->audio_parameters()); |
37 } | 37 } |
38 | 38 |
39 virtual ~FakeAudioThread() { DCHECK(thread_.is_null()); } | 39 virtual ~FakeAudioThread() { DCHECK(thread_.is_null()); } |
40 | 40 |
41 // base::PlatformThread::Delegate: | 41 // base::PlatformThread::Delegate: |
42 virtual void ThreadMain() OVERRIDE { | 42 virtual void ThreadMain() OVERRIDE { |
43 while (true) { | 43 while (true) { |
44 if (closure_.IsSignaled()) | 44 if (closure_.IsSignaled()) |
45 return; | 45 return; |
46 | 46 |
47 media::AudioCapturerSource::CaptureCallback* callback = | 47 media::AudioCapturerSource::CaptureCallback* callback = |
48 static_cast<media::AudioCapturerSource::CaptureCallback*>(capturer_); | 48 static_cast<media::AudioCapturerSource::CaptureCallback*>( |
| 49 capturer_.get()); |
49 audio_bus_->Zero(); | 50 audio_bus_->Zero(); |
50 callback->Capture(audio_bus_.get(), 0, 0); | 51 callback->Capture(audio_bus_.get(), 0, 0); |
51 | 52 |
52 // Sleep 1ms to yield the resource for the main thread. | 53 // Sleep 1ms to yield the resource for the main thread. |
53 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); | 54 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); |
54 } | 55 } |
55 } | 56 } |
56 | 57 |
57 void Start() { | 58 void Start() { |
58 base::PlatformThread::CreateWithPriority( | 59 base::PlatformThread::CreateWithPriority( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 MOCK_METHOD1(SetCaptureFormat, void(const media::AudioParameters& params)); | 102 MOCK_METHOD1(SetCaptureFormat, void(const media::AudioParameters& params)); |
102 }; | 103 }; |
103 | 104 |
104 } // namespace | 105 } // namespace |
105 | 106 |
106 class WebRtcLocalAudioTrackTest : public ::testing::Test { | 107 class WebRtcLocalAudioTrackTest : public ::testing::Test { |
107 protected: | 108 protected: |
108 virtual void SetUp() OVERRIDE { | 109 virtual void SetUp() OVERRIDE { |
109 capturer_ = WebRtcAudioCapturer::CreateCapturer(); | 110 capturer_ = WebRtcAudioCapturer::CreateCapturer(); |
110 capturer_source_ = new MockCapturerSource(); | 111 capturer_source_ = new MockCapturerSource(); |
111 EXPECT_CALL(*capturer_source_, Initialize(_, capturer_.get(), 0)) | 112 EXPECT_CALL(*capturer_source_.get(), Initialize(_, capturer_.get(), 0)) |
112 .WillOnce(Return()); | 113 .WillOnce(Return()); |
113 capturer_->SetCapturerSource(capturer_source_, | 114 capturer_->SetCapturerSource(capturer_source_, |
114 media::CHANNEL_LAYOUT_STEREO, | 115 media::CHANNEL_LAYOUT_STEREO, |
115 48000); | 116 48000); |
116 | 117 |
117 EXPECT_CALL(*capturer_source_, Start()).WillOnce(Return()); | 118 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); |
118 EXPECT_CALL(*capturer_source_, SetAutomaticGainControl(false)) | 119 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(false)) |
119 .WillOnce(Return()); | 120 .WillOnce(Return()); |
120 capturer_->Start(); | 121 capturer_->Start(); |
121 audio_thread_.reset(new FakeAudioThread(capturer_)); | 122 audio_thread_.reset(new FakeAudioThread(capturer_)); |
122 audio_thread_->Start(); | 123 audio_thread_->Start(); |
123 } | 124 } |
124 | 125 |
125 virtual void TearDown() { | 126 virtual void TearDown() { |
126 audio_thread_->Stop(); | 127 audio_thread_->Stop(); |
127 audio_thread_.reset(); | 128 audio_thread_.reset(); |
128 EXPECT_CALL(*capturer_source_, Stop()).WillOnce(Return()); | 129 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); |
129 capturer_->Stop(); | 130 capturer_->Stop(); |
130 } | 131 } |
131 | 132 |
132 scoped_refptr<MockCapturerSource> capturer_source_; | 133 scoped_refptr<MockCapturerSource> capturer_source_; |
133 scoped_refptr<WebRtcAudioCapturer> capturer_; | 134 scoped_refptr<WebRtcAudioCapturer> capturer_; |
134 scoped_ptr<FakeAudioThread> audio_thread_; | 135 scoped_ptr<FakeAudioThread> audio_thread_; |
135 }; | 136 }; |
136 | 137 |
137 // Creates a capturer and audio track, fakes its audio thread, and | 138 // Creates a capturer and audio track, fakes its audio thread, and |
138 // connect/disconnect the sink to the audio track on the fly, the sink should | 139 // connect/disconnect the sink to the audio track on the fly, the sink should |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 233 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
233 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); | 234 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); |
234 | 235 |
235 track_1->RemoveSink(sink_1.get()); | 236 track_1->RemoveSink(sink_1.get()); |
236 track_2->RemoveSink(sink_2.get()); | 237 track_2->RemoveSink(sink_2.get()); |
237 track_1 = NULL; | 238 track_1 = NULL; |
238 track_2 = NULL; | 239 track_2 = NULL; |
239 } | 240 } |
240 | 241 |
241 } // namespace content | 242 } // namespace content |
OLD | NEW |