audio_renderer.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 8#include <list> 9 10#include "base/callback.h" 11#include "base/memory/ref_counted.h" 12#include "base/time.h" 13#include "media/base/media_export.h" 14#include "media/base/pipeline_status.h" 15 16namespace media { 17 18class AudioDecoder; 19class DemuxerStream; 20 21class MEDIA_EXPORT AudioRenderer 22 : public base::RefCountedThreadSafe<AudioRenderer> { 23 public: 24 typedef std::list<scoped_refptr<AudioDecoder> > AudioDecoderList; 25 26 // First parameter is the current time that has been rendered. 27 // Second parameter is the maximum time value that the clock cannot exceed. 28 typedef base::Callback<void(base::TimeDelta, base::TimeDelta)> TimeCB; 29 30 // Initialize a AudioRenderer with the given AudioDecoder, executing the 31 // |init_cb| upon completion. 32 // 33 // |statistics_cb| is executed periodically with audio rendering stats. 34 // 35 // |underflow_cb| is executed when the renderer runs out of data to pass to 36 // the audio card during playback. ResumeAfterUnderflow() must be called 37 // to resume playback. Pause(), Preroll(), or Stop() cancels the underflow 38 // condition. 39 // 40 // |time_cb| is executed whenever time has advanced by way of audio rendering. 41 // 42 // |ended_cb| is executed when audio rendering has reached the end of stream. 43 // 44 // |disabled_cb| is executed when audio rendering has been disabled due to 45 // external factors (i.e., device was removed). |time_cb| will no longer be 46 // executed. 47 // 48 // |error_cb| is executed if an error was encountered. 49 virtual void Initialize(const scoped_refptr<DemuxerStream>& stream, 50 const AudioDecoderList& decoders, 51 const PipelineStatusCB& init_cb, 52 const StatisticsCB& statistics_cb, 53 const base::Closure& underflow_cb, 54 const TimeCB& time_cb, 55 const base::Closure& ended_cb, 56 const base::Closure& disabled_cb, 57 const PipelineStatusCB& error_cb) = 0; 58 59 // Start audio decoding and rendering at the current playback rate, executing 60 // |callback| when playback is underway. 61 virtual void Play(const base::Closure& callback) = 0; 62 63 // Temporarily suspend decoding and rendering audio, executing |callback| when 64 // playback has been suspended. 65 virtual void Pause(const base::Closure& callback) = 0; 66 67 // Discard any audio data, executing |callback| when completed. 68 virtual void Flush(const base::Closure& callback) = 0; 69 70 // Start prerolling audio data for samples starting at |time|, executing 71 // |callback| when completed. 72 // 73 // Only valid to call after a successful Initialize() or Flush(). 74 virtual void Preroll(base::TimeDelta time, 75 const PipelineStatusCB& callback) = 0; 76 77 // Stop all operations in preparation for being deleted, executing |callback| 78 // when complete. 79 virtual void Stop(const base::Closure& callback) = 0; 80 81 // Updates the current playback rate. 82 virtual void SetPlaybackRate(float playback_rate) = 0; 83 84 // Sets the output volume. 85 virtual void SetVolume(float volume) = 0; 86 87 // Resumes playback after underflow occurs. 88 // 89 // |buffer_more_audio| is set to true if you want to increase the size of the 90 // decoded audio buffer. 91 virtual void ResumeAfterUnderflow(bool buffer_more_audio) = 0; 92 93 protected: 94 friend class base::RefCountedThreadSafe<AudioRenderer>; 95 96 AudioRenderer(); 97 virtual ~AudioRenderer(); 98 99 private: 100 DISALLOW_COPY_AND_ASSIGN(AudioRenderer); 101}; 102 103} // namespace media 104 105#endif // MEDIA_BASE_AUDIO_RENDERER_H_ 106