[MM][ME][MSE] Implemented to pass over media_packet to renderer.
[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 "media/blink/webmediaplayer_params.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&, media::WebSetSinkIdCB*) override;
81
82   void paint(blink::WebCanvas*,
83       const blink::WebRect&,
84       unsigned char alpha,
85       SkXfermode::Mode) override;
86
87   // True if the loaded media has a playable video/audio track.
88   bool hasVideo() const override;
89   bool hasAudio() const override;
90
91   // Dimension of the video.
92   blink::WebSize naturalSize() const override;
93
94   // Getters of playback state.
95   bool paused() const override;
96   bool seeking() const override;
97   double duration() const override;
98   double currentTime() const override;
99
100   // Internal states of loading and network.
101   NetworkState networkState() const override;
102   ReadyState readyState() const override;
103
104   bool didLoadingProgress() override;
105
106   bool hasSingleSecurityOrigin() const override;
107   bool didPassCORSAccessCheck() const override;
108
109   double mediaTimeForTimeValue(double timeValue) const override;
110
111   unsigned decodedFrameCount() const override;
112   unsigned droppedFrameCount() const override;
113   unsigned audioDecodedByteCount() const override;
114   unsigned videoDecodedByteCount() const override;
115
116 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
117   virtual MediaKeyException generateKeyRequest(
118       const blink::WebString& key_system,
119       const unsigned char* init_data,
120       unsigned init_data_length);
121
122   virtual MediaKeyException addKey(const blink::WebString& key_system,
123                                    const unsigned char* key,
124                                    unsigned key_length,
125                                    const unsigned char* init_data,
126                                    unsigned init_data_length,
127                                    const blink::WebString& session_id);
128
129   virtual MediaKeyException cancelKeyRequest(
130       const blink::WebString& key_system,
131       const blink::WebString& session_id);
132
133   // TODO(jrummell): Remove this method once Blink updated to use the other
134   // method.
135   virtual void setContentDecryptionModule(
136       blink::WebContentDecryptionModule* cdm);
137   virtual void setContentDecryptionModule(
138       blink::WebContentDecryptionModule* cdm,
139       blink::WebContentDecryptionModuleResult result);
140 #endif
141
142   void SetReadyState(WebMediaPlayer::ReadyState state);
143   void SetNetworkState(WebMediaPlayer::NetworkState state);
144
145   void OnNewFrameAvailable(base::SharedMemoryHandle foreign_memory_handle,
146                            uint32 length, base::TimeDelta timestamp);
147
148 #if defined(TIZEN_TBM_SUPPORT)
149   void OnNewTbmBufferAvailable(gfx::TbmBufferHandle tbm_handle,
150                                base::TimeDelta timestamp);
151 #endif
152
153 #if defined(TIZEN_MULTIMEDIA_PIXMAP_SUPPORT)
154   void OnPlatformSurfaceUpdated(int pixmap_id, base::TimeDelta timestamp);
155 #endif
156
157   void OnMediaDataChange(int format, int height, int width, 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   uint32 gst_video_format_;
231   int gst_width_;
232   int gst_height_;
233
234   bool audio_;
235   bool video_;
236
237   double current_time_;
238   double duration_;
239   bool is_paused_;
240
241   bool is_seeking_;
242   double seek_time_;
243   bool pending_seek_;
244   double pending_seek_time_;
245
246   // Whether the video is known to be opaque or not.
247   bool opaque_;
248
249   gfx::Size natural_size_;
250   blink::WebTimeRanges buffered_;
251   mutable bool did_loading_progress_;
252
253   // Factories for supporting video accelerators. May be null.
254   scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories_;
255 #if defined(TIZEN_MULTIMEDIA_EME_SUPPORT)
256   scoped_ptr<media::EncryptedMediaPlayerSupport> encrypted_media_support_;
257 #endif
258
259   DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerEfl);
260 };
261
262 }  // namespace content
263
264 #endif  // CONTENT_RENDERER_MEDIA_EFL_WEBMEDIAPLAYER_EFL_H_