| 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 #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" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 135 |
| 136 RemoteMediaPlayerBridge* RemoteMediaPlayerManager::CreateRemoteMediaPlayer( | 136 RemoteMediaPlayerBridge* RemoteMediaPlayerManager::CreateRemoteMediaPlayer( |
| 137 int player_id) { | 137 int player_id) { |
| 138 RemoteMediaPlayerBridge* player = | 138 RemoteMediaPlayerBridge* player = |
| 139 new RemoteMediaPlayerBridge(player_id, GetUserAgent(), false, this); | 139 new RemoteMediaPlayerBridge(player_id, GetUserAgent(), false, this); |
| 140 alternative_players_.push_back(player); | 140 alternative_players_.push_back(player); |
| 141 player->Initialize(); | 141 player->Initialize(); |
| 142 return player; | 142 return player; |
| 143 } | 143 } |
| 144 | 144 |
| 145 void RemoteMediaPlayerManager::SwapCurrentPlayer(int player_id) { | 145 bool RemoteMediaPlayerManager::SwapCurrentPlayer(int player_id) { |
| 146 // Find the remote player | 146 // Find the alternative player to swap the current one with. |
| 147 auto it = GetAlternativePlayer(player_id); | 147 auto it = GetAlternativePlayer(player_id); |
| 148 if (it == alternative_players_.end()) | 148 if (it == alternative_players_.end()) |
| 149 return; | 149 return false; |
| 150 |
| 150 MediaPlayerAndroid* new_player = *it; | 151 MediaPlayerAndroid* new_player = *it; |
| 151 std::unique_ptr<MediaPlayerAndroid> old_player = | 152 std::unique_ptr<MediaPlayerAndroid> old_player = |
| 152 SwapPlayer(player_id, new_player); | 153 SwapPlayer(player_id, new_player); |
| 154 if (!old_player) { |
| 155 // There's no player to swap with, destroy the alternative player and exit. |
| 156 alternative_players_.erase(it); |
| 157 return false; |
| 158 } |
| 159 |
| 153 alternative_players_.weak_erase(it); | 160 alternative_players_.weak_erase(it); |
| 154 alternative_players_.push_back(old_player.release()); | 161 alternative_players_.push_back(old_player.release()); |
| 162 return true; |
| 155 } | 163 } |
| 156 | 164 |
| 157 void RemoteMediaPlayerManager::SwitchToRemotePlayer( | 165 void RemoteMediaPlayerManager::SwitchToRemotePlayer( |
| 158 int player_id, | 166 int player_id, |
| 159 const std::string& casting_message) { | 167 const std::string& casting_message) { |
| 160 DCHECK(!IsPlayingRemotely(player_id)); | 168 DCHECK(!IsPlayingRemotely(player_id)); |
| 161 SwapCurrentPlayer(player_id); | 169 if (!SwapCurrentPlayer(player_id)) |
| 170 return; |
| 162 players_playing_remotely_.insert(player_id); | 171 players_playing_remotely_.insert(player_id); |
| 163 Send(new MediaPlayerMsg_DidMediaPlayerPlay(RoutingID(), player_id)); | 172 Send(new MediaPlayerMsg_DidMediaPlayerPlay(RoutingID(), player_id)); |
| 164 Send(new MediaPlayerMsg_ConnectedToRemoteDevice(RoutingID(), player_id, | 173 Send(new MediaPlayerMsg_ConnectedToRemoteDevice(RoutingID(), player_id, |
| 165 casting_message)); | 174 casting_message)); |
| 166 // The remote player will want the poster bitmap, however, to avoid wasting | 175 // The remote player will want the poster bitmap, however, to avoid wasting |
| 167 // memory we don't fetch it until we are likely to need it. | 176 // memory we don't fetch it until we are likely to need it. |
| 168 FetchPosterBitmap(player_id); | 177 FetchPosterBitmap(player_id); |
| 169 } | 178 } |
| 170 | 179 |
| 171 void RemoteMediaPlayerManager::SwitchToLocalPlayer(int player_id) { | 180 void RemoteMediaPlayerManager::SwitchToLocalPlayer(int player_id) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 MediaPlayerAndroid* local_player = GetLocalPlayer(player_id); | 277 MediaPlayerAndroid* local_player = GetLocalPlayer(player_id); |
| 269 Send(new MediaPlayerMsg_MediaMetadataChanged( | 278 Send(new MediaPlayerMsg_MediaMetadataChanged( |
| 270 RoutingID(), player_id, duration, local_player->GetVideoWidth(), | 279 RoutingID(), player_id, duration, local_player->GetVideoWidth(), |
| 271 local_player->GetVideoHeight(), success)); | 280 local_player->GetVideoHeight(), success)); |
| 272 } else { | 281 } else { |
| 273 BrowserMediaPlayerManager::OnMediaMetadataChanged(player_id, duration, | 282 BrowserMediaPlayerManager::OnMediaMetadataChanged(player_id, duration, |
| 274 width, height, success); | 283 width, height, success); |
| 275 } | 284 } |
| 276 } | 285 } |
| 277 } // namespace remote_media | 286 } // namespace remote_media |
| OLD | NEW |