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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 // Helper function to send messages to RenderFrameObserver. | 155 // Helper function to send messages to RenderFrameObserver. |
154 bool Send(IPC::Message* msg); | 156 bool Send(IPC::Message* msg); |
155 | 157 |
156 private: | 158 private: |
157 // Constructs a MediaPlayerAndroid object. | 159 // Constructs a MediaPlayerAndroid object. |
158 media::MediaPlayerAndroid* CreateMediaPlayer( | 160 media::MediaPlayerAndroid* CreateMediaPlayer( |
159 const MediaPlayerHostMsg_Initialize_Params& media_player_params, | 161 const MediaPlayerHostMsg_Initialize_Params& media_player_params, |
160 bool hide_url_log, | 162 bool hide_url_log, |
161 BrowserDemuxerAndroid* demuxer); | 163 BrowserDemuxerAndroid* demuxer); |
162 | 164 |
163 // MediaPlayerAndroid must call this before it is going to decode | 165 // Called to request decoder resources. Returns true if the request is |
164 // media streams. This helps the manager object maintain an array | 166 // permitted, or false otherwise. The manager object maintains an array |
165 // of active MediaPlayerAndroid objects and release the resources | 167 // of active MediaPlayerAndroid objects and releases the inactive resources |
166 // when needed. Currently we only count video resources as they are | 168 // when needed. If |temporary| is true, the request is short lived |
167 // constrained by hardware and memory limits. | 169 // and it will not be cleaned up when handling other requests. |
168 virtual void OnMediaResourcesRequested(int player_id); | 170 // On the contrary, requests with false |temporary| value are subject to |
171 // clean up if their players are idle. | |
172 virtual bool RequestDecoderResources(int player_id, bool temporary); | |
ctserng
2015/09/30 17:41:11
Can we make RequestDecoderResources protected so t
qinmin
2015/09/30 19:27:42
Done.
| |
169 | 173 |
170 // Called when a player releases all decoding resources. | 174 // MediaPlayerAndroid must call this to inform the manager that it has |
171 void ReleaseMediaResources(int player_id); | 175 // released the decoder resources. This can be triggered by the |
176 // ReleasePlayer() call below, or when meta data is extracted, or when player | |
177 // is stuck in an error. | |
178 virtual void OnDecorderResourcesReleased(int player_id); | |
ctserng
2015/09/30 17:41:10
/s/Decorder/Decoder
Also can we make OnDecoderRes
qinmin
2015/09/30 19:27:42
Done.
| |
172 | 179 |
173 // Releases the player. However, don't remove it from |players_|. | 180 // Instructs |player| to release its java player. This will not remove the |
181 // player from |players_|. | |
174 void ReleasePlayer(media::MediaPlayerAndroid* player); | 182 void ReleasePlayer(media::MediaPlayerAndroid* player); |
175 | 183 |
184 // Called when user approves media playback after being throttled. | |
185 void OnPlaybackPermissionGranted(int player_id, bool granted); | |
186 | |
187 // Helper method to start playback. | |
188 void StartInternal(int player_id); | |
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 |