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/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/time/time.h"
12 #include "media/base/buffering_state.h"
13 #include "media/base/cdm_context.h"
14 #include "media/base/demuxer_stream.h"
15 #include "media/base/media_export.h"
16 #include "media/base/pipeline_status.h"
23 class MEDIA_EXPORT Renderer {
27 // Stops rendering and fires any pending callbacks.
30 // Initializes the Renderer with |media_resource|, executing |init_cb| upon
31 // completion. |media_resource| must be valid for the lifetime of the Renderer
32 // object. |init_cb| must only be run after this method has returned. Firing
33 // |init_cb| may result in the immediate destruction of the caller, so it must
34 // be run only prior to returning.
35 virtual void Initialize(MediaResource* media_resource,
36 RendererClient* client,
37 const PipelineStatusCB& init_cb) = 0;
39 // Associates the |cdm_context| with this Renderer for decryption (and
40 // decoding) of media data, then fires |cdm_attached_cb| with the result.
41 virtual void SetCdm(CdmContext* cdm_context,
42 const CdmAttachedCB& cdm_attached_cb) = 0;
44 // The following functions must be called after Initialize().
46 // Discards any buffered data, executing |flush_cb| when completed.
47 virtual void Flush(const base::Closure& flush_cb) = 0;
49 // Starts rendering from |time|.
50 virtual void StartPlayingFrom(base::TimeDelta time) = 0;
52 // Updates the current playback rate. The default playback rate should be 0.
53 virtual void SetPlaybackRate(double playback_rate) = 0;
55 // Sets the output volume. The default volume should be 1.
56 virtual void SetVolume(float volume) = 0;
58 // Returns the current media time.
60 // This method must be safe to call from any thread.
61 virtual base::TimeDelta GetMediaTime() = 0;
63 // Provides a list of DemuxerStreams correlating to the tracks which should
64 // be played. An empty list would mean that any playing track of the same
65 // type should be flushed and disabled. Any provided Streams should be played
66 // by whatever mechanism the subclass of Renderer choses for managing it's AV
68 virtual void OnSelectedVideoTracksChanged(
69 const std::vector<DemuxerStream*>& enabled_tracks,
70 base::OnceClosure change_completed_cb);
71 virtual void OnEnabledAudioTracksChanged(
72 const std::vector<DemuxerStream*>& enabled_tracks,
73 base::OnceClosure change_completed_cb);
76 DISALLOW_COPY_AND_ASSIGN(Renderer);
81 #endif // MEDIA_BASE_RENDERER_H_