OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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/external_video_surface_view_holder.h" |
| 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" |
| 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "base/bind.h" |
| 11 #include "base/lazy_instance.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/message_loop.h" |
| 14 #include "jni/ExternalVideoSurfaceViewHolder_jni.h" |
| 15 #include "media/base/android/media_player_bridge.h" |
| 16 |
| 17 using base::android::AttachCurrentThread; |
| 18 using media::MediaPlayerBridge; |
| 19 |
| 20 namespace content { |
| 21 |
| 22 // static |
| 23 bool ExternalVideoSurfaceViewHolder::RegisterExternalVideoSurfaceViewHolder( |
| 24 JNIEnv* env) { |
| 25 return RegisterNativesImpl(env); |
| 26 } |
| 27 |
| 28 ExternalVideoSurfaceViewHolder::ExternalVideoSurfaceViewHolder(JNIEnv* env, |
| 29 jobject obj) |
| 30 : java_ref_(env, obj), |
| 31 player_(NULL) { |
| 32 } |
| 33 |
| 34 ExternalVideoSurfaceViewHolder::~ExternalVideoSurfaceViewHolder() { |
| 35 } |
| 36 |
| 37 void ExternalVideoSurfaceViewHolder::registerPlayer(MediaPlayerBridge* player) { |
| 38 DCHECK(player); |
| 39 |
| 40 if (player_) { |
| 41 unregisterPlayer(player_); |
| 42 } |
| 43 player_ = player; |
| 44 |
| 45 JNIEnv* env = AttachCurrentThread(); |
| 46 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 47 if (obj.is_null()) |
| 48 return; |
| 49 Java_ExternalVideoSurfaceViewHolder_requestExternalVideoSurface( |
| 50 env, obj.obj()); |
| 51 } |
| 52 |
| 53 void ExternalVideoSurfaceViewHolder::unregisterPlayer( |
| 54 MediaPlayerBridge* player) { |
| 55 if (player_ == player) { |
| 56 player_->SetVideoSurface(NULL); |
| 57 player_ = NULL; |
| 58 } |
| 59 } |
| 60 |
| 61 // static |
| 62 jint Init(JNIEnv* env, jobject obj) { |
| 63 ExternalVideoSurfaceViewHolder* external_video_surface_view_holder = |
| 64 new ExternalVideoSurfaceViewHolder(env, obj); |
| 65 return reinterpret_cast<jint>(external_video_surface_view_holder); |
| 66 } |
| 67 |
| 68 void ExternalVideoSurfaceViewHolder::Destroy(JNIEnv* env, jobject obj) { |
| 69 delete this; |
| 70 } |
| 71 |
| 72 void ExternalVideoSurfaceViewHolder::AttachExternalVideoSurface( |
| 73 JNIEnv* env, jobject obj, jobject jsurface) { |
| 74 if (player_) |
| 75 player_->SetVideoSurface(jsurface); |
| 76 } |
| 77 |
| 78 void ExternalVideoSurfaceViewHolder::DetachExternalVideoSurface( |
| 79 JNIEnv* env, jobject obj) { |
| 80 if (player_) |
| 81 player_->SetVideoSurface(NULL); |
| 82 } |
| 83 |
| 84 } // namespace content |
OLD | NEW |