summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-04-16 18:18:09 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2024-04-16 18:18:09 +0000
commit2c83efe4b950f7d4a57a80b1553832c46503c18b (patch)
tree33bb80d4ec3fe661774abb48bcb069516aa0c19e
parentd00c53bb080038f77cd8301b56817559705ae11f (diff)
parentd666832c39f1dc17718dc6687eafb221afbe2f4b (diff)
Merge "Enable reuse of LinearBlock for during secure playback" into main am: d666832c39
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3039900 Change-Id: I2f7b0d18170a86d2453de52e93ddfc2e4f39c2c6 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--media/jni/android_media_MediaCodec.cpp27
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(