Replace android.hidl.allocator usage
Allocate the memory directly with ashmem_create_region which is what the
allocator implementation does.
The HIDL allocator service is no longer installed on a new devices with
the deprecation of HIDL.
Test: atest Mpeg2tsUnitTest
Bug: 205764958
Change-Id: I34a96ac63e0be9fb81d281d3bdab22146fd1c3cd
diff --git a/media/module/mpeg2ts/ATSParser.cpp b/media/module/mpeg2ts/ATSParser.cpp
index 6aeea3b..86187bd 100644
--- a/media/module/mpeg2ts/ATSParser.cpp
+++ b/media/module/mpeg2ts/ATSParser.cpp
@@ -23,8 +23,8 @@
#include "ESQueue.h"
#include <android/hardware/cas/native/1.0/IDescrambler.h>
-#include <android/hidl/allocator/1.0/IAllocator.h>
#include <android/hidl/memory/1.0/IMemory.h>
+#include <cutils/ashmem.h>
#include <cutils/native_handle.h>
#include <hidlmemory/mapping.h>
#include <media/cas/DescramblerAPI.h>
@@ -46,12 +46,12 @@
#include <inttypes.h>
namespace android {
+using hardware::hidl_handle;
using hardware::hidl_string;
using hardware::hidl_vec;
using hardware::hidl_memory;
using namespace hardware::cas::V1_0;
using namespace hardware::cas::native::V1_0;
-typedef hidl::allocator::V1_0::IAllocator TAllocator;
typedef hidl::memory::V1_0::IMemory TMemory;
// I want the expression "y" evaluated even if verbose logging is off.
@@ -210,7 +210,6 @@
bool mSampleEncrypted;
sp<AMessage> mSampleAesKeyItem;
sp<TMemory> mHidlMemory;
- sp<TAllocator> mHidlAllocator;
hardware::cas::native::V1_0::SharedBuffer mDescramblerSrcBuffer;
sp<ABuffer> mDescrambledBuffer;
List<SubSampleInfo> mSubSamples;
@@ -1006,34 +1005,29 @@
sp<ABuffer> newBuffer, newScrambledBuffer;
sp<TMemory> newMem;
if (mScrambled) {
- if (mHidlAllocator == nullptr) {
- mHidlAllocator = TAllocator::getService("ashmem");
- if (mHidlAllocator == nullptr) {
- ALOGE("[stream %d] can't get hidl allocator", mElementaryPID);
- return false;
+ int fd = ashmem_create_region("mediaATS", neededSize);
+ if (fd < 0) {
+ ALOGE("[stream %d] create_ashmem_region failed for size %zu. FD returned: %d",
+ mElementaryPID, neededSize, fd);
+ return false;
+ }
+
+ native_handle_t* handle = native_handle_create(1 /*numFds*/, 0/*numInts*/);
+ if (handle == nullptr) {
+ ALOGE("[stream %d] failed to create a native_handle_t", mElementaryPID);
+ if (close(fd)) {
+ ALOGE("[stream %d] failed to close ashmem fd. errno: %s", mElementaryPID,
+ strerror(errno));
}
- }
- hidl_memory hidlMemToken;
- bool success;
- auto transStatus = mHidlAllocator->allocate(
- neededSize,
- [&success, &hidlMemToken](
- bool s,
- hidl_memory const& m) {
- success = s;
- hidlMemToken = m;
- });
-
- if (!transStatus.isOk()) {
- ALOGE("[stream %d] hidl allocator failed at the transport: %s",
- mElementaryPID, transStatus.description().c_str());
return false;
}
- if (!success) {
- ALOGE("[stream %d] hidl allocator failed", mElementaryPID);
- return false;
- }
+
+ handle->data[0] = fd;
+ hidl_handle memHandle;
+ memHandle.setTo(handle, true /*shouldOwn*/);
+ hidl_memory hidlMemToken("ashmem", memHandle, neededSize);
+
newMem = mapMemory(hidlMemToken);
if (newMem == nullptr || newMem->getPointer() == nullptr) {
ALOGE("[stream %d] hidl failed to map memory", mElementaryPID);