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/video_frame_compositor.h"
18 #include "media/blink/webmediaplayer_params.h"
19 #include "media/renderers/skcanvas_video_renderer.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& sink_id,
81 const blink::WebSecurityOrigin& security_origin,
82 blink::WebSetSinkIdCallbacks* web_callback) override;
84 void paint(blink::WebCanvas*,
85 const blink::WebRect&,
87 SkXfermode::Mode) override;
89 // True if the loaded media has a playable video/audio track.
90 bool hasVideo() const override;
91 bool hasAudio() const override;
93 // Dimension of the video.
94 blink::WebSize naturalSize() const override;
96 // Getters of playback state.
97 bool paused() const override;
98 bool seeking() const override;
99 double duration() const override;
100 double currentTime() const override;
102 // Internal states of loading and network.
103 NetworkState networkState() const override;
104 ReadyState readyState() const override;
106 bool didLoadingProgress() override;
108 bool hasSingleSecurityOrigin() const override;
109 bool didPassCORSAccessCheck() const override;
111 double mediaTimeForTimeValue(double timeValue) const override;
113 unsigned decodedFrameCount() const override;
114 unsigned droppedFrameCount() const override;
115 unsigned audioDecodedByteCount() const override;
116 unsigned videoDecodedByteCount() const override;
118 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
119 virtual MediaKeyException generateKeyRequest(
120 const blink::WebString& key_system,
121 const unsigned char* init_data,
122 unsigned init_data_length);
124 virtual MediaKeyException addKey(const blink::WebString& key_system,
125 const unsigned char* key,
127 const unsigned char* init_data,
128 unsigned init_data_length,
129 const blink::WebString& session_id);
131 virtual MediaKeyException cancelKeyRequest(
132 const blink::WebString& key_system,
133 const blink::WebString& session_id);
135 // TODO(jrummell): Remove this method once Blink updated to use the other
137 virtual void setContentDecryptionModule(
138 blink::WebContentDecryptionModule* cdm);
139 virtual void setContentDecryptionModule(
140 blink::WebContentDecryptionModule* cdm,
141 blink::WebContentDecryptionModuleResult result);
144 void SetReadyState(WebMediaPlayer::ReadyState state);
145 void SetNetworkState(WebMediaPlayer::NetworkState state);
147 void OnNewFrameAvailable(base::SharedMemoryHandle foreign_memory_handle,
148 uint32 length, base::TimeDelta timestamp);
150 #if defined(TIZEN_TBM_SUPPORT)
151 void OnNewTbmBufferAvailable(
152 const gfx::TbmBufferHandle& tbm_handle,
153 base::TimeDelta timestamp,
154 const base::Closure& cb);
157 void OnMediaDataChange(int format, int height, int width, int media);
158 void OnDurationChange(double duration);
159 void OnTimeUpdate(double current_time);
161 std::vector<media::MediaPlayerEfl::TimeRanges> buffer_range);
162 void OnTimeChanged();
163 void OnPauseStateChange(bool state);
164 void OnSeekStateChange(bool state);
165 void OnRequestSeek(double seek_time);
167 void OnMediaSourceOpened(blink::WebMediaSource* web_media_source);
168 void OnDemuxerSeekDone();
172 // Called when a decoder detects that the key needed to decrypt the stream
174 void OnWaitingForDecryptionKey();
177 // Called after |defer_load_cb_| has decided to allow the load. If
178 // |defer_load_cb_| is null this is called immediately.
179 void DoLoad(LoadType load_type, const blink::WebURL& url);
181 void OnNaturalSizeChanged(gfx::Size size);
182 void OnOpacityChanged(bool opaque);
184 // Returns the current video frame from |compositor_|. Blocks until the
185 // compositor can return the frame.
186 scoped_refptr<media::VideoFrame> GetCurrentFrameFromCompositor();
188 // Called whenever there is new frame to be painted.
189 void FrameReady(const scoped_refptr<media::VideoFrame>& frame);
191 blink::WebFrame* frame_;
193 blink::WebMediaPlayer::NetworkState network_state_;
194 blink::WebMediaPlayer::ReadyState ready_state_;
196 // Message loops for posting tasks on Chrome's main thread. Also used
197 // for DCHECKs so methods calls won't execute in the wrong thread.
198 const scoped_refptr<base::SingleThreadTaskRunner> main_loop_;
199 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
201 // Manager for managing this object and for delegating method calls on
203 content::RendererMediaPlayerManager* manager_;
205 blink::WebMediaPlayerClient* client_;
206 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client_;
208 scoped_refptr<media::MediaLog> media_log_;
210 base::WeakPtr<media::WebMediaPlayerDelegate> delegate_;
212 media::WebMediaPlayerParams::DeferLoadCB defer_load_cb_;
214 // The compositor layer for displaying the video content when using
215 // composited playback.
216 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_;
218 // Video rendering members.
219 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
220 media::VideoFrameCompositor* compositor_;
221 media::SkCanvasVideoRenderer skcanvas_video_renderer_;
223 base::WeakPtrFactory<WebMediaPlayerEfl> weak_factory_;
224 scoped_ptr<content::MediaSourceDelegateEfl> media_source_delegate_;
225 MediaPlayerHostMsg_Initialize_Type player_type_;
227 // Player ID assigned by the |manager_|.
236 double current_time_;
243 double pending_seek_time_;
245 // Whether the video is known to be opaque or not.
248 gfx::Size natural_size_;
249 blink::WebTimeRanges buffered_;
250 mutable bool did_loading_progress_;
252 // Factories for supporting video accelerators. May be null.
253 media::GpuVideoAcceleratorFactories* gpu_factories_;
254 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
255 scoped_ptr<media::EncryptedMediaPlayerSupport> encrypted_media_support_;
258 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerEfl);
261 } // namespace content
263 #endif // CONTENT_RENDERER_MEDIA_EFL_WEBMEDIAPLAYER_EFL_H_