OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_unified.h" | 5 #include "media/audio/cras/cras_unified.h" |
6 | 6 |
7 #include <cras_client.h> | |
8 | |
9 #include "base/command_line.h" | |
10 #include "base/logging.h" | 7 #include "base/logging.h" |
11 #include "media/audio/alsa/alsa_util.h" | |
12 #include "media/audio/cras/audio_manager_cras.h" | 8 #include "media/audio/cras/audio_manager_cras.h" |
13 | 9 |
14 namespace media { | 10 namespace media { |
15 | 11 |
16 // Overview of operation: | 12 // Overview of operation: |
17 // 1) An object of CrasUnifiedStream is created by the AudioManager | 13 // 1) An object of CrasUnifiedStream is created by the AudioManager |
18 // factory: audio_man->MakeAudioStream(). | 14 // factory: audio_man->MakeAudioStream(). |
19 // 2) Next some thread will call Open(), at that point a client is created and | 15 // 2) Next some thread will call Open(), at that point a client is created and |
20 // configured for the correct format and sample rate. | 16 // configured for the correct format and sample rate. |
21 // 3) Then Start(source) is called and a stream is added to the CRAS client | 17 // 3) Then Start(source) is called and a stream is added to the CRAS client |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 DCHECK(!is_playing_); | 105 DCHECK(!is_playing_); |
110 } | 106 } |
111 | 107 |
112 bool CrasUnifiedStream::Open() { | 108 bool CrasUnifiedStream::Open() { |
113 // Sanity check input values. | 109 // Sanity check input values. |
114 if (params_.sample_rate() <= 0) { | 110 if (params_.sample_rate() <= 0) { |
115 LOG(WARNING) << "Unsupported audio frequency."; | 111 LOG(WARNING) << "Unsupported audio frequency."; |
116 return false; | 112 return false; |
117 } | 113 } |
118 | 114 |
119 if (alsa_util::BitsToFormat(params_.bits_per_sample()) == | 115 if (AudioManagerCras::BitsToFormat(params_.bits_per_sample()) == |
120 SND_PCM_FORMAT_UNKNOWN) { | 116 SND_PCM_FORMAT_UNKNOWN) { |
121 LOG(WARNING) << "Unsupported pcm format"; | 117 LOG(WARNING) << "Unsupported pcm format"; |
122 return false; | 118 return false; |
123 } | 119 } |
124 | 120 |
125 // Create the client and connect to the CRAS server. | 121 // Create the client and connect to the CRAS server. |
126 if (cras_client_create(&client_)) { | 122 if (cras_client_create(&client_)) { |
127 LOG(WARNING) << "Couldn't create CRAS client.\n"; | 123 LOG(WARNING) << "Couldn't create CRAS client.\n"; |
128 client_ = NULL; | 124 client_ = NULL; |
129 return false; | 125 return false; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 176 |
181 source_callback_ = callback; | 177 source_callback_ = callback; |
182 | 178 |
183 // Only start if we can enter the playing state. | 179 // Only start if we can enter the playing state. |
184 if (is_playing_) | 180 if (is_playing_) |
185 return; | 181 return; |
186 | 182 |
187 // Prepare |audio_format| and |stream_params| for the stream we | 183 // Prepare |audio_format| and |stream_params| for the stream we |
188 // will create. | 184 // will create. |
189 cras_audio_format* audio_format = cras_audio_format_create( | 185 cras_audio_format* audio_format = cras_audio_format_create( |
190 alsa_util::BitsToFormat(params_.bits_per_sample()), | 186 AudioManagerCras::BitsToFormat(params_.bits_per_sample()), |
191 params_.sample_rate(), | 187 params_.sample_rate(), |
192 params_.channels()); | 188 params_.channels()); |
193 if (!audio_format) { | 189 if (!audio_format) { |
194 LOG(WARNING) << "Error setting up audio parameters."; | 190 LOG(WARNING) << "Error setting up audio parameters."; |
195 callback->OnError(this); | 191 callback->OnError(this); |
196 return; | 192 return; |
197 } | 193 } |
198 | 194 |
199 // Initialize channel layout to all -1 to indicate that none of | 195 // Initialize channel layout to all -1 to indicate that none of |
200 // the channels is set in the layout. | 196 // the channels is set in the layout. |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 return frames_filled; | 387 return frames_filled; |
392 } | 388 } |
393 | 389 |
394 void CrasUnifiedStream::NotifyStreamError(int err) { | 390 void CrasUnifiedStream::NotifyStreamError(int err) { |
395 // This will remove the stream from the client. | 391 // This will remove the stream from the client. |
396 if (source_callback_) | 392 if (source_callback_) |
397 source_callback_->OnError(this); | 393 source_callback_->OnError(this); |
398 } | 394 } |
399 | 395 |
400 } // namespace media | 396 } // namespace media |
OLD | NEW |