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

Commit 19431587 authored by Praveen Chavan's avatar Praveen Chavan Committed by Lajos Molnar
Browse files

NdkMediaCodec: implement createInputSurface

Expose createInputSurface() via NDK-mediaCodec to enable native
encoder apps to record from an input surface.

Bug: 32746065
Change-Id: I654f2c0deadb336d492cdd6ba290e09c8996ce40
parent 6fcb1488
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -179,6 +179,19 @@ media_status_t AMediaCodec_setOutputSurface(AMediaCodec*, ANativeWindow* surface
media_status_t AMediaCodec_releaseOutputBufferAtTime(
        AMediaCodec *mData, size_t idx, int64_t timestampNs);

/**
 * Creates a Surface that can be used as the input to encoder, in place of input buffers
 *
 * This can only be called after the codec has been configured via
 * AMediaCodec_configure(..); and before AMediaCodec_start() has been called.
 *
 * The application is responsible for releasing the surface by calling
 * ANativeWindow_release() when done.
 *
 * For more details, see the Java documentation for MediaCodec.createInputSurface.
 */
media_status_t AMediaCodec_createInputSurface(AMediaCodec*, ANativeWindow** surface);

typedef enum {
    AMEDIACODECRYPTOINFO_MODE_CLEAR = 0,
    AMEDIACODECRYPTOINFO_MODE_AES_CTR = 1,
+2 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ LOCAL_C_INCLUDES := \
    frameworks/base/core/jni \
    frameworks/base/media/jni \
    frameworks/av/include/ndk \
    frameworks/native/include \
    system/media/camera/include \
    $(call include-path-for, libhardware)/hardware \

@@ -60,6 +61,7 @@ LOCAL_SHARED_LIBRARIES := \
    libbinder \
    libgui \
    libui \
    libandroid \

include $(BUILD_SHARED_LIBRARY)

+19 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include <media/stagefright/MediaCodec.h>
#include <media/stagefright/MediaErrors.h>
#include <media/MediaCodecBuffer.h>
#include <android/native_window.h>

using namespace android;

@@ -377,6 +378,24 @@ media_status_t AMediaCodec_setOutputSurface(AMediaCodec *mData, ANativeWindow* w
    return translate_error(mData->mCodec->setSurface(surface));
}

EXPORT
media_status_t AMediaCodec_createInputSurface(AMediaCodec *mData, ANativeWindow **surface) {
    if (surface == NULL || mData == NULL) {
        return AMEDIA_ERROR_INVALID_PARAMETER;
    }
    *surface = NULL;

    sp<IGraphicBufferProducer> igbp = NULL;
    status_t err = mData->mCodec->createInputSurface(&igbp);
    if (err != NO_ERROR) {
        return translate_error(err);
    }

    *surface = new Surface(igbp);
    ANativeWindow_acquire(*surface);
    return AMEDIA_OK;
}

//EXPORT
media_status_t AMediaCodec_setNotificationCallback(AMediaCodec *mData, OnCodecEvent callback,
        void *userdata) {