Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / media / base / audio_renderer.h
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 "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/time/time.h"
11 #include "media/base/media_export.h"
12 #include "media/base/pipeline_status.h"
13
14 namespace media {
15
16 class DemuxerStream;
17
18 class MEDIA_EXPORT AudioRenderer {
19  public:
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
24   AudioRenderer();
25   virtual ~AudioRenderer();
26
27   // Initialize an AudioRenderer with |stream|, executing |init_cb| upon
28   // completion.
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   // |error_cb| is executed if an error was encountered.
42   virtual void Initialize(DemuxerStream* stream,
43                           const PipelineStatusCB& init_cb,
44                           const StatisticsCB& statistics_cb,
45                           const base::Closure& underflow_cb,
46                           const TimeCB& time_cb,
47                           const base::Closure& ended_cb,
48                           const PipelineStatusCB& error_cb) = 0;
49
50   // Signal audio playback to start at the current rate. It is expected that
51   // |time_cb| will eventually start being run with time updates.
52   virtual void StartRendering() = 0;
53
54   // Signal audio playback to stop until further notice. It is expected that
55   // |time_cb| will no longer be run.
56   virtual void StopRendering() = 0;
57
58   // Discard any audio data, executing |callback| when completed.
59   virtual void Flush(const base::Closure& callback) = 0;
60
61   // Start prerolling audio data for samples starting at |time|, executing
62   // |callback| when completed.
63   //
64   // Only valid to call after a successful Initialize() or Flush().
65   virtual void Preroll(base::TimeDelta time,
66                        const PipelineStatusCB& callback) = 0;
67
68   // Stop all operations in preparation for being deleted, executing |callback|
69   // when complete.
70   virtual void Stop(const base::Closure& callback) = 0;
71
72   // Updates the current playback rate.
73   virtual void SetPlaybackRate(float playback_rate) = 0;
74
75   // Sets the output volume.
76   virtual void SetVolume(float volume) = 0;
77
78   // Resumes playback after underflow occurs.
79   virtual void ResumeAfterUnderflow() = 0;
80
81  private:
82   DISALLOW_COPY_AND_ASSIGN(AudioRenderer);
83 };
84
85 }  // namespace media
86
87 #endif  // MEDIA_BASE_AUDIO_RENDERER_H_