1 // Copyright 2014 The Chromium Authors
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/demuxer_stream.h"
13 #include "media/base/media_export.h"
14 #include "media/base/pipeline_status.h"
15 #include "third_party/abseil-cpp/absl/types/optional.h"
17 #if defined(TIZEN_VIDEO_HOLE)
18 #include "ui/gfx/geometry/rect_f.h"
27 class MEDIA_EXPORT Renderer {
31 Renderer(const Renderer&) = delete;
32 Renderer& operator=(const Renderer&) = delete;
34 // Stops rendering and fires any pending callbacks.
37 // Initializes the Renderer with |media_resource|, executing |init_cb| upon
38 // completion. |media_resource| must be valid for the lifetime of the Renderer
39 // object. |init_cb| must only be run after this method has returned. Firing
40 // |init_cb| may result in the immediate destruction of the caller, so it must
41 // be run only prior to returning.
42 virtual void Initialize(MediaResource* media_resource,
43 RendererClient* client,
44 PipelineStatusCallback init_cb) = 0;
46 // Associates the |cdm_context| with this Renderer for decryption (and
47 // decoding) of media data, then fires |cdm_attached_cb| with whether the
48 // operation succeeded.
49 using CdmAttachedCB = base::OnceCallback<void(bool)>;
50 virtual void SetCdm(CdmContext* cdm_context, CdmAttachedCB cdm_attached_cb);
52 // Specifies a latency hint from the site. Renderers should clamp the hint
53 // value to reasonable min and max and use the resulting value as a target
54 // latency such that the buffering state reaches HAVE_ENOUGH when this amount
55 // of decoded data is buffered. A nullopt hint indicates the user is clearing
56 // their preference and the renderer should restore its default buffering
58 virtual void SetLatencyHint(absl::optional<base::TimeDelta> latency_hint) = 0;
60 // Sets whether pitch adjustment should be applied when the playback rate is
61 // different than 1.0.
62 virtual void SetPreservesPitch(bool preserves_pitch);
64 // Sets a flag indicating whether the audio stream was played with user
66 virtual void SetWasPlayedWithUserActivation(
67 bool was_played_with_user_activation);
69 // The following functions must be called after Initialize().
71 // Discards any buffered data, executing |flush_cb| when completed.
72 virtual void Flush(base::OnceClosure flush_cb) = 0;
74 #if defined(TIZEN_MULTIMEDIA)
75 virtual void Seek(base::TimeDelta time, base::OnceClosure seek_cb) {}
76 virtual void Suspend() {}
79 #if defined(TIZEN_VIDEO_HOLE)
80 virtual void SetVideoHole(bool is_video_hole) {}
81 virtual void SetMediaGeometry(const gfx::RectF& rect) {}
84 // Starts rendering from |time|.
85 virtual void StartPlayingFrom(base::TimeDelta time) = 0;
87 // Updates the current playback rate. The default playback rate should be 0.
88 virtual void SetPlaybackRate(double playback_rate) = 0;
90 // Sets the output volume. The default volume should be 1.
91 virtual void SetVolume(float volume) = 0;
93 // Returns the current media time.
95 // This method must be safe to call from any thread.
96 virtual base::TimeDelta GetMediaTime() = 0;
98 // Provides a list of DemuxerStreams correlating to the tracks which should
99 // be played. An empty list would mean that any playing track of the same
100 // type should be flushed and disabled. Any provided Streams should be played
101 // by whatever mechanism the subclass of Renderer choses for managing it's AV
103 virtual void OnSelectedVideoTracksChanged(
104 const std::vector<DemuxerStream*>& enabled_tracks,
105 base::OnceClosure change_completed_cb);
106 virtual void OnEnabledAudioTracksChanged(
107 const std::vector<DemuxerStream*>& enabled_tracks,
108 base::OnceClosure change_completed_cb);
110 // Signal to the renderer that there has been a client request to access a
111 // VideoFrame. This signal may be used by the renderer to ensure it is
112 // operating in a mode which produces a VideoFrame usable by the client.
113 // E.g., the MediaFoundationRendererClient on Windows has two modes
114 // of operation: Frame Server & Direct Composition. Direct Composition mode
115 // does not produce a VideoFrame with an accessible 'data' buffer, so clients
116 // cannot access the underlying image data. In order for
117 // MediaFoundationRendererClient to produce a VideoFrame with 'data'
118 // accessible by the client it must switch to operate in Frame Server mode.
119 virtual void OnExternalVideoFrameRequest();
124 #endif // MEDIA_BASE_RENDERER_H_