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_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ |
6 #define CONTENT_BROWSER_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ | 6 #define CONTENT_BROWSER_ANDROID_BROWSER_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/callback.h" | 13 #include "base/callback.h" |
14 #include "base/id_map.h" | |
15 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
17 #include "base/time/time.h" | 16 #include "base/time/time.h" |
18 #include "content/browser/android/content_video_view.h" | 17 #include "content/browser/android/content_video_view.h" |
19 #include "content/common/media/media_player_messages_enums_android.h" | 18 #include "content/common/media/media_player_messages_enums_android.h" |
20 #include "content/public/browser/render_view_host_observer.h" | 19 #include "content/public/browser/render_view_host_observer.h" |
21 #include "media/base/android/demuxer_android.h" | |
22 #include "media/base/android/demuxer_stream_player_params.h" | |
23 #include "media/base/android/media_player_android.h" | 20 #include "media/base/android/media_player_android.h" |
24 #include "media/base/android/media_player_manager.h" | 21 #include "media/base/android/media_player_manager.h" |
25 #include "ui/gfx/rect_f.h" | 22 #include "ui/gfx/rect_f.h" |
26 #include "url/gurl.h" | 23 #include "url/gurl.h" |
27 | 24 |
28 namespace media { | 25 namespace media { |
| 26 class DemuxerAndroid; |
29 class MediaDrmBridge; | 27 class MediaDrmBridge; |
30 } | 28 } |
31 | 29 |
32 namespace content { | 30 namespace content { |
33 | 31 |
| 32 class BrowserDemuxerAndroid; |
34 class WebContents; | 33 class WebContents; |
35 | 34 |
36 // This class manages all the MediaPlayerAndroid objects. It receives | 35 // This class manages all the MediaPlayerAndroid objects. It receives |
37 // control operations from the the render process, and forwards | 36 // control operations from the the render process, and forwards |
38 // them to corresponding MediaPlayerAndroid object. Callbacks from | 37 // them to corresponding MediaPlayerAndroid object. Callbacks from |
39 // MediaPlayerAndroid objects are converted to IPCs and then sent to the | 38 // MediaPlayerAndroid objects are converted to IPCs and then sent to the |
40 // render process. | 39 // render process. |
41 class CONTENT_EXPORT BrowserMediaPlayerManager | 40 class CONTENT_EXPORT BrowserMediaPlayerManager |
42 : public RenderViewHostObserver, | 41 : public RenderViewHostObserver, |
43 public media::MediaPlayerManager, | 42 public media::MediaPlayerManager { |
44 public media::DemuxerAndroid { | |
45 public: | 43 public: |
46 // Permits embedders to provide an extended version of the class. | 44 // Permits embedders to provide an extended version of the class. |
47 typedef BrowserMediaPlayerManager* (*Factory)(RenderViewHost*); | 45 typedef BrowserMediaPlayerManager* (*Factory)(RenderViewHost*); |
48 static void RegisterFactory(Factory factory); | 46 static void RegisterFactory(Factory factory); |
49 | 47 |
50 // Returns a new instance using the registered factory if available. | 48 // Returns a new instance using the registered factory if available. |
51 static BrowserMediaPlayerManager* Create(RenderViewHost* rvh); | 49 static BrowserMediaPlayerManager* Create(RenderViewHost* rvh); |
52 | 50 |
53 virtual ~BrowserMediaPlayerManager(); | 51 virtual ~BrowserMediaPlayerManager(); |
54 | 52 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 const std::string& session_id) OVERRIDE; | 89 const std::string& session_id) OVERRIDE; |
92 virtual void OnKeyError(int media_keys_id, | 90 virtual void OnKeyError(int media_keys_id, |
93 const std::string& session_id, | 91 const std::string& session_id, |
94 media::MediaKeys::KeyError error_code, | 92 media::MediaKeys::KeyError error_code, |
95 int system_code) OVERRIDE; | 93 int system_code) OVERRIDE; |
96 virtual void OnKeyMessage(int media_keys_id, | 94 virtual void OnKeyMessage(int media_keys_id, |
97 const std::string& session_id, | 95 const std::string& session_id, |
98 const std::vector<uint8>& message, | 96 const std::vector<uint8>& message, |
99 const std::string& destination_url) OVERRIDE; | 97 const std::string& destination_url) OVERRIDE; |
100 | 98 |
101 // media::DemuxerAndroid implementation. | |
102 virtual void AddDemuxerClient(int demuxer_client_id, | |
103 media::DemuxerAndroidClient* client) OVERRIDE; | |
104 virtual void RemoveDemuxerClient(int demuxer_client_id) OVERRIDE; | |
105 virtual void RequestDemuxerConfigs(int demuxer_client_id) OVERRIDE; | |
106 virtual void RequestDemuxerData(int demuxer_client_id, | |
107 media::DemuxerStream::Type type) OVERRIDE; | |
108 virtual void RequestDemuxerSeek(int demuxer_client_id, | |
109 base::TimeDelta time_to_seek, | |
110 unsigned seek_request_id) OVERRIDE; | |
111 | |
112 #if defined(GOOGLE_TV) | 99 #if defined(GOOGLE_TV) |
113 void AttachExternalVideoSurface(int player_id, jobject surface); | 100 void AttachExternalVideoSurface(int player_id, jobject surface); |
114 void DetachExternalVideoSurface(int player_id); | 101 void DetachExternalVideoSurface(int player_id); |
115 #endif | 102 #endif |
116 | 103 |
117 protected: | 104 protected: |
118 // Clients must use Create() or subclass constructor. | 105 // Clients must use Create() or subclass constructor. |
119 explicit BrowserMediaPlayerManager(RenderViewHost* render_view_host); | 106 explicit BrowserMediaPlayerManager(RenderViewHost* render_view_host); |
120 | 107 |
121 // Message handlers. | 108 // Message handlers. |
122 virtual void OnEnterFullscreen(int player_id); | 109 virtual void OnEnterFullscreen(int player_id); |
123 virtual void OnExitFullscreen(int player_id); | 110 virtual void OnExitFullscreen(int player_id); |
124 virtual void OnInitialize( | 111 virtual void OnInitialize( |
125 int player_id, | 112 int player_id, |
126 const GURL& url, | 113 const GURL& url, |
127 MediaPlayerHostMsg_Initialize_Type type, | 114 MediaPlayerHostMsg_Initialize_Type type, |
128 const GURL& first_party_for_cookies); | 115 const GURL& first_party_for_cookies); |
129 virtual void OnStart(int player_id); | 116 virtual void OnStart(int player_id); |
130 virtual void OnSeek(int player_id, base::TimeDelta time); | 117 virtual void OnSeek(int player_id, base::TimeDelta time); |
131 virtual void OnPause(int player_id); | 118 virtual void OnPause(int player_id); |
132 virtual void OnSetVolume(int player_id, double volume); | 119 virtual void OnSetVolume(int player_id, double volume); |
133 virtual void OnReleaseResources(int player_id); | 120 virtual void OnReleaseResources(int player_id); |
134 virtual void OnDestroyPlayer(int player_id); | 121 virtual void OnDestroyPlayer(int player_id); |
135 virtual void OnDemuxerReady(int player_id, | |
136 const media::DemuxerConfigs& configs); | |
137 virtual void OnReadFromDemuxerAck(int player_id, | |
138 const media::DemuxerData& data); | |
139 void OnMediaSeekRequestAck(int player_id, unsigned seek_request_id); | |
140 void OnInitializeCDM(int media_keys_id, const std::vector<uint8>& uuid); | 122 void OnInitializeCDM(int media_keys_id, const std::vector<uint8>& uuid); |
141 void OnGenerateKeyRequest(int media_keys_id, | 123 void OnGenerateKeyRequest(int media_keys_id, |
142 const std::string& type, | 124 const std::string& type, |
143 const std::vector<uint8>& init_data); | 125 const std::vector<uint8>& init_data); |
144 void OnAddKey(int media_keys_id, | 126 void OnAddKey(int media_keys_id, |
145 const std::vector<uint8>& key, | 127 const std::vector<uint8>& key, |
146 const std::vector<uint8>& init_data, | 128 const std::vector<uint8>& init_data, |
147 const std::string& session_id); | 129 const std::string& session_id); |
148 void OnCancelKeyRequest(int media_keys_id, const std::string& session_id); | 130 void OnCancelKeyRequest(int media_keys_id, const std::string& session_id); |
149 void OnDurationChanged(int player_id, const base::TimeDelta& duration); | |
150 void OnSetMediaKeys(int player_id, int media_keys_id); | 131 void OnSetMediaKeys(int player_id, int media_keys_id); |
151 | 132 |
152 #if defined(GOOGLE_TV) | 133 #if defined(GOOGLE_TV) |
153 virtual void OnNotifyExternalSurface( | 134 virtual void OnNotifyExternalSurface( |
154 int player_id, bool is_request, const gfx::RectF& rect); | 135 int player_id, bool is_request, const gfx::RectF& rect); |
155 #endif | 136 #endif |
156 | 137 |
157 // Adds a given player to the list. | 138 // Adds a given player to the list. |
158 void AddPlayer(media::MediaPlayerAndroid* player); | 139 void AddPlayer(media::MediaPlayerAndroid* player); |
159 | 140 |
(...skipping 16 matching lines...) Expand all Loading... |
176 // needed. | 157 // needed. |
177 static media::MediaPlayerAndroid* CreateMediaPlayer( | 158 static media::MediaPlayerAndroid* CreateMediaPlayer( |
178 int player_id, | 159 int player_id, |
179 const GURL& url, | 160 const GURL& url, |
180 MediaPlayerHostMsg_Initialize_Type type, | 161 MediaPlayerHostMsg_Initialize_Type type, |
181 const GURL& first_party_for_cookies, | 162 const GURL& first_party_for_cookies, |
182 bool hide_url_log, | 163 bool hide_url_log, |
183 media::MediaPlayerManager* manager, | 164 media::MediaPlayerManager* manager, |
184 media::DemuxerAndroid* demuxer); | 165 media::DemuxerAndroid* demuxer); |
185 | 166 |
| 167 // Owned by RenderViewHost. |
| 168 BrowserDemuxerAndroid* browser_demuxer_; |
| 169 |
186 // An array of managed players. | 170 // An array of managed players. |
187 ScopedVector<media::MediaPlayerAndroid> players_; | 171 ScopedVector<media::MediaPlayerAndroid> players_; |
188 | 172 |
189 // An array of managed media DRM bridges. | 173 // An array of managed media DRM bridges. |
190 ScopedVector<media::MediaDrmBridge> drm_bridges_; | 174 ScopedVector<media::MediaDrmBridge> drm_bridges_; |
191 | 175 |
192 IDMap<media::DemuxerAndroidClient> demuxer_clients_; | |
193 | |
194 // The fullscreen video view object or NULL if video is not played in | 176 // The fullscreen video view object or NULL if video is not played in |
195 // fullscreen. | 177 // fullscreen. |
196 scoped_ptr<ContentVideoView> video_view_; | 178 scoped_ptr<ContentVideoView> video_view_; |
197 | 179 |
198 // Player ID of the fullscreen media player. | 180 // Player ID of the fullscreen media player. |
199 int fullscreen_player_id_; | 181 int fullscreen_player_id_; |
200 | 182 |
201 WebContents* web_contents_; | 183 WebContents* web_contents_; |
202 | 184 |
203 // Object for retrieving resources media players. | 185 // Object for retrieving resources media players. |
204 scoped_ptr<media::MediaResourceGetter> media_resource_getter_; | 186 scoped_ptr<media::MediaResourceGetter> media_resource_getter_; |
205 | 187 |
206 DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager); | 188 DISALLOW_COPY_AND_ASSIGN(BrowserMediaPlayerManager); |
207 }; | 189 }; |
208 | 190 |
209 } // namespace content | 191 } // namespace content |
210 | 192 |
211 #endif // CONTENT_BROWSER_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ | 193 #endif // CONTENT_BROWSER_ANDROID_BROWSER_MEDIA_PLAYER_MANAGER_H_ |
OLD | NEW |