[M108 Migration][MM] Introduce renderer seek
[platform/framework/web/chromium-efl.git] / media / base / renderer.h
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.
4
5 #ifndef MEDIA_BASE_RENDERER_H_
6 #define MEDIA_BASE_RENDERER_H_
7
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"
16
17 #if defined(TIZEN_VIDEO_HOLE)
18 #include "ui/gfx/geometry/rect_f.h"
19 #endif
20
21 namespace media {
22
23 class CdmContext;
24 class MediaResource;
25 class RendererClient;
26
27 class MEDIA_EXPORT Renderer {
28  public:
29   Renderer();
30
31   Renderer(const Renderer&) = delete;
32   Renderer& operator=(const Renderer&) = delete;
33
34   // Stops rendering and fires any pending callbacks.
35   virtual ~Renderer();
36
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;
45
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);
51
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
57   // thresholds.
58   virtual void SetLatencyHint(absl::optional<base::TimeDelta> latency_hint) = 0;
59
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);
63
64   // Sets a flag indicating whether the audio stream was played with user
65   // activation.
66   virtual void SetWasPlayedWithUserActivation(
67       bool was_played_with_user_activation);
68
69   // The following functions must be called after Initialize().
70
71   // Discards any buffered data, executing |flush_cb| when completed.
72   virtual void Flush(base::OnceClosure flush_cb) = 0;
73
74 #if defined(TIZEN_MULTIMEDIA)
75   virtual void Seek(base::TimeDelta time, base::OnceClosure seek_cb) {}
76 #endif
77
78 #if defined(TIZEN_VIDEO_HOLE)
79   virtual void SetVideoHole(bool is_video_hole) {}
80   virtual void SetMediaGeometry(const gfx::RectF& rect) {}
81 #endif
82
83   // Starts rendering from |time|.
84   virtual void StartPlayingFrom(base::TimeDelta time) = 0;
85
86   // Updates the current playback rate. The default playback rate should be 0.
87   virtual void SetPlaybackRate(double playback_rate) = 0;
88
89   // Sets the output volume. The default volume should be 1.
90   virtual void SetVolume(float volume) = 0;
91
92   // Returns the current media time.
93   //
94   // This method must be safe to call from any thread.
95   virtual base::TimeDelta GetMediaTime() = 0;
96
97   // Provides a list of DemuxerStreams correlating to the tracks which should
98   // be played. An empty list would mean that any playing track of the same
99   // type should be flushed and disabled. Any provided Streams should be played
100   // by whatever mechanism the subclass of Renderer choses for managing it's AV
101   // playback.
102   virtual void OnSelectedVideoTracksChanged(
103       const std::vector<DemuxerStream*>& enabled_tracks,
104       base::OnceClosure change_completed_cb);
105   virtual void OnEnabledAudioTracksChanged(
106       const std::vector<DemuxerStream*>& enabled_tracks,
107       base::OnceClosure change_completed_cb);
108
109   // Signal to the renderer that there has been a client request to access a
110   // VideoFrame. This signal may be used by the renderer to ensure it is
111   // operating in a mode which produces a VideoFrame usable by the client.
112   // E.g., the MediaFoundationRendererClient on Windows has two modes
113   // of operation: Frame Server & Direct Composition. Direct Composition mode
114   // does not produce a VideoFrame with an accessible 'data' buffer, so clients
115   // cannot access the underlying image data. In order for
116   // MediaFoundationRendererClient to produce a VideoFrame with 'data'
117   // accessible by the client it must switch to operate in Frame Server mode.
118   virtual void OnExternalVideoFrameRequest();
119 };
120
121 }  // namespace media
122
123 #endif  // MEDIA_BASE_RENDERER_H_