Chromium Code Reviews| Index: media/capture/video/android/tango_api.cc |
| diff --git a/media/capture/video/android/tango_api.cc b/media/capture/video/android/tango_api.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0566b5b475714aa1802521ff5f58012766650aca |
| --- /dev/null |
| +++ b/media/capture/video/android/tango_api.cc |
| @@ -0,0 +1,122 @@ |
| +// 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_api.h" |
| + |
| +#include <dlfcn.h> |
| + |
| +#include "base/logging.h" |
| + |
| +namespace media { |
| + |
| +// static |
| +std::unique_ptr<TangoApi> TangoApi::loadAndCreate() { |
|
aleksandar.stojiljkovic
2017/07/24 08:16:58
Note that WebAR code (I copied the native Tango in
|
| + void* lib_ = dlopen( |
| + "/data/data/com.google.tango/libfiles/armeabi-v7a/" |
| + "libtango_client_api.so", |
| + RTLD_NOW); |
| + if (!lib_) { |
| + LOG(ERROR) << "Could not dlopen(\"libtango_client_api\"):" << dlerror(); |
| + return nullptr; |
| + } |
| + return std::unique_ptr<TangoApi>(new TangoApi(lib_)); |
| +} |
| + |
| +TangoApi::TangoApi(void* lib_client_api) : lib_(lib_client_api) {} |
| + |
| +// 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) { |
| +// LOG(ERROR) << "dlsym failed on"<< __PRETTY_FUNCTION__ << dlerror(); |
| +// return TANGO_ERROR; |
| +// } |
| +#define TANGO_METHOD(ret, name, return_on_error, params, ...) \ |
| + ret TangoApi::name(__VA_ARGS__) { \ |
| + using name##Ptr = ret (*)(__VA_ARGS__); \ |
| + static name##Ptr func = \ |
| + reinterpret_cast<name##Ptr>(dlsym(lib_, __func__)); \ |
| + if (!func) { \ |
| + LOG(ERROR) << "dlsym failed on" << __func__ << dlerror(); \ |
| + return return_on_error; \ |
| + } \ |
| + return params; \ |
| + } |
| + |
| +TANGO_METHOD(TangoApi::TangoErrorType, |
| + TangoService_setBinder, |
| + TANGO_METHOD_NOT_FOUND, |
| + func(jni_env, iBinder), |
| + void* jni_env, |
| + void* iBinder) |
| + |
| +TANGO_METHOD(TangoApi::TangoConfig, |
| + TangoService_getConfig, |
| + nullptr, |
| + func(config_type), |
| + TangoConfigType config_type) |
| + |
| +TANGO_METHOD(TangoApi::TangoErrorType, |
| + TangoConfig_setBool, |
| + TANGO_METHOD_NOT_FOUND, |
| + func(config, key, value), |
| + TangoConfig config, |
| + const char* key, |
| + bool value) |
| + |
| +TANGO_METHOD(TangoApi::TangoErrorType, |
| + TangoConfig_setInt32, |
| + TANGO_METHOD_NOT_FOUND, |
| + func(config, key, value), |
| + TangoConfig config, |
| + const char* key, |
| + int32_t value) |
| + |
| +TANGO_METHOD(TangoApi::TangoErrorType, |
| + TangoService_connect, |
| + TANGO_METHOD_NOT_FOUND, |
| + func(context, config), |
| + void* context, |
| + TangoConfig config) |
| + |
| +TANGO_METHOD(TangoApi::TangoErrorType, |
| + TangoService_getCameraIntrinsics, |
| + TANGO_METHOD_NOT_FOUND, |
| + func(camera_id, intrinsics), |
| + TangoCameraId camera_id, |
| + TangoCameraIntrinsics* intrinsics) |
| + |
| +TANGO_METHOD(void, TangoService_disconnect, void(), func()) |
| + |
| +TangoApi::TangoErrorType TangoApi::TangoService_connectOnPointCloudAvailable( |
| + void (*TangoService_onPointCloudAvailable)(void* context, |
| + const TangoPointCloud* cloud), |
| + ...) { |
| + using TangoService_connectOnPointCloudAvailablePtr = |
| + TangoApi::TangoErrorType (*)( |
| + void (*TangoService_onPointCloudAvailable)( |
| + void* context, const TangoPointCloud* cloud), |
| + ...); |
| + static TangoService_connectOnPointCloudAvailablePtr func = |
| + reinterpret_cast<TangoService_connectOnPointCloudAvailablePtr>( |
| + dlsym(lib_, __func__)); |
| + if (!func) { |
| + LOG(ERROR) << "dlsym failed on" << __PRETTY_FUNCTION__ << dlerror(); |
| + return TANGO_METHOD_NOT_FOUND; |
| + } |
| + va_list args; |
| + va_start(args, TangoService_onPointCloudAvailable); |
| + TangoApi::TangoErrorType result = |
| + func(TangoService_onPointCloudAvailable, args); |
| + va_end(args); |
| + return result; |
| +} |
| + |
| +} // namespace media |