[MM] Multimedia up-version to M47
[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/skcanvas_video_renderer.h"
18 #include "media/blink/video_frame_compositor.h"
19 #include "third_party/WebKit/public/platform/WebMediaPlayer.h"
20 #include "third_party/WebKit/public/platform/WebMediaPlayerEncryptedMediaClient.h"
21
22 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
23 #include "media/blink/encrypted_media_player_support.h"
24 #endif
25
26 namespace blink {
27 class WebFrame;
28 class WebMediaPlayerClient;
29 }
30
31 namespace cc_blink {
32 class WebLayerImpl;
33 }
34
35 namespace media {
36 class GpuVideoAcceleratorFactories;
37 class MediaLog;
38 class MediaPlayerEfl;
39 class WebMediaPlayerDelegate;
40 class WebMediaPlayerEncryptedMediaClient;
41 }
42
43 namespace content {
44 class RendererMediaPlayerManager;
45
46 // This class implements blink::WebMediaPlayer by keeping the efl
47 // media player in the browser process. It listens to all the status changes
48 // sent from the browser process and sends playback controls to the media
49 // player.
50 class WebMediaPlayerEfl
51     : public blink::WebMediaPlayer,
52       public base::SupportsWeakPtr<WebMediaPlayerEfl> {
53  public:
54   // Construct a WebMediaPlayerEfl object. This class communicates
55   // with the WebMediaPlayerEfl object in the browser process through
56   // |proxy|.
57   WebMediaPlayerEfl(
58       RendererMediaPlayerManager* manager,
59       blink::WebFrame* frame,
60       blink::WebMediaPlayerClient* client,
61       base::WeakPtr<media::WebMediaPlayerDelegate> delegate);
62   ~WebMediaPlayerEfl() override;
63
64   // blink::WebMediaPlayer implementation.
65   void load(LoadType load_type,
66             const blink::WebURL& url,
67             CORSMode cors_mode) override;
68
69   // Playback controls.
70   void play() override;
71   void pause() override;
72   bool supportsSave() const override;
73   void seek(double seconds) override;
74   void setRate(double) override;
75   void setVolume(double) override;
76   blink::WebTimeRanges buffered() const override;
77   blink::WebTimeRanges seekable() const override;
78   void setSinkId(const blink::WebString&, media::WebSetSinkIdCB*) override;
79
80   void paint(blink::WebCanvas*,
81       const blink::WebRect&,
82       unsigned char alpha,
83       SkXfermode::Mode) override;
84
85   // True if the loaded media has a playable video/audio track.
86   bool hasVideo() const override;
87   bool hasAudio() const override;
88
89   // Dimension of the video.
90   blink::WebSize naturalSize() const override;
91
92   // Getters of playback state.
93   bool paused() const override;
94   bool seeking() const override;
95   double duration() const override;
96   double currentTime() const override;
97
98   // Internal states of loading and network.
99   NetworkState networkState() const override;
100   ReadyState readyState() const override;
101
102   bool didLoadingProgress() override;
103
104   bool hasSingleSecurityOrigin() const override;
105   bool didPassCORSAccessCheck() const override;
106
107   double mediaTimeForTimeValue(double timeValue) const override;
108
109   unsigned decodedFrameCount() const override;
110   unsigned droppedFrameCount() const override;
111   unsigned audioDecodedByteCount() const override;
112   unsigned videoDecodedByteCount() const override;
113
114 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
115   virtual MediaKeyException generateKeyRequest(
116       const blink::WebString& key_system,
117       const unsigned char* init_data,
118       unsigned init_data_length);
119
120   virtual MediaKeyException addKey(const blink::WebString& key_system,
121                                    const unsigned char* key,
122                                    unsigned key_length,
123                                    const unsigned char* init_data,
124                                    unsigned init_data_length,
125                                    const blink::WebString& session_id);
126
127   virtual MediaKeyException cancelKeyRequest(
128       const blink::WebString& key_system,
129       const blink::WebString& session_id);
130
131   // TODO(jrummell): Remove this method once Blink updated to use the other
132   // method.
133   virtual void setContentDecryptionModule(
134       blink::WebContentDecryptionModule* cdm);
135   virtual void setContentDecryptionModule(
136       blink::WebContentDecryptionModule* cdm,
137       blink::WebContentDecryptionModuleResult result);
138 #endif
139
140   void SetReadyState(WebMediaPlayer::ReadyState state);
141   void SetNetworkState(WebMediaPlayer::NetworkState state);
142
143   void OnNewFrameAvailable(base::SharedMemoryHandle foreign_memory_handle,
144       uint32 length, base::TimeDelta timestamp);
145
146 #if defined(TIZEN_MULTIMEDIA_PIXMAP_SUPPORT)
147   void OnPlatformSurfaceUpdated(int pixmap_id, base::TimeDelta timestamp);
148 #endif
149
150   void OnMediaDataChange(int format, int height, int width, int media);
151   void OnDurationChange(double duration);
152   void OnTimeUpdate(double current_time);
153   void OnBufferUpdate(
154       std::vector<media::MediaPlayerEfl::TimeRanges> buffer_range);
155   void OnTimeChanged();
156   void OnPauseStateChange(bool state);
157   void OnSeekStateChange(bool state);
158   void OnRequestSeek(double seek_time);
159
160   void OnMediaSourceOpened(blink::WebMediaSource* web_media_source);
161   void OnDemuxerSeekDone();
162
163   void RequestPause();
164
165   // Called when a decoder detects that the key needed to decrypt the stream
166   // is not available.
167   void OnWaitingForDecryptionKey();
168
169  private:
170   void OnNaturalSizeChanged(gfx::Size size);
171   void OnOpacityChanged(bool opaque);
172
173   // Returns the current video frame from |compositor_|. Blocks until the
174   // compositor can return the frame.
175   scoped_refptr<media::VideoFrame> GetCurrentFrameFromCompositor();
176
177   // Called whenever there is new frame to be painted.
178   void FrameReady(const scoped_refptr<media::VideoFrame>& frame);
179
180   blink::WebFrame* frame_;
181
182   blink::WebMediaPlayer::NetworkState network_state_;
183   blink::WebMediaPlayer::ReadyState ready_state_;
184
185   // Message loops for posting tasks on Chrome's main thread. Also used
186   // for DCHECKs so methods calls won't execute in the wrong thread.
187   const scoped_refptr<base::SingleThreadTaskRunner> main_loop_;
188   scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_;
189
190   // Manager for managing this object and for delegating method calls on
191   // Render Thread.
192   content::RendererMediaPlayerManager* manager_;
193
194   blink::WebMediaPlayerClient* client_;
195   blink::WebMediaPlayerEncryptedMediaClient* encrypted_client_;
196
197   scoped_refptr<media::MediaLog> media_log_;
198
199   base::WeakPtr<media::WebMediaPlayerDelegate> delegate_;
200
201   // The compositor layer for displaying the video content when using
202   // composited playback.
203   scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_;
204
205   // Video rendering members.
206   scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
207   media::VideoFrameCompositor* compositor_;
208   media::SkCanvasVideoRenderer skcanvas_video_renderer_;
209
210   base::WeakPtrFactory<WebMediaPlayerEfl> weak_factory_;
211   scoped_ptr<content::MediaSourceDelegateEfl> media_source_delegate_;
212   MediaPlayerHostMsg_Initialize_Type player_type_;
213
214   // Player ID assigned by the |manager_|.
215   int player_id_;
216
217   uint32 gst_video_format_;
218   int gst_width_;
219   int gst_height_;
220
221   bool audio_;
222   bool video_;
223
224   double current_time_;
225   double duration_;
226   bool is_paused_;
227
228   bool is_seeking_;
229   double seek_time_;
230   bool pending_seek_;
231   double pending_seek_time_;
232
233   // Whether the video is known to be opaque or not.
234   bool opaque_;
235
236   gfx::Size natural_size_;
237   blink::WebTimeRanges buffered_;
238   mutable bool did_loading_progress_;
239
240   // Factories for supporting video accelerators. May be null.
241   scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories_;
242 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
243   scoped_ptr<media::EncryptedMediaPlayerSupport> encrypted_media_support_;
244 #endif
245
246   DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerEfl);
247 };
248
249 }  // namespace content
250
251 #endif  // CONTENT_RENDERER_MEDIA_EFL_WEBMEDIAPLAYER_EFL_H_