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 "base/android/jni_android.h" | |
7 #include "content/browser/android/media_player_manager_android.h" | 8 #include "content/browser/android/media_player_manager_android.h" |
8 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
9 #include "content/common/android/surface_callback.h" | 10 #include "content/common/android/surface.h" |
10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
11 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
12 #include "jni/BrowserProcessSurfaceTexture_jni.h" | |
13 #include "media/base/android/media_player_bridge.h" | 13 #include "media/base/android/media_player_bridge.h" |
14 | 14 |
15 using base::android::MethodID; | 15 using base::android::MethodID; |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 | 18 |
19 // Pass a java surface object to the MediaPlayerBridge object | 19 // Pass a java surface object to the MediaPlayerBridge object |
20 // identified by render process handle, render view ID and player ID. | 20 // identified by render process handle, render view ID and player ID. |
21 static void SetSurfacePeer( | 21 static void SetSurfacePeer( |
22 scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, | 22 scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, |
(...skipping 13 matching lines...) Expand all Loading... | |
36 JNIEnv* env = base::android::AttachCurrentThread(); | 36 JNIEnv* env = base::android::AttachCurrentThread(); |
37 DCHECK(env); | 37 DCHECK(env); |
38 if (renderer_id) { | 38 if (renderer_id) { |
39 RenderViewHostImpl* host = RenderViewHostImpl::FromID( | 39 RenderViewHostImpl* host = RenderViewHostImpl::FromID( |
40 renderer_id, render_view_id); | 40 renderer_id, render_view_id); |
41 if (host) { | 41 if (host) { |
42 media::MediaPlayerBridge* player = | 42 media::MediaPlayerBridge* player = |
43 host->media_player_manager()->GetPlayer(player_id); | 43 host->media_player_manager()->GetPlayer(player_id); |
44 if (player && | 44 if (player && |
45 player != host->media_player_manager()->GetFullscreenPlayer()) { | 45 player != host->media_player_manager()->GetFullscreenPlayer()) { |
46 base::android::ScopedJavaLocalRef<jclass> cls( | 46 Surface surface(surface_texture_bridge->j_surface_texture()); |
47 base::android::GetClass(env, "android/view/Surface")); | 47 player->SetVideoSurface(surface.j_surface().obj()); |
bulach
2013/03/04 10:44:51
I don't quite understand your concerns here, my ma
| |
48 jmethodID constructor = MethodID::Get<MethodID::TYPE_INSTANCE>( | 48 surface.Release(); |
bulach
2013/03/04 10:44:51
ok, so if you don't agree with the above :)
"Rele
| |
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 } | 49 } |
57 } | 50 } |
58 } | 51 } |
59 } | 52 } |
60 | 53 |
61 SurfaceTexturePeerBrowserImpl::SurfaceTexturePeerBrowserImpl( | 54 SurfaceTexturePeerBrowserImpl::SurfaceTexturePeerBrowserImpl() { |
62 bool player_in_render_process) | |
63 : player_in_render_process_(player_in_render_process) { | |
64 } | 55 } |
65 | 56 |
66 SurfaceTexturePeerBrowserImpl::~SurfaceTexturePeerBrowserImpl() { | 57 SurfaceTexturePeerBrowserImpl::~SurfaceTexturePeerBrowserImpl() { |
67 if (surface_.obj()) | |
68 ReleaseSurface(surface_.obj()); | |
69 } | 58 } |
70 | 59 |
71 void SurfaceTexturePeerBrowserImpl::EstablishSurfaceTexturePeer( | 60 void SurfaceTexturePeerBrowserImpl::EstablishSurfaceTexturePeer( |
72 base::ProcessHandle render_process_handle, | 61 base::ProcessHandle render_process_handle, |
73 SurfaceTextureTarget type, | 62 SurfaceTextureTarget type, |
74 scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, | 63 scoped_refptr<SurfaceTextureBridge> surface_texture_bridge, |
75 int render_view_id, | 64 int render_view_id, |
76 int player_id) { | 65 int player_id) { |
77 if (!surface_texture_bridge) | 66 if (!surface_texture_bridge) |
78 return; | 67 return; |
79 | 68 |
80 JNIEnv* env = base::android::AttachCurrentThread(); | 69 JNIEnv* env = base::android::AttachCurrentThread(); |
81 DCHECK(env); | 70 DCHECK(env); |
82 if (player_in_render_process_) { | 71 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
83 Java_BrowserProcessSurfaceTexture_establishSurfaceTexturePeer( | 72 &SetSurfacePeer, surface_texture_bridge, render_process_handle, |
84 env, render_process_handle, type, | 73 render_view_id, player_id)); |
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 } | 74 } |
98 | 75 |
99 } // namespace content | 76 } // namespace content |
OLD | NEW |