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

Side by Side Diff: media/audio/linux/cras_output.cc

Issue 10832285: Switch OnMoreData() to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Comments. Created 8 years, 3 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/linux/cras_output.h ('k') | media/audio/linux/cras_output_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 // 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
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
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 // Note: If this ever changes to output raw float the data must be clipped and
286 // sanitized since it may come from an untrusted source such as NaCl.
287 audio_bus_->ToInterleaved(
288 frames_filled, bytes_per_frame_ / (frames * num_channels_), buffer);
289 return frames_filled;
284 } 290 }
285 291
286 void CrasOutputStream::NotifyStreamError(int err) { 292 void CrasOutputStream::NotifyStreamError(int err) {
287 // This will remove the stream from the client. 293 // This will remove the stream from the client.
288 if (state_ == kIsClosed || state_ == kInError) 294 if (state_ == kIsClosed || state_ == kInError)
289 return; // Don't care about error if we aren't using it. 295 return; // Don't care about error if we aren't using it.
290 TransitionTo(kInError); 296 TransitionTo(kInError);
291 if (source_callback_) 297 if (source_callback_)
292 source_callback_->OnError(this, err); 298 source_callback_->OnError(this, err);
293 } 299 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 state_ = to; 332 state_ = to;
327 } 333 }
328 return state_; 334 return state_;
329 } 335 }
330 336
331 CrasOutputStream::InternalState CrasOutputStream::state() { 337 CrasOutputStream::InternalState CrasOutputStream::state() {
332 return state_; 338 return state_;
333 } 339 }
334 340
335 } // namespace media 341 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/linux/cras_output.h ('k') | media/audio/linux/cras_output_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698