[M120 Migration][hbbtv] Audio tracks count notification
[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/functional/callback.h"
9 #include "base/time/time.h"
10 #include "media/base/buffering_state.h"
11 #include "media/base/demuxer_stream.h"
12 #include "media/base/media_export.h"
13 #include "media/base/pipeline_status.h"
14 #include "third_party/abseil-cpp/absl/types/optional.h"
15
16 #if defined(TIZEN_VIDEO_HOLE)
17 #include "ui/gfx/geometry/rect_f.h"
18 #endif
19
20 namespace media {
21
22 class CdmContext;
23 class MediaResource;
24 class RendererClient;
25 #if defined(TIZEN_MULTIMEDIA)
26 namespace mojom {
27 enum class HardwareResourceConfig;
28 }
29 #endif
30
31 // Types of media::Renderer.
32 // WARNING: These values are reported to metrics. Entries should not be
33 // renumbered and numeric values should not be reused. When adding new entries,
34 // also update media::mojom::RendererType & tools/metrics/histograms/enums.xml.
35 enum class RendererType {
36   kRendererImpl = 0,     // RendererImplFactory
37   kMojo = 1,             // MojoRendererFactory
38   kMediaPlayer = 2,      // MediaPlayerRendererClientFactory
39   kCourier = 3,          // CourierRendererFactory
40   kFlinging = 4,         // FlingingRendererClientFactory
41   kCast = 5,             // CastRendererClientFactory
42   kMediaFoundation = 6,  // MediaFoundationRendererClientFactory
43   // kFuchsia = 7,       // Deprecated
44   kRemoting = 8,       // RemotingRendererFactory for remoting::Receiver
45   kCastStreaming = 9,  // PlaybackCommandForwardingRendererFactory
46   kContentEmbedderDefined = 10,  // Defined by the content embedder
47   kTest = 11,                    // Renderer implementations used in tests
48   kMaxValue = kTest,
49 };
50
51 // Get the name of the Renderer for `renderer_type`. The returned name could be
52 // the actual Renderer class name or a descriptive name.
53 std::string MEDIA_EXPORT GetRendererName(RendererType renderer_type);
54
55 class MEDIA_EXPORT Renderer {
56  public:
57   Renderer();
58
59   Renderer(const Renderer&) = delete;
60   Renderer& operator=(const Renderer&) = delete;
61
62   // Stops rendering and fires any pending callbacks.
63   virtual ~Renderer();
64
65   // Initializes the Renderer with |media_resource|, executing |init_cb| upon
66   // completion. |media_resource| must be valid for the lifetime of the Renderer
67   // object.  |init_cb| must only be run after this method has returned. Firing
68   // |init_cb| may result in the immediate destruction of the caller, so it must
69   // be run only prior to returning.
70   virtual void Initialize(MediaResource* media_resource,
71                           RendererClient* client,
72                           PipelineStatusCallback init_cb) = 0;
73
74   // Associates the |cdm_context| with this Renderer for decryption (and
75   // decoding) of media data, then fires |cdm_attached_cb| with whether the
76   // operation succeeded.
77   using CdmAttachedCB = base::OnceCallback<void(bool)>;
78   virtual void SetCdm(CdmContext* cdm_context, CdmAttachedCB cdm_attached_cb);
79
80   // Specifies a latency hint from the site. Renderers should clamp the hint
81   // value to reasonable min and max and use the resulting value as a target
82   // latency such that the buffering state reaches HAVE_ENOUGH when this amount
83   // of decoded data is buffered. A nullopt hint indicates the user is clearing
84   // their preference and the renderer should restore its default buffering
85   // thresholds.
86   virtual void SetLatencyHint(absl::optional<base::TimeDelta> latency_hint) = 0;
87
88   // Sets whether pitch adjustment should be applied when the playback rate is
89   // different than 1.0.
90   virtual void SetPreservesPitch(bool preserves_pitch);
91
92   // Sets a flag indicating whether the audio stream was played with user
93   // activation.
94   virtual void SetWasPlayedWithUserActivation(
95       bool was_played_with_user_activation);
96
97   // The following functions must be called after Initialize().
98
99   // Discards any buffered data, executing |flush_cb| when completed.
100   virtual void Flush(base::OnceClosure flush_cb) = 0;
101
102 #if defined(TIZEN_MULTIMEDIA)
103   virtual void Seek(base::TimeDelta time, base::OnceClosure seek_cb) {}
104   virtual void Suspend() {}
105   virtual void EnableLowLatencyMode() {}
106   using SetHardwareResourceCB = base::OnceCallback<void(bool)>;
107   virtual void SetHardwareResource(media::mojom::HardwareResourceConfig config,
108                                    SetHardwareResourceCB cb) {}
109   using RequestVideoDecodedBufferCB = base::OnceCallback<void(bool)>;
110   virtual void RequestVideoDecodedBuffer(RequestVideoDecodedBufferCB cb) {}
111   using ToggledFullscreenCB = base::OnceCallback<void()>;
112   virtual void ToggleFullscreenMode(bool is_fullscreen,
113                                     ToggledFullscreenCB cb) {}
114 #endif
115
116 #if defined(TIZEN_VIDEO_HOLE)
117   virtual void SetPlayerVideoAbove(int32_t other_id) {}
118   virtual void UseSubsurfaceController() {}
119   virtual void SetVideoHole(bool is_video_hole) {}
120   virtual void SetMediaGeometry(const gfx::RectF& rect,
121                                 media::VideoRotation rotation) {}
122 #endif
123
124   using StartDateCB = base::OnceCallback<void(double)>;
125 #if BUILDFLAG(IS_TIZEN_TV)
126   using GetVideoIdCB = base::OnceCallback<void(int32_t)>;
127   virtual void GetVideoId(GetVideoIdCB cb) {}
128   virtual void SetContentMimeType(const std::string& mime_type) {}
129   virtual void AudioTracksCountChanged(unsigned count) {}
130   virtual void SetParentalRatingResult(bool is_pass) {}
131   virtual void SetActiveTextTrack(int id, bool is_in_band) {}
132   virtual void SetActiveAudioTrack(int index) {}
133   virtual void SetActiveVideoTrack(int index) {}
134   virtual void SetPreferTextLanguage(const std::string& lang) {}
135   virtual void GetStartDate(StartDateCB cb) {}
136   virtual void DestroyPlayerSync(base::OnceClosure cb) {}
137 #endif
138
139   // Starts rendering from |time|.
140   virtual void StartPlayingFrom(base::TimeDelta time) = 0;
141
142   // Updates the current playback rate. The default playback rate should be 0.
143   virtual void SetPlaybackRate(double playback_rate) = 0;
144
145   // Sets the output volume. The default volume should be 1.
146   virtual void SetVolume(float volume) = 0;
147
148   // Returns the current media time.
149   //
150   // This method must be safe to call from any thread.
151   virtual base::TimeDelta GetMediaTime() = 0;
152
153   // Provides a list of DemuxerStreams correlating to the tracks which should
154   // be played. An empty list would mean that any playing track of the same
155   // type should be flushed and disabled. Any provided Streams should be played
156   // by whatever mechanism the subclass of Renderer choses for managing it's AV
157   // playback.
158   virtual void OnSelectedVideoTracksChanged(
159       const std::vector<DemuxerStream*>& enabled_tracks,
160       base::OnceClosure change_completed_cb);
161   virtual void OnEnabledAudioTracksChanged(
162       const std::vector<DemuxerStream*>& enabled_tracks,
163       base::OnceClosure change_completed_cb);
164
165   // Signal to the renderer that there has been a client request to access a
166   // VideoFrame. This signal may be used by the renderer to ensure it is
167   // operating in a mode which produces a VideoFrame usable by the client.
168   // E.g., the MediaFoundationRendererClient on Windows has two modes
169   // of operation: Frame Server & Direct Composition. Direct Composition mode
170   // does not produce a VideoFrame with an accessible 'data' buffer, so clients
171   // cannot access the underlying image data. In order for
172   // MediaFoundationRendererClient to produce a VideoFrame with 'data'
173   // accessible by the client it must switch to operate in Frame Server mode.
174   virtual void OnExternalVideoFrameRequest();
175
176   // Returns the type of the Renderer implementation. Marked as pure virtual to
177   // enforce RendererType registration for all Renderer implementations.
178   // Note: New implementation should update RendererType.
179   virtual RendererType GetRendererType() = 0;
180 };
181
182 }  // namespace media
183
184 #endif  // MEDIA_BASE_RENDERER_H_