fixup! [M44_2403] Chromium upversion to m44_2403 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/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"
19
20 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
21 #include "media/blink/encrypted_media_player_support.h"
22 #endif
23
24 namespace blink {
25 class WebFrame;
26 class WebMediaPlayerClient;
27 }
28
29 namespace cc_blink {
30 class WebLayerImpl;
31 }
32
33 namespace media {
34 class GpuVideoAcceleratorFactories;
35 class MediaLog;
36 class MediaPlayerEfl;
37 class WebMediaPlayerDelegate;
38 }
39
40 namespace content {
41 class RendererMediaPlayerManager;
42
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
46 // player.
47 class WebMediaPlayerEfl
48     : public blink::WebMediaPlayer,
49       public base::SupportsWeakPtr<WebMediaPlayerEfl> {
50  public:
51   // Construct a WebMediaPlayerEfl object. This class communicates
52   // with the WebMediaPlayerEfl object in the browser process through
53   // |proxy|.
54   WebMediaPlayerEfl(
55       RendererMediaPlayerManager* manager,
56       blink::WebFrame* frame,
57       blink::WebMediaPlayerClient* client,
58       base::WeakPtr<media::WebMediaPlayerDelegate> delegate);
59   ~WebMediaPlayerEfl() override;
60
61   // blink::WebMediaPlayer implementation.
62   void load(LoadType load_type,
63             const blink::WebURL& url,
64             CORSMode cors_mode) override;
65
66   // Playback controls.
67   void play() 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;
75
76   void paint(blink::WebCanvas*,
77       const blink::WebRect&,
78       unsigned char alpha,
79       SkXfermode::Mode) override;
80
81   // True if the loaded media has a playable video/audio track.
82   bool hasVideo() const override;
83   bool hasAudio() const override;
84
85   // Dimension of the video.
86   blink::WebSize naturalSize() const override;
87
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;
93
94   // Internal states of loading and network.
95   NetworkState networkState() const override;
96   ReadyState readyState() const override;
97
98   bool didLoadingProgress() override;
99
100   bool hasSingleSecurityOrigin() const override;
101   bool didPassCORSAccessCheck() const override;
102
103   double mediaTimeForTimeValue(double timeValue) const override;
104
105   unsigned decodedFrameCount() const override;
106   unsigned droppedFrameCount() const override;
107   unsigned audioDecodedByteCount() const override;
108   unsigned videoDecodedByteCount() const override;
109
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);
115
116   virtual MediaKeyException addKey(const blink::WebString& key_system,
117                                    const unsigned char* key,
118                                    unsigned key_length,
119                                    const unsigned char* init_data,
120                                    unsigned init_data_length,
121                                    const blink::WebString& session_id);
122
123   virtual MediaKeyException cancelKeyRequest(
124       const blink::WebString& key_system,
125       const blink::WebString& session_id);
126
127   // TODO(jrummell): Remove this method once Blink updated to use the other
128   // method.
129   virtual void setContentDecryptionModule(
130       blink::WebContentDecryptionModule* cdm);
131   virtual void setContentDecryptionModule(
132       blink::WebContentDecryptionModule* cdm,
133       blink::WebContentDecryptionModuleResult result);
134 #endif
135
136   void SetReadyState(WebMediaPlayer::ReadyState state);
137   void SetNetworkState(WebMediaPlayer::NetworkState state);
138
139   void OnNewFrameAvailable(base::SharedMemoryHandle foreign_memory_handle,
140       uint32 length, base::TimeDelta timestamp);
141
142 #if defined(TIZEN_MULTIMEDIA_PIXMAP_SUPPORT)
143   void OnPlatformSurfaceUpdated(int pixmap_id, base::TimeDelta timestamp);
144 #endif
145
146   void OnMediaDataChange(int format, int height, int width, int media);
147   void OnDurationChange(double duration);
148   void OnTimeUpdate(double current_time);
149   void OnBufferUpdate(
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);
155
156   void OnMediaSourceOpened(blink::WebMediaSource* web_media_source);
157   void OnDemuxerSeekDone();
158
159   void RequestPause();
160
161   // Called when a decoder detects that the key needed to decrypt the stream
162   // is not available.
163   void OnWaitingForDecryptionKey();
164
165  private:
166   void OnNaturalSizeChanged(gfx::Size size);
167   void OnOpacityChanged(bool opaque);
168
169   // Returns the current video frame from |compositor_|. Blocks until the
170   // compositor can return the frame.
171   scoped_refptr<media::VideoFrame> GetCurrentFrameFromCompositor();
172
173   // Called whenever there is new frame to be painted.
174   void FrameReady(const scoped_refptr<media::VideoFrame>& frame);
175
176   blink::WebFrame* frame_;
177
178   blink::WebMediaPlayer::NetworkState network_state_;
179   blink::WebMediaPlayer::ReadyState ready_state_;
180
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_;
185
186   // Manager for managing this object and for delegating method calls on
187   // Render Thread.
188   content::RendererMediaPlayerManager* manager_;
189
190   blink::WebMediaPlayerClient* client_;
191
192   scoped_refptr<media::MediaLog> media_log_;
193
194   base::WeakPtr<media::WebMediaPlayerDelegate> delegate_;
195
196   // The compositor layer for displaying the video content when using
197   // composited playback.
198   scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_;
199
200   // Video rendering members.
201   scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
202   media::VideoFrameCompositor* compositor_;
203   media::SkCanvasVideoRenderer skcanvas_video_renderer_;
204
205   base::WeakPtrFactory<WebMediaPlayerEfl> weak_factory_;
206   scoped_ptr<content::MediaSourceDelegateEfl> media_source_delegate_;
207   MediaPlayerHostMsg_Initialize_Type player_type_;
208
209   // Player ID assigned by the |manager_|.
210   int player_id_;
211
212   uint32 gst_video_format_;
213   int gst_width_;
214   int gst_height_;
215
216   bool audio_;
217   bool video_;
218
219   double current_time_;
220   double duration_;
221   bool is_paused_;
222
223   bool is_seeking_;
224   double seek_time_;
225   bool pending_seek_;
226   double pending_seek_time_;
227
228   // Whether the video is known to be opaque or not.
229   bool opaque_;
230
231   gfx::Size natural_size_;
232   blink::WebTimeRanges buffered_;
233   mutable bool did_loading_progress_;
234
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_;
239 #endif
240
241   DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerEfl);
242 };
243
244 }  // namespace content
245
246 #endif  // CONTENT_RENDERER_MEDIA_EFL_WEBMEDIAPLAYER_EFL_H_