优化系统相机拍照

nx2024TEMP
Matthew 8 months ago
parent 49931e8d9a
commit 0c7dee683f

@ -950,7 +950,7 @@ Java_com_xypower_mpapp_MicroPhotoService_reloadConfigs(
extern "C" JNIEXPORT jboolean JNICALL extern "C" JNIEXPORT jboolean JNICALL
Java_com_xypower_mpapp_MicroPhotoService_sendExternalPhoto( Java_com_xypower_mpapp_MicroPhotoService_sendExternalPhoto(
JNIEnv* env, jclass cls, jlong handler, jstring path) { JNIEnv* env, jclass cls, jlong handler, jstring path, jlong photoInfo) {
CTerminal* pTerminal = reinterpret_cast<CTerminal *>(handler); CTerminal* pTerminal = reinterpret_cast<CTerminal *>(handler);
if (pTerminal == NULL) if (pTerminal == NULL)
@ -963,10 +963,25 @@ Java_com_xypower_mpapp_MicroPhotoService_sendExternalPhoto(
return JNI_FALSE; return JNI_FALSE;
} }
const char *pathStr = env->GetStringUTFChars(path, 0); IDevice::PHOTO_INFO* pPhotoInfo = photoInfo == 0 ? NULL : reinterpret_cast<IDevice::PHOTO_INFO *>(photoInfo);
const char *pathStr = NULL;
if (path != NULL)
{
pathStr = env->GetStringUTFChars(path, 0);
}
bool res = pTerminal->SendExternalPhoto(pathStr); bool res = pTerminal->SendExternalPhoto(pathStr);
env->ReleaseStringUTFChars(path, pathStr); if (pathStr != NULL)
{
env->ReleaseStringUTFChars(path, pathStr);
}
if (pPhotoInfo != NULL)
{
delete pPhotoInfo;
}
return res ? JNI_TRUE : JNI_FALSE; return res ? JNI_TRUE : JNI_FALSE;
} }

@ -433,6 +433,8 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
mExecHdrplusMid = env->GetMethodID(classService, "execHdrplus", "(IILjava/lang/String;Ljava/lang/String;)I"); mExecHdrplusMid = env->GetMethodID(classService, "execHdrplus", "(IILjava/lang/String;Ljava/lang/String;)I");
mCallSysCameraMid = env->GetMethodID(classService, "callSystemCamera", "(IJ)V");
env->DeleteLocalRef(classService); env->DeleteLocalRef(classService);
} }
@ -1441,7 +1443,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
TurnOnCameraPower(NULL); TurnOnCameraPower(NULL);
res = true; res = true;
if (mPhotoInfo.mediaType == 0/* && mPhotoInfo.usingRawFormat == 0*/) if (mPhotoInfo.mediaType == 0 && mPhotoInfo.usingSysCamera == 0)
{ {
mCamera = new CPhoneCamera(this, photoInfo.width, photoInfo.height, params); mCamera = new CPhoneCamera(this, photoInfo.width, photoInfo.height, params);
// mCamera = new CJpegCamera(this, photoInfo.width, photoInfo.height, mPath, params); // mCamera = new CJpegCamera(this, photoInfo.width, photoInfo.height, mPath, params);
@ -1463,6 +1465,28 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
} }
} }
} }
else if (mPhotoInfo.usingSysCamera == 1)
{
JNIEnv* env = NULL;
bool didAttachThread = false;
res = GetJniEnv(m_vm, &env, didAttachThread);
if (!res)
{
ALOGE("Failed to get JNI Env");
return false;
}
IDevice::PHOTO_INFO *pPhotoInfo = new IDevice::PHOTO_INFO(mPhotoInfo);
jboolean photoOrVideo = mPhotoInfo.mediaType == 0 ? JNI_TRUE : JNI_FALSE;
env->CallVoidMethod(m_javaService, mCallSysCameraMid, mPhotoInfo.cameraId,
reinterpret_cast<jlong>(pPhotoInfo));
if (didAttachThread)
{
m_vm->DetachCurrentThread();
}
}
else else
{ {
JNIEnv* env = NULL; JNIEnv* env = NULL;
@ -2870,6 +2894,20 @@ bool CPhoneDevice::OnVideoReady(bool photoOrVideo, bool result, const char* path
{ {
if (photoOrVideo) if (photoOrVideo)
{ {
mPhotoInfo.photoTime = time(NULL);
CPhoneCamera* pCamera = NULL;
std::vector<IDevice::RECOG_OBJECT> objs;
std::string fullPath = mPath + CTerminal::BuildPhotoFileName(mPhotoInfo);
if (result)
{
std::rename(path, fullPath.c_str());
}
TakePhotoCb(result ? 3 : 0, mPhotoInfo, fullPath, time(NULL), objs);
bool turnOffOtg = (mPhotoInfo.usbCamera != 0);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, mPhotoInfo.photoId, turnOffOtg);
m_threadClose.swap(closeThread);
} }
else else
{ {

@ -324,6 +324,8 @@ protected:
jmethodID mRequestPositionMid; jmethodID mRequestPositionMid;
jmethodID mExecHdrplusMid; jmethodID mExecHdrplusMid;
jmethodID mCallSysCameraMid;
std::string mPath; std::string mPath;
IDevice::PHOTO_INFO mPhotoInfo; IDevice::PHOTO_INFO mPhotoInfo;
vector<IDevice::OSD_INFO> mOsds; vector<IDevice::OSD_INFO> mOsds;

@ -432,27 +432,6 @@ public class MicroPhotoService extends Service {
Log.i(TAG, "PhotoTimer Fired: CH=" + channel + " PR=" + preset); Log.i(TAG, "PhotoTimer Fired: CH=" + channel + " PR=" + preset);
mService.notifyToTakePhoto(mService.mNativeHandle, channel, preset, ts, photoOrVideo); mService.notifyToTakePhoto(mService.mNativeHandle, channel, preset, ts, photoOrVideo);
} }
File cameraAdbCfg = new File(MicroPhotoContext.buildMpAppDir(mService.getApplication()), "data/cameraAdb.cfg");
if (cameraAdbCfg.exists()) {
final String appPath = MicroPhotoContext.buildMpAppDir(context);
mService.mHander.postDelayed(new Runnable() {
@Override
public void run() {
final CameraAdb cameraAdb = new CameraAdb(context, appPath);
cameraAdb.setCallback(new Runnable() {
@Override
public void run() {
List<String> targetPaths = cameraAdb.getTargetPaths();
for (String targetPath : targetPaths) {
mService.sendExternalPhoto(mService.mNativeHandle, targetPath);
}
}
});
cameraAdb.takePhoto();
}
}, 10000 * cnt);
}
} }
// Register Next Photo Timer // Register Next Photo Timer
@ -1480,7 +1459,7 @@ cellSignalStrengthGsm.getDbm();
protected native void burstCaptureFinished(long handler, boolean result, int numberOfCaptures, String pathsJoinedByTab, boolean frontCamera, int rotation, long photoId); protected native void burstCaptureFinished(long handler, boolean result, int numberOfCaptures, String pathsJoinedByTab, boolean frontCamera, int rotation, long photoId);
public static native long takePhoto(int channel, int preset, boolean photoOrVideo, String configFilePath, String path); 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 releaseDeviceHandle(long deviceHandle);
public static native boolean sendExternalPhoto(long deviceHandle, String path); public static native boolean sendExternalPhoto(long deviceHandle, String path, long photoInfo);
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);
@ -1570,6 +1549,25 @@ cellSignalStrengthGsm.getDbm();
} }
}; };
public void callSystemCamera(final int cameraId, final long photoId) {
Context context = getApplicationContext();
final CameraAdb cameraAdb = new CameraAdb(context, MicroPhotoContext.buildMpAppDir(context));
cameraAdb.setCallback(new Runnable() {
@Override
public void run() {
List<String> targetPaths = cameraAdb.getTargetPaths();
if (targetPaths.isEmpty()) {
recordingFinished(mNativeHandle, true, false, null, photoId);
} else {
for (String targetPath : targetPaths) {
recordingFinished(mNativeHandle, true, true, targetPath, photoId);
}
}
}
});
cameraAdb.takePhoto(cameraId);
}
////////////////////////GPS//////////////////// ////////////////////////GPS////////////////////
private void setDefaultDataSubId(int subId) { private void setDefaultDataSubId(int subId) {

@ -78,19 +78,19 @@ public class CameraAdb {
mAdbKeyPair = AdbKeyPair.read(priKeyFile, pubKeyFile); mAdbKeyPair = AdbKeyPair.read(priKeyFile, pubKeyFile);
} }
public void takePhoto() { public void takePhoto(final int cameraId) {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
takePhotoImpl(); takePhotoImpl(cameraId);
} }
}).start(); }).start();
} }
private void takePhotoImpl() { private void takePhotoImpl(final int cameraId) {
long requestTime = System.currentTimeMillis() / 1000; long requestTime = System.currentTimeMillis() / 1000;
takePhoto(false); takePhoto(cameraId == 1);
long takingTime = System.currentTimeMillis() / 1000; long takingTime = System.currentTimeMillis() / 1000;
sleep(1500); sleep(1500);
String path = movePhoto(false, requestTime, takingTime); String path = movePhoto(false, requestTime, takingTime);
@ -100,21 +100,6 @@ public class CameraAdb {
sleep(100); sleep(100);
SysApi.forceStopApp(mContext, "com.mediatek.camera"); SysApi.forceStopApp(mContext, "com.mediatek.camera");
sleep(1000);
requestTime = System.currentTimeMillis() / 1000;
takePhoto(true);
takingTime = System.currentTimeMillis() / 1000;
sleep(200);
SysApi.forceStopApp(mContext, "com.mediatek.camera");
sleep(250);
path = movePhoto(true, requestTime, takingTime);
if (!TextUtils.isEmpty(path)) {
mTargetPaths.add(path);
}
if (mRunnable != null) { if (mRunnable != null) {
mRunnable.run(); mRunnable.run();
} }
@ -168,7 +153,7 @@ public class CameraAdb {
} }
} }
public void takePhoto(final boolean frontCamera) { protected void takePhoto(final boolean frontCamera) {
Dadb adb = Dadb.create(mDeviceIp, 5555, mAdbKeyPair); Dadb adb = Dadb.create(mDeviceIp, 5555, mAdbKeyPair);
if (adb == null) { if (adb == null) {

Loading…
Cancel
Save