diff options
author | Arun Johnson <arunjohnson@google.com> | 2024-04-12 17:04:01 +0000 |
---|---|---|
committer | Arun Johnson <arunjohnson@google.com> | 2024-04-12 17:19:22 +0000 |
commit | 5fb6f67e1989d122238893dd4cd4232ee03eaf90 (patch) | |
tree | 7650ca502d4c7a726394e415f9906e71c56fffe7 /media | |
parent | 209c1cda37740d39194262d96faf6a686f0c4925 (diff) | |
download | base-5fb6f67e1989d122238893dd4cd4232ee03eaf90.tar.gz |
Enable reuse of LinearBlock for during secure playback
The mapping of the linearblock is kept open until a call to
recycle() is done. Users are allowed to use the space in the linear
block if available. Behaviour of using overlapping memory location
is undefined.
Bug: 331921194
Test: atest CtsMediaDrmFrameworkTestCases
Change-Id: I5d81be242a2187fe3a57a5474804482e64a5b083
Diffstat (limited to 'media')
-rw-r--r-- | media/jni/android_media_MediaCodec.cpp | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/media/jni/android_media_MediaCodec.cpp b/media/jni/android_media_MediaCodec.cpp index 82561f982a03..4f9917b19110 100644 --- a/media/jni/android_media_MediaCodec.cpp +++ b/media/jni/android_media_MediaCodec.cpp @@ -2886,6 +2886,10 @@ static void extractMemoryFromContext( jint offset, jint size, sp<hardware::HidlMemory> *memory) { + if ((offset + size) > context->capacity()) { + ALOGW("extractMemoryFromContext: offset + size provided exceed capacity"); + return; + } *memory = context->toHidlMemory(); if (*memory == nullptr) { if (!context->mBlock) { @@ -2893,23 +2897,26 @@ static void extractMemoryFromContext( return; } ALOGD("extractMemoryFromContext: realloc & copying from C2Block to IMemory (cap=%zu)", - context->capacity()); + context->capacity()); if (!obtain(context, context->capacity(), context->mCodecNames, true /* secure */)) { ALOGW("extractMemoryFromContext: failed to obtain secure block"); return; } - C2WriteView view = context->mBlock->map().get(); - if (view.error() != C2_OK) { - ALOGW("extractMemoryFromContext: failed to map C2Block (%d)", view.error()); - return; - } - uint8_t *memoryPtr = static_cast<uint8_t *>(context->mMemory->unsecurePointer()); - memcpy(memoryPtr + offset, view.base() + offset, size); - context->mBlock.reset(); - context->mReadWriteMapping.reset(); *memory = context->toHidlMemory(); } + if (context->mBlock == nullptr || context->mReadWriteMapping == nullptr) { + ALOGW("extractMemoryFromContext: Cannot extract memory as C2Block is not created/mapped"); + return; + } + if (context->mReadWriteMapping->error() != C2_OK) { + ALOGW("extractMemoryFromContext: failed to map C2Block (%d)", + context->mReadWriteMapping->error()); + return; + } + // We are proceeding to extract memory from C2Block + uint8_t *memoryPtr = static_cast<uint8_t *>(context->mMemory->unsecurePointer()); + memcpy(memoryPtr + offset, context->mReadWriteMapping->base() + offset, size); } static void extractBufferFromContext( |