Commit 86c7e183 authored by Alexander Smorkalov's avatar Alexander Smorkalov

Issue #2316 Change default libnative_camera path implemented.

parent e564a53c
...@@ -5,7 +5,7 @@ ENDIF() ...@@ -5,7 +5,7 @@ ENDIF()
set(the_description "Auxiliary module for Android native camera support") set(the_description "Auxiliary module for Android native camera support")
set(OPENCV_MODULE_TYPE STATIC) set(OPENCV_MODULE_TYPE STATIC)
ocv_define_module(androidcamera INTERNAL log dl) ocv_define_module(androidcamera INTERNAL opencv_core log dl)
ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/camera_wrapper") ocv_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/camera_wrapper")
# Android source tree for native camera # Android source tree for native camera
......
#include <dlfcn.h> #include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <android/log.h> #include <android/log.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <opencv2/core/version.hpp>
#include "camera_activity.hpp" #include "camera_activity.hpp"
#include "camera_wrapper.h" #include "camera_wrapper.h"
...@@ -41,6 +45,7 @@ private: ...@@ -41,6 +45,7 @@ private:
static bool isConnectedToLib; static bool isConnectedToLib;
static std::string getPathLibFolder(); static std::string getPathLibFolder();
static std::string getDefaultPathLibFolder();
static CameraActivity::ErrorCode connectToLib(); static CameraActivity::ErrorCode connectToLib();
static CameraActivity::ErrorCode getSymbolFromLib(void * libHandle, const char* symbolName, void** ppSymbol); static CameraActivity::ErrorCode getSymbolFromLib(void * libHandle, const char* symbolName, void** ppSymbol);
static void fillListWrapperLibs(const string& folderPath, vector<string>& listLibs); static void fillListWrapperLibs(const string& folderPath, vector<string>& listLibs);
...@@ -55,8 +60,6 @@ private: ...@@ -55,8 +60,6 @@ private:
}; };
std::string CameraWrapperConnector::pathLibFolder; std::string CameraWrapperConnector::pathLibFolder;
#define DEFAULT_WRAPPER_PACKAGE_NAME "com.NativeCamera"
#define DEFAULT_PATH_LIB_FOLDER "/data/data/" DEFAULT_WRAPPER_PACKAGE_NAME "/lib/"
bool CameraWrapperConnector::isConnectedToLib=false; bool CameraWrapperConnector::isConnectedToLib=false;
InitCameraConnectC CameraWrapperConnector::pInitCameraC = 0; InitCameraConnectC CameraWrapperConnector::pInitCameraC = 0;
...@@ -163,7 +166,13 @@ CameraActivity::ErrorCode CameraWrapperConnector::connectToLib() ...@@ -163,7 +166,13 @@ CameraActivity::ErrorCode CameraWrapperConnector::connectToLib()
} }
dlerror(); dlerror();
string folderPath=getPathLibFolder(); string folderPath = getPathLibFolder();
if (folderPath.empty())
{
LOGD("Trying to find native camera in default OpenCV packages");
folderPath = getDefaultPathLibFolder();
}
LOGD("CameraWrapperConnector::connectToLib: folderPath=%s", folderPath.c_str()); LOGD("CameraWrapperConnector::connectToLib: folderPath=%s", folderPath.c_str());
vector<string> listLibs; vector<string> listLibs;
...@@ -256,6 +265,31 @@ void CameraWrapperConnector::fillListWrapperLibs(const string& folderPath, vecto ...@@ -256,6 +265,31 @@ void CameraWrapperConnector::fillListWrapperLibs(const string& folderPath, vecto
} }
} }
std::string CameraWrapperConnector::getDefaultPathLibFolder()
{
const string packageList[] = {"tegra3", "armv7a_neon", "armv7a", "armv5", "x86"};
for (size_t i = 0; i < 5; i++)
{
char path[128];
sprintf(path, "/data/data/org.opencv.lib_v%d%d_%s/lib/", CV_MAJOR_VERSION, CV_MINOR_VERSION, packageList[i].c_str());
LOGD("Trying package \"%s\" (\"%s\")", packageList[i], path);
DIR* dir = opendir(path);
if (!dir)
{
LOGD("Package not found");
continue;
}
else
{
closedir(dir);
return path;
}
}
return string();
}
std::string CameraWrapperConnector::getPathLibFolder() std::string CameraWrapperConnector::getPathLibFolder()
{ {
if (!pathLibFolder.empty()) if (!pathLibFolder.empty())
...@@ -312,7 +346,7 @@ std::string CameraWrapperConnector::getPathLibFolder() ...@@ -312,7 +346,7 @@ std::string CameraWrapperConnector::getPathLibFolder()
return pathBegin; return pathBegin;
} }
fclose(file); fclose(file);
LOGE("Could not find library path."); LOGE("Could not find library path");
} }
else else
{ {
...@@ -321,10 +355,10 @@ std::string CameraWrapperConnector::getPathLibFolder() ...@@ -321,10 +355,10 @@ std::string CameraWrapperConnector::getPathLibFolder()
} }
else else
{ {
LOGE("Could not get library name and base address."); LOGE("Could not get library name and base address");
} }
return DEFAULT_PATH_LIB_FOLDER ; return string();
} }
void CameraWrapperConnector::setPathLibFolder(const string& path) void CameraWrapperConnector::setPathLibFolder(const string& path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment