[M120 Migration][MM] Handle live stream duration and currenttime
[platform/framework/web/chromium-efl.git] / third_party / blink / public / platform / web_media_player_client.h
1 /*
2  * Copyright (C) 2009 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_MEDIA_PLAYER_CLIENT_H_
32 #define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_MEDIA_PLAYER_CLIENT_H_
33
34 #include "base/time/time.h"
35 #include "third_party/blink/public/common/media/display_type.h"
36 #include "third_party/blink/public/platform/web_common.h"
37 #include "third_party/blink/public/platform/web_media_player.h"
38 #include "ui/gfx/color_space.h"
39
40 namespace cc {
41 class Layer;
42 }
43
44 namespace media {
45 enum class MediaContentType;
46 enum class VideoCodec;
47 enum class AudioCodec;
48 }  // namespace media
49
50 namespace blink {
51
52 class WebMediaSource;
53 class WebRemotePlaybackClient;
54
55 class BLINK_PLATFORM_EXPORT WebMediaPlayerClient {
56  public:
57   enum VideoTrackKind {
58     kVideoTrackKindNone,
59     kVideoTrackKindAlternative,
60     kVideoTrackKindCaptions,
61     kVideoTrackKindMain,
62     kVideoTrackKindSign,
63     kVideoTrackKindSubtitles,
64     kVideoTrackKindCommentary
65   };
66
67   enum AudioTrackKind {
68     kAudioTrackKindNone,
69     kAudioTrackKindAlternative,
70     kAudioTrackKindDescriptions,
71     kAudioTrackKindMain,
72     kAudioTrackKindMainDescriptions,
73     kAudioTrackKindTranslation,
74     kAudioTrackKindCommentary
75   };
76
77   // Reason for a PausePlayback call, for better diagnostic messages.
78   enum class PauseReason {
79     kUnknown,
80     kBackgroundVideoOptimization,
81     kSuspendedPlayerIdleTimeout,
82     kRemotePlayStateChange,
83   };
84
85   static const int kMediaRemotingStopNoText = -1;
86
87   virtual void NetworkStateChanged() = 0;
88   virtual void ReadyStateChanged() = 0;
89   virtual void TimeChanged() = 0;
90   virtual void Repaint() = 0;
91   virtual void DurationChanged() = 0;
92   virtual void SizeChanged() = 0;
93   virtual void SetCcLayer(cc::Layer*) = 0;
94   virtual WebMediaPlayer::TrackId AddAudioTrack(const WebString& id,
95                                                 AudioTrackKind,
96                                                 const WebString& label,
97                                                 const WebString& language,
98                                                 bool enabled) = 0;
99   virtual void RemoveAudioTrack(WebMediaPlayer::TrackId) = 0;
100   virtual WebMediaPlayer::TrackId AddVideoTrack(const WebString& id,
101                                                 VideoTrackKind,
102                                                 const WebString& label,
103                                                 const WebString& language,
104                                                 bool selected) = 0;
105   virtual void RemoveVideoTrack(WebMediaPlayer::TrackId) = 0;
106   virtual void MediaSourceOpened(WebMediaSource*) = 0;
107   virtual void RemotePlaybackCompatibilityChanged(const WebURL&,
108                                                   bool is_compatible) = 0;
109
110   // Returns whether the media element has always been muted. This is used to
111   // avoid take audio focus for elements that the user is not aware is playing.
112   virtual bool WasAlwaysMuted() = 0;
113
114   // Returns if there's a selected video track.
115   virtual bool HasSelectedVideoTrack() = 0;
116
117   // Returns the selected video track id (or an empty id if there's none).
118   virtual WebMediaPlayer::TrackId GetSelectedVideoTrackId() = 0;
119
120   // Informs that media starts being rendered and played back remotely.
121   // |remote_device_friendly_name| will be shown in the remoting UI to indicate
122   // which device the content is rendered on. An empty name indicates an unknown
123   // remote device. A default message will be shown in this case.
124   virtual void MediaRemotingStarted(
125       const WebString& remote_device_friendly_name) = 0;
126
127   // Informs that media stops being rendered remotely. |error_code| corresponds
128   // to a localized string that explains the reason as user-readable text.
129   // |error_code| should be IDS_FOO or kMediaRemotingStopNoText.
130   virtual void MediaRemotingStopped(int error_code) = 0;
131
132   // Returns whether the media element has native controls. It does not mean
133   // that the controls are currently visible.
134   virtual bool HasNativeControls() = 0;
135
136   // Returns true iff the client represents an HTML <audio> element.
137   virtual bool IsAudioElement() = 0;
138
139   // Returns the current display type of the media element.
140   virtual DisplayType GetDisplayType() const = 0;
141
142   // Returns the remote playback client associated with the media element, if
143   // any.
144   virtual WebRemotePlaybackClient* RemotePlaybackClient() { return nullptr; }
145
146   // Returns the color space to render media into if.
147   // Rendering media into this color space may avoid some conversions.
148   virtual gfx::ColorSpace TargetColorSpace() { return gfx::ColorSpace(); }
149
150   // Returns whether the media element was initiated via autoplay.
151   // In this context, autoplay means that it was initiated before any user
152   // activation was received on the page and before a user initiated same-domain
153   // navigation. In other words, with the unified autoplay policy applied, it
154   // should only return `true` when MEI allowed autoplay.
155   virtual bool WasAutoplayInitiated() { return false; }
156
157   // Returns true if playback would start if the ready state was at least
158   // WebMediaPlayer::kReadyStateHaveFutureData.
159   virtual bool CouldPlayIfEnoughData() const = 0;
160
161   // Returns whether the playback is in auto-pip mode which does not have th
162   // behavior as regular Picture-in-Picture.
163   virtual bool IsInAutoPIP() const = 0;
164
165   // Requests the player to resume playback.
166   virtual void ResumePlayback() = 0;
167
168   // Request the player to pause playback.
169   virtual void PausePlayback(PauseReason) = 0;
170
171   // Notify the client that the media player started playing content.
172   virtual void DidPlayerStartPlaying() = 0;
173
174   // Notify the client that the media player stopped playing content, indicating
175   // in |stream_ended| if playback has reached the end of the stream.
176   virtual void DidPlayerPaused(bool stream_ended) = 0;
177
178   // Notify the client that the muted status of the media player has changed.
179   virtual void DidPlayerMutedStatusChange(bool muted) = 0;
180
181   // Notify the client that the media metadata of the media player has changed.
182   virtual void DidMediaMetadataChange(
183       bool has_audio,
184       bool has_video,
185       media::AudioCodec audio_codec,
186       media::VideoCodec video_codec,
187       media::MediaContentType media_content_type,
188       bool is_encrypted_media) = 0;
189
190   // Notify the client that the playback position has changed.
191   virtual void DidPlayerMediaPositionStateChange(double playback_rate,
192                                                  base::TimeDelta duration,
193                                                  base::TimeDelta position,
194                                                  bool end_of_media) = 0;
195
196   // Notify the client that the audio sink cannot be changed.
197   virtual void DidDisableAudioOutputSinkChanges() = 0;
198
199   // Notify the client that the playback starts/stops to use AudioService.
200   virtual void DidUseAudioServiceChange(bool uses_audio_service) = 0;
201
202   // Notify the client that the size of the media player has changed.
203   // TODO(crbug.com/1039252): Remove by merging this method into SizeChanged().
204   virtual void DidPlayerSizeChange(const gfx::Size& size) = 0;
205
206   virtual void OnFirstFrame(base::TimeTicks first_frame,
207                             size_t bytes_to_first_frame) = 0;
208
209   // Notify the client that one of the state used by Picture-in-Picture has
210   // changed. The client will then have to poll the states from the associated
211   // WebMediaPlayer.
212   // The states are:
213   //  - Delegate ID;
214   //  - Surface ID;
215   //  - Natural Size.
216   virtual void OnPictureInPictureStateChange() = 0;
217
218   // Called when a video frame has been presented to the compositor, after a
219   // request was initiated via WebMediaPlayer::RequestVideoFrameCallback().
220   // See https://wicg.github.io/video-rvfc/.
221   virtual void OnRequestVideoFrameCallback() {}
222
223   // Notify the client that the RemotePlayback has been disabled/enabled.
224   virtual void OnRemotePlaybackDisabled(bool disabled) = 0;
225
226 #if defined(TIZEN_MULTIMEDIA)
227   virtual void SuspendPlayer() {}
228   virtual void OnLivePlaybackComplete() = 0;
229 #endif
230
231 #if BUILDFLAG(IS_TIZEN_TV)
232   virtual WebString GetContentMIMEType() = 0;
233 #endif
234
235  protected:
236   ~WebMediaPlayerClient() = default;
237 };
238
239 }  // namespace blink
240
241 #endif  // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_MEDIA_PLAYER_CLIENT_H_