| 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 uint32 bytes_per_frame = cras_client_bytes_per_frame(client_, stream_id_); | 260 uint32 bytes_per_frame = cras_client_bytes_per_frame(client_, stream_id_); |
| 261 timespec latency_ts = {0, 0}; | 261 timespec latency_ts = {0, 0}; |
| 262 | 262 |
| 263 // Determine latency and pass that on to the source. | 263 // Determine latency and pass that on to the source. |
| 264 cras_client_calc_latency(client_, stream_id_, sample_ts, &latency_ts); | 264 cras_client_calc_latency(client_, stream_id_, sample_ts, &latency_ts); |
| 265 uint32 latency_usec = (latency_ts.tv_sec * 1000000) + | 265 uint32 latency_usec = (latency_ts.tv_sec * 1000000) + |
| 266 latency_ts.tv_nsec / 1000; | 266 latency_ts.tv_nsec / 1000; |
| 267 | 267 |
| 268 uint32 frames_latency = latency_usec * frame_rate_ / 1000000; | 268 uint32 frames_latency = latency_usec * frame_rate_ / 1000000; |
| 269 uint32 bytes_latency = frames_latency * bytes_per_frame; | 269 uint32 bytes_latency = frames_latency * bytes_per_frame; |
| 270 uint32 rendered = source_callback_->OnMoreData(this, buffer, | 270 uint32 rendered = source_callback_->OnMoreData(buffer, |
| 271 frames * bytes_per_frame, | 271 frames * bytes_per_frame, |
| 272 AudioBuffersState(0, bytes_latency)); | 272 AudioBuffersState(0, bytes_latency)); |
| 273 return rendered / bytes_per_frame; | 273 return rendered / bytes_per_frame; |
| 274 } | 274 } |
| 275 | 275 |
| 276 void CrasOutputStream::NotifyStreamError(int err) { | 276 void CrasOutputStream::NotifyStreamError(int err) { |
| 277 // This will remove the stream from the client. | 277 // This will remove the stream from the client. |
| 278 if (state_ == kIsClosed || state_ == kInError) | 278 if (state_ == kIsClosed || state_ == kInError) |
| 279 return; // Don't care about error if we aren't using it. | 279 return; // Don't care about error if we aren't using it. |
| 280 TransitionTo(kInError); | 280 TransitionTo(kInError); |
| 281 if (source_callback_) | 281 if (source_callback_) |
| 282 source_callback_->OnError(this, err); | 282 source_callback_->OnError(this, err); |
| 283 } | 283 } |
| 284 | 284 |
| 285 bool CrasOutputStream::CanTransitionTo(InternalState to) { | 285 bool CrasOutputStream::CanTransitionTo(InternalState to) { |
| 286 switch (state_) { | 286 switch (state_) { |
| 287 case kCreated: | 287 case kCreated: |
| 288 return to == kIsOpened || to == kIsClosed || to == kInError; | 288 return to == kIsOpened || to == kIsClosed || to == kInError; |
| 289 | 289 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 316 state_ = to; | 316 state_ = to; |
| 317 } | 317 } |
| 318 return state_; | 318 return state_; |
| 319 } | 319 } |
| 320 | 320 |
| 321 CrasOutputStream::InternalState CrasOutputStream::state() { | 321 CrasOutputStream::InternalState CrasOutputStream::state() { |
| 322 return state_; | 322 return state_; |
| 323 } | 323 } |
| 324 | 324 |
| 325 } // namespace media | 325 } // namespace media |
| OLD | NEW |