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

Commit d0a98fa0 authored by Chong Zhang's avatar Chong Zhang
Browse files

stagefright: remove Miracast sender code

This has been deprecated for some time. Remove this from codebase
to avoid introducing new HAL for HDCP. Log warning and return NULL
when remote display is requested. 

bug: 62213914
Change-Id: I3560b60fe83a01c51df0f2e715a8f2c760e57bf8
parent 5bb3cfe6
Loading
Loading
Loading
Loading

include/media/IHDCP.h

deleted120000 → 0
+0 −1
Original line number Diff line number Diff line
../../media/libmedia/include/media/IHDCP.h
 No newline at end of file
+0 −1
Original line number Diff line number Diff line
@@ -137,7 +137,6 @@ cc_library_shared {

    srcs: [
        "IDataSource.cpp",
        "IHDCP.cpp",
        "BufferingSettings.cpp",
        "mediaplayer.cpp",
        "IMediaHTTPConnection.cpp",

media/libmedia/IHDCP.cpp

deleted100644 → 0
+0 −359
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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.
 */

//#define LOG_NDEBUG 0
#define LOG_TAG "IHDCP"
#include <utils/Log.h>

#include <binder/Parcel.h>
#include <media/IHDCP.h>
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/foundation/ADebug.h>

namespace android {

enum {
    OBSERVER_NOTIFY = IBinder::FIRST_CALL_TRANSACTION,
    HDCP_SET_OBSERVER,
    HDCP_INIT_ASYNC,
    HDCP_SHUTDOWN_ASYNC,
    HDCP_GET_CAPS,
    HDCP_ENCRYPT,
    HDCP_ENCRYPT_NATIVE,
    HDCP_DECRYPT,
};

struct BpHDCPObserver : public BpInterface<IHDCPObserver> {
    explicit BpHDCPObserver(const sp<IBinder> &impl)
        : BpInterface<IHDCPObserver>(impl) {
    }

    virtual void notify(
            int msg, int ext1, int ext2, const Parcel *obj) {
        Parcel data, reply;
        data.writeInterfaceToken(IHDCPObserver::getInterfaceDescriptor());
        data.writeInt32(msg);
        data.writeInt32(ext1);
        data.writeInt32(ext2);
        if (obj && obj->dataSize() > 0) {
            data.appendFrom(const_cast<Parcel *>(obj), 0, obj->dataSize());
        }
        remote()->transact(OBSERVER_NOTIFY, data, &reply, IBinder::FLAG_ONEWAY);
    }
};

IMPLEMENT_META_INTERFACE(HDCPObserver, "android.hardware.IHDCPObserver");

struct BpHDCP : public BpInterface<IHDCP> {
    explicit BpHDCP(const sp<IBinder> &impl)
        : BpInterface<IHDCP>(impl) {
    }

    virtual status_t setObserver(const sp<IHDCPObserver> &observer) {
        Parcel data, reply;
        data.writeInterfaceToken(IHDCP::getInterfaceDescriptor());
        data.writeStrongBinder(IInterface::asBinder(observer));
        remote()->transact(HDCP_SET_OBSERVER, data, &reply);
        return reply.readInt32();
    }

    virtual status_t initAsync(const char *host, unsigned port) {
        Parcel data, reply;
        data.writeInterfaceToken(IHDCP::getInterfaceDescriptor());
        data.writeCString(host);
        data.writeInt32(port);
        remote()->transact(HDCP_INIT_ASYNC, data, &reply);
        return reply.readInt32();
    }

    virtual status_t shutdownAsync() {
        Parcel data, reply;
        data.writeInterfaceToken(IHDCP::getInterfaceDescriptor());
        remote()->transact(HDCP_SHUTDOWN_ASYNC, data, &reply);
        return reply.readInt32();
    }

    virtual uint32_t getCaps() {
        Parcel data, reply;
        data.writeInterfaceToken(IHDCP::getInterfaceDescriptor());
        remote()->transact(HDCP_GET_CAPS, data, &reply);
        return reply.readInt32();
    }

    virtual status_t encrypt(
            const void *inData, size_t size, uint32_t streamCTR,
            uint64_t *outInputCTR, void *outData) {
        Parcel data, reply;
        data.writeInterfaceToken(IHDCP::getInterfaceDescriptor());
        data.writeInt32(size);
        data.write(inData, size);
        data.writeInt32(streamCTR);
        remote()->transact(HDCP_ENCRYPT, 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 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,
            void *outData) {
        Parcel data, reply;
        data.writeInterfaceToken(IHDCP::getInterfaceDescriptor());
        data.writeInt32(size);
        data.write(inData, size);
        data.writeInt32(streamCTR);
        data.writeInt64(inputCTR);
        remote()->transact(HDCP_DECRYPT, data, &reply);

        status_t err = reply.readInt32();

        if (err != OK) {
            return err;
        }

        reply.read(outData, size);

        return err;
    }
};

IMPLEMENT_META_INTERFACE(HDCP, "android.hardware.IHDCP");

status_t BnHDCPObserver::onTransact(
        uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
    switch (code) {
        case OBSERVER_NOTIFY:
        {
            CHECK_INTERFACE(IHDCPObserver, data, reply);

            int msg = data.readInt32();
            int ext1 = data.readInt32();
            int ext2 = data.readInt32();

            Parcel obj;
            if (data.dataAvail() > 0) {
                obj.appendFrom(
                        const_cast<Parcel *>(&data),
                        data.dataPosition(),
                        data.dataAvail());
            }

            notify(msg, ext1, ext2, &obj);

            return OK;
        }

        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
}

status_t BnHDCP::onTransact(
        uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) {
    switch (code) {
        case HDCP_SET_OBSERVER:
        {
            CHECK_INTERFACE(IHDCP, data, reply);

            sp<IHDCPObserver> observer =
                interface_cast<IHDCPObserver>(data.readStrongBinder());

            reply->writeInt32(setObserver(observer));
            return OK;
        }

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

            const char *host = data.readCString();
            unsigned port = data.readInt32();

            reply->writeInt32(initAsync(host, port));
            return OK;
        }

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

            reply->writeInt32(shutdownAsync());
            return OK;
        }

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

            reply->writeInt32(getCaps());
            return OK;
        }

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

            size_t size = data.readInt32();
            void *inData = NULL;
            // watch out for overflow
            if (size <= SIZE_MAX / 2) {
                inData = malloc(2 * size);
            }
            if (inData == NULL) {
                reply->writeInt32(ERROR_OUT_OF_RANGE);
                return OK;
            }

            void *outData = (uint8_t *)inData + size;

            status_t err = data.read(inData, size);
            if (err != OK) {
                free(inData);
                reply->writeInt32(err);
                return OK;
            }

            uint32_t streamCTR = data.readInt32();
            uint64_t inputCTR;
            err = encrypt(inData, size, streamCTR, &inputCTR, outData);

            reply->writeInt32(err);

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

            free(inData);
            inData = outData = NULL;

            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 = NULL;
            uint64_t inputCTR;

            status_t err = ERROR_OUT_OF_RANGE;

            outData = malloc(size);

            if (outData != NULL) {
                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:
        {
            CHECK_INTERFACE(IHDCP, data, reply);

            size_t size = data.readInt32();
            size_t bufSize = 2 * size;

            // watch out for overflow
            void *inData = NULL;
            if (bufSize > size) {
                inData = malloc(bufSize);
            }

            if (inData == NULL) {
                reply->writeInt32(ERROR_OUT_OF_RANGE);
                return OK;
            }

            void *outData = (uint8_t *)inData + size;

            data.read(inData, size);

            uint32_t streamCTR = data.readInt32();
            uint64_t inputCTR = data.readInt64();
            status_t err = decrypt(inData, size, streamCTR, inputCTR, outData);

            reply->writeInt32(err);

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

            free(inData);
            inData = outData = NULL;

            return OK;
        }

        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
}

}  // namespace android
+0 −17
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@

#include <binder/Parcel.h>
#include <binder/IMemory.h>
#include <media/IHDCP.h>
#include <media/IMediaCodecList.h>
#include <media/IMediaHTTPService.h>
#include <media/IMediaPlayerService.h>
@@ -40,7 +39,6 @@ enum {
    CREATE_MEDIA_RECORDER,
    CREATE_METADATA_RETRIEVER,
    GET_OMX,
    MAKE_HDCP,
    ADD_BATTERY_DATA,
    PULL_BATTERY_DATA,
    LISTEN_FOR_REMOTE_DISPLAY,
@@ -90,14 +88,6 @@ public:
        return interface_cast<IOMX>(reply.readStrongBinder());
    }

    virtual sp<IHDCP> makeHDCP(bool createEncryptionModule) {
        Parcel data, reply;
        data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
        data.writeInt32(createEncryptionModule);
        remote()->transact(MAKE_HDCP, data, &reply);
        return interface_cast<IHDCP>(reply.readStrongBinder());
    }

    virtual void addBatteryData(uint32_t params) {
        Parcel data, reply;
        data.writeInterfaceToken(IMediaPlayerService::getInterfaceDescriptor());
@@ -167,13 +157,6 @@ status_t BnMediaPlayerService::onTransact(
            reply->writeStrongBinder(IInterface::asBinder(omx));
            return NO_ERROR;
        } break;
        case MAKE_HDCP: {
            CHECK_INTERFACE(IMediaPlayerService, data, reply);
            bool createEncryptionModule = data.readInt32();
            sp<IHDCP> hdcp = makeHDCP(createEncryptionModule);
            reply->writeStrongBinder(IInterface::asBinder(hdcp));
            return NO_ERROR;
        } break;
        case ADD_BATTERY_DATA: {
            CHECK_INTERFACE(IMediaPlayerService, data, reply);
            uint32_t params = data.readInt32();
+0 −120
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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.
 */

#include <binder/IInterface.h>
#include <media/hardware/HDCPAPI.h>
#include <media/stagefright/foundation/ABase.h>
#include <ui/GraphicBuffer.h>

namespace android {

struct IHDCPObserver : public IInterface {
    DECLARE_META_INTERFACE(HDCPObserver);

    virtual void notify(
            int msg, int ext1, int ext2, const Parcel *obj) = 0;

private:
    DISALLOW_EVIL_CONSTRUCTORS(IHDCPObserver);
};

struct IHDCP : public IInterface {
    DECLARE_META_INTERFACE(HDCP);

    // Called to specify the observer that receives asynchronous notifications
    // from the HDCP implementation to signal completion/failure of asynchronous
    // operations (such as initialization) or out of band events.
    virtual status_t setObserver(const sp<IHDCPObserver> &observer) = 0;

    // Request to setup an HDCP session with the specified host listening
    // on the specified port.
    virtual status_t initAsync(const char *host, unsigned port) = 0;

    // Request to shutdown the active HDCP session.
    virtual status_t shutdownAsync() = 0;

    // Returns the capability bitmask of this HDCP session.
    // Possible return values (please refer to HDCAPAPI.h):
    //   HDCP_CAPS_ENCRYPT: mandatory, meaning the HDCP module can encrypt
    //   from an input byte-array buffer to an output byte-array buffer
    //   HDCP_CAPS_ENCRYPT_NATIVE: the HDCP module supports encryption from
    //   a native buffer to an output byte-array buffer. The format of the
    //   input native buffer is specific to vendor's encoder implementation.
    //   It is the same format as that used by the encoder when
    //   "storeMetaDataInBuffers" extension is enabled on its output port.
    virtual uint32_t getCaps() = 0;

    // ENCRYPTION only:
    // Encrypt data according to the HDCP spec. "size" bytes of data are
    // available at "inData" (virtual address), "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 encrypt(
            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"
    // (virtual address), "size" may not be a multiple of 128 bits (16 bytes).
    // An equal number of decrypted 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 decrypted data.
    // Both streamCTR and inputCTR will be provided by the caller.
    virtual status_t decrypt(
            const void *inData, size_t size,
            uint32_t streamCTR, uint64_t inputCTR,
            void *outData) = 0;

private:
    DISALLOW_EVIL_CONSTRUCTORS(IHDCP);
};

struct BnHDCPObserver : public BnInterface<IHDCPObserver> {
    virtual status_t onTransact(
            uint32_t code, const Parcel &data, Parcel *reply,
            uint32_t flags = 0);
};

struct BnHDCP : public BnInterface<IHDCP> {
    virtual status_t onTransact(
            uint32_t code, const Parcel &data, Parcel *reply,
            uint32_t flags = 0);
};

}  // namespace android

Loading