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/cdm_context.h"
13 #include "media/base/media_export.h"
14 #include "media/base/pipeline_status.h"
18 class DemuxerStreamProvider
;
21 class MEDIA_EXPORT Renderer
{
23 typedef base::Callback
<void(const scoped_refptr
<VideoFrame
>&)> PaintCB
;
24 typedef base::Callback
<base::TimeDelta()> TimeDeltaCB
;
28 // Stops rendering and fires any pending callbacks.
31 // Initializes the Renderer with |demuxer_stream_provider|, executing
32 // |init_cb| upon completion. If initialization fails, only |init_cb| (not
33 // |error_cb|) should be called. |demuxer_stream_provider| must be valid for
34 // the lifetime of the Renderer object. |init_cb| must only be run after this
35 // method has returned. Firing |init_cb| may result in the immediate
36 // destruction of the caller, so it must be run only prior to returning.
38 // Permanent callbacks:
39 // - |statistics_cb|: Executed periodically with rendering statistics.
40 // - |buffering_state_cb|: Executed when buffering state is changed.
41 // - |paint_cb|: Executed when there is a VideoFrame ready to paint. Can be
42 // ignored if the Renderer handles the painting by itself. Can
43 // be called from any thread.
44 // - |ended_cb|: Executed when rendering has reached the end of stream.
45 // - |error_cb|: Executed if any error was encountered after initialization.
46 virtual void Initialize(DemuxerStreamProvider
* demuxer_stream_provider
,
47 const PipelineStatusCB
& init_cb
,
48 const StatisticsCB
& statistics_cb
,
49 const BufferingStateCB
& buffering_state_cb
,
50 const PaintCB
& paint_cb
,
51 const base::Closure
& ended_cb
,
52 const PipelineStatusCB
& error_cb
) = 0;
54 // Associates the |cdm_context| with this Renderer for decryption (and
55 // decoding) of media data, then fires |cdm_attached_cb| with the result.
56 virtual void SetCdm(CdmContext
* cdm_context
,
57 const CdmAttachedCB
& cdm_attached_cb
) = 0;
59 // The following functions must be called after Initialize().
61 // Discards any buffered data, executing |flush_cb| when completed.
62 virtual void Flush(const base::Closure
& flush_cb
) = 0;
64 // Starts rendering from |time|.
65 virtual void StartPlayingFrom(base::TimeDelta time
) = 0;
67 // Updates the current playback rate. The default playback rate should be 1.
68 virtual void SetPlaybackRate(float playback_rate
) = 0;
70 // Sets the output volume. The default volume should be 1.
71 virtual void SetVolume(float volume
) = 0;
73 // Returns the current media time.
74 virtual base::TimeDelta
GetMediaTime() = 0;
76 // Returns whether |this| renders audio.
77 virtual bool HasAudio() = 0;
79 // Returns whether |this| renders video.
80 virtual bool HasVideo() = 0;
83 DISALLOW_COPY_AND_ASSIGN(Renderer
);
88 #endif // MEDIA_BASE_RENDERER_H_