1 // Copyright 2015 Samsung Electronics Inc. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MEDIA_EFL_WEBMEDIAPLAYER_EFL_H_
6 #define CONTENT_RENDERER_MEDIA_EFL_WEBMEDIAPLAYER_EFL_H_
10 #include "base/message_loop/message_loop.h"
11 #include "base/memory/shared_memory.h"
12 #include "cc/layers/video_frame_provider_client_impl.h"
13 #include "content/renderer/media/efl/media_source_delegate_efl.h"
14 #include "content/renderer/media/efl/renderer_media_player_manager_efl.h"
15 #include "media/blink/webmediaplayer_util.h"
16 #include "media/base/efl/media_player_efl.h"
17 #include "media/blink/skcanvas_video_renderer.h"
18 #include "media/blink/video_frame_compositor.h"
19 #include "media/blink/webmediaplayer_params.h"
20 #include "third_party/WebKit/public/platform/WebMediaPlayer.h"
21 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient.h"
23 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
24 #include "media/blink/encrypted_media_player_support.h"
29 class WebMediaPlayerClient;
37 class GpuVideoAcceleratorFactories;
40 class WebMediaPlayerDelegate;
41 class WebMediaPlayerEncryptedMediaClient;
45 class RendererMediaPlayerManager;
47 // This class implements blink::WebMediaPlayer by keeping the efl
48 // media player in the browser process. It listens to all the status changes
49 // sent from the browser process and sends playback controls to the media
51 class WebMediaPlayerEfl
52 : public blink::WebMediaPlayer,
53 public base::SupportsWeakPtr<WebMediaPlayerEfl> {
55 // Construct a WebMediaPlayerEfl object. This class communicates
56 // with the WebMediaPlayerEfl object in the browser process through
59 RendererMediaPlayerManager* manager,
60 blink::WebFrame* frame,
61 blink::WebMediaPlayerClient* client,
62 base::WeakPtr<media::WebMediaPlayerDelegate> delegate,
63 const media::WebMediaPlayerParams& params);
64 ~WebMediaPlayerEfl() override;
66 // blink::WebMediaPlayer implementation.
67 void load(LoadType load_type,
68 const blink::WebURL& url,
69 CORSMode cors_mode) override;
73 void pause() override;
74 bool supportsSave() const override;
75 void seek(double seconds) override;
76 void setRate(double) override;
77 void setVolume(double) override;
78 blink::WebTimeRanges buffered() const override;
79 blink::WebTimeRanges seekable() const override;
80 void setSinkId(const blink::WebString&, media::WebSetSinkIdCB*) override;
82 void paint(blink::WebCanvas*,
83 const blink::WebRect&,
85 SkXfermode::Mode) override;
87 // True if the loaded media has a playable video/audio track.
88 bool hasVideo() const override;
89 bool hasAudio() const override;
91 // Dimension of the video.
92 blink::WebSize naturalSize() const override;
94 // Getters of playback state.
95 bool paused() const override;
96 bool seeking() const override;
97 double duration() const override;
98 double currentTime() const override;
100 // Internal states of loading and network.
101 NetworkState networkState() const override;
102 ReadyState readyState() const override;
104 bool didLoadingProgress() override;
106 bool hasSingleSecurityOrigin() const override;
107 bool didPassCORSAccessCheck() const override;
109 double mediaTimeForTimeValue(double timeValue) const override;
111 unsigned decodedFrameCount() const override;
112 unsigned droppedFrameCount() const override;
113 unsigned audioDecodedByteCount() const override;
114 unsigned videoDecodedByteCount() const override;
116 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
117 virtual MediaKeyException generateKeyRequest(
118 const blink::WebString& key_system,
119 const unsigned char* init_data,
120 unsigned init_data_length);
122 virtual MediaKeyException addKey(const blink::WebString& key_system,
123 const unsigned char* key,
125 const unsigned char* init_data,
126 unsigned init_data_length,
127 const blink::WebString& session_id);
129 virtual MediaKeyException cancelKeyRequest(
130 const blink::WebString& key_system,
131 const blink::WebString& session_id);
133 // TODO(jrummell): Remove this method once Blink updated to use the other
135 virtual void setContentDecryptionModule(
136 blink::WebContentDecryptionModule* cdm);
137 virtual void setContentDecryptionModule(
138 blink::WebContentDecryptionModule* cdm,
139 blink::WebContentDecryptionModuleResult result);
142 void SetReadyState(WebMediaPlayer::ReadyState state);
143 void SetNetworkState(WebMediaPlayer::NetworkState state);
145 void OnNewFrameAvailable(base::SharedMemoryHandle foreign_memory_handle,
146 uint32 length, base::TimeDelta timestamp);
148 #if defined(TIZEN_MULTIMEDIA_PIXMAP_SUPPORT)
149 void OnPlatformSurfaceUpdated(int pixmap_id, base::TimeDelta timestamp);
152 void OnMediaDataChange(int format, int height, int width, int media);
153 void OnDurationChange(double duration);
154 void OnTimeUpdate(double current_time);
156 std::vector<media::MediaPlayerEfl::TimeRanges> buffer_range);
157 void OnTimeChanged();
158 void OnPauseStateChange(bool state);
159 void OnSeekStateChange(bool state);
160 void OnRequestSeek(double seek_time);
162 void OnMediaSourceOpened(blink::WebMediaSource* web_media_source);
163 void OnDemuxerSeekDone();
167 // Called when a decoder detects that the key needed to decrypt the stream
169 void OnWaitingForDecryptionKey();
172 // Called after |defer_load_cb_| has decided to allow the load. If
173 // |defer_load_cb_| is null this is called immediately.
174 void DoLoad(LoadType load_type, const blink::WebURL& url);
176 void OnNaturalSizeChanged(gfx::Size size);
177 void OnOpacityChanged(bool opaque);
179 // Returns the current video frame from |compositor_|. Blocks until the
180 // compositor can return the frame.
181 scoped_refptr<media::VideoFrame> GetCurrentFrameFromCompositor();
183 // Called whenever there is new frame to be painted.
184 void FrameReady(const scoped_refptr<media::VideoFrame>& frame);
186 blink::WebFrame* frame_;
188 blink::WebMediaPlayer::NetworkState network_state_;
189 blink::WebMediaPlayer::ReadyState ready_state_;
191 // Message loops for posting tasks on Chrome's main thread. Also used
192 // for DCHECKs so methods calls won't execute in the wrong thread.
193 const scoped_refptr<base::SingleThreadTaskRunner> main_loop_;
194 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
196 // Manager for managing this object and for delegating method calls on
198 content::RendererMediaPlayerManager* manager_;
200 blink::WebMediaPlayerClient* client_;
201 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client_;
203 scoped_refptr<media::MediaLog> media_log_;
205 base::WeakPtr<media::WebMediaPlayerDelegate> delegate_;
207 media::WebMediaPlayerParams::DeferLoadCB defer_load_cb_;
209 // The compositor layer for displaying the video content when using
210 // composited playback.
211 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_;
213 // Video rendering members.
214 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
215 media::VideoFrameCompositor* compositor_;
216 media::SkCanvasVideoRenderer skcanvas_video_renderer_;
218 base::WeakPtrFactory<WebMediaPlayerEfl> weak_factory_;
219 scoped_ptr<content::MediaSourceDelegateEfl> media_source_delegate_;
220 MediaPlayerHostMsg_Initialize_Type player_type_;
222 // Player ID assigned by the |manager_|.
225 uint32 gst_video_format_;
232 double current_time_;
239 double pending_seek_time_;
241 // Whether the video is known to be opaque or not.
244 gfx::Size natural_size_;
245 blink::WebTimeRanges buffered_;
246 mutable bool did_loading_progress_;
248 // Factories for supporting video accelerators. May be null.
249 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories_;
250 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
251 scoped_ptr<media::EncryptedMediaPlayerSupport> encrypted_media_support_;
254 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerEfl);
257 } // namespace content
259 #endif // CONTENT_RENDERER_MEDIA_EFL_WEBMEDIAPLAYER_EFL_H_