OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ |
6 #define CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ | 6 #define CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "content/browser/android/content_video_view.h" | 15 #include "content/browser/android/content_video_view.h" |
16 #include "content/browser/media/android/media_session_observer.h" | |
17 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
18 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
19 #include "media/base/android/media_player_android.h" | 18 #include "media/base/android/media_player_android.h" |
20 #include "media/base/android/media_player_manager.h" | 19 #include "media/base/android/media_player_manager.h" |
21 #include "media/base/android/media_url_interceptor.h" | 20 #include "media/base/android/media_url_interceptor.h" |
22 #include "ui/gfx/geometry/rect_f.h" | 21 #include "ui/gfx/geometry/rect_f.h" |
23 #include "ui/gl/android/scoped_java_surface.h" | 22 #include "ui/gl/android/scoped_java_surface.h" |
24 #include "url/gurl.h" | 23 #include "url/gurl.h" |
25 | 24 |
26 namespace media { | 25 namespace media { |
(...skipping 11 matching lines...) Expand all Loading... |
38 class RenderFrameHost; | 37 class RenderFrameHost; |
39 class WebContents; | 38 class WebContents; |
40 | 39 |
41 // This class manages all the MediaPlayerAndroid objects. | 40 // This class manages all the MediaPlayerAndroid objects. |
42 // It receives control operations from the the render process, and forwards | 41 // It receives control operations from the the render process, and forwards |
43 // them to corresponding MediaPlayerAndroid object. Callbacks from | 42 // them to corresponding MediaPlayerAndroid object. Callbacks from |
44 // MediaPlayerAndroid objects are converted to IPCs and then sent to the render | 43 // MediaPlayerAndroid objects are converted to IPCs and then sent to the render |
45 // process. | 44 // process. |
46 class CONTENT_EXPORT BrowserMediaPlayerManager | 45 class CONTENT_EXPORT BrowserMediaPlayerManager |
47 : public media::MediaPlayerManager, | 46 : public media::MediaPlayerManager, |
48 public MediaSessionObserver, | |
49 public ContentVideoView::Client { | 47 public ContentVideoView::Client { |
50 public: | 48 public: |
51 // Permits embedders to provide an extended version of the class. | 49 // Permits embedders to provide an extended version of the class. |
52 typedef BrowserMediaPlayerManager* (*Factory)(RenderFrameHost*); | 50 typedef BrowserMediaPlayerManager* (*Factory)(RenderFrameHost*); |
53 static void RegisterFactory(Factory factory); | 51 static void RegisterFactory(Factory factory); |
54 | 52 |
55 // Permits embedders to handle custom urls. | 53 // Permits embedders to handle custom urls. |
56 static void RegisterMediaUrlInterceptor( | 54 static void RegisterMediaUrlInterceptor( |
57 media::MediaUrlInterceptor* media_url_interceptor); | 55 media::MediaUrlInterceptor* media_url_interceptor); |
58 | 56 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 media::MediaPlayerAndroid* GetFullscreenPlayer() override; | 104 media::MediaPlayerAndroid* GetFullscreenPlayer() override; |
107 media::MediaPlayerAndroid* GetPlayer(int player_id) override; | 105 media::MediaPlayerAndroid* GetPlayer(int player_id) override; |
108 bool RequestPlay(int player_id, base::TimeDelta duration, | 106 bool RequestPlay(int player_id, base::TimeDelta duration, |
109 bool has_audio) override; | 107 bool has_audio) override; |
110 #if defined(VIDEO_HOLE) | 108 #if defined(VIDEO_HOLE) |
111 void AttachExternalVideoSurface(int player_id, jobject surface); | 109 void AttachExternalVideoSurface(int player_id, jobject surface); |
112 void DetachExternalVideoSurface(int player_id); | 110 void DetachExternalVideoSurface(int player_id); |
113 void OnFrameInfoUpdated(); | 111 void OnFrameInfoUpdated(); |
114 #endif // defined(VIDEO_HOLE) | 112 #endif // defined(VIDEO_HOLE) |
115 | 113 |
116 // MediaSessionObserver overrides. | |
117 void OnSuspend(int player_id) override; | |
118 void OnResume(int player_id) override; | |
119 void OnSetVolumeMultiplier(int player_id, double volume_multiplier) override; | |
120 | |
121 // Message handlers. | 114 // Message handlers. |
122 virtual void OnEnterFullscreen(int player_id); | 115 virtual void OnEnterFullscreen(int player_id); |
123 virtual void OnInitialize( | 116 virtual void OnInitialize( |
124 const MediaPlayerHostMsg_Initialize_Params& media_player_params); | 117 const MediaPlayerHostMsg_Initialize_Params& media_player_params); |
125 virtual void OnStart(int player_id); | 118 virtual void OnStart(int player_id); |
126 virtual void OnSeek(int player_id, const base::TimeDelta& time); | 119 virtual void OnSeek(int player_id, const base::TimeDelta& time); |
127 virtual void OnPause(int player_id, bool is_media_related_action); | 120 virtual void OnPause(int player_id, bool is_media_related_action); |
128 virtual void OnSetVolume(int player_id, double volume); | 121 virtual void OnSetVolume(int player_id, double volume); |
129 virtual void OnSetPoster(int player_id, const GURL& poster); | 122 virtual void OnSetPoster(int player_id, const GURL& poster); |
130 virtual void OnSuspendAndReleaseResources(int player_id); | 123 virtual void OnSuspendAndReleaseResources(int player_id); |
131 virtual void OnDestroyPlayer(int player_id); | 124 virtual void OnDestroyPlayer(int player_id); |
132 virtual void OnRequestRemotePlayback(int player_id); | 125 virtual void OnRequestRemotePlayback(int player_id); |
133 virtual void OnRequestRemotePlaybackControl(int player_id); | 126 virtual void OnRequestRemotePlaybackControl(int player_id); |
134 virtual bool IsPlayingRemotely(int player_id); | 127 virtual bool IsPlayingRemotely(int player_id); |
135 virtual void ReleaseFullscreenPlayer(media::MediaPlayerAndroid* player); | 128 virtual void ReleaseFullscreenPlayer(media::MediaPlayerAndroid* player); |
136 | 129 |
137 #if defined(VIDEO_HOLE) | 130 #if defined(VIDEO_HOLE) |
138 void OnNotifyExternalSurface( | 131 void OnNotifyExternalSurface( |
139 int player_id, bool is_request, const gfx::RectF& rect); | 132 int player_id, bool is_request, const gfx::RectF& rect); |
140 #endif // defined(VIDEO_HOLE) | 133 #endif // defined(VIDEO_HOLE) |
141 | 134 |
142 protected: | 135 protected: |
143 // Clients must use Create() or subclass constructor. | 136 // Clients must use Create() or subclass constructor. |
144 explicit BrowserMediaPlayerManager(RenderFrameHost* render_frame_host); | 137 explicit BrowserMediaPlayerManager(RenderFrameHost* render_frame_host); |
145 | 138 |
146 WebContents* web_contents() const { return web_contents_; } | 139 WebContents* web_contents() const { return web_contents_; } |
147 | 140 |
148 // Adds a given player to the list. | |
149 void AddPlayer(media::MediaPlayerAndroid* player); | |
150 | |
151 // Removes the player with the specified id. | 141 // Removes the player with the specified id. |
152 void DestroyPlayer(int player_id); | 142 void DestroyPlayer(int player_id); |
153 | 143 |
154 // Release resources associated to a player. | 144 // Release resources associated to a player. |
155 virtual void ReleaseResources(int player_id); | 145 virtual void ReleaseResources(int player_id); |
156 | 146 |
157 // Replaces a player with the specified id with a given MediaPlayerAndroid | 147 // Replaces a player with the specified id with a given MediaPlayerAndroid |
158 // object. This will also return the original MediaPlayerAndroid object that | 148 // object. This will also return the original MediaPlayerAndroid object that |
159 // was replaced. | 149 // was replaced. |
160 scoped_ptr<media::MediaPlayerAndroid> SwapPlayer( | 150 scoped_ptr<media::MediaPlayerAndroid> SwapPlayer( |
(...skipping 14 matching lines...) Expand all Loading... |
175 // ReleasePlayer() call below, or when meta data is extracted, or when player | 165 // ReleasePlayer() call below, or when meta data is extracted, or when player |
176 // is stuck in an error. | 166 // is stuck in an error. |
177 virtual void OnDecoderResourcesReleased(int player_id); | 167 virtual void OnDecoderResourcesReleased(int player_id); |
178 | 168 |
179 int RoutingID(); | 169 int RoutingID(); |
180 | 170 |
181 // Helper function to send messages to RenderFrameObserver. | 171 // Helper function to send messages to RenderFrameObserver. |
182 bool Send(IPC::Message* msg); | 172 bool Send(IPC::Message* msg); |
183 | 173 |
184 private: | 174 private: |
| 175 // Adds a given player to the list. |
| 176 void AddPlayer(media::MediaPlayerAndroid* player); |
| 177 |
185 // Constructs a MediaPlayerAndroid object. | 178 // Constructs a MediaPlayerAndroid object. |
186 media::MediaPlayerAndroid* CreateMediaPlayer( | 179 media::MediaPlayerAndroid* CreateMediaPlayer( |
187 const MediaPlayerHostMsg_Initialize_Params& media_player_params, | 180 const MediaPlayerHostMsg_Initialize_Params& media_player_params, |
188 bool hide_url_log, | 181 bool hide_url_log, |
189 BrowserDemuxerAndroid* demuxer); | 182 BrowserDemuxerAndroid* demuxer); |
190 | 183 |
191 // Instructs |player| to release its java player. This will not remove the | 184 // Instructs |player| to release its java player. This will not remove the |
192 // player from |players_|. | 185 // player from |players_|. |
193 void ReleasePlayer(media::MediaPlayerAndroid* player); | 186 void ReleasePlayer(media::MediaPlayerAndroid* player); |
194 | 187 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 int fullscreen_player_id_; | 220 int fullscreen_player_id_; |
228 | 221 |
229 // Whether the fullscreen player has been Release()-d. | 222 // Whether the fullscreen player has been Release()-d. |
230 bool fullscreen_player_is_released_; | 223 bool fullscreen_player_is_released_; |
231 | 224 |
232 WebContents* const web_contents_; | 225 WebContents* const web_contents_; |
233 | 226 |
234 // Object for retrieving resources media players. | 227 // Object for retrieving resources media players. |
235 scoped_ptr<media::MediaResourceGetter> media_resource_getter_; | 228 scoped_ptr<media::MediaResourceGetter> media_resource_getter_; |
236 | 229 |
| 230 // Map of player IDs to delegate IDs for use with |
| 231 // MediaWebContentsObserverAndroid. |
| 232 std::map<int, int> player_id_to_delegate_id_map_; |
| 233 |
237 // NOTE: Weak pointers must be invalidated before all other member variables. | 234 // NOTE: Weak pointers must be invalidated before all other member variables. |
238 base::WeakPtrFactory<BrowserMediaPlayerManager> weak_ptr_factory_; | 235 base::WeakPtrFactory<BrowserMediaPlayerManager> weak_ptr_factory_; |
239 | 236 |
240 DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager); | 237 DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager); |
241 }; | 238 }; |
242 | 239 |
243 } // namespace content | 240 } // namespace content |
244 | 241 |
245 #endif // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ | 242 #endif // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ |
OLD | NEW |