格式变化

hdrplus
jxjajs 7 months ago
commit 25e459faea

@ -5,7 +5,7 @@ plugins {
// 10,00,000 major-minor-build
def AppMajorVersion = 1
def AppMinorVersion = 1
def AppBuildNumber = 9
def AppBuildNumber = 10
def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber
def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber

@ -51,11 +51,7 @@ elseif(ANDROID_ABI STREQUAL "arm64-v8a")
# add_definitions(-DUSING_N938)
endif()
<<<<<<< HEAD
add_definitions(-DUSING_N938)
=======
>>>>>>> 1b0d0f421fe8db524af9afc327dce98899a13e6d
# include_directories(${OpenCV_DIR}/include)
# add_library( lib_opencv SHARED IMPORTED )
@ -377,7 +373,6 @@ add_library( # Sets the name of the library.
# Provides a relative path to your source file(s).
GPIOControl.cpp
MicroPhoto.cpp
TerminalDevice.cpp
PhoneDevice.cpp
# PhoneDevice2.cpp
Camera.cpp

@ -1,4 +1,3 @@
#include "TerminalDevice.h"
/*
* Copyright 2018 The Android Open Source Project
*

@ -11,6 +11,7 @@
#include <sys/mman.h>
#include <unistd.h>
#include <climits>
#include "GPIOControl.h"
@ -22,12 +23,15 @@
#define IOT_PARAM_READ 0xAF
std::mutex GpioControl::m_locker;
std::vector<std::pair<int, uint32_t>> GpioControl::m_references;
CSemaphore GpioControl::m_semaphore;
std::vector<GpioControl::ITEM> GpioControl::m_items;
std::thread GpioControl::m_thread;
bool GpioControl::m_exitSignal = false;
int GpioControl::turnOnImpl(const IOT_PARAM& param)
size_t GpioControl::turnOnImpl(const IOT_PARAM& param)
{
uint32_t references = 1;
std::vector<std::pair<int, uint32_t> >::iterator it;
size_t references = 1;
std::vector<ITEM>::iterator it;
int res = 0;
int fd = -1;
@ -37,108 +41,41 @@ int GpioControl::turnOnImpl(const IOT_PARAM& param)
res = ioctl(fd, IOT_PARAM_WRITE, &param);
close(fd);
// check res???
for (it = m_references.begin(); it != m_references.end(); ++it)
for (it = m_items.begin(); it != m_items.end(); ++it)
{
if (it->first == param.cmd)
if (it->cmd == param.cmd)
{
it->second++;
references = it->second;
it->references++;
it->closeTime = 0;
references = it->references;
break;
}
}
if (it == m_references.end())
if (it == m_items.end())
{
m_references.push_back(std::pair<int, uint32_t >(param.cmd, references));
ITEM item = {param.cmd, references, 0, 0};
m_items.push_back(item);
}
}
return references;
}
int GpioControl::turnOffImpl(const IOT_PARAM& param)
void GpioControl::setInt(int cmd, int value)
{
uint32_t references = 0;
std::vector<std::pair<int, uint32_t> >::iterator it;
int res = 0;
int fd = -1;
for (it = m_references.begin(); it != m_references.end(); ++it)
{
if (it->first == param.cmd)
{
if (it->second > 0)
{
it->second--;
}
references = it->second;
break;
}
}
IOT_PARAM param = { cmd, value, 0 };
// param.cmd = cmd;
// param.value = value;
if (references == 0)
{
fd = open(GPIO_NODE_MP, O_RDONLY);
int fd = open(GPIO_NODE_MP, O_RDONLY);
if (fd > 0)
{
res = ioctl(fd, IOT_PARAM_WRITE, &param);
int res = ioctl(fd, IOT_PARAM_WRITE, &param);
#ifdef _DEBUG
ALOGI("setInt cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result);
#endif
close(fd);
}
}
return references;
}
void GpioControl::setInt(int cmd, int value)
{
IOT_PARAM param = { cmd, value, 0 };
// param.cmd = cmd;
// param.value = value;
if (value)
{
m_locker.lock();
turnOnImpl(param);
m_locker.unlock();
}
else
{
m_locker.lock();
turnOffImpl(param);
m_locker.unlock();
}
}
void GpioControl::setInt(const std::vector<int>& cmds, int value)
{
IOT_PARAM param = { 0, value, 0 };
// param.cmd = cmd;
// param.value = value;
std::vector<int>::const_iterator it;
if (value)
{
m_locker.lock();
for (it = cmds.cbegin(); it != cmds.cend(); ++it)
{
param.cmd = *it;
turnOnImpl(param);
}
m_locker.unlock();
}
else
{
m_locker.lock();
for (it = cmds.cbegin(); it != cmds.cend(); ++it)
{
param.cmd = *it;
turnOffImpl(param);
}
m_locker.unlock();
}
}
int GpioControl::getInt(int cmd)
@ -226,7 +163,6 @@ std::string GpioControl::getString(int cmd)
return "";
}
<<<<<<< HEAD
#ifdef USING_N938
#if 0
@ -271,22 +207,244 @@ bool GpioControl::OpenSensors()
igpio = GpioControl::getInt(CMD_SET_PIC1_POWER);
GpioControl::setInt(CMD_SET_SPI_POWER, 1);
GpioControl::setInt(CMD_SET_485_en0, 1);
GpioControl::setInt(CMD_SET_485_en1, 1);
GpioControl::setInt(CMD_SET_485_en2, 1);
GpioControl::setInt(CMD_SET_485_en3, 1);
GpioControl::setInt(CMD_SET_485_en4, 1);
GpioControl::setInt(CMD_SET_485_EN0, 1);
GpioControl::setInt(CMD_SET_485_EN1, 1);
GpioControl::setInt(CMD_SET_485_EN2, 1);
GpioControl::setInt(CMD_SET_485_EN3, 1);
GpioControl::setInt(CMD_SET_485_EN4, 1);
igpio = GpioControl::getInt(CMD_SET_SPI_POWER);
igpio = GpioControl::getInt(CMD_SET_485_en0);
igpio = GpioControl::getInt(CMD_SET_485_en1);
igpio = GpioControl::getInt(CMD_SET_485_en2);
igpio = GpioControl::getInt(CMD_SET_485_en3);
igpio = GpioControl::getInt(CMD_SET_485_en4);
igpio = GpioControl::getInt(CMD_SET_485_EN0);
igpio = GpioControl::getInt(CMD_SET_485_EN1);
igpio = GpioControl::getInt(CMD_SET_485_EN2);
igpio = GpioControl::getInt(CMD_SET_485_EN3);
igpio = GpioControl::getInt(CMD_SET_485_EN4);
return 0;
}
#endif
/////////////////////////// Power Control /////////////////////////////////
size_t GpioControl::TurnOn(int cmd)
{
IOT_PARAM param = { cmd, 1, 0 };
// param.cmd = cmd;
// param.value = value;
m_locker.lock();
size_t ref = turnOnImpl(param);
m_locker.unlock();
return ref;
}
size_t GpioControl::TurnOn(const std::vector<int>& cmds)
{
IOT_PARAM param = { 0, 1, 0 };
// param.cmd = cmd;
// param.value = value;
std::vector<int>::const_iterator it;
m_locker.lock();
for (it = cmds.cbegin(); it != cmds.cend(); ++it)
{
param.cmd = *it;
turnOnImpl(param);
}
m_locker.unlock();
return 0;
}
size_t GpioControl::TurnOff(int cmd, uint32_t delayedCloseTime/* = 0*/)
{
time_t ts = 0;
if (delayedCloseTime > 0)
{
ts = time(NULL) + delayedCloseTime;
}
size_t ref = 0;
std::vector<ITEM>::iterator it;
m_locker.lock();
for (it = m_items.begin(); it != m_items.end(); ++it)
{
if (it->cmd == cmd)
{
ref = it->references;
it->closeCmds++;
if (ts > it->closeTime)
{
it->closeTime = ts;
}
break;
}
}
m_locker.unlock();
m_semaphore.release();
return 0;
}
size_t GpioControl::TurnOff(const std::vector<int>& cmds, uint32_t delayedCloseTime/* = 0*/)
{
time_t ts = 0;
if (delayedCloseTime > 0)
{
ts = time(NULL) + delayedCloseTime;
}
std::vector<ITEM>::iterator it;
std::vector<int>::const_iterator itCmd;
m_locker.lock();
// turnOnImpl(param);
for (itCmd = cmds.cbegin(); itCmd != cmds.end(); ++itCmd)
{
for (it = m_items.begin(); it != m_items.end(); ++it)
{
if (it->cmd == *itCmd)
{
it->closeCmds++;
if (ts > it->closeTime)
{
it->closeTime = ts;
}
break;
}
}
}
m_locker.unlock();
m_semaphore.release();
return 0;
}
size_t GpioControl::TurnOff(const std::vector<std::pair<int, uint32_t> >& cmds)
{
time_t ts = time(NULL);
time_t ts2;
std::vector<ITEM>::iterator it;
std::vector<std::pair<int, uint32_t> >::const_iterator itCmd;
m_locker.lock();
for (itCmd = cmds.cbegin(); itCmd != cmds.end(); ++itCmd)
{
for (it = m_items.begin(); it != m_items.end(); ++it)
{
if (it->cmd == itCmd->first)
{
it->closeCmds++;
if (itCmd->second != 0)
{
ts2 = itCmd->second + ts;
if (ts2 > it->closeTime)
{
it->closeTime = ts2;
}
}
break;
}
}
}
m_locker.unlock();
m_semaphore.release();
return 0;
}
void GpioControl::PowerControlThreadProc()
{
time_t ts = 0;
std::vector<ITEM>::iterator it;
std::vector<int> items;
time_t minDelayTime = 0;
time_t delayTime = 0;
int fd = -1;
int res = -1;
while(1)
{
// Check if there is close cmd
ts = time(NULL);
minDelayTime = std::numeric_limits<time_t>::max();
m_locker.lock();
for (it = m_items.begin(); it != m_items.end(); ++it)
{
if (it->references == 0 && it->closeCmds == 0 && it->closeTime == 0)
{
continue;
}
if (it->closeCmds > 0)
{
if (it->references <= it->closeCmds)
{
it->references = 0;
}
else
{
it->references -= it->closeCmds;
}
it->closeCmds = 0;
}
if (it->references == 0)
{
// Should turn off the power
if ((it->closeTime == 0) || (it->closeTime <= ts))
{
// close it directly
setInt(it->cmd, 0);
it->closeTime = 0;
}
else
{
// Check Time
delayTime = ts - it->closeTime;
if (delayTime < minDelayTime)
{
minDelayTime = delayTime;
}
}
}
}
m_locker.unlock();
if (minDelayTime < std::numeric_limits<time_t>::max())
{
m_semaphore.try_acquire_for(std::chrono::seconds(1));
}
else
{
m_semaphore.acquire();
}
if (m_exitSignal)
{
break;
}
}
}
bool GpioControl::Startup()
{
// if (m_thread.)
m_exitSignal = false;
m_thread = std::thread(PowerControlThreadProc);
#ifdef _DEBUG
pthread_t nativeHandle = m_thread.native_handle();
pthread_setname_np(nativeHandle, "gpioclose");
#endif
=======
>>>>>>> 1b0d0f421fe8db524af9afc327dce98899a13e6d
return true;
}
void GpioControl::Stop()
{
// Notify
m_exitSignal = true;
m_semaphore.release();
m_thread.detach();
}

@ -12,7 +12,7 @@
#include <vector>
#include <utility>
#include <SemaphoreEx.h>
#ifndef USING_N938
@ -115,12 +115,9 @@
#endif // USING_N938
<<<<<<< HEAD
#ifndef USING_N938
#define GPIO_NODE_N938 "/sys/devices/platform/1000b000.pinctrl/mt_gpio"
#else
=======
>>>>>>> 1b0d0f421fe8db524af9afc327dce98899a13e6d
#define GPIO_NODE_MP "/dev/mtkgpioctrl"
#define MAX_STRING_LEN 32
@ -135,18 +132,42 @@ typedef struct
class GpioControl
{
public:
struct ITEM
{
int cmd;
size_t references;
size_t closeCmds;
time_t closeTime;
};
private:
static std::mutex m_locker;
static std::vector<std::pair<int, uint32_t>> m_references;
static CSemaphore m_semaphore;
static std::vector<ITEM> m_items;
static bool m_exitSignal;
static std::thread m_thread;
protected:
static int turnOnImpl(const IOT_PARAM& param);
static int turnOffImpl(const IOT_PARAM& param);
static size_t turnOnImpl(const IOT_PARAM& param);
static size_t turnOffImpl(const IOT_PARAM& param);
public:
static void setInt(int cmd, int value);
static void setInt(const std::vector<int>& cmds, int value);
// Power
static size_t TurnOn(int cmd);
static size_t TurnOn(const std::vector<int>& cmds);
static size_t TurnOff(int cmd, uint32_t delayedCloseTime = 0);
static size_t TurnOff(const std::vector<int>& cmds, uint32_t delayedCloseTime = 0);
static size_t TurnOff(const std::vector<std::pair<int, uint32_t> >& cmds);
static void PowerControlThreadProc();
static bool Startup();
static void Stop();
public:
static void setInt(int cmd, int value);
static int getInt(int cmd);
static void setLong(int cmd, long value);
static long getLong(int cmd);
@ -156,7 +177,7 @@ public:
static void setOtgState(bool on)
{
#ifndef USING_N938
setInt(CMD_SET_OTG_STATE, on ? 1 : 0);
on ? TurnOn(CMD_SET_OTG_STATE) : TurnOff(CMD_SET_OTG_STATE);
#endif
}
@ -171,10 +192,42 @@ public:
static void setCam3V3Enable(bool enabled)
{
#ifdef ENABLE_3V3_ALWAYS
setInt(CMD_SET_CAM_3V3_EN_STATE, 1);
#else
setInt(CMD_SET_CAM_3V3_EN_STATE, enabled ? 1 : 0);
enabled ? TurnOn(CMD_SET_CAM_3V3_EN_STATE) : TurnOff(CMD_SET_CAM_3V3_EN_STATE);
}
static void setBeeOn(bool z)
{
#ifndef USING_N938
z ? TurnOn(CMD_SET_PWM_BEE_STATE) : TurnOff(CMD_SET_PWM_BEE_STATE);
#endif
}
static void setJidianqiState(bool z) {
#ifndef USING_N938
z ? TurnOn(CMD_SET_ALM_MODE) : TurnOff(CMD_SET_ALM_MODE);
#endif
}
static void setSpiPower(bool on) {
on ? TurnOn(CMD_SET_SPI_POWER) : TurnOff(CMD_SET_SPI_POWER);
if (on)
{
std::this_thread::sleep_for(std::chrono::milliseconds(40));
}
}
static void setRS485Enable(bool z)
{
#ifndef USING_N938
z ? TurnOn(CMD_SET_485_EN_STATE) : TurnOff(CMD_SET_485_EN_STATE);
#endif
}
static void set12VEnable(bool z)
{
#ifndef USING_N938
z ? TurnOn(CMD_SET_12V_EN_STATE) : TurnOff(CMD_SET_12V_EN_STATE);
#endif
}
@ -311,40 +364,7 @@ public:
#endif
}
static void setBeeOn(bool z) {
#ifndef USING_N938
setInt(CMD_SET_PWM_BEE_STATE, z ? 1 : 0);
#endif
}
static void setJidianqiState(bool z) {
#ifndef USING_N938
setInt(CMD_SET_ALM_MODE, z ? 1 : 0);
#endif
}
static void setSpiPower(bool on) {
setInt(CMD_SET_SPI_POWER, on ? 1 : 0);
if (on)
{
std::this_thread::sleep_for(std::chrono::milliseconds(40));
}
}
static void setRS485Enable(bool z) {
#ifndef USING_N938
setInt(CMD_SET_485_EN_STATE, z ? 1 : 0);
#endif
}
static void set12VEnable(bool z) {
#ifndef USING_N938
setInt(CMD_SET_12V_EN_STATE, z ? 1 : 0);
#endif
}
};
#endif
#endif //MICROPHOTO_GPIOCONTROL_H

@ -3,9 +3,7 @@
#include <thread>
#include <Factory.h>
#include <Client/Terminal.h>
#include "TerminalDevice.h"
#include "PhoneDevice.h"
#include "PhoneDevice2.h"
#include <LogThread.h>
#include <sys/system_properties.h>
#include <AndroidHelper.h>
@ -26,7 +24,6 @@
#include <android/native_window.h>
#include <android/native_window_jni.h>
#include "Camera.h"
#include "Camera2Reader.h"
#include "GPIOControl.h"
@ -401,9 +398,9 @@ Java_com_xypower_mpapp_MicroPhotoService_takePhoto(
if (photoInfo.usbCamera)
{
CPhoneDevice::TurnOnOtg(NULL);
GpioControl::setOtgState(true);
}
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setCam3V3Enable(true);
std::vector<IDevice::OSD_INFO> osds;
osds.resize(4);
@ -1045,8 +1042,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPublicKeyFile(
const char *md5Str = env->GetStringUTFChars(md5, 0);
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setCam3V3Enable(true);
GpioControl::setSpiPower(true);
NrsecPort nrsec;
@ -1059,7 +1055,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPublicKeyFile(
}
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL);
GpioControl::setCam3V3Enable(false);
env->ReleaseStringUTFChars(md5, md5Str);
@ -1081,8 +1077,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPublicKey(
return JNI_FALSE;
}
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setCam3V3Enable(true);
GpioControl::setSpiPower(true);
NrsecPort nrsec;
@ -1097,7 +1092,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPublicKey(
}
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL);
GpioControl::setCam3V3Enable(false);
return res ? JNI_TRUE : JNI_FALSE;
#else
@ -1118,8 +1113,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPrivateKey(
return JNI_FALSE;
}
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setCam3V3Enable(true);
GpioControl::setSpiPower(true);
NrsecPort nrsec;
@ -1134,7 +1128,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPrivateKey(
}
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL);
GpioControl::setCam3V3Enable(false);
return res ? JNI_TRUE : JNI_FALSE;
#else
@ -1157,8 +1151,7 @@ Java_com_xypower_mpapp_MicroPhotoService_genKeys(
#ifdef USING_NRSEC
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setCam3V3Enable(true);
GpioControl::setSpiPower(true);
const char *path = NRSEC_PATH;
@ -1172,7 +1165,7 @@ Java_com_xypower_mpapp_MicroPhotoService_genKeys(
}
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL);
GpioControl::setCam3V3Enable(false);
return res ? JNI_TRUE : JNI_FALSE;
#else
@ -1187,8 +1180,7 @@ Java_com_xypower_mpapp_MicroPhotoService_querySecVersion(
std::string version;
#ifdef USING_NRSEC
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setCam3V3Enable(true);
GpioControl::setSpiPower(true);
const char *path = NRSEC_PATH;
@ -1202,7 +1194,7 @@ Java_com_xypower_mpapp_MicroPhotoService_querySecVersion(
}
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL);
GpioControl::setCam3V3Enable(false);
#endif
return env->NewStringUTF(version.c_str());
}
@ -1218,8 +1210,7 @@ Java_com_xypower_mpapp_MicroPhotoService_genCertRequest(
}
const char *path = NRSEC_PATH;
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setCam3V3Enable(true);
GpioControl::setSpiPower(true);
uint8_t output[1024] = { 0 };
@ -1237,7 +1228,7 @@ Java_com_xypower_mpapp_MicroPhotoService_genCertRequest(
}
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL);
GpioControl::setCam3V3Enable(false);
if (res)
{
@ -1276,8 +1267,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPrivateKeyFile(
const char *path = NRSEC_PATH;
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setCam3V3Enable(true);
GpioControl::setSpiPower(true);
NrsecPort nrsec;
@ -1289,7 +1279,7 @@ Java_com_xypower_mpapp_MicroPhotoService_importPrivateKeyFile(
}
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL);
GpioControl::setCam3V3Enable(false);
// const char *md5Str = env->GetStringUTFChars(md5, 0);
// env->ReleaseStringUTFChars(md5, md5Str);
@ -1316,8 +1306,7 @@ Java_com_xypower_mpapp_MicroPhotoService_exportPublicKeyFile(
uint8_t len = 0;
std::vector<unsigned char> data(64, 0);
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setCam3V3Enable(true);
GpioControl::setSpiPower(true);
NrsecPort nrsec;
@ -1329,7 +1318,7 @@ Java_com_xypower_mpapp_MicroPhotoService_exportPublicKeyFile(
}
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL);
GpioControl::setCam3V3Enable(false);
if (res)
{
@ -1355,8 +1344,7 @@ Java_com_xypower_mpapp_MicroPhotoService_exportPrivateFile(
const char *path = NRSEC_PATH;
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOnCameraPower(NULL);
GpioControl::setCam3V3Enable(true);
GpioControl::setSpiPower(true);
NrsecPort nrsec;
@ -1371,7 +1359,7 @@ Java_com_xypower_mpapp_MicroPhotoService_exportPrivateFile(
nrsec.Close();
GpioControl::setSpiPower(false);
CPhoneDevice::TurnOffCameraPower(NULL);
GpioControl::setCam3V3Enable(false);
if (res) {
const char *outputPathStr = env->GetStringUTFChars(outputPath, 0);

@ -417,10 +417,6 @@ int32_t CPhoneDevice::CJpegCamera::getOutputFormat() const
return AIMAGE_FORMAT_JPEG;
}
std::mutex CPhoneDevice::m_powerLocker;
long CPhoneDevice::mCameraPowerCount = 0;
long CPhoneDevice::mOtgCount = 0;
CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPath, unsigned int netId, unsigned int versionCode, const std::string& nativeLibDir)
: mVersionCode(versionCode), m_nativeLibraryDir(nativeLibDir), m_network(NULL), m_netHandle(NETWORK_UNSPECIFIED)
{
@ -445,6 +441,8 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
RegisterHandlerForSignal(SIGUSR2);
GpioControl::Startup();
LoadNetworkInfo();
m_vm = vm;
@ -493,7 +491,7 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
m_uniqueIdFeed = (unsigned long)m_timerUidFeed;
#ifdef USING_NRSEC
TurnOnCameraPower(env);
GpioControl::setCam3V3Enable(true);
GpioControl::setSpiPower(true);
#endif
}
@ -537,6 +535,8 @@ CPhoneDevice::~CPhoneDevice()
delete m_network;
m_network = NULL;
}
GpioControl::Stop();
}
void CPhoneDevice::SetListener(IListener* listener)
@ -671,16 +671,16 @@ bool CPhoneDevice::SelfTest(std::string& result)
params.burstCaptures = 1;
if (usbCamera)
{
TurnOnOtg(NULL);
GpioControl::setOtgState(true);
}
TurnOnCameraPower(NULL);
GpioControl::setCam3V3Enable(true);
NdkCamera camera(width, height, params);
int res = camera.selfTest(std::to_string(cameraId), width, height);
TurnOffCameraPower(NULL);
GpioControl::setCam3V3Enable(false);
if (usbCamera)
{
TurnOffOtg(NULL);
GpioControl::setOtgState(false);
}
if (res == 0)
{
@ -1457,17 +1457,17 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
if (photoInfo.cameraType == CAM_TYPE_USB || photoInfo.cameraType == CAM_TYPE_NET)
{
TurnOnOtg(NULL);
GpioControl::setOtgState(true);
}
if (photoInfo.cameraType == CAM_TYPE_NET)
{
GpioControl::set12VEnable(true);
#ifdef USING_N938
GpioControl::setInt(CMD_SET_NETWORK_POWER_EN, 1);
GpioControl::setInt(CMD_SET_485_EN_STATE, 1);
GpioControl::TurnOn(CMD_SET_NETWORK_POWER_EN);
GpioControl::TurnOn(CMD_SET_485_EN_STATE);
#endif
}
TurnOnCameraPower(NULL);
GpioControl::setCam3V3Enable(true);
res = true;
if ((mPhotoInfo.mediaType == 0) && ((mPhotoInfo.cameraType == CAM_TYPE_MIPI) || (mPhotoInfo.cameraType == CAM_TYPE_USB)))
@ -1521,10 +1521,10 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
mCamera = NULL;
res = false;
TurnOffCameraPower(NULL);
GpioControl::setCam3V3Enable(false);
if (photoInfo.usbCamera)
{
TurnOffOtg(NULL);
GpioControl::setOtgState(false);
}
if (hasFatalError)
@ -1575,11 +1575,11 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
XYLOG(XYLOG_SEVERITY_ERROR, "Ethernet not existing CH=%u PR=%X PHOTOID=%u", (uint32_t)localPhotoInfo.channel, (uint32_t)localPhotoInfo.preset, localPhotoInfo.photoId);
pThis->TakePhotoCb(0, localPhotoInfo, "", 0);
TurnOffOtg(NULL);
GpioControl::setOtgState(false);
GpioControl::set12VEnable(false);
#ifdef USING_N938
GpioControl::setInt(CMD_SET_NETWORK_POWER_EN, 0);
GpioControl::setInt(CMD_SET_485_EN_STATE, 0);
GpioControl::TurnOff(CMD_SET_NETWORK_POWER_EN);
GpioControl::TurnOff(CMD_SET_485_EN_STATE);
#endif
return;
}
@ -1609,11 +1609,11 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
XYLOG(XYLOG_SEVERITY_ERROR, "Vendor(%u) not Supported CH=%u PR=%X PHOTOID=%u", (uint32_t)localPhotoInfo.vendor, (uint32_t)localPhotoInfo.channel, (unsigned int)localPhotoInfo.preset, localPhotoInfo.photoId);
pThis->TakePhotoCb(0, localPhotoInfo, "", 0);
TurnOffOtg(NULL);
GpioControl::setOtgState(false);
GpioControl::set12VEnable(false);
#ifdef USING_N938
GpioControl::setInt(CMD_SET_NETWORK_POWER_EN, 0);
GpioControl::setInt(CMD_SET_485_EN_STATE, 0);
GpioControl::TurnOff(CMD_SET_NETWORK_POWER_EN);
GpioControl::TurnOff(CMD_SET_485_EN_STATE);
#endif
return;
}
@ -1651,11 +1651,11 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
}
}
TurnOffOtg(NULL);
GpioControl::setOtgState(false);
GpioControl::set12VEnable(false);
#ifdef USING_N938
GpioControl::setInt(CMD_SET_NETWORK_POWER_EN, 0);
GpioControl::setInt(CMD_SET_485_EN_STATE, 0);
GpioControl::TurnOff(CMD_SET_NETWORK_POWER_EN);
GpioControl::TurnOff(CMD_SET_485_EN_STATE);
#endif
if (netCaptureResult)
{
@ -1699,9 +1699,9 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
time_t ts = time(NULL);
if(!GetPTZSensorsStatus() && !GetCameraStatus())
{
OpenPTZSensors(120);
OpenPTZSensors(photoInfo.selfTestingTime);
}
CameraPhotoCmd(ts, photoInfo.channel, 0, 6, 0);
CameraPhotoCmd(ts, photoInfo.channel, 0, photoInfo.resolution, 0);
res = TakePTZPhotoCb(3, photoInfo);
}
else if (mPhotoInfo.usingSysCamera == 1)
@ -3395,34 +3395,6 @@ void CPhoneDevice::UpdatePosition(double lon, double lat, double radius, time_t
}
}
void CPhoneDevice::TurnOnCameraPower(JNIEnv* env)
{
m_powerLocker.lock();
GpioControl::setCam3V3Enable(true);
m_powerLocker.unlock();
}
void CPhoneDevice::TurnOffCameraPower(JNIEnv* env)
{
m_powerLocker.lock();
GpioControl::setCam3V3Enable(false);
m_powerLocker.unlock();
}
void CPhoneDevice::TurnOnOtg(JNIEnv* env)
{
m_powerLocker.lock();
GpioControl::setInt(CMD_SET_OTG_STATE, 1);
m_powerLocker.unlock();
}
void CPhoneDevice::TurnOffOtg(JNIEnv* env)
{
m_powerLocker.lock();
GpioControl::setInt(CMD_SET_OTG_STATE, 0);
m_powerLocker.unlock();
}
void CPhoneDevice::UpdateSignalLevel(int signalLevel)
{
m_signalLevel = signalLevel;
@ -3646,18 +3618,18 @@ bool CPhoneDevice::OpenSensors(int sensortype)
GpioControl::set12VEnable(true);
GpioControl::setCam3V3Enable(true);
GpioControl::setRS485Enable(true);
GpioControl::setInt(CMD_SET_SPI_POWER, 1);
// GpioControl::setInt(CMD_SET_485_EN_STATE, 1); // 打开RS485电源
GpioControl::TurnOn(CMD_SET_SPI_POWER);
// GpioControl::TurnOn(CMD_SET_485_EN_STATE); // 打开RS485电源
#ifndef USING_N938
#ifndef USING_PLZ
GpioControl::setInt(CMD_SET_485_EN_STATE, 1);
GpioControl::TurnOn(CMD_SET_485_EN_STATE);
#else
GpioControl::setInt(CMD_SET_485_ENABLE, 1);
GpioControl::TurnOn(CMD_SET_485_ENABLE);
#endif
#else
GpioControl::setInt(CMD_SPI2SERIAL_POWER_EN, 1);
GpioControl::setInt(CMD_RS485_3V3_EN, 1);
GpioControl::TurnOn(CMD_SPI2SERIAL_POWER_EN);
GpioControl::TurnOn(CMD_RS485_3V3_EN);
#endif
}
if(sensortype == CAMERA_SENSOR_OPEN)
@ -3665,39 +3637,39 @@ bool CPhoneDevice::OpenSensors(int sensortype)
#ifndef USING_N938
#ifndef USING_PLZ
#else
GpioControl::setInt(CMD_SET_PTZ_PWR_ENABLE, 1);
GpioControl::TurnOn(CMD_SET_PTZ_PWR_ENABLE);
#endif
#else
GpioControl::setInt(CMD_SET_PIC1_POWER, 1);
GpioControl::setInt(CMD_SET_485_EN4, 1);
GpioControl::TurnOn(CMD_SET_PIC1_POWER);
GpioControl::TurnOn(CMD_SET_485_EN4);
#endif
// GpioControl::setInt(CMD_SET_CAM_3V3_EN_STATE, 1); // 打开3.3V电压
// GpioControl::setInt(CMD_SET_3V3_PWR_ENABLE, 1);
// GpioControl::TurnOn(CMD_SET_CAM_3V3_EN_STATE); // 打开3.3V电压
// GpioControl::TurnOn(CMD_SET_3V3_PWR_ENABLE);
}
if(sensortype == WEATHER_SENSOR_OPEN)
{
#ifndef USING_N938
#else
GpioControl::setInt(CMD_SET_WTH_POWER, 1);
GpioControl::setInt(CMD_SET_485_EN3, 1);
GpioControl::TurnOn(CMD_SET_WTH_POWER);
GpioControl::TurnOn(CMD_SET_485_EN3);
#endif
}
if(sensortype == ICETHICK_SENSOR_OPEN)
{
#ifndef USING_N938
#else
GpioControl::setInt(CMD_SET_PULL_POWER, 1);
GpioControl::setInt(CMD_SET_ANGLE_POWER, 1);
GpioControl::setInt(CMD_SET_485_EN1, 1);
GpioControl::setInt(CMD_SET_485_EN0, 1);
GpioControl::TurnOn(CMD_SET_PULL_POWER);
GpioControl::TurnOn(CMD_SET_ANGLE_POWER);
GpioControl::TurnOn(CMD_SET_485_EN1);
GpioControl::TurnOn(CMD_SET_485_EN0);
#endif
}
if(sensortype == OTHER_SENSOR)
{
#ifndef USING_N938
#else
GpioControl::setInt(CMD_SET_OTHER_POWER, 1);
GpioControl::setInt(CMD_SET_485_EN2, 1);
GpioControl::TurnOn(CMD_SET_OTHER_POWER);
GpioControl::TurnOn(CMD_SET_485_EN2);
#endif
}
return 0;
@ -3707,36 +3679,36 @@ bool CPhoneDevice::CloseSensors(int sensortype)
{
if(sensortype == MAIN_POWER_OPEN)
{
GpioControl::setInt(CMD_SET_SPI_POWER, 0);
GpioControl::TurnOff(CMD_SET_SPI_POWER);
GpioControl::set12VEnable(false);
GpioControl::setCam3V3Enable(false);
GpioControl::setRS485Enable(false);
// GpioControl::setInt(CMD_SET_485_EN_STATE, 0);
// GpioControl::TurnOff(CMD_SET_485_EN_STATE);
#ifndef USING_N938
#ifndef USING_PLZ
GpioControl::setInt(CMD_SET_485_EN_STATE, 0);
GpioControl::TurnOff(CMD_SET_485_EN_STATE);
#else
GpioControl::setInt(CMD_SET_485_ENABLE, 0);
GpioControl::TurnOff(CMD_SET_485_ENABLE);
#endif
#else
GpioControl::setInt(CMD_SPI2SERIAL_POWER_EN, 0);
GpioControl::setInt(CMD_RS485_3V3_EN, 0);
GpioControl::TurnOff(CMD_SPI2SERIAL_POWER_EN);
GpioControl::TurnOff(CMD_RS485_3V3_EN);
#endif
}
if(sensortype == CAMERA_SENSOR_OPEN)
{
#ifdef USING_N938
GpioControl::setInt(CMD_SET_PIC1_POWER, 0);
GpioControl::setInt(CMD_SET_485_EN4, 0);
// GpioControl::setInt(CMD_SET_CAM_3V3_EN_STATE, 0);
GpioControl::TurnOff(CMD_SET_PIC1_POWER);
GpioControl::TurnOff(CMD_SET_485_EN4);
// GpioControl::TurnOff(CMD_SET_CAM_3V3_EN_STATE);
#endif
#ifndef USING_N938
// GpioControl::setInt(CMD_SET_3V3_PWR_ENABLE, 0);
// GpioControl::TurnOff(CMD_SET_3V3_PWR_ENABLE);
#ifndef USING_PLZ
#else
GpioControl::setInt(CMD_SET_PTZ_PWR_ENABLE, 0);
GpioControl::TurnOff(CMD_SET_PTZ_PWR_ENABLE);
#endif
#endif
}
@ -3744,26 +3716,26 @@ bool CPhoneDevice::CloseSensors(int sensortype)
{
#ifndef USING_N938
#else
GpioControl::setInt(CMD_SET_WTH_POWER, 0);
GpioControl::setInt(CMD_SET_485_EN3, 0);
GpioControl::TurnOff(CMD_SET_WTH_POWER);
GpioControl::TurnOff(CMD_SET_485_EN3);
#endif
}
if(sensortype == ICETHICK_SENSOR_OPEN)
{
#ifndef USING_N938
#else
GpioControl::setInt(CMD_SET_PULL_POWER, 0);
GpioControl::setInt(CMD_SET_ANGLE_POWER, 0);
GpioControl::setInt(CMD_SET_485_EN1, 0);
GpioControl::setInt(CMD_SET_485_EN0, 0);
GpioControl::TurnOff(CMD_SET_PULL_POWER);
GpioControl::TurnOff(CMD_SET_ANGLE_POWER);
GpioControl::TurnOff(CMD_SET_485_EN1);
GpioControl::TurnOff(CMD_SET_485_EN0);
#endif
}
if(sensortype == OTHER_SENSOR)
{
#ifndef USING_N938
#else
GpioControl::setInt(CMD_SET_OTHER_POWER, 0);
GpioControl::setInt(CMD_SET_485_EN2, 0);
GpioControl::TurnOff(CMD_SET_OTHER_POWER);
GpioControl::TurnOff(CMD_SET_485_EN2);
#endif
}
return 0;
@ -3805,5 +3777,11 @@ void CPhoneDevice::SetStaticIp()
if (m_network != NULL)
{
SetStaticIp(m_network->iface, m_network->ip, m_network->netmask, m_network->gateway);
XYLOG(XYLOG_SEVERITY_INFO, "Set Static IP on %s: %s", m_network->iface.c_str(),
m_network->ip.c_str());
}
else
{
XYLOG(XYLOG_SEVERITY_WARNING, "No Static IP Confg");
}
}

@ -257,12 +257,6 @@ public:
net_handle_t GetNetHandle() const;
static void TurnOnCameraPower(JNIEnv* env);
static void TurnOffCameraPower(JNIEnv* env);
static void TurnOnOtg(JNIEnv* env);
static void TurnOffOtg(JNIEnv* env);
protected:
std::string GetFileName() const;
@ -382,9 +376,6 @@ protected:
time_t mHeartbeatStartTime;
unsigned int mHeartbeatDuration;
static std::mutex m_powerLocker;
static long mCameraPowerCount;
static long mOtgCount;
std::thread m_threadClose;
int m_signalLevel;

@ -1,912 +0,0 @@
#include "TerminalDevice.h"
/*
* Copyright 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#define LOG_TAG "CameraTestHelpers"
#include "PhoneDevice2.h"
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
// #include <opencv2/objdetect.hpp>
// #include <opencv2/features2d.hpp>
// #include <opencv2/core/types.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <android/log.h>
#include <AndroidHelper.h>
extern bool GetJniEnv(JavaVM *vm, JNIEnv **env, bool& didAttachThread);
// This value is 2 ^ 18 - 1, and is used to clamp the RGB values before their
// ranges
// are normalized to eight bits.
static const int kMaxChannelValue = 262143;
static inline uint32_t YUV2RGB(int nY, int nU, int nV) {
nY -= 16;
nU -= 128;
nV -= 128;
if (nY < 0) nY = 0;
// This is the floating point equivalent. We do the conversion in integer
// because some Android devices do not have floating point in hardware.
// nR = (int)(1.164 * nY + 1.596 * nV);
// nG = (int)(1.164 * nY - 0.813 * nV - 0.391 * nU);
// nB = (int)(1.164 * nY + 2.018 * nU);
int nR = (int)(1192 * nY + 1634 * nV);
int nG = (int)(1192 * nY - 833 * nV - 400 * nU);
int nB = (int)(1192 * nY + 2066 * nU);
nR = std::min(kMaxChannelValue, std::max(0, nR));
nG = std::min(kMaxChannelValue, std::max(0, nG));
nB = std::min(kMaxChannelValue, std::max(0, nB));
nR = (nR >> 10) & 0xff;
nG = (nG >> 10) & 0xff;
nB = (nB >> 10) & 0xff;
return 0xff000000 | (nR << 16) | (nG << 8) | nB;
}
CPhoneDevice2::CPhoneDevice2(JavaVM* vm, jobject service)
{
m_vm = vm;
JNIEnv* env = NULL;
bool attached = false;
bool res = GetJniEnv(m_vm, &env, attached);
if (!res)
{
ALOGE("Failed to get JNI Env");
}
m_javaService = env->NewGlobalRef(service);
jclass classService = env->GetObjectClass(m_javaService);
mRegisterTimerMid = env->GetMethodID(classService, "registerTimer", "(JI)Z");
mRegisterHeartbeatMid = env->GetMethodID(classService, "registerHeartbeatTimer", "(I)V");
mUnregisterTimerMid = env->GetMethodID(classService, "unregisterTimer", "(J)Z");
mUpdateTimeMid = env->GetMethodID(classService, "updateTime", "(J)Z");
env->DeleteLocalRef(classService);
if (attached)
{
vm->DetachCurrentThread();
}
m_timerUidFeed = time(NULL);
presentRotation_ = 0;
}
CPhoneDevice2::~CPhoneDevice2()
{
JNIEnv* env = NULL;
bool attached = false;
bool res = GetJniEnv(m_vm, &env, attached);
if (!res)
{
ALOGE("Failed to get JNI Env");
}
env->DeleteGlobalRef(m_javaService);
if (attached)
{
m_vm->DetachCurrentThread();
}
m_javaService = NULL;
}
void CPhoneDevice2::SetListener(IListener* listener)
{
m_listener = listener;
}
bool CPhoneDevice2::UpdateTime(time_t ts)
{
JNIEnv* env = NULL;
jboolean ret = JNI_FALSE;
bool attached = false;
bool res = GetJniEnv(m_vm, &env, attached);
if (!res)
{
ALOGE("Failed to get JNI Env");
return false;
}
jlong timeInMillis = ((jlong)ts) * 1000;
ret = env->CallBooleanMethod(m_javaService, mUpdateTimeMid, timeInMillis);
if (attached)
{
m_vm->DetachCurrentThread();
}
return (ret == JNI_TRUE);
}
bool CPhoneDevice2::Reboot()
{
return false;
}
IDevice::timer_uid_t CPhoneDevice2::RegisterTimer(unsigned int timerType, unsigned int timeout)
{
IDevice::timer_uid_t uid = m_timerUidFeed.fetch_add(1);
ALOGI("NDK RegTimer: uid=%lld Type=%u timeout=%u", uid, timerType, timeout);
JNIEnv* env = NULL;
jboolean ret = JNI_FALSE;
bool attached = false;
bool res = GetJniEnv(m_vm, &env, attached);
if (!res)
{
ALOGE("Failed to get JNI Env");
return 0;
}
ret = env->CallBooleanMethod(m_javaService, mRegisterTimerMid, (jlong)uid, (jint)timeout);
if (attached)
{
m_vm->DetachCurrentThread();
}
if (ret == JNI_TRUE)
{
unsigned long val = timerType;
mTimers.insert(mTimers.end(), std::pair<IDevice::timer_uid_t, unsigned long>(uid, val));
return uid;
}
return 0;
}
bool CPhoneDevice2::UnregisterTimer(IDevice::timer_uid_t uid)
{
JNIEnv* env = NULL;
jboolean ret = JNI_FALSE;
bool attached = false;
bool res = GetJniEnv(m_vm, &env, attached);
if (!res)
{
ALOGE("Failed to get JNI Env");
return false;
}
ret = env->CallBooleanMethod(m_javaService, mUnregisterTimerMid, (jlong)uid);
if (attached)
{
m_vm->DetachCurrentThread();
}
if (ret == JNI_TRUE)
{
mTimers.erase(uid);
return true;
}
return false;
}
bool CPhoneDevice2::FireTimer(timer_uid_t uid)
{
std::map<IDevice::timer_uid_t, unsigned long>::iterator it = mTimers.find(uid);
if (it == mTimers.end())
{
return false;
}
unsigned long timerType = it->second & 0xFFFFFFFF;
unsigned long times = (it->second & 0xFFFFFFFF00000000) >> 32;
times++;
if (timerType != 100)
{
int aa = 0;
}
it->second = timerType | (times << 32);
if (m_listener == NULL)
{
return false;
}
m_listener->OnTimeout(uid, timerType, NULL, times);
return true;
}
IDevice::timer_uid_t CPhoneDevice2::RegisterHeartbeat(unsigned int timerType, unsigned int timeout)
{
IDevice::timer_uid_t uid = m_timerUidFeed.fetch_add(1);
JNIEnv* env = NULL;
jboolean ret = JNI_FALSE;
bool attached = false;
bool res = GetJniEnv(m_vm, &env, attached);
if (!res)
{
ALOGE("Failed to get JNI Env");
return 0;
}
env->CallVoidMethod(m_javaService, mRegisterHeartbeatMid, (jint)timeout);
if (attached)
{
m_vm->DetachCurrentThread();
}
return uid;
}
bool CPhoneDevice2::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<OSD_INFO>& osds, const string& path)
{
ALOGI("TAKE_PHOTO: CH=%u PR=%u\n", (unsigned int)photoInfo.channel, (unsigned int)photoInfo.preset);
mPhotoInfo = photoInfo;
mPath = path;
mDisplayDimension = DisplayDimension(photoInfo.width, photoInfo.height);
ALOGE("Image Buffer Size: %d", photoInfo.width * photoInfo.height * 4);
imageBuffer_ = (uint8_t*)malloc(photoInfo.width * photoInfo.height * 4);
AASSERT(imageBuffer_ != nullptr, "Failed to allocate imageBuffer_");
int cameraId = (int)photoInfo.channel - 1;
ACameraIdList *cameraIdList = NULL;
ACameraMetadata *cameraMetadata = NULL;
const char *selectedCameraId = NULL;
camera_status_t camera_status = ACAMERA_OK;
ACameraManager *cameraManager = ACameraManager_create();
camera_status = ACameraManager_getCameraIdList(cameraManager, &cameraIdList);
if (camera_status != ACAMERA_OK) {
ALOGI("Failed to get camera id list (reason: %d)\n", camera_status);
TakePhotoCb(false, photoInfo, path, 0);
return false;
}
if (cameraIdList->numCameras < 1 ) {
ALOGI("No camera device detected.\n");
TakePhotoCb(false, photoInfo, path, 0);
return false;
}
if (cameraIdList->numCameras <= cameraId ) {
ALOGI("No required camera device %d detected.\n", cameraId);
TakePhotoCb(false, photoInfo, path, 0);
return false;
}
selectedCameraId = cameraIdList->cameraIds[cameraId];
ALOGI("Trying to open Camera2 (id: %s, num of camera : %d)\n", selectedCameraId,
cameraIdList->numCameras);
camera_status = ACameraManager_getCameraCharacteristics(cameraManager, selectedCameraId,
&cameraMetadata);
if (camera_status != ACAMERA_OK) {
ALOGI("Failed to get camera meta data of ID:%s\n", selectedCameraId);
}
ACameraMetadata_const_entry face, orientation;
camera_status = ACameraMetadata_getConstEntry(cameraMetadata, ACAMERA_LENS_FACING, &face);
uint32_t cameraFacing_ = static_cast<int32_t>(face.data.u8[0]);
if (cameraFacing_ == ACAMERA_LENS_FACING_FRONT)
{
int aa = 0;
}
camera_status = ACameraMetadata_getConstEntry(cameraMetadata, ACAMERA_SENSOR_ORIENTATION, &orientation);
ALOGI("====Current SENSOR_ORIENTATION: %8d", orientation.data.i32[0]);
uint32_t cameraOrientation_ = orientation.data.i32[0];
if (cameraOrientation_ == 90 || cameraOrientation_ == 270)
{
mDisplayDimension.Flip();
}
ImageFormat resCap = {(int32_t)photoInfo.width, (int32_t)photoInfo.height, AIMAGE_FORMAT_YUV_420_888};
MatchCaptureSizeRequest(cameraManager, selectedCameraId, photoInfo.width, photoInfo.height, cameraOrientation_, &resCap);
deviceStateCallbacks.onDisconnected = camera_device_on_disconnected;
deviceStateCallbacks.onError = camera_device_on_error;
camera_status = ACameraManager_openCamera(cameraManager, selectedCameraId,
&deviceStateCallbacks, &cameraDevice);
if (camera_status != ACAMERA_OK) {
ALOGI("Failed to open camera device (id: %s)\n", selectedCameraId);
}
camera_status = ACameraDevice_createCaptureRequest(cameraDevice, TEMPLATE_STILL_CAPTURE/*TEMPLATE_PREVIEW*/,
&captureRequest);
if (camera_status != ACAMERA_OK) {
ALOGI("Failed to create preview capture request (id: %s)\n", selectedCameraId);
}
ACaptureSessionOutputContainer_create(&captureSessionOutputContainer);
captureSessionStateCallbacks.onReady = capture_session_on_ready;
captureSessionStateCallbacks.onActive = capture_session_on_active;
captureSessionStateCallbacks.onClosed = capture_session_on_closed;
ACameraMetadata_free(cameraMetadata);
ACameraManager_deleteCameraIdList(cameraIdList);
ACameraManager_delete(cameraManager);
media_status_t status;
// status = AImageReader_new(1920, 1080, AIMAGE_FORMAT_YUV_420_888, 5, &mAImageReader);
status = AImageReader_new(resCap.width, resCap.height, resCap.format, 5, &mAImageReader);
if (status != AMEDIA_OK)
{
ALOGI("AImageReader_new error\n");
TakePhotoCb(false, photoInfo, path, 0);
return false;
}
AImageReader_ImageListener listener{
.context = this,
.onImageAvailable = OnImageCallback,
};
AImageReader_setImageListener(mAImageReader, &listener);
//ANativeWindow *mNativeWindow;
status = AImageReader_getWindow(mAImageReader, &theNativeWindow);
if (status != AMEDIA_OK)
{
ALOGI("AImageReader_getWindow error\n");
TakePhotoCb(false, photoInfo, path, 0);
return false;
}
ALOGI("Surface is prepared in %p.\n", theNativeWindow);
// theNativeWindow
ACameraOutputTarget_create(theNativeWindow, &cameraOutputTarget);
ACaptureRequest_addTarget(captureRequest, cameraOutputTarget);
ACaptureSessionOutput_create(theNativeWindow, &sessionOutput);
ACaptureSessionOutputContainer_add(captureSessionOutputContainer, sessionOutput);
ACameraDevice_createCaptureSession(cameraDevice, captureSessionOutputContainer,
&captureSessionStateCallbacks, &captureSession);
// ACameraCaptureSession_setRepeatingRequest(captureSession, NULL, 1, &captureRequest, NULL);
ACameraCaptureSession_capture(captureSession, NULL, 1, &captureRequest, NULL);
ALOGI("Surface is prepared in here.\n");
return true;
}
ACameraCaptureSession_stateCallbacks* CPhoneDevice2::GetSessionListener()
{
static ACameraCaptureSession_stateCallbacks sessionListener = {
.context = this,
.onClosed = CPhoneDevice2::capture_session_on_closed,
.onReady = CPhoneDevice2::capture_session_on_ready,
.onActive = CPhoneDevice2::capture_session_on_active,
};
return &sessionListener;
}
void CPhoneDevice2::ImageCallback(AImageReader *reader)
{
bool res = false;
AImage *image = nullptr;
media_status_t status = AImageReader_acquireNextImage(reader, &image);
if (status == AMEDIA_OK && image)
{
int32_t srcFormat = -1;
AImage_getFormat(image, &srcFormat);
AASSERT(AIMAGE_FORMAT_YUV_420_888 == srcFormat, "Failed to get format");
int32_t srcPlanes = 0;
AImage_getNumberOfPlanes(image, &srcPlanes);
AASSERT(srcPlanes == 3, "Is not 3 planes");
AImageCropRect srcRect;
AImage_getCropRect(image, &srcRect);
int32_t width = srcRect.right - srcRect.left;
int32_t height = srcRect.bottom - srcRect.top;
// int32_t height = srcRect.right - srcRect.left;
// int32_t width = srcRect.bottom - srcRect.top;
uint8_t *yPixel = nullptr;
uint8_t *uPixel = nullptr;
uint8_t *vPixel = nullptr;
int32_t yLen = 0;
int32_t uLen = 0;
int32_t vLen = 0;
AImage_getPlaneData(image, 0, &yPixel, &yLen);
AImage_getPlaneData(image, 1, &uPixel, &uLen);
AImage_getPlaneData(image, 2, &vPixel, &vLen);
uint8_t * data = new uint8_t[yLen + vLen + uLen];
memcpy(data, yPixel, yLen);
memcpy(data+yLen, vPixel, vLen);
memcpy(data+yLen+vLen, uPixel, uLen);
cv::Mat mYUV = cv::Mat(((height * 3) >> 1), width, CV_8UC1, data);
// cv::cvtColor(mYUV, _yuv_rgb_img, cv::COLOR_YUV2RGB_NV21, 3);
// cv::Mat mYUV = cv::Mat(height, yStride, CV_8UC4, data);
cv::Mat _yuv_rgb_img(height, width, CV_8UC4), _yuv_gray_img;
cv::cvtColor(mYUV, _yuv_rgb_img, cv::COLOR_YUV2RGB_NV21, 3);
cv::rotate(_yuv_rgb_img, _yuv_rgb_img, cv::ROTATE_180);
// cv::Mat rgbMat(height, width, CV_8UC3);
// 通过cv::cvtColor将yuv420转换为rgb格式
// cvtColor(_yuv_rgb_img, rgbMat, cv::COLOR_YUV2RGB_I420);
// cv::Mat mat = cv::Mat(buffer.height, buffer.stride, CV_8UC4, buffer.bits);
const char *str = "OSD";
putText(_yuv_rgb_img, str, cv::Point(50, 50), cv::FONT_HERSHEY_COMPLEX, 1, cv::Scalar(0, 0, 0), 4,cv::LINE_AA);
putText(_yuv_rgb_img, str, cv::Point(50, 50), cv::FONT_HERSHEY_COMPLEX, 1, cv::Scalar(255, 255, 255), 2,cv::LINE_AA);
vector <int> compression_params;
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY);
compression_params.push_back(80);
res = cv::imwrite(mPath.c_str(), _yuv_rgb_img, compression_params);
// ANativeWindow_unlockAndPost(theNativeWindow);
if (res)
{
int aa = 0;
}
// res = WriteFile(image, GetFileName() + ".org.jpg");
AImage_delete(image);
// delete pThis;
TakePhotoCb(res, mPhotoInfo, mPath, time(NULL));
}
}
void CPhoneDevice2::OnImageCallback(void *ctx, AImageReader *reader)
{
CPhoneDevice2* pThis = reinterpret_cast<CPhoneDevice2*>(ctx);
if (pThis != NULL)
{
pThis->ImageCallback(reader);
}
}
bool CPhoneDevice2::WriteFile(AImage *image, const string& path)
{
int planeCount = 0;
media_status_t status = AImage_getNumberOfPlanes(image, &planeCount);
ALOGI("Info: getNumberOfPlanes() planeCount = %d", planeCount);
if (!(status == AMEDIA_OK && planeCount == 1))
{
ALOGE("Error: getNumberOfPlanes() planeCount = %d", planeCount);
return false;
}
uint8_t *data = nullptr;
int len = 0;
AImage_getPlaneData(image, 0, &data, &len);
bool res = false;
FILE *file = fopen(path.c_str(), "wb");
if (file && data && len)
{
fwrite(data, 1, len, file);
fclose(file);
ALOGI("Capture: %s", path.c_str());
res = true;
}
else
{
if (file)
fclose(file);
}
return res;
}
bool CPhoneDevice2::WriteFile(CPhoneDevice2* pThis, AImage *image)
{
return pThis->WriteFile(image, pThis->GetFileName());
}
std::string CPhoneDevice2::GetFileName() const
{
return mPath;
}
/*
const char *selectedCameraId = NULL;
ACameraManager *cameraManager = ACameraManager_create();
*/
bool CPhoneDevice2::MatchCaptureSizeRequest(ACameraManager *cameraManager, const char *selectedCameraId, unsigned int width, unsigned int height, uint32_t cameraOrientation_,
ImageFormat* resCap) {
DisplayDimension disp(resCap->width,resCap->height);
if (cameraOrientation_ == 90 || cameraOrientation_ == 270) {
disp.Flip();
}
ACameraMetadata* metadata;
camera_status_t camera_status = ACAMERA_OK;
camera_status = ACameraManager_getCameraCharacteristics(cameraManager, selectedCameraId, &metadata);
ACameraMetadata_const_entry entry;
camera_status = ACameraMetadata_getConstEntry(metadata, ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, &entry);
// format of the data: format, width, height, input?, type int32
bool foundIt = false;
DisplayDimension foundRes(16384, 16384);
DisplayDimension maxJPG(0, 0);
for (int i = 0; i < entry.count; i += 4) {
int32_t input = entry.data.i32[i + 3];
int32_t format = entry.data.i32[i + 0];
if (input) continue;
if (format == AIMAGE_FORMAT_YUV_420_888 || format == AIMAGE_FORMAT_JPEG) {
DisplayDimension res(entry.data.i32[i + 1], entry.data.i32[i + 2]);
ALOGI("Camera Resolution: %d x %d fmt=%d", res.width(), res.height(), format);
if (!disp.IsSameRatio(res)) continue;
if (format == AIMAGE_FORMAT_YUV_420_888 && res > disp) {
foundIt = true;
foundRes = res;
} else if (format == AIMAGE_FORMAT_JPEG && res > maxJPG) {
maxJPG = res;
}
}
}
if (foundIt) {
// resView->width = foundRes.org_width();
// resView->height = foundRes.org_height();
resCap->width = foundRes.org_width();
resCap->height = foundRes.org_height();
} else {
ALOGI("Did not find any compatible camera resolution, taking 640x480");
resCap->width = disp.org_width();
resCap->height = disp.org_height();
// *resCap = *resView;
}
// resView->format = AIMAGE_FORMAT_YUV_420_888;
// resCap->format = AIMAGE_FORMAT_JPEG;
return foundIt;
}
/**
* Convert yuv image inside AImage into ANativeWindow_Buffer
* ANativeWindow_Buffer format is guaranteed to be
* WINDOW_FORMAT_RGBX_8888
* WINDOW_FORMAT_RGBA_8888
* @param buf a {@link ANativeWindow_Buffer } instance, destination of
* image conversion
* @param image a {@link AImage} instance, source of image conversion.
* it will be deleted via {@link AImage_delete}
*/
bool CPhoneDevice2::DisplayImage(ANativeWindow_Buffer *buf, AImage *image) {
AASSERT(buf->format == WINDOW_FORMAT_RGBX_8888 ||
buf->format == WINDOW_FORMAT_RGBA_8888,
"Not supported buffer format");
int32_t srcFormat = -1;
AImage_getFormat(image, &srcFormat);
AASSERT(AIMAGE_FORMAT_YUV_420_888 == srcFormat, "Failed to get format");
int32_t srcPlanes = 0;
AImage_getNumberOfPlanes(image, &srcPlanes);
AASSERT(srcPlanes == 3, "Is not 3 planes");
switch (presentRotation_) {
case 0:
PresentImage(buf, image);
break;
case 90:
PresentImage90(buf, image);
break;
case 180:
PresentImage180(buf, image);
break;
case 270:
PresentImage270(buf, image);
break;
default:
AASSERT(0, "NOT recognized display rotation: %d", presentRotation_);
}
AImage_delete(image);
image = nullptr;
return true;
}
/*
* PresentImage()
* Converting yuv to RGB
* No rotation: (x,y) --> (x, y)
* Refer to:
* https://mathbits.com/MathBits/TISection/Geometry/Transformations2.htm
*/
void CPhoneDevice2::PresentImage(ANativeWindow_Buffer *buf, AImage *image) {
AImageCropRect srcRect;
AImage_getCropRect(image, &srcRect);
AImage_getPlaneRowStride(image, 0, &yStride);
AImage_getPlaneRowStride(image, 1, &uvStride);
yPixel = imageBuffer_;
AImage_getPlaneData(image, 0, &yPixel, &yLen);
vPixel = imageBuffer_ + yLen;
AImage_getPlaneData(image, 1, &vPixel, &vLen);
uPixel = imageBuffer_ + yLen + vLen;
AImage_getPlaneData(image, 2, &uPixel, &uLen);
AImage_getPlanePixelStride(image, 1, &uvPixelStride);
int32_t rowStride;
AImage_getPlaneRowStride(image, 0, &rowStride);
int32_t height = std::min(buf->height, (srcRect.bottom - srcRect.top));
int32_t width = std::min(buf->width, (srcRect.right - srcRect.left));
uint32_t *out = static_cast<uint32_t *>(buf->bits);
for (int32_t y = 0; y < height; y++) {
const uint8_t *pY = yPixel + yStride * (y + srcRect.top) + srcRect.left;
int32_t uv_row_start = uvStride * ((y + srcRect.top) >> 1);
const uint8_t *pU = uPixel + uv_row_start + (srcRect.left >> 1);
const uint8_t *pV = vPixel + uv_row_start + (srcRect.left >> 1);
for (int32_t x = 0; x < width; x++) {
const int32_t uv_offset = (x >> 1) * uvPixelStride;
out[x] = YUV2RGB(pY[x], pU[uv_offset], pV[uv_offset]);
}
out += buf->stride;
}
}
/*
* PresentImage90()
* Converting YUV to RGB
* Rotation image anti-clockwise 90 degree -- (x, y) --> (-y, x)
*/
void CPhoneDevice2::PresentImage90(ANativeWindow_Buffer *buf, AImage *image) {
AImageCropRect srcRect;
AImage_getCropRect(image, &srcRect);
AImage_getPlaneRowStride(image, 0, &yStride);
AImage_getPlaneRowStride(image, 1, &uvStride);
yPixel = imageBuffer_;
AImage_getPlaneData(image, 0, &yPixel, &yLen);
vPixel = imageBuffer_ + yLen;
AImage_getPlaneData(image, 1, &vPixel, &vLen);
uPixel = imageBuffer_ + yLen + vLen;
AImage_getPlaneData(image, 2, &uPixel, &uLen);
AImage_getPlanePixelStride(image, 1, &uvPixelStride);
int32_t height = std::min(buf->width, (srcRect.bottom - srcRect.top));
int32_t width = std::min(buf->height, (srcRect.right - srcRect.left));
uint32_t *out = static_cast<uint32_t *>(buf->bits);
out += height - 1;
for (int32_t y = 0; y < height; y++) {
const uint8_t *pY = yPixel + yStride * (y + srcRect.top) + srcRect.left;
int32_t uv_row_start = uvStride * ((y + srcRect.top) >> 1);
const uint8_t *pU = uPixel + uv_row_start + (srcRect.left >> 1);
const uint8_t *pV = vPixel + uv_row_start + (srcRect.left >> 1);
for (int32_t x = 0; x < width; x++) {
const int32_t uv_offset = (x >> 1) * uvPixelStride;
// [x, y]--> [-y, x]
int testb = pU[uv_offset];
int testc = pV[uv_offset];
int testA = pY[x];
out[x * buf->stride] = YUV2RGB(testA, testb, testc);
}
out -= 1; // move to the next column
}
}
/*
* PresentImage180()
* Converting yuv to RGB
* Rotate image 180 degree: (x, y) --> (-x, -y)
*/
void CPhoneDevice2::PresentImage180(ANativeWindow_Buffer *buf, AImage *image) {
AImageCropRect srcRect;
AImage_getCropRect(image, &srcRect);
AImage_getPlaneRowStride(image, 0, &yStride);
AImage_getPlaneRowStride(image, 1, &uvStride);
yPixel = imageBuffer_;
AImage_getPlaneData(image, 0, &yPixel, &yLen);
vPixel = imageBuffer_ + yLen;
AImage_getPlaneData(image, 1, &vPixel, &vLen);
uPixel = imageBuffer_ + yLen + vLen;
AImage_getPlaneData(image, 2, &uPixel, &uLen);
AImage_getPlanePixelStride(image, 1, &uvPixelStride);
int32_t height = std::min(buf->height, (srcRect.bottom - srcRect.top));
int32_t width = std::min(buf->width, (srcRect.right - srcRect.left));
uint32_t *out = static_cast<uint32_t *>(buf->bits);
out += (height - 1) * buf->stride;
for (int32_t y = 0; y < height; y++) {
const uint8_t *pY = yPixel + yStride * (y + srcRect.top) + srcRect.left;
int32_t uv_row_start = uvStride * ((y + srcRect.top) >> 1);
const uint8_t *pU = uPixel + uv_row_start + (srcRect.left >> 1);
const uint8_t *pV = vPixel + uv_row_start + (srcRect.left >> 1);
for (int32_t x = 0; x < width; x++) {
const int32_t uv_offset = (x >> 1) * uvPixelStride;
// mirror image since we are using front camera
out[width - 1 - x] = YUV2RGB(pY[x], pU[uv_offset], pV[uv_offset]);
// out[x] = YUV2RGB(pY[x], pU[uv_offset], pV[uv_offset]);
}
out -= buf->stride;
}
}
/*
* PresentImage270()
* Converting image from YUV to RGB
* Rotate Image counter-clockwise 270 degree: (x, y) --> (y, x)
*/
void CPhoneDevice2::PresentImage270(ANativeWindow_Buffer *buf, AImage *image) {
AImageCropRect srcRect;
AImage_getCropRect(image, &srcRect);
AImage_getPlaneRowStride(image, 0, &yStride);
AImage_getPlaneRowStride(image, 1, &uvStride);
yPixel = imageBuffer_;
AImage_getPlaneData(image, 0, &yPixel, &yLen);
vPixel = imageBuffer_ + yLen;
AImage_getPlaneData(image, 1, &vPixel, &vLen);
uPixel = imageBuffer_ + yLen + vLen;
AImage_getPlaneData(image, 2, &uPixel, &uLen);
AImage_getPlanePixelStride(image, 1, &uvPixelStride);
int32_t height = std::min(buf->width, (srcRect.bottom - srcRect.top));
int32_t width = std::min(buf->height, (srcRect.right - srcRect.left));
uint32_t *out = static_cast<uint32_t *>(buf->bits);
for (int32_t y = 0; y < height; y++) {
const uint8_t *pY = yPixel + yStride * (y + srcRect.top) + srcRect.left;
int32_t uv_row_start = uvStride * ((y + srcRect.top) >> 1);
const uint8_t *pU = uPixel + uv_row_start + (srcRect.left >> 1);
const uint8_t *pV = vPixel + uv_row_start + (srcRect.left >> 1);
for (int32_t x = 0; x < width; x++) {
const int32_t uv_offset = (x >> 1) * uvPixelStride;
int testb = pU[uv_offset];
int testc = pV[uv_offset];
int testA = pY[x];
out[(width - 1 - x) * buf->stride] =
YUV2RGB(testA, testb, testc);
}
out += 1; // move to the next column
}
}
/*
bool CPhoneDevice2::SendBroadcastMessage(String16 action, int value)
{
TM_INFO_LOG("sendBroadcastMessage(): Action: %s, Value: %d ", action.string(), value);
sp <IServiceManager> sm = defaultServiceManager();
sp <IBinder> am = sm->getService(String16("activity"));
if (am != NULL) {
Parcel data, reply;
data.writeInterfaceToken(String16("android.app.IActivityManager"));
data.writeStrongBinder(NULL);
// intent begin
data.writeString16(action); // action
data.writeInt32(0); // URI data type
data.writeString16(NULL, 0); // type
data.writeInt32(0); // flags
data.writeString16(NULL, 0); // package name
data.writeString16(NULL, 0); // component name
data.writeInt32(0); // source bound - size
data.writeInt32(0); // categories - size
data.writeInt32(0); // selector - size
data.writeInt32(0); // clipData - size
data.writeInt32(-2); // contentUserHint: -2 -> UserHandle.USER_CURRENT
data.writeInt32(-1); // bundle extras length
data.writeInt32(0x4C444E42); // 'B' 'N' 'D' 'L'
int oldPos = data.dataPosition();
data.writeInt32(1); // size
// data.writeInt32(0); // VAL_STRING, need to remove because of analyze common intent
data.writeString16(String16("type"));
data.writeInt32(1); // VAL_INTEGER
data.writeInt32(value);
int newPos = data.dataPosition();
data.setDataPosition(oldPos - 8);
data.writeInt32(newPos - oldPos); // refill bundle extras length
data.setDataPosition(newPos);
// intent end
data.writeString16(NULL, 0); // resolvedType
data.writeStrongBinder(NULL); // resultTo
data.writeInt32(0); // resultCode
data.writeString16(NULL, 0); // resultData
data.writeInt32(-1); // resultExtras
data.writeString16(NULL, 0); // permission
data.writeInt32(0); // appOp
data.writeInt32(-1); // option
data.writeInt32(1); // serialized: != 0 -> ordered
data.writeInt32(0); // sticky
data.writeInt32(-2); // userId: -2 -> UserHandle.USER_CURRENT
status_t ret = am->transact(IBinder::FIRST_CALL_TRANSACTION + 13, data,
&reply); // BROADCAST_INTENT_TRANSACTION
if (ret == NO_ERROR) {
int exceptionCode = reply.readExceptionCode();
if (exceptionCode) {
TM_INFO_LOG("sendBroadcastMessage(%s) caught exception %d\n",
action.string(), exceptionCode);
return false;
}
} else {
return false;
}
} else {
TM_INFO_LOG("getService() couldn't find activity service!\n");
return false;
}
return true;
}
*/
void CPhoneDevice2::camera_device_on_disconnected(void *context, ACameraDevice *device)
{
ALOGI("Camera(id: %s) is diconnected.\n", ACameraDevice_getId(device));
CPhoneDevice2* pThis = (CPhoneDevice2*)context;
// delete pThis;
}
void CPhoneDevice2::camera_device_on_error(void *context, ACameraDevice *device, int error)
{
ALOGI("Error(code: %d) on Camera(id: %s).\n", error, ACameraDevice_getId(device));
}
void CPhoneDevice2::capture_session_on_ready(void *context, ACameraCaptureSession *session)
{
ALOGI("Session is ready. %p\n", session);
}
void CPhoneDevice2::capture_session_on_active(void *context, ACameraCaptureSession *session)
{
ALOGI("Session is activated. %p\n", session);
}
void CPhoneDevice2::capture_session_on_closed(void *context, ACameraCaptureSession *session)
{
ALOGI("Session is closed. %p\n", session);
}

@ -1,124 +0,0 @@
#ifndef __PHONE_DEVICE2_H__
#define __PHONE_DEVICE2_H__
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <map>
#include <atomic>
#include <camera/NdkCameraManager.h>
#include <camera/NdkCameraError.h>
#include <camera/NdkCameraDevice.h>
#include <camera/NdkCameraMetadataTags.h>
#include <media/NdkImageReader.h>
#include <Client/Device.h>
#include <string>
#include "camera2/Camera2Helper.h"
class CPhoneDevice2 : public IDevice
{
public:
CPhoneDevice2(JavaVM* vm, jobject service);
virtual ~CPhoneDevice2();
virtual void SetListener(IListener* listener);
virtual bool UpdateTime(time_t ts);
virtual bool Reboot();
virtual timer_uid_t RegisterHeartbeat(unsigned int timerType, unsigned int timeout);
virtual bool TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<OSD_INFO>& osds, const string& path);
virtual timer_uid_t RegisterTimer(unsigned int timerType, unsigned int timeout);
virtual bool UnregisterTimer(timer_uid_t uid);
virtual bool FireTimer(timer_uid_t uid);
protected:
ACameraCaptureSession_stateCallbacks *GetSessionListener();
std::string GetFileName() const;
bool SendBroadcastMessage(std::string action, int value);
bool MatchCaptureSizeRequest(ACameraManager *cameraManager, const char *selectedCameraId, unsigned int width, unsigned int height, uint32_t cameraOrientation_,
ImageFormat* resCap);
bool DisplayImage(ANativeWindow_Buffer* buf, AImage* image);
void PresentImage(ANativeWindow_Buffer* buf, AImage* image);
void PresentImage90(ANativeWindow_Buffer* buf, AImage* image);
void PresentImage180(ANativeWindow_Buffer* buf, AImage* image);
void PresentImage270(ANativeWindow_Buffer* buf, AImage* image);
static void camera_device_on_disconnected(void *context, ACameraDevice *device);
static void camera_device_on_error(void *context, ACameraDevice *device, int error);
static void capture_session_on_ready(void *context, ACameraCaptureSession *session);
static void capture_session_on_active(void *context, ACameraCaptureSession *session);
static void capture_session_on_closed(void *context, ACameraCaptureSession *session);
void ImageCallback(AImageReader *reader);
static void OnImageCallback(void *ctx, AImageReader *reader);
bool WriteFile(AImage *image, const string& path);
static bool WriteFile(CPhoneDevice2* pThis, AImage *image);
inline bool TakePhotoCb(bool res, const IDevice::PHOTO_INFO& photoInfo, const string& path, time_t photoTime)
{
if (m_listener != NULL)
{
std::vector<IDevice::RECOG_OBJECT> objects;
return m_listener->OnPhotoTaken(res, photoInfo, path, photoTime, objects);
}
return false;
}
protected:
JavaVM* m_vm;
jobject m_javaService;
jmethodID mRegisterTimerMid;
jmethodID mRegisterHeartbeatMid;
jmethodID mUnregisterTimerMid;
jmethodID mUpdateTimeMid;
std::string mPath;
IDevice::PHOTO_INFO mPhotoInfo;
IListener* m_listener;
atomic_ulong m_timerUidFeed;
std::map<IDevice::timer_uid_t, unsigned long> mTimers;
AImageReader *mAImageReader;
ANativeWindow *theNativeWindow;
ACameraDevice *cameraDevice;
ACaptureRequest *captureRequest;
ACameraOutputTarget *cameraOutputTarget;
ACaptureSessionOutput *sessionOutput;
ACaptureSessionOutputContainer *captureSessionOutputContainer;
ACameraCaptureSession *captureSession;
ACameraDevice_StateCallbacks deviceStateCallbacks;
ACameraCaptureSession_stateCallbacks captureSessionStateCallbacks;
DisplayDimension mDisplayDimension;
int32_t presentRotation_;
int32_t imageHeight_;
int32_t imageWidth_;
uint8_t* imageBuffer_;
int32_t yStride, uvStride;
uint8_t *yPixel, *uPixel, *vPixel;
int32_t yLen, uLen, vLen;
int32_t uvPixelStride;
};
#endif // __PHONE_DEVICE2_H__

@ -36,72 +36,6 @@ AI_DEF weatherpntmsg[WEATHER_DATA_NUM];
AI_DEF rallypntmsg[6][RALLY_DATA_NUM];
AI_DEF slantpntmsg[6][SLANTANGLE_DATA_NUM];
static void setInt(int cmd, int value)
{
int fd = ::open("/dev/mtkgpioctrl", O_RDONLY);
IOT_PARAM param;
param.cmd = cmd;
param.value = value;
// LOGE("set_int fd=%d,cmd=%d,value=%d\r\n",fd, cmd, value);
if (fd > 0)
{
ioctl(fd, IOT_PARAM_WRITE, &param);
// LOGE("set_int22 cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result);
close(fd);
}
//return;
}
int getInt(int cmd)
{
int fd = ::open("/dev/mtkgpioctrl", O_RDONLY);
// LOGE("get_int fd=%d,cmd=%d\r\n",fd, cmd);
if (fd > 0)
{
IOT_PARAM param;
param.cmd = cmd;
ioctl(fd, IOT_PARAM_READ, &param);
#ifdef _DEBUG
//ALOGI("getInt cmd=%d,value=%d,result=%d\r\n",param.cmd, param.value, param.result);
#endif
close(fd);
return param.value;
}
return -1;
}
static void setRS485Enable(bool z) {
#ifndef USING_N938
setInt(CMD_SET_485_EN_STATE, z ? 1 : 0);
#endif
}
static void set485WriteMode() {
#ifndef USING_N938
setInt(CMD_SET_485_STATE, 1);
#endif
}
static void set485ReadMode() {
#ifndef USING_N938
setInt(CMD_SET_485_STATE, 0);
#endif
}
static void set12VEnable(bool z) {
#ifndef USING_N938
setInt(CMD_SET_12V_EN_STATE, z ? 1 : 0);
#endif
}
static void setCam3V3Enable(bool enabled)
{
#ifdef ENABLE_3V3_ALWAYS
setInt(CMD_SET_CAM_3V3_EN_STATE, 1);
#else
setInt(CMD_SET_CAM_3V3_EN_STATE, enabled ? 1 : 0);
#endif
}
#if 0
/*********************************************************************************
* *
@ -2483,7 +2417,7 @@ int FindNextCameraPhotoCommand(int devidx)
return 1;
case 10009: /* 近距离聚焦(1 有效)*/
Gm_CtrlPtzCmd(channel, P_FOCUS_NEAR);
usleep(100000);
usleep(500000);
Gm_CtrlPtzCmd(channel, Cmd_Cancel);
usleep(100000);
srdt.ms_dev[devidx].SerialCmdidx = srdt.iLastGetPhotoNo;
@ -2491,7 +2425,7 @@ int FindNextCameraPhotoCommand(int devidx)
return 1;
case 10010: /* 远距离聚焦(1 有效)*/
Gm_CtrlPtzCmd(channel, P_FOCUS_FAR);
usleep(100000);
usleep(500000);
Gm_CtrlPtzCmd(channel, Cmd_Cancel);
usleep(100000);
srdt.ms_dev[devidx].SerialCmdidx = srdt.iLastGetPhotoNo;
@ -2499,7 +2433,7 @@ int FindNextCameraPhotoCommand(int devidx)
return 1;
case 10011: /* 远离物体(1 有效)*/
Gm_CtrlPtzCmd(channel, P_ZOOM_WIDE);
usleep(100000);
usleep(500000);
Gm_CtrlPtzCmd(channel, Cmd_Cancel);
usleep(100000);
srdt.ms_dev[devidx].SerialCmdidx = srdt.iLastGetPhotoNo;
@ -2507,7 +2441,7 @@ int FindNextCameraPhotoCommand(int devidx)
return 1;
case 10012: /* 接近物体(1 有效)*/
Gm_CtrlPtzCmd(channel, P_ZOOM_TELE);
usleep(100000);
usleep(500000);
Gm_CtrlPtzCmd(channel, Cmd_Cancel);
usleep(100000);
srdt.ms_dev[devidx].SerialCmdidx = srdt.iLastGetPhotoNo;

@ -1,79 +0,0 @@
#include "TerminalDevice.h"
#include <dlfcn.h>
#include "Camera.h"
#include <AndroidHelper.h>
typedef jbyteArray (*TakePhotoFunc)(int, int, int, int);
extern bool GetJniEnv(JavaVM *vm, JNIEnv **env, bool& didAttachThread);
CTerminalDevice::CTerminalDevice(JavaVM* vm, jobject service)
{
m_vm = vm;
JNIEnv* env = NULL;
bool attached = false;
bool res = GetJniEnv(m_vm, &env, attached);
if (!res)
{
ALOGE("Failed to get JNI Env");
}
m_javaService = env->NewGlobalRef(service);
if (attached)
{
vm->DetachCurrentThread();
}
}
CTerminalDevice::~CTerminalDevice()
{
JNIEnv* env = NULL;
bool attached = false;
bool res = GetJniEnv(m_vm, &env, attached);
if (!res)
{
ALOGE("Failed to get JNI Env");
}
env->DeleteGlobalRef(m_javaService);
if (attached)
{
m_vm->DetachCurrentThread();
}
m_javaService = NULL;
}
bool CTerminalDevice::TakePhoto(unsigned char channel, unsigned char preset, const string& path, bool photo)
{
jboolean res = JNI_FALSE;
CCamera camera;
camera.initCamera(NULL);
if (camera.isCameraReady())
{
camera.takePicture();
}
camera.closeCamera();
#if 0
JNIEnv* env = NULL;
bool attached = GetJniEnv(m_vm, &env);
jclass serviceClass = env->GetObjectClass(m_javaService);
jmethodID mid = env->GetMethodID(serviceClass, "takePhoto", "(SSLjava/lang/String;)Z");
jstring str = env->NewStringUTF(path.c_str());
res = env->CallBooleanMethod (m_javaService, mid, (jint)channel, (jint)preset, str);
env->ReleaseStringUTFChars(str, path.c_str());
env->DeleteLocalRef(serviceClass);
if (!res)
{
int aa = 1;
}
if (attached)
{
m_vm->DetachCurrentThread();
}
#endif
return res == JNI_TRUE;
}

@ -1,21 +0,0 @@
#ifndef __TERMINAL_DEVICE_H__
#define __TERMINAL_DEVICE_H__
#include <Client/Device.h>
#include <jni.h>
class CTerminalDevice : public IDevice
{
public:
CTerminalDevice(JavaVM* vm, jobject service);
~CTerminalDevice();
virtual bool TakePhoto(unsigned char channel, unsigned char preset, const string& path, bool photo);
private:
JavaVM* m_vm;
jobject m_javaService;
};
#endif // __TERMINAL_DEVICE_H__

@ -4,7 +4,7 @@ plugins {
def AppMajorVersion = 1
def AppMinorVersion = 0
def AppBuildNumber = 70
def AppBuildNumber = 87
def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber
def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber

@ -437,11 +437,14 @@ public class MpMasterService extends Service {
if (mPreviousMpHbTime <= ts && ts - mPreviousMpHbTime > mMpHeartbeatDuration * 2) {
// MpApp is not running
if (ts - mTimeToStartMpApp >= 30000) {
if (ts - mTimeToStartMpApp >= 1800000) {
MicroPhotoContext.restartMpApp(context, "MpMST Keep Alive Detection");
mTimeToStartMpApp = ts;
logger.warning("Restart MpAPP as it is NOT Running Prev MPAPP HB=" +
Long.toString((ts - mPreviousMpHbTime) / 1000) + " MPAPP HBDuration=" + Long.toString(mMpHeartbeatDuration));
Long.toString((ts - mPreviousMpHbTime) / 1000) + " MPAPP HBDuration=" + Long.toString(mMpHeartbeatDuration)
+ " Prev MpRestart Time=" + Long.toString(mTimeToStartMpApp));
mTimeToStartMpApp = ts;
} else {
logger.warning("MpAPP has restarted during 30s, skip the check.");
}
@ -459,7 +462,7 @@ public class MpMasterService extends Service {
((ts - modifiedTimeOfPhoto) > mTimeOfMpAppAlive * 4) ||
((ts - modifiedTimeOfUpload) > mTimeOfMpAppAlive * 4)) {
if (ts - mTimeToStartMpApp >= 30000) {
if (ts - mTimeToStartMpApp >= 1800000) {
String msg = "Restart MpAPP as it is NOT Running hb=" + Long.toString(ts - modifiedTimeOfHb) +
" taking=" + Long.toString(ts - modifiedTimeOfPhoto) + " sending=" + Long.toString(ts - modifiedTimeOfUpload) +
" Will restart MpApp in " + Long.toString(mDelayedRestartMpTime / 1000) + " seconds";

Loading…
Cancel
Save