Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef MEDIA_BASE_AUDIO_RENDERER_H_ |
| 6 | #define MEDIA_BASE_AUDIO_RENDERER_H_ |
| 7 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 8 | #include "base/callback.h" |
| 9 | #include "base/memory/ref_counted.h" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 10 | #include "base/time/time.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 11 | #include "media/base/media_export.h" |
| 12 | #include "media/base/pipeline_status.h" |
| 13 | |
| 14 | namespace media { |
| 15 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 16 | class DemuxerStream; |
| 17 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 18 | class MEDIA_EXPORT AudioRenderer { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 19 | public: |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 20 | // First parameter is the current time that has been rendered. |
| 21 | // Second parameter is the maximum time value that the clock cannot exceed. |
| 22 | typedef base::Callback<void(base::TimeDelta, base::TimeDelta)> TimeCB; |
| 23 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 24 | AudioRenderer(); |
| 25 | virtual ~AudioRenderer(); |
| 26 | |
| 27 | // Initialize an AudioRenderer with |stream|, executing |init_cb| upon |
| 28 | // completion. |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 29 | // |
| 30 | // |statistics_cb| is executed periodically with audio rendering stats. |
| 31 | // |
| 32 | // |underflow_cb| is executed when the renderer runs out of data to pass to |
| 33 | // the audio card during playback. ResumeAfterUnderflow() must be called |
| 34 | // to resume playback. Pause(), Preroll(), or Stop() cancels the underflow |
| 35 | // condition. |
| 36 | // |
| 37 | // |time_cb| is executed whenever time has advanced by way of audio rendering. |
| 38 | // |
| 39 | // |ended_cb| is executed when audio rendering has reached the end of stream. |
| 40 | // |
| 41 | // |disabled_cb| is executed when audio rendering has been disabled due to |
| 42 | // external factors (i.e., device was removed). |time_cb| will no longer be |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 43 | // executed. TODO(scherkus): this might not be needed http://crbug.com/234708 |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 44 | // |
| 45 | // |error_cb| is executed if an error was encountered. |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 46 | virtual void Initialize(DemuxerStream* stream, |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 47 | const PipelineStatusCB& init_cb, |
| 48 | const StatisticsCB& statistics_cb, |
| 49 | const base::Closure& underflow_cb, |
| 50 | const TimeCB& time_cb, |
| 51 | const base::Closure& ended_cb, |
| 52 | const base::Closure& disabled_cb, |
| 53 | const PipelineStatusCB& error_cb) = 0; |
| 54 | |
| 55 | // Start audio decoding and rendering at the current playback rate, executing |
| 56 | // |callback| when playback is underway. |
| 57 | virtual void Play(const base::Closure& callback) = 0; |
| 58 | |
| 59 | // Temporarily suspend decoding and rendering audio, executing |callback| when |
| 60 | // playback has been suspended. |
| 61 | virtual void Pause(const base::Closure& callback) = 0; |
| 62 | |
| 63 | // Discard any audio data, executing |callback| when completed. |
| 64 | virtual void Flush(const base::Closure& callback) = 0; |
| 65 | |
| 66 | // Start prerolling audio data for samples starting at |time|, executing |
| 67 | // |callback| when completed. |
| 68 | // |
| 69 | // Only valid to call after a successful Initialize() or Flush(). |
| 70 | virtual void Preroll(base::TimeDelta time, |
| 71 | const PipelineStatusCB& callback) = 0; |
| 72 | |
| 73 | // Stop all operations in preparation for being deleted, executing |callback| |
| 74 | // when complete. |
| 75 | virtual void Stop(const base::Closure& callback) = 0; |
| 76 | |
| 77 | // Updates the current playback rate. |
| 78 | virtual void SetPlaybackRate(float playback_rate) = 0; |
| 79 | |
| 80 | // Sets the output volume. |
| 81 | virtual void SetVolume(float volume) = 0; |
| 82 | |
| 83 | // Resumes playback after underflow occurs. |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 84 | virtual void ResumeAfterUnderflow() = 0; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 85 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 86 | private: |
| 87 | DISALLOW_COPY_AND_ASSIGN(AudioRenderer); |
| 88 | }; |
| 89 | |
| 90 | } // namespace media |
| 91 | |
| 92 | #endif // MEDIA_BASE_AUDIO_RENDERER_H_ |