|
@@ -1,5 +1,3 @@
|
|
-import image from '@ohos.multimedia.image';
|
|
|
|
-import fs from "@ohos.file.fs"
|
|
|
|
import CommonEventManager from '@ohos.commonEventManager'
|
|
import CommonEventManager from '@ohos.commonEventManager'
|
|
import uploadInstance from '../../common/util/UploadUtil';
|
|
import uploadInstance from '../../common/util/UploadUtil';
|
|
import { DrawingInfo, DrawingPage } from '../../viewmodel/DrawingInfo';
|
|
import { DrawingInfo, DrawingPage } from '../../viewmodel/DrawingInfo';
|
|
@@ -10,6 +8,7 @@ import { ConfirmDialogParams } from '../../viewmodel/ConfirmDialogParam';
|
|
import { ConfirmDialog } from '../ConfirmDialog';
|
|
import { ConfirmDialog } from '../ConfirmDialog';
|
|
import promptAction from '@ohos.promptAction';
|
|
import promptAction from '@ohos.promptAction';
|
|
import ProcessInfo from '../../viewmodel/process/ProcessInfo';
|
|
import ProcessInfo from '../../viewmodel/process/ProcessInfo';
|
|
|
|
+import { PreviewManager } from '../../common/util/PreviewManager';
|
|
|
|
|
|
const TAG = "Process camera upload"
|
|
const TAG = "Process camera upload"
|
|
|
|
|
|
@@ -275,19 +274,38 @@ export struct MultiMediaCollect {
|
|
|
|
|
|
//开始预览 50ms一张图片(20帧)
|
|
//开始预览 50ms一张图片(20帧)
|
|
liveShow = async () => {
|
|
liveShow = async () => {
|
|
|
|
+ if (this.previewManager) {
|
|
|
|
+ this.previewManager.release();
|
|
|
|
+ }
|
|
|
|
+ if (this.readTimer) {
|
|
|
|
+ clearInterval(this.readTimer);
|
|
|
|
+ }
|
|
this.previewManager = new PreviewManager(getContext(this));
|
|
this.previewManager = new PreviewManager(getContext(this));
|
|
let index = 0;
|
|
let index = 0;
|
|
|
|
+ let retryCount = 0;
|
|
|
|
+ const MAX_RETRIES = 5; // 最大重试次数
|
|
this.readTimer = setInterval(async () => {
|
|
this.readTimer = setInterval(async () => {
|
|
if (!this.isStopView && !this.isCapturing) {
|
|
if (!this.isStopView && !this.isCapturing) {
|
|
try {
|
|
try {
|
|
const success = await this.previewManager!.processFrame(index);
|
|
const success = await this.previewManager!.processFrame(index);
|
|
if (success) {
|
|
if (success) {
|
|
this.commodityPixelMap = this.previewManager!.getActiveBuffer();
|
|
this.commodityPixelMap = this.previewManager!.getActiveBuffer();
|
|
|
|
+ retryCount=0;
|
|
}
|
|
}
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
|
+ retryCount++
|
|
console.warn(TAG, "预览更新失败:", error);
|
|
console.warn(TAG, "预览更新失败:", error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if(retryCount===MAX_RETRIES)
|
|
|
|
+ {
|
|
|
|
+ clearInterval(this.readTimer);
|
|
|
|
+ this.previewManager?.release();
|
|
|
|
+ this.stopView()
|
|
|
|
+ await sleep(50)
|
|
|
|
+ this.startView()
|
|
|
|
+ console.info(TAG, "预览更新:");
|
|
|
|
+ }
|
|
}, 50);
|
|
}, 50);
|
|
};
|
|
};
|
|
|
|
|
|
@@ -398,7 +416,6 @@ export struct MultiMediaCollect {
|
|
await this.createSubscriber();
|
|
await this.createSubscriber();
|
|
await this.connectCamera();
|
|
await this.connectCamera();
|
|
await this.queryFlashMode();
|
|
await this.queryFlashMode();
|
|
- console.info('sssss'+this.seqNo)
|
|
|
|
uploadInstance.uploadParams = {
|
|
uploadInstance.uploadParams = {
|
|
token: "your_token_here", // 替换为实际 token
|
|
token: "your_token_here", // 替换为实际 token
|
|
operationMediaId: this.selectOperationId, // 默认值
|
|
operationMediaId: this.selectOperationId, // 默认值
|
|
@@ -595,8 +612,8 @@ export struct MultiMediaCollect {
|
|
this.pinchCenterY = event.pinchCenterY - 121 - 520 / 2; //rk3588
|
|
this.pinchCenterY = event.pinchCenterY - 121 - 520 / 2; //rk3588
|
|
// this.pinchCenterX = event.pinchCenterX - 1090 / 2; //rk3568
|
|
// this.pinchCenterX = event.pinchCenterX - 1090 / 2; //rk3568
|
|
// this.pinchCenterY = event.pinchCenterY - 692 / 2; //rk3568
|
|
// this.pinchCenterY = event.pinchCenterY - 692 / 2; //rk3568
|
|
- console.info(TAG,event.pinchCenterX,TAG,event.pinchCenterY)
|
|
|
|
- console.info(TAG,this.pinchCenterX,TAG,this.pinchCenterY)
|
|
|
|
|
|
+ // console.info(TAG,event.pinchCenterX,TAG,event.pinchCenterY)
|
|
|
|
+ // console.info(TAG,this.pinchCenterX,TAG,this.pinchCenterY)
|
|
})
|
|
})
|
|
.onActionUpdate((event: GestureEvent) => {
|
|
.onActionUpdate((event: GestureEvent) => {
|
|
const newScale = this.lastScale * event.scale;
|
|
const newScale = this.lastScale * event.scale;
|
|
@@ -813,73 +830,6 @@ function sleep(ms: number): Promise<void> {
|
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
}
|
|
}
|
|
|
|
|
|
-class PreviewManager {
|
|
|
|
- private context: Context;
|
|
|
|
- private activeBuffer: PixelMap | null = null;
|
|
|
|
- private nextBuffer: PixelMap | null = null;
|
|
|
|
- private isProcessing: boolean = false;
|
|
|
|
- private lastFrameTime: number = 0;
|
|
|
|
- private frameInterval: number = 50;
|
|
|
|
-
|
|
|
|
- constructor(context: Context) {
|
|
|
|
- this.context = context;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- async processFrame(index: number): Promise<boolean> {
|
|
|
|
- if (this.isProcessing) return false;
|
|
|
|
-
|
|
|
|
- const now = Date.now();
|
|
|
|
- if (now - this.lastFrameTime < this.frameInterval) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.isProcessing = true;
|
|
|
|
- try {
|
|
|
|
- const filePath = `${this.context.filesDir}/live${index}.jpg`;
|
|
|
|
- try {
|
|
|
|
- fs.accessSync(filePath);
|
|
|
|
- } catch {
|
|
|
|
- this.isProcessing = false;
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const imageSource = image.createImageSource(filePath);
|
|
|
|
- if (!imageSource) {
|
|
|
|
- this.isProcessing = false;
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- this.nextBuffer = await imageSource.createPixelMap();
|
|
|
|
- imageSource.release();
|
|
|
|
- if (this.activeBuffer) {
|
|
|
|
- this.activeBuffer.release();
|
|
|
|
- }
|
|
|
|
- this.activeBuffer = this.nextBuffer;
|
|
|
|
- this.nextBuffer = null;
|
|
|
|
- this.lastFrameTime = now;
|
|
|
|
- return true;
|
|
|
|
- } catch (error) {
|
|
|
|
- console.warn(TAG, "处理预览帧失败:", error);
|
|
|
|
- return false;
|
|
|
|
- } finally {
|
|
|
|
- this.isProcessing = false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- getActiveBuffer(): PixelMap | null {
|
|
|
|
- return this.activeBuffer;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- release() {
|
|
|
|
- if (this.activeBuffer) {
|
|
|
|
- this.activeBuffer.release();
|
|
|
|
- this.activeBuffer = null;
|
|
|
|
- }
|
|
|
|
- if (this.nextBuffer) {
|
|
|
|
- this.nextBuffer.release();
|
|
|
|
- this.nextBuffer = null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
|
|
interface CameraParam {
|
|
interface CameraParam {
|
|
flash_mode: string;
|
|
flash_mode: string;
|