| 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> | |
| 11 | 10 |
| 12 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 13 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 14 #include "content/common/media/cdm_messages_enums.h" | |
| 15 #include "content/common/media/media_player_messages_enums_android.h" | 13 #include "content/common/media/media_player_messages_enums_android.h" |
| 16 #include "content/public/renderer/render_frame_observer.h" | 14 #include "content/public/renderer/render_frame_observer.h" |
| 17 #include "media/base/android/media_player_android.h" | 15 #include "media/base/android/media_player_android.h" |
| 18 #include "media/base/media_keys.h" | |
| 19 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 20 | 17 |
| 21 namespace blink { | 18 namespace blink { |
| 22 class WebFrame; | 19 class WebFrame; |
| 23 } | 20 } |
| 24 | 21 |
| 25 namespace gfx { | 22 namespace gfx { |
| 26 class RectF; | 23 class RectF; |
| 27 } | 24 } |
| 28 | 25 |
| 29 namespace content { | 26 namespace content { |
| 30 | 27 |
| 31 class ProxyMediaKeys; | |
| 32 class WebMediaPlayerAndroid; | 28 class WebMediaPlayerAndroid; |
| 33 | 29 |
| 34 // Class for managing all the WebMediaPlayerAndroid objects in the same | 30 // Class for managing all the WebMediaPlayerAndroid objects in the same |
| 35 // RenderFrame. | 31 // RenderFrame. |
| 36 class RendererMediaPlayerManager : public RenderFrameObserver { | 32 class RendererMediaPlayerManager : public RenderFrameObserver { |
| 37 public: | 33 public: |
| 38 static const int kInvalidCdmId = 0; | |
| 39 | |
| 40 // Constructs a RendererMediaPlayerManager object for the |render_frame|. | 34 // Constructs a RendererMediaPlayerManager object for the |render_frame|. |
| 41 RendererMediaPlayerManager(RenderFrame* render_frame); | 35 explicit RendererMediaPlayerManager(RenderFrame* render_frame); |
| 42 virtual ~RendererMediaPlayerManager(); | 36 virtual ~RendererMediaPlayerManager(); |
| 43 | 37 |
| 44 // RenderFrameObserver overrides. | 38 // RenderFrameObserver overrides. |
| 45 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 39 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 46 | 40 |
| 47 // Initializes a MediaPlayerAndroid object in browser process. | 41 // Initializes a MediaPlayerAndroid object in browser process. |
| 48 void Initialize(MediaPlayerHostMsg_Initialize_Type type, | 42 void Initialize(MediaPlayerHostMsg_Initialize_Type type, |
| 49 int player_id, | 43 int player_id, |
| 50 const GURL& url, | 44 const GURL& url, |
| 51 const GURL& first_party_for_cookies, | 45 const GURL& first_party_for_cookies, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 void RequestExternalSurface(int player_id, const gfx::RectF& geometry); | 86 void RequestExternalSurface(int player_id, const gfx::RectF& geometry); |
| 93 | 87 |
| 94 // RenderFrameObserver overrides. | 88 // RenderFrameObserver overrides. |
| 95 virtual void DidCommitCompositorFrame() OVERRIDE; | 89 virtual void DidCommitCompositorFrame() OVERRIDE; |
| 96 | 90 |
| 97 // Returns true if a media player should use video-overlay for the embedded | 91 // Returns true if a media player should use video-overlay for the embedded |
| 98 // encrypted video. | 92 // encrypted video. |
| 99 bool ShouldUseVideoOverlayForEmbeddedEncryptedVideo(); | 93 bool ShouldUseVideoOverlayForEmbeddedEncryptedVideo(); |
| 100 #endif // defined(VIDEO_HOLE) | 94 #endif // defined(VIDEO_HOLE) |
| 101 | 95 |
| 102 // Encrypted media related methods. | |
| 103 void InitializeCdm(int cdm_id, | |
| 104 ProxyMediaKeys* media_keys, | |
| 105 const std::string& key_system, | |
| 106 const GURL& security_origin); | |
| 107 void CreateSession(int cdm_id, | |
| 108 uint32 session_id, | |
| 109 CdmHostMsg_CreateSession_ContentType conent_type, | |
| 110 const std::vector<uint8>& init_data); | |
| 111 void UpdateSession(int cdm_id, | |
| 112 uint32 session_id, | |
| 113 const std::vector<uint8>& response); | |
| 114 void ReleaseSession(int cdm_id, uint32 session_id); | |
| 115 void DestroyCdm(int cdm_id); | |
| 116 | |
| 117 // Registers and unregisters a WebMediaPlayerAndroid object. | 96 // Registers and unregisters a WebMediaPlayerAndroid object. |
| 118 int RegisterMediaPlayer(WebMediaPlayerAndroid* player); | 97 int RegisterMediaPlayer(WebMediaPlayerAndroid* player); |
| 119 void UnregisterMediaPlayer(int player_id); | 98 void UnregisterMediaPlayer(int player_id); |
| 120 | 99 |
| 121 // Registers a ProxyMediaKeys object. There must be a WebMediaPlayerAndroid | |
| 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 | |
| 124 // used in other methods. | |
| 125 void RegisterMediaKeys(int cdm_id, ProxyMediaKeys* media_keys); | |
| 126 | |
| 127 // Checks whether a player can enter fullscreen. | 100 // Checks whether a player can enter fullscreen. |
| 128 bool CanEnterFullscreen(blink::WebFrame* frame); | 101 bool CanEnterFullscreen(blink::WebFrame* frame); |
| 129 | 102 |
| 130 // Called when a player entered or exited fullscreen. | 103 // Called when a player entered or exited fullscreen. |
| 131 void DidEnterFullscreen(blink::WebFrame* frame); | 104 void DidEnterFullscreen(blink::WebFrame* frame); |
| 132 void DidExitFullscreen(); | 105 void DidExitFullscreen(); |
| 133 | 106 |
| 134 // Checks whether the Webframe is in fullscreen. | 107 // Checks whether the Webframe is in fullscreen. |
| 135 bool IsInFullscreen(blink::WebFrame* frame); | 108 bool IsInFullscreen(blink::WebFrame* frame); |
| 136 | 109 |
| 137 // True if a newly created media player should enter fullscreen. | 110 // True if a newly created media player should enter fullscreen. |
| 138 bool ShouldEnterFullscreen(blink::WebFrame* frame); | 111 bool ShouldEnterFullscreen(blink::WebFrame* frame); |
| 139 | 112 |
| 140 // Gets the pointer to WebMediaPlayerAndroid given the |player_id|. | 113 // Gets the pointer to WebMediaPlayerAndroid given the |player_id|. |
| 141 WebMediaPlayerAndroid* GetMediaPlayer(int player_id); | 114 WebMediaPlayerAndroid* GetMediaPlayer(int player_id); |
| 142 | 115 |
| 143 // Gets the pointer to ProxyMediaKeys given the |cdm_id|. | |
| 144 ProxyMediaKeys* GetMediaKeys(int cdm_id); | |
| 145 | |
| 146 #if defined(VIDEO_HOLE) | 116 #if defined(VIDEO_HOLE) |
| 147 // Gets the list of media players with video geometry changes. | 117 // Gets the list of media players with video geometry changes. |
| 148 void RetrieveGeometryChanges(std::map<int, gfx::RectF>* changes); | 118 void RetrieveGeometryChanges(std::map<int, gfx::RectF>* changes); |
| 149 #endif // defined(VIDEO_HOLE) | 119 #endif // defined(VIDEO_HOLE) |
| 150 | 120 |
| 151 private: | 121 private: |
| 152 // Message handlers. | 122 // Message handlers. |
| 153 void OnMediaMetadataChanged(int player_id, | 123 void OnMediaMetadataChanged(int player_id, |
| 154 base::TimeDelta duration, | 124 base::TimeDelta duration, |
| 155 int width, | 125 int width, |
| 156 int height, | 126 int height, |
| 157 bool success); | 127 bool success); |
| 158 void OnMediaPlaybackCompleted(int player_id); | 128 void OnMediaPlaybackCompleted(int player_id); |
| 159 void OnMediaBufferingUpdate(int player_id, int percent); | 129 void OnMediaBufferingUpdate(int player_id, int percent); |
| 160 void OnSeekRequest(int player_id, const base::TimeDelta& time_to_seek); | 130 void OnSeekRequest(int player_id, const base::TimeDelta& time_to_seek); |
| 161 void OnSeekCompleted(int player_id, const base::TimeDelta& current_time); | 131 void OnSeekCompleted(int player_id, const base::TimeDelta& current_time); |
| 162 void OnMediaError(int player_id, int error); | 132 void OnMediaError(int player_id, int error); |
| 163 void OnVideoSizeChanged(int player_id, int width, int height); | 133 void OnVideoSizeChanged(int player_id, int width, int height); |
| 164 void OnTimeUpdate(int player_id, base::TimeDelta current_time); | 134 void OnTimeUpdate(int player_id, base::TimeDelta current_time); |
| 165 void OnMediaPlayerReleased(int player_id); | 135 void OnMediaPlayerReleased(int player_id); |
| 166 void OnConnectedToRemoteDevice(int player_id, | 136 void OnConnectedToRemoteDevice(int player_id, |
| 167 const std::string& remote_playback_message); | 137 const std::string& remote_playback_message); |
| 168 void OnDisconnectedFromRemoteDevice(int player_id); | 138 void OnDisconnectedFromRemoteDevice(int player_id); |
| 169 void OnDidExitFullscreen(int player_id); | 139 void OnDidExitFullscreen(int player_id); |
| 170 void OnDidEnterFullscreen(int player_id); | 140 void OnDidEnterFullscreen(int player_id); |
| 171 void OnPlayerPlay(int player_id); | 141 void OnPlayerPlay(int player_id); |
| 172 void OnPlayerPause(int player_id); | 142 void OnPlayerPause(int player_id); |
| 173 void OnRequestFullscreen(int player_id); | 143 void OnRequestFullscreen(int player_id); |
| 174 void OnPauseVideo(); | 144 void OnPauseVideo(); |
| 175 void OnSessionCreated(int cdm_id, | |
| 176 uint32 session_id, | |
| 177 const std::string& web_session_id); | |
| 178 void OnSessionMessage(int cdm_id, | |
| 179 uint32 session_id, | |
| 180 const std::vector<uint8>& message, | |
| 181 const GURL& destination_url); | |
| 182 void OnSessionReady(int cdm_id, uint32 session_id); | |
| 183 void OnSessionClosed(int cdm_id, uint32 session_id); | |
| 184 void OnSessionError(int cdm_id, | |
| 185 uint32 session_id, | |
| 186 media::MediaKeys::KeyError error_code, | |
| 187 uint32 system_code); | |
| 188 | 145 |
| 189 // Release all video player resources. | 146 // Release all video player resources. |
| 190 // If something is in progress the resource will not be freed. It will | 147 // 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 | 148 // only be freed once the tab is destroyed or if the user navigates away |
| 192 // via WebMediaPlayerAndroid::Destroy. | 149 // via WebMediaPlayerAndroid::Destroy. |
| 193 void ReleaseVideoResources(); | 150 void ReleaseVideoResources(); |
| 194 | 151 |
| 195 // Info for all available WebMediaPlayerAndroid on a page; kept so that | 152 // Info for all available WebMediaPlayerAndroid on a page; kept so that |
| 196 // we can enumerate them to send updates about tab focus and visibility. | 153 // we can enumerate them to send updates about tab focus and visibility. |
| 197 std::map<int, WebMediaPlayerAndroid*> media_players_; | 154 std::map<int, WebMediaPlayerAndroid*> media_players_; |
| 198 | 155 |
| 199 // Info for all available ProxyMediaKeys. There must be at most one | |
| 200 // ProxyMediaKeys for each available WebMediaPlayerAndroid. | |
| 201 std::map<int, ProxyMediaKeys*> media_keys_; | |
| 202 | |
| 203 int next_media_player_id_; | 156 int next_media_player_id_; |
| 204 | 157 |
| 205 // WebFrame of the fullscreen video. | 158 // WebFrame of the fullscreen video. |
| 206 blink::WebFrame* fullscreen_frame_; | 159 blink::WebFrame* fullscreen_frame_; |
| 207 | 160 |
| 208 // WebFrame of pending fullscreen request. | 161 // WebFrame of pending fullscreen request. |
| 209 blink::WebFrame* pending_fullscreen_frame_; | 162 blink::WebFrame* pending_fullscreen_frame_; |
| 210 | 163 |
| 211 DISALLOW_COPY_AND_ASSIGN(RendererMediaPlayerManager); | 164 DISALLOW_COPY_AND_ASSIGN(RendererMediaPlayerManager); |
| 212 }; | 165 }; |
| 213 | 166 |
| 214 } // namespace content | 167 } // namespace content |
| 215 | 168 |
| 216 #endif // CONTENT_RENDERER_MEDIA_ANDROID_RENDERER_MEDIA_PLAYER_MANAGER_H_ | 169 #endif // CONTENT_RENDERER_MEDIA_ANDROID_RENDERER_MEDIA_PLAYER_MANAGER_H_ |
| OLD | NEW |