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.
5 #ifndef MEDIA_BASE_AUDIO_RENDERER_H_
6 #define MEDIA_BASE_AUDIO_RENDERER_H_
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"
21 class MEDIA_EXPORT AudioRenderer
22 : public base::RefCountedThreadSafe
<AudioRenderer
> {
24 typedef std::list
<scoped_refptr
<AudioDecoder
> > AudioDecoderList
;
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
;
30 // Initialize a AudioRenderer with the given AudioDecoder, executing the
31 // |init_cb| upon completion.
33 // |statistics_cb| is executed periodically with audio rendering stats.
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
40 // |time_cb| is executed whenever time has advanced by way of audio rendering.
42 // |ended_cb| is executed when audio rendering has reached the end of stream.
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
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;
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;
63 // Temporarily suspend decoding and rendering audio, executing |callback| when
64 // playback has been suspended.
65 virtual void Pause(const base::Closure
& callback
) = 0;
67 // Discard any audio data, executing |callback| when completed.
68 virtual void Flush(const base::Closure
& callback
) = 0;
70 // Start prerolling audio data for samples starting at |time|, executing
71 // |callback| when completed.
73 // Only valid to call after a successful Initialize() or Flush().
74 virtual void Preroll(base::TimeDelta time
,
75 const PipelineStatusCB
& callback
) = 0;
77 // Stop all operations in preparation for being deleted, executing |callback|
79 virtual void Stop(const base::Closure
& callback
) = 0;
81 // Updates the current playback rate.
82 virtual void SetPlaybackRate(float playback_rate
) = 0;
84 // Sets the output volume.
85 virtual void SetVolume(float volume
) = 0;
87 // Resumes playback after underflow occurs.
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;
94 friend class base::RefCountedThreadSafe
<AudioRenderer
>;
97 virtual ~AudioRenderer();
100 DISALLOW_COPY_AND_ASSIGN(AudioRenderer
);
105 #endif // MEDIA_BASE_AUDIO_RENDERER_H_