Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / content / browser / android / surface_texture_peer_browser_impl.cc
blob7935c9ab409b15bad3d7cf32eefd742d563947f0
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.
5 #include "content/browser/android/surface_texture_peer_browser_impl.h"
7 #include "content/browser/media/android/browser_media_player_manager.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/render_process_host.h"
11 #include "media/base/android/media_player_android.h"
12 #include "ui/gl/android/scoped_java_surface.h"
14 namespace content {
16 namespace {
18 // Pass a java surface object to the MediaPlayerAndroid object
19 // identified by render process handle, render view ID and player ID.
20 static void SetSurfacePeer(
21 scoped_refptr<gfx::SurfaceTexture> surface_texture,
22 base::ProcessHandle render_process_handle,
23 int render_view_id,
24 int player_id) {
25 int renderer_id = 0;
26 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
27 while (!it.IsAtEnd()) {
28 if (it.GetCurrentValue()->GetHandle() == render_process_handle) {
29 renderer_id = it.GetCurrentValue()->GetID();
30 break;
32 it.Advance();
35 if (renderer_id) {
36 RenderViewHostImpl* host = RenderViewHostImpl::FromID(
37 renderer_id, render_view_id);
38 if (host) {
39 media::MediaPlayerAndroid* player =
40 host->media_player_manager()->GetPlayer(player_id);
41 if (player &&
42 player != host->media_player_manager()->GetFullscreenPlayer()) {
43 gfx::ScopedJavaSurface surface(surface_texture.get());
44 player->SetVideoSurface(surface.Pass());
50 } // anonymous namespace
52 SurfaceTexturePeerBrowserImpl::SurfaceTexturePeerBrowserImpl() {
55 SurfaceTexturePeerBrowserImpl::~SurfaceTexturePeerBrowserImpl() {
58 void SurfaceTexturePeerBrowserImpl::EstablishSurfaceTexturePeer(
59 base::ProcessHandle render_process_handle,
60 scoped_refptr<gfx::SurfaceTexture> surface_texture,
61 int render_view_id,
62 int player_id) {
63 if (!surface_texture.get())
64 return;
66 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
67 &SetSurfacePeer, surface_texture, render_process_handle,
68 render_view_id, player_id));
71 } // namespace content