Roll leveldb 3f7758:803d69 (v1.17 -> v1.18)
[chromium-blink-merge.git] / media / base / renderer.h
blobd6cb74ab76d363e0d282e9586783d720a41d3fa5
1 // Copyright 2014 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_RENDERER_H_
6 #define MEDIA_BASE_RENDERER_H_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/time/time.h"
11 #include "media/base/buffering_state.h"
12 #include "media/base/media_export.h"
13 #include "media/base/pipeline_status.h"
15 namespace media {
17 class DemuxerStreamProvider;
18 class MediaKeys;
19 class VideoFrame;
21 class MEDIA_EXPORT Renderer {
22 public:
23 typedef base::Callback<void(const scoped_refptr<VideoFrame>&)> PaintCB;
24 typedef base::Callback<base::TimeDelta()> TimeDeltaCB;
26 Renderer();
28 // Stops rendering and fires any pending callbacks.
29 virtual ~Renderer();
31 // Initializes the Renderer with |demuxer_stream_provider|, executing
32 // |init_cb| upon completion. If initialization failed, fires |error_cb|
33 // before |init_cb|. |demuxer_stream_provider| must be valid throughout the
34 // lifetime of the Renderer object.
36 // Permanent callbacks:
37 // - |statistics_cb|: Executed periodically with rendering statistics.
38 // - |buffering_state_cb|: Executed when buffering state is changed.
39 // - |paint_cb|: Executed when there is a VideoFrame ready to paint. Can be
40 // ignored if the Renderer handles the painting by itself. Can
41 // be called from any thread.
42 // - |ended_cb|: Executed when rendering has reached the end of stream.
43 // - |error_cb|: Executed if any error was encountered during rendering.
44 virtual void Initialize(DemuxerStreamProvider* demuxer_stream_provider,
45 const base::Closure& init_cb,
46 const StatisticsCB& statistics_cb,
47 const BufferingStateCB& buffering_state_cb,
48 const PaintCB& paint_cb,
49 const base::Closure& ended_cb,
50 const PipelineStatusCB& error_cb) = 0;
52 // The following functions must be called after Initialize().
54 // Discards any buffered data, executing |flush_cb| when completed.
55 virtual void Flush(const base::Closure& flush_cb) = 0;
57 // Starts rendering from |time|.
58 virtual void StartPlayingFrom(base::TimeDelta time) = 0;
60 // Updates the current playback rate. The default playback rate should be 1.
61 virtual void SetPlaybackRate(float playback_rate) = 0;
63 // Sets the output volume. The default volume should be 1.
64 virtual void SetVolume(float volume) = 0;
66 // Returns the current media time.
67 virtual base::TimeDelta GetMediaTime() = 0;
69 // Returns whether |this| renders audio.
70 virtual bool HasAudio() = 0;
72 // Returns whether |this| renders video.
73 virtual bool HasVideo() = 0;
75 // Associates the |cdm| with this Renderer.
76 virtual void SetCdm(MediaKeys* cdm) = 0;
78 private:
79 DISALLOW_COPY_AND_ASSIGN(Renderer);
82 } // namespace media
84 #endif // MEDIA_BASE_RENDERER_H_