| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/android/surface_texture_peer_browser_impl.h" | 5 #include "content/browser/android/surface_texture_peer_browser_impl.h" |
| 6 | 6 |
| 7 #include "content/browser/android/media_player_manager_android.h" | 7 #include "content/browser/android/media_player_manager_android.h" |
| 8 #include "content/browser/renderer_host/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 9 #include "content/common/android/surface_callback.h" | 9 #include "content/common/android/scoped_java_surface.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
| 12 #include "jni/BrowserProcessSurfaceTexture_jni.h" | |
| 13 #include "media/base/android/media_player_bridge.h" | 12 #include "media/base/android/media_player_bridge.h" |
| 14 | 13 |
| 15 using base::android::MethodID; | 14 namespace content { |
| 16 | 15 |
| 17 namespace content { | 16 namespace { |
| 18 | 17 |
| 19 // Pass a java surface object to the MediaPlayerBridge object | 18 // Pass a java surface object to the MediaPlayerBridge object |
| 20 // identified by render process handle, render view ID and player ID. | 19 // identified by render process handle, render view ID and player ID. |
| 21 static void SetSurfacePeer( | 20 static void SetSurfacePeer( |
| 22 scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, | 21 scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, |
| 23 base::ProcessHandle render_process_handle, | 22 base::ProcessHandle render_process_handle, |
| 24 int render_view_id, | 23 int render_view_id, |
| 25 int player_id) { | 24 int player_id) { |
| 26 int renderer_id = 0; | 25 int renderer_id = 0; |
| 27 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); | 26 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
| 28 while (!it.IsAtEnd()) { | 27 while (!it.IsAtEnd()) { |
| 29 if (it.GetCurrentValue()->GetHandle() == render_process_handle) { | 28 if (it.GetCurrentValue()->GetHandle() == render_process_handle) { |
| 30 renderer_id = it.GetCurrentValue()->GetID(); | 29 renderer_id = it.GetCurrentValue()->GetID(); |
| 31 break; | 30 break; |
| 32 } | 31 } |
| 33 it.Advance(); | 32 it.Advance(); |
| 34 } | 33 } |
| 35 | 34 |
| 36 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 37 DCHECK(env); | |
| 38 if (renderer_id) { | 35 if (renderer_id) { |
| 39 RenderViewHostImpl* host = RenderViewHostImpl::FromID( | 36 RenderViewHostImpl* host = RenderViewHostImpl::FromID( |
| 40 renderer_id, render_view_id); | 37 renderer_id, render_view_id); |
| 41 if (host) { | 38 if (host) { |
| 42 media::MediaPlayerBridge* player = | 39 media::MediaPlayerBridge* player = |
| 43 host->media_player_manager()->GetPlayer(player_id); | 40 host->media_player_manager()->GetPlayer(player_id); |
| 44 if (player && | 41 if (player && |
| 45 player != host->media_player_manager()->GetFullscreenPlayer()) { | 42 player != host->media_player_manager()->GetFullscreenPlayer()) { |
| 46 base::android::ScopedJavaLocalRef<jclass> cls( | 43 ScopedJavaSurface surface(surface_texture_bridge.get()); |
| 47 base::android::GetClass(env, "android/view/Surface")); | 44 player->SetVideoSurface(surface.j_surface().obj()); |
| 48 jmethodID constructor = MethodID::Get<MethodID::TYPE_INSTANCE>( | |
| 49 env, cls.obj(), "<init>", "(Landroid/graphics/SurfaceTexture;)V"); | |
| 50 ScopedJavaLocalRef<jobject> j_surface( | |
| 51 env, env->NewObject( | |
| 52 cls.obj(), constructor, | |
| 53 surface_texture_bridge->j_surface_texture().obj())); | |
| 54 player->SetVideoSurface(j_surface.obj()); | |
| 55 ReleaseSurface(j_surface.obj()); | |
| 56 } | 45 } |
| 57 } | 46 } |
| 58 } | 47 } |
| 59 } | 48 } |
| 60 | 49 |
| 61 SurfaceTexturePeerBrowserImpl::SurfaceTexturePeerBrowserImpl( | 50 } // anonymous namespace |
| 62 bool player_in_render_process) | 51 |
| 63 : player_in_render_process_(player_in_render_process) { | 52 SurfaceTexturePeerBrowserImpl::SurfaceTexturePeerBrowserImpl() { |
| 64 } | 53 } |
| 65 | 54 |
| 66 SurfaceTexturePeerBrowserImpl::~SurfaceTexturePeerBrowserImpl() { | 55 SurfaceTexturePeerBrowserImpl::~SurfaceTexturePeerBrowserImpl() { |
| 67 if (surface_.obj()) | |
| 68 ReleaseSurface(surface_.obj()); | |
| 69 } | 56 } |
| 70 | 57 |
| 71 void SurfaceTexturePeerBrowserImpl::EstablishSurfaceTexturePeer( | 58 void SurfaceTexturePeerBrowserImpl::EstablishSurfaceTexturePeer( |
| 72 base::ProcessHandle render_process_handle, | 59 base::ProcessHandle render_process_handle, |
| 73 SurfaceTextureTarget type, | |
| 74 scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, | 60 scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, |
| 75 int render_view_id, | 61 int render_view_id, |
| 76 int player_id) { | 62 int player_id) { |
| 77 if (!surface_texture_bridge) | 63 if (!surface_texture_bridge) |
| 78 return; | 64 return; |
| 79 | 65 |
| 80 JNIEnv* env = base::android::AttachCurrentThread(); | 66 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 81 DCHECK(env); | 67 &SetSurfacePeer, surface_texture_bridge, render_process_handle, |
| 82 if (player_in_render_process_) { | 68 render_view_id, player_id)); |
| 83 Java_BrowserProcessSurfaceTexture_establishSurfaceTexturePeer( | |
| 84 env, render_process_handle, type, | |
| 85 surface_texture_bridge->j_surface_texture().obj(), | |
| 86 render_view_id, player_id); | |
| 87 } else { | |
| 88 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | |
| 89 &SetSurfacePeer, surface_texture_bridge, render_process_handle, | |
| 90 render_view_id, player_id)); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 bool SurfaceTexturePeerBrowserImpl::RegisterBrowserProcessSurfaceTexture( | |
| 95 JNIEnv* env) { | |
| 96 return RegisterNativesImpl(env); | |
| 97 } | 69 } |
| 98 | 70 |
| 99 } // namespace content | 71 } // namespace content |
| OLD | NEW |