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> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/callback.h" | 11 #include "base/callback.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
12 #include "base/time/time.h" | 14 #include "base/time/time.h" |
13 #include "content/browser/android/content_video_view.h" | 15 #include "content/browser/android/content_video_view.h" |
14 #include "content/browser/media/android/media_session_observer.h" | 16 #include "content/browser/media/android/media_session_observer.h" |
15 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
16 #include "content/common/media/media_player_messages_enums_android.h" | 18 #include "content/common/media/media_player_messages_enums_android.h" |
17 #include "content/public/browser/android/content_view_core.h" | 19 #include "content/public/browser/android/content_view_core.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // Removes the player with the specified id. | 143 // Removes the player with the specified id. |
142 void RemovePlayer(int player_id); | 144 void RemovePlayer(int player_id); |
143 | 145 |
144 // Replaces a player with the specified id with a given MediaPlayerAndroid | 146 // Replaces a player with the specified id with a given MediaPlayerAndroid |
145 // object. This will also return the original MediaPlayerAndroid object that | 147 // object. This will also return the original MediaPlayerAndroid object that |
146 // was replaced. | 148 // was replaced. |
147 scoped_ptr<media::MediaPlayerAndroid> SwapPlayer( | 149 scoped_ptr<media::MediaPlayerAndroid> SwapPlayer( |
148 int player_id, | 150 int player_id, |
149 media::MediaPlayerAndroid* player); | 151 media::MediaPlayerAndroid* player); |
150 | 152 |
| 153 // Called to request decoder resources. Returns true if the request is |
| 154 // permitted, or false otherwise. The manager object maintains a list |
| 155 // of active MediaPlayerAndroid objects and releases the inactive resources |
| 156 // when needed. If |temporary| is true, the request is short lived |
| 157 // and it will not be cleaned up when handling other requests. |
| 158 // On the contrary, requests with false |temporary| value are subject to |
| 159 // clean up if their players are idle. |
| 160 virtual bool RequestDecoderResources(int player_id, bool temporary); |
| 161 |
| 162 // MediaPlayerAndroid must call this to inform the manager that it has |
| 163 // released the decoder resources. This can be triggered by the |
| 164 // ReleasePlayer() call below, or when meta data is extracted, or when player |
| 165 // is stuck in an error. |
| 166 virtual void OnDecoderResourcesReleased(int player_id); |
| 167 |
151 int RoutingID(); | 168 int RoutingID(); |
152 | 169 |
153 // Helper function to send messages to RenderFrameObserver. | 170 // Helper function to send messages to RenderFrameObserver. |
154 bool Send(IPC::Message* msg); | 171 bool Send(IPC::Message* msg); |
155 | 172 |
156 private: | 173 private: |
157 // Constructs a MediaPlayerAndroid object. | 174 // Constructs a MediaPlayerAndroid object. |
158 media::MediaPlayerAndroid* CreateMediaPlayer( | 175 media::MediaPlayerAndroid* CreateMediaPlayer( |
159 const MediaPlayerHostMsg_Initialize_Params& media_player_params, | 176 const MediaPlayerHostMsg_Initialize_Params& media_player_params, |
160 bool hide_url_log, | 177 bool hide_url_log, |
161 BrowserDemuxerAndroid* demuxer); | 178 BrowserDemuxerAndroid* demuxer); |
162 | 179 |
163 // MediaPlayerAndroid must call this before it is going to decode | 180 // Instructs |player| to release its java player. This will not remove the |
164 // media streams. This helps the manager object maintain an array | 181 // player from |players_|. |
165 // of active MediaPlayerAndroid objects and release the resources | 182 void ReleasePlayer(media::MediaPlayerAndroid* player); |
166 // when needed. Currently we only count video resources as they are | |
167 // constrained by hardware and memory limits. | |
168 virtual void OnMediaResourcesRequested(int player_id); | |
169 | 183 |
170 // Called when a player releases all decoding resources. | 184 // Called when user approves media playback after being throttled. |
171 void ReleaseMediaResources(int player_id); | 185 void OnPlaybackPermissionGranted(int player_id, bool granted); |
172 | 186 |
173 // Releases the player. However, don't remove it from |players_|. | 187 // Helper method to start playback. |
174 void ReleasePlayer(media::MediaPlayerAndroid* player); | 188 void StartInternal(int player_id); |
175 | 189 |
176 #if defined(VIDEO_HOLE) | 190 #if defined(VIDEO_HOLE) |
177 void ReleasePlayerOfExternalVideoSurfaceIfNeeded(int future_player); | 191 void ReleasePlayerOfExternalVideoSurfaceIfNeeded(int future_player); |
178 void OnRequestExternalSurface(int player_id, const gfx::RectF& rect); | 192 void OnRequestExternalSurface(int player_id, const gfx::RectF& rect); |
| 193 void ReleaseExternalSurface(int player_id); |
179 #endif // defined(VIDEO_HOLE) | 194 #endif // defined(VIDEO_HOLE) |
180 | 195 |
181 RenderFrameHost* const render_frame_host_; | 196 RenderFrameHost* const render_frame_host_; |
182 | 197 |
183 // An array of managed players. | 198 // An array of managed players. |
184 ScopedVector<media::MediaPlayerAndroid> players_; | 199 ScopedVector<media::MediaPlayerAndroid> players_; |
185 | 200 |
| 201 typedef std::map<int, bool> ActivePlayerMap; |
| 202 // Players that have requested decoding resources. Even though resource is |
| 203 // requested, a player may be in a paused or error state and the manager |
| 204 // will release its resources later. |
| 205 ActivePlayerMap active_players_; |
| 206 |
186 // The fullscreen video view object or NULL if video is not played in | 207 // The fullscreen video view object or NULL if video is not played in |
187 // fullscreen. | 208 // fullscreen. |
188 scoped_ptr<ContentVideoView> video_view_; | 209 scoped_ptr<ContentVideoView> video_view_; |
189 | 210 |
190 #if defined(VIDEO_HOLE) | 211 #if defined(VIDEO_HOLE) |
191 scoped_ptr<ExternalVideoSurfaceContainer> external_video_surface_container_; | 212 scoped_ptr<ExternalVideoSurfaceContainer> external_video_surface_container_; |
192 #endif | 213 #endif |
193 | 214 |
194 // Player ID of the fullscreen media player. | 215 // Player ID of the fullscreen media player. |
195 int fullscreen_player_id_; | 216 int fullscreen_player_id_; |
196 | 217 |
197 // Whether the fullscreen player has been Release()-d. | 218 // Whether the fullscreen player has been Release()-d. |
198 bool fullscreen_player_is_released_; | 219 bool fullscreen_player_is_released_; |
199 | 220 |
200 WebContents* const web_contents_; | 221 WebContents* const web_contents_; |
201 | 222 |
202 // Object for retrieving resources media players. | 223 // Object for retrieving resources media players. |
203 scoped_ptr<media::MediaResourceGetter> media_resource_getter_; | 224 scoped_ptr<media::MediaResourceGetter> media_resource_getter_; |
204 | 225 |
205 // NOTE: Weak pointers must be invalidated before all other member variables. | 226 // NOTE: Weak pointers must be invalidated before all other member variables. |
206 base::WeakPtrFactory<BrowserMediaPlayerManager> weak_ptr_factory_; | 227 base::WeakPtrFactory<BrowserMediaPlayerManager> weak_ptr_factory_; |
207 | 228 |
208 DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager); | 229 DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager); |
209 }; | 230 }; |
210 | 231 |
211 } // namespace content | 232 } // namespace content |
212 | 233 |
213 #endif // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ | 234 #endif // CONTENT_BROWSER_MEDIA_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ |
OLD | NEW |