c1d76501bd52b2aaf3f518e7eb6ce7be9cb8df62
[platform/framework/web/crosswalk-tizen.git] /
1 // Copyright 2016 Samsung Electronics. 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_BROWSER_RENDERER_HOST_PEPPER_MEDIA_PLAYER_PEPPER_MEDIA_PLAYER_HOST_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_PEPPER_MEDIA_PLAYER_PEPPER_MEDIA_PLAYER_HOST_H_
7
8 #include <string>
9 #include <memory>
10
11 #include "base/callback.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/weak_ptr.h"
14 #include "cc/layers/video_layer.h"
15 #include "content/browser/renderer_host/pepper/media_player/buffering_listener_private.h"
16 #include "content/browser/renderer_host/pepper/media_player/drm_listener_private.h"
17 #include "content/browser/renderer_host/pepper/media_player/media_events_listener_private.h"
18 #include "content/browser/renderer_host/pepper/media_player/subtitle_listener_private.h"
19 #include "media/blink/video_frame_compositor.h"
20 #include "ppapi/c/pp_rect.h"
21 #include "ppapi/c/samsung/pp_media_player_samsung.h"
22 #include "ppapi/host/resource_host.h"
23 #include "ui/gfx/geometry/size.h"
24 #include "ui/gfx/geometry/rect.h"
25 #include "url/gurl.h"
26
27 namespace base {
28 class ScopedTempDir;
29 }
30
31 namespace content {
32
33 class PepperMediaPlayerPrivate;
34 class BrowserPpapiHost;
35
36 class PepperMediaPlayerHost : public ppapi::host::ResourceHost {
37  public:
38   class SubtitlesDownloader {
39    public:
40     static std::unique_ptr<SubtitlesDownloader> Create(
41         const GURL& url,
42         const base::Callback<base::ScopedTempDir*(void)>& temp_dir_callback,
43         const base::Callback<void(int32_t, const base::FilePath&)>& callback);
44
45     SubtitlesDownloader(
46         const base::Callback<void(int32_t, const base::FilePath&)>& callback);
47     virtual ~SubtitlesDownloader();
48
49    protected:
50     void PostDownloadCompleted(int32_t result, const base::FilePath& file_path);
51
52    private:
53     static void DownloadCompleted(
54         const base::Callback<void(int32_t, const base::FilePath&)>& callback,
55         int32_t result,
56         const base::FilePath& file_path);
57
58     base::Callback<void(int32_t, const base::FilePath&)> callback_;
59
60     DISALLOW_COPY_AND_ASSIGN(SubtitlesDownloader);
61   };
62
63   PepperMediaPlayerHost(BrowserPpapiHost*,
64                         PP_Instance,
65                         PP_Resource,
66                         PP_MediaPlayerMode);
67   virtual ~PepperMediaPlayerHost();
68
69   bool IsMediaPlayerHost() override;
70   void UpdatePluginView(const PP_Rect& plugin_rect, const PP_Rect& clip_rect);
71
72  protected:
73   // ppapi::host::ResourceHost override.
74   int32_t OnResourceMessageReceived(
75       const IPC::Message& msg,
76       ppapi::host::HostMessageContext* context) override;
77
78  private:
79   PP_Rect GetViewportRect();
80   bool UpdateVideoPosition(const base::Callback<void(int32_t)>& callback);
81   int32_t OnSetMediaEventsListener(ppapi::host::HostMessageContext*,
82                                    bool is_set);
83   int32_t OnSetSubtitleListener(ppapi::host::HostMessageContext*, bool is_set);
84   int32_t OnSetBufferingListener(ppapi::host::HostMessageContext*, bool is_set);
85   int32_t OnSetDRMListener(ppapi::host::HostMessageContext*, bool is_set);
86   int32_t OnAttachDataSource(ppapi::host::HostMessageContext*,
87                              PP_Resource data_source);
88   int32_t OnPlay(ppapi::host::HostMessageContext*);
89   int32_t OnPause(ppapi::host::HostMessageContext*);
90   int32_t OnStop(ppapi::host::HostMessageContext*);
91   int32_t OnSeek(ppapi::host::HostMessageContext*, PP_TimeTicks);
92   int32_t OnSetPlaybackRate(ppapi::host::HostMessageContext*, double);
93   int32_t OnGetDuration(ppapi::host::HostMessageContext*);
94   int32_t OnGetCurrentTime(ppapi::host::HostMessageContext*);
95   int32_t OnGetPlayerState(ppapi::host::HostMessageContext*);
96   int32_t OnGetCurrentVideoTrackInfo(ppapi::host::HostMessageContext*);
97   int32_t OnGetVideoTracksList(ppapi::host::HostMessageContext*);
98   int32_t OnGetCurrentAudioTrackInfo(ppapi::host::HostMessageContext*);
99   int32_t OnGetAudioTracksList(ppapi::host::HostMessageContext*);
100   int32_t OnGetCurrentTextTrackInfo(ppapi::host::HostMessageContext*);
101   int32_t OnGetTextTracksList(ppapi::host::HostMessageContext*);
102   int32_t OnSelectTrack(ppapi::host::HostMessageContext*,
103                         PP_ElementaryStream_Type_Samsung,
104                         uint32_t trackIndex);
105   int32_t OnAddExternalSubtitles(ppapi::host::HostMessageContext*,
106                                  const std::string& url,
107                                  const std::string& encoding);
108   int32_t OnSetSubtitlesDelay(ppapi::host::HostMessageContext*, PP_TimeDelta);
109   int32_t OnSetDisplayRect(ppapi::host::HostMessageContext*, const PP_Rect&);
110   int32_t OnSetDRMSpecificData(ppapi::host::HostMessageContext*,
111                                PP_MediaPlayerDRMType,
112                                PP_MediaPlayerDRMOperation,
113                                const std::string& data);
114
115   void OnSubtitlesDownloaded(ppapi::host::ReplyMessageContext reply_context,
116                              const std::string& encoding,
117                              int32_t download_result,
118                              const base::FilePath& path);
119
120   base::ScopedTempDir* GetTempDir();
121
122   std::unique_ptr<SubtitlesDownloader> downloader_;
123   std::unique_ptr<base::ScopedTempDir> temp_dir_;
124
125   // plugin_rect_ is plugin rect relative to the page. When scrolled
126   // out of screen plugin_rect_ x and y may go negative.
127   PP_Rect plugin_rect_;
128   // video_position_ is rect of media player video relative to the plugin_rect_
129   PP_Rect video_position_;
130   // clip_rect is visible part of plugin relative to the plugin_rect_
131   PP_Rect clip_rect_;
132
133   BrowserPpapiHost* browser_ppapi_host_;
134   scoped_refptr<PepperMediaPlayerPrivate> private_;
135   base::WeakPtrFactory<PepperMediaPlayerHost> factory_;
136
137   DISALLOW_COPY_AND_ASSIGN(PepperMediaPlayerHost);
138 };
139
140 }  // namespace content
141
142 #endif  // CONTENT_BROWSER_RENDERER_HOST_PEPPER_MEDIA_PLAYER_PEPPER_MEDIA_PLAYER_HOST_H_