2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_MEDIA_PLAYER_CLIENT_H_
32 #define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_MEDIA_PLAYER_CLIENT_H_
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"
45 enum class MediaContentType;
46 enum class VideoCodec;
47 enum class AudioCodec;
53 class WebRemotePlaybackClient;
55 class BLINK_PLATFORM_EXPORT WebMediaPlayerClient {
59 kVideoTrackKindAlternative,
60 kVideoTrackKindCaptions,
63 kVideoTrackKindSubtitles,
64 kVideoTrackKindCommentary
69 kAudioTrackKindAlternative,
70 kAudioTrackKindDescriptions,
72 kAudioTrackKindMainDescriptions,
73 kAudioTrackKindTranslation,
74 kAudioTrackKindCommentary
77 // Reason for a PausePlayback call, for better diagnostic messages.
78 enum class PauseReason {
80 kBackgroundVideoOptimization,
81 kSuspendedPlayerIdleTimeout,
82 kRemotePlayStateChange,
85 static const int kMediaRemotingStopNoText = -1;
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,
96 const WebString& label,
97 const WebString& language,
99 virtual void RemoveAudioTrack(WebMediaPlayer::TrackId) = 0;
100 virtual WebMediaPlayer::TrackId AddVideoTrack(const WebString& id,
102 const WebString& label,
103 const WebString& language,
105 virtual void RemoveVideoTrack(WebMediaPlayer::TrackId) = 0;
106 virtual void MediaSourceOpened(WebMediaSource*) = 0;
107 virtual void RemotePlaybackCompatibilityChanged(const WebURL&,
108 bool is_compatible) = 0;
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;
114 // Returns if there's a selected video track.
115 virtual bool HasSelectedVideoTrack() = 0;
117 // Returns the selected video track id (or an empty id if there's none).
118 virtual WebMediaPlayer::TrackId GetSelectedVideoTrackId() = 0;
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;
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;
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;
136 // Returns true iff the client represents an HTML <audio> element.
137 virtual bool IsAudioElement() = 0;
139 // Returns the current display type of the media element.
140 virtual DisplayType GetDisplayType() const = 0;
142 // Returns the remote playback client associated with the media element, if
144 virtual WebRemotePlaybackClient* RemotePlaybackClient() { return nullptr; }
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(); }
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; }
157 // Returns true if playback would start if the ready state was at least
158 // WebMediaPlayer::kReadyStateHaveFutureData.
159 virtual bool CouldPlayIfEnoughData() const = 0;
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;
165 // Requests the player to resume playback.
166 virtual void ResumePlayback() = 0;
168 // Request the player to pause playback.
169 virtual void PausePlayback(PauseReason) = 0;
171 // Notify the client that the media player started playing content.
172 virtual void DidPlayerStartPlaying() = 0;
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;
178 // Notify the client that the muted status of the media player has changed.
179 virtual void DidPlayerMutedStatusChange(bool muted) = 0;
181 // Notify the client that the media metadata of the media player has changed.
182 virtual void DidMediaMetadataChange(
185 media::AudioCodec audio_codec,
186 media::VideoCodec video_codec,
187 media::MediaContentType media_content_type,
188 bool is_encrypted_media) = 0;
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;
196 // Notify the client that the audio sink cannot be changed.
197 virtual void DidDisableAudioOutputSinkChanges() = 0;
199 // Notify the client that the playback starts/stops to use AudioService.
200 virtual void DidUseAudioServiceChange(bool uses_audio_service) = 0;
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;
206 virtual void OnFirstFrame(base::TimeTicks first_frame,
207 size_t bytes_to_first_frame) = 0;
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
216 virtual void OnPictureInPictureStateChange() = 0;
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() {}
223 // Notify the client that the RemotePlayback has been disabled/enabled.
224 virtual void OnRemotePlaybackDisabled(bool disabled) = 0;
226 #if defined(TIZEN_MULTIMEDIA)
227 virtual void SuspendPlayer() {}
228 virtual void OnLivePlaybackComplete() = 0;
231 #if BUILDFLAG(IS_TIZEN_TV)
232 virtual WebString GetContentMIMEType() = 0;
236 ~WebMediaPlayerClient() = default;
241 #endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_WEB_MEDIA_PLAYER_CLIENT_H_