summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Bonkenburg <tedbo@google.com>2011-07-26 09:51:18 -0700
committerTed Bonkenburg <tedbo@google.com>2011-08-11 19:58:25 -0700
commit1ee60119c4fa51ebfa781cf5fdc33f192e8551b8 (patch)
tree2fb0ce22107a1d3f0c73f3bd5d63a877f5a16d44
parent61bb11cfa03abc345f27ec14f63929b6f600edff (diff)
downloadframeworks_base-1ee60119c4fa51ebfa781cf5fdc33f192e8551b8.zip
frameworks_base-1ee60119c4fa51ebfa781cf5fdc33f192e8551b8.tar.gz
frameworks_base-1ee60119c4fa51ebfa781cf5fdc33f192e8551b8.tar.bz2
Remove ParcelSurfaceTexture and update MediaPlayer
This removes the ParcelSurfaceTexture class since that functionality has been folded into Surface.java. The change also updates the MediaPlayer to get rid of setParcelSurfaceTexture() and modifies setTexture() to use the new Surface functionality in order to simplify the code. Change-Id: Iafa75ea3188263928128325d8a726786971b4de4
-rw-r--r--core/jni/Android.mk1
-rw-r--r--core/jni/AndroidRuntime.cpp2
-rw-r--r--core/jni/android/graphics/ParcelSurfaceTexture.cpp165
-rw-r--r--graphics/java/android/graphics/ParcelSurfaceTexture.aidl19
-rw-r--r--graphics/java/android/graphics/ParcelSurfaceTexture.java118
-rw-r--r--include/android_runtime/android_graphics_ParcelSurfaceTexture.h37
-rw-r--r--media/java/android/media/MediaPlayer.java61
-rw-r--r--media/jni/android_media_MediaPlayer.cpp97
-rw-r--r--native/android/native_window.cpp10
9 files changed, 63 insertions, 447 deletions
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 170957c..aece5f0 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -104,7 +104,6 @@ LOCAL_SRC_FILES:= \
android/graphics/NinePatchImpl.cpp \
android/graphics/NinePatchPeeker.cpp \
android/graphics/Paint.cpp \
- android/graphics/ParcelSurfaceTexture.cpp \
android/graphics/Path.cpp \
android/graphics/PathMeasure.cpp \
android/graphics/PathEffect.cpp \
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index 9e46d80..dd7dd86 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -105,7 +105,6 @@ extern int register_android_graphics_ColorFilter(JNIEnv* env);
extern int register_android_graphics_DrawFilter(JNIEnv* env);
extern int register_android_graphics_Matrix(JNIEnv* env);
extern int register_android_graphics_Paint(JNIEnv* env);
-extern int register_android_graphics_ParcelSurfaceTexture(JNIEnv* env);
extern int register_android_graphics_Path(JNIEnv* env);
extern int register_android_graphics_PathMeasure(JNIEnv* env);
extern int register_android_graphics_Picture(JNIEnv*);
@@ -1125,7 +1124,6 @@ static const RegJNIRec gRegJNI[] = {
REG_JNI(register_android_graphics_Movie),
REG_JNI(register_android_graphics_NinePatch),
REG_JNI(register_android_graphics_Paint),
- REG_JNI(register_android_graphics_ParcelSurfaceTexture),
REG_JNI(register_android_graphics_Path),
REG_JNI(register_android_graphics_PathMeasure),
REG_JNI(register_android_graphics_PathEffect),
diff --git a/core/jni/android/graphics/ParcelSurfaceTexture.cpp b/core/jni/android/graphics/ParcelSurfaceTexture.cpp
deleted file mode 100644
index 754485f..0000000
--- a/core/jni/android/graphics/ParcelSurfaceTexture.cpp
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "ParcelSurfaceTexture"
-
-#include <gui/SurfaceTextureClient.h>
-#include <surfaceflinger/Surface.h>
-
-#include <android_runtime/AndroidRuntime.h>
-#include <android_runtime/android_graphics_SurfaceTexture.h>
-#include <android_runtime/android_view_Surface.h>
-
-#include <utils/Log.h>
-
-#include <binder/Parcel.h>
-
-#include "android_util_Binder.h"
-#include "jni.h"
-#include "JNIHelp.h"
-
-// ----------------------------------------------------------------------------
-
-namespace android {
-
-const char* const kParcelSurfaceTextureClassPathName =
- "android/graphics/ParcelSurfaceTexture";
-
-struct fields_t {
- jfieldID iSurfaceTexture;
-};
-static fields_t fields;
-
-#define ANDROID_GRAPHICS_ISURFACETEXTURE_JNI_ID "mISurfaceTexture"
-
-// ----------------------------------------------------------------------------
-
-static void ParcelSurfaceTexture_setISurfaceTexture(
- JNIEnv* env, jobject thiz, const sp<ISurfaceTexture>& iSurfaceTexture)
-{
- ISurfaceTexture* const p =
- (ISurfaceTexture*)env->GetIntField(thiz, fields.iSurfaceTexture);
- if (iSurfaceTexture.get()) {
- iSurfaceTexture->incStrong(thiz);
- }
- if (p) {
- p->decStrong(thiz);
- }
- env->SetIntField(thiz, fields.iSurfaceTexture, (int)iSurfaceTexture.get());
-}
-
-sp<ISurfaceTexture> ParcelSurfaceTexture_getISurfaceTexture(
- JNIEnv* env, jobject thiz)
-{
- sp<ISurfaceTexture> iSurfaceTexture(
- (ISurfaceTexture*)env->GetIntField(thiz, fields.iSurfaceTexture));
- return iSurfaceTexture;
-}
-
-sp<ANativeWindow> android_ParcelSurfaceTexture_getNativeWindow(
- JNIEnv* env, jobject thiz)
-{
- sp<ISurfaceTexture> iSurfaceTexture(
- ParcelSurfaceTexture_getISurfaceTexture(env, thiz));
- sp<SurfaceTextureClient> surfaceTextureClient(iSurfaceTexture != NULL ?
- new SurfaceTextureClient(iSurfaceTexture) : NULL);
- return surfaceTextureClient;
-}
-
-bool android_ParcelSurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz)
-{
- jclass parcelSurfaceTextureClass = env->FindClass(
- kParcelSurfaceTextureClassPathName);
- return env->IsInstanceOf(thiz, parcelSurfaceTextureClass);
-}
-
-// ----------------------------------------------------------------------------
-
-static void ParcelSurfaceTexture_classInit(JNIEnv* env, jclass clazz)
-{
- fields.iSurfaceTexture =
- env->GetFieldID(clazz, ANDROID_GRAPHICS_ISURFACETEXTURE_JNI_ID, "I");
- if (fields.iSurfaceTexture == NULL) {
- LOGE("can't find android/graphics/ParcelSurfaceTexture.%s",
- ANDROID_GRAPHICS_ISURFACETEXTURE_JNI_ID);
- }
-}
-
-static void ParcelSurfaceTexture_initFromSurface(
- JNIEnv* env, jobject thiz, jobject jSurface)
-{
- sp<Surface> surface(Surface_getSurface(env, jSurface));
- sp<ISurfaceTexture> iSurfaceTexture(surface->getSurfaceTexture());
- ParcelSurfaceTexture_setISurfaceTexture(env, thiz, iSurfaceTexture);
-}
-
-static void ParcelSurfaceTexture_initFromSurfaceTexture(
- JNIEnv* env, jobject thiz, jobject jSurfaceTexture)
-{
- sp<ISurfaceTexture> iSurfaceTexture(
- SurfaceTexture_getSurfaceTexture(env, jSurfaceTexture));
- ParcelSurfaceTexture_setISurfaceTexture(env, thiz, iSurfaceTexture);
-}
-
-static void ParcelSurfaceTexture_finalize(JNIEnv* env, jobject thiz)
-{
- ParcelSurfaceTexture_setISurfaceTexture(env, thiz, 0);
-}
-
-static void ParcelSurfaceTexture_writeToParcel(
- JNIEnv* env, jobject thiz, jobject jParcel, jint flags)
-{
- Parcel* parcel = parcelForJavaObject(env, jParcel);
- sp<ISurfaceTexture> iSurfaceTexture(
- ParcelSurfaceTexture_getISurfaceTexture(env, thiz));
- sp<IBinder> b(iSurfaceTexture->asBinder());
- parcel->writeStrongBinder(b);
-}
-
-static void ParcelSurfaceTexture_readFromParcel(
- JNIEnv* env, jobject thiz, jobject jParcel)
-{
- Parcel* parcel = parcelForJavaObject(env, jParcel);
- sp<ISurfaceTexture> iSurfaceTexture(
- interface_cast<ISurfaceTexture>(parcel->readStrongBinder()));
- ParcelSurfaceTexture_setISurfaceTexture(env, thiz, iSurfaceTexture);
-}
-
-// ----------------------------------------------------------------------------
-
-static JNINativeMethod gParcelSurfaceTextureMethods[] = {
- {"nativeClassInit", "()V", (void*)ParcelSurfaceTexture_classInit },
- {"nativeInitFromSurface", "(Landroid/view/Surface;)V",
- (void *)ParcelSurfaceTexture_initFromSurface },
- {"nativeInitFromSurfaceTexture", "(Landroid/graphics/SurfaceTexture;)V",
- (void *)ParcelSurfaceTexture_initFromSurfaceTexture },
- { "nativeFinalize", "()V", (void *)ParcelSurfaceTexture_finalize },
- { "nativeWriteToParcel", "(Landroid/os/Parcel;I)V",
- (void *)ParcelSurfaceTexture_writeToParcel },
- { "nativeReadFromParcel", "(Landroid/os/Parcel;)V",
- (void *)ParcelSurfaceTexture_readFromParcel },
-};
-
-
-int register_android_graphics_ParcelSurfaceTexture(JNIEnv* env)
-{
- int err = 0;
- err = AndroidRuntime::registerNativeMethods(env, kParcelSurfaceTextureClassPathName,
- gParcelSurfaceTextureMethods, NELEM(gParcelSurfaceTextureMethods));
- return err;
-}
-
-} // namespace android
diff --git a/graphics/java/android/graphics/ParcelSurfaceTexture.aidl b/graphics/java/android/graphics/ParcelSurfaceTexture.aidl
deleted file mode 100644
index 35ff285..0000000
--- a/graphics/java/android/graphics/ParcelSurfaceTexture.aidl
+++ /dev/null
@@ -1,19 +0,0 @@
-/**
- * Copyright (c) 2011, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.graphics;
-
-parcelable ParcelSurfaceTexture;
diff --git a/graphics/java/android/graphics/ParcelSurfaceTexture.java b/graphics/java/android/graphics/ParcelSurfaceTexture.java
deleted file mode 100644
index cc8bd02..0000000
--- a/graphics/java/android/graphics/ParcelSurfaceTexture.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.graphics;
-
-import android.graphics.SurfaceTexture;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.view.Surface;
-
-/**
- *
- * @hide Pending review by API council.
- */
-public final class ParcelSurfaceTexture implements Parcelable {
- /**
- * This field is used by native code, do not access or modify.
- *
- * @hide
- */
- @SuppressWarnings({"UnusedDeclaration"})
- private int mISurfaceTexture;
-
- /**
- * Create a new ParcelSurfaceTexture from a Surface
- *
- * @param surface The Surface to create a ParcelSurfaceTexture from.
- *
- * @return Returns a new ParcelSurfaceTexture for the given Surface.
- */
- public static ParcelSurfaceTexture fromSurface(Surface surface) {
- return new ParcelSurfaceTexture(surface);
- }
-
- /**
- * Create a new ParcelSurfaceTexture from a SurfaceTexture
- *
- * @param surfaceTexture The SurfaceTexture to transport.
- *
- * @return Returns a new ParcelSurfaceTexture for the given SurfaceTexture.
- */
- public static ParcelSurfaceTexture fromSurfaceTexture(SurfaceTexture surfaceTexture) {
- return new ParcelSurfaceTexture(surfaceTexture);
- }
-
- /**
- * @see android.os.Parcelable#describeContents()
- */
- @Override
- public int describeContents() {
- return 0;
- }
-
- /**
- * @see android.os.Parcelable#writeToParcel(android.os.Parcel, int)
- */
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- nativeWriteToParcel(dest, flags);
- }
-
- public static final Parcelable.Creator<ParcelSurfaceTexture> CREATOR =
- new Parcelable.Creator<ParcelSurfaceTexture>() {
- @Override
- public ParcelSurfaceTexture createFromParcel(Parcel in) {
- return new ParcelSurfaceTexture(in);
- }
- @Override
- public ParcelSurfaceTexture[] newArray(int size) {
- return new ParcelSurfaceTexture[size];
- }
- };
-
- private ParcelSurfaceTexture(Parcel in) {
- nativeReadFromParcel(in);
- }
- private ParcelSurfaceTexture(Surface surface) {
- nativeInitFromSurface(surface);
- }
- private ParcelSurfaceTexture(SurfaceTexture surfaceTexture) {
- nativeInitFromSurfaceTexture(surfaceTexture);
- }
-
- @Override
- protected void finalize() throws Throwable {
- try {
- nativeFinalize();
- } finally {
- super.finalize();
- }
- }
-
- private native void nativeInitFromSurface(Surface surface);
- private native void nativeInitFromSurfaceTexture(SurfaceTexture surfaceTexture);
- private native void nativeFinalize();
- private native void nativeWriteToParcel(Parcel dest, int flags);
- private native void nativeReadFromParcel(Parcel in);
-
- /*
- * We use a class initializer to allow the native code to cache some
- * field offsets.
- */
- private static native void nativeClassInit();
- static { nativeClassInit(); }
-}
diff --git a/include/android_runtime/android_graphics_ParcelSurfaceTexture.h b/include/android_runtime/android_graphics_ParcelSurfaceTexture.h
deleted file mode 100644
index b94ac9b..0000000
--- a/include/android_runtime/android_graphics_ParcelSurfaceTexture.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _ANDROID_GRAPHICS_PARCELSURFACETEXTURE_H
-#define _ANDROID_GRAPHICS_PARCELSURFACETEXTURE_H
-
-#include <android/native_window.h>
-
-#include "jni.h"
-
-namespace android {
-
-class ISurfaceTexture;
-
-extern sp<ANativeWindow> android_ParcelSurfaceTexture_getNativeWindow(
- JNIEnv* env, jobject thiz);
-extern bool android_ParcelSurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz);
-
-/* Gets the underlying ISurfaceTexture from a ParcelSurfaceTexture Java object. */
-extern sp<ISurfaceTexture> ParcelSurfaceTexture_getISurfaceTexture(JNIEnv* env, jobject thiz);
-
-} // namespace android
-
-#endif // _ANDROID_GRAPHICS_PARCELSURFACETEXTURE_H
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index 434ef14..66bd56a 100644
--- a/media/java/android/media/MediaPlayer.java
+++ b/media/java/android/media/MediaPlayer.java
@@ -30,7 +30,6 @@ import android.util.Log;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.graphics.Bitmap;
-import android.graphics.ParcelSurfaceTexture;
import android.graphics.SurfaceTexture;
import android.media.AudioManager;
@@ -527,10 +526,9 @@ public class MediaPlayer
private final static String IMEDIA_PLAYER = "android.media.IMediaPlayer";
private int mNativeContext; // accessed by native methods
+ private int mNativeSurfaceTexture; // accessed by native methods
private int mListenerContext; // accessed by native methods
- private Surface mSurface; // accessed by native methods
- private SurfaceHolder mSurfaceHolder;
- private ParcelSurfaceTexture mParcelSurfaceTexture; // accessed by native methods
+ private SurfaceHolder mSurfaceHolder;
private EventHandler mEventHandler;
private PowerManager.WakeLock mWakeLock = null;
private boolean mScreenOnWhilePlaying;
@@ -561,10 +559,10 @@ public class MediaPlayer
}
/*
- * Update the MediaPlayer ISurface and ISurfaceTexture.
- * Call after updating mSurface and/or mParcelSurfaceTexture.
+ * Update the MediaPlayer SurfaceTexture.
+ * Call after setting a new display surface.
*/
- private native void _setVideoSurfaceOrSurfaceTexture();
+ private native void _setVideoSurface(Surface surface);
/**
* Create a request parcel which can be routed to the native media
@@ -619,13 +617,13 @@ public class MediaPlayer
*/
public void setDisplay(SurfaceHolder sh) {
mSurfaceHolder = sh;
+ Surface surface;
if (sh != null) {
- mSurface = sh.getSurface();
+ surface = sh.getSurface();
} else {
- mSurface = null;
+ surface = null;
}
- mParcelSurfaceTexture = null;
- _setVideoSurfaceOrSurfaceTexture();
+ _setVideoSurface(surface);
updateSurfaceScreenOn();
}
@@ -641,13 +639,11 @@ public class MediaPlayer
* @hide Pending review by API council.
*/
public void setSurface(Surface surface) {
- if (mScreenOnWhilePlaying && surface != null && mSurface != null) {
+ if (mScreenOnWhilePlaying && surface != null) {
Log.w(TAG, "setScreenOnWhilePlaying(true) is ineffective for Surface");
}
mSurfaceHolder = null;
- mSurface = surface;
- mParcelSurfaceTexture = null; // TODO(tedbo): Remove.
- _setVideoSurfaceOrSurfaceTexture();
+ _setVideoSurface(surface);
updateSurfaceScreenOn();
}
@@ -670,34 +666,19 @@ public class MediaPlayer
* by time-of-day adjustments, but is reset when the position is set.
*/
public void setTexture(SurfaceTexture st) {
- ParcelSurfaceTexture pst = null;
+ // TODO: This method should be hidden before it is published and setSurface
+ // should be unhidden and made public instead.
if (st != null) {
- pst = ParcelSurfaceTexture.fromSurfaceTexture(st);
- }
- setParcelSurfaceTexture(pst);
- }
+ Surface surface = new Surface(st);
+ setSurface(surface);
- /**
- * Sets the {@link ParcelSurfaceTexture} to be used as the sink for the video portion of
- * the media. This is similar to {@link #setTexture(SurfaceTexture)}, but supports using
- * a {@link ParcelSurfaceTexture} to transport the texture to be used via Binder. Setting
- * a parceled surface texture will un-set any surface or surface texture that was previously
- * set. See {@link #setTexture(SurfaceTexture)} for more details.
- *
- * @param pst The {@link ParcelSurfaceTexture} to be used as the sink for
- * the video portion of the media.
- *
- * @hide Pending removal when there are no more callers.
- */
- public void setParcelSurfaceTexture(ParcelSurfaceTexture pst) {
- if (mScreenOnWhilePlaying && pst != null && mParcelSurfaceTexture == null) {
- Log.w(TAG, "setScreenOnWhilePlaying(true) is ineffective for SurfaceTexture");
+ // It is safe and desired to release the newly created Surface here since the
+ // native code will grab a reference to the underlying ISurfaceTexture. At that
+ // point the Surface we just created is no longer needed.
+ surface.release();
+ } else {
+ setSurface(null);
}
- mSurfaceHolder = null;
- mSurface = null;
- mParcelSurfaceTexture = pst;
- _setVideoSurfaceOrSurfaceTexture();
- updateSurfaceScreenOn();
}
/**
diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp
index 9090daa..13ed152 100644
--- a/media/jni/android_media_MediaPlayer.cpp
+++ b/media/jni/android_media_MediaPlayer.cpp
@@ -30,7 +30,7 @@
#include "jni.h"
#include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h"
-#include "android_runtime/android_graphics_ParcelSurfaceTexture.h"
+#include "android_runtime/android_view_Surface.h"
#include "utils/Errors.h" // for status_t
#include "utils/KeyedVector.h"
#include "utils/String8.h"
@@ -51,10 +51,7 @@ using namespace android;
struct fields_t {
jfieldID context;
- jfieldID surface;
- jfieldID parcelSurfaceTexture;
- /* actually in android.view.Surface XXX */
- jfieldID surface_native;
+ jfieldID surface_texture;
jmethodID post_event;
};
@@ -123,11 +120,6 @@ void JNIMediaPlayerListener::notify(int msg, int ext1, int ext2, const Parcel *o
// ----------------------------------------------------------------------------
-static Surface* get_surface(JNIEnv* env, jobject clazz)
-{
- return (Surface*)env->GetIntField(clazz, fields.surface_native);
-}
-
static sp<MediaPlayer> getMediaPlayer(JNIEnv* env, jobject thiz)
{
Mutex::Autolock l(sLock);
@@ -244,40 +236,38 @@ android_media_MediaPlayer_setDataSourceFD(JNIEnv *env, jobject thiz, jobject fil
process_media_player_call( env, thiz, mp->setDataSource(fd, offset, length), "java/io/IOException", "setDataSourceFD failed." );
}
-static void setVideoSurfaceOrSurfaceTexture(
- const sp<MediaPlayer>& mp, JNIEnv *env, jobject thiz, const char *prefix)
-{
- // Both mSurface and mParcelSurfaceTexture could be null.
- // We give priority to mSurface over mParcelSurfaceTexture.
- jobject surface = env->GetObjectField(thiz, fields.surface);
- if (surface != NULL) {
- sp<Surface> native_surface(get_surface(env, surface));
- LOGV("%s: surface=%p (id=%d)", prefix,
- native_surface.get(), native_surface->getIdentity());
- mp->setVideoSurface(native_surface);
- } else {
- jobject parcelSurfaceTexture = env->GetObjectField(thiz, fields.parcelSurfaceTexture);
- if (parcelSurfaceTexture != NULL) {
- sp<ISurfaceTexture> native_surfaceTexture(
- ParcelSurfaceTexture_getISurfaceTexture(env, parcelSurfaceTexture));
- LOGV("%s: texture=%p", prefix, native_surfaceTexture.get());
- mp->setVideoSurfaceTexture(native_surfaceTexture);
- } else {
- mp->setVideoSurfaceTexture(NULL);
- }
- }
+static sp<ISurfaceTexture>
+getVideoSurfaceTexture(JNIEnv* env, jobject thiz) {
+ ISurfaceTexture * const p = (ISurfaceTexture*)env->GetIntField(thiz, fields.surface_texture);
+ return sp<ISurfaceTexture>(p);
}
static void
-android_media_MediaPlayer_setVideoSurfaceOrSurfaceTexture(JNIEnv *env, jobject thiz)
+android_media_MediaPlayer_setVideoSurface(JNIEnv *env, jobject thiz, jobject jsurface)
{
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
if (mp == NULL ) {
jniThrowException(env, "java/lang/IllegalStateException", NULL);
return;
}
- setVideoSurfaceOrSurfaceTexture(mp, env, thiz,
- "_setVideoSurfaceOrSurfaceTexture");
+
+ sp<ISurfaceTexture> old_st = getVideoSurfaceTexture(env, thiz);
+ sp<ISurfaceTexture> new_st;
+ if (jsurface) {
+ sp<Surface> surface(Surface_getSurface(env, jsurface));
+ new_st = surface->getSurfaceTexture();
+ new_st->incStrong(thiz);
+ }
+ if (old_st != NULL) {
+ old_st->decStrong(thiz);
+ }
+ env->SetIntField(thiz, fields.surface_texture, (int)new_st.get());
+
+ // This will fail if the media player has not been initialized yet. This
+ // can be the case if setDisplay() on MediaPlayer.java has been called
+ // before setDataSource(). The redundant call to setVideoSurfaceTexture()
+ // in prepare/prepareAsync covers for this case.
+ mp->setVideoSurfaceTexture(new_st);
}
static void
@@ -288,7 +278,12 @@ android_media_MediaPlayer_prepare(JNIEnv *env, jobject thiz)
jniThrowException(env, "java/lang/IllegalStateException", NULL);
return;
}
- setVideoSurfaceOrSurfaceTexture(mp, env, thiz, "prepare");
+
+ // Handle the case where the display surface was set before the mp was
+ // initialized. We try again to make it stick.
+ sp<ISurfaceTexture> st = getVideoSurfaceTexture(env, thiz);
+ mp->setVideoSurfaceTexture(st);
+
process_media_player_call( env, thiz, mp->prepare(), "java/io/IOException", "Prepare failed." );
}
@@ -300,7 +295,12 @@ android_media_MediaPlayer_prepareAsync(JNIEnv *env, jobject thiz)
jniThrowException(env, "java/lang/IllegalStateException", NULL);
return;
}
- setVideoSurfaceOrSurfaceTexture(mp, env, thiz, "prepareAsync");
+
+ // Handle the case where the display surface was set before the mp was
+ // initialized. We try again to make it stick.
+ sp<ISurfaceTexture> st = getVideoSurfaceTexture(env, thiz);
+ mp->setVideoSurfaceTexture(st);
+
process_media_player_call( env, thiz, mp->prepareAsync(), "java/io/IOException", "Prepare Async failed." );
}
@@ -587,24 +587,8 @@ android_media_MediaPlayer_native_init(JNIEnv *env)
return;
}
- fields.surface = env->GetFieldID(clazz, "mSurface", "Landroid/view/Surface;");
- if (fields.surface == NULL) {
- return;
- }
-
- jclass surface = env->FindClass("android/view/Surface");
- if (surface == NULL) {
- return;
- }
-
- fields.surface_native = env->GetFieldID(surface, ANDROID_VIEW_SURFACE_JNI_ID, "I");
- if (fields.surface_native == NULL) {
- return;
- }
-
- fields.parcelSurfaceTexture = env->GetFieldID(clazz, "mParcelSurfaceTexture",
- "Landroid/graphics/ParcelSurfaceTexture;");
- if (fields.parcelSurfaceTexture == NULL) {
+ fields.surface_texture = env->GetFieldID(clazz, "mNativeSurfaceTexture", "I");
+ if (fields.surface_texture == NULL) {
return;
}
}
@@ -643,6 +627,7 @@ static void
android_media_MediaPlayer_native_finalize(JNIEnv *env, jobject thiz)
{
LOGV("native_finalize");
+ android_media_MediaPlayer_setVideoSurface(env, thiz, NULL);
android_media_MediaPlayer_release(env, thiz);
}
@@ -749,7 +734,7 @@ static JNINativeMethod gMethods[] = {
},
{"setDataSource", "(Ljava/io/FileDescriptor;JJ)V", (void *)android_media_MediaPlayer_setDataSourceFD},
- {"_setVideoSurfaceOrSurfaceTexture", "()V", (void *)android_media_MediaPlayer_setVideoSurfaceOrSurfaceTexture},
+ {"_setVideoSurface", "(Landroid/view/Surface;)V", (void *)android_media_MediaPlayer_setVideoSurface},
{"prepare", "()V", (void *)android_media_MediaPlayer_prepare},
{"prepareAsync", "()V", (void *)android_media_MediaPlayer_prepareAsync},
{"_start", "()V", (void *)android_media_MediaPlayer_start},
diff --git a/native/android/native_window.cpp b/native/android/native_window.cpp
index 36fc9bf..d266fc6 100644
--- a/native/android/native_window.cpp
+++ b/native/android/native_window.cpp
@@ -20,20 +20,12 @@
#include <android/native_window_jni.h>
#include <surfaceflinger/Surface.h>
#include <android_runtime/android_view_Surface.h>
-#include <android_runtime/android_graphics_ParcelSurfaceTexture.h>
#include <android_runtime/android_graphics_SurfaceTexture.h>
using namespace android;
ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface) {
- sp<ANativeWindow> win;
- if (android_Surface_isInstanceOf(env, surface)) {
- win = android_Surface_getNativeWindow(env, surface);
- } else if (android_SurfaceTexture_isInstanceOf(env, surface)) {
- win = android_SurfaceTexture_getNativeWindow(env, surface);
- } else if (android_ParcelSurfaceTexture_isInstanceOf(env, surface)) {
- win = android_ParcelSurfaceTexture_getNativeWindow(env, surface);
- }
+ sp<ANativeWindow> win = android_Surface_getNativeWindow(env, surface);
if (win != NULL) {
win->incStrong((void*)ANativeWindow_acquire);
}