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

Commit a63141af authored by Lajos Molnar's avatar Lajos Molnar
Browse files

stagefright: enable native handles for secure buffers

- rename IOMX::allocateBuffer to allocateSecureBuffer as ACodec
  only uses allocateBuffer for secure compressed buffers.
- add argument to return native_handle if component supports it.
- rename IOMX::enableGraphicBuffers to enableNativeBuffers.
- add argument to select graphic vs. native handle mode
- request native handles for secure input buffers, but allow
  fallback

Bug: 26782004
Change-Id: Ide9d07f54d2e7e3e6a82dbca011f4db9a5630950
parent c52198dc
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -98,8 +98,8 @@ public:
            node_id node, OMX_U32 portIndex, OMX_BOOL tunneled,
            OMX_U32 audioHwSync, native_handle_t **sidebandHandle) = 0;

    virtual status_t enableGraphicBuffers(
            node_id node, OMX_U32 port_index, OMX_BOOL enable) = 0;
    virtual status_t enableNativeBuffers(
            node_id node, OMX_U32 port_index, OMX_BOOL graphic, OMX_BOOL enable) = 0;

    virtual status_t getGraphicBufferUsage(
            node_id node, OMX_U32 port_index, OMX_U32* usage) = 0;
@@ -137,13 +137,14 @@ public:

    virtual status_t signalEndOfInputStream(node_id node) = 0;

    // This API clearly only makes sense if the caller lives in the
    // same process as the callee, i.e. is the media_server, as the
    // returned "buffer_data" pointer is just that, a pointer into local
    // address space.
    virtual status_t allocateBuffer(
    // Allocate an opaque buffer as a native handle. If component supports returning native
    // handles, those are returned in *native_handle. Otherwise, the allocated buffer is
    // returned in *buffer_data. This clearly only makes sense if the caller lives in the
    // same process as the callee, i.e. is the media_server, as the returned "buffer_data"
    // pointer is just that, a pointer into local address space.
    virtual status_t allocateSecureBuffer(
            node_id node, OMX_U32 port_index, size_t size,
            buffer_id *buffer, void **buffer_data) = 0;
            buffer_id *buffer, void **buffer_data, native_handle_t **native_handle) = 0;

    // Allocate an OMX buffer of size |allotedSize|. Use |params| as the backup buffer, which
    // may be larger.
+7 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include <media/stagefright/CodecBase.h>
#include <media/stagefright/FrameRenderTracker.h>
#include <media/stagefright/SkipCutBuffer.h>
#include <utils/NativeHandle.h>
#include <OMX_Audio.h>

#define TRACK_BUFFER_TIMING     0
@@ -72,6 +73,7 @@ struct ACodec : public AHierarchicalStateMachine, public CodecBase {
        size_t countBuffers();
        IOMX::buffer_id bufferIDAt(size_t index) const;
        sp<ABuffer> bufferAt(size_t index) const;
        sp<NativeHandle> handleAt(size_t index) const;
        sp<RefBase> memRefAt(size_t index) const;

    private:
@@ -79,10 +81,13 @@ struct ACodec : public AHierarchicalStateMachine, public CodecBase {

        Vector<IOMX::buffer_id> mBufferIDs;
        Vector<sp<ABuffer> > mBuffers;
        Vector<sp<NativeHandle> > mHandles;
        Vector<sp<RefBase> > mMemRefs;

        PortDescription();
        void addBuffer(IOMX::buffer_id id, const sp<ABuffer> &buffer, const sp<RefBase> &memRef);
        void addBuffer(
                IOMX::buffer_id id, const sp<ABuffer> &buffer,
                const sp<NativeHandle> &handle, const sp<RefBase> &memRef);

        DISALLOW_EVIL_CONSTRUCTORS(PortDescription);
    };
@@ -186,6 +191,7 @@ private:
        sp<ABuffer> mData;
        sp<RefBase> mMemRef;
        sp<GraphicBuffer> mGraphicBuffer;
        sp<NativeHandle> mNativeHandle;
        int mFenceFd;
        FrameRenderTracker::Info *mRenderInfo;

+2 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@

#include <media/MediaCodecInfo.h>
#include <media/stagefright/foundation/AHandler.h>
#include <utils/NativeHandle.h>

namespace android {

@@ -77,6 +78,7 @@ struct CodecBase : public AHandler {
        virtual size_t countBuffers() = 0;
        virtual IOMX::buffer_id bufferIDAt(size_t index) const = 0;
        virtual sp<ABuffer> bufferAt(size_t index) const = 0;
        virtual sp<NativeHandle> handleAt(size_t index) { return NULL; };
        virtual sp<RefBase> memRefAt(size_t index) const { return NULL; }

    protected:
+1 −0
Original line number Diff line number Diff line
@@ -254,6 +254,7 @@ private:
    struct BufferInfo {
        uint32_t mBufferID;
        sp<ABuffer> mData;
        sp<NativeHandle> mNativeHandle;
        sp<RefBase> mMemRef;
        sp<ABuffer> mEncryptedData;
        sp<IMemory> mSharedEncryptedBuffer;
+28 −17
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ enum {
    GET_CONFIG,
    SET_CONFIG,
    GET_STATE,
    ENABLE_GRAPHIC_BUFFERS,
    ENABLE_NATIVE_BUFFERS,
    USE_BUFFER,
    USE_GRAPHIC_BUFFER,
    CREATE_INPUT_SURFACE,
@@ -46,7 +46,7 @@ enum {
    SIGNAL_END_OF_INPUT_STREAM,
    STORE_META_DATA_IN_BUFFERS,
    PREPARE_FOR_ADAPTIVE_PLAYBACK,
    ALLOC_BUFFER,
    ALLOC_SECURE_BUFFER,
    ALLOC_BUFFER_WITH_BACKUP,
    FREE_BUFFER,
    FILL_BUFFER,
@@ -217,14 +217,15 @@ public:
        return reply.readInt32();
    }

    virtual status_t enableGraphicBuffers(
            node_id node, OMX_U32 port_index, OMX_BOOL enable) {
    virtual status_t enableNativeBuffers(
            node_id node, OMX_U32 port_index, OMX_BOOL graphic, OMX_BOOL enable) {
        Parcel data, reply;
        data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
        data.writeInt32((int32_t)node);
        data.writeInt32(port_index);
        data.writeInt32((uint32_t)graphic);
        data.writeInt32((uint32_t)enable);
        remote()->transact(ENABLE_GRAPHIC_BUFFERS, data, &reply);
        remote()->transact(ENABLE_NATIVE_BUFFERS, data, &reply);

        status_t err = reply.readInt32();
        return err;
@@ -453,26 +454,31 @@ public:
    }


    virtual status_t allocateBuffer(
    virtual status_t allocateSecureBuffer(
            node_id node, OMX_U32 port_index, size_t size,
            buffer_id *buffer, void **buffer_data) {
            buffer_id *buffer, void **buffer_data, native_handle_t **native_handle) {
        Parcel data, reply;
        data.writeInterfaceToken(IOMX::getInterfaceDescriptor());
        data.writeInt32((int32_t)node);
        data.writeInt32(port_index);
        data.writeInt64(size);
        remote()->transact(ALLOC_BUFFER, data, &reply);
        remote()->transact(ALLOC_SECURE_BUFFER, data, &reply);

        status_t err = reply.readInt32();
        if (err != OK) {
            *buffer = 0;

            *buffer_data = NULL;
            *native_handle = NULL;
            return err;
        }

        *buffer = (buffer_id)reply.readInt32();
        *buffer_data = (void *)reply.readInt64();

        if (*buffer_data == NULL) {
            *native_handle = reply.readNativeHandle();
        } else {
            *native_handle = NULL;
        }
        return err;
    }

@@ -754,15 +760,16 @@ status_t BnOMX::onTransact(
            return NO_ERROR;
        }

        case ENABLE_GRAPHIC_BUFFERS:
        case ENABLE_NATIVE_BUFFERS:
        {
            CHECK_OMX_INTERFACE(IOMX, data, reply);

            node_id node = (node_id)data.readInt32();
            OMX_U32 port_index = data.readInt32();
            OMX_BOOL graphic = (OMX_BOOL)data.readInt32();
            OMX_BOOL enable = (OMX_BOOL)data.readInt32();

            status_t err = enableGraphicBuffers(node, port_index, enable);
            status_t err = enableNativeBuffers(node, port_index, graphic, enable);
            reply->writeInt32(err);

            return NO_ERROR;
@@ -965,7 +972,7 @@ status_t BnOMX::onTransact(
            OMX_BOOL tunneled = (OMX_BOOL)data.readInt32();
            OMX_U32 audio_hw_sync = data.readInt32();

            native_handle_t *sideband_handle;
            native_handle_t *sideband_handle = NULL;
            status_t err = configureVideoTunnelMode(
                    node, port_index, tunneled, audio_hw_sync, &sideband_handle);
            reply->writeInt32(err);
@@ -974,7 +981,7 @@ status_t BnOMX::onTransact(
            return NO_ERROR;
        }

        case ALLOC_BUFFER:
        case ALLOC_SECURE_BUFFER:
        {
            CHECK_OMX_INTERFACE(IOMX, data, reply);

@@ -989,14 +996,18 @@ status_t BnOMX::onTransact(
            size_t size = data.readInt64();

            buffer_id buffer;
            void *buffer_data;
            status_t err = allocateBuffer(
                    node, port_index, size, &buffer, &buffer_data);
            void *buffer_data = NULL;
            native_handle_t *native_handle = NULL;
            status_t err = allocateSecureBuffer(
                    node, port_index, size, &buffer, &buffer_data, &native_handle);
            reply->writeInt32(err);

            if (err == OK) {
                reply->writeInt32((int32_t)buffer);
                reply->writeInt64((uintptr_t)buffer_data);
                if (buffer_data == NULL) {
                    reply->writeNativeHandle(native_handle);
                }
            }

            return NO_ERROR;
Loading