OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/message_loop.h" | |
6 #include "base/synchronization/waitable_event.h" | |
7 #include "media/audio/audio_manager.h" | |
8 #include "media/audio/simple_sources.h" | |
9 #include "media/audio/virtual_audio_input_stream.h" | |
10 #include "media/audio/virtual_audio_output_stream.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace media { | |
14 | |
15 // TODO(justinlin): Make these better.. | |
Alpha Left Google
2012/11/28 01:04:47
What does it mean by better? Need to document more
justinlin
2012/11/28 14:30:31
Was left as a TODO because this wasn't quite ready
| |
16 class VirtualAudioInputStreamTest : public testing::Test { | |
17 public: | |
18 VirtualAudioInputStreamTest() | |
19 : audio_manager_(AudioManager::Create()), | |
20 params_( | |
21 AudioParameters::AUDIO_MIRROR_BROWSER, | |
22 CHANNEL_LAYOUT_MONO, 8000, 8, 128), | |
23 output_params_(AudioParameters::AUDIO_PCM_LINEAR, | |
24 CHANNEL_LAYOUT_MONO, 8000, 8, 128), | |
25 done_(false, false), | |
26 output_stream_(NULL), | |
27 source_(params_.channels(), 200.0, params_.sample_rate()) { | |
28 } | |
29 | |
30 void AddStreamOnAudioThread() { | |
31 ASSERT_TRUE(audio_manager_->GetMessageLoop()->BelongsToCurrentThread()); | |
32 | |
33 output_stream_ = audio_manager_->MakeAudioOutputStream(output_params_); | |
34 output_stream_->Open(); | |
35 | |
36 EXPECT_EQ(1u, static_cast<VirtualAudioInputStream*>(stream_)-> | |
37 converters_.size()); | |
38 | |
39 output_stream_->Start(&source_); | |
40 audio_manager_->GetMessageLoop()->PostTask(FROM_HERE, base::Bind( | |
41 &VirtualAudioInputStreamTest::EndTest, base::Unretained(this), 1)); | |
42 } | |
43 | |
44 void EndTest(int callbacks) { | |
45 if (output_stream_) { | |
46 output_stream_->Stop(); | |
47 output_stream_->Close(); | |
48 } | |
49 | |
50 stream_->Stop(); | |
51 stream_->Close(); | |
52 | |
53 EXPECT_EQ(callbacks, source_.callbacks()); | |
54 EXPECT_EQ(0, source_.errors()); | |
55 | |
56 done_.Signal(); | |
57 } | |
58 | |
59 protected: | |
60 scoped_ptr<AudioManager> audio_manager_; | |
61 AudioParameters params_; | |
62 AudioParameters output_params_; | |
63 VirtualAudioInputStream* stream_; | |
64 base::WaitableEvent done_; | |
65 std::vector<AudioOutputStream*> output_streams_; | |
66 AudioOutputStream* output_stream_; | |
67 SineWaveAudioSource source_; | |
68 | |
69 private: | |
70 DISALLOW_COPY_AND_ASSIGN(VirtualAudioInputStreamTest); | |
71 }; | |
72 | |
73 TEST_F(VirtualAudioInputStreamTest, AttachAndReadVirtualAudioOutputStream) { | |
74 stream_ = static_cast<VirtualAudioInputStream*>( | |
75 audio_manager_->MakeAudioInputStream(params_, "1")); | |
76 DCHECK(stream_); | |
77 | |
78 audio_manager_->GetMessageLoop()->PostTask(FROM_HERE, base::Bind( | |
79 &VirtualAudioInputStreamTest::AddStreamOnAudioThread, | |
80 base::Unretained(this))); | |
81 | |
82 done_.Wait(); | |
83 } | |
84 | |
85 } // namespace media | |
OLD | NEW |