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.
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_
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"
33 class PepperMediaPlayerPrivate;
34 class BrowserPpapiHost;
36 class PepperMediaPlayerHost : public ppapi::host::ResourceHost {
38 class SubtitlesDownloader {
40 static std::unique_ptr<SubtitlesDownloader> Create(
42 const base::Callback<base::ScopedTempDir*(void)>& temp_dir_callback,
43 const base::Callback<void(int32_t, const base::FilePath&)>& callback);
46 const base::Callback<void(int32_t, const base::FilePath&)>& callback);
47 virtual ~SubtitlesDownloader();
50 void PostDownloadCompleted(int32_t result, const base::FilePath& file_path);
53 static void DownloadCompleted(
54 const base::Callback<void(int32_t, const base::FilePath&)>& callback,
56 const base::FilePath& file_path);
58 base::Callback<void(int32_t, const base::FilePath&)> callback_;
60 DISALLOW_COPY_AND_ASSIGN(SubtitlesDownloader);
63 PepperMediaPlayerHost(BrowserPpapiHost*,
67 virtual ~PepperMediaPlayerHost();
69 bool IsMediaPlayerHost() override;
70 void UpdatePluginView(const PP_Rect& plugin_rect, const PP_Rect& clip_rect);
73 // ppapi::host::ResourceHost override.
74 int32_t OnResourceMessageReceived(
75 const IPC::Message& msg,
76 ppapi::host::HostMessageContext* context) override;
79 PP_Rect GetViewportRect();
80 bool UpdateVideoPosition(const base::Callback<void(int32_t)>& callback);
81 int32_t OnSetMediaEventsListener(ppapi::host::HostMessageContext*,
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);
115 void OnSubtitlesDownloaded(ppapi::host::ReplyMessageContext reply_context,
116 const std::string& encoding,
117 int32_t download_result,
118 const base::FilePath& path);
120 base::ScopedTempDir* GetTempDir();
122 std::unique_ptr<SubtitlesDownloader> downloader_;
123 std::unique_ptr<base::ScopedTempDir> temp_dir_;
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_
133 BrowserPpapiHost* browser_ppapi_host_;
134 scoped_refptr<PepperMediaPlayerPrivate> private_;
135 base::WeakPtrFactory<PepperMediaPlayerHost> factory_;
137 DISALLOW_COPY_AND_ASSIGN(PepperMediaPlayerHost);
140 } // namespace content
142 #endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_MEDIA_PLAYER_PEPPER_MEDIA_PLAYER_HOST_H_