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

Commit fbec72e7 authored by Lajos Molnar's avatar Lajos Molnar Committed by Automerger Merge Worker
Browse files

Merge changes from topic "non-tee-secure-decoder" am: 3fbe65fc am: 4e87af59 am: 257f8aef

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/1456944

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: If7c383825674a1110fb9dbc2d6460126f550c573
parents 21bca0f4 257f8aef
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -151,6 +151,7 @@ enum C2ParamIndexKind : C2Param::type_index_t {

    /* protected content */
    kParamIndexSecureMode,
    kParamIndexEncryptedBuffer, // info-buffer, used with SM_READ_PROTECTED_WITH_ENCRYPTED

    // deprecated
    kParamIndexDelayRequest = kParamIndexDelay | C2Param::CoreIndex::IS_REQUEST_FLAG,
@@ -1145,6 +1146,8 @@ constexpr char C2_PARAMKEY_PRIORITY[] = "algo.priority";
C2ENUM(C2Config::secure_mode_t, uint32_t,
    SM_UNPROTECTED,    ///< no content protection
    SM_READ_PROTECTED, ///< input and output buffers shall be protected from reading
    /// both read protected and readable encrypted buffers are used
    SM_READ_PROTECTED_WITH_ENCRYPTED,
)

typedef C2GlobalParam<C2Tuning, C2SimpleValueStruct<C2Config::secure_mode_t>, kParamIndexSecureMode>
+52 −3
Original line number Diff line number Diff line
@@ -143,7 +143,8 @@ CCodecBufferChannel::CCodecBufferChannel(
      mFrameIndex(0u),
      mFirstValidFrameIndex(0u),
      mMetaMode(MODE_NONE),
      mInputMetEos(false) {
      mInputMetEos(false),
      mSendEncryptedInfoBuffer(false) {
    mOutputSurface.lock()->maxDequeueBuffers = kSmoothnessFactor + kRenderingDepth;
    {
        Mutexed<Input>::Locked input(mInput);
@@ -192,7 +193,10 @@ status_t CCodecBufferChannel::signalEndOfInputStream() {
    return mInputSurface->signalEndOfInputStream();
}

status_t CCodecBufferChannel::queueInputBufferInternal(sp<MediaCodecBuffer> buffer) {
status_t CCodecBufferChannel::queueInputBufferInternal(
        sp<MediaCodecBuffer> buffer,
        std::shared_ptr<C2LinearBlock> encryptedBlock,
        size_t blockSize) {
    int64_t timeUs;
    CHECK(buffer->meta()->findInt64("timeUs", &timeUs));

@@ -258,6 +262,11 @@ status_t CCodecBufferChannel::queueInputBufferInternal(sp<MediaCodecBuffer> buff
            output->rotation[queuedFrameIndex] = rotation;
        }
        work->input.buffers.push_back(c2buffer);
        if (encryptedBlock) {
            work->input.infoBuffers.emplace_back(C2InfoBuffer::CreateLinearBuffer(
                    kParamIndexEncryptedBuffer,
                    encryptedBlock->share(0, blockSize, C2Fence())));
        }
        queuedBuffers.push_back(c2buffer);
    } else if (eos) {
        flags |= C2FrameData::FLAG_END_OF_STREAM;
@@ -526,6 +535,40 @@ status_t CCodecBufferChannel::queueSecureInputBuffer(
    }
    sp<EncryptedLinearBlockBuffer> encryptedBuffer((EncryptedLinearBlockBuffer *)buffer.get());

    std::shared_ptr<C2LinearBlock> block;
    size_t allocSize = buffer->size();
    size_t bufferSize = 0;
    c2_status_t blockRes = C2_OK;
    bool copied = false;
    if (mSendEncryptedInfoBuffer) {
        static const C2MemoryUsage kDefaultReadWriteUsage{
            C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE};
        constexpr int kAllocGranule0 = 1024 * 64;
        constexpr int kAllocGranule1 = 1024 * 1024;
        std::shared_ptr<C2BlockPool> pool = mBlockPools.lock()->inputPool;
        // round up encrypted sizes to limit fragmentation and encourage buffer reuse
        if (allocSize <= kAllocGranule1) {
            bufferSize = align(allocSize, kAllocGranule0);
        } else {
            bufferSize = align(allocSize, kAllocGranule1);
        }
        blockRes = pool->fetchLinearBlock(
                bufferSize, kDefaultReadWriteUsage, &block);

        if (blockRes == C2_OK) {
            C2WriteView view = block->map().get();
            if (view.error() == C2_OK && view.size() == bufferSize) {
                copied = true;
                // TODO: only copy clear sections
                memcpy(view.data(), buffer->data(), allocSize);
            }
        }
    }

    if (!copied) {
        block.reset();
    }

    ssize_t result = -1;
    ssize_t codecDataOffset = 0;
    if (numSubSamples == 1
@@ -617,7 +660,8 @@ status_t CCodecBufferChannel::queueSecureInputBuffer(
    }

    buffer->setRange(codecDataOffset, result - codecDataOffset);
    return queueInputBufferInternal(buffer);

    return queueInputBufferInternal(buffer, block, bufferSize);
}

void CCodecBufferChannel::feedInputBufferIfAvailable() {
@@ -907,6 +951,7 @@ status_t CCodecBufferChannel::start(
    C2PortActualDelayTuning::input inputDelay(0);
    C2PortActualDelayTuning::output outputDelay(0);
    C2ActualPipelineDelayTuning pipelineDelay(0);
    C2SecureModeTuning secureMode(C2Config::SM_UNPROTECTED);

    c2_status_t err = mComponent->query(
            {
@@ -917,6 +962,7 @@ status_t CCodecBufferChannel::start(
                &inputDelay,
                &pipelineDelay,
                &outputDelay,
                &secureMode,
            },
            {},
            C2_DONT_BLOCK,
@@ -939,6 +985,9 @@ status_t CCodecBufferChannel::start(
    // TODO: get this from input format
    bool secure = mComponent->getName().find(".secure") != std::string::npos;

    // secure mode is a static parameter (shall not change in the executing state)
    mSendEncryptedInfoBuffer = secureMode.value == C2Config::SM_READ_PROTECTED_WITH_ENCRYPTED;

    std::shared_ptr<C2AllocatorStore> allocatorStore = GetCodec2PlatformAllocatorStore();
    int poolMask = GetCodec2PoolMask();
    C2PlatformAllocatorStore::id_t preferredLinearId = GetPreferredLinearAllocatorId(poolMask);
+4 −1
Original line number Diff line number Diff line
@@ -238,7 +238,9 @@ private:

    void feedInputBufferIfAvailable();
    void feedInputBufferIfAvailableInternal();
    status_t queueInputBufferInternal(sp<MediaCodecBuffer> buffer);
    status_t queueInputBufferInternal(sp<MediaCodecBuffer> buffer,
                                      std::shared_ptr<C2LinearBlock> encryptedBlock = nullptr,
                                      size_t blockSize = 0);
    bool handleWork(
            std::unique_ptr<C2Work> work, const sp<AMessage> &outputFormat,
            const C2StreamInitDataInfo::output *initData);
@@ -316,6 +318,7 @@ private:
    inline bool hasCryptoOrDescrambler() {
        return mCrypto != nullptr || mDescrambler != nullptr;
    }
    std::atomic_bool mSendEncryptedInfoBuffer;
};

// Conversion of a c2_status_t value to a status_t value may depend on the