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

Commit 29b9e601 authored by Arun Johnson's avatar Arun Johnson Committed by Android (Google) Code Review
Browse files

Merge "Callback behaviour change for CONFIGURE_FLAG_USE_CRYPTO_ASYNC" into udc-dev

parents b1e6fedb 634d0800
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -426,7 +426,8 @@ status_t CCodecBufferChannel::attachEncryptedBuffer(
        size_t offset,
        const CryptoPlugin::SubSample *subSamples,
        size_t numSubSamples,
        const sp<MediaCodecBuffer> &buffer) {
        const sp<MediaCodecBuffer> &buffer,
        AString* errorDetailMsg) {
    static const C2MemoryUsage kSecureUsage{C2MemoryUsage::READ_PROTECTED, 0};
    static const C2MemoryUsage kDefaultReadWriteUsage{
        C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE};
@@ -456,7 +457,6 @@ status_t CCodecBufferChannel::attachEncryptedBuffer(
    ssize_t result = -1;
    ssize_t codecDataOffset = 0;
    if (mCrypto) {
        AString errorDetailMsg;
        int32_t heapSeqNum = getHeapSeqNum(memory);
        hardware::drm::V1_0::SharedBuffer src{(uint32_t)heapSeqNum, offset, size};
        hardware::drm::V1_0::DestinationBuffer dst;
@@ -470,7 +470,7 @@ status_t CCodecBufferChannel::attachEncryptedBuffer(
        }
        result = mCrypto->decrypt(
                key, iv, mode, pattern, src, 0, subSamples, numSubSamples,
                dst, &errorDetailMsg);
                dst, errorDetailMsg);
        if (result < 0) {
            ALOGI("[%s] attachEncryptedBuffer: decrypt failed: result = %zd", mName, result);
            return result;
@@ -515,7 +515,9 @@ status_t CCodecBufferChannel::attachEncryptedBuffer(
                    result = (ssize_t)_bytesWritten;
                    detailedError = _detailedError;
                });

        if (errorDetailMsg) {
            errorDetailMsg->setTo(detailedError.c_str(), detailedError.size());
        }
        if (!returnVoid.isOk() || status != CasStatus::OK || result < 0) {
            ALOGI("[%s] descramble failed, trans=%s, status=%d, result=%zd",
                    mName, returnVoid.description().c_str(), status, result);
+2 −1
Original line number Diff line number Diff line
@@ -86,7 +86,8 @@ public:
            size_t offset,
            const CryptoPlugin::SubSample *subSamples,
            size_t numSubSamples,
            const sp<MediaCodecBuffer> &buffer) override;
            const sp<MediaCodecBuffer> &buffer,
            AString* errorDetailMsg) override;
    virtual status_t renderOutputBuffer(
            const sp<MediaCodecBuffer> &buffer, int64_t timestampNs) override;
    virtual void pollForRenderedBuffers() override;
+6 −4
Original line number Diff line number Diff line
@@ -347,7 +347,8 @@ status_t ACodecBufferChannel::attachEncryptedBuffer(
        size_t offset,
        const CryptoPlugin::SubSample *subSamples,
        size_t numSubSamples,
        const sp<MediaCodecBuffer> &buffer) {
        const sp<MediaCodecBuffer> &buffer,
        AString* errorDetailMsg) {
    std::shared_ptr<const std::vector<const BufferInfo>> array(
            std::atomic_load(&mInputBuffers));
    BufferInfoIterator it = findClientBuffer(array, buffer);
@@ -371,7 +372,6 @@ status_t ACodecBufferChannel::attachEncryptedBuffer(
    ssize_t result = -1;
    ssize_t codecDataOffset = 0;
    if (mCrypto != NULL) {
        AString errorDetailMsg;
        hardware::drm::V1_0::DestinationBuffer destination;
        if (secure) {
            destination.type = DrmBufferType::NATIVE_HANDLE;
@@ -387,7 +387,7 @@ status_t ACodecBufferChannel::attachEncryptedBuffer(

        result = mCrypto->decrypt(key, iv, mode, pattern,
                source, it->mClientBuffer->offset(),
                subSamples, numSubSamples, destination, &errorDetailMsg);
                subSamples, numSubSamples, destination, errorDetailMsg);

        if (result < 0) {
            return result;
@@ -441,7 +441,9 @@ status_t ACodecBufferChannel::attachEncryptedBuffer(
                    result = (ssize_t)_bytesWritten;
                    detailedError = _detailedError;
                });

        if (errorDetailMsg) {
            errorDetailMsg->setTo(detailedError.c_str(), detailedError.size());
        }
        if (!returnVoid.isOk() || status != Status::OK || result < 0) {
            ALOGE("descramble failed, trans=%s, status=%d, result=%zd",
                    returnVoid.description().c_str(), status, result);
+1 −1
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ status_t CryptoAsync::attachEncryptedBufferAndQueue(sp<AMessage> & msg) {
    // attach buffer
    err = channel->attachEncryptedBuffer(
        memory, secure, key, iv, mode, pattern,
        offset, subSamples, numSubSamples, buffer);
        offset, subSamples, numSubSamples, buffer, &errorDetailMsg);

    // a generic error
    auto handleError = [this, &err, &msg]() {
+37 −17
Original line number Diff line number Diff line
@@ -4290,11 +4290,10 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
                    mFlags |= kFlagUseBlockModel;
                }
                if (flags & CONFIGURE_FLAG_USE_CRYPTO_ASYNC) {
                    // silently disable crytoasync with blockmodel
                    if (!(mFlags & kFlagUseBlockModel)) {
                    mFlags |= kFlagUseCryptoAsync;
                    } else {
                        ALOGW("CrytoAsync not yet enabled for block model, falling back to normal");
                    if ((mFlags & kFlagUseBlockModel)) {
                        ALOGW("CrytoAsync not yet enabled for block model,\
                                falling back to normal");
                    }
                }
            }
@@ -4324,6 +4323,11 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
            mBufferChannel->setDescrambler(mDescrambler);
            if ((mFlags & kFlagUseCryptoAsync) &&
                mCrypto  && (mDomain == DOMAIN_VIDEO)) {
                // set kFlagUseCryptoAsync but do-not use this for block model
                // this is to propagate the error in onCryptoError()
                // TODO (b/274628160): Enable Use of CONFIG_FLAG_USE_CRYPTO_ASYNC
                //                     with CONFIGURE_FLAG_USE_BLOCK_MODEL)
                if (!(mFlags & kFlagUseBlockModel)) {
                    mCryptoAsync = new CryptoAsync(mBufferChannel);
                    mCryptoAsync->setCallback(
                    std::make_unique<CryptoAsyncCallback>(new AMessage(kWhatCodecNotify, this)));
@@ -4337,6 +4341,7 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
                        mCryptoLooper = nullptr;
                    }
                }
            }

            format->setInt32("flags", flags);
            if (flags & CONFIGURE_FLAG_ENCODE) {
@@ -5510,9 +5515,24 @@ status_t MediaCodec::onQueueInputBuffer(const sp<AMessage> &msg) {
        if (c2Buffer) {
            err = mBufferChannel->attachBuffer(c2Buffer, buffer);
        } else if (memory) {
            AString errorDetailMsg;
            err = mBufferChannel->attachEncryptedBuffer(
                    memory, (mFlags & kFlagIsSecure), key, iv, mode, pattern,
                    offset, subSamples, numSubSamples, buffer);
                    offset, subSamples, numSubSamples, buffer, &errorDetailMsg);
            if (err != OK && hasCryptoOrDescrambler()
                    && (mFlags & kFlagUseCryptoAsync)) {
                // create error detail
                AString errorDetailMsg;
                sp<AMessage> cryptoErrorInfo = new AMessage();
                buildCryptoInfoAMessage(cryptoErrorInfo, CryptoAsync::kActionDecrypt);
                cryptoErrorInfo->setInt32("err", err);
                cryptoErrorInfo->setInt32("actionCode", ACTION_CODE_FATAL);
                cryptoErrorInfo->setString("errorDetail", errorDetailMsg);
                onCryptoError(cryptoErrorInfo);
                // we want cryptoError to be in the callback
                // but Codec IllegalStateException to be triggered.
                err = INVALID_OPERATION;
            }
        } else {
            err = UNKNOWN_ERROR;
        }
Loading