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. 4 5 #ifndef MEDIA_BASE_RENDERER_H_ 6 #define MEDIA_BASE_RENDERER_H_ 7 8 #include "base/callback.h" 9 #include "base/macros.h" 10 #include "base/memory/ref_counted.h" 11 #include "base/optional.h" 12 #include "base/time/time.h" 13 #include "media/base/buffering_state.h" 14 #include "media/base/cdm_context.h" 15 #include "media/base/demuxer_stream.h" 16 #include "media/base/media_export.h" 17 #include "media/base/pipeline_status.h" 18 19 namespace media { 20 21 class MediaResource; 22 class RendererClient; 23 24 class MEDIA_EXPORT Renderer { 25 public: 26 Renderer(); 27 28 // Stops rendering and fires any pending callbacks. 29 virtual ~Renderer(); 30 31 // Initializes the Renderer with |media_resource|, executing |init_cb| upon 32 // completion. |media_resource| must be valid for the lifetime of the Renderer 33 // object. |init_cb| must only be run after this method has returned. Firing 34 // |init_cb| may result in the immediate destruction of the caller, so it must 35 // be run only prior to returning. 36 virtual void Initialize(MediaResource* media_resource, 37 RendererClient* client, 38 PipelineStatusCallback init_cb) = 0; 39 40 // Associates the |cdm_context| with this Renderer for decryption (and 41 // decoding) of media data, then fires |cdm_attached_cb| with the result. 42 virtual void SetCdm(CdmContext* cdm_context, 43 CdmAttachedCB cdm_attached_cb) = 0; 44 45 // Specifies a latency hint from the site. Renderers should clamp the hint 46 // value to reasonable min and max and use the resulting value as a target 47 // latency such that the buffering state reaches HAVE_ENOUGH when this amount 48 // of decoded data is buffered. A nullopt hint indicates the user is clearing 49 // their preference and the renderer should restore its default buffering 50 // thresholds. 51 virtual void SetLatencyHint(base::Optional<base::TimeDelta> latency_hint) = 0; 52 53 // The following functions must be called after Initialize(). 54 55 // Discards any buffered data, executing |flush_cb| when completed. 56 virtual void Flush(base::OnceClosure flush_cb) = 0; 57 58 // Starts rendering from |time|. 59 virtual void StartPlayingFrom(base::TimeDelta time) = 0; 60 61 // Updates the current playback rate. The default playback rate should be 0. 62 virtual void SetPlaybackRate(double playback_rate) = 0; 63 64 // Sets the output volume. The default volume should be 1. 65 virtual void SetVolume(float volume) = 0; 66 67 // Returns the current media time. 68 // 69 // This method must be safe to call from any thread. 70 virtual base::TimeDelta GetMediaTime() = 0; 71 72 // Provides a list of DemuxerStreams correlating to the tracks which should 73 // be played. An empty list would mean that any playing track of the same 74 // type should be flushed and disabled. Any provided Streams should be played 75 // by whatever mechanism the subclass of Renderer choses for managing it's AV 76 // playback. 77 virtual void OnSelectedVideoTracksChanged( 78 const std::vector<DemuxerStream*>& enabled_tracks, 79 base::OnceClosure change_completed_cb); 80 virtual void OnEnabledAudioTracksChanged( 81 const std::vector<DemuxerStream*>& enabled_tracks, 82 base::OnceClosure change_completed_cb); 83 84 private: 85 DISALLOW_COPY_AND_ASSIGN(Renderer); 86 }; 87 88 } // namespace media 89 90 #endif // MEDIA_BASE_RENDERER_H_ 91