Codec2: Add sys-prop to allow dmabuf heap usage to be forced
This patch adds support for a debug.c2.use_dmabufheaps=1 sysprop
which can be used to force DMABUF Heaps to be used even when
/dev/ion is present.
In the case the override is specified, but there is no
/dev/dma_heap/system device, the override will be ignored and
it will fall back to ION.
This will allow vendors to test DMABUF Heap implementations
while allowing other parts of the system to continue to use ION.
Signed-off-by: John Stultz <john.stultz@linaro.org>
Change-Id: I1cbbd8e201d11c4a47b89c9a45fe6dda53241355
diff --git a/media/codec2/vndk/C2Store.cpp b/media/codec2/vndk/C2Store.cpp
index dee3bf6..74ef9ea 100644
--- a/media/codec2/vndk/C2Store.cpp
+++ b/media/codec2/vndk/C2Store.cpp
@@ -102,16 +102,30 @@
}
static bool using_ion(void) {
- static int cached_result = -1;
-
- if (cached_result == -1) {
+ static int cached_result = []()->int {
struct stat buffer;
- cached_result = (stat("/dev/ion", &buffer) == 0);
- if (cached_result)
+ int ret = (stat("/dev/ion", &buffer) == 0);
+
+ if (property_get_int32("debug.c2.use_dmabufheaps", 0)) {
+ /*
+ * Double check that the system heap is present so we
+ * can gracefully fail back to ION if we cannot satisfy
+ * the override
+ */
+ ret = (stat("/dev/dma_heap/system", &buffer) != 0);
+ if (ret)
+ ALOGE("debug.c2.use_dmabufheaps set, but no system heap. Ignoring override!");
+ else
+ ALOGD("debug.c2.use_dmabufheaps set, forcing DMABUF Heaps");
+ }
+
+ if (ret)
ALOGD("Using ION\n");
else
ALOGD("Using DMABUF Heaps\n");
- }
+ return ret;
+ }();
+
return (cached_result == 1);
}