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_RENDERER_MEDIA_ANDROID_RENDERER_MEDIA_PLAYER_MANAGER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_RENDERER_MEDIA_PLAYER_MANAGER_H_ |
6 #define CONTENT_RENDERER_MEDIA_ANDROID_RENDERER_MEDIA_PLAYER_MANAGER_H_ | 6 #define CONTENT_RENDERER_MEDIA_ANDROID_RENDERER_MEDIA_PLAYER_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "content/common/media/cdm_messages_enums.h" | 14 #include "content/common/media/cdm_messages_enums.h" |
15 #include "content/common/media/media_player_messages_enums_android.h" | 15 #include "content/common/media/media_player_messages_enums_android.h" |
16 #include "content/public/renderer/render_view_observer.h" | 16 #include "content/public/renderer/render_frame_observer.h" |
17 #include "media/base/android/media_player_android.h" | 17 #include "media/base/android/media_player_android.h" |
18 #include "media/base/media_keys.h" | 18 #include "media/base/media_keys.h" |
19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
20 | 20 |
21 namespace blink { | 21 namespace blink { |
22 class WebFrame; | 22 class WebFrame; |
23 } | 23 } |
24 | 24 |
25 namespace gfx { | 25 namespace gfx { |
26 class RectF; | 26 class RectF; |
27 } | 27 } |
28 | 28 |
29 namespace content { | 29 namespace content { |
30 | 30 |
31 class ProxyMediaKeys; | 31 class ProxyMediaKeys; |
32 class WebMediaPlayerAndroid; | 32 class WebMediaPlayerAndroid; |
33 | 33 |
34 // Class for managing all the WebMediaPlayerAndroid objects in the same | 34 // Class for managing all the WebMediaPlayerAndroid objects in the same |
35 // RenderView. | 35 // RenderFrame. |
36 class RendererMediaPlayerManager : public RenderViewObserver { | 36 class RendererMediaPlayerManager : public RenderFrameObserver { |
37 public: | 37 public: |
38 static const int kInvalidCdmId = 0; | 38 static const int kInvalidCdmId = 0; |
39 | 39 |
40 // Constructs a RendererMediaPlayerManager object for the |render_view|. | 40 // Constructs a RendererMediaPlayerManager object for the |render_frame|. |
41 RendererMediaPlayerManager(RenderView* render_view); | 41 RendererMediaPlayerManager(RenderFrame* render_frame); |
42 virtual ~RendererMediaPlayerManager(); | 42 virtual ~RendererMediaPlayerManager(); |
43 | 43 |
44 // RenderViewObserver overrides. | 44 // RenderFrameObserver overrides. |
45 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 45 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
46 | 46 |
47 // Initializes a MediaPlayerAndroid object in browser process. | 47 // Initializes a MediaPlayerAndroid object in browser process. |
48 void Initialize(MediaPlayerHostMsg_Initialize_Type type, | 48 void Initialize(MediaPlayerHostMsg_Initialize_Type type, |
49 int player_id, | 49 int player_id, |
50 const GURL& url, | 50 const GURL& url, |
51 const GURL& first_party_for_cookies, | 51 const GURL& first_party_for_cookies, |
52 int demuxer_client_id); | 52 int demuxer_client_id); |
53 | 53 |
54 // Starts the player. | 54 // Starts the player. |
(...skipping 29 matching lines...) Expand all Loading... |
84 | 84 |
85 // Requests the player with |player_id| to use the CDM with |cdm_id|. | 85 // Requests the player with |player_id| to use the CDM with |cdm_id|. |
86 // Does nothing if |cdm_id| is kInvalidCdmId. | 86 // Does nothing if |cdm_id| is kInvalidCdmId. |
87 // TODO(xhwang): Update this when we implement setCdm(0). | 87 // TODO(xhwang): Update this when we implement setCdm(0). |
88 void SetCdm(int player_id, int cdm_id); | 88 void SetCdm(int player_id, int cdm_id); |
89 | 89 |
90 #if defined(VIDEO_HOLE) | 90 #if defined(VIDEO_HOLE) |
91 // Requests an external surface for out-of-band compositing. | 91 // Requests an external surface for out-of-band compositing. |
92 void RequestExternalSurface(int player_id, const gfx::RectF& geometry); | 92 void RequestExternalSurface(int player_id, const gfx::RectF& geometry); |
93 | 93 |
94 // RenderViewObserver overrides. | 94 // RenderFrameObserver overrides. |
95 virtual void DidCommitCompositorFrame() OVERRIDE; | 95 virtual void DidCommitCompositorFrame() OVERRIDE; |
96 | 96 |
97 // Returns true if a media player should use video-overlay for the embedded | 97 // Returns true if a media player should use video-overlay for the embedded |
98 // encrypted video. | 98 // encrypted video. |
99 bool ShouldUseVideoOverlayForEmbeddedEncryptedVideo(); | 99 bool ShouldUseVideoOverlayForEmbeddedEncryptedVideo(); |
100 #endif // defined(VIDEO_HOLE) | 100 #endif // defined(VIDEO_HOLE) |
101 | 101 |
102 // Encrypted media related methods. | 102 // Encrypted media related methods. |
103 void InitializeCdm(int cdm_id, | 103 void InitializeCdm(int cdm_id, |
104 ProxyMediaKeys* media_keys, | 104 ProxyMediaKeys* media_keys, |
(...skipping 12 matching lines...) Expand all Loading... |
117 // Registers and unregisters a WebMediaPlayerAndroid object. | 117 // Registers and unregisters a WebMediaPlayerAndroid object. |
118 int RegisterMediaPlayer(WebMediaPlayerAndroid* player); | 118 int RegisterMediaPlayer(WebMediaPlayerAndroid* player); |
119 void UnregisterMediaPlayer(int player_id); | 119 void UnregisterMediaPlayer(int player_id); |
120 | 120 |
121 // Registers a ProxyMediaKeys object. There must be a WebMediaPlayerAndroid | 121 // Registers a ProxyMediaKeys object. There must be a WebMediaPlayerAndroid |
122 // object already registered for this id, and it is unregistered when the | 122 // object already registered for this id, and it is unregistered when the |
123 // player is unregistered. For now |cdm_id| is the same as player_id | 123 // player is unregistered. For now |cdm_id| is the same as player_id |
124 // used in other methods. | 124 // used in other methods. |
125 void RegisterMediaKeys(int cdm_id, ProxyMediaKeys* media_keys); | 125 void RegisterMediaKeys(int cdm_id, ProxyMediaKeys* media_keys); |
126 | 126 |
127 // Releases the media resources managed by this object when a video | |
128 // is playing. | |
129 void ReleaseVideoResources(); | |
130 | |
131 // Checks whether a player can enter fullscreen. | 127 // Checks whether a player can enter fullscreen. |
132 bool CanEnterFullscreen(blink::WebFrame* frame); | 128 bool CanEnterFullscreen(blink::WebFrame* frame); |
133 | 129 |
134 // Called when a player entered or exited fullscreen. | 130 // Called when a player entered or exited fullscreen. |
135 void DidEnterFullscreen(blink::WebFrame* frame); | 131 void DidEnterFullscreen(blink::WebFrame* frame); |
136 void DidExitFullscreen(); | 132 void DidExitFullscreen(); |
137 | 133 |
138 // Checks whether the Webframe is in fullscreen. | 134 // Checks whether the Webframe is in fullscreen. |
139 bool IsInFullscreen(blink::WebFrame* frame); | 135 bool IsInFullscreen(blink::WebFrame* frame); |
140 | 136 |
(...skipping 27 matching lines...) Expand all Loading... |
168 void OnTimeUpdate(int player_id, base::TimeDelta current_time); | 164 void OnTimeUpdate(int player_id, base::TimeDelta current_time); |
169 void OnMediaPlayerReleased(int player_id); | 165 void OnMediaPlayerReleased(int player_id); |
170 void OnConnectedToRemoteDevice(int player_id, | 166 void OnConnectedToRemoteDevice(int player_id, |
171 const std::string& remote_playback_message); | 167 const std::string& remote_playback_message); |
172 void OnDisconnectedFromRemoteDevice(int player_id); | 168 void OnDisconnectedFromRemoteDevice(int player_id); |
173 void OnDidExitFullscreen(int player_id); | 169 void OnDidExitFullscreen(int player_id); |
174 void OnDidEnterFullscreen(int player_id); | 170 void OnDidEnterFullscreen(int player_id); |
175 void OnPlayerPlay(int player_id); | 171 void OnPlayerPlay(int player_id); |
176 void OnPlayerPause(int player_id); | 172 void OnPlayerPause(int player_id); |
177 void OnRequestFullscreen(int player_id); | 173 void OnRequestFullscreen(int player_id); |
| 174 void OnPauseVideo(); |
178 void OnSessionCreated(int cdm_id, | 175 void OnSessionCreated(int cdm_id, |
179 uint32 session_id, | 176 uint32 session_id, |
180 const std::string& web_session_id); | 177 const std::string& web_session_id); |
181 void OnSessionMessage(int cdm_id, | 178 void OnSessionMessage(int cdm_id, |
182 uint32 session_id, | 179 uint32 session_id, |
183 const std::vector<uint8>& message, | 180 const std::vector<uint8>& message, |
184 const GURL& destination_url); | 181 const GURL& destination_url); |
185 void OnSessionReady(int cdm_id, uint32 session_id); | 182 void OnSessionReady(int cdm_id, uint32 session_id); |
186 void OnSessionClosed(int cdm_id, uint32 session_id); | 183 void OnSessionClosed(int cdm_id, uint32 session_id); |
187 void OnSessionError(int cdm_id, | 184 void OnSessionError(int cdm_id, |
188 uint32 session_id, | 185 uint32 session_id, |
189 media::MediaKeys::KeyError error_code, | 186 media::MediaKeys::KeyError error_code, |
190 uint32 system_code); | 187 uint32 system_code); |
191 | 188 |
| 189 // Release all video player resources. |
| 190 // If something is in progress the resource will not be freed. It will |
| 191 // only be freed once the tab is destroyed or if the user navigates away |
| 192 // via WebMediaPlayerAndroid::Destroy. |
| 193 void ReleaseVideoResources(); |
| 194 |
192 // Info for all available WebMediaPlayerAndroid on a page; kept so that | 195 // Info for all available WebMediaPlayerAndroid on a page; kept so that |
193 // we can enumerate them to send updates about tab focus and visibility. | 196 // we can enumerate them to send updates about tab focus and visibility. |
194 std::map<int, WebMediaPlayerAndroid*> media_players_; | 197 std::map<int, WebMediaPlayerAndroid*> media_players_; |
195 | 198 |
196 // Info for all available ProxyMediaKeys. There must be at most one | 199 // Info for all available ProxyMediaKeys. There must be at most one |
197 // ProxyMediaKeys for each available WebMediaPlayerAndroid. | 200 // ProxyMediaKeys for each available WebMediaPlayerAndroid. |
198 std::map<int, ProxyMediaKeys*> media_keys_; | 201 std::map<int, ProxyMediaKeys*> media_keys_; |
199 | 202 |
200 int next_media_player_id_; | 203 int next_media_player_id_; |
201 | 204 |
202 // WebFrame of the fullscreen video. | 205 // WebFrame of the fullscreen video. |
203 blink::WebFrame* fullscreen_frame_; | 206 blink::WebFrame* fullscreen_frame_; |
204 | 207 |
205 // WebFrame of pending fullscreen request. | 208 // WebFrame of pending fullscreen request. |
206 blink::WebFrame* pending_fullscreen_frame_; | 209 blink::WebFrame* pending_fullscreen_frame_; |
207 | 210 |
208 DISALLOW_COPY_AND_ASSIGN(RendererMediaPlayerManager); | 211 DISALLOW_COPY_AND_ASSIGN(RendererMediaPlayerManager); |
209 }; | 212 }; |
210 | 213 |
211 } // namespace content | 214 } // namespace content |
212 | 215 |
213 #endif // CONTENT_RENDERER_MEDIA_ANDROID_RENDERER_MEDIA_PLAYER_MANAGER_H_ | 216 #endif // CONTENT_RENDERER_MEDIA_ANDROID_RENDERER_MEDIA_PLAYER_MANAGER_H_ |
OLD | NEW |