Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 114420f5 authored by tedbo's avatar tedbo Committed by Android (Google) Code Review
Browse files

Merge "Support for setting a ParcelSurfaceTexture as the MediaPlayer sink."

parents fd1235fc cc5278a3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <gui/SurfaceTextureClient.h>

#include <android_runtime/AndroidRuntime.h>
#include <android_runtime/android_graphics_SurfaceTexture.h>

#include <utils/Log.h>

@@ -27,7 +28,6 @@
#include "android_util_Binder.h"
#include "jni.h"
#include "JNIHelp.h"
#include "SurfaceTexture.h"

// ----------------------------------------------------------------------------

@@ -59,7 +59,7 @@ static void ParcelSurfaceTexture_setISurfaceTexture(
    env->SetIntField(thiz, fields.iSurfaceTexture, (int)iSurfaceTexture.get());
}

static sp<ISurfaceTexture> ParcelSurfaceTexture_getISurfaceTexture(
sp<ISurfaceTexture> ParcelSurfaceTexture_getISurfaceTexture(
        JNIEnv* env, jobject thiz)
{
    sp<ISurfaceTexture> iSurfaceTexture(
+0 −31
Original line number Diff line number Diff line
/*
 * 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_SURFACETEXTURE_H
#define _ANDROID_GRAPHICS_SURFACETEXTURE_H

#include <gui/SurfaceTexture.h>
#include <utils/StrongPointer.h>
#include "jni.h"

namespace android {

/* Gets the underlying SurfaceTexture from a SurfaceTexture Java object. */
sp<SurfaceTexture> SurfaceTexture_getSurfaceTexture(JNIEnv* env, jobject thiz);

} // namespace android

#endif // _ANDROID_GRAPHICS_SURFACETEXTURE_H
+5 −0
Original line number Diff line number Diff line
@@ -23,10 +23,15 @@

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
+4 −0
Original line number Diff line number Diff line
@@ -23,10 +23,14 @@

namespace android {

class SurfaceTexture;

extern sp<ANativeWindow> android_SurfaceTexture_getNativeWindow(
        JNIEnv* env, jobject thiz);
extern bool android_SurfaceTexture_isInstanceOf(JNIEnv* env, jobject thiz);

/* Gets the underlying SurfaceTexture from a SurfaceTexture Java object. */
extern sp<SurfaceTexture> SurfaceTexture_getSurfaceTexture(JNIEnv* env, jobject thiz);

} // namespace android

+27 −6
Original line number Diff line number Diff line
@@ -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;
Loading