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

Commit 9fb2c5f8 authored by Carlos Martinez Romero's avatar Carlos Martinez Romero Committed by Android (Google) Code Review
Browse files

Merge "Replace IGBP references for Surface in MediaRecorder." into main

parents bc1f004b 1d4bf54d
Loading
Loading
Loading
Loading
+22 −27
Original line number Diff line number Diff line
@@ -376,14 +376,13 @@ status_t JMediaCodec::setCallback(jobject cb) {

status_t JMediaCodec::configure(
        const sp<AMessage> &format,
        const sp<IGraphicBufferProducer> &bufferProducer,
        const sp<MediaSurfaceType> &surface,
        const sp<ICrypto> &crypto,
        const sp<IDescrambler> &descrambler,
        int flags) {
    sp<Surface> client;
    if (bufferProducer != NULL) {
        mSurfaceTextureClient =
            new Surface(bufferProducer, true /* controlledByApp */);
    if (surface != NULL) {
        mSurfaceTextureClient = mediaflagtools::surfaceTypeToSurface(surface, true);
    } else {
        mSurfaceTextureClient.clear();
    }
@@ -400,11 +399,10 @@ status_t JMediaCodec::configure(
            format, mSurfaceTextureClient, crypto, descrambler, flags);
}

status_t JMediaCodec::setSurface(
        const sp<IGraphicBufferProducer> &bufferProducer) {
status_t JMediaCodec::setSurface(const sp<MediaSurfaceType> &surface) {
    sp<Surface> client;
    if (bufferProducer != NULL) {
        client = new Surface(bufferProducer, true /* controlledByApp */);
    if (surface != NULL) {
        client = mediaflagtools::surfaceTypeToSurface(surface, true);
    }
    status_t err = mCodec->setSurface(client);
    if (err == OK) {
@@ -421,9 +419,8 @@ status_t JMediaCodec::detachOutputSurface() {
    return err;
}

status_t JMediaCodec::createInputSurface(
        sp<IGraphicBufferProducer>* bufferProducer) {
    return mCodec->createInputSurface(bufferProducer);
status_t JMediaCodec::createInputSurface(sp<IGraphicBufferProducer>* surface) {
    return mCodec->createInputSurface(surface);
}

status_t JMediaCodec::setInputSurface(
@@ -1841,11 +1838,11 @@ static void android_media_MediaCodec_native_configure(
        return;
    }

    sp<IGraphicBufferProducer> bufferProducer;
    sp<MediaSurfaceType> surface;
    if (jsurface != NULL) {
        sp<Surface> surface(android_view_Surface_getSurface(env, jsurface));
        if (surface != NULL) {
            bufferProducer = surface->getIGraphicBufferProducer();
        sp<Surface> tempSurface(android_view_Surface_getSurface(env, jsurface));
        if (tempSurface != NULL) {
            surface = mediaflagtools::surfaceToSurfaceType(tempSurface);
        } else {
            jniThrowException(
                    env,
@@ -1865,7 +1862,7 @@ static void android_media_MediaCodec_native_configure(
        descrambler = GetDescrambler(env, descramblerBinderObj);
    }

    err = codec->configure(format, bufferProducer, crypto, descrambler, flags);
    err = codec->configure(format, surface, crypto, descrambler, flags);

    throwExceptionAsNecessary(env, err, codec);
}
@@ -1881,11 +1878,11 @@ static void android_media_MediaCodec_native_setSurface(
        return;
    }

    sp<IGraphicBufferProducer> bufferProducer;
    sp<MediaSurfaceType> surface;
    if (jsurface != NULL) {
        sp<Surface> surface(android_view_Surface_getSurface(env, jsurface));
        if (surface != NULL) {
            bufferProducer = surface->getIGraphicBufferProducer();
        sp<Surface> tempSurface(android_view_Surface_getSurface(env, jsurface));
        if (tempSurface != NULL) {
            surface = mediaflagtools::surfaceToSurfaceType(tempSurface);
        } else {
            jniThrowException(
                    env,
@@ -1895,7 +1892,7 @@ static void android_media_MediaCodec_native_setSurface(
        }
    }

    status_t err = codec->setSurface(bufferProducer);
    status_t err = codec->setSurface(surface);
    throwExceptionAsNecessary(env, err, codec);
}

@@ -1940,8 +1937,7 @@ static jobject android_media_MediaCodec_createPersistentInputSurface(
        return NULL;
    }

    sp<Surface> surface = new Surface(
            persistentSurface->getBufferProducer(), true);
    sp<Surface> surface = sp<Surface>::make(persistentSurface->getBufferProducer(), true);
    if (surface == NULL) {
        return NULL;
    }
@@ -2043,16 +2039,15 @@ static jobject android_media_MediaCodec_createInputSurface(JNIEnv* env,
    }

    // Tell the MediaCodec that we want to use a Surface as input.
    sp<IGraphicBufferProducer> bufferProducer;
    status_t err = codec->createInputSurface(&bufferProducer);
    sp<IGraphicBufferProducer> surface;
    status_t err = codec->createInputSurface(&surface);
    if (err != NO_ERROR) {
        throwExceptionAsNecessary(env, err, codec);
        return NULL;
    }

    // Wrap the IGBP in a Java-language Surface.
    return android_view_Surface_createFromIGraphicBufferProducer(env,
            bufferProducer);
    return android_view_Surface_createFromIGraphicBufferProducer(env, surface);
}

static void android_media_MediaCodec_start(JNIEnv *env, jobject thiz) {
+4 −5
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@

#include <C2Buffer.h>
#include <binder/MemoryHeapBase.h>
#include <gui/Flags.h> // Remove with MediaSurfaceType
#include <media/MediaCodecBuffer.h>
#include <media/MediaMetricsItem.h>
#include <media/hardware/CryptoAPI.h>
@@ -40,7 +41,6 @@ struct ALooper;
struct AMessage;
struct AString;
struct ICrypto;
class IGraphicBufferProducer;
struct MediaCodec;
struct PersistentSurface;
class Surface;
@@ -72,17 +72,16 @@ struct JMediaCodec : public AHandler {

    status_t configure(
            const sp<AMessage> &format,
            const sp<IGraphicBufferProducer> &bufferProducer,
            const sp<MediaSurfaceType> &surface,
            const sp<ICrypto> &crypto,
            const sp<IDescrambler> &descrambler,
            int flags);

    status_t setSurface(
            const sp<IGraphicBufferProducer> &surface);
    status_t setSurface(const sp<MediaSurfaceType> &surface);

    status_t detachOutputSurface();

    status_t createInputSurface(sp<IGraphicBufferProducer>* bufferProducer);
    status_t createInputSurface(sp<IGraphicBufferProducer>* surface);
    status_t setInputSurface(const sp<PersistentSurface> &surface);

    status_t start();
+17 −6
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@
#include <android_runtime/android_view_Surface.h>
#include <android/content/AttributionSourceState.h>
#include <android_os_Parcel.h>
#include <com_android_graphics_libgui_flags.h> // Remove with WB_MEDIA_MIGRATION.

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

@@ -457,7 +458,17 @@ android_media_MediaRecorder_prepare(JNIEnv *env, jobject thiz)
        }

        ALOGI("prepare: surface=%p", native_surface.get());
        if (process_media_recorder_call(env, mr->setPreviewSurface(native_surface->getIGraphicBufferProducer()), "java/lang/RuntimeException", "setPreviewSurface failed.")) {

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
        const sp<Surface> &preview_surface = native_surface;
#else
        const sp<IGraphicBufferProducer> preview_surface =
                native_surface->getIGraphicBufferProducer();
#endif

        if (process_media_recorder_call(env, mr->setPreviewSurface(preview_surface),
                                        "java/lang/RuntimeException",
                                        "setPreviewSurface failed.")) {
            return;
        }
    }
@@ -488,8 +499,8 @@ android_media_MediaRecorder_getSurface(JNIEnv *env, jobject thiz)
        return NULL;
    }

    sp<IGraphicBufferProducer> bufferProducer = mr->querySurfaceMediaSourceFromMediaServer();
    if (bufferProducer == NULL) {
    sp<MediaSurfaceType> qSurface = mr->querySurfaceMediaSourceFromMediaServer();
    if (qSurface == NULL) {
        jniThrowException(
                env,
                "java/lang/IllegalStateException",
@@ -497,9 +508,9 @@ android_media_MediaRecorder_getSurface(JNIEnv *env, jobject thiz)
        return NULL;
    }

    // Wrap the IGBP in a Java-language Surface.
    return android_view_Surface_createFromIGraphicBufferProducer(env,
            bufferProducer);
    // This will be removed once the flag is disabled, with the wb_media flag this is a no op.
    sp<Surface> surface = sp<Surface>::make(mediaflagtools::surfaceTypeToIGBP(qSurface), true);
    return android_view_Surface_createFromSurface(env, surface);
}

static void
+20 −7
Original line number Diff line number Diff line
@@ -23,19 +23,23 @@
#include "native/core/gl_env.h"
#include <media/mediarecorder.h>

#include <gui/IGraphicBufferProducer.h>
#include <gui/Flags.h> // Remove with MediaSurfaceType and WB_MEDIA_MIGRATION.

#include <gui/Surface.h>
#include <gui/view/Surface.h>
#include <utils/Errors.h>
#include <system/window.h>


using android::filterfw::GLEnv;
using android::filterfw::WindowHandle;
using android::MediaRecorder;
using android::sp;
using android::IGraphicBufferProducer;
using android::Surface;

#if not COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
#include <gui/IGraphicBufferProducer.h>
using android::IGraphicBufferProducer;
#endif

class NativeWindowHandle : public WindowHandle {
  public:
@@ -285,6 +289,15 @@ jint Java_android_filterfw_core_GLEnvironment_nativeAddSurfaceFromMediaRecorder(
    // Ask the mediarecorder to return a handle to a surfacemediasource
    // This will talk to the StageFrightRecorder via MediaRecorderClient
    // over binder calls

#if COM_ANDROID_GRAPHICS_LIBGUI_FLAGS(WB_MEDIA_MIGRATION)
    sp<Surface> surfaceTC = mr->querySurfaceMediaSourceFromMediaServer();
    if (surfaceTC == nullptr) {
        ALOGE("GLEnvironment: Error- MediaRecorder returned a null \
                <IGraphicBufferProducer> handle.");
        return -1;
    }
#else
    sp<IGraphicBufferProducer> surfaceMS = mr->querySurfaceMediaSourceFromMediaServer();
    if (surfaceMS == NULL) {
        ALOGE("GLEnvironment: Error- MediaRecorder returned a null \
@@ -292,10 +305,10 @@ jint Java_android_filterfw_core_GLEnvironment_nativeAddSurfaceFromMediaRecorder(
        return -1;
    }
    sp<Surface> surfaceTC = new Surface(surfaceMS);
#endif
    // Get the ANativeWindow
    sp<ANativeWindow> window = surfaceTC;


    if (window == NULL) {
      ALOGE("GLEnvironment: Error creating window!");
      return -1;