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

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

Issue 2101303004: Pass delay and timestamp to AudioSourceCallback::OnMoreData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 4 years, 5 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
OLDNEW
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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/time/time.h"
9 #include "media/audio/cras/audio_manager_cras.h" 10 #include "media/audio/cras/audio_manager_cras.h"
10 11
11 namespace media { 12 namespace media {
12 13
13 // Overview of operation: 14 // Overview of operation:
14 // 1) An object of CrasUnifiedStream is created by the AudioManager 15 // 1) An object of CrasUnifiedStream is created by the AudioManager
15 // factory: audio_man->MakeAudioStream(). 16 // factory: audio_man->MakeAudioStream().
16 // 2) Next some thread will call Open(), at that point a client is created and 17 // 2) Next some thread will call Open(), at that point a client is created and
17 // configured for the correct format and sample rate. 18 // configured for the correct format and sample rate.
18 // 3) Then Start(source) is called and a stream is added to the CRAS client 19 // 3) Then Start(source) is called and a stream is added to the CRAS client
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 : client_(NULL), 55 : client_(NULL),
55 stream_id_(0), 56 stream_id_(0),
56 params_(params), 57 params_(params),
57 bytes_per_frame_(0), 58 bytes_per_frame_(0),
58 is_playing_(false), 59 is_playing_(false),
59 volume_(1.0), 60 volume_(1.0),
60 manager_(manager), 61 manager_(manager),
61 source_callback_(NULL), 62 source_callback_(NULL),
62 stream_direction_(CRAS_STREAM_OUTPUT) { 63 stream_direction_(CRAS_STREAM_OUTPUT) {
63 DCHECK(manager_); 64 DCHECK(manager_);
64 DCHECK(params_.channels() > 0); 65 DCHECK_GT(params_.channels(), 0);
65 66
66 output_bus_ = AudioBus::Create(params); 67 output_bus_ = AudioBus::Create(params);
67 } 68 }
68 69
69 CrasUnifiedStream::~CrasUnifiedStream() { 70 CrasUnifiedStream::~CrasUnifiedStream() {
70 DCHECK(!is_playing_); 71 DCHECK(!is_playing_);
71 } 72 }
72 73
73 bool CrasUnifiedStream::Open() { 74 bool CrasUnifiedStream::Open() {
74 // Sanity check input values. 75 // Sanity check input values.
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 uint32_t CrasUnifiedStream::WriteAudio(size_t frames, 300 uint32_t CrasUnifiedStream::WriteAudio(size_t frames,
300 uint8_t* buffer, 301 uint8_t* buffer,
301 const timespec* sample_ts) { 302 const timespec* sample_ts) {
302 DCHECK_EQ(frames, static_cast<size_t>(output_bus_->frames())); 303 DCHECK_EQ(frames, static_cast<size_t>(output_bus_->frames()));
303 304
304 // Determine latency and pass that on to the source. 305 // Determine latency and pass that on to the source.
305 timespec latency_ts = {0, 0}; 306 timespec latency_ts = {0, 0};
306 cras_client_calc_playback_latency(sample_ts, &latency_ts); 307 cras_client_calc_playback_latency(sample_ts, &latency_ts);
307 308
308 int frames_filled = source_callback_->OnMoreData( 309 int frames_filled = source_callback_->OnMoreData(
309 output_bus_.get(), GetBytesLatency(latency_ts), 0); 310 output_bus_.get(), GetBytesLatency(latency_ts), base::TimeDelta(), 0);
310 311
311 // Note: If this ever changes to output raw float the data must be clipped and 312 // Note: If this ever changes to output raw float the data must be clipped and
312 // sanitized since it may come from an untrusted source such as NaCl. 313 // sanitized since it may come from an untrusted source such as NaCl.
313 output_bus_->ToInterleaved( 314 output_bus_->ToInterleaved(
314 frames_filled, bytes_per_frame_ / params_.channels(), buffer); 315 frames_filled, bytes_per_frame_ / params_.channels(), buffer);
315 316
316 return frames_filled; 317 return frames_filled;
317 } 318 }
318 319
319 void CrasUnifiedStream::NotifyStreamError(int err) { 320 void CrasUnifiedStream::NotifyStreamError(int err) {
320 // This will remove the stream from the client. 321 // This will remove the stream from the client.
321 if (source_callback_) 322 if (source_callback_)
322 source_callback_->OnError(this); 323 source_callback_->OnError(this);
323 } 324 }
324 325
325 } // namespace media 326 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698