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

Side by Side Diff: content/browser/android/surface_texture_peer_browser_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 and resolving merge conflicts 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 "content/browser/android/surface_texture_peer_browser_impl.h"
6
7 #include "content/browser/android/media_player_manager_android.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/common/android/surface_callback.h"
10 #include "content/public/browser/browser_thread.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"
14
15 namespace content {
16
17 // Pass a java surface object to the MediaPlayerBridge object
18 // identified by render process handle, render view ID and player ID.
19 static void SetSurfacePeer(jobject j_surface,
20 base::ProcessHandle render_process_handle,
21 int render_view_id,
22 int player_id) {
23 int renderer_id = 0;
24 RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
25 while (!it.IsAtEnd()) {
26 if (it.GetCurrentValue()->GetHandle() == render_process_handle) {
27 renderer_id = it.GetCurrentValue()->GetID();
28 break;
29 }
30 it.Advance();
31 }
32
33 JNIEnv* env = base::android::AttachCurrentThread();
34 DCHECK(env);
35 if (renderer_id) {
36 RenderViewHostImpl* host = RenderViewHostImpl::FromID(
37 renderer_id, render_view_id);
38 if (host) {
39 media::MediaPlayerBridge* player =
40 host->media_player_manager()->GetPlayer(player_id);
41 if (player) {
42 player->SetVideoSurface(j_surface);
43 }
44 }
45 }
46
47 ReleaseSurface(j_surface);
48 env->DeleteGlobalRef(j_surface);
49 }
50
51 SurfaceTexturePeerBrowserImpl::SurfaceTexturePeerBrowserImpl(
52 bool player_in_render_process)
53 : player_in_render_process_(player_in_render_process) {
54 }
55
56 SurfaceTexturePeerBrowserImpl::~SurfaceTexturePeerBrowserImpl() {
57 if (surface_.obj())
58 ReleaseSurface(surface_.obj());
59 }
60
61 void SurfaceTexturePeerBrowserImpl::EstablishSurfaceTexturePeer(
62 base::ProcessHandle render_process_handle,
63 SurfaceTextureTarget type,
64 jobject j_surface_texture,
65 int render_view_id,
66 int player_id) {
67 if (j_surface_texture == NULL)
68 return;
69
70 JNIEnv* env = base::android::AttachCurrentThread();
71 DCHECK(env);
72 if (player_in_render_process_) {
73 Java_BrowserProcessSurfaceTexture_establishSurfaceTexturePeer(
74 env, render_process_handle, type, j_surface_texture,
75 render_view_id, player_id);
76 } else {
77 base::android::ScopedJavaLocalRef<jclass> cls(
78 base::android::GetClass(env, "android/view/Surface"));
79 jmethodID constructor = GetMethodID(env, cls, "<init>",
80 "(Landroid/graphics/SurfaceTexture;)V");
81 ScopedJavaLocalRef<jobject> tmp(env,
82 env->NewObject(cls.obj(), constructor, j_surface_texture));
83 jobject surface = env->NewGlobalRef(tmp.obj());
84
85 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
86 &SetSurfacePeer, surface, render_process_handle, render_view_id,
87 player_id));
88 }
89 }
90
91 bool SurfaceTexturePeerBrowserImpl::RegisterBrowserProcessSurfaceTexture(
92 JNIEnv* env) {
93 return RegisterNativesImpl(env);
94 }
95
96 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/surface_texture_peer_browser_impl.h ('k') | content/browser/browser_main_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698