基于安装工具调整接口和实现

hdrplus
Matthew 12 months ago
parent 30a3c9a703
commit b601de49d9

@ -369,6 +369,65 @@ Java_com_xypower_mpapp_MicroPhotoService_notifyToTakePhoto(
return JNI_TRUE; return JNI_TRUE;
} }
extern "C" JNIEXPORT jlong JNICALL
Java_com_xypower_mpapp_MicroPhotoService_takePhoto(
JNIEnv* env,
jclass cls, jint channel, jint preset, jint cameraId, jboolean usb, jstring path) {
if (channel < 1 || channel > 0xFF)
{
return 0;
}
JavaVM* vm = NULL;
jint ret = env->GetJavaVM(&vm);
CPhoneDevice* device = new CPhoneDevice(vm, NULL, "", NETID_UNSET, 0);
// device->SetListener(pTerminal);
if (usb == JNI_TRUE)
{
device->TurnOnOtg(NULL);
}
device->TurnOnCameraPower(NULL);
int32_t width = 1920;
int32_t height = 1080;
NdkCamera::CAMERA_PARAMS params = { 0 };
NdkCamera camera(0, 0, params);
int res = camera.selfTest(std::to_string(cameraId), width, height);
// const IDevice::PHOTO_INFO& photoInfo, const vector<OSD_INFO>& osds, const std::string& path
IDevice::PHOTO_INFO photoInfo(channel, preset);
photoInfo.usbCamera = (usb == JNI_TRUE) ? 1 : 0;
photoInfo.width = width;
photoInfo.height = height;
photoInfo.cameraId = cameraId;
std::vector<IDevice::OSD_INFO> osds;
const char* pathStr = env->GetStringUTFChars(path, 0);
device->TakePhoto(photoInfo, osds, MakeString(pathStr));
env->ReleaseStringUTFChars(path, pathStr);
return reinterpret_cast<jlong>(device);
}
extern "C" JNIEXPORT void JNICALL
Java_com_xypower_mpapp_MicroPhotoService_releaseDeviceHandle(
JNIEnv* env,
jclass cls, jlong deviceHandle) {
if (deviceHandle != 0)
{
CPhoneDevice* pDevice = reinterpret_cast<CPhoneDevice*>(deviceHandle);
delete pDevice;
}
}
extern "C" JNIEXPORT jboolean JNICALL extern "C" JNIEXPORT jboolean JNICALL
Java_com_xypower_mpapp_MicroPhotoService_sendHeartbeat( Java_com_xypower_mpapp_MicroPhotoService_sendHeartbeat(
JNIEnv* env, JNIEnv* env,

@ -186,6 +186,8 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
{ {
ALOGE("Failed to get JNI Env"); ALOGE("Failed to get JNI Env");
} }
if (service != NULL)
{
m_javaService = env->NewGlobalRef(service); m_javaService = env->NewGlobalRef(service);
jclass classService = env->GetObjectClass(m_javaService); jclass classService = env->GetObjectClass(m_javaService);
@ -204,6 +206,7 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
mRequestPositionMid = env->GetMethodID(classService, "requestPosition", "()Z"); mRequestPositionMid = env->GetMethodID(classService, "requestPosition", "()Z");
env->DeleteLocalRef(classService); env->DeleteLocalRef(classService);
}
if (didAttachThread) if (didAttachThread)
{ {
@ -1591,7 +1594,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
params.push_back(mPhotoInfo.quality); params.push_back(mPhotoInfo.quality);
bool res = false; bool res = false;
std::string fullPath = mPath + CTerminal::BuildPhotoFileName(mPhotoInfo); std::string fullPath = endsWith(mPath, ".jpg") ? mPath : (mPath + CTerminal::BuildPhotoFileName(mPhotoInfo));
if (!std::filesystem::exists(std::filesystem::path(fullPath))) if (!std::filesystem::exists(std::filesystem::path(fullPath)))
{ {
bool res = cv::imwrite(fullPath.c_str(), mat, params); bool res = cv::imwrite(fullPath.c_str(), mat, params);

@ -213,6 +213,12 @@ public:
} }
void UpdateSimcard(const std::string& simcard); void UpdateSimcard(const std::string& simcard);
void TurnOnCameraPower(JNIEnv* env);
void TurnOffCameraPower(JNIEnv* env);
void TurnOnOtg(JNIEnv* env);
void TurnOffOtg(JNIEnv* env);
protected: protected:
std::string GetFileName() const; std::string GetFileName() const;
@ -251,12 +257,6 @@ protected:
void CloseCamera2(CPhoneCamera* camera, unsigned int photoId, bool turnOffOtg); void CloseCamera2(CPhoneCamera* camera, unsigned int photoId, bool turnOffOtg);
void TurnOnCameraPower(JNIEnv* env);
void TurnOffCameraPower(JNIEnv* env);
void TurnOnOtg(JNIEnv* env);
void TurnOffOtg(JNIEnv* env);
static void handleSignal(int sig, siginfo_t *si, void *uc); static void handleSignal(int sig, siginfo_t *si, void *uc);
bool RegisterHandlerForSignal(int sig); bool RegisterHandlerForSignal(int sig);
void static handleTimer(union sigval v); void static handleTimer(union sigval v);

@ -154,7 +154,7 @@ NdkCamera::~NdkCamera()
close(); close();
} }
int NdkCamera::selfTest(const std::string& cameraId, int& maxResolutionX, int& maxResolutionY) int NdkCamera::selfTest(const std::string& cameraId, int32_t& maxResolutionX, int32_t& maxResolutionY)
{ {
camera_manager.Create(); camera_manager.Create();
// ACameraManager_registerAvailabilityCallback(camera_manager, &camera_manager_cb); // ACameraManager_registerAvailabilityCallback(camera_manager, &camera_manager_cb);
@ -1113,10 +1113,17 @@ void NdkCamera::on_image(const unsigned char* nv21, int nv21_width, int nv21_hei
else else
{ {
// Crop image // Crop image
if (w > orgWidth && h >= orgHeight)
{
int left = (w - orgWidth) / 2; int left = (w - orgWidth) / 2;
int top = (h - orgHeight) / 2; int top = (h - orgHeight) / 2;
rgb = org(cv::Range(top, top + orgHeight), cv::Range(left, left + orgWidth)); rgb = org(cv::Range(top, top + orgHeight), cv::Range(left, left + orgWidth));
} }
else
{
rgb = org;
}
}
} }
on_image(rgb); on_image(rgb);
} }

@ -106,7 +106,7 @@ public:
int open(const std::string& cameraId); int open(const std::string& cameraId);
void close(); void close();
int selfTest(const std::string& cameraId, int& maxResolutionX, int& maxResolutionY); int selfTest(const std::string& cameraId, int32_t& maxResolutionX, int32_t& maxResolutionY);
void onAvailabilityCallback(const char* cameraId); void onAvailabilityCallback(const char* cameraId);
void onUnavailabilityCallback(const char* cameraId); void onUnavailabilityCallback(const char* cameraId);

@ -22,6 +22,7 @@ public class BridgeActivity extends AppCompatActivity {
private final static String ACTION_CERT_REQ = "cert_req"; private final static String ACTION_CERT_REQ = "cert_req";
private final static String ACTION_BATTERY_VOLTAGE = "query_bv"; private final static String ACTION_BATTERY_VOLTAGE = "query_bv";
private final static String ACTION_RECORDING = "recording"; private final static String ACTION_RECORDING = "recording";
private final static String ACTION_TAKE_PHOTO = "take_photo";
private final static int REQUEST_CODE_RECORDING = Camera2VideoActivity.REQUEST_CODE_RECORDING; private final static int REQUEST_CODE_RECORDING = Camera2VideoActivity.REQUEST_CODE_RECORDING;
@ -87,6 +88,22 @@ public class BridgeActivity extends AppCompatActivity {
File file = new File(path + ".tmp"); File file = new File(path + ".tmp");
file.renameTo(new File(path)); file.renameTo(new File(path));
} }
} else if (TextUtils.equals(action, ACTION_TAKE_PHOTO)) {
String path = intent.getStringExtra("path");
int channel = intent.getIntExtra("channel", 1);
int preset = intent.getIntExtra("preset", 0xFF);
boolean usb = intent.getBooleanExtra("usb", false);
int cameraId = intent.getIntExtra("cameraId", -1);
File file = new File(path);
if (file.exists()) {
file.delete();
} else {
FileUtils.ensureParentDirectoryExisted(path);
}
MicroPhotoService.takePhoto(channel, preset, cameraId, usb, path);
} else if (TextUtils.equals(action, ACTION_RECORDING)) { } else if (TextUtils.equals(action, ACTION_RECORDING)) {
String path = intent.getStringExtra("path"); String path = intent.getStringExtra("path");
int channel = intent.getIntExtra("channel", 1); int channel = intent.getIntExtra("channel", 1);

@ -570,8 +570,23 @@ public class MainActivity extends AppCompatActivity {
} }
private void takePhoto(int channel, int preset, boolean photoOrVideo) { private void takePhoto(int channel, int preset, boolean photoOrVideo) {
if (binding.btnStartServ.isEnabled()) {
String appPath = MicroPhotoContext.buildMpAppDir(getApplicationContext());
File file = new File(appPath);
File tempFile = new File(file, "tmp");
if (!tempFile.exists()) {
tempFile.mkdirs();
}
File photoFile = new File(tempFile, Integer.toString(channel) + "-img.jpg");
if (photoFile.exists()) {
photoFile.delete();
}
MicroPhotoService.takePhoto(channel, preset, channel - 1, (channel == 4), photoFile.getAbsolutePath());
} else {
MicroPhotoService.takePhoto(this.getApplicationContext(), channel, preset, photoOrVideo); MicroPhotoService.takePhoto(this.getApplicationContext(), channel, preset, photoOrVideo);
} }
}
@Override @Override
protected void onResume() { protected void onResume() {
@ -693,9 +708,6 @@ public class MainActivity extends AppCompatActivity {
return 0; return 0;
} }
public native boolean takePhoto(int channel, int preset, String path, String fileName);
private void gpsTake() { private void gpsTake() {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

@ -1153,11 +1153,14 @@ cellSignalStrengthGsm.getDbm();
protected native long[] getPhotoTimeData2(long handler); protected native long[] getPhotoTimeData2(long handler);
// protected native long[] getNextScheduleItem(long handler); // protected native long[] getNextScheduleItem(long handler);
protected native boolean notifyToTakePhoto(long handler, int channel, int preset, long scheduleTime, boolean photoOrVideo); protected native boolean notifyToTakePhoto(long handler, int channel, int preset, long scheduleTime, boolean photoOrVideo);
protected native boolean sendHeartbeat(long handler, int signalLevel); protected native boolean sendHeartbeat(long handler, int signalLevel);
protected native boolean reloadConfigs(long handler); protected native boolean reloadConfigs(long handler);
protected native void updatePosition(long handler, double lon, double lat, double radius, long ts); protected native void updatePosition(long handler, double lon, double lat, double radius, long ts);
protected native boolean uninit(long handler); protected native boolean uninit(long handler);
protected native void recordingFinished(long handler, boolean result, String path, long videoId); protected native void recordingFinished(long handler, boolean result, String path, long videoId);
public static native long takePhoto(int channel, int preset, int cameraId, boolean usb, String path);
public static native void releaseDeviceHandle(long deviceHandle);
public static native void infoLog(String log); public static native void infoLog(String log);
public static native void setOtgState(boolean enabled); public static native void setOtgState(boolean enabled);
public static native void setCam3V3Enable(boolean enabled); public static native void setCam3V3Enable(boolean enabled);

Loading…
Cancel
Save