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

Side by Side Diff: media/base/channel_mixing_matrix_unittest.cc

Issue 672793002: Expose the internal MatrixBuilder class as ChannelMixingMatrix. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add new files to BUILD.gn Created 6 years, 1 month 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
(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 // MSVC++ requires this to be set before any other includes to get M_SQRT1_2.
6 #define _USE_MATH_DEFINES
7
8 #include "media/base/channel_mixing_matrix.h"
9
10 #include <cmath>
11
12 #include "base/strings/stringprintf.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace media {
16
17 // Test all possible layout conversions can be constructed and mixed.
18 TEST(ChannelMixingMatrixTest, ConstructAllPossibleLayouts) {
19 for (ChannelLayout input_layout = CHANNEL_LAYOUT_MONO;
20 input_layout <= CHANNEL_LAYOUT_MAX;
21 input_layout = static_cast<ChannelLayout>(input_layout + 1)) {
22 for (ChannelLayout output_layout = CHANNEL_LAYOUT_MONO;
23 // TODO(wtc): why do we only test up to CHANNEL_LAYOUT_STEREO_DOWNMIX?
24 output_layout < CHANNEL_LAYOUT_STEREO_DOWNMIX;
25 output_layout = static_cast<ChannelLayout>(output_layout + 1)) {
26 // DISCRETE can't be tested here based on the current approach.
27 // CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC is not mixable.
28 if (input_layout == CHANNEL_LAYOUT_DISCRETE ||
29 input_layout == CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC ||
30 output_layout == CHANNEL_LAYOUT_DISCRETE ||
31 output_layout == CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC) {
32 continue;
33 }
34
35 SCOPED_TRACE(base::StringPrintf(
36 "Input Layout: %d, Output Layout: %d", input_layout, output_layout));
37 ChannelMixingMatrix matrix_builder(
38 input_layout,
39 ChannelLayoutToChannelCount(input_layout),
40 output_layout,
41 ChannelLayoutToChannelCount(output_layout));
42 std::vector<std::vector<float>> matrix;
43 matrix_builder.CreateTransformationMatrix(&matrix);
44 }
45 }
46 }
47
48 // Verify channels are mixed and scaled correctly.
49 TEST(ChannelMixingMatrixTest, StereoToMono) {
50 ChannelLayout input_layout = CHANNEL_LAYOUT_STEREO;
51 ChannelLayout output_layout = CHANNEL_LAYOUT_MONO;
52 ChannelMixingMatrix matrix_builder(
53 input_layout,
54 ChannelLayoutToChannelCount(input_layout),
55 output_layout,
56 ChannelLayoutToChannelCount(output_layout));
57 std::vector<std::vector<float>> matrix;
58 bool remapping = matrix_builder.CreateTransformationMatrix(&matrix);
59 EXPECT_FALSE(remapping);
60 EXPECT_EQ(1u, matrix.size());
61 EXPECT_EQ(2u, matrix[0].size());
62 EXPECT_EQ(0.5f, matrix[0][0]);
63 EXPECT_EQ(0.5f, matrix[0][1]);
64 }
65
66 TEST(ChannelMixingMatrixTest, MonoToStereo) {
67 ChannelLayout input_layout = CHANNEL_LAYOUT_MONO;
68 ChannelLayout output_layout = CHANNEL_LAYOUT_STEREO;
69 ChannelMixingMatrix matrix_builder(
70 input_layout,
71 ChannelLayoutToChannelCount(input_layout),
72 output_layout,
73 ChannelLayoutToChannelCount(output_layout));
74 std::vector<std::vector<float>> matrix;
75 bool remapping = matrix_builder.CreateTransformationMatrix(&matrix);
76 EXPECT_TRUE(remapping);
77 EXPECT_EQ(2u, matrix.size());
78 EXPECT_EQ(1u, matrix[0].size());
79 EXPECT_EQ(1.0f, matrix[0][0]);
80 EXPECT_EQ(1u, matrix[1].size());
81 EXPECT_EQ(1.0f, matrix[1][0]);
82 }
83
84 TEST(ChannelMixingMatrixTest, FiveOneToMono) {
85 ChannelLayout input_layout = CHANNEL_LAYOUT_5_1;
86 ChannelLayout output_layout = CHANNEL_LAYOUT_MONO;
87 ChannelMixingMatrix matrix_builder(
88 input_layout,
89 ChannelLayoutToChannelCount(input_layout),
90 output_layout,
91 ChannelLayoutToChannelCount(output_layout));
92 std::vector<std::vector<float>> matrix;
93 bool remapping = matrix_builder.CreateTransformationMatrix(&matrix);
94 EXPECT_FALSE(remapping);
95 EXPECT_EQ(1u, matrix.size());
96 EXPECT_EQ(6u, matrix[0].size());
97 EXPECT_EQ(static_cast<float>(M_SQRT1_2), matrix[0][0]);
DaleCurtis 2014/10/23 16:49:05 You may need EXPECT_FLOAT_EQ all over to get past
wtc 2014/10/23 18:39:45 Done. EXPECT_EQ also works on all the try bots. I
DaleCurtis 2014/10/23 19:23:50 I'd just wait and see if any trybots actually fail
98 EXPECT_EQ(static_cast<float>(M_SQRT1_2), matrix[0][1]);
99 // The center channel will be mixed at scale 1.
100 EXPECT_EQ(1.0f, matrix[0][2]);
101 EXPECT_EQ(static_cast<float>(M_SQRT1_2), matrix[0][3]);
102 EXPECT_EQ(static_cast<float>(M_SQRT1_2), matrix[0][4]);
103 EXPECT_EQ(static_cast<float>(M_SQRT1_2), matrix[0][5]);
104 }
105
106 TEST(ChannelMixingMatrixTest, DiscreteToDiscrete) {
107 const struct {
108 int input_channels;
109 int output_channels;
110 } test_case[] = {
111 {2, 2}, {2, 5}, {5, 2},
112 };
113
114 for (size_t n = 0; n < arraysize(test_case); n++) {
115 int input_channels = test_case[n].input_channels;
116 int output_channels = test_case[n].output_channels;
117 ChannelMixingMatrix matrix_builder(CHANNEL_LAYOUT_DISCRETE,
118 input_channels,
119 CHANNEL_LAYOUT_DISCRETE,
120 output_channels);
121 std::vector<std::vector<float>> matrix;
122 bool remapping = matrix_builder.CreateTransformationMatrix(&matrix);
123 EXPECT_TRUE(remapping);
124 EXPECT_EQ(static_cast<size_t>(output_channels), matrix.size());
125 for (int i = 0; i < output_channels; i++) {
126 EXPECT_EQ(static_cast<size_t>(input_channels), matrix[i].size());
127 for (int j = 0; j < input_channels; j++) {
128 if (i == j) {
129 EXPECT_EQ(1.0f, matrix[i][j]);
130 } else {
131 EXPECT_EQ(0.0f, matrix[i][j]);
132 }
133 }
134 }
135 }
136 }
137
138 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698