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

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

Issue 132773002: Fix chromeos=1 so Pulse is preferred when use_cras=0. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove alsa_util.h dependency. Created 6 years, 11 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
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/bind.h"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #include "base/time/time.h" 11 #include "base/time/time.h"
13 #include "media/audio/alsa/alsa_util.h"
14 #include "media/audio/audio_manager.h" 12 #include "media/audio/audio_manager.h"
15 #include "media/audio/cras/audio_manager_cras.h" 13 #include "media/audio/cras/audio_manager_cras.h"
16 14
17 namespace media { 15 namespace media {
18 16
19 CrasInputStream::CrasInputStream(const AudioParameters& params, 17 CrasInputStream::CrasInputStream(const AudioParameters& params,
20 AudioManagerCras* manager, 18 AudioManagerCras* manager,
21 const std::string& device_id) 19 const std::string& device_id)
22 : audio_manager_(manager), 20 : audio_manager_(manager),
23 bytes_per_frame_(0), 21 bytes_per_frame_(0),
(...skipping 23 matching lines...) Expand all
47 return false; 45 return false;
48 } 46 }
49 47
50 if (AudioParameters::AUDIO_PCM_LINEAR != params_.format() && 48 if (AudioParameters::AUDIO_PCM_LINEAR != params_.format() &&
51 AudioParameters::AUDIO_PCM_LOW_LATENCY != params_.format()) { 49 AudioParameters::AUDIO_PCM_LOW_LATENCY != params_.format()) {
52 DLOG(WARNING) << "Unsupported audio format."; 50 DLOG(WARNING) << "Unsupported audio format.";
53 return false; 51 return false;
54 } 52 }
55 53
56 snd_pcm_format_t pcm_format = 54 snd_pcm_format_t pcm_format =
57 alsa_util::BitsToFormat(params_.bits_per_sample()); 55 AudioManagerCras::BitsToFormat(params_.bits_per_sample());
58 if (pcm_format == SND_PCM_FORMAT_UNKNOWN) { 56 if (pcm_format == SND_PCM_FORMAT_UNKNOWN) {
59 DLOG(WARNING) << "Unsupported bits/sample: " << params_.bits_per_sample(); 57 DLOG(WARNING) << "Unsupported bits/sample: " << params_.bits_per_sample();
60 return false; 58 return false;
61 } 59 }
62 60
63 // Create the client and connect to the CRAS server. 61 // Create the client and connect to the CRAS server.
64 if (cras_client_create(&client_) < 0) { 62 if (cras_client_create(&client_) < 0) {
65 DLOG(WARNING) << "Couldn't create CRAS client.\n"; 63 DLOG(WARNING) << "Couldn't create CRAS client.\n";
66 client_ = NULL; 64 client_ = NULL;
67 return false; 65 return false;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 if (started_) 105 if (started_)
108 return; 106 return;
109 107
110 StartAgc(); 108 StartAgc();
111 109
112 callback_ = callback; 110 callback_ = callback;
113 111
114 // Prepare |audio_format| and |stream_params| for the stream we 112 // Prepare |audio_format| and |stream_params| for the stream we
115 // will create. 113 // will create.
116 cras_audio_format* audio_format = cras_audio_format_create( 114 cras_audio_format* audio_format = cras_audio_format_create(
117 alsa_util::BitsToFormat(params_.bits_per_sample()), 115 AudioManagerCras::BitsToFormat(params_.bits_per_sample()),
118 params_.sample_rate(), 116 params_.sample_rate(),
119 params_.channels()); 117 params_.channels());
120 if (!audio_format) { 118 if (!audio_format) {
121 DLOG(WARNING) << "Error setting up audio parameters."; 119 DLOG(WARNING) << "Error setting up audio parameters.";
122 callback_->OnError(this); 120 callback_->OnError(this);
123 callback_ = NULL; 121 callback_ = NULL;
124 return; 122 return;
125 } 123 }
126 124
127 unsigned int frames_per_packet = params_.frames_per_buffer(); 125 unsigned int frames_per_packet = params_.frames_per_buffer();
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 268
271 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const { 269 double CrasInputStream::GetVolumeRatioFromDecibels(double dB) const {
272 return pow(10, dB / 20.0); 270 return pow(10, dB / 20.0);
273 } 271 }
274 272
275 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const { 273 double CrasInputStream::GetDecibelsFromVolumeRatio(double volume_ratio) const {
276 return 20 * log10(volume_ratio); 274 return 20 * log10(volume_ratio);
277 } 275 }
278 276
279 } // namespace media 277 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698