1 // Copyright (c) 2013 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.
5 #include "build/build_config.h"
6 #include "media/base/audio_hardware_config.h"
7 #include "media/audio/audio_parameters.h"
8 #include "testing/gtest/include/gtest/gtest.h"
12 static const int kOutputBufferSize
= 2048;
13 static const int kOutputSampleRate
= 48000;
14 static const ChannelLayout kOutputChannelLayout
= CHANNEL_LAYOUT_STEREO
;
15 static const int kInputSampleRate
= 44100;
16 static const ChannelLayout kInputChannelLayout
= CHANNEL_LAYOUT_STEREO
;
18 TEST(AudioHardwareConfig
, Getters
) {
19 AudioParameters
input_params(
20 AudioParameters::AUDIO_PCM_LOW_LATENCY
,
26 AudioParameters
output_params(
27 AudioParameters::AUDIO_PCM_LOW_LATENCY
,
33 AudioHardwareConfig
fake_config(input_params
, output_params
);
35 EXPECT_EQ(kOutputBufferSize
, fake_config
.GetOutputBufferSize());
36 EXPECT_EQ(kOutputSampleRate
, fake_config
.GetOutputSampleRate());
37 EXPECT_EQ(kInputSampleRate
, fake_config
.GetInputSampleRate());
38 EXPECT_EQ(kInputChannelLayout
, fake_config
.GetInputChannelLayout());
41 TEST(AudioHardwareConfig
, Setters
) {
42 AudioParameters
input_params(
43 AudioParameters::AUDIO_PCM_LOW_LATENCY
,
49 AudioParameters
output_params(
50 AudioParameters::AUDIO_PCM_LOW_LATENCY
,
56 AudioHardwareConfig
fake_config(input_params
, output_params
);
58 // Verify output parameters.
59 const int kNewOutputBufferSize
= kOutputBufferSize
* 2;
60 const int kNewOutputSampleRate
= kOutputSampleRate
* 2;
61 EXPECT_NE(kNewOutputBufferSize
, fake_config
.GetOutputBufferSize());
62 EXPECT_NE(kNewOutputSampleRate
, fake_config
.GetOutputSampleRate());
64 AudioParameters
new_output_params(
65 AudioParameters::AUDIO_PCM_LOW_LATENCY
,
69 kNewOutputBufferSize
);
70 fake_config
.UpdateOutputConfig(new_output_params
);
71 EXPECT_EQ(kNewOutputBufferSize
, fake_config
.GetOutputBufferSize());
72 EXPECT_EQ(kNewOutputSampleRate
, fake_config
.GetOutputSampleRate());
74 // Verify input parameters.
75 const int kNewInputSampleRate
= kInputSampleRate
* 2;
76 const ChannelLayout kNewInputChannelLayout
= CHANNEL_LAYOUT_MONO
;
77 EXPECT_NE(kNewInputSampleRate
, fake_config
.GetInputSampleRate());
78 EXPECT_NE(kNewInputChannelLayout
, fake_config
.GetInputChannelLayout());
80 AudioParameters
new_input_params(
81 AudioParameters::AUDIO_PCM_LOW_LATENCY
,
82 kNewInputChannelLayout
,
86 fake_config
.UpdateInputConfig(new_input_params
);
87 EXPECT_EQ(kNewInputSampleRate
, fake_config
.GetInputSampleRate());
88 EXPECT_EQ(kNewInputChannelLayout
, fake_config
.GetInputChannelLayout());
91 TEST(AudioHardwareConfig
, HighLatencyBufferSizes
) {
92 AudioParameters
input_params(AudioParameters::AUDIO_PCM_LOW_LATENCY
,
97 AudioParameters
output_params(AudioParameters::AUDIO_PCM_LOW_LATENCY
,
102 AudioHardwareConfig
fake_config(input_params
, output_params
);
105 for (int i
= 6400; i
<= 204800; i
*= 2) {
106 fake_config
.UpdateOutputConfig(
107 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
,
108 kOutputChannelLayout
,
112 EXPECT_EQ(2 * (i
/ 100), fake_config
.GetHighLatencyBufferSize());
115 EXPECT_EQ(64, fake_config
.GetHighLatencyBufferSize());
117 for (int i
= 6400; i
<= 204800; i
*= 2) {
118 fake_config
.UpdateOutputConfig(
119 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
,
120 kOutputChannelLayout
,
124 EXPECT_EQ(2 * (i
/ 100), fake_config
.GetHighLatencyBufferSize());
126 #endif // defined(OS_WIN)
129 } // namespace content