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

Side by Side Diff: webkit/media/android/media_player_bridge_manager_impl.cc

Issue 10919075: Move android mediaplayer from render process to browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressing comments Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
(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)
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698