media codec2: Remove use of hardcoded PAGE_SIZE 4096
bionic hard codes the PAGE_SIZE macro as 4096. This is going away as
Android begins to support larger page sizes. Remove the usage of this
assumption from media codec2 source; use instead getpagesize() which
provides the real pagesize.
Test: mma
Bug: 295016003
Change-Id: If70250d4ef1e838756082974abd4d2e41e28f343
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
diff --git a/media/codec2/fuzzer/C2Fuzzer.cpp b/media/codec2/fuzzer/C2Fuzzer.cpp
index d6793e0..719962d 100644
--- a/media/codec2/fuzzer/C2Fuzzer.cpp
+++ b/media/codec2/fuzzer/C2Fuzzer.cpp
@@ -239,6 +239,7 @@
}
void Codec2Fuzzer::decodeFrames(const uint8_t* data, size_t size) {
+ static const size_t kPageSize = getpagesize();
std::unique_ptr<BufferSource> bufferSource = std::make_unique<BufferSource>(data, size);
if (!bufferSource) {
return;
@@ -270,7 +271,7 @@
work->input.ordinal.timestamp = 0;
work->input.ordinal.frameIndex = ++numFrames;
work->input.buffers.clear();
- int32_t alignedSize = C2FUZZER_ALIGN(frameSize, PAGE_SIZE);
+ int32_t alignedSize = C2FUZZER_ALIGN(frameSize, kPageSize);
std::shared_ptr<C2LinearBlock> block;
status = mLinearPool->fetchLinearBlock(
diff --git a/media/codec2/hal/hidl/1.0/vts/functional/video/VtsHalMediaC2V1_0TargetVideoDecTest.cpp b/media/codec2/hal/hidl/1.0/vts/functional/video/VtsHalMediaC2V1_0TargetVideoDecTest.cpp
index 117d9ca..3dc5b29 100644
--- a/media/codec2/hal/hidl/1.0/vts/functional/video/VtsHalMediaC2V1_0TargetVideoDecTest.cpp
+++ b/media/codec2/hal/hidl/1.0/vts/functional/video/VtsHalMediaC2V1_0TargetVideoDecTest.cpp
@@ -438,6 +438,7 @@
std::ifstream& eleStream, android::Vector<FrameInfo>* Info, int offset,
int range, bool signalEOS = true) {
typedef std::unique_lock<std::mutex> ULock;
+ static const size_t kPageSize = getpagesize();
int frameID = offset;
int maxRetry = 0;
while (1) {
@@ -479,7 +480,7 @@
ASSERT_EQ(eleStream.gcount(), size);
work->input.buffers.clear();
- auto alignedSize = ALIGN(size, PAGE_SIZE);
+ auto alignedSize = ALIGN(size, kPageSize);
if (size) {
std::shared_ptr<C2LinearBlock> block;
ASSERT_EQ(C2_OK, linearPool->fetchLinearBlock(
diff --git a/media/codec2/vndk/C2AllocatorIon.cpp b/media/codec2/vndk/C2AllocatorIon.cpp
index a6a733e..582a993 100644
--- a/media/codec2/vndk/C2AllocatorIon.cpp
+++ b/media/codec2/vndk/C2AllocatorIon.cpp
@@ -179,6 +179,7 @@
static Impl *Alloc(int ionFd, size_t size, size_t align, unsigned heapMask, unsigned flags, C2Allocator::id_t id);
c2_status_t map(size_t offset, size_t size, C2MemoryUsage usage, C2Fence *fence, void **addr) {
+ static const size_t kPageSize = getpagesize();
(void)fence; // TODO: wait for fence
*addr = nullptr;
if (!mMappings.lock()->empty()) {
@@ -201,7 +202,7 @@
prot |= PROT_WRITE;
}
- size_t alignmentBytes = offset % PAGE_SIZE;
+ size_t alignmentBytes = offset % kPageSize;
size_t mapOffset = offset - alignmentBytes;
size_t mapSize = size + alignmentBytes;
Mapping map = { nullptr, alignmentBytes, mapSize };
diff --git a/media/codec2/vndk/C2DmaBufAllocator.cpp b/media/codec2/vndk/C2DmaBufAllocator.cpp
index c470171..9baf8d8 100644
--- a/media/codec2/vndk/C2DmaBufAllocator.cpp
+++ b/media/codec2/vndk/C2DmaBufAllocator.cpp
@@ -170,6 +170,7 @@
c2_status_t C2DmaBufAllocation::map(size_t offset, size_t size, C2MemoryUsage usage, C2Fence* fence,
void** addr) {
+ static const size_t kPageSize = getpagesize();
(void)fence; // TODO: wait for fence
*addr = nullptr;
if (!mMappings.lock()->empty()) {
@@ -192,7 +193,7 @@
prot |= PROT_WRITE;
}
- size_t alignmentBytes = offset % PAGE_SIZE;
+ size_t alignmentBytes = offset % kPageSize;
size_t mapOffset = offset - alignmentBytes;
size_t mapSize = size + alignmentBytes;
Mapping map = {nullptr, alignmentBytes, mapSize};