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

Commit 308bcaa4 authored by Chong Zhang's avatar Chong Zhang
Browse files

wifi-display: add support for metadata mode on encoder output

pass buffer_handle_t from encoder output to HDCP encryptor input

Bug: 8968123

Change-Id: Iea8007ce568641e213fd2e3cf6947a6f7a95746c
parent 6d101328
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include <binder/IInterface.h>
#include <media/hardware/HDCPAPI.h>
#include <media/stagefright/foundation/ABase.h>
#include <ui/GraphicBuffer.h>

namespace android {

@@ -59,6 +60,20 @@ struct IHDCP : public IInterface {
            const void *inData, size_t size, uint32_t streamCTR,
            uint64_t *outInputCTR, void *outData) = 0;

    // Encrypt data according to the HDCP spec. "size" bytes of data starting
    // at location "offset" are available in "buffer" (buffer handle). "size"
    // may not be a multiple of 128 bits (16 bytes). An equal number of
    // encrypted bytes should be written to the buffer at "outData" (virtual
    // address). This operation is to be synchronous, i.e. this call does not
    // return until outData contains size bytes of encrypted data.
    // streamCTR will be assigned by the caller (to 0 for the first PES stream,
    // 1 for the second and so on)
    // inputCTR _will_be_maintained_by_the_callee_ for each PES stream.
    virtual status_t encryptNative(
            const sp<GraphicBuffer> &graphicBuffer,
            size_t offset, size_t size, uint32_t streamCTR,
            uint64_t *outInputCTR, void *outData) = 0;

    // DECRYPTION only:
    // Decrypt data according to the HDCP spec.
    // "size" bytes of encrypted data are available at "inData"
+1 −1
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ private:

    bool mSentFormat;
    bool mIsEncoder;

    bool mUseMetadataOnEncoderOutput;
    bool mShutdownInProgress;

    // If "mKeepComponentAllocated" we only transition back to Loaded state
+54 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ enum {
    HDCP_INIT_ASYNC,
    HDCP_SHUTDOWN_ASYNC,
    HDCP_ENCRYPT,
    HDCP_ENCRYPT_NATIVE,
    HDCP_DECRYPT,
};

@@ -108,6 +109,31 @@ struct BpHDCP : public BpInterface<IHDCP> {
        return err;
    }

    virtual status_t encryptNative(
            const sp<GraphicBuffer> &graphicBuffer,
            size_t offset, size_t size, uint32_t streamCTR,
            uint64_t *outInputCTR, void *outData) {
        Parcel data, reply;
        data.writeInterfaceToken(IHDCP::getInterfaceDescriptor());
        data.write(*graphicBuffer);
        data.writeInt32(offset);
        data.writeInt32(size);
        data.writeInt32(streamCTR);
        remote()->transact(HDCP_ENCRYPT_NATIVE, data, &reply);

        status_t err = reply.readInt32();

        if (err != OK) {
            *outInputCTR = 0;
            return err;
        }

        *outInputCTR = reply.readInt64();
        reply.read(outData, size);

        return err;
    }

    virtual status_t decrypt(
            const void *inData, size_t size,
            uint32_t streamCTR, uint64_t inputCTR,
@@ -222,6 +248,34 @@ status_t BnHDCP::onTransact(
            return OK;
        }

        case HDCP_ENCRYPT_NATIVE:
        {
            CHECK_INTERFACE(IHDCP, data, reply);

            sp<GraphicBuffer> graphicBuffer = new GraphicBuffer();
            data.read(*graphicBuffer);
            size_t offset = data.readInt32();
            size_t size = data.readInt32();
            uint32_t streamCTR = data.readInt32();
            void *outData = malloc(size);
            uint64_t inputCTR;

            status_t err = encryptNative(graphicBuffer, offset, size,
                                         streamCTR, &inputCTR, outData);

            reply->writeInt32(err);

            if (err == OK) {
                reply->writeInt64(inputCTR);
                reply->write(outData, size);
            }

            free(outData);
            outData = NULL;

            return OK;
        }

        case HDCP_DECRYPT:
        {
            size_t size = data.readInt32();
+18 −0
Original line number Diff line number Diff line
@@ -116,6 +116,24 @@ status_t HDCP::encrypt(
    return mHDCPModule->encrypt(inData, size, streamCTR, outInputCTR, outData);
}

status_t HDCP::encryptNative(
        const sp<GraphicBuffer> &graphicBuffer,
        size_t offset, size_t size, uint32_t streamCTR,
        uint64_t *outInputCTR, void *outData) {
    Mutex::Autolock autoLock(mLock);

    CHECK(mIsEncryptionModule);

    if (mHDCPModule == NULL) {
        *outInputCTR = 0;

        return NO_INIT;
    }

    return mHDCPModule->encryptNative(graphicBuffer->handle,
                    offset, size, streamCTR, outInputCTR, outData);
}

status_t HDCP::decrypt(
        const void *inData, size_t size,
        uint32_t streamCTR, uint64_t outInputCTR, void *outData) {
+5 −0
Original line number Diff line number Diff line
@@ -35,6 +35,11 @@ struct HDCP : public BnHDCP {
            const void *inData, size_t size, uint32_t streamCTR,
            uint64_t *outInputCTR, void *outData);

    virtual status_t encryptNative(
            const sp<GraphicBuffer> &graphicBuffer,
            size_t offset, size_t size, uint32_t streamCTR,
            uint64_t *outInputCTR, void *outData);

    virtual status_t decrypt(
            const void *inData, size_t size,
            uint32_t streamCTR, uint64_t outInputCTR, void *outData);
Loading