diff options
author | tedbo <tedbo@google.com> | 2011-06-14 11:18:30 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-06-14 11:18:30 -0700 |
commit | 114420f5315c72e9cbd41cd4ae7472ef24ef1b94 (patch) | |
tree | 5f7813399474e7bf5715a7f7e41cb608b889ee2a /media | |
parent | fd1235fc34c72cafd1b5aa0ab634804b7e2b41c2 (diff) | |
parent | cc5278a3e258b30903102b718fb1cd832e79bb2b (diff) | |
download | frameworks_base-114420f5315c72e9cbd41cd4ae7472ef24ef1b94.zip frameworks_base-114420f5315c72e9cbd41cd4ae7472ef24ef1b94.tar.gz frameworks_base-114420f5315c72e9cbd41cd4ae7472ef24ef1b94.tar.bz2 |
Merge "Support for setting a ParcelSurfaceTexture as the MediaPlayer sink."
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/MediaPlayer.java | 33 | ||||
-rw-r--r-- | media/jni/android_media_MediaPlayer.cpp | 41 |
2 files changed, 37 insertions, 37 deletions
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java index 8f7dd60..e34d75cc 100644 --- a/media/java/android/media/MediaPlayer.java +++ b/media/java/android/media/MediaPlayer.java @@ -30,6 +30,7 @@ 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; @@ -509,7 +510,7 @@ public class MediaPlayer private int mListenerContext; // accessed by native methods private Surface mSurface; // accessed by native methods private SurfaceHolder mSurfaceHolder; - private SurfaceTexture mSurfaceTexture; // accessed by native methods + private ParcelSurfaceTexture mParcelSurfaceTexture; // accessed by native methods private EventHandler mEventHandler; private PowerManager.WakeLock mWakeLock = null; private boolean mScreenOnWhilePlaying; @@ -541,7 +542,7 @@ public class MediaPlayer /* * Update the MediaPlayer ISurface and ISurfaceTexture. - * Call after updating mSurface and/or mSurfaceTexture. + * Call after updating mSurface and/or mParcelSurfaceTexture. */ private native void _setVideoSurfaceOrSurfaceTexture(); @@ -607,7 +608,7 @@ public class MediaPlayer } else { mSurface = null; } - mSurfaceTexture = null; + mParcelSurfaceTexture = null; _setVideoSurfaceOrSurfaceTexture(); updateSurfaceScreenOn(); } @@ -630,12 +631,32 @@ public class MediaPlayer * program. */ public void setTexture(SurfaceTexture st) { - if (mScreenOnWhilePlaying && st != null && mSurfaceTexture == null) { + ParcelSurfaceTexture pst = null; + if (st != null) { + pst = ParcelSurfaceTexture.fromSurfaceTexture(st); + } + setParcelSurfaceTexture(pst); + } + + /** + * 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 review by API council. + */ + public void setParcelSurfaceTexture(ParcelSurfaceTexture pst) { + if (mScreenOnWhilePlaying && pst != null && mParcelSurfaceTexture == null) { Log.w(TAG, "setScreenOnWhilePlaying(true) is ineffective for SurfaceTexture"); } mSurfaceHolder = null; mSurface = null; - mSurfaceTexture = st; + mParcelSurfaceTexture = pst; _setVideoSurfaceOrSurfaceTexture(); updateSurfaceScreenOn(); } @@ -962,7 +983,7 @@ public class MediaPlayer */ public void setScreenOnWhilePlaying(boolean screenOn) { if (mScreenOnWhilePlaying != screenOn) { - if (screenOn && mSurfaceTexture != null) { + if (screenOn && mParcelSurfaceTexture != null) { Log.w(TAG, "setScreenOnWhilePlaying(true) is ineffective for SurfaceTexture"); } mScreenOnWhilePlaying = screenOn; diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp index b03aa38..5663683 100644 --- a/media/jni/android_media_MediaPlayer.cpp +++ b/media/jni/android_media_MediaPlayer.cpp @@ -30,6 +30,7 @@ #include "jni.h" #include "JNIHelp.h" #include "android_runtime/AndroidRuntime.h" +#include "android_runtime/android_graphics_ParcelSurfaceTexture.h" #include "utils/Errors.h" // for status_t #include "utils/KeyedVector.h" #include "utils/String8.h" @@ -37,7 +38,6 @@ #include "android_util_Binder.h" #include <binder/Parcel.h> -#include <gui/SurfaceTexture.h> #include <gui/ISurfaceTexture.h> #include <surfaceflinger/Surface.h> #include <binder/IPCThreadState.h> @@ -52,11 +52,9 @@ using namespace android; struct fields_t { jfieldID context; jfieldID surface; - jfieldID surfaceTexture; + jfieldID parcelSurfaceTexture; /* actually in android.view.Surface XXX */ jfieldID surface_native; - // actually in android.graphics.SurfaceTexture - jfieldID surfaceTexture_native; jmethodID post_event; }; @@ -130,13 +128,6 @@ static Surface* get_surface(JNIEnv* env, jobject clazz) return (Surface*)env->GetIntField(clazz, fields.surface_native); } -sp<ISurfaceTexture> getSurfaceTexture(JNIEnv* env, jobject clazz) -{ - sp<ISurfaceTexture> surfaceTexture( - (ISurfaceTexture*)env->GetIntField(clazz, fields.surfaceTexture_native)); - return surfaceTexture; -} - static sp<MediaPlayer> getMediaPlayer(JNIEnv* env, jobject thiz) { Mutex::Autolock l(sLock); @@ -257,8 +248,8 @@ static void setVideoSurfaceOrSurfaceTexture( const sp<MediaPlayer>& mp, JNIEnv *env, jobject thiz, const char *prefix) { // The Java MediaPlayer class makes sure that at most one of mSurface and - // mSurfaceTexture is non-null. But just in case, we give priority to - // mSurface over mSurfaceTexture. + // mParcelSurfaceTexture is non-null. But just in case, 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)); @@ -266,10 +257,10 @@ static void setVideoSurfaceOrSurfaceTexture( native_surface.get(), native_surface->getIdentity()); mp->setVideoSurface(native_surface); } else { - jobject surfaceTexture = env->GetObjectField(thiz, fields.surfaceTexture); - if (surfaceTexture != NULL) { + jobject parcelSurfaceTexture = env->GetObjectField(thiz, fields.parcelSurfaceTexture); + if (parcelSurfaceTexture != NULL) { sp<ISurfaceTexture> native_surfaceTexture( - getSurfaceTexture(env, surfaceTexture)); + ParcelSurfaceTexture_getISurfaceTexture(env, parcelSurfaceTexture)); LOGV("%s: texture=%p", prefix, native_surfaceTexture.get()); mp->setVideoSurfaceTexture(native_surfaceTexture); } @@ -610,23 +601,11 @@ android_media_MediaPlayer_native_init(JNIEnv *env) return; } - fields.surfaceTexture = env->GetFieldID(clazz, "mSurfaceTexture", - "Landroid/graphics/SurfaceTexture;"); - if (fields.surfaceTexture == NULL) { - return; - } - - jclass surfaceTexture = env->FindClass("android/graphics/SurfaceTexture"); - if (surfaceTexture == NULL) { + fields.parcelSurfaceTexture = env->GetFieldID(clazz, "mParcelSurfaceTexture", + "Landroid/graphics/ParcelSurfaceTexture;"); + if (fields.parcelSurfaceTexture == NULL) { return; } - - fields.surfaceTexture_native = env->GetFieldID(surfaceTexture, - ANDROID_GRAPHICS_SURFACETEXTURE_JNI_ID, "I"); - if (fields.surfaceTexture_native == NULL) { - return; - } - } static void |