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

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

Issue 344583002: Modifies AudioInputCallback::OnData and use media::AudioBus instead of plain byte vector (Relanding) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added extra non-pure OnData API Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/cras/cras_input.h ('k') | media/audio/cras/cras_input_unittest.cc » ('j') | 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"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "media/audio/audio_manager.h" 12 #include "media/audio/audio_manager.h"
13 #include "media/audio/cras/audio_manager_cras.h" 13 #include "media/audio/cras/audio_manager_cras.h"
14 14
15 namespace media { 15 namespace media {
16 16
17 CrasInputStream::CrasInputStream(const AudioParameters& params, 17 CrasInputStream::CrasInputStream(const AudioParameters& params,
18 AudioManagerCras* manager, 18 AudioManagerCras* manager,
19 const std::string& device_id) 19 const std::string& device_id)
20 : audio_manager_(manager), 20 : audio_manager_(manager),
21 bytes_per_frame_(0), 21 bytes_per_frame_(0),
22 callback_(NULL), 22 callback_(NULL),
23 client_(NULL), 23 client_(NULL),
24 params_(params), 24 params_(params),
25 started_(false), 25 started_(false),
26 stream_id_(0), 26 stream_id_(0),
27 stream_direction_(device_id == AudioManagerBase::kLoopbackInputDeviceId ? 27 stream_direction_(device_id == AudioManagerBase::kLoopbackInputDeviceId ?
28 CRAS_STREAM_POST_MIX_PRE_DSP : CRAS_STREAM_INPUT) { 28 CRAS_STREAM_POST_MIX_PRE_DSP : CRAS_STREAM_INPUT) {
29 DCHECK(audio_manager_); 29 DCHECK(audio_manager_);
30 audio_bus_ = AudioBus::Create(params_);
30 } 31 }
31 32
32 CrasInputStream::~CrasInputStream() { 33 CrasInputStream::~CrasInputStream() {
33 DCHECK(!client_); 34 DCHECK(!client_);
34 } 35 }
35 36
36 bool CrasInputStream::Open() { 37 bool CrasInputStream::Open() {
37 if (client_) { 38 if (client_) {
38 NOTREACHED() << "CrasInputStream already open"; 39 NOTREACHED() << "CrasInputStream already open";
39 return false; // Already open. 40 return false; // Already open.
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 latency_usec * params_.sample_rate() / base::Time::kMicrosecondsPerSecond; 216 latency_usec * params_.sample_rate() / base::Time::kMicrosecondsPerSecond;
216 unsigned int bytes_latency = 217 unsigned int bytes_latency =
217 static_cast<unsigned int>(frames_latency * bytes_per_frame_); 218 static_cast<unsigned int>(frames_latency * bytes_per_frame_);
218 219
219 // Update the AGC volume level once every second. Note that, |volume| is 220 // Update the AGC volume level once every second. Note that, |volume| is
220 // also updated each time SetVolume() is called through IPC by the 221 // also updated each time SetVolume() is called through IPC by the
221 // render-side AGC. 222 // render-side AGC.
222 double normalized_volume = 0.0; 223 double normalized_volume = 0.0;
223 GetAgcVolume(&normalized_volume); 224 GetAgcVolume(&normalized_volume);
224 225
225 callback_->OnData(this, 226 audio_bus_->FromInterleaved(
226 buffer, 227 buffer, audio_bus_->frames(), params_.bits_per_sample() / 8);
227 frames * bytes_per_frame_, 228 callback_->OnData(this, audio_bus_.get(), bytes_latency, normalized_volume);
228 bytes_latency,
229 normalized_volume);
230 } 229 }
231 230
232 void CrasInputStream::NotifyStreamError(int err) { 231 void CrasInputStream::NotifyStreamError(int err) {
233 if (callback_) 232 if (callback_)
234 callback_->OnError(this); 233 callback_->OnError(this);
235 } 234 }
236 235
237 double CrasInputStream::GetMaxVolume() { 236 double CrasInputStream::GetMaxVolume() {
238 DCHECK(client_); 237 DCHECK(client_);
239 238
(...skipping 28 matching lines...) Expand all
268 267
269 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { 268 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const {
270 return pow(10, dB / 20.0); 269 return pow(10, dB / 20.0);
271 } 270 }
272 271
273 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { 272 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const {
274 return 20 * log10(volume_ratio); 273 return 20 * log10(volume_ratio);
275 } 274 }
276 275
277 } // namespace media 276 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/cras/cras_input.h ('k') | media/audio/cras/cras_input_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698