From cdd0fcc361fd02b2164985dab17f4f83d5ffd9ba Mon Sep 17 00:00:00 2001 From: "XI.CHEN" <2311041011@qq.com> Date: Mon, 10 Mar 2025 20:27:41 +0800 Subject: [PATCH 01/33] Update version to 1.3.64 Based Core Version to 1.4.35 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 852dca67..e5143c3e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ plugins { // 10,00,000 major-minor-build def AppMajorVersion = 1 def AppMinorVersion = 3 -def AppBuildNumber = 63 +def AppBuildNumber = 64 def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber From 87f9559cfd4ec2f64ad34765ba9552e050599329 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Mar 2025 11:05:05 +0800 Subject: [PATCH 02/33] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/PhoneDevice.h b/app/src/main/cpp/PhoneDevice.h index 3c696365..50c1be77 100644 --- a/app/src/main/cpp/PhoneDevice.h +++ b/app/src/main/cpp/PhoneDevice.h @@ -231,6 +231,8 @@ public: virtual uint64_t RequestWakelock(uint64_t timeout); virtual bool ReleaseWakelock(uint64_t wakelock); + virtual std::string GetVersion() const; + virtual int GetWData(WEATHER_INFO *weatherInfo, D_SENSOR_PARAM *sensorParam); virtual int GetIceData(ICE_INFO *iceInfo, ICE_TAIL *icetail, D_SENSOR_PARAM *sensorParam); virtual bool OpenSensors(int sensortype); @@ -267,7 +269,7 @@ public: protected: std::string GetFileName() const; - std::string GetVersion() const; + bool SendBroadcastMessage(std::string action, int value); // bool MatchCaptureSizeRequest(ACameraManager *cameraManager, const char *selectedCameraId, unsigned int width, unsigned int height, uint32_t cameraOrientation_, From 55a01c47b60ff81e2471445ac8e15248330adcbf Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Mar 2025 11:46:26 +0800 Subject: [PATCH 03/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/SensorsProtocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/cpp/SensorsProtocol.h b/app/src/main/cpp/SensorsProtocol.h index 06ddc11c..433f8e4f 100644 --- a/app/src/main/cpp/SensorsProtocol.h +++ b/app/src/main/cpp/SensorsProtocol.h @@ -106,7 +106,7 @@ #define D_OPEN_MODULE_POWER 0x0009000C /* 打开机芯电源(1 有效)*/ /* 摄像机下发命令宏定义*/ -#define TAKE_PHOTO 0 /* 拍照*/ +#define TAKE_PHOTO 10 /* 拍照*/ #define SET_BAUD 10000 /* 设置球机波特率*/ #define STOP_CMD 10005 /* 取消或停止指令*/ #define AUTO_SCAN 10006 /* 自动扫描功能控制(1/0 打开/关闭该功能)*/ From b996c663a93684b5d76b32234d1dbda41f7b7cf7 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Mar 2025 11:48:44 +0800 Subject: [PATCH 04/33] Update version to 1.3.65 Based Core Version to 1.4.36 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index e5143c3e..35b8499f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ plugins { // 10,00,000 major-minor-build def AppMajorVersion = 1 def AppMinorVersion = 3 -def AppBuildNumber = 64 +def AppBuildNumber = 65 def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber From b6e58239d3c93fd896b493f4100add30f34d2252 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Mar 2025 12:46:50 +0800 Subject: [PATCH 05/33] Update version to 1.3.66 Based Core Version to 1.4.37 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 35b8499f..1588ec59 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ plugins { // 10,00,000 major-minor-build def AppMajorVersion = 1 def AppMinorVersion = 3 -def AppBuildNumber = 65 +def AppBuildNumber = 66 def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber From 341045651c3e9a2edd5efbd000c88bd88fe2e04a Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Mar 2025 15:31:39 +0800 Subject: [PATCH 06/33] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 50 ++++++++++++++++++++++++--------- app/src/main/cpp/CMakeLists.txt | 15 ++++++---- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1588ec59..a38b75a2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,7 +39,6 @@ android { cppFlags '-std=c++17 -fexceptions -Wno-error=format-security -fopenmp' // cppFlags '-std=c++17 -Wno-error=format-security' // arguments "-DANDROID_STL=c++_shared" - arguments "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot abiFilters 'arm64-v8a', 'armeabi-v7a' // setAbiFilters(['arm64-v8a']) } @@ -75,15 +74,34 @@ android { } } - splits { - boolean isReleaseTask = gradle.startParameter.taskNames.any { it.contains("Release") } - // enabled on release build - abi { - enable isReleaseTask - reset() - include "armeabi-v7a", "arm64-v8a" - // include "arm64-v8a" - universalApk false + flavorDimensions "apps" + productFlavors { + N938 { + dimension = "apps" + externalNativeBuild { + cmake { + arguments "-DUSING_N938=1", "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot + abiFilters "armeabi-v7a" + } + } + } + RP { + dimension = "apps" + externalNativeBuild { + cmake { + arguments "-DUSING_PLZ=1", "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot + abiFilters "arm64-v8a" + } + } + } + WP { + dimension = "apps" + externalNativeBuild { + cmake { + arguments "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot + abiFilters "arm64-v8a" + } + } } } @@ -91,15 +109,19 @@ android { variant.outputs.all { output -> if (outputFileName.endsWith('.apk')) { def buildTypeFlag = "dbg" + def flavor = variant.flavorName def prevFileName = "mpapp" + def buildType = variant.buildType if(variant.buildType.name.equals('release')) { buildTypeFlag = "rel" } - def abi = output.getFilter(com.android.build.OutputFile.ABI) - if (abi == null) abi = "all" - if (abi.contains("v7a")) prevFileName = "N938" - def fileName = "${prevFileName}_v${defaultConfig.versionName}_${buildTypeFlag}_${new Date(System.currentTimeMillis()).format("yyyyMMdd")}_${abi}.apk" + if (flavor.equals("N938")) prevFileName = "N938" + else if (flavor.equals("RP")) prevFileName = "rpapp" + def fileName = "${prevFileName}_v${defaultConfig.versionName}_${buildTypeFlag}_${new Date(System.currentTimeMillis()).format("yyyyMMdd")}.apk" + def outputDir = new File("${project.buildDir}/${buildType}") outputFileName = fileName + + // variant.getPackageApplication().outputDirectory = outputDir // new File(project.rootDir.absolutePath + "/app/build/") } } } diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 9d18a0af..59b29b0e 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -17,12 +17,15 @@ set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") add_definitions(-DUSING_ETHERNET) -if(ANDROID_ABI STREQUAL "armeabi-v7a") - add_definitions(-DUSING_N938) -elseif(ANDROID_ABI STREQUAL "arm64-v8a") - # add_definitions(-DUSING_N938) - add_definitions(-DUSING_PLZ) -endif() +# USING_N938 defined in gradle +# USING_PLZ defined in gradle + +#if(ANDROID_ABI STREQUAL "armeabi-v7a") +# add_definitions(-DUSING_N938) +#elseif(ANDROID_ABI STREQUAL "arm64-v8a") +# # add_definitions(-DUSING_N938) +# # add_definitions(-DUSING_PLZ) +#endif() # OUTPUT_DBG_INFO: 输出调试相关信息 add_definitions(-DOUTPUT_DBG_INFO) From 2167afa1d83f40756a06a2a7423673291febcedb Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Mar 2025 15:55:26 +0800 Subject: [PATCH 07/33] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/xypower/mpapp/MicroPhotoService.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index b26a5d06..15ea34cf 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -162,8 +162,6 @@ public class MicroPhotoService extends Service { private ServiceHandler mHander = null; private Messenger mMessenger = null; - private static AtomicInteger mPendingIntentFeed = new AtomicInteger(); - private String mModelName = null; public static boolean isRunning = false; @@ -1527,7 +1525,7 @@ public class MicroPhotoService extends Service { Intent intent = new Intent(); intent.setAction(ACTION_GPS_TIMEOUT); - mPreviousGpsTimer = PendingIntent.getBroadcast(this, mPendingIntentFeed.getAndIncrement(), intent, 0); + mPreviousGpsTimer = PendingIntent.getBroadcast(this, BROADCAST_REQUEST_CODE_GPS, intent, 0); alarmManager.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + mGpsTimeout, mPreviousGpsTimer); } catch (Exception ex) { From 9eafc3d2f3f045ffec7680c7879498cbace3b8d2 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Mar 2025 16:17:26 +0800 Subject: [PATCH 08/33] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E6=89=A7=E8=A1=8C=EF=BC=8C=E5=88=99=E8=B7=B3?= =?UTF-8?q?=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/GPIOControl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/cpp/GPIOControl.cpp b/app/src/main/cpp/GPIOControl.cpp index db90c2e9..d4b053ac 100644 --- a/app/src/main/cpp/GPIOControl.cpp +++ b/app/src/main/cpp/GPIOControl.cpp @@ -496,6 +496,10 @@ void GpioControl::PowerControlThreadProc() bool GpioControl::Startup() { + if (m_thread.joinable()) + { + return true; + } // if (m_thread.) m_exitSignal = false; m_thread = std::thread(PowerControlThreadProc); From d908a36d3b21a9cfd411b74fb929ee007cb67b1c Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Mar 2025 16:27:00 +0800 Subject: [PATCH 09/33] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a38b75a2..be415186 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -76,12 +76,12 @@ android { flavorDimensions "apps" productFlavors { - N938 { + WP { dimension = "apps" externalNativeBuild { cmake { - arguments "-DUSING_N938=1", "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot - abiFilters "armeabi-v7a" + arguments "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot + abiFilters "arm64-v8a" } } } @@ -94,12 +94,12 @@ android { } } } - WP { + N938 { dimension = "apps" externalNativeBuild { cmake { - arguments "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot - abiFilters "arm64-v8a" + arguments "-DUSING_N938=1", "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot + abiFilters "armeabi-v7a" } } } From 127b06de779d21ff6ebf8259643d08cb0325a698 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Mar 2025 20:03:49 +0800 Subject: [PATCH 10/33] =?UTF-8?q?=E8=B0=83=E6=95=B4APP=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/MicroPhoto.cpp | 12 ++++++++++++ .../main/java/com/xypower/mpapp/MainActivity.java | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/MicroPhoto.cpp b/app/src/main/cpp/MicroPhoto.cpp index 97dbe010..7c717ca7 100644 --- a/app/src/main/cpp/MicroPhoto.cpp +++ b/app/src/main/cpp/MicroPhoto.cpp @@ -1421,3 +1421,15 @@ Java_com_xypower_mpapp_MicroPhotoService_releasePowerControl( return JNI_TRUE; } + +extern "C" +JNIEXPORT jint JNICALL +Java_com_xypower_mpapp_MainActivity_getCustomAppId(JNIEnv *env, jobject thiz) { +#ifdef USING_N938 + return 2; +#elif defined(USING_PLZ) + return 1; +#else + return 0; +#endif +} \ No newline at end of file diff --git a/app/src/main/java/com/xypower/mpapp/MainActivity.java b/app/src/main/java/com/xypower/mpapp/MainActivity.java index 5fa35cc0..47b94a97 100644 --- a/app/src/main/java/com/xypower/mpapp/MainActivity.java +++ b/app/src/main/java/com/xypower/mpapp/MainActivity.java @@ -72,7 +72,18 @@ public class MainActivity extends AppCompatActivity { Date date = new Date(BuildConfig.BUILD_TIMESTAMP); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - String caption = actionBar.getTitle().toString() + " v" + MicroPhotoContext.getVersionName(getApplicationContext()) + " " + sdf.format(date); + String caption = "MP"; + switch (getCustomAppId()) { + case 1: + caption = "RP"; + break; + case 2: + caption = "N938"; + break; + default: + break; + } + caption += " v" + MicroPhotoContext.getVersionName(getApplicationContext()) + " " + sdf.format(date); sdf = new SimpleDateFormat("MM-dd HH:mm"); caption += " / " + sdf.format(new Date()); actionBar.setTitle(caption); @@ -629,4 +640,6 @@ public class MainActivity extends AppCompatActivity { } + private native int getCustomAppId(); + } \ No newline at end of file From 1bdc190a1bb11d33a175f7408e3b6336227c4f56 Mon Sep 17 00:00:00 2001 From: "XI.CHEN" <2311041011@qq.com> Date: Tue, 11 Mar 2025 21:13:21 +0800 Subject: [PATCH 11/33] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=8B=8D=E7=85=A7?= =?UTF-8?q?=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/SensorsProtocol.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/cpp/SensorsProtocol.h b/app/src/main/cpp/SensorsProtocol.h index 433f8e4f..7a5b648b 100644 --- a/app/src/main/cpp/SensorsProtocol.h +++ b/app/src/main/cpp/SensorsProtocol.h @@ -106,7 +106,7 @@ #define D_OPEN_MODULE_POWER 0x0009000C /* 打开机芯电源(1 有效)*/ /* 摄像机下发命令宏定义*/ -#define TAKE_PHOTO 10 /* 拍照*/ +#define TAKE_PHOTO 0 /* 拍照*/ #define SET_BAUD 10000 /* 设置球机波特率*/ #define STOP_CMD 10005 /* 取消或停止指令*/ #define AUTO_SCAN 10006 /* 自动扫描功能控制(1/0 打开/关闭该功能)*/ From a34e66c7ff370f293381e0ace0ac1e3bf0519837 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Mar 2025 21:41:41 +0800 Subject: [PATCH 12/33] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=EF=BC=8C=E9=81=BF=E5=85=8D=E5=A4=A7=E6=96=87=E4=BB=B6=E5=B4=A9?= =?UTF-8?q?=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/xypower/common/FileUploader.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/xypower/common/FileUploader.java b/common/src/main/java/com/xypower/common/FileUploader.java index 1e5343ae..e647eb21 100644 --- a/common/src/main/java/com/xypower/common/FileUploader.java +++ b/common/src/main/java/com/xypower/common/FileUploader.java @@ -6,6 +6,7 @@ import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -92,8 +93,22 @@ public class FileUploader { } request.writeBytes(this.CRLF); - byte[] bytes = Files.readAllBytes(uploadFile.toPath()); - request.write(bytes); + FileInputStream fis = null; + try { + fis = new FileInputStream(uploadFile); + int bufferSize = 1024; + byte[] buffer = new byte[bufferSize]; + int length = -1; + while ((length = fis.read(buffer)) != -1) { + request.write(buffer, 0, length); + } + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + FilesUtils.closeFriendly(fis); + } + // byte[] bytes = Files.readAllBytes(uploadFile.toPath()); + // request.write(bytes); } /** From 4de7693aaa88b63da6480b5b0b7525a3d46231f5 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Mar 2025 22:20:22 +0800 Subject: [PATCH 13/33] =?UTF-8?q?Revert=20"=E8=B0=83=E6=95=B4=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit d908a36d3b21a9cfd411b74fb929ee007cb67b1c. --- app/build.gradle | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index be415186..a38b75a2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -76,12 +76,12 @@ android { flavorDimensions "apps" productFlavors { - WP { + N938 { dimension = "apps" externalNativeBuild { cmake { - arguments "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot - abiFilters "arm64-v8a" + arguments "-DUSING_N938=1", "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot + abiFilters "armeabi-v7a" } } } @@ -94,12 +94,12 @@ android { } } } - N938 { + WP { dimension = "apps" externalNativeBuild { cmake { - arguments "-DUSING_N938=1", "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot - abiFilters "armeabi-v7a" + arguments "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot + abiFilters "arm64-v8a" } } } From df1fc220d1c9a5be3c9858d0596888fea79b67d1 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Mar 2025 22:20:31 +0800 Subject: [PATCH 14/33] =?UTF-8?q?Revert=20"=E8=B0=83=E6=95=B4=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E8=84=9A=E6=9C=AC"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 341045651c3e9a2edd5efbd000c88bd88fe2e04a. --- app/build.gradle | 50 +++++++++------------------------ app/src/main/cpp/CMakeLists.txt | 15 ++++------ 2 files changed, 20 insertions(+), 45 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a38b75a2..1588ec59 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,6 +39,7 @@ android { cppFlags '-std=c++17 -fexceptions -Wno-error=format-security -fopenmp' // cppFlags '-std=c++17 -Wno-error=format-security' // arguments "-DANDROID_STL=c++_shared" + arguments "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot abiFilters 'arm64-v8a', 'armeabi-v7a' // setAbiFilters(['arm64-v8a']) } @@ -74,34 +75,15 @@ android { } } - flavorDimensions "apps" - productFlavors { - N938 { - dimension = "apps" - externalNativeBuild { - cmake { - arguments "-DUSING_N938=1", "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot - abiFilters "armeabi-v7a" - } - } - } - RP { - dimension = "apps" - externalNativeBuild { - cmake { - arguments "-DUSING_PLZ=1", "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot - abiFilters "arm64-v8a" - } - } - } - WP { - dimension = "apps" - externalNativeBuild { - cmake { - arguments "-DNCNN_DISABLE_EXCEPTION=OFF", "-DTERM_CORE_ROOT=" + coreroot, "-DOpenCV_DIR=" + opencvsdk + "/sdk/native/jni", "-DHDRPLUS_ROOT=" + hdrplusroot, "-DNCNN_ROOT=" + ncnnroot, "-DHALIDE_ROOT=" + halideroot - abiFilters "arm64-v8a" - } - } + splits { + boolean isReleaseTask = gradle.startParameter.taskNames.any { it.contains("Release") } + // enabled on release build + abi { + enable isReleaseTask + reset() + include "armeabi-v7a", "arm64-v8a" + // include "arm64-v8a" + universalApk false } } @@ -109,19 +91,15 @@ android { variant.outputs.all { output -> if (outputFileName.endsWith('.apk')) { def buildTypeFlag = "dbg" - def flavor = variant.flavorName def prevFileName = "mpapp" - def buildType = variant.buildType if(variant.buildType.name.equals('release')) { buildTypeFlag = "rel" } - if (flavor.equals("N938")) prevFileName = "N938" - else if (flavor.equals("RP")) prevFileName = "rpapp" - def fileName = "${prevFileName}_v${defaultConfig.versionName}_${buildTypeFlag}_${new Date(System.currentTimeMillis()).format("yyyyMMdd")}.apk" - def outputDir = new File("${project.buildDir}/${buildType}") + def abi = output.getFilter(com.android.build.OutputFile.ABI) + if (abi == null) abi = "all" + if (abi.contains("v7a")) prevFileName = "N938" + def fileName = "${prevFileName}_v${defaultConfig.versionName}_${buildTypeFlag}_${new Date(System.currentTimeMillis()).format("yyyyMMdd")}_${abi}.apk" outputFileName = fileName - - // variant.getPackageApplication().outputDirectory = outputDir // new File(project.rootDir.absolutePath + "/app/build/") } } } diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 59b29b0e..9d18a0af 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -17,15 +17,12 @@ set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") add_definitions(-DUSING_ETHERNET) -# USING_N938 defined in gradle -# USING_PLZ defined in gradle - -#if(ANDROID_ABI STREQUAL "armeabi-v7a") -# add_definitions(-DUSING_N938) -#elseif(ANDROID_ABI STREQUAL "arm64-v8a") -# # add_definitions(-DUSING_N938) -# # add_definitions(-DUSING_PLZ) -#endif() +if(ANDROID_ABI STREQUAL "armeabi-v7a") + add_definitions(-DUSING_N938) +elseif(ANDROID_ABI STREQUAL "arm64-v8a") + # add_definitions(-DUSING_N938) + add_definitions(-DUSING_PLZ) +endif() # OUTPUT_DBG_INFO: 输出调试相关信息 add_definitions(-DOUTPUT_DBG_INFO) From bbb78f44b976977fecff90ab47c1bbf5ad97c150 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Mar 2025 22:43:16 +0800 Subject: [PATCH 15/33] =?UTF-8?q?=E8=B0=83=E6=95=B4APP=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/xypower/mpapp/MainActivity.java | 4 ++-- app/src/main/java/com/xypower/mpapp/MicroPhotoService.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/xypower/mpapp/MainActivity.java b/app/src/main/java/com/xypower/mpapp/MainActivity.java index 47b94a97..009dc428 100644 --- a/app/src/main/java/com/xypower/mpapp/MainActivity.java +++ b/app/src/main/java/com/xypower/mpapp/MainActivity.java @@ -73,7 +73,7 @@ public class MainActivity extends AppCompatActivity { Date date = new Date(BuildConfig.BUILD_TIMESTAMP); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String caption = "MP"; - switch (getCustomAppId()) { + switch (MicroPhotoService.getCustomAppId()) { case 1: caption = "RP"; break; @@ -640,6 +640,6 @@ public class MainActivity extends AppCompatActivity { } - private native int getCustomAppId(); + } \ No newline at end of file diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index 15ea34cf..87bd2016 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -1681,6 +1681,8 @@ cellSignalStrengthGsm.getDbm(); public static native long requestPowerControl(int type); public static native boolean releasePowerControl(long powerControlHandle); + public static native int getCustomAppId(); + ////////////////////////GPS//////////////////// // private static final String GPS_LOCATION_NAME = android.location.LocationManager.GPS_PROVIDER; private LocationManager mLocationManager; From c912c7057240049abeeb06d5a007097475176c21 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Mar 2025 22:43:28 +0800 Subject: [PATCH 16/33] =?UTF-8?q?=E8=B0=83=E6=95=B4APP=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/MicroPhoto.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/cpp/MicroPhoto.cpp b/app/src/main/cpp/MicroPhoto.cpp index 7c717ca7..a7f1a29c 100644 --- a/app/src/main/cpp/MicroPhoto.cpp +++ b/app/src/main/cpp/MicroPhoto.cpp @@ -1424,7 +1424,7 @@ Java_com_xypower_mpapp_MicroPhotoService_releasePowerControl( extern "C" JNIEXPORT jint JNICALL -Java_com_xypower_mpapp_MainActivity_getCustomAppId(JNIEnv *env, jobject thiz) { +Java_com_xypower_mpapp_MicroPhotoService_getCustomAppId(JNIEnv *env, jobject thiz) { #ifdef USING_N938 return 2; #elif defined(USING_PLZ) From d9f6c6e8acb665a21e6e3e7d0a6fa99dce3060ee Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 12 Mar 2025 10:56:08 +0800 Subject: [PATCH 17/33] Update version to 1.3.70 Based Core Version to 1.4.38 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 1588ec59..489eae03 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ plugins { // 10,00,000 major-minor-build def AppMajorVersion = 1 def AppMinorVersion = 3 -def AppBuildNumber = 66 +def AppBuildNumber = 70 def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber From 79e8a8ff712723c034fec8fe974415424d309720 Mon Sep 17 00:00:00 2001 From: "XI.CHEN" <2311041011@qq.com> Date: Wed, 12 Mar 2025 11:38:15 +0800 Subject: [PATCH 18/33] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BF=A1=E5=8F=B7?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 9939c964..f4021b17 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -4097,6 +4097,7 @@ void CPhoneDevice::UpdateSignalLevel(int signalLevel) { m_signalLevel = signalLevel; m_signalLevelUpdateTime = time(NULL); + XYLOG(XYLOG_SEVERITY_DEBUG, "Signal Level Updated: %d", signalLevel); } void CPhoneDevice::UpdateSimcard(const std::string& simcard) From b82fe124d8360f97442e43d5dd4372f2906743a6 Mon Sep 17 00:00:00 2001 From: huangfeng Date: Wed, 12 Mar 2025 11:48:55 +0800 Subject: [PATCH 19/33] =?UTF-8?q?perf:=20=E8=B0=83=E6=95=B4registerHeartbe?= =?UTF-8?q?atTimer=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xypower/mpmaster/MpMasterService.java | 93 +++++++++---------- 1 file changed, 46 insertions(+), 47 deletions(-) diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java index da06972b..bc85bb0f 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java @@ -50,6 +50,7 @@ import java.lang.reflect.Method; import java.nio.channels.FileLock; import java.text.SimpleDateFormat; import java.util.Arrays; +import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.logging.Level; @@ -764,67 +765,65 @@ public class MpMasterService extends Service { } private void registerHeartbeatTimer() { - - long timeout = mHeartbeatDuration; + long delaySec = 20; // 比i1延迟20秒 + long interval = mHeartbeatDuration; // 距离下一次间隔,默认10分钟 boolean keepAlive = false; - long currentTimeMs = System.currentTimeMillis(); + long currentSec = System.currentTimeMillis() / 1000; + if (mMntnMode) { + // 无延迟 + delaySec = 0; if (mQuickHbMode) { - timeout = mQuickHeartbeatDuration; + interval = mQuickHeartbeatDuration; } - registerHeartbeatTimer(currentTimeMs + timeout * 1000, keepAlive); + registerHeartbeatTimer((currentSec + interval + delaySec) * 1000, keepAlive); } else { - long closestTime = -1; if (mUsingAbsHbTime) { - Date dt = new Date(); - long ts = dt.getTime(); - ts -= ts % 1000; - - dt.setHours(0); - dt.setMinutes(0); - dt.setSeconds(0); - - long zeroPoint = dt.getTime(); - zeroPoint -= zeroPoint % 1000; - long offsetTs = (ts - zeroPoint) / 1000; - - if (mAbsHeartbeatTimes != null && mAbsHeartbeatTimes.length > 0) { - - for (int i = 0; i < mAbsHeartbeatTimes.length; i++) { - if (mAbsHeartbeatTimes[i] > offsetTs) { - closestTime = mAbsHeartbeatTimes[i]; - break; - } - } - - if (closestTime == -1) { - // next day - closestTime = mAbsHeartbeatTimes[0] + 86400; - } - } else { - closestTime = 9 * 3600 + 13 * 60; - if (offsetTs > closestTime) { - closestTime += 86400; - } - } - - if (zeroPoint + closestTime * 1000 > currentTimeMs + mMpHeartbeatDuration) { + long expandSec = 120; // 扩展2分钟之内的都触发 + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MILLISECOND, 0); + long todayZero = calendar.getTimeInMillis() / 1000; + long todaySec = currentSec - todayZero; + + long nextAbsSec = this.getNextAbsSec(todaySec); + if (nextAbsSec - todaySec > interval + expandSec) { keepAlive = true; - registerHeartbeatTimer(currentTimeMs + mMpHeartbeatDuration + 5000, keepAlive); + registerHeartbeatTimer((currentSec + interval + delaySec) * 1000, keepAlive); } else { - registerHeartbeatTimer(zeroPoint + closestTime * 1000, keepAlive); + registerHeartbeatTimer((todayZero + nextAbsSec) * 1000, keepAlive); } } else { - // mUsingAbsHbTime: false - if ((mPreviousHeartbeatTime != 0) && (mPreviousHeartbeatTime - currentTimeMs < mHeartbeatDuration * 1000)) { - registerHeartbeatTimer(mPreviousHeartbeatTime + mHeartbeatDuration * 1000, keepAlive); - } else { - registerHeartbeatTimer(currentTimeMs + timeout * 1000, keepAlive); - } + // mUsingAbsHbTime=false,间隔10分钟 + 延迟 + registerHeartbeatTimer((currentSec + interval + delaySec) * 1000, keepAlive); } } } + private long getNextAbsSec(long todaySec) { + long nextAbsSec = -1; + if (mAbsHeartbeatTimes != null && mAbsHeartbeatTimes.length > 0) { + for (int i = 0; i < mAbsHeartbeatTimes.length; i++) { + if (mAbsHeartbeatTimes[i] > todaySec) { + nextAbsSec = mAbsHeartbeatTimes[i]; + break; + } + } + + if (nextAbsSec == -1) { + // next day + nextAbsSec = mAbsHeartbeatTimes[0] + 24 * 3600; + } + } else { + nextAbsSec = 9 * 3600 + 13 * 60; + if (todaySec > nextAbsSec) { + nextAbsSec += 24 * 3600; + } + } + return nextAbsSec; + } private void registerHeartbeatTimer(long triggerTime, boolean keepAlive) { AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); From d1298663f3979d9bcf5476e96b69db905b369698 Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 12 Mar 2025 20:57:27 +0800 Subject: [PATCH 20/33] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E7=9F=AD=E8=A7=86=E9=A2=91=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/CMakeLists.txt | 5 +- app/src/main/cpp/PhoneDevice.cpp | 90 +++++++++++------------ app/src/main/cpp/PhoneDevice.h | 3 + app/src/main/cpp/netcamera/HangYuCtrl.cpp | 87 ++++++++++++++++++++++ app/src/main/cpp/netcamera/HangYuCtrl.h | 28 +++++++ app/src/main/cpp/netcamera/VendorCtrl.cpp | 2 +- app/src/main/cpp/netcamera/VendorCtrl.h | 5 +- app/src/main/cpp/netcamera/YuShiCtrl.h | 1 + app/src/main/cpp/netcamera/httpclient.cpp | 7 +- app/src/main/cpp/netcamera/httpclient.h | 2 +- 10 files changed, 174 insertions(+), 56 deletions(-) create mode 100644 app/src/main/cpp/netcamera/HangYuCtrl.cpp create mode 100644 app/src/main/cpp/netcamera/HangYuCtrl.h diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 9d18a0af..36093aca 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -21,7 +21,7 @@ if(ANDROID_ABI STREQUAL "armeabi-v7a") add_definitions(-DUSING_N938) elseif(ANDROID_ABI STREQUAL "arm64-v8a") # add_definitions(-DUSING_N938) - add_definitions(-DUSING_PLZ) + # add_definitions(-DUSING_PLZ) endif() # OUTPUT_DBG_INFO: 输出调试相关信息 @@ -396,6 +396,9 @@ add_library( # Sets the name of the library. ncnn/yolov5ncnn.cpp netcamera/httpclient.cpp + netcamera/VendorCtrl.cpp + netcamera/YuShiCtrl.cpp + netcamera/HangYuCtrl.cpp ${STREAMING_SRCS} diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index f4021b17..8eabf34b 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -10,6 +10,10 @@ #include "PositionHelper.h" #include "DngCreator.h" +#include "netcamera/VendorCtrl.h" +#include "netcamera/YuShiCtrl.h" +#include "netcamera/HangYuCtrl.h" + #include "media/RTSPRecorder.h" #include @@ -1711,8 +1715,8 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c } XYLOG(XYLOG_SEVERITY_DEBUG, "Ethernet Power ON"); - // std::shared_ptr ethernetPowerCtrl = std::make_shared(1); - std::shared_ptr ethernetPowerCtrl; + std::shared_ptr ethernetPowerCtrl = std::make_shared(1); + // std::shared_ptr ethernetPowerCtrl; net_handle_t netHandle = GetEthnetHandle(); if (netHandle == 0) @@ -1747,64 +1751,31 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c // SetStaticIp(); std::this_thread::sleep_for(std::chrono::milliseconds(256)); - NET_PHOTO_INFO netPhotoInfo = { netHandle, 0 }; - if (localPhotoInfo.vendor == 1) - { - // Hai Kang - netPhotoInfo.authType = HTTP_AUTH_TYPE_DIGEST; - snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/ISAPI/Streaming/channels/1/picture?"); - } - else if (localPhotoInfo.vendor == 2) - { - // Hang Yu - strcpy(netPhotoInfo.url, "/cgi-bin/snapshot.cgi"); - } - else if (localPhotoInfo.vendor == 3) - { - // Yu Shi - netPhotoInfo.authType = HTTP_AUTH_TYPE_DIGEST; - int streamSid = 0; // should put into config - // rtsp://192.168.0.13:554/media/video1 - snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/media/video%u", (uint32_t)localPhotoInfo.cameraId); - // strcpy(netPhotoInfo.url, "rtsp://192.168.50.224/live/0"); - } - else if (localPhotoInfo.vendor == 5) - { - // Hang Yu - New - netPhotoInfo.authType = HTTP_AUTH_TYPE_BASIC; - // http://192.168.1.46/Snapshot/%u/RemoteImageCapture?ImageFormat=2&HorizontalPixel=1920&VerticalPixel=1080 - // http://192.168.1.101/Snapshot/1/2/RemoteImageCaptureV2?ImageFormat=jpg - // http://192.168.1.101/Snapshot/1/1/RemoteImageCaptureV2?ImageFormat=jpg - snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/Snapshot/%u/1/RemoteImageCaptureV2?ImageFormat=jpg", (uint32_t)localPhotoInfo.cameraId); - } - else + struct in_addr addr; + char ip[32] = { 0 }; + addr.s_addr = localPhotoInfo.ip; + strcpy(ip, inet_ntoa(addr)); + // strcpy(netPhotoInfo.outputPath, path.c_str()); + + VendorCtrl* vendorCtrl = MakeVendorCtrl(localPhotoInfo.vendor, localPhotoInfo.channel, ip, localPhotoInfo.userName, localPhotoInfo.password, netHandle); + if (vendorCtrl == NULL) { 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); TakePhotoCb(0, localPhotoInfo, "", 0); return false; } - struct in_addr addr; - addr.s_addr = localPhotoInfo.ip; - strcpy(netPhotoInfo.ip, inet_ntoa(addr)); - strcpy(netPhotoInfo.outputPath, path.c_str()); - if (!localPhotoInfo.userName.empty()) - { - size_t len = std::min(sizeof(netPhotoInfo.userName) - 1, localPhotoInfo.userName.size()); - strncpy(netPhotoInfo.userName, localPhotoInfo.userName.c_str(), len); - } - if (!localPhotoInfo.password.empty()) - { - size_t len = std::min(sizeof(netPhotoInfo.password) - 1, localPhotoInfo.password.size()); - strncpy(netPhotoInfo.password, localPhotoInfo.password.c_str(), len); - } + std::string streamingUrl = vendorCtrl->GetStreamingUrl(localPhotoInfo.channel); + + // strcpy(netPhotoInfo.outputPath, path.c_str()); + // strcpy(netPhotoInfo.interface, "eth0"); localPhotoInfo.photoTime = time(NULL); std::string tmpFile = m_appPath + (APP_PATH_TMP DIR_SEP_STR) + std::to_string(localPhotoInfo.photoId) + ".mp4"; // RTSPToMP4 dumper(netPhotoInfo.url, tmpFile.c_str(), localPhotoInfo.duration * 1000); // dumper.start(); - dumpRtspToMp4(netPhotoInfo.url, tmpFile.c_str(), localPhotoInfo.duration * 1000); + dumpRtspToMp4(streamingUrl.c_str(), tmpFile.c_str(), localPhotoInfo.duration * 1000); ethernetPowerCtrl.reset(); XYLOG(XYLOG_SEVERITY_DEBUG, "Ethernet Power OFF"); @@ -1820,7 +1791,7 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c { TakePhotoCb(0, localPhotoInfo, "", 0); XYLOG(XYLOG_SEVERITY_ERROR, "Failed to TP on NET Camera CH=%u PR=%X PHOTOID=%u URL=http://%s%s", (uint32_t)localPhotoInfo.channel, (uint32_t)localPhotoInfo.preset, - localPhotoInfo.photoId, netPhotoInfo.ip, netPhotoInfo.url); + localPhotoInfo.photoId, ip, streamingUrl.c_str()); } // Notify to take next photo // TakePhotoCb(1, localPhotoInfo, "", takingTime); @@ -4957,4 +4928,25 @@ void CPhoneDevice::SetStaticIp() #endif XYLOG(XYLOG_SEVERITY_WARNING, "No Static IP Confg"); } +} + +VendorCtrl* CPhoneDevice::MakeVendorCtrl(int vendor, uint8_t channel, const std::string& ip, const std::string& userName, const std::string& password, net_handle_t netHandle) +{ + VendorCtrl* vendorCtrl = NULL; + switch (vendor) + { + case 1: + // Hai Kang + break; + case 2: + break; + case 3: + // Yu Shi + vendorCtrl = new YuShiCtrl(ip, userName, password, channel, netHandle); + break; + case 5: + // Hang Yu - New + vendorCtrl = new HangYuCtrl(ip, userName, password, channel, netHandle); + } + return vendorCtrl; } \ No newline at end of file diff --git a/app/src/main/cpp/PhoneDevice.h b/app/src/main/cpp/PhoneDevice.h index 50c1be77..49033047 100644 --- a/app/src/main/cpp/PhoneDevice.h +++ b/app/src/main/cpp/PhoneDevice.h @@ -154,6 +154,7 @@ void MatToBitmap(JNIEnv *env, cv::Mat& mat, jobject& bitmap) { #endif class PowerControl; +class VendorCtrl; class CPhoneDevice : public IDevice { @@ -266,6 +267,8 @@ public: net_handle_t GetEthnetHandle() const; + VendorCtrl* MakeVendorCtrl(int vendor, uint8_t channel, const std::string& ip, const std::string& userName, const std::string& password, net_handle_t netHandle); + protected: std::string GetFileName() const; diff --git a/app/src/main/cpp/netcamera/HangYuCtrl.cpp b/app/src/main/cpp/netcamera/HangYuCtrl.cpp new file mode 100644 index 00000000..b40e6450 --- /dev/null +++ b/app/src/main/cpp/netcamera/HangYuCtrl.cpp @@ -0,0 +1,87 @@ +// +// Created by Matthew on 2025/3/4. +// + +#include "YuShiCtrl.h" +#include "httpclient.h" + +HangYuCtrl::~HangYuCtrl() +{ + +} + +bool HangYuCtrl::SetOsd() +{ + // /LAPI/V1.0/Channels//Media/OSDs/Contents +} + +void HangYuCtrl::EnableOsd(bool enable) +{ + return false; +} + +std::string HangYuCtrl::GetStreamingUrl(uint8_t channel) +{ + // /LAPI/V1.0/Channels//Media/Video/Streams//LiveStreamURL?TransType=&TransProtocol= + char url[128] = { 0 }; + snprintf(url, sizeof(url), "/Streams/%u/1/Transport", (uint32_t)channel); + + std::vector resData; + int res = DoPutRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, "", resData); + if (res != 0 || resData.empty()) + { + return ""; + } + + resData.push_back(0); + const char* start = strstr(&resData[0], ""); + if (start == NULL) + { + return ""; + } + start += 9; + const char* end = strstr(start, ""); + if (end == NULL) + { + return ""; + } + strncpy(url, start, end - start); + + return std::string(url); +} + +bool HangYuCtrl::UpdateTime(time_t ts) +{ + // /LAPI/V1.0/System/Time + + // + // + + std::string reqData = ""; + + std::string url = "http://" + m_ip + " /System/Time"; + std::vector resData; + int res = DoPutRequest(url.c_str(), HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, reqData.c_str(), resData); + + if (res != 0) + { + return false; + } + + return true; +} + +bool HangYuCtrl::TakePhoto(std::vector& img) +{ + return false; +} \ No newline at end of file diff --git a/app/src/main/cpp/netcamera/HangYuCtrl.h b/app/src/main/cpp/netcamera/HangYuCtrl.h new file mode 100644 index 00000000..3cb86ede --- /dev/null +++ b/app/src/main/cpp/netcamera/HangYuCtrl.h @@ -0,0 +1,28 @@ +// +// Created by Matthew on 2025/3/4. +// + +#ifndef __MICROPHOTO_HANGYUCTRL_H__ +#define __MICROPHOTO_HANGYUCTRL_H__ + +#include "VendorCtrl.h" + +class HangYuCtrl : public VendorCtrl +{ +public: + using VendorCtrl::VendorCtrl; + virtual ~HangYuCtrl(); + + virtual bool SetOsd(); + virtual void EnableOsd(bool enable); + virtual std::string GetStreamingUrl(uint8_t channel); + virtual bool UpdateTime(time_t ts); + virtual bool TakePhoto(std::vector& img); + virtual bool TakeVideo(uint32_t duration, std::string path); + +private: + +}; + + +#endif //__MICROPHOTO_HANGYUCTRL_H__ diff --git a/app/src/main/cpp/netcamera/VendorCtrl.cpp b/app/src/main/cpp/netcamera/VendorCtrl.cpp index 81f5d1c8..e89fa58e 100644 --- a/app/src/main/cpp/netcamera/VendorCtrl.cpp +++ b/app/src/main/cpp/netcamera/VendorCtrl.cpp @@ -4,7 +4,7 @@ #include "VendorCtrl.h" VendorCtrl::VendorCtrl(const std::string& ip, const std::string& userName, const std::string& password) : - m_ip(ip), m_userName(userName), m_password(password), m_channel(channel) + m_ip(ip), m_userName(userName), m_password(password), m_channel(channel), m_netHandle(netHandle) { } std::string VendorCtrl::CvtJSONToString(const Json::Value& data) diff --git a/app/src/main/cpp/netcamera/VendorCtrl.h b/app/src/main/cpp/netcamera/VendorCtrl.h index 66a18e4a..d12e80f8 100644 --- a/app/src/main/cpp/netcamera/VendorCtrl.h +++ b/app/src/main/cpp/netcamera/VendorCtrl.h @@ -7,10 +7,11 @@ #include #include +#include class VendorCtrl { public: - VendorCtrl(const std::string& ip, const std::string& userName, const std::string& password, uint8_t channel); + VendorCtrl(const std::string& ip, const std::string& userName, const std::string& password, uint8_t channel, net_handle_t netHandle); virtual ~VendorCtrl() = 0; virtual bool SetOsd() = 0; @@ -18,6 +19,7 @@ public: virtual std::string GetStreamingUrl(uint8_t channel) = 0; virtual bool UpdateTime(time_t ts) = 0; virtual bool TakePhoto(std::vector& img) = 0; + virtual bool TakeVideo(uint32_t duration, std::string path) = 0; protected: @@ -28,6 +30,7 @@ protected: std::string m_userName; std::string m_password; uint8_t m_channel; + net_handle_t m_netHandle; }; diff --git a/app/src/main/cpp/netcamera/YuShiCtrl.h b/app/src/main/cpp/netcamera/YuShiCtrl.h index d5da62ad..d0103ad1 100644 --- a/app/src/main/cpp/netcamera/YuShiCtrl.h +++ b/app/src/main/cpp/netcamera/YuShiCtrl.h @@ -18,6 +18,7 @@ public: virtual std::string GetStreamingUrl(uint8_t channel); virtual bool UpdateTime(time_t ts); virtual bool TakePhoto(std::vector& img); + virtual bool TakeVideo(uint32_t duration, std::string path); private: diff --git a/app/src/main/cpp/netcamera/httpclient.cpp b/app/src/main/cpp/netcamera/httpclient.cpp index 532b5353..6f4e4ac4 100644 --- a/app/src/main/cpp/netcamera/httpclient.cpp +++ b/app/src/main/cpp/netcamera/httpclient.cpp @@ -119,7 +119,7 @@ int DoGetRequest(const char* url, int authType, const char* userName, const char return ((0 == nRet) && (responseCode == 200)) ? 0 : 1; } -int DoPutRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, const char* contents, char* data) +int DoPutRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector& data) { std::string auth; @@ -239,10 +239,11 @@ int UniviewResolutionSet(const NET_PHOTO_INFO& photoInfo, int channel, unsigned Json::StreamWriterBuilder writer; std::string sendbuf = Json::writeString(writer, outdata); - char respContent[1024]; + std::vector respContent; DoPutRequest(path.c_str(), photoInfo.authType, photoInfo.userName, photoInfo.password, photoInfo.netHandle, sendbuf.c_str(), respContent); - XYLOG(XYLOG_SEVERITY_DEBUG, "Sendlen= %zu, respContent=%s", sendbuf.size(), respContent); + // respContent.push_back(0); + // XYLOG(XYLOG_SEVERITY_DEBUG, "Sendlen= %zu, respContent=%s", sendbuf.size(), (const char*)&respContent[0]); return 0; } diff --git a/app/src/main/cpp/netcamera/httpclient.h b/app/src/main/cpp/netcamera/httpclient.h index 496c8515..fe57564c 100644 --- a/app/src/main/cpp/netcamera/httpclient.h +++ b/app/src/main/cpp/netcamera/httpclient.h @@ -19,6 +19,6 @@ bool setIPAddress(const char *if_name, const char *ip_addr, const char *net_mask, const char *gateway_addr); int DoGetRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, std::vector& data); -int DoPutRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, const char* contents, char* data); +int DoPutRequest(const char* url, int authType, const char* userName, const char* password, net_handle_t netHandle, const char* contents, std::vector& data); #endif // __HTTP_CLIENT__ \ No newline at end of file From 6f56bf0fe36f862f58fe5a1c20e653fd52ceda87 Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 12 Mar 2025 21:00:27 +0800 Subject: [PATCH 21/33] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E7=9F=AD=E8=A7=86=E9=A2=91=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/CMakeLists.txt | 2 +- app/src/main/cpp/PhoneDevice.cpp | 91 +++++++++++++- app/src/main/cpp/PhoneDevice.h | 3 + app/src/main/cpp/media/RTSPRecorder.cpp | 44 ++++++- app/src/main/cpp/media/RTSPRecorder.h | 5 +- app/src/main/cpp/media/Streaming.cpp | 159 ++++++++++++++++++++++++ app/src/main/cpp/media/Streaming.h | 50 ++++++++ 7 files changed, 344 insertions(+), 10 deletions(-) create mode 100644 app/src/main/cpp/media/Streaming.cpp create mode 100644 app/src/main/cpp/media/Streaming.h diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 36093aca..9ecc18f2 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -154,7 +154,7 @@ add_definitions(-DDISABLE_RTTI) # include_directories( ${HDRPLUS_ROOT}/${ANDROID_ABI}/include/ZLToolKit/src/ ) # SET(ZLMEDIAKIT_LIBS ${ZLMEDIAKIT_LIBS} zlmediakit zltoolkit) -SET(STREAMING_SRCS media/RTSPToMP4.cpp media/RTSPRecorder.cpp ) +SET(STREAMING_SRCS media/RTSPToMP4.cpp media/RTSPRecorder.cpp media/Streaming.cpp ) SET(HDRPLUS_LIBS raw exiv2 exiv2-xmp expat lcms2 OpenMP::OpenMP_CXX) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 8eabf34b..f5de977c 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -9,6 +9,7 @@ #include "CvText.h" #include "PositionHelper.h" #include "DngCreator.h" +#include "media/Streaming.h" #include "netcamera/VendorCtrl.h" #include "netcamera/YuShiCtrl.h" @@ -1775,7 +1776,7 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c std::string tmpFile = m_appPath + (APP_PATH_TMP DIR_SEP_STR) + std::to_string(localPhotoInfo.photoId) + ".mp4"; // RTSPToMP4 dumper(netPhotoInfo.url, tmpFile.c_str(), localPhotoInfo.duration * 1000); // dumper.start(); - dumpRtspToMp4(streamingUrl.c_str(), tmpFile.c_str(), localPhotoInfo.duration * 1000); + dumpRtspToMp4(streamingUrl.c_str(), tmpFile.c_str(), localPhotoInfo.duration * 1000, GetEthnetHandle()); ethernetPowerCtrl.reset(); XYLOG(XYLOG_SEVERITY_DEBUG, "Ethernet Power OFF"); @@ -1803,8 +1804,92 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c return true; } -bool CPhoneDevice::StartPushStreaming(IDevice::PHOTO_INFO& localPhotoInfo, const std::string& url, std::vector& osds, std::shared_ptr powerCtrlPtr) +bool CPhoneDevice::StartPushStreaming(IDevice::PHOTO_INFO& photoInfo, const std::string& url, std::vector& osds, std::shared_ptr powerCtrlPtr) { +#if 0 + if (photoInfo.mediaType == XY_MEDIA_TYPE_STREAM) + { + std::map >::iterator it = m_streamings.find(photoInfo.channel); + if (it != m_streamings.end()) + { + it->second->stop(); + it->second.reset(); + m_streamings.erase(it); + } + + NET_PHOTO_INFO netPhotoInfo = { 0, 0 }; + if (photoInfo.vendor == 1) + { + // Hai Kang + netPhotoInfo.authType = HTTP_AUTH_TYPE_DIGEST; + snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/ISAPI/Streaming/channels/1/picture?"); + } + else if (photoInfo.vendor == 2) + { + // Hang Yu + strcpy(netPhotoInfo.url, "/cgi-bin/snapshot.cgi"); + } + else if (photoInfo.vendor == 3) + { + // Yu Shi + netPhotoInfo.authType = HTTP_AUTH_TYPE_DIGEST; + int streamSid = 0; // should put into config + // rtsp://192.168.0.13:554/media/video1 + snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/media/video%u", (uint32_t)photoInfo.cameraId); + // strcpy(netPhotoInfo.url, "rtsp://192.168.50.224/live/0"); + } + else if (photoInfo.vendor == 5) + { + // Hang Yu - New + netPhotoInfo.authType = HTTP_AUTH_TYPE_BASIC; + // http://192.168.1.46/Snapshot/%u/RemoteImageCapture?ImageFormat=2&HorizontalPixel=1920&VerticalPixel=1080 + // http://192.168.1.101/Snapshot/1/2/RemoteImageCaptureV2?ImageFormat=jpg + // http://192.168.1.101/Snapshot/1/1/RemoteImageCaptureV2?ImageFormat=jpg + snprintf(netPhotoInfo.url, sizeof(netPhotoInfo.url), "/Snapshot/%u/1/RemoteImageCaptureV2?ImageFormat=jpg", (uint32_t)photoInfo.cameraId); + } + else + { + XYLOG(XYLOG_SEVERITY_ERROR, "Vendor(%u) not Supported CH=%u PR=%X PHOTOID=%u", (uint32_t)photoInfo.vendor, (uint32_t)photoInfo.channel, (unsigned int)photoInfo.preset, photoInfo.photoId); + TakePhotoCb(0, photoInfo, "", 0); + return false; + } + + StreamForwarder* forwarder = new StreamForwarder(); + m_streamings[photoInfo.channel] = std::shared_ptr((Streaming*)forwarder); + // Initialize with RTSP input and RTMP output + if (!forwarder->initialize(std::string(netPhotoInfo.url), url)) { + std::cerr << "Failed to initialize stream forwarder" << std::endl; + return -1; + } + + // Optional: Set callback to process video frames +#if 0 + forwarder->setFrameCallback([](uint8_t* data, int linesize, int width, int height) { + // Process frame data here + // Example: Add OSD overlay + }); +#endif + + // Start forwarding + forwarder->start(); + + // Wait for user input to stop + // std::cout << "Press Enter to stop streaming..." << std::endl; + // std::cin.get(); + + // forwarder.stop(); + } + else if (photoInfo.mediaType == XY_MEDIA_TYPE_STREAM_OFF) + { + auto it = m_streamings.find(photoInfo.channel); + if (it != m_streamings.end()) + { + it->second->stop(); + it->second.reset(); + m_streamings.erase(it); + } + } +#endif return true; } @@ -4949,4 +5034,4 @@ VendorCtrl* CPhoneDevice::MakeVendorCtrl(int vendor, uint8_t channel, const std: vendorCtrl = new HangYuCtrl(ip, userName, password, channel, netHandle); } return vendorCtrl; -} \ No newline at end of file +} diff --git a/app/src/main/cpp/PhoneDevice.h b/app/src/main/cpp/PhoneDevice.h index 49033047..daced027 100644 --- a/app/src/main/cpp/PhoneDevice.h +++ b/app/src/main/cpp/PhoneDevice.h @@ -155,6 +155,7 @@ void MatToBitmap(JNIEnv *env, cv::Mat& mat, jobject& bitmap) { class PowerControl; class VendorCtrl; +class Streaming; class CPhoneDevice : public IDevice { @@ -425,6 +426,8 @@ protected: std::atomic m_collecting; unsigned long long localDelayTime; + std::map > m_streamings; + }; diff --git a/app/src/main/cpp/media/RTSPRecorder.cpp b/app/src/main/cpp/media/RTSPRecorder.cpp index 11edccfa..85cbf668 100644 --- a/app/src/main/cpp/media/RTSPRecorder.cpp +++ b/app/src/main/cpp/media/RTSPRecorder.cpp @@ -6,6 +6,7 @@ #include #include #include +#include extern "C" { #include #include @@ -21,15 +22,17 @@ extern "C" { #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__) -void dumpRtmpToMp4(const char* rtmpUrl, const char* outputPath, uint32_t duration) +void dumpRtmpToMp4(const char* rtmpUrl, const char* outputPath, uint32_t duration, net_handle_t netHandle) { AVFormatContext* inputFormatContext = nullptr; AVFormatContext* outputFormatContext = nullptr; AVPacket packet; + AVDictionary *options = NULL; av_register_all(); avformat_network_init(); + // Open input RTMP stream if (avformat_open_input(&inputFormatContext, rtmpUrl, nullptr, nullptr) != 0) { fprintf(stderr, "Could not open input file '%s'\n", rtmpUrl); @@ -126,28 +129,61 @@ void dumpRtmpToMp4(const char* rtmpUrl, const char* outputPath, uint32_t duratio } -void dumpRtspToMp4(const char* rtspUrl, const char* outputPath, uint32_t duration) +void dumpRtspToMp4(const char* rtspUrl, const char* outputPath, uint32_t duration, net_handle_t netHandle) { AVFormatContext* inputFormatContext = nullptr; AVFormatContext* outputFormatContext = nullptr; AVPacket packet; + AVDictionary *options = NULL; + int res = 0; av_register_all(); avformat_network_init(); + // Set RTSP transport protocol option before opening + av_dict_set(&options, "rtsp_transport", "tcp", 0); + + // Set custom socket options via protocol whitelist and options + inputFormatContext->protocol_whitelist = av_strdup("file,udp,rtp,tcp,rtsp"); + // Open input RTSP stream if (avformat_open_input(&inputFormatContext, rtspUrl, nullptr, nullptr) != 0) { - fprintf(stderr, "Could not open input file '%s'\n", rtspUrl); + // fprintf(stderr, "Could not open input file '%s'\n", rtspUrl); return; } // Retrieve input stream information if (avformat_find_stream_info(inputFormatContext, nullptr) < 0) { - fprintf(stderr, "Could not find stream information\n"); + // fprintf(stderr, "Could not find stream information\n"); avformat_close_input(&inputFormatContext); return; } + // Get socket file descriptor + if (NETWORK_UNSPECIFIED != netHandle) + { + int fd = -1; + if (inputFormatContext->pb) { + AVIOContext *io_ctx = inputFormatContext->pb; + // const char *url = io_ctx->filename; + + // You can access socket options using av_opt API + res = av_opt_get_int(io_ctx, "fd", AV_OPT_SEARCH_CHILDREN, (int64_t*)&fd); + if (res >= 0 && fd >= 0) { + // printf("Socket file descriptor: %d\n", fd); + + int res = android_setsocknetwork(netHandle, fd); + if (res == -1) + { + int errcode = errno; + // printf("android_setsocknetwork errno=%d", errcode); + // XYLOG(XYLOG_SEVERITY_ERROR,"setsocknetwork -1, errcode=%d",errcode); + } + } + } + } + + // Open output MP4 file if (avformat_alloc_output_context2(&outputFormatContext, nullptr, "mp4", outputPath) < 0) { fprintf(stderr, "Could not create output context\n"); diff --git a/app/src/main/cpp/media/RTSPRecorder.h b/app/src/main/cpp/media/RTSPRecorder.h index 1133c8e0..c406a43e 100644 --- a/app/src/main/cpp/media/RTSPRecorder.h +++ b/app/src/main/cpp/media/RTSPRecorder.h @@ -6,10 +6,11 @@ #define MICROPHOTO_RTSPRECORDER_H #include +#include // void dumpRtspToMp4(const std::string &rtspUrl, const std::string &outputPath, uint32_t durationInMs); -void dumpRtmpToMp4(const char* rtmpUrl, const char* outputPath, uint32_t duration); -void dumpRtspToMp4(const char* rtspUrl, const char* outputPath, uint32_t duration); +void dumpRtmpToMp4(const char* rtmpUrl, const char* outputPath, uint32_t duration, net_handle_t netHandle); +void dumpRtspToMp4(const char* rtspUrl, const char* outputPath, uint32_t duration, net_handle_t netHandle); class RTSPRecorder { diff --git a/app/src/main/cpp/media/Streaming.cpp b/app/src/main/cpp/media/Streaming.cpp new file mode 100644 index 00000000..a0bd9b3a --- /dev/null +++ b/app/src/main/cpp/media/Streaming.cpp @@ -0,0 +1,159 @@ +// +// Created by Matthew on 2025/3/11. +// + +#include "Streaming.h" + +#include +#include +#include +#include +#include + +#if 0 +StreamForwarder::~StreamForwarder() { + stop(); + if (inputCtx) { + avformat_close_input(&inputCtx); + } + if (outputCtx) { + if (outputCtx->pb) { + avio_closep(&outputCtx->pb); + } + avformat_free_context(outputCtx); + } +} + +bool StreamForwarder::initialize(const std::string& inputUrl, const std::string& outputUrl) { + if (!openInput(inputUrl)) { + return false; + } + + if (!openOutput(outputUrl)) { + return false; + } + + return true; +} + +bool StreamForwarder::openInput(const std::string& inputUrl) { + inputCtx = avformat_alloc_context(); + if (!inputCtx) { + return false; + } + + if (avformat_open_input(&inputCtx, inputUrl.c_str(), nullptr, nullptr) < 0) { + return false; + } + + if (avformat_find_stream_info(inputCtx, nullptr) < 0) { + return false; + } + + return true; +} + +bool StreamForwarder::openOutput(const std::string& outputUrl) { + int ret = avformat_alloc_output_context2(&outputCtx, nullptr, "flv", outputUrl.c_str()); + if (ret < 0) { + return false; + } + + // Copy streams from input to output + for (unsigned int i = 0; i < inputCtx->nb_streams; i++) { + AVStream* inStream = inputCtx->streams[i]; + AVStream* outStream = avformat_new_stream(outputCtx, inStream->codec->codec); + if (!outStream) { + return false; + } + + ret = avcodec_copy_context(outStream->codec, inStream->codec); + if (ret < 0) { + return false; + } + } + + // Open output file + if (!(outputCtx->oformat->flags & AVFMT_NOFILE)) { + ret = avio_open(&outputCtx->pb, outputUrl.c_str(), AVIO_FLAG_WRITE); + if (ret < 0) { + return false; + } + } + + // Write header + ret = avformat_write_header(outputCtx, nullptr); + if (ret < 0) { + return false; + } + + return true; +} + +void StreamForwarder::setFrameCallback(std::function callback) { + frameCallback = callback; +} + +void StreamForwarder::start() { + isRunning = true; + forwardPackets(); +} + +void StreamForwarder::stop() { + isRunning = false; +} + +void StreamForwarder::forwardPackets() { + AVPacket packet; + AVFrame* frame = av_frame_alloc(); + + while (isRunning) { + if (av_read_frame(inputCtx, &packet) < 0) { + break; + } + + // Process video frames if callback is set + if (frameCallback && packet.stream_index == 0) { // Assuming video is stream 0 + AVCodecContext* codecCtx = inputCtx->streams[packet.stream_index]->codec; + int ret = avcodec_send_packet(codecCtx, &packet); + if (ret < 0) { + continue; + } + + while (ret >= 0) { + ret = avcodec_receive_frame(codecCtx, frame); + if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { + break; + } else if (ret < 0) { + goto end; + } + + processFrame(frame); + } + } + + // Forward packet + av_packet_rescale_ts(&packet, + inputCtx->streams[packet.stream_index]->time_base, + outputCtx->streams[packet.stream_index]->time_base); + + int ret = av_interleaved_write_frame(outputCtx, &packet); + if (ret < 0) { + break; + } + + av_packet_unref(&packet); + } + + end: + av_frame_free(&frame); + av_write_trailer(outputCtx); +} + +void StreamForwarder::processFrame(AVFrame* frame) { + if (frameCallback) { + frameCallback(frame->data[0], frame->linesize[0], + frame->width, frame->height); + } +} +#endif \ No newline at end of file diff --git a/app/src/main/cpp/media/Streaming.h b/app/src/main/cpp/media/Streaming.h new file mode 100644 index 00000000..9819f40f --- /dev/null +++ b/app/src/main/cpp/media/Streaming.h @@ -0,0 +1,50 @@ +// +// Created by Matthew on 2025/3/11. +// + +#ifndef MICROPHOTO_STREAMING_H +#define MICROPHOTO_STREAMING_H + +#include +#include + +#include + +extern "C" { +#include +#include +#include +#include +} + +class Streaming +{ +public: + virtual ~Streaming() {} + virtual void start() {} + virtual void stop() {} +}; +#if 0 +class StreamForwarder : public Streaming +{ +private: + AVFormatContext* inputCtx = nullptr; + AVFormatContext* outputCtx = nullptr; + bool isRunning = false; + +public: + StreamForwarder() = default; + virtual ~StreamForwarder(); + + bool initialize(const std::string& inputUrl, const std::string& outputUrl); + virtual void start(); + virtual void stop(); + +private: + bool openInput(const std::string& inputUrl); + bool openOutput(const std::string& outputUrl); + void forwardPackets(); +}; +#endif + +#endif //MICROPHOTO_STREAMING_H From 53578065f1240a8f921d8f2b439787d4d9427b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=9B=A6?= Date: Wed, 12 Mar 2025 21:44:00 +0800 Subject: [PATCH 22/33] =?UTF-8?q?=E8=A6=86=E5=86=B0=E6=B0=94=E8=B1=A1?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E9=98=9F=E5=88=97=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/CMakeLists.txt | 1 + app/src/main/cpp/DataController.cpp | 112 ++++++++++++++++++++++++++++ app/src/main/cpp/DataController.h | 77 +++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 app/src/main/cpp/DataController.cpp create mode 100644 app/src/main/cpp/DataController.h diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index 9ecc18f2..cb634f48 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -392,6 +392,7 @@ add_library( # Sets the name of the library. #WeatherComm.cpp SensorsProtocol.cpp SerialComm.cpp + DataController.cpp ncnn/yolov5ncnn.cpp diff --git a/app/src/main/cpp/DataController.cpp b/app/src/main/cpp/DataController.cpp new file mode 100644 index 00000000..8afa9593 --- /dev/null +++ b/app/src/main/cpp/DataController.cpp @@ -0,0 +1,112 @@ +// +// Created by shxy on 2025/3/12. +// + +#include "DataController.h" + +DataController::DataController(CTerminal* pTerminal) :m_pTerminal(pTerminal), m_exit(false){} + +void DataController::Startup() +{ + m_thread = std::thread(DataThreadProc, this); +} + +void DataController::DataThreadProc(DataController* pThis) +{ + pThis->DataProc(); +} +void DataController::AddSendData(unsigned char frameType, unsigned char packetType, time_t timestamp,const vector &data) +{ + DATA_INFO predata = {0}; + predata.frameType = frameType; + predata.packetType = packetType; + predata.data = data; + + m_locker.lock(); + m_datas.push_back(predata); + m_locker.unlock(); + + m_sem.release(); +} + +bool DataController::WaitForResponse(unsigned char frameNo, unsigned char packetType, int sec) +{ + auto startTime = std::chrono::steady_clock::now(); + while (true) + { + { + std::lock_guard lock(m_responseLocker); + if (m_receivedresp.frameNo == frameNo && m_receivedresp.packetType == packetType) + { + m_receivedresp.frameNo = 0; + m_receivedresp.packetType = 0; + return true; + } + } + + auto currentTime = std::chrono::steady_clock::now(); + auto elapsed = std::chrono::duration_cast(currentTime - startTime).count(); + if (elapsed >= sec) + { + return false; + } + + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + +} + +void DataController::OnResponseReceived(unsigned char frameNo, unsigned char packetType) +{ + std::lock_guard lock(m_responseLocker); + m_receivedresp.frameNo = frameNo; + m_receivedresp.packetType = packetType; +} + +void DataController::DataProc() +{ + bool hasData; + DATA_INFO datasend; + string hispath = m_pTerminal->m_appPath + APP_DATA_DIR + "/" + APP_FILE_NAME_HIS_DB; + while(true) { + m_sem.acquire(); + + if (m_exit) { + break; + } + + hasData = false; + + m_locker.lock(); + if (!m_datas.empty()) + { + datasend = m_datas.front(); + m_datas.pop_front(); + hasData = true; + } + m_locker.unlock(); + + if (hasData) { + bool success = false; + for (int retry = 0; retry < 3; retry++) + { + unsigned char frameNo = 0; + m_pTerminal->DataSendTo(datasend.frameType, datasend.packetType, datasend.data, &frameNo); + + if (WaitForResponse(frameNo, datasend.packetType, 8)) + { + success = true; + UpdateHistoryStatus(hispath, datasend.packetType, datasend.timestamp); + break; + } + } + + if (!success) + { + std::lock_guard lock(m_locker); + m_datas.push_back(datasend); + } + } + + } +} \ No newline at end of file diff --git a/app/src/main/cpp/DataController.h b/app/src/main/cpp/DataController.h new file mode 100644 index 00000000..f6c23010 --- /dev/null +++ b/app/src/main/cpp/DataController.h @@ -0,0 +1,77 @@ +// +// Created by shxy on 2025/3/12. +// + +#ifndef MICROPHOTO_DATACONTROLLER_H +#define MICROPHOTO_DATACONTROLLER_H + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct DATA_INFO +{ + unsigned char frameNo; + unsigned char frameType; + unsigned char packetType; + time_t timestamp; + vector data; +}; + +struct DATA_RESP +{ + unsigned char frameNo; + unsigned char packetType; +}; + +class CTerminal; +class DataController { +public: + DataController(CTerminal *pTerminal); + ~DataController() + { + m_exit = true; + m_sem.release(); + if (m_thread.joinable()) { + m_thread.join(); + } + } + + void Startup(); + void AddSendData(unsigned char frameType, unsigned char packetType, time_t timestamp, const vector &data); + void OnResponseReceived(unsigned char frameNo, unsigned char packetType); + + + +protected: + static void DataThreadProc(DataController* pThis); + void DataProc(); + bool WaitForResponse(unsigned char frameNo, unsigned char packetType, int sec); + + + +protected: + + +protected: + std::mutex m_locker; + std::mutex m_responseLocker; + CSemaphore m_sem; + std::deque m_datas; + bool m_exit; + DATA_RESP m_receivedresp = {0,0}; + std::thread m_thread; + + CTerminal* m_pTerminal; +}; + + +#endif //MICROPHOTO_DATACONTROLLER_H From ee93791683169b029761c7ce6fa3c85214e8cf13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=9B=A6?= Date: Wed, 12 Mar 2025 21:44:18 +0800 Subject: [PATCH 23/33] =?UTF-8?q?=E8=A6=86=E5=86=B0=E6=B0=94=E8=B1=A1?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/CMakeLists.txt | 2 +- app/src/main/cpp/DataController.cpp | 112 ---------------------------- app/src/main/cpp/DataController.h | 77 ------------------- 3 files changed, 1 insertion(+), 190 deletions(-) delete mode 100644 app/src/main/cpp/DataController.cpp delete mode 100644 app/src/main/cpp/DataController.h diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index cb634f48..6ffc05ee 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -392,7 +392,6 @@ add_library( # Sets the name of the library. #WeatherComm.cpp SensorsProtocol.cpp SerialComm.cpp - DataController.cpp ncnn/yolov5ncnn.cpp @@ -449,6 +448,7 @@ add_library( # Sets the name of the library. ${TERM_CORE_ROOT}/Client/UpgradeReceiver.cpp ${TERM_CORE_ROOT}/Client/Database.cpp ${TERM_CORE_ROOT}/Client/SimulatorDevice.cpp + ${TERM_CORE_ROOT}/Client/DataController.cpp ) diff --git a/app/src/main/cpp/DataController.cpp b/app/src/main/cpp/DataController.cpp deleted file mode 100644 index 8afa9593..00000000 --- a/app/src/main/cpp/DataController.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// -// Created by shxy on 2025/3/12. -// - -#include "DataController.h" - -DataController::DataController(CTerminal* pTerminal) :m_pTerminal(pTerminal), m_exit(false){} - -void DataController::Startup() -{ - m_thread = std::thread(DataThreadProc, this); -} - -void DataController::DataThreadProc(DataController* pThis) -{ - pThis->DataProc(); -} -void DataController::AddSendData(unsigned char frameType, unsigned char packetType, time_t timestamp,const vector &data) -{ - DATA_INFO predata = {0}; - predata.frameType = frameType; - predata.packetType = packetType; - predata.data = data; - - m_locker.lock(); - m_datas.push_back(predata); - m_locker.unlock(); - - m_sem.release(); -} - -bool DataController::WaitForResponse(unsigned char frameNo, unsigned char packetType, int sec) -{ - auto startTime = std::chrono::steady_clock::now(); - while (true) - { - { - std::lock_guard lock(m_responseLocker); - if (m_receivedresp.frameNo == frameNo && m_receivedresp.packetType == packetType) - { - m_receivedresp.frameNo = 0; - m_receivedresp.packetType = 0; - return true; - } - } - - auto currentTime = std::chrono::steady_clock::now(); - auto elapsed = std::chrono::duration_cast(currentTime - startTime).count(); - if (elapsed >= sec) - { - return false; - } - - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - -} - -void DataController::OnResponseReceived(unsigned char frameNo, unsigned char packetType) -{ - std::lock_guard lock(m_responseLocker); - m_receivedresp.frameNo = frameNo; - m_receivedresp.packetType = packetType; -} - -void DataController::DataProc() -{ - bool hasData; - DATA_INFO datasend; - string hispath = m_pTerminal->m_appPath + APP_DATA_DIR + "/" + APP_FILE_NAME_HIS_DB; - while(true) { - m_sem.acquire(); - - if (m_exit) { - break; - } - - hasData = false; - - m_locker.lock(); - if (!m_datas.empty()) - { - datasend = m_datas.front(); - m_datas.pop_front(); - hasData = true; - } - m_locker.unlock(); - - if (hasData) { - bool success = false; - for (int retry = 0; retry < 3; retry++) - { - unsigned char frameNo = 0; - m_pTerminal->DataSendTo(datasend.frameType, datasend.packetType, datasend.data, &frameNo); - - if (WaitForResponse(frameNo, datasend.packetType, 8)) - { - success = true; - UpdateHistoryStatus(hispath, datasend.packetType, datasend.timestamp); - break; - } - } - - if (!success) - { - std::lock_guard lock(m_locker); - m_datas.push_back(datasend); - } - } - - } -} \ No newline at end of file diff --git a/app/src/main/cpp/DataController.h b/app/src/main/cpp/DataController.h deleted file mode 100644 index f6c23010..00000000 --- a/app/src/main/cpp/DataController.h +++ /dev/null @@ -1,77 +0,0 @@ -// -// Created by shxy on 2025/3/12. -// - -#ifndef MICROPHOTO_DATACONTROLLER_H -#define MICROPHOTO_DATACONTROLLER_H - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct DATA_INFO -{ - unsigned char frameNo; - unsigned char frameType; - unsigned char packetType; - time_t timestamp; - vector data; -}; - -struct DATA_RESP -{ - unsigned char frameNo; - unsigned char packetType; -}; - -class CTerminal; -class DataController { -public: - DataController(CTerminal *pTerminal); - ~DataController() - { - m_exit = true; - m_sem.release(); - if (m_thread.joinable()) { - m_thread.join(); - } - } - - void Startup(); - void AddSendData(unsigned char frameType, unsigned char packetType, time_t timestamp, const vector &data); - void OnResponseReceived(unsigned char frameNo, unsigned char packetType); - - - -protected: - static void DataThreadProc(DataController* pThis); - void DataProc(); - bool WaitForResponse(unsigned char frameNo, unsigned char packetType, int sec); - - - -protected: - - -protected: - std::mutex m_locker; - std::mutex m_responseLocker; - CSemaphore m_sem; - std::deque m_datas; - bool m_exit; - DATA_RESP m_receivedresp = {0,0}; - std::thread m_thread; - - CTerminal* m_pTerminal; -}; - - -#endif //MICROPHOTO_DATACONTROLLER_H From d206a59d9af8c96554f58843c73e0bfaaa3456bf Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 12 Mar 2025 22:10:18 +0800 Subject: [PATCH 24/33] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/netcamera/HangYuCtrl.cpp | 14 +++++++++++--- app/src/main/cpp/netcamera/VendorCtrl.cpp | 2 +- app/src/main/cpp/netcamera/VendorCtrl.h | 2 +- app/src/main/cpp/netcamera/YuShiCtrl.cpp | 13 +++++++++---- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/src/main/cpp/netcamera/HangYuCtrl.cpp b/app/src/main/cpp/netcamera/HangYuCtrl.cpp index b40e6450..bb779b2d 100644 --- a/app/src/main/cpp/netcamera/HangYuCtrl.cpp +++ b/app/src/main/cpp/netcamera/HangYuCtrl.cpp @@ -2,9 +2,12 @@ // Created by Matthew on 2025/3/4. // -#include "YuShiCtrl.h" +#include "HangYuCtrl.h" +#include "netcamera.h" #include "httpclient.h" +#include + HangYuCtrl::~HangYuCtrl() { @@ -17,7 +20,7 @@ bool HangYuCtrl::SetOsd() void HangYuCtrl::EnableOsd(bool enable) { - return false; + // return false; } std::string HangYuCtrl::GetStreamingUrl(uint8_t channel) @@ -35,7 +38,7 @@ std::string HangYuCtrl::GetStreamingUrl(uint8_t channel) } resData.push_back(0); - const char* start = strstr(&resData[0], ""); + const char* start = strstr((const char*)&resData[0], ""); if (start == NULL) { return ""; @@ -84,4 +87,9 @@ bool HangYuCtrl::UpdateTime(time_t ts) bool HangYuCtrl::TakePhoto(std::vector& img) { return false; +} + +bool HangYuCtrl::TakeVideo(uint32_t duration, std::string path) +{ + } \ No newline at end of file diff --git a/app/src/main/cpp/netcamera/VendorCtrl.cpp b/app/src/main/cpp/netcamera/VendorCtrl.cpp index e89fa58e..96ee7913 100644 --- a/app/src/main/cpp/netcamera/VendorCtrl.cpp +++ b/app/src/main/cpp/netcamera/VendorCtrl.cpp @@ -3,7 +3,7 @@ // #include "VendorCtrl.h" -VendorCtrl::VendorCtrl(const std::string& ip, const std::string& userName, const std::string& password) : +VendorCtrl::VendorCtrl(const std::string& ip, const std::string& userName, const std::string& password, uint8_t channel, net_handle_t netHandle) : m_ip(ip), m_userName(userName), m_password(password), m_channel(channel), m_netHandle(netHandle) { } diff --git a/app/src/main/cpp/netcamera/VendorCtrl.h b/app/src/main/cpp/netcamera/VendorCtrl.h index d12e80f8..faf4b7ae 100644 --- a/app/src/main/cpp/netcamera/VendorCtrl.h +++ b/app/src/main/cpp/netcamera/VendorCtrl.h @@ -12,7 +12,7 @@ class VendorCtrl { public: VendorCtrl(const std::string& ip, const std::string& userName, const std::string& password, uint8_t channel, net_handle_t netHandle); - virtual ~VendorCtrl() = 0; + virtual ~VendorCtrl() {} virtual bool SetOsd() = 0; virtual void EnableOsd(bool enable) = 0; diff --git a/app/src/main/cpp/netcamera/YuShiCtrl.cpp b/app/src/main/cpp/netcamera/YuShiCtrl.cpp index 9c51f8f0..24eeacf7 100644 --- a/app/src/main/cpp/netcamera/YuShiCtrl.cpp +++ b/app/src/main/cpp/netcamera/YuShiCtrl.cpp @@ -17,10 +17,10 @@ bool YuShiCtrl::SetOsd() void YuShiCtrl::EnableOsd(bool enable) { - return false; + // return false; } -std::string GetStreamingUrl(uint8_t channel) +std::string YuShiCtrl::GetStreamingUrl(uint8_t channel) { // /LAPI/V1.0/Channels//Media/Video/Streams//LiveStreamURL?TransType=&TransProtocol= @@ -29,12 +29,12 @@ std::string GetStreamingUrl(uint8_t channel) bool YuShiCtrl::UpdateTime(time_t ts) { - /LAPI/V1.0/System/Time + // /LAPI/V1.0/System/Time Json::Value jsonData(Json::objectValue); jsonData["TimeZone"] = "GMT+08:00"; - jsonData["DeviceTime"] = ts; + jsonData["DeviceTime"] = (int64_t)ts; jsonData["DateFormat"] = 0; // YYYY-MM-DD jsonData["HourFormat"] = 1; // 24H @@ -44,4 +44,9 @@ bool YuShiCtrl::UpdateTime(time_t ts) bool YuShiCtrl::TakePhoto(std::vector& img) { return false; +} + +bool YuShiCtrl::TakeVideo(uint32_t duration, std::string path) +{ + } \ No newline at end of file From fd84d84157bf3296a3314bb4ac0e45c2b382d092 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 13 Mar 2025 09:32:26 +0800 Subject: [PATCH 25/33] =?UTF-8?q?=E8=B0=83=E6=95=B4Toast=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/xypower/mpapp/MicroPhotoService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index 87bd2016..62a6c1ef 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -56,6 +56,7 @@ import android.telephony.TelephonyManager; import android.text.TextUtils; import android.text.format.DateFormat; import android.util.Log; +import android.view.Gravity; import android.widget.RemoteViews; import android.widget.Toast; @@ -1238,7 +1239,9 @@ public class MicroPhotoService extends Service { new Runnable() { public void run() { // Log.d(TAG, "Bluetooth Low Energy device is connected!!"); - Toast.makeText(getApplicationContext(), "MP Connected!", Toast.LENGTH_SHORT).show(); + Toast toast = Toast.makeText(getApplicationContext(), "MP Connected!", Toast.LENGTH_SHORT); + toast.setGravity(Gravity.TOP, 0, 0); + toast.show(); mStateService = STATE_SERVICE.CONNECTED; startForeground(NOTIFICATION_ID_FOREGROUND_SERVICE, prepareNotification()); } From 02663dd08b5cb1bec8fd40233a774ddda7eae9d6 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 13 Mar 2025 09:32:48 +0800 Subject: [PATCH 26/33] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/netcamera/HangYuCtrl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/cpp/netcamera/HangYuCtrl.cpp b/app/src/main/cpp/netcamera/HangYuCtrl.cpp index bb779b2d..e91467ca 100644 --- a/app/src/main/cpp/netcamera/HangYuCtrl.cpp +++ b/app/src/main/cpp/netcamera/HangYuCtrl.cpp @@ -31,7 +31,7 @@ std::string HangYuCtrl::GetStreamingUrl(uint8_t channel) snprintf(url, sizeof(url), "/Streams/%u/1/Transport", (uint32_t)channel); std::vector resData; - int res = DoPutRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, "", resData); + int res = DoGetRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, resData); if (res != 0 || resData.empty()) { return ""; From 5c7f6abb713a98cff9f26b51b67be85f0afb54b3 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 13 Mar 2025 10:07:46 +0800 Subject: [PATCH 27/33] Update MpMaster version to 1.1.9 --- mpmaster/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpmaster/build.gradle b/mpmaster/build.gradle index a816e021..5dbc9298 100644 --- a/mpmaster/build.gradle +++ b/mpmaster/build.gradle @@ -4,7 +4,7 @@ plugins { def AppMajorVersion = 1 def AppMinorVersion = 1 -def AppBuildNumber = 8 +def AppBuildNumber = 9 def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber From 4ba4be427e4f09c73bd37cf1333abecc12c3f042 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 13 Mar 2025 10:13:34 +0800 Subject: [PATCH 28/33] =?UTF-8?q?=E8=88=AA=E7=85=9C=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 8 +++++++- app/src/main/cpp/netcamera/HangYuCtrl.cpp | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index f5de977c..ce492feb 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -1766,8 +1766,14 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c return false; } - std::string streamingUrl = vendorCtrl->GetStreamingUrl(localPhotoInfo.channel); + std::string streamingUrl = vendorCtrl->GetStreamingUrl(localPhotoInfo.cameraId); + if (streamingUrl.empty()) + { + XYLOG(XYLOG_SEVERITY_ERROR, "Invalid Streaming URL CH=%u PR=%X PHOTOID=%u", (uint32_t)localPhotoInfo.channel, (unsigned int)localPhotoInfo.preset, localPhotoInfo.photoId); + TakePhotoCb(0, localPhotoInfo, "", 0); + return false; + } // strcpy(netPhotoInfo.outputPath, path.c_str()); // strcpy(netPhotoInfo.interface, "eth0"); diff --git a/app/src/main/cpp/netcamera/HangYuCtrl.cpp b/app/src/main/cpp/netcamera/HangYuCtrl.cpp index e91467ca..66200efd 100644 --- a/app/src/main/cpp/netcamera/HangYuCtrl.cpp +++ b/app/src/main/cpp/netcamera/HangYuCtrl.cpp @@ -28,9 +28,10 @@ std::string HangYuCtrl::GetStreamingUrl(uint8_t channel) // /LAPI/V1.0/Channels//Media/Video/Streams//LiveStreamURL?TransType=&TransProtocol= char url[128] = { 0 }; - snprintf(url, sizeof(url), "/Streams/%u/1/Transport", (uint32_t)channel); + snprintf(url, sizeof(url), "http://%s/Streams/%u/1/Transport", m_ip.c_str(), (uint32_t)channel); std::vector resData; + int res = DoGetRequest(url, HTTP_AUTH_TYPE_BASIC, m_userName.c_str(), m_password.c_str(), m_netHandle, resData); if (res != 0 || resData.empty()) { @@ -49,9 +50,8 @@ std::string HangYuCtrl::GetStreamingUrl(uint8_t channel) { return ""; } - strncpy(url, start, end - start); - return std::string(url); + return std::string(start, end); } bool HangYuCtrl::UpdateTime(time_t ts) From 3a8ef64e2fe8d8e4c0887ed9d428d3c4d58898c7 Mon Sep 17 00:00:00 2001 From: huangfeng Date: Thu, 13 Mar 2025 11:27:55 +0800 Subject: [PATCH 29/33] =?UTF-8?q?Revert=20"perf:=20=E8=B0=83=E6=95=B4regis?= =?UTF-8?q?terHeartbeatTimer=E6=96=B9=E6=B3=95"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b82fe124d8360f97442e43d5dd4372f2906743a6. --- .../com/xypower/mpmaster/MpMasterService.java | 93 ++++++++++--------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java index bc85bb0f..da06972b 100644 --- a/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java +++ b/mpmaster/src/main/java/com/xypower/mpmaster/MpMasterService.java @@ -50,7 +50,6 @@ import java.lang.reflect.Method; import java.nio.channels.FileLock; import java.text.SimpleDateFormat; import java.util.Arrays; -import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.logging.Level; @@ -765,65 +764,67 @@ public class MpMasterService extends Service { } private void registerHeartbeatTimer() { - long delaySec = 20; // 比i1延迟20秒 - long interval = mHeartbeatDuration; // 距离下一次间隔,默认10分钟 - boolean keepAlive = false; - long currentSec = System.currentTimeMillis() / 1000; + long timeout = mHeartbeatDuration; + boolean keepAlive = false; + long currentTimeMs = System.currentTimeMillis(); if (mMntnMode) { - // 无延迟 - delaySec = 0; if (mQuickHbMode) { - interval = mQuickHeartbeatDuration; + timeout = mQuickHeartbeatDuration; } - registerHeartbeatTimer((currentSec + interval + delaySec) * 1000, keepAlive); + registerHeartbeatTimer(currentTimeMs + timeout * 1000, keepAlive); } else { + long closestTime = -1; if (mUsingAbsHbTime) { - long expandSec = 120; // 扩展2分钟之内的都触发 - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.HOUR_OF_DAY, 0); - calendar.set(Calendar.MINUTE, 0); - calendar.set(Calendar.SECOND, 0); - calendar.set(Calendar.MILLISECOND, 0); - long todayZero = calendar.getTimeInMillis() / 1000; - long todaySec = currentSec - todayZero; - - long nextAbsSec = this.getNextAbsSec(todaySec); - if (nextAbsSec - todaySec > interval + expandSec) { + Date dt = new Date(); + long ts = dt.getTime(); + ts -= ts % 1000; + + dt.setHours(0); + dt.setMinutes(0); + dt.setSeconds(0); + + long zeroPoint = dt.getTime(); + zeroPoint -= zeroPoint % 1000; + long offsetTs = (ts - zeroPoint) / 1000; + + if (mAbsHeartbeatTimes != null && mAbsHeartbeatTimes.length > 0) { + + for (int i = 0; i < mAbsHeartbeatTimes.length; i++) { + if (mAbsHeartbeatTimes[i] > offsetTs) { + closestTime = mAbsHeartbeatTimes[i]; + break; + } + } + + if (closestTime == -1) { + // next day + closestTime = mAbsHeartbeatTimes[0] + 86400; + } + } else { + closestTime = 9 * 3600 + 13 * 60; + if (offsetTs > closestTime) { + closestTime += 86400; + } + } + + if (zeroPoint + closestTime * 1000 > currentTimeMs + mMpHeartbeatDuration) { keepAlive = true; - registerHeartbeatTimer((currentSec + interval + delaySec) * 1000, keepAlive); + registerHeartbeatTimer(currentTimeMs + mMpHeartbeatDuration + 5000, keepAlive); } else { - registerHeartbeatTimer((todayZero + nextAbsSec) * 1000, keepAlive); + registerHeartbeatTimer(zeroPoint + closestTime * 1000, keepAlive); } } else { - // mUsingAbsHbTime=false,间隔10分钟 + 延迟 - registerHeartbeatTimer((currentSec + interval + delaySec) * 1000, keepAlive); - } - } - } - - private long getNextAbsSec(long todaySec) { - long nextAbsSec = -1; - if (mAbsHeartbeatTimes != null && mAbsHeartbeatTimes.length > 0) { - for (int i = 0; i < mAbsHeartbeatTimes.length; i++) { - if (mAbsHeartbeatTimes[i] > todaySec) { - nextAbsSec = mAbsHeartbeatTimes[i]; - break; + // mUsingAbsHbTime: false + if ((mPreviousHeartbeatTime != 0) && (mPreviousHeartbeatTime - currentTimeMs < mHeartbeatDuration * 1000)) { + registerHeartbeatTimer(mPreviousHeartbeatTime + mHeartbeatDuration * 1000, keepAlive); + } else { + registerHeartbeatTimer(currentTimeMs + timeout * 1000, keepAlive); } } - - if (nextAbsSec == -1) { - // next day - nextAbsSec = mAbsHeartbeatTimes[0] + 24 * 3600; - } - } else { - nextAbsSec = 9 * 3600 + 13 * 60; - if (todaySec > nextAbsSec) { - nextAbsSec += 24 * 3600; - } } - return nextAbsSec; } + private void registerHeartbeatTimer(long triggerTime, boolean keepAlive) { AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); From 5734762c07f4d026ce935c3d90c647a0c9ff889f Mon Sep 17 00:00:00 2001 From: "XI.CHEN" <2311041011@qq.com> Date: Thu, 13 Mar 2025 11:30:20 +0800 Subject: [PATCH 30/33] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=B2=E5=8F=A3?= =?UTF-8?q?=E6=8B=8D=E7=85=A7=E6=8C=87=E4=BB=A4=E5=AE=8F=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 2 +- app/src/main/cpp/SensorsProtocol.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index ce492feb..bfc0e992 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -2099,7 +2099,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< std::this_thread::sleep_for(std::chrono::seconds(5)); } - CameraPhotoCmd(ts, localPhotoInfo.channel, 0, localPhotoInfo.resolution, localPhotoInfo.preset, param.serfile, param.baud, param.addr); + CameraPhotoCmd(ts, localPhotoInfo.channel, TAKE_PHOTO, localPhotoInfo.resolution, localPhotoInfo.preset, param.serfile, param.baud, param.addr); XYLOG(XYLOG_SEVERITY_INFO, "Taking photo over"); if(localPhotoInfo.scheduleTime == 0) { diff --git a/app/src/main/cpp/SensorsProtocol.h b/app/src/main/cpp/SensorsProtocol.h index 7a5b648b..034e2985 100644 --- a/app/src/main/cpp/SensorsProtocol.h +++ b/app/src/main/cpp/SensorsProtocol.h @@ -106,7 +106,7 @@ #define D_OPEN_MODULE_POWER 0x0009000C /* 打开机芯电源(1 有效)*/ /* 摄像机下发命令宏定义*/ -#define TAKE_PHOTO 0 /* 拍照*/ +#define TAKE_PHOTO 20000 /* 拍照*/ #define SET_BAUD 10000 /* 设置球机波特率*/ #define STOP_CMD 10005 /* 取消或停止指令*/ #define AUTO_SCAN 10006 /* 自动扫描功能控制(1/0 打开/关闭该功能)*/ From 216a053086272d6733b0e0fa7b420736ac19a77d Mon Sep 17 00:00:00 2001 From: "XI.CHEN" <2311041011@qq.com> Date: Thu, 13 Mar 2025 11:31:14 +0800 Subject: [PATCH 31/33] Update version to 1.3.71 Based Core Version to 1.4.39 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 489eae03..ff17f1e0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ plugins { // 10,00,000 major-minor-build def AppMajorVersion = 1 def AppMinorVersion = 3 -def AppBuildNumber = 70 +def AppBuildNumber = 71 def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber From 89fe772caa9781ef969082fe58180510c1417ea7 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 13 Mar 2025 11:34:42 +0800 Subject: [PATCH 32/33] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E4=B8=8B=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E6=8B=8D=E7=85=A7=E6=97=B6=E9=97=B4=E4=BB=A5=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E6=8B=8D=E7=85=A7=E6=97=B6=E9=97=B4=E4=B8=BA=E5=8F=82?= =?UTF-8?q?=E8=80=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 避免系统提早触发闹钟 --- app/src/main/java/com/xypower/mpapp/MicroPhotoService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index 62a6c1ef..efa9d299 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -530,8 +530,7 @@ public class MicroPhotoService extends Service { } // Register Next Photo Timer - Date date = new Date(); - long startTime = (date.getTime() + 999) / 1000 + 1; // Add one second + long startTime = (ts == 0) ? (((new Date()).getTime() + 999) / 1000 + 1) : (ts + 1); // Add one second mService.updateCaptureSchedule(startTime); } else if (TextUtils.equals(ACTION_HEARTBEAT_MANUALLY, action)) { Log.i(TAG, "HB Timer Fired ACTION=" + action); From a14c76c4eddc436b10683d23630387abd35e787f Mon Sep 17 00:00:00 2001 From: "XI.CHEN" <2311041011@qq.com> Date: Thu, 13 Mar 2025 11:37:58 +0800 Subject: [PATCH 33/33] Update version to 1.3.72 Based Core Version to 1.4.39 --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index ff17f1e0..1b0869e2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ plugins { // 10,00,000 major-minor-build def AppMajorVersion = 1 def AppMinorVersion = 3 -def AppBuildNumber = 71 +def AppBuildNumber = 72 def AppVersionName = AppMajorVersion + "." + AppMinorVersion + "." + AppBuildNumber def AppVersionCode = AppMajorVersion * 100000 + AppMinorVersion * 1000 + AppBuildNumber