OLD | NEW |
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 // The object has one error state: |state_| == kInError. When |state_| == | 5 // The object has one error state: |state_| == kInError. When |state_| == |
6 // kInError, all public API functions will fail with an error (Start() will call | 6 // kInError, all public API functions will fail with an error (Start() will call |
7 // the OnError() function on the callback immediately), or no-op themselves with | 7 // the OnError() function on the callback immediately), or no-op themselves with |
8 // the exception of Close(). Even if an error state has been entered, if Open() | 8 // the exception of Close(). Even if an error state has been entered, if Open() |
9 // has previously returned successfully, Close() must be called. | 9 // has previously returned successfully, Close() must be called. |
10 | 10 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 : client_(NULL), | 65 : client_(NULL), |
66 stream_id_(0), | 66 stream_id_(0), |
67 samples_per_packet_(params.frames_per_buffer()), | 67 samples_per_packet_(params.frames_per_buffer()), |
68 bytes_per_frame_(0), | 68 bytes_per_frame_(0), |
69 frame_rate_(params.sample_rate()), | 69 frame_rate_(params.sample_rate()), |
70 num_channels_(params.channels()), | 70 num_channels_(params.channels()), |
71 pcm_format_(alsa_util::BitsToFormat(params.bits_per_sample())), | 71 pcm_format_(alsa_util::BitsToFormat(params.bits_per_sample())), |
72 state_(kCreated), | 72 state_(kCreated), |
73 volume_(1.0), | 73 volume_(1.0), |
74 manager_(manager), | 74 manager_(manager), |
75 source_callback_(NULL) { | 75 source_callback_(NULL), |
| 76 audio_bus_(AudioBus::Create(params)) { |
76 // We must have a manager. | 77 // We must have a manager. |
77 DCHECK(manager_); | 78 DCHECK(manager_); |
78 | 79 |
79 // Sanity check input values. | 80 // Sanity check input values. |
80 if (params.sample_rate() <= 0) { | 81 if (params.sample_rate() <= 0) { |
81 LOG(WARNING) << "Unsupported audio frequency."; | 82 LOG(WARNING) << "Unsupported audio frequency."; |
82 TransitionTo(kInError); | 83 TransitionTo(kInError); |
83 return; | 84 return; |
84 } | 85 } |
85 | 86 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 const timespec* sample_ts) { | 272 const timespec* sample_ts) { |
272 timespec latency_ts = {0, 0}; | 273 timespec latency_ts = {0, 0}; |
273 | 274 |
274 // Determine latency and pass that on to the source. | 275 // Determine latency and pass that on to the source. |
275 cras_client_calc_playback_latency(sample_ts, &latency_ts); | 276 cras_client_calc_playback_latency(sample_ts, &latency_ts); |
276 uint32 latency_usec = (latency_ts.tv_sec * 1000000) + | 277 uint32 latency_usec = (latency_ts.tv_sec * 1000000) + |
277 latency_ts.tv_nsec / 1000; | 278 latency_ts.tv_nsec / 1000; |
278 | 279 |
279 uint32 frames_latency = latency_usec * frame_rate_ / 1000000; | 280 uint32 frames_latency = latency_usec * frame_rate_ / 1000000; |
280 uint32 bytes_latency = frames_latency * bytes_per_frame_; | 281 uint32 bytes_latency = frames_latency * bytes_per_frame_; |
281 uint32 rendered = source_callback_->OnMoreData( | 282 DCHECK_EQ(frames, static_cast<size_t>(audio_bus_->frames())); |
282 buffer, frames * bytes_per_frame_, AudioBuffersState(0, bytes_latency)); | 283 int frames_filled = source_callback_->OnMoreData( |
283 return rendered / bytes_per_frame_; | 284 audio_bus_.get(), AudioBuffersState(0, bytes_latency)); |
| 285 audio_bus_->ToInterleaved( |
| 286 frames_filled, bytes_per_frame_ / (frames * num_channels_), buffer); |
| 287 return frames_filled; |
284 } | 288 } |
285 | 289 |
286 void CrasOutputStream::NotifyStreamError(int err) { | 290 void CrasOutputStream::NotifyStreamError(int err) { |
287 // This will remove the stream from the client. | 291 // This will remove the stream from the client. |
288 if (state_ == kIsClosed || state_ == kInError) | 292 if (state_ == kIsClosed || state_ == kInError) |
289 return; // Don't care about error if we aren't using it. | 293 return; // Don't care about error if we aren't using it. |
290 TransitionTo(kInError); | 294 TransitionTo(kInError); |
291 if (source_callback_) | 295 if (source_callback_) |
292 source_callback_->OnError(this, err); | 296 source_callback_->OnError(this, err); |
293 } | 297 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 state_ = to; | 330 state_ = to; |
327 } | 331 } |
328 return state_; | 332 return state_; |
329 } | 333 } |
330 | 334 |
331 CrasOutputStream::InternalState CrasOutputStream::state() { | 335 CrasOutputStream::InternalState CrasOutputStream::state() { |
332 return state_; | 336 return state_; |
333 } | 337 } |
334 | 338 |
335 } // namespace media | 339 } // namespace media |
OLD | NEW |