From 54ddc6f9d6b512523674a1c69482089aed61a928 Mon Sep 17 00:00:00 2001 From: Matthew Date: Sat, 28 Sep 2024 10:09:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=85=A7=E7=89=87=E6=96=B9?= =?UTF-8?q?=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/MicroPhoto.cpp | 6 ++-- app/src/main/cpp/PhoneDevice.cpp | 33 ++++++++++++++++++- app/src/main/cpp/PhoneDevice.h | 2 +- app/src/main/cpp/camera2/ndkcamera.h | 2 +- .../com/xypower/mpapp/MicroPhotoService.java | 4 +-- .../com/xypower/mpapp/video/RawActivity.java | 6 ++++ .../com/xypower/mpmaster/MpMasterService.java | 3 +- 7 files changed, 47 insertions(+), 9 deletions(-) diff --git a/app/src/main/cpp/MicroPhoto.cpp b/app/src/main/cpp/MicroPhoto.cpp index 34e6a548..c753f5c2 100644 --- a/app/src/main/cpp/MicroPhoto.cpp +++ b/app/src/main/cpp/MicroPhoto.cpp @@ -776,8 +776,8 @@ Java_com_xypower_mpapp_MicroPhotoService_captureFinished( extern "C" JNIEXPORT void JNICALL Java_com_xypower_mpapp_MicroPhotoService_burstCaptureFinished( JNIEnv* env, - jobject pThis, jlong handler, jboolean result, jint numberOfCaptures, jstring pathsJoinedByTab, jlong photoId) { - + jobject pThis, jlong handler, jboolean result, jint numberOfCaptures, + jstring pathsJoinedByTab, jboolean frontCamera, jint rotation, jlong photoId) { CTerminal* pTerminal = reinterpret_cast(handler); if (pTerminal == NULL) @@ -801,7 +801,7 @@ Java_com_xypower_mpapp_MicroPhotoService_burstCaptureFinished( } const char* pathsStr = env->GetStringUTFChars(pathsJoinedByTab, 0); - ((CPhoneDevice *)dev)->ProcessRawCapture(result != JNI_FALSE, numberOfCaptures, MakeString(pathsStr), photoId); + ((CPhoneDevice *)dev)->ProcessRawCapture(result != JNI_FALSE, numberOfCaptures, MakeString(pathsStr), frontCamera != JNI_FALSE, rotation, photoId); env->ReleaseStringUTFChars(pathsJoinedByTab, pathsStr); } } diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 7aab8c46..18025baf 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -2017,7 +2017,7 @@ void CPhoneDevice::UpdateSimcard(const std::string& simcard) m_simcard = simcard; } -bool CPhoneDevice::ProcessRawCapture(bool result, int numberOfCaptures, const std::string& pathsJoinedByTab, long photoId) +bool CPhoneDevice::ProcessRawCapture(bool result, int numberOfCaptures, const std::string& pathsJoinedByTab, bool frontCamera, int rotation, long photoId) { std::vector paths = split(pathsJoinedByTab, "\t"); @@ -2033,8 +2033,39 @@ bool CPhoneDevice::ProcessRawCapture(bool result, int numberOfCaptures, const st hdrplus::hdrplus_pipeline pipeline; cv::Mat mat; pipeline.run_pipeline(paths, 0, mat); + XYLOG(XYLOG_SEVERITY_ERROR, "Finish HDR CH=%u IMGID=%u", (uint32_t)mPhotoInfo.channel, (uint32_t)mPhotoInfo.photoId); mat = convert16bit2_8bit_(mat.clone()); + + if (rotation >= 0) + { + if (rotation == 90) + { + cv::Mat tempPic; + cv::transpose(mat, tempPic); + cv::flip(tempPic, mat, 1); + } + else if (rotation == 180) + { + if (frontCamera) + { + flip(mat, mat, 0); + + } + else + { + cv::flip(mat, mat, -1); + } + } + else if (rotation == 270) + { + cv::Mat tempPic; + cv::transpose(mat, tempPic); + cv::flip(tempPic, mat, 0); + } + + XYLOG(XYLOG_SEVERITY_ERROR, "Finish rotation CH=%u IMGID=%u", (uint32_t)mPhotoInfo.channel, (uint32_t)mPhotoInfo.photoId); + } cv::cvtColor(mat, mat, cv::COLOR_RGB2BGR); XYLOG(XYLOG_SEVERITY_ERROR, "Finish Processing Raw Capture CH=%u IMGID=%u", (uint32_t)mPhotoInfo.channel, (uint32_t)mPhotoInfo.photoId); diff --git a/app/src/main/cpp/PhoneDevice.h b/app/src/main/cpp/PhoneDevice.h index 104617ea..5bf95647 100644 --- a/app/src/main/cpp/PhoneDevice.h +++ b/app/src/main/cpp/PhoneDevice.h @@ -221,7 +221,7 @@ public: void UpdatePosition(double lon, double lat, double radius, time_t ts); bool OnVideoReady(bool photoOrVideo, bool result, const char* path, unsigned int photoId); bool OnCaptureReady(bool photoOrVideo, bool result, cv::Mat& mat, unsigned int photoId); - bool ProcessRawCapture(bool result, int numberOfCaptures, const std::string& pathsJoinedByTab, long photoId); + bool ProcessRawCapture(bool result, int numberOfCaptures, const std::string& pathsJoinedByTab, bool frontCamera, int rotation, long photoId); void UpdateSignalLevel(int signalLevel); void UpdateTfCardPath(const std::string& tfCardPath) diff --git a/app/src/main/cpp/camera2/ndkcamera.h b/app/src/main/cpp/camera2/ndkcamera.h index 2b211336..42d45f75 100644 --- a/app/src/main/cpp/camera2/ndkcamera.h +++ b/app/src/main/cpp/camera2/ndkcamera.h @@ -38,7 +38,7 @@ static const uint64_t kMaxExposureTime = static_cast(250000000); #define WAIT_AWB_LOCKED 2 #define WAIT_AF_LOCKED 4 -#define EXPECTED_CAPTURE_IDX 0 +// #define EXPECTED_CAPTURE_IDX 0 #define EXPECTED_CAPTURE_IDX 1 class CameraManager diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index f5fadff3..acd9e1d1 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -436,7 +436,7 @@ public class MicroPhotoService extends Service { File rawFile = new File(path); String pathsStr = String.join("\t", paths); - mService.burstCaptureFinished(mService.mNativeHandle, result, numberOfCaptures, pathsStr, videoId); + mService.burstCaptureFinished(mService.mNativeHandle, result, numberOfCaptures, pathsStr, frontCamera, orientation, videoId); for (String p : paths) { try { File f = new File(p); @@ -1324,7 +1324,7 @@ cellSignalStrengthGsm.getDbm(); protected native boolean uninit(long handler); protected native void recordingFinished(long handler, boolean photoOrVideo, boolean result, String path, long videoId); protected native void captureFinished(long handler, boolean photoOrVideo, boolean result, Bitmap bm, long videoId); - protected native void burstCaptureFinished(long handler, boolean result, int numberOfCaptures, String pathsJoinedByTab, 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 void releaseDeviceHandle(long deviceHandle); public static native boolean sendExternalPhoto(long deviceHandle, String path); diff --git a/app/src/main/java/com/xypower/mpapp/video/RawActivity.java b/app/src/main/java/com/xypower/mpapp/video/RawActivity.java index e067ec39..11b0d5ac 100644 --- a/app/src/main/java/com/xypower/mpapp/video/RawActivity.java +++ b/app/src/main/java/com/xypower/mpapp/video/RawActivity.java @@ -620,6 +620,12 @@ public class RawActivity extends AppCompatActivity { mRawResultQueue.remove(requestId); finishedCaptureLocked(); } + + if (mRequestIds.isEmpty()) { + finish(); + } else { + broadcastPhotoFile(false, ""); + } // showToast("Capture failed!"); } diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java index ff92754a..56d738f7 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java @@ -201,6 +201,7 @@ public class MpMasterService extends Service { mMpAppVersion = packageInfo == null ? "" : packageInfo.versionName; mPreviousMpHbTime = System.currentTimeMillis(); + mTimeToStartMpApp = mPreviousMpHbTime; buildChargingBatteryVoltage(System.currentTimeMillis()); @@ -368,7 +369,7 @@ public class MpMasterService extends Service { final Context context = getApplicationContext(); long ts = System.currentTimeMillis(); - if (ts - mPreviousMpHbTime > mMpHeartbeatDuration * 2) { + if (mPreviousMpHbTime <= ts && ts - mPreviousMpHbTime > mMpHeartbeatDuration * 2) { // MpApp is not running if (ts - mTimeToStartMpApp >= 30000) { MicroPhotoContext.restartMpApp(context);