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_
8 #include "base/callback.h"
9 #include "base/time/time.h"
10 #include "media/base/buffering_state.h"
11 #include "media/base/decryptor.h"
12 #include "media/base/media_export.h"
13 #include "media/base/pipeline_status.h"
20 class MEDIA_EXPORT AudioRenderer
{
24 // Stop all operations and fire all pending callbacks.
25 virtual ~AudioRenderer();
27 // Initialize an AudioRenderer with |stream|, executing |init_cb| upon
28 // completion. If initialization fails, only |init_cb| (not |error_cb|) will
31 // |set_decryptor_ready_cb| is fired when a Decryptor is needed, i.e. when the
32 // |stream| is encrypted.
34 // |statistics_cb| is executed periodically with audio rendering stats.
36 // |buffering_state_cb| is executed when audio rendering has either run out of
37 // data or has enough data to continue playback.
39 // |ended_cb| is executed when audio rendering has reached the end of stream.
41 // |error_cb| is executed if an error was encountered after initialization.
43 // |waiting_for_decryption_key_cb| is called whenever the key needed to
44 // decrypt the stream is not available.
45 virtual void Initialize(
46 DemuxerStream
* stream
,
47 const PipelineStatusCB
& init_cb
,
48 const SetDecryptorReadyCB
& set_decryptor_ready_cb
,
49 const StatisticsCB
& statistics_cb
,
50 const BufferingStateCB
& buffering_state_cb
,
51 const base::Closure
& ended_cb
,
52 const PipelineStatusCB
& error_cb
,
53 const base::Closure
& waiting_for_decryption_key_cb
) = 0;
55 // Returns the TimeSource associated with audio rendering.
56 virtual TimeSource
* GetTimeSource() = 0;
58 // Discard any audio data, executing |callback| when completed.
60 // Clients should expect |buffering_state_cb| to be called with
61 // BUFFERING_HAVE_NOTHING while flushing is in progress.
62 virtual void Flush(const base::Closure
& callback
) = 0;
64 // Starts playback by reading from |stream| and decoding and rendering audio.
66 // Only valid to call after a successful Initialize() or Flush().
67 virtual void StartPlaying() = 0;
69 // Sets the output volume.
70 virtual void SetVolume(float volume
) = 0;
73 DISALLOW_COPY_AND_ASSIGN(AudioRenderer
);
78 #endif // MEDIA_BASE_AUDIO_RENDERER_H_