| 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 void MediaPlayerBridgeManagerImpl::RequestMediaResources( |
| 19 media::MediaPlayerBridge* player) { |
| 20 if (!player) |
| 21 return; |
| 22 |
| 23 int num_active_player = 0; |
| 24 std::vector<media::MediaPlayerBridge*>::iterator it; |
| 25 for (it = players_.begin(); it != players_.end(); ++it) { |
| 26 // The player is already active, ignore it. |
| 27 if ((*it) == player) |
| 28 return; |
| 29 |
| 30 num_active_player++; |
| 31 } |
| 32 |
| 33 if (num_active_player < active_player_threshold_) { |
| 34 players_.push_back(player); |
| 35 return; |
| 36 } |
| 37 |
| 38 // Get a list of the players to free. |
| 39 std::vector<media::MediaPlayerBridge*> players_to_release; |
| 40 for (it = players_.begin(); it != players_.end(); ++it) { |
| 41 if ((*it)->prepared() && !(*it)->IsPlaying()) |
| 42 players_to_release.push_back(*it); |
| 43 } |
| 44 |
| 45 // Calling release() will result in a call to ReleaseMediaResources(), so |
| 46 // the player will be removed from |players_|. |
| 47 for (it = players_to_release.begin(); it != players_to_release.end(); ++it) |
| 48 (*it)->Release(); |
| 49 |
| 50 players_.push_back(player); |
| 51 } |
| 52 |
| 53 void MediaPlayerBridgeManagerImpl::ReleaseMediaResources( |
| 54 media::MediaPlayerBridge* player) { |
| 55 for (std::vector<media::MediaPlayerBridge*>::iterator it = players_.begin(); |
| 56 it != players_.end(); ++it) { |
| 57 if ((*it) == player) { |
| 58 players_.erase(it); |
| 59 return; |
| 60 } |
| 61 } |
| 62 } |
| 63 |
| 64 } // namespace webkit_media |
| OLD | NEW |