[tracing] Non functional refactor of MemoryInfra headers
[chromium-blink-merge.git] / media / base / audio_hardware_config_unittest.cc
blob2cb16fc96a31dd7257acc57ecb1fbcd03aa820cb
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"
10 namespace media {
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,
21 kInputChannelLayout,
22 kInputSampleRate,
23 16,
24 kOutputBufferSize);
26 AudioParameters output_params(
27 AudioParameters::AUDIO_PCM_LOW_LATENCY,
28 kOutputChannelLayout,
29 kOutputSampleRate,
30 16,
31 kOutputBufferSize);
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,
44 kInputChannelLayout,
45 kInputSampleRate,
46 16,
47 kOutputBufferSize);
49 AudioParameters output_params(
50 AudioParameters::AUDIO_PCM_LOW_LATENCY,
51 kOutputChannelLayout,
52 kOutputSampleRate,
53 16,
54 kOutputBufferSize);
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,
66 kOutputChannelLayout,
67 kNewOutputSampleRate,
68 16,
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,
83 kNewInputSampleRate,
84 16,
85 kOutputBufferSize);
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,
93 kInputChannelLayout,
94 kInputSampleRate,
95 16,
96 kOutputBufferSize);
97 AudioParameters output_params(AudioParameters::AUDIO_PCM_LOW_LATENCY,
98 kOutputChannelLayout,
99 3200,
101 32);
102 AudioHardwareConfig fake_config(input_params, output_params);
104 #if defined(OS_WIN)
105 for (int i = 6400; i <= 204800; i *= 2) {
106 fake_config.UpdateOutputConfig(
107 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
108 kOutputChannelLayout,
111 i / 100));
112 EXPECT_EQ(2 * (i / 100), fake_config.GetHighLatencyBufferSize());
114 #else
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,
123 32));
124 EXPECT_EQ(2 * (i / 100), fake_config.GetHighLatencyBufferSize());
126 #endif // defined(OS_WIN)
129 } // namespace content