From 160f93b95602412ccdabe7fc6cf285a7777e1965 Mon Sep 17 00:00:00 2001
From: Dana <Dana_Lee1016@126.com>
Date: 星期三, 24 十二月 2025 15:43:01 +0800
Subject: [PATCH] 新增 useTFCard 字段与 setUseTFCard,由两处服务在创建编码器时传入配置。H264EncodeService、H264EncodeService2 均调用了该 setter。 在创建新文件前(非 TF 卡模式)调用 ensureInternalFlashSpaceForH264;若清理后仍不足 800MB,停止文件输出并返回失败,不再在写帧时重复检查。 保留 TF 卡目录的清理逻辑,仅针对 TF 卡路径。
---
app/src/main/java/com/anyun/h264/H264Encoder.java | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/app/src/main/java/com/anyun/h264/H264Encoder.java b/app/src/main/java/com/anyun/h264/H264Encoder.java
index c5b9bae..bdceadb 100644
--- a/app/src/main/java/com/anyun/h264/H264Encoder.java
+++ b/app/src/main/java/com/anyun/h264/H264Encoder.java
@@ -88,6 +88,7 @@
// Context 鍜屾竻鐞嗛厤缃�
private Context context; // Context 瀵硅薄锛岀敤浜庢竻鐞� TF 鍗℃枃浠�
private long maxH264TotalSizeGB = 100; // 鏈�澶� H264 鏂囦欢鎬诲ぇ灏忥紙GB锛夛紝榛樿 100GB
+ private boolean useTFCard = false; // 鏄惁浣跨敤 TF 鍗¤緭鍑�
// 缃戠粶浼犺緭鎺у埗
private boolean enableNetworkTransmission = true; // 鏄惁鍚敤TCP/UDP缃戠粶浼犺緭
@@ -174,6 +175,13 @@
*/
public void setContext(Context context) {
this.context = context;
+ }
+
+ /**
+ * 璁剧疆鏄惁浣跨敤 TF 鍗�
+ */
+ public void setUseTFCard(boolean useTFCard) {
+ this.useTFCard = useTFCard;
}
/**
@@ -459,6 +467,16 @@
fileOutputStream = null;
}
+ // 濡傛灉浣跨敤鍐呴儴 Flash锛堥潪 TF 鍗★級锛屽湪鍒涘缓鏂版枃浠跺墠妫�鏌ュ苟娓呯悊绌洪棿
+ if (!useTFCard && context != null) {
+ int result = FileUtil.ensureInternalFlashSpaceForH264(context);
+ if (result == -1) {
+ Timber.e("Insufficient internal flash space (<800MB) even after cleanup, stop file output");
+ enableFileOutput = false;
+ return false;
+ }
+ }
+
// 妫�鏌ュ苟娓呯悊 TF 鍗′笂鐨� h264 鏂囦欢锛堝鏋滈渶瑕侊級
if (context != null && outputFileDirectory != null && !outputFileDirectory.isEmpty()) {
try {
--
Gitblit v1.8.0