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

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

Issue 148553003: Clean up histogram'd media enum max values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 6 years, 10 months 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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 // MSVC++ requires this to be set before any other includes to get M_SQRT1_2. 5 // MSVC++ requires this to be set before any other includes to get M_SQRT1_2.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include "media/base/channel_mixer.h" 8 #include "media/base/channel_mixer.h"
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <cmath> 11 #include <cmath>
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "media/audio/audio_parameters.h" 14 #include "media/audio/audio_parameters.h"
15 #include "media/base/audio_bus.h" 15 #include "media/base/audio_bus.h"
16 #include "media/base/vector_math.h" 16 #include "media/base/vector_math.h"
17 17
18 namespace media { 18 namespace media {
19 19
20 // Default scale factor for mixing two channels together. We use a different 20 // Default scale factor for mixing two channels together. We use a different
21 // value for stereo -> mono and mono -> stereo mixes. 21 // value for stereo -> mono and mono -> stereo mixes.
22 static const float kEqualPowerScale = static_cast<float>(M_SQRT1_2); 22 static const float kEqualPowerScale = static_cast<float>(M_SQRT1_2);
23 23
24 static void ValidateLayout(ChannelLayout layout) { 24 static void ValidateLayout(ChannelLayout layout) {
25 CHECK_NE(layout, CHANNEL_LAYOUT_NONE); 25 CHECK_NE(layout, CHANNEL_LAYOUT_NONE);
26 CHECK_NE(layout, CHANNEL_LAYOUT_MAX); 26 CHECK_LE(layout, CHANNEL_LAYOUT_MAX);
27 CHECK_NE(layout, CHANNEL_LAYOUT_UNSUPPORTED); 27 CHECK_NE(layout, CHANNEL_LAYOUT_UNSUPPORTED);
28 CHECK_NE(layout, CHANNEL_LAYOUT_DISCRETE); 28 CHECK_NE(layout, CHANNEL_LAYOUT_DISCRETE);
29 29
30 // Verify there's at least one channel. Should always be true here by virtue 30 // Verify there's at least one channel. Should always be true here by virtue
31 // of not being one of the invalid layouts, but lets double check to be sure. 31 // of not being one of the invalid layouts, but lets double check to be sure.
32 int channel_count = ChannelLayoutToChannelCount(layout); 32 int channel_count = ChannelLayoutToChannelCount(layout);
33 DCHECK_GT(channel_count, 0); 33 DCHECK_GT(channel_count, 0);
34 34
35 // If we have more than one channel, verify a symmetric layout for sanity. 35 // If we have more than one channel, verify a symmetric layout for sanity.
36 // The unit test will verify all possible layouts, so this can be a DCHECK. 36 // The unit test will verify all possible layouts, so this can be a DCHECK.
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // If the number of input channels is less than output channels, then 163 // If the number of input channels is less than output channels, then
164 // copy them all, then zero out the remaining output channels. 164 // copy them all, then zero out the remaining output channels.
165 int passthrough_channels = std::min(input_channels_, output_channels_); 165 int passthrough_channels = std::min(input_channels_, output_channels_);
166 for (int i = 0; i < passthrough_channels; ++i) 166 for (int i = 0; i < passthrough_channels; ++i)
167 (*matrix_)[i][i] = 1; 167 (*matrix_)[i][i] = 1;
168 168
169 return true; 169 return true;
170 } 170 }
171 171
172 // Route matching channels and figure out which ones aren't accounted for. 172 // Route matching channels and figure out which ones aren't accounted for.
173 for (Channels ch = LEFT; ch < CHANNELS_MAX; 173 for (Channels ch = LEFT; ch < CHANNELS_MAX + 1;
174 ch = static_cast<Channels>(ch + 1)) { 174 ch = static_cast<Channels>(ch + 1)) {
175 int input_ch_index = ChannelOrder(input_layout_, ch); 175 int input_ch_index = ChannelOrder(input_layout_, ch);
176 if (input_ch_index < 0) 176 if (input_ch_index < 0)
177 continue; 177 continue;
178 178
179 int output_ch_index = ChannelOrder(output_layout_, ch); 179 int output_ch_index = ChannelOrder(output_layout_, ch);
180 if (output_ch_index < 0) { 180 if (output_ch_index < 0) {
181 unaccounted_inputs_.push_back(ch); 181 unaccounted_inputs_.push_back(ch);
182 continue; 182 continue;
183 } 183 }
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 397
398 DCHECK(IsUnaccounted(input_ch)); 398 DCHECK(IsUnaccounted(input_ch));
399 DCHECK_GE(input_ch_index, 0); 399 DCHECK_GE(input_ch_index, 0);
400 DCHECK_GE(output_ch_index, 0); 400 DCHECK_GE(output_ch_index, 0);
401 401
402 DCHECK_EQ((*matrix_)[output_ch_index][input_ch_index], 0); 402 DCHECK_EQ((*matrix_)[output_ch_index][input_ch_index], 0);
403 (*matrix_)[output_ch_index][input_ch_index] = scale; 403 (*matrix_)[output_ch_index][input_ch_index] = scale;
404 } 404 }
405 405
406 } // namespace media 406 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698