• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "media/base/audio_hardware_config.h"
6 #include "media/audio/audio_parameters.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 
9 namespace media {
10 
11 static const int kOutputBufferSize = 2048;
12 static const int kOutputSampleRate = 48000;
13 static const ChannelLayout kOutputChannelLayout = CHANNEL_LAYOUT_STEREO;
14 static const int kInputSampleRate = 44100;
15 static const ChannelLayout kInputChannelLayout = CHANNEL_LAYOUT_STEREO;
16 
TEST(AudioHardwareConfig,Getters)17 TEST(AudioHardwareConfig, Getters) {
18   AudioParameters input_params(
19       AudioParameters::AUDIO_PCM_LOW_LATENCY,
20       kInputChannelLayout,
21       kInputSampleRate,
22       16,
23       kOutputBufferSize);
24 
25   AudioParameters output_params(
26       AudioParameters::AUDIO_PCM_LOW_LATENCY,
27       kOutputChannelLayout,
28       kOutputSampleRate,
29       16,
30       kOutputBufferSize);
31 
32   AudioHardwareConfig fake_config(input_params, output_params);
33 
34   EXPECT_EQ(kOutputBufferSize, fake_config.GetOutputBufferSize());
35   EXPECT_EQ(kOutputSampleRate, fake_config.GetOutputSampleRate());
36   EXPECT_EQ(kInputSampleRate, fake_config.GetInputSampleRate());
37   EXPECT_EQ(kInputChannelLayout, fake_config.GetInputChannelLayout());
38 }
39 
TEST(AudioHardwareConfig,Setters)40 TEST(AudioHardwareConfig, Setters) {
41   AudioParameters input_params(
42       AudioParameters::AUDIO_PCM_LOW_LATENCY,
43       kInputChannelLayout,
44       kInputSampleRate,
45       16,
46       kOutputBufferSize);
47 
48   AudioParameters output_params(
49       AudioParameters::AUDIO_PCM_LOW_LATENCY,
50       kOutputChannelLayout,
51       kOutputSampleRate,
52       16,
53       kOutputBufferSize);
54 
55   AudioHardwareConfig fake_config(input_params, output_params);
56 
57   // Verify output parameters.
58   const int kNewOutputBufferSize = kOutputBufferSize * 2;
59   const int kNewOutputSampleRate = kOutputSampleRate * 2;
60   EXPECT_NE(kNewOutputBufferSize, fake_config.GetOutputBufferSize());
61   EXPECT_NE(kNewOutputSampleRate, fake_config.GetOutputSampleRate());
62 
63   AudioParameters new_output_params(
64       AudioParameters::AUDIO_PCM_LOW_LATENCY,
65       kOutputChannelLayout,
66       kNewOutputSampleRate,
67       16,
68       kNewOutputBufferSize);
69   fake_config.UpdateOutputConfig(new_output_params);
70   EXPECT_EQ(kNewOutputBufferSize, fake_config.GetOutputBufferSize());
71   EXPECT_EQ(kNewOutputSampleRate, fake_config.GetOutputSampleRate());
72 
73   // Verify input parameters.
74   const int kNewInputSampleRate = kInputSampleRate * 2;
75   const ChannelLayout kNewInputChannelLayout = CHANNEL_LAYOUT_MONO;
76   EXPECT_NE(kNewInputSampleRate, fake_config.GetInputSampleRate());
77   EXPECT_NE(kNewInputChannelLayout, fake_config.GetInputChannelLayout());
78 
79   AudioParameters new_input_params(
80       AudioParameters::AUDIO_PCM_LOW_LATENCY,
81       kNewInputChannelLayout,
82       kNewInputSampleRate,
83       16,
84       kOutputBufferSize);
85   fake_config.UpdateInputConfig(new_input_params);
86   EXPECT_EQ(kNewInputSampleRate, fake_config.GetInputSampleRate());
87   EXPECT_EQ(kNewInputChannelLayout, fake_config.GetInputChannelLayout());
88 }
89 
90 }  // namespace content
91