Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Side by Side Diff: chrome/browser/media/android/remote/remote_media_player_manager.cc

Issue 1634173002: Reduce and limit video poster memory usage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix empty poster handling. Also clear poster url when player destroyed. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/media/android/remote/remote_media_player_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/media/android/remote/remote_media_player_manager.h" 5 #include "chrome/browser/media/android/remote/remote_media_player_manager.h"
6 6
7 #include "chrome/browser/android/tab_android.h" 7 #include "chrome/browser/android/tab_android.h"
8 #include "chrome/common/chrome_content_client.h" 8 #include "chrome/common/chrome_content_client.h"
9 #include "content/common/media/media_player_messages_android.h" 9 #include "content/common/media/media_player_messages_android.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
11 #include "ui/gfx/android/java_bitmap.h" 11 #include "ui/gfx/android/java_bitmap.h"
12 12
13 using media::MediaPlayerAndroid; 13 using media::MediaPlayerAndroid;
14 14
15 static const int MAX_POSTER_BITMAP_SIZE = 1024 * 1024;
16
15 namespace remote_media { 17 namespace remote_media {
16 18
17 RemoteMediaPlayerManager::RemoteMediaPlayerManager( 19 RemoteMediaPlayerManager::RemoteMediaPlayerManager(
18 content::RenderFrameHost* render_frame_host) 20 content::RenderFrameHost* render_frame_host)
19 : BrowserMediaPlayerManager(render_frame_host), 21 : BrowserMediaPlayerManager(render_frame_host),
20 weak_ptr_factory_(this) { 22 weak_ptr_factory_(this) {
21 } 23 }
22 24
23 RemoteMediaPlayerManager::~RemoteMediaPlayerManager() { 25 RemoteMediaPlayerManager::~RemoteMediaPlayerManager() {
24 for (MediaPlayerAndroid* player : alternative_players_) 26 for (MediaPlayerAndroid* player : alternative_players_)
(...skipping 18 matching lines...) Expand all
43 if (player) { 45 if (player) {
44 RemoteMediaPlayerBridge* remote_player = CreateRemoteMediaPlayer(player); 46 RemoteMediaPlayerBridge* remote_player = CreateRemoteMediaPlayer(player);
45 remote_player->OnPlayerCreated(); 47 remote_player->OnPlayerCreated();
46 } 48 }
47 } 49 }
48 50
49 void RemoteMediaPlayerManager::OnDestroyPlayer(int player_id) { 51 void RemoteMediaPlayerManager::OnDestroyPlayer(int player_id) {
50 RemoteMediaPlayerBridge* player = GetRemotePlayer(player_id); 52 RemoteMediaPlayerBridge* player = GetRemotePlayer(player_id);
51 if (player) 53 if (player)
52 player->OnPlayerDestroyed(); 54 player->OnPlayerDestroyed();
55 poster_urls_.erase(player_id);
53 BrowserMediaPlayerManager::OnDestroyPlayer(player_id); 56 BrowserMediaPlayerManager::OnDestroyPlayer(player_id);
54 } 57 }
55 58
56 void RemoteMediaPlayerManager::OnSuspendAndReleaseResources(int player_id) { 59 void RemoteMediaPlayerManager::OnSuspendAndReleaseResources(int player_id) {
57 // We only want to release resources of local players. 60 // We only want to release resources of local players.
58 if (!IsPlayingRemotely(player_id)) 61 if (!IsPlayingRemotely(player_id))
59 BrowserMediaPlayerManager::OnSuspendAndReleaseResources(player_id); 62 BrowserMediaPlayerManager::OnSuspendAndReleaseResources(player_id);
60 } 63 }
61 64
62 void RemoteMediaPlayerManager::OnRequestRemotePlayback(int player_id) { 65 void RemoteMediaPlayerManager::OnRequestRemotePlayback(int player_id) {
(...skipping 16 matching lines...) Expand all
79 if (!web_contents()) 82 if (!web_contents())
80 return -1; 83 return -1;
81 84
82 TabAndroid* tab = TabAndroid::FromWebContents(web_contents()); 85 TabAndroid* tab = TabAndroid::FromWebContents(web_contents());
83 if (!tab) 86 if (!tab)
84 return -1; 87 return -1;
85 88
86 return tab->GetAndroidId(); 89 return tab->GetAndroidId();
87 } 90 }
88 91
92 void RemoteMediaPlayerManager::FetchPosterBitmap(int player_id) {
93 RemoteMediaPlayerBridge* player = GetRemotePlayer(player_id);
94 if (poster_urls_.count(player_id) == 0 ||
95 poster_urls_[player_id].is_empty()) {
96 if (player)
97 player->SetPosterBitmap(std::vector<SkBitmap>());
98 return;
99 }
100 content::WebContents::ImageDownloadCallback callback =
101 base::Bind(&RemoteMediaPlayerManager::DidDownloadPoster,
102 weak_ptr_factory_.GetWeakPtr(), player_id);
103 web_contents()->DownloadImage(
104 poster_urls_[player_id],
105 false, // is_favicon, false so that cookies will be used.
106 MAX_POSTER_BITMAP_SIZE, // max_bitmap_size, 0 means no limit.
107 false, // normal cache policy.
108 callback);
109 }
110
89 void RemoteMediaPlayerManager::OnSetPoster(int player_id, const GURL& url) { 111 void RemoteMediaPlayerManager::OnSetPoster(int player_id, const GURL& url) {
90 RemoteMediaPlayerBridge* player = GetRemotePlayer(player_id); 112 // OnSetPoster is called when the attibutes of the video element are parsed,
91 113 // which may be before OnInitialize is called, so we can't assume that the
92 if (player && url.is_empty()) { 114 // players wil exist.
93 player->SetPosterBitmap(std::vector<SkBitmap>()); 115 poster_urls_[player_id] = url;
94 } else {
95 // TODO(aberent) OnSetPoster is called when the attributes of the video
96 // element are parsed, which may be before OnInitialize is called. We are
97 // here relying on the image fetch taking longer than the delay until
98 // OnInitialize is called, and hence the player is created. This is not
99 // guaranteed.
100 content::WebContents::ImageDownloadCallback callback = base::Bind(
101 &RemoteMediaPlayerManager::DidDownloadPoster,
102 weak_ptr_factory_.GetWeakPtr(), player_id);
103 web_contents()->DownloadImage(
104 url,
105 false, // is_favicon, false so that cookies will be used.
106 0, // max_bitmap_size, 0 means no limit.
107 false, // normal cache policy.
108 callback);
109 }
110 } 116 }
111 117
112 void RemoteMediaPlayerManager::ReleaseResources(int player_id) { 118 void RemoteMediaPlayerManager::ReleaseResources(int player_id) {
113 if (IsPlayingRemotely(player_id)) 119 if (IsPlayingRemotely(player_id))
114 return; 120 return;
115 BrowserMediaPlayerManager::ReleaseResources(player_id); 121 BrowserMediaPlayerManager::ReleaseResources(player_id);
116 } 122 }
117 123
118 void RemoteMediaPlayerManager::DidDownloadPoster( 124 void RemoteMediaPlayerManager::DidDownloadPoster(
119 int player_id, 125 int player_id,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 170
165 void RemoteMediaPlayerManager::SwitchToRemotePlayer( 171 void RemoteMediaPlayerManager::SwitchToRemotePlayer(
166 int player_id, 172 int player_id,
167 const std::string& casting_message) { 173 const std::string& casting_message) {
168 DCHECK(!IsPlayingRemotely(player_id)); 174 DCHECK(!IsPlayingRemotely(player_id));
169 SwapCurrentPlayer(player_id); 175 SwapCurrentPlayer(player_id);
170 players_playing_remotely_.insert(player_id); 176 players_playing_remotely_.insert(player_id);
171 Send(new MediaPlayerMsg_DidMediaPlayerPlay(RoutingID(), player_id)); 177 Send(new MediaPlayerMsg_DidMediaPlayerPlay(RoutingID(), player_id));
172 Send(new MediaPlayerMsg_ConnectedToRemoteDevice(RoutingID(), player_id, 178 Send(new MediaPlayerMsg_ConnectedToRemoteDevice(RoutingID(), player_id,
173 casting_message)); 179 casting_message));
180 // The remote player will want the poster bitmap, however, to avoid wasting
181 // memory we don't fetch it until we are likely to need it.
182 FetchPosterBitmap(player_id);
174 } 183 }
175 184
176 void RemoteMediaPlayerManager::SwitchToLocalPlayer(int player_id) { 185 void RemoteMediaPlayerManager::SwitchToLocalPlayer(int player_id) {
177 DCHECK(IsPlayingRemotely(player_id)); 186 DCHECK(IsPlayingRemotely(player_id));
178 SwapCurrentPlayer(player_id); 187 SwapCurrentPlayer(player_id);
179 players_playing_remotely_.erase(player_id); 188 players_playing_remotely_.erase(player_id);
180 Send(new MediaPlayerMsg_DisconnectedFromRemoteDevice(RoutingID(), player_id)); 189 Send(new MediaPlayerMsg_DisconnectedFromRemoteDevice(RoutingID(), player_id));
181 } 190 }
182 191
183 void RemoteMediaPlayerManager::ReplaceRemotePlayerWithLocal(int player_id) { 192 void RemoteMediaPlayerManager::ReplaceRemotePlayerWithLocal(int player_id) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 MediaPlayerAndroid* local_player = GetLocalPlayer(player_id); 276 MediaPlayerAndroid* local_player = GetLocalPlayer(player_id);
268 Send(new MediaPlayerMsg_MediaMetadataChanged( 277 Send(new MediaPlayerMsg_MediaMetadataChanged(
269 RoutingID(), player_id, duration, local_player->GetVideoWidth(), 278 RoutingID(), player_id, duration, local_player->GetVideoWidth(),
270 local_player->GetVideoHeight(), success)); 279 local_player->GetVideoHeight(), success));
271 } else { 280 } else {
272 BrowserMediaPlayerManager::OnMediaMetadataChanged(player_id, duration, 281 BrowserMediaPlayerManager::OnMediaMetadataChanged(player_id, duration,
273 width, height, success); 282 width, height, success);
274 } 283 }
275 } 284 }
276 } // namespace remote_media 285 } // namespace remote_media
OLDNEW
« no previous file with comments | « chrome/browser/media/android/remote/remote_media_player_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698