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/base/efl/media_player_efl.h"
16 #include "media/blink/skcanvas_video_renderer.h"
17 #include "media/blink/video_frame_compositor.h"
18 #include "third_party/WebKit/public/platform/WebMediaPlayer.h"
20 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
21 #include "media/blink/encrypted_media_player_support.h"
26 class WebMediaPlayerClient;
34 class GpuVideoAcceleratorFactories;
37 class WebMediaPlayerDelegate;
41 class RendererMediaPlayerManager;
43 // This class implements blink::WebMediaPlayer by keeping the efl
44 // media player in the browser process. It listens to all the status changes
45 // sent from the browser process and sends playback controls to the media
47 class WebMediaPlayerEfl
48 : public blink::WebMediaPlayer,
49 public base::SupportsWeakPtr<WebMediaPlayerEfl> {
51 // Construct a WebMediaPlayerEfl object. This class communicates
52 // with the WebMediaPlayerEfl object in the browser process through
55 RendererMediaPlayerManager* manager,
56 blink::WebFrame* frame,
57 blink::WebMediaPlayerClient* client,
58 base::WeakPtr<media::WebMediaPlayerDelegate> delegate);
59 ~WebMediaPlayerEfl() override;
61 // blink::WebMediaPlayer implementation.
62 void load(LoadType load_type,
63 const blink::WebURL& url,
64 CORSMode cors_mode) override;
68 void pause() override;
69 bool supportsSave() const override;
70 void seek(double seconds) override;
71 void setRate(double) override;
72 void setVolume(double) override;
73 blink::WebTimeRanges buffered() const override;
74 blink::WebTimeRanges seekable() const override;
76 void paint(blink::WebCanvas*,
77 const blink::WebRect&,
79 SkXfermode::Mode) override;
81 // True if the loaded media has a playable video/audio track.
82 bool hasVideo() const override;
83 bool hasAudio() const override;
85 // Dimension of the video.
86 blink::WebSize naturalSize() const override;
88 // Getters of playback state.
89 bool paused() const override;
90 bool seeking() const override;
91 double duration() const override;
92 double currentTime() const override;
94 // Internal states of loading and network.
95 NetworkState networkState() const override;
96 ReadyState readyState() const override;
98 bool didLoadingProgress() override;
100 bool hasSingleSecurityOrigin() const override;
101 bool didPassCORSAccessCheck() const override;
103 double mediaTimeForTimeValue(double timeValue) const override;
105 unsigned decodedFrameCount() const override;
106 unsigned droppedFrameCount() const override;
107 unsigned audioDecodedByteCount() const override;
108 unsigned videoDecodedByteCount() const override;
110 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
111 virtual MediaKeyException generateKeyRequest(
112 const blink::WebString& key_system,
113 const unsigned char* init_data,
114 unsigned init_data_length);
116 virtual MediaKeyException addKey(const blink::WebString& key_system,
117 const unsigned char* key,
119 const unsigned char* init_data,
120 unsigned init_data_length,
121 const blink::WebString& session_id);
123 virtual MediaKeyException cancelKeyRequest(
124 const blink::WebString& key_system,
125 const blink::WebString& session_id);
127 // TODO(jrummell): Remove this method once Blink updated to use the other
129 virtual void setContentDecryptionModule(
130 blink::WebContentDecryptionModule* cdm);
131 virtual void setContentDecryptionModule(
132 blink::WebContentDecryptionModule* cdm,
133 blink::WebContentDecryptionModuleResult result);
136 void SetReadyState(WebMediaPlayer::ReadyState state);
137 void SetNetworkState(WebMediaPlayer::NetworkState state);
139 void OnNewFrameAvailable(base::SharedMemoryHandle foreign_memory_handle,
140 uint32 length, base::TimeDelta timestamp);
142 #if defined(TIZEN_MULTIMEDIA_PIXMAP_SUPPORT)
143 void OnPlatformSurfaceUpdated(int pixmap_id, base::TimeDelta timestamp);
146 void OnMediaDataChange(int format, int height, int width, int media);
147 void OnDurationChange(double duration);
148 void OnTimeUpdate(double current_time);
150 std::vector<media::MediaPlayerEfl::TimeRanges> buffer_range);
151 void OnTimeChanged();
152 void OnPauseStateChange(bool state);
153 void OnSeekStateChange(bool state);
154 void OnRequestSeek(double seek_time);
156 void OnMediaSourceOpened(blink::WebMediaSource* web_media_source);
157 void OnDemuxerSeekDone();
161 // Called when a decoder detects that the key needed to decrypt the stream
163 void OnWaitingForDecryptionKey();
166 void OnNaturalSizeChanged(gfx::Size size);
167 void OnOpacityChanged(bool opaque);
169 // Returns the current video frame from |compositor_|. Blocks until the
170 // compositor can return the frame.
171 scoped_refptr<media::VideoFrame> GetCurrentFrameFromCompositor();
173 // Called whenever there is new frame to be painted.
174 void FrameReady(const scoped_refptr<media::VideoFrame>& frame);
176 blink::WebFrame* frame_;
178 blink::WebMediaPlayer::NetworkState network_state_;
179 blink::WebMediaPlayer::ReadyState ready_state_;
181 // Message loops for posting tasks on Chrome's main thread. Also used
182 // for DCHECKs so methods calls won't execute in the wrong thread.
183 const scoped_refptr<base::MessageLoopProxy> main_loop_;
184 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
186 // Manager for managing this object and for delegating method calls on
188 content::RendererMediaPlayerManager* manager_;
190 blink::WebMediaPlayerClient* client_;
192 scoped_refptr<media::MediaLog> media_log_;
194 base::WeakPtr<media::WebMediaPlayerDelegate> delegate_;
196 // The compositor layer for displaying the video content when using
197 // composited playback.
198 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_;
200 // Video rendering members.
201 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
202 media::VideoFrameCompositor* compositor_;
203 media::SkCanvasVideoRenderer skcanvas_video_renderer_;
205 base::WeakPtrFactory<WebMediaPlayerEfl> weak_factory_;
206 scoped_ptr<content::MediaSourceDelegateEfl> media_source_delegate_;
207 MediaPlayerHostMsg_Initialize_Type player_type_;
209 // Player ID assigned by the |manager_|.
212 uint32 gst_video_format_;
219 double current_time_;
226 double pending_seek_time_;
228 // Whether the video is known to be opaque or not.
231 gfx::Size natural_size_;
232 blink::WebTimeRanges buffered_;
233 mutable bool did_loading_progress_;
235 // Factories for supporting video accelerators. May be null.
236 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories_;
237 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
238 scoped_ptr<media::EncryptedMediaPlayerSupport> encrypted_media_support_;
241 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerEfl);
244 } // namespace content
246 #endif // CONTENT_RENDERER_MEDIA_EFL_WEBMEDIAPLAYER_EFL_H_