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

Side by Side Diff: media/audio/cras/cras_input.cc

Issue 531523002: Convert channel layout for cras_input (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "media/audio/cras/cras_input.h" 5 #include "media/audio/cras/cras_input.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 95
96 // Signal to the manager that we're closed and can be removed. 96 // Signal to the manager that we're closed and can be removed.
97 // Should be last call in the method as it deletes "this". 97 // Should be last call in the method as it deletes "this".
98 audio_manager_->ReleaseInputStream(this); 98 audio_manager_->ReleaseInputStream(this);
99 } 99 }
100 100
101 void CrasInputStream::Start(AudioInputCallback* callback) { 101 void CrasInputStream::Start(AudioInputCallback* callback) {
102 DCHECK(client_); 102 DCHECK(client_);
103 DCHECK(callback); 103 DCHECK(callback);
104 104
105 // Channel map to CRAS_CHANNEL, values in the same order of
106 // corresponding source in Chromium defined Channels.
107 static const int kChannelMap[] = {
108 CRAS_CH_FL,
109 CRAS_CH_FR,
110 CRAS_CH_FC,
111 CRAS_CH_LFE,
112 CRAS_CH_RL,
113 CRAS_CH_RR,
114 CRAS_CH_FLC,
115 CRAS_CH_FRC,
116 CRAS_CH_RC,
117 CRAS_CH_SL,
118 CRAS_CH_SR
119 };
120 COMPILE_ASSERT(arraysize(kChannelMap) == CHANNELS_MAX + 1,
121 channel_map_size_do_not_match);
122
105 // If already playing, stop before re-starting. 123 // If already playing, stop before re-starting.
106 if (started_) 124 if (started_)
107 return; 125 return;
108 126
109 StartAgc(); 127 StartAgc();
110 128
111 callback_ = callback; 129 callback_ = callback;
112 130
113 // Prepare |audio_format| and |stream_params| for the stream we 131 // Prepare |audio_format| and |stream_params| for the stream we
114 // will create. 132 // will create.
115 cras_audio_format* audio_format = cras_audio_format_create( 133 cras_audio_format* audio_format = cras_audio_format_create(
116 AudioManagerCras::BitsToFormat(params_.bits_per_sample()), 134 AudioManagerCras::BitsToFormat(params_.bits_per_sample()),
117 params_.sample_rate(), 135 params_.sample_rate(),
118 params_.channels()); 136 params_.channels());
119 if (!audio_format) { 137 if (!audio_format) {
120 DLOG(WARNING) << "Error setting up audio parameters."; 138 DLOG(WARNING) << "Error setting up audio parameters.";
121 callback_->OnError(this); 139 callback_->OnError(this);
122 callback_ = NULL; 140 callback_ = NULL;
123 return; 141 return;
124 } 142 }
125 143
144 // Initialize channel layout to all -1 to indicate that none of
145 // the channels is set in the layout.
146 int8 layout[CRAS_CH_MAX];
147 for (size_t i = 0; i < arraysize(layout); ++i)
148 layout[i] = -1;
149
150 // Converts to CRAS defined channels. ChannelOrder will return -1
151 // for channels that are not present in params_.channel_layout().
152 for (size_t i = 0; i < arraysize(kChannelMap); ++i) {
153 layout[kChannelMap[i]] = ChannelOrder(params_.channel_layout(),
154 static_cast<Channels>(i));
155 }
156 if (cras_audio_format_set_channel_layout(audio_format, layout) != 0) {
157 DLOG(WARNING) << "Error setting channel layout.";
158 callback->OnError(this);
159 return;
160 }
161
126 unsigned int frames_per_packet = params_.frames_per_buffer(); 162 unsigned int frames_per_packet = params_.frames_per_buffer();
127 cras_stream_params* stream_params = cras_client_stream_params_create( 163 cras_stream_params* stream_params = cras_client_stream_params_create(
128 stream_direction_, 164 stream_direction_,
129 frames_per_packet, // Total latency. 165 frames_per_packet, // Total latency.
130 frames_per_packet, // Call back when this many ready. 166 frames_per_packet, // Call back when this many ready.
131 frames_per_packet, // Minimum Callback level ignored for capture streams. 167 frames_per_packet, // Minimum Callback level ignored for capture streams.
132 CRAS_STREAM_TYPE_DEFAULT, 168 CRAS_STREAM_TYPE_DEFAULT,
133 0, // Unused flags. 169 0, // Unused flags.
134 this, 170 this,
135 CrasInputStream::SamplesReady, 171 CrasInputStream::SamplesReady,
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 303
268 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { 304 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const {
269 return pow(10, dB / 20.0); 305 return pow(10, dB / 20.0);
270 } 306 }
271 307
272 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { 308 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const {
273 return 20 * log10(volume_ratio); 309 return 20 * log10(volume_ratio);
274 } 310 }
275 311
276 } // namespace media 312 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698