[M49_2623] Chromium upversion to m49_2623 branch.
[platform/framework/web/chromium-efl.git] / tizen_src / chromium_impl / content / renderer / media / efl / webmediaplayer_efl.h
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.
4
5 #ifndef CONTENT_RENDERER_MEDIA_EFL_WEBMEDIAPLAYER_EFL_H_
6 #define CONTENT_RENDERER_MEDIA_EFL_WEBMEDIAPLAYER_EFL_H_
7
8 #include <vector>
9
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"
22
23 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
24 #include "media/blink/encrypted_media_player_support.h"
25 #endif
26
27 namespace blink {
28 class WebFrame;
29 class WebMediaPlayerClient;
30 }
31
32 namespace cc_blink {
33 class WebLayerImpl;
34 }
35
36 namespace media {
37 class GpuVideoAcceleratorFactories;
38 class MediaLog;
39 class MediaPlayerEfl;
40 class WebMediaPlayerDelegate;
41 class WebMediaPlayerEncryptedMediaClient;
42 }
43
44 namespace content {
45 class RendererMediaPlayerManager;
46
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
50 // player.
51 class WebMediaPlayerEfl
52     : public blink::WebMediaPlayer,
53       public base::SupportsWeakPtr<WebMediaPlayerEfl> {
54  public:
55   // Construct a WebMediaPlayerEfl object. This class communicates
56   // with the WebMediaPlayerEfl object in the browser process through
57   // |proxy|.
58   WebMediaPlayerEfl(
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;
65
66   // blink::WebMediaPlayer implementation.
67   void load(LoadType load_type,
68             const blink::WebURL& url,
69             CORSMode cors_mode) override;
70
71   // Playback controls.
72   void play() 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;
83
84   void paint(blink::WebCanvas*,
85       const blink::WebRect&,
86       unsigned char alpha,
87       SkXfermode::Mode) override;
88
89   // True if the loaded media has a playable video/audio track.
90   bool hasVideo() const override;
91   bool hasAudio() const override;
92
93   // Dimension of the video.
94   blink::WebSize naturalSize() const override;
95
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;
101
102   // Internal states of loading and network.
103   NetworkState networkState() const override;
104   ReadyState readyState() const override;
105
106   bool didLoadingProgress() override;
107
108   bool hasSingleSecurityOrigin() const override;
109   bool didPassCORSAccessCheck() const override;
110
111   double mediaTimeForTimeValue(double timeValue) const override;
112
113   unsigned decodedFrameCount() const override;
114   unsigned droppedFrameCount() const override;
115   unsigned audioDecodedByteCount() const override;
116   unsigned videoDecodedByteCount() const override;
117
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);
123
124   virtual MediaKeyException addKey(const blink::WebString& key_system,
125                                    const unsigned char* key,
126                                    unsigned key_length,
127                                    const unsigned char* init_data,
128                                    unsigned init_data_length,
129                                    const blink::WebString& session_id);
130
131   virtual MediaKeyException cancelKeyRequest(
132       const blink::WebString& key_system,
133       const blink::WebString& session_id);
134
135   // TODO(jrummell): Remove this method once Blink updated to use the other
136   // method.
137   virtual void setContentDecryptionModule(
138       blink::WebContentDecryptionModule* cdm);
139   virtual void setContentDecryptionModule(
140       blink::WebContentDecryptionModule* cdm,
141       blink::WebContentDecryptionModuleResult result);
142 #endif
143
144   void SetReadyState(WebMediaPlayer::ReadyState state);
145   void SetNetworkState(WebMediaPlayer::NetworkState state);
146
147   void OnNewFrameAvailable(base::SharedMemoryHandle foreign_memory_handle,
148                            uint32_t length, base::TimeDelta timestamp);
149
150 #if defined(TIZEN_TBM_SUPPORT)
151   void OnNewTbmBufferAvailable(
152       const gfx::TbmBufferHandle& tbm_handle,
153       base::TimeDelta timestamp,
154       const base::Closure& cb);
155 #endif
156
157   void OnMediaDataChange(int width, int height, int media);
158   void OnDurationChange(double duration);
159   void OnTimeUpdate(double current_time);
160   void OnBufferUpdate(
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);
166
167   void OnMediaSourceOpened(blink::WebMediaSource* web_media_source);
168   void OnDemuxerSeekDone();
169
170   void RequestPause();
171
172   // Called when a decoder detects that the key needed to decrypt the stream
173   // is not available.
174   void OnWaitingForDecryptionKey();
175
176  private:
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);
180
181   void OnNaturalSizeChanged(gfx::Size size);
182   void OnOpacityChanged(bool opaque);
183
184   // Returns the current video frame from |compositor_|. Blocks until the
185   // compositor can return the frame.
186   scoped_refptr<media::VideoFrame> GetCurrentFrameFromCompositor();
187
188   // Called whenever there is new frame to be painted.
189   void FrameReady(const scoped_refptr<media::VideoFrame>& frame);
190
191   blink::WebFrame* frame_;
192
193   blink::WebMediaPlayer::NetworkState network_state_;
194   blink::WebMediaPlayer::ReadyState ready_state_;
195
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_;
200
201   // Manager for managing this object and for delegating method calls on
202   // Render Thread.
203   content::RendererMediaPlayerManager* manager_;
204
205   blink::WebMediaPlayerClient* client_;
206   blink::WebMediaPlayerEncryptedMediaClient* encrypted_client_;
207
208   scoped_refptr<media::MediaLog> media_log_;
209
210   base::WeakPtr<media::WebMediaPlayerDelegate> delegate_;
211
212   media::WebMediaPlayerParams::DeferLoadCB defer_load_cb_;
213
214   // The compositor layer for displaying the video content when using
215   // composited playback.
216   scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_;
217
218   // Video rendering members.
219   scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
220   media::VideoFrameCompositor* compositor_;
221   media::SkCanvasVideoRenderer skcanvas_video_renderer_;
222
223   base::WeakPtrFactory<WebMediaPlayerEfl> weak_factory_;
224   scoped_ptr<content::MediaSourceDelegateEfl> media_source_delegate_;
225   MediaPlayerHostMsg_Initialize_Type player_type_;
226
227   // Player ID assigned by the |manager_|.
228   int player_id_;
229
230   int video_width_;
231   int video_height_;
232
233   bool audio_;
234   bool video_;
235
236   double current_time_;
237   double duration_;
238   bool is_paused_;
239
240   bool is_seeking_;
241   double seek_time_;
242   bool pending_seek_;
243   double pending_seek_time_;
244
245   // Whether the video is known to be opaque or not.
246   bool opaque_;
247
248   gfx::Size natural_size_;
249   blink::WebTimeRanges buffered_;
250   mutable bool did_loading_progress_;
251
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_;
256 #endif
257
258   DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerEfl);
259 };
260
261 }  // namespace content
262
263 #endif  // CONTENT_RENDERER_MEDIA_EFL_WEBMEDIAPLAYER_EFL_H_