| Index: media/capture/video/android/tango_client_api_glue.cc
|
| diff --git a/media/capture/video/android/tango_client_api_glue.cc b/media/capture/video/android/tango_client_api_glue.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ae1753537b332e7c2c70eded3d1302c84debfd64
|
| --- /dev/null
|
| +++ b/media/capture/video/android/tango_client_api_glue.cc
|
| @@ -0,0 +1,117 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "tango_client_api_glue.h"
|
| +
|
| +#include <dlfcn.h>
|
| +
|
| +#include "base/logging.h"
|
| +
|
| +namespace media {
|
| +
|
| +void* TangoClientApiGlue::handle() {
|
| + static void* lib = dlopen(
|
| + "/data/data/com.google.tango/libfiles/armeabi-v7a/"
|
| + "libtango_client_api.so",
|
| + RTLD_NOW);
|
| + DLOG_IF(ERROR, !lib) << "Could not dlopen(\"libtango_client_api\")";
|
| + return lib;
|
| +}
|
| +
|
| +// An example of expanded code for TANGO_METHOD:
|
| +// TANGO_METHOD(TangoErrorType, TangoService_setBinder, TANGO_ERROR,
|
| +// void* jni_env, void* iBinder)
|
| +// expands to:
|
| +// TangoErrorType TangoService_setBinder(void* jni_env, void* iBinder) {
|
| +// using TangoService_setBinderPtr = TangoErrorType(*)(void* jni_env,
|
| +// void* iBinder);
|
| +// static TangoService_setBinderPtr func =
|
| +// reinterpret_cast<TangoService_setBinderPtr>(dlsym(lib_, __func__));
|
| +// if (!func) {
|
| +// DLOG(ERROR) << "dlsym failed on"<< __func__;
|
| +// return TANGO_ERROR;
|
| +// }
|
| +#define TANGO_METHOD(ret, name, return_on_error, params, ...) \
|
| + ret TangoClientApiGlue::name(__VA_ARGS__) { \
|
| + using name##Ptr = ret (*)(__VA_ARGS__); \
|
| + static name##Ptr func = \
|
| + reinterpret_cast<name##Ptr>(dlsym(handle(), __func__)); \
|
| + if (!func) { \
|
| + DLOG(ERROR) << "dlsym failed on" << __func__; \
|
| + return return_on_error; \
|
| + } \
|
| + return params; \
|
| + }
|
| +
|
| +TANGO_METHOD(TangoClientApiGlue::TangoErrorType,
|
| + TangoService_setBinder,
|
| + TANGO_METHOD_NOT_FOUND,
|
| + func(jni_env, iBinder),
|
| + void* jni_env,
|
| + void* iBinder)
|
| +
|
| +TANGO_METHOD(TangoClientApiGlue::TangoConfig,
|
| + TangoService_getConfig,
|
| + nullptr,
|
| + func(config_type),
|
| + TangoConfigType config_type)
|
| +
|
| +TANGO_METHOD(TangoClientApiGlue::TangoErrorType,
|
| + TangoConfig_setBool,
|
| + TANGO_METHOD_NOT_FOUND,
|
| + func(config, key, value),
|
| + TangoConfig config,
|
| + const char* key,
|
| + bool value)
|
| +
|
| +TANGO_METHOD(TangoClientApiGlue::TangoErrorType,
|
| + TangoConfig_setInt32,
|
| + TANGO_METHOD_NOT_FOUND,
|
| + func(config, key, value),
|
| + TangoConfig config,
|
| + const char* key,
|
| + int32_t value)
|
| +
|
| +TANGO_METHOD(TangoClientApiGlue::TangoErrorType,
|
| + TangoService_connect,
|
| + TANGO_METHOD_NOT_FOUND,
|
| + func(context, config),
|
| + void* context,
|
| + TangoConfig config)
|
| +
|
| +TANGO_METHOD(TangoClientApiGlue::TangoErrorType,
|
| + TangoService_getCameraIntrinsics,
|
| + TANGO_METHOD_NOT_FOUND,
|
| + func(camera_id, intrinsics),
|
| + TangoCameraId camera_id,
|
| + TangoCameraIntrinsics* intrinsics)
|
| +
|
| +TANGO_METHOD(void, TangoService_disconnect, void(), func())
|
| +
|
| +TangoClientApiGlue::TangoErrorType
|
| +TangoClientApiGlue::TangoService_connectOnPointCloudAvailable(
|
| + void (*TangoService_onPointCloudAvailable)(void* context,
|
| + const TangoPointCloud* cloud),
|
| + ...) {
|
| + using TangoService_connectOnPointCloudAvailablePtr =
|
| + TangoClientApiGlue::TangoErrorType (*)(
|
| + void (*TangoService_onPointCloudAvailable)(
|
| + void* context, const TangoPointCloud* cloud),
|
| + ...);
|
| + static TangoService_connectOnPointCloudAvailablePtr func =
|
| + reinterpret_cast<TangoService_connectOnPointCloudAvailablePtr>(
|
| + dlsym(handle(), __func__));
|
| + if (!func) {
|
| + DLOG(ERROR) << "dlsym failed on" << __func__;
|
| + return TANGO_METHOD_NOT_FOUND;
|
| + }
|
| + va_list args;
|
| + va_start(args, TangoService_onPointCloudAvailable);
|
| + TangoClientApiGlue::TangoErrorType result =
|
| + func(TangoService_onPointCloudAvailable, args);
|
| + va_end(args);
|
| + return result;
|
| +}
|
| +
|
| +} // namespace media
|
|
|