From f5c7dcee2d14734e013e0f32ee8f93cf0ae4ae5e Mon Sep 17 00:00:00 2001 From: Amy Zhang Date: Mon, 1 Mar 2021 20:18:26 -0800 Subject: [PATCH] Make the tv tuner hal use libdmabufheap instead of libion Cherry-pick the same change from aosp/1610134 on Tuner 1.0 to Tuner 1.1 in sc-dev branch Let the TV tuner HAL allocate DMA-BUFs fds with libdmabufheap. Devices supporting ION will continue to allocate from ION with the change. Devices that are deprecating ION will be able to allocate from the DMA-BUF heap framework instead. Both frameworks allocate DMA-BUFs, hence no other changes are required in the handling of the fd. Test: make android.hardware.tv.tuner@1.1-service and sampletis on Cuttlefish Refer to AOSP Change-Id: Ic147ed83c9097be76162a86cd4f94d3b1c27a10f Change-Id: Ibb4f29624008b5af24429c48fc72f6bf8a8bc5ac Bug: 181341260 Bug: 181997400 Change-Id: Ic392428f1cef183ef4c9c8720bc984673095f2a9 --- tv/tuner/1.1/default/Android.bp | 1 + tv/tuner/1.1/default/Filter.cpp | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tv/tuner/1.1/default/Android.bp b/tv/tuner/1.1/default/Android.bp index 86025cf4dd..a612802527 100644 --- a/tv/tuner/1.1/default/Android.bp +++ b/tv/tuner/1.1/default/Android.bp @@ -31,6 +31,7 @@ cc_defaults { "android.hardware.tv.tuner@1.1", "android.hidl.memory@1.0", "libcutils", + "libdmabufheap", "libfmq", "libhidlbase", "libhidlmemory", diff --git a/tv/tuner/1.1/default/Filter.cpp b/tv/tuner/1.1/default/Filter.cpp index 5ddac9909f..7d609ea3dc 100644 --- a/tv/tuner/1.1/default/Filter.cpp +++ b/tv/tuner/1.1/default/Filter.cpp @@ -16,9 +16,11 @@ #define LOG_TAG "android.hardware.tv.tuner@1.1-Filter" -#include "Filter.h" +#include #include +#include "Filter.h" + namespace android { namespace hardware { namespace tv { @@ -829,15 +831,15 @@ void Filter::detachFilterFromRecord() { } int Filter::createAvIonFd(int size) { - // Create an ion fd and allocate an av fd mapped to a buffer to it. - int ion_fd = ion_open(); - if (ion_fd == -1) { - ALOGE("[Filter] Failed to open ion fd %d", errno); + // Create an DMA-BUF fd and allocate an av fd mapped to a buffer to it. + auto buffer_allocator = std::make_unique(); + if (!buffer_allocator) { + ALOGE("[Filter] Unable to create BufferAllocator object"); return -1; } int av_fd = -1; - ion_alloc_fd(dup(ion_fd), size, 0 /*align*/, ION_HEAP_SYSTEM_MASK, 0 /*flags*/, &av_fd); - if (av_fd == -1) { + av_fd = buffer_allocator->Alloc("system-uncached", size); + if (av_fd < 0) { ALOGE("[Filter] Failed to create av fd %d", errno); return -1; }