Adds option to use tensor_ahwb in Android vendor processes

PiperOrigin-RevId: 558086646
This commit is contained in:
MediaPipe Team 2023-08-18 02:28:03 -07:00 committed by Copybara-Service
parent a04a3a1c81
commit fda0d19337
2 changed files with 26 additions and 2 deletions

View File

@ -427,6 +427,17 @@ cc_test(
],
)
# Used by vendor processes that don't have access to libandroid.so, but want to use AHardwareBuffer.
config_setting(
name = "android_link_native_window",
define_values = {
"MEDIAPIPE_ANDROID_LINK_NATIVE_WINDOW": "1",
"MEDIAPIPE_NO_JNI": "1",
},
values = {"crosstool_top": "//external:android/crosstool"},
visibility = ["//visibility:private"],
)
cc_library(
name = "tensor",
srcs =
@ -449,7 +460,13 @@ cc_library(
"//conditions:default": [],
}),
defines = select({
# Excludes AHardwareBuffer features from vendor processes
"//mediapipe/framework:android_no_jni": ["MEDIAPIPE_NO_JNI"],
# unless they're linked against nativewindow.
":android_link_native_window": [
"MEDIAPIPE_ANDROID_LINK_NATIVE_WINDOW",
"MEDIAPIPE_NO_JNI",
],
"//conditions:default": [],
}),
linkopts = select({
@ -462,6 +479,9 @@ cc_library(
"//mediapipe:android": [
"-landroid",
],
":android_link_native_window": [
"-lnativewindow", # Provides <android/hardware_buffer.h> to vendor processes on Android API >= 26.
],
}),
deps = [
"//mediapipe/framework:port",

View File

@ -29,12 +29,16 @@
#include "mediapipe/framework/formats/tensor/internal.h"
#include "mediapipe/framework/port.h"
#ifndef MEDIAPIPE_NO_JNI
// Supported use cases for tensor_ahwb:
// 1. Native code running in Android apps.
// 2. Android vendor processes linked against nativewindow.
#if !defined(MEDIAPIPE_NO_JNI) || defined(MEDIAPIPE_ANDROID_LINK_NATIVE_WINDOW)
#if __ANDROID_API__ >= 26 || defined(__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__)
#define MEDIAPIPE_TENSOR_USE_AHWB 1
#endif // __ANDROID_API__ >= 26 ||
// defined(__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__)
#endif // MEDIAPIPE_NO_JNI
#endif // !defined(MEDIAPIPE_NO_JNI) ||
// defined(MEDIAPIPE_ANDROID_LINK_NATIVE_WINDOW)
#ifdef MEDIAPIPE_TENSOR_USE_AHWB
#include <EGL/egl.h>