Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/media/android/media_player_bridge_manager_impl.h" | |
| 6 | |
| 7 #include "media/base/android/media_player_bridge.h" | |
| 8 | |
| 9 namespace webkit_media { | |
| 10 | |
| 11 MediaPlayerBridgeManagerImpl::MediaPlayerBridgeManagerImpl( | |
| 12 int threshold) | |
| 13 : active_player_threshold_(threshold) { | |
| 14 } | |
| 15 | |
| 16 MediaPlayerBridgeManagerImpl::~MediaPlayerBridgeManagerImpl() { | |
| 17 } | |
| 18 | |
| 19 void MediaPlayerBridgeManagerImpl::RequestMediaResources( | |
| 20 media::MediaPlayerBridge* player) { | |
| 21 if (player == NULL) | |
|
scherkus (not reviewing)
2012/09/10 12:19:08
s/player == NULL/!player/
qinmin
2012/09/11 04:50:24
Done.
| |
| 22 return; | |
| 23 | |
| 24 int num_active_player = 0; | |
| 25 std::vector<media::MediaPlayerBridge*>::iterator it; | |
| 26 for (it = players_.begin(); it != players_.end(); ++it) { | |
| 27 // The player is already active, ignore it. | |
| 28 if ((*it) == player) | |
| 29 return; | |
| 30 | |
| 31 num_active_player++; | |
| 32 } | |
| 33 | |
| 34 if (num_active_player < active_player_threshold_) { | |
| 35 players_.push_back(player); | |
| 36 return; | |
| 37 } | |
| 38 | |
| 39 // Get a list of the players to free. | |
| 40 std::vector<media::MediaPlayerBridge*> players_to_release; | |
| 41 for (it = players_.begin(); it != players_.end(); ++it) { | |
| 42 if ((*it)->prepared() && !(*it)->IsPlaying()) | |
| 43 players_to_release.push_back(*it); | |
| 44 } | |
| 45 | |
| 46 // Calling release() will result in a call to ReleaseMediaResources(), so | |
| 47 // the player will be removed from |players_|. | |
| 48 for (it = players_to_release.begin(); it != players_to_release.end(); ++it) | |
| 49 (*it)->Release(); | |
| 50 | |
| 51 players_.push_back(player); | |
| 52 } | |
| 53 | |
| 54 void MediaPlayerBridgeManagerImpl::ReleaseMediaResources( | |
| 55 media::MediaPlayerBridge* player) { | |
| 56 for (std::vector<media::MediaPlayerBridge*>::iterator it = players_.begin(); | |
| 57 it != players_.end(); ++it) { | |
| 58 if ((*it) == player) { | |
| 59 players_.erase(it); | |
| 60 return; | |
| 61 } | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 } // namespace webkit_media | |
| OLD | NEW |