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

Side by Side Diff: media/audio/cras/cras_unified_unittest.cc

Issue 2516813002: Enable pinning stream output routing for webapp request on ChromeOS (Closed)
Patch Set: comment Created 4 years 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
OLDNEW
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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "base/test/test_message_loop.h" 13 #include "base/test/test_message_loop.h"
14 #include "base/test/test_timeouts.h" 14 #include "base/test/test_timeouts.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "media/audio/audio_device_description.h"
17 #include "media/audio/cras/audio_manager_cras.h" 18 #include "media/audio/cras/audio_manager_cras.h"
18 #include "media/audio/fake_audio_log_factory.h" 19 #include "media/audio/fake_audio_log_factory.h"
19 #include "media/audio/mock_audio_source_callback.h" 20 #include "media/audio/mock_audio_source_callback.h"
20 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 // cras_util.h defines custom min/max macros which break compilation, so ensure 24 // cras_util.h defines custom min/max macros which break compilation, so ensure
24 // it's not included until last. #if avoids presubmit errors. 25 // it's not included until last. #if avoids presubmit errors.
25 #if defined(USE_CRAS) 26 #if defined(USE_CRAS)
26 #include "media/audio/cras/cras_unified.h" 27 #include "media/audio/cras/cras_unified.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 ~CrasUnifiedStreamTest() override {} 66 ~CrasUnifiedStreamTest() override {}
66 67
67 CrasUnifiedStream* CreateStream(ChannelLayout layout) { 68 CrasUnifiedStream* CreateStream(ChannelLayout layout) {
68 return CreateStream(layout, kTestFramesPerPacket); 69 return CreateStream(layout, kTestFramesPerPacket);
69 } 70 }
70 71
71 CrasUnifiedStream* CreateStream(ChannelLayout layout, 72 CrasUnifiedStream* CreateStream(ChannelLayout layout,
72 int32_t samples_per_packet) { 73 int32_t samples_per_packet) {
73 AudioParameters params(kTestFormat, layout, kTestSampleRate, 74 AudioParameters params(kTestFormat, layout, kTestSampleRate,
74 kTestBitsPerSample, samples_per_packet); 75 kTestBitsPerSample, samples_per_packet);
75 return new CrasUnifiedStream(params, mock_manager_.get()); 76 return new CrasUnifiedStream(params, mock_manager_.get(),
77 AudioDeviceDescription::kDefaultDeviceId);
76 } 78 }
77 79
78 MockAudioManagerCras& mock_manager() { 80 MockAudioManagerCras& mock_manager() {
79 return *(mock_manager_.get()); 81 return *(mock_manager_.get());
80 } 82 }
81 83
82 static const ChannelLayout kTestChannelLayout; 84 static const ChannelLayout kTestChannelLayout;
83 static const int kTestSampleRate; 85 static const int kTestSampleRate;
84 static const int kTestBitsPerSample; 86 static const int kTestBitsPerSample;
85 static const AudioParameters::Format kTestFormat; 87 static const AudioParameters::Format kTestFormat;
(...skipping 28 matching lines...) Expand all
114 116
115 // Should support multi-channel. 117 // Should support multi-channel.
116 test_stream = CreateStream(CHANNEL_LAYOUT_SURROUND); 118 test_stream = CreateStream(CHANNEL_LAYOUT_SURROUND);
117 EXPECT_TRUE(test_stream->Open()); 119 EXPECT_TRUE(test_stream->Open());
118 test_stream->Close(); 120 test_stream->Close();
119 121
120 // Bad bits per sample. 122 // Bad bits per sample.
121 AudioParameters bad_bps_params(kTestFormat, kTestChannelLayout, 123 AudioParameters bad_bps_params(kTestFormat, kTestChannelLayout,
122 kTestSampleRate, kTestBitsPerSample - 1, 124 kTestSampleRate, kTestBitsPerSample - 1,
123 kTestFramesPerPacket); 125 kTestFramesPerPacket);
124 test_stream = new CrasUnifiedStream(bad_bps_params, mock_manager_.get()); 126 test_stream = new CrasUnifiedStream(bad_bps_params, mock_manager_.get(),
127 AudioDeviceDescription::kDefaultDeviceId);
125 EXPECT_FALSE(test_stream->Open()); 128 EXPECT_FALSE(test_stream->Open());
126 test_stream->Close(); 129 test_stream->Close();
127 130
128 // Bad sample rate. 131 // Bad sample rate.
129 AudioParameters bad_rate_params(kTestFormat, kTestChannelLayout, 132 AudioParameters bad_rate_params(kTestFormat, kTestChannelLayout,
130 0, kTestBitsPerSample, kTestFramesPerPacket); 133 0, kTestBitsPerSample, kTestFramesPerPacket);
131 test_stream = new CrasUnifiedStream(bad_rate_params, mock_manager_.get()); 134 test_stream = new CrasUnifiedStream(bad_rate_params, mock_manager_.get(),
135 AudioDeviceDescription::kDefaultDeviceId);
132 EXPECT_FALSE(test_stream->Open()); 136 EXPECT_FALSE(test_stream->Open());
133 test_stream->Close(); 137 test_stream->Close();
134 } 138 }
135 139
136 TEST_F(CrasUnifiedStreamTest, RenderFrames) { 140 TEST_F(CrasUnifiedStreamTest, RenderFrames) {
137 CrasUnifiedStream* test_stream = CreateStream(CHANNEL_LAYOUT_MONO); 141 CrasUnifiedStream* test_stream = CreateStream(CHANNEL_LAYOUT_MONO);
138 MockAudioSourceCallback mock_callback; 142 MockAudioSourceCallback mock_callback;
139 143
140 ASSERT_TRUE(test_stream->Open()); 144 ASSERT_TRUE(test_stream->Open());
141 145
142 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, 146 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC,
143 base::WaitableEvent::InitialState::NOT_SIGNALED); 147 base::WaitableEvent::InitialState::NOT_SIGNALED);
144 148
145 EXPECT_CALL(mock_callback, OnMoreData(_, _, 0, _)) 149 EXPECT_CALL(mock_callback, OnMoreData(_, _, 0, _))
146 .WillRepeatedly( 150 .WillRepeatedly(
147 DoAll(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal), 151 DoAll(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal),
148 Return(kTestFramesPerPacket))); 152 Return(kTestFramesPerPacket)));
149 153
150 test_stream->Start(&mock_callback); 154 test_stream->Start(&mock_callback);
151 155
152 // Wait for samples to be captured. 156 // Wait for samples to be captured.
153 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); 157 EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout()));
154 158
155 test_stream->Stop(); 159 test_stream->Stop();
156 160
157 test_stream->Close(); 161 test_stream->Close();
158 } 162 }
159 163
160 } // namespace media 164 } // namespace media
OLDNEW
« media/audio/cras/cras_unified.cc ('K') | « media/audio/cras/cras_unified.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698