通过配置文件的方式把拍照参数传入到JNI

hdrplus
Matthew 12 months ago
parent 2bed6b270d
commit 50dbd18645

@ -373,8 +373,7 @@ Java_com_xypower_mpapp_MicroPhotoService_notifyToTakePhoto(
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,
jstring leftTopOsd, jstring rightTopOsd, jstring rightBottomOsd, jstring leftBottomOsd) {
jclass cls, jint channel, jint preset, jboolean photoOrVideo, jstring configFilePath, jstring path) {
if (channel < 1 || channel > 0xFF)
{
@ -384,39 +383,31 @@ Java_com_xypower_mpapp_MicroPhotoService_takePhoto(
JavaVM* vm = NULL;
jint ret = env->GetJavaVM(&vm);
std::string configFilePathStr = jstring2string(env, configFilePath);
CFG_CHANNEL cfg;
IDevice::PHOTO_INFO photoInfo(channel, preset);
CTerminal::LoadChannelConfig(channel, configFilePathStr, cfg);
CTerminal::ConvertChannelConfigToPhotoInfo(cfg, photoOrVideo != JNI_FALSE, photoInfo);
CPhoneDevice* device = new CPhoneDevice(vm, NULL, "", NETID_UNSET, 0);
// device->SetListener(pTerminal);
if (usb == JNI_TRUE)
if (photoInfo.usbCamera)
{
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;
osds.resize(4);
osds[1].alignment = IDevice::OSD_ALIGNMENT_TOP_RIGHT;
osds[2].alignment = IDevice::OSD_ALIGNMENT_BOTTOM_RIGHT;
osds[3].alignment = IDevice::OSD_ALIGNMENT_BOTTOM_LEFT;
osds[0].text = jstring2string(env, leftTopOsd);
osds[1].text = jstring2string(env, rightTopOsd);
osds[2].text = jstring2string(env, rightBottomOsd);
osds[3].text = jstring2string(env, leftBottomOsd);
osds[0].text = cfg.osd.leftTop;
osds[1].text = cfg.osd.rightTop;
osds[2].text = cfg.osd.rightBottom;
osds[3].text = cfg.osd.leftBottom);
const char* pathStr = env->GetStringUTFChars(path, 0);

@ -1,19 +1,27 @@
package com.xypower.mpapp;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Base64;
import com.xypower.common.FileUtils;
import com.xypower.common.JSONUtils;
import com.xypower.common.MicroPhotoContext;
import com.xypower.mpapp.v2.Camera2VideoActivity;
import org.json.JSONObject;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
public class BridgeActivity extends AppCompatActivity {
@ -92,14 +100,58 @@ public class BridgeActivity extends AppCompatActivity {
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);
int width = intent.getIntExtra("width", 0);
int height = intent.getIntExtra("height", 0);
String leftTopOsd = intent.getStringExtra("leftTopOsd");
String rightTopOsd = intent.getStringExtra("rightTopOsd");
String rightBottomOsd = intent.getStringExtra("rightBottomOsd");
String leftBottomOsd = intent.getStringExtra("leftBottomOsd");
String appPath = MicroPhotoContext.buildMpAppDir(getApplicationContext());
File configFile = new File(appPath);
configFile = new File(configFile, "data/channels/" + Integer.toString(channel) + ".json");
File tmpConfigFile = new File(appPath);
tmpConfigFile = new File(tmpConfigFile, "tmp/" + Integer.toString(channel) + "-" + Long.toString(System.currentTimeMillis()) + ".json");
if (configFile.exists()) {
try {
FileUtils.copyFile(configFile, tmpConfigFile);
} catch (Exception ex) {
ex.printStackTrace();
}
}
JSONObject configJson = JSONUtils.loadJson(tmpConfigFile.getAbsolutePath());
try {
if (configJson == null) {
configJson = new JSONObject();
}
if (width > 0) {
configJson.put("resolutionCX", width);
}
if (height > 0) {
configJson.put("resolutionCY", height);
}
JSONObject osdJson = configJson.getJSONObject("osd");
if (osdJson == null) {
osdJson = configJson.put("osd", new JSONObject());
}
osdJson.put("leftTop", TextUtils.isEmpty(leftTopOsd) ? "" : leftTopOsd);
osdJson.put("rightTop", TextUtils.isEmpty(rightTopOsd) ? "" : rightTopOsd);
osdJson.put("rightBottom", TextUtils.isEmpty(rightBottomOsd) ? "" : rightBottomOsd);
osdJson.put("leftBottom", TextUtils.isEmpty(leftBottomOsd) ? "" : leftBottomOsd);
JSONUtils.saveJson(tmpConfigFile.getAbsolutePath(), configJson);
} catch (Exception ex) {
ex.printStackTrace();
}
File file = new File(path);
if (file.exists()) {
file.delete();
@ -107,7 +159,10 @@ public class BridgeActivity extends AppCompatActivity {
FileUtils.ensureParentDirectoryExisted(path);
}
MicroPhotoService.takePhoto(channel, preset, cameraId, usb, path, leftTopOsd, rightTopOsd, rightBottomOsd, leftBottomOsd);
MicroPhotoService.takePhoto(channel, preset, true, tmpConfigFile.getAbsolutePath(), path);
if (tmpConfigFile.exists()) {
tmpConfigFile.delete();
}
} else if (TextUtils.equals(action, ACTION_RECORDING)) {
String path = intent.getStringExtra("path");

@ -1161,7 +1161,7 @@ cellSignalStrengthGsm.getDbm();
protected native void updatePosition(long handler, double lon, double lat, double radius, long ts);
protected native boolean uninit(long handler);
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, String leftTopOsd, String rightTopOsd, String rightBottomOsd, String leftBottomOsd);
public static native long takePhoto(int channel, int preset, boolean photoOrVideo, String configFilePath, String path);
public static native void releaseDeviceHandle(long deviceHandle);
public static native void infoLog(String log);
public static native void setOtgState(boolean enabled);

@ -8,7 +8,10 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Date;
@ -18,6 +21,28 @@ public class FileUtils {
public static void copyFile(File source, File dest) throws IOException {
InputStream input = null;
OutputStream output = null;
try {
input = new FileInputStream(source);
output = new FileOutputStream(dest);
byte[] buf = new byte[1024];
int bytesRead;
while ((bytesRead = input.read(buf)) > 0) {
output.write(buf, 0, bytesRead);
}
} finally {
try {
if (input != null) input.close();
} catch (Exception ex) {
}
try {
if (output != null) output.close();
} catch (Exception ex) {
}
}
}
public static boolean DeleteFilesInPath(String path, long seconds) {
File pathFile = new File(path);

Loading…
Cancel
Save