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

Side by Side Diff: media/audio/audio_output_resampler.cc

Issue 290003002: Remove OnMoreIOData() (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fixed the media unittests on mac. Created 6 years, 7 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
« no previous file with comments | « media/audio/audio_output_proxy_unittest.cc ('k') | media/audio/cras/cras_unified.h » ('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 #include "media/audio/audio_output_resampler.h" 5 #include "media/audio/audio_output_resampler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 13 matching lines...) Expand all
24 : public AudioOutputStream::AudioSourceCallback, 24 : public AudioOutputStream::AudioSourceCallback,
25 public AudioConverter::InputCallback { 25 public AudioConverter::InputCallback {
26 public: 26 public:
27 OnMoreDataConverter(const AudioParameters& input_params, 27 OnMoreDataConverter(const AudioParameters& input_params,
28 const AudioParameters& output_params); 28 const AudioParameters& output_params);
29 virtual ~OnMoreDataConverter(); 29 virtual ~OnMoreDataConverter();
30 30
31 // AudioSourceCallback interface. 31 // AudioSourceCallback interface.
32 virtual int OnMoreData(AudioBus* dest, 32 virtual int OnMoreData(AudioBus* dest,
33 AudioBuffersState buffers_state) OVERRIDE; 33 AudioBuffersState buffers_state) OVERRIDE;
34 virtual int OnMoreIOData(AudioBus* source,
35 AudioBus* dest,
36 AudioBuffersState buffers_state) OVERRIDE;
37 virtual void OnError(AudioOutputStream* stream) OVERRIDE; 34 virtual void OnError(AudioOutputStream* stream) OVERRIDE;
38 35
39 // Sets |source_callback_|. If this is not a new object, then Stop() must be 36 // Sets |source_callback_|. If this is not a new object, then Stop() must be
40 // called before Start(). 37 // called before Start().
41 void Start(AudioOutputStream::AudioSourceCallback* callback); 38 void Start(AudioOutputStream::AudioSourceCallback* callback);
42 39
43 // Clears |source_callback_| and flushes the resampler. 40 // Clears |source_callback_| and flushes the resampler.
44 void Stop(); 41 void Stop();
45 42
46 bool started() { return source_callback_ != NULL; } 43 bool started() { return source_callback_ != NULL; }
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 321 }
325 322
326 void OnMoreDataConverter::Stop() { 323 void OnMoreDataConverter::Stop() {
327 CHECK(source_callback_); 324 CHECK(source_callback_);
328 source_callback_ = NULL; 325 source_callback_ = NULL;
329 audio_converter_.RemoveInput(this); 326 audio_converter_.RemoveInput(this);
330 } 327 }
331 328
332 int OnMoreDataConverter::OnMoreData(AudioBus* dest, 329 int OnMoreDataConverter::OnMoreData(AudioBus* dest,
333 AudioBuffersState buffers_state) { 330 AudioBuffersState buffers_state) {
334 return OnMoreIOData(NULL, dest, buffers_state);
335 }
336
337 int OnMoreDataConverter::OnMoreIOData(AudioBus* source,
338 AudioBus* dest,
339 AudioBuffersState buffers_state) {
340 // Note: The input portion of OnMoreIOData() is not supported when a converter
341 // has been injected. Downstream clients prefer silence to potentially split
342 // apart input data.
343
344 current_buffers_state_ = buffers_state; 331 current_buffers_state_ = buffers_state;
345 audio_converter_.Convert(dest); 332 audio_converter_.Convert(dest);
346 333
347 // Always return the full number of frames requested, ProvideInput() 334 // Always return the full number of frames requested, ProvideInput()
348 // will pad with silence if it wasn't able to acquire enough data. 335 // will pad with silence if it wasn't able to acquire enough data.
349 return dest->frames(); 336 return dest->frames();
350 } 337 }
351 338
352 double OnMoreDataConverter::ProvideInput(AudioBus* dest, 339 double OnMoreDataConverter::ProvideInput(AudioBus* dest,
353 base::TimeDelta buffer_delay) { 340 base::TimeDelta buffer_delay) {
354 // Adjust playback delay to include |buffer_delay|. 341 // Adjust playback delay to include |buffer_delay|.
355 // TODO(dalecurtis): Stop passing bytes around, it doesn't make sense since 342 // TODO(dalecurtis): Stop passing bytes around, it doesn't make sense since
356 // AudioBus is just float data. Use TimeDelta instead. 343 // AudioBus is just float data. Use TimeDelta instead.
357 AudioBuffersState new_buffers_state; 344 AudioBuffersState new_buffers_state;
358 new_buffers_state.pending_bytes = 345 new_buffers_state.pending_bytes =
359 io_ratio_ * (current_buffers_state_.total_bytes() + 346 io_ratio_ * (current_buffers_state_.total_bytes() +
360 buffer_delay.InSecondsF() * input_bytes_per_second_); 347 buffer_delay.InSecondsF() * input_bytes_per_second_);
361 348
362 // Retrieve data from the original callback. 349 // Retrieve data from the original callback.
363 const int frames = source_callback_->OnMoreIOData( 350 const int frames = source_callback_->OnMoreData(dest, new_buffers_state);
364 NULL, dest, new_buffers_state);
365 351
366 // Zero any unfilled frames if anything was filled, otherwise we'll just 352 // Zero any unfilled frames if anything was filled, otherwise we'll just
367 // return a volume of zero and let AudioConverter drop the output. 353 // return a volume of zero and let AudioConverter drop the output.
368 if (frames > 0 && frames < dest->frames()) 354 if (frames > 0 && frames < dest->frames())
369 dest->ZeroFramesPartial(frames, dest->frames() - frames); 355 dest->ZeroFramesPartial(frames, dest->frames() - frames);
370 return frames > 0 ? 1 : 0; 356 return frames > 0 ? 1 : 0;
371 } 357 }
372 358
373 void OnMoreDataConverter::OnError(AudioOutputStream* stream) { 359 void OnMoreDataConverter::OnError(AudioOutputStream* stream) {
374 source_callback_->OnError(stream); 360 source_callback_->OnError(stream);
375 } 361 }
376 362
377 } // namespace media 363 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_output_proxy_unittest.cc ('k') | media/audio/cras/cras_unified.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698