|
@@ -13,7 +13,7 @@ import { PreviewManager } from '../common/util/PreviewManager';
|
|
const TAG = "sony_camera info"
|
|
const TAG = "sony_camera info"
|
|
@Entry
|
|
@Entry
|
|
@Component
|
|
@Component
|
|
-struct RgvControl {
|
|
|
|
|
|
+struct CameraControl {
|
|
@StorageLink('CameraStatus') cameraStatus: boolean = false;
|
|
@StorageLink('CameraStatus') cameraStatus: boolean = false;
|
|
commonDialogController: CustomDialogController | null = null;
|
|
commonDialogController: CustomDialogController | null = null;
|
|
build() {
|
|
build() {
|
|
@@ -174,8 +174,9 @@ export struct CameraDialog {
|
|
// 控制帧率
|
|
// 控制帧率
|
|
@State readTimer:number = 0
|
|
@State readTimer:number = 0
|
|
// 预览操作
|
|
// 预览操作
|
|
- private previewManager: PreviewManager | null =null ;
|
|
|
|
|
|
+ private previewManager: PreviewManager | null = null;
|
|
@State photoPixelMaps: photoInfo[] = []; // 存储所有照片的 PixelMap
|
|
@State photoPixelMaps: photoInfo[] = []; // 存储所有照片的 PixelMap
|
|
|
|
+
|
|
// 加载照片并生成 PixelMap
|
|
// 加载照片并生成 PixelMap
|
|
loadPhotos = async () => {
|
|
loadPhotos = async () => {
|
|
const context = getContext(this);
|
|
const context = getContext(this);
|
|
@@ -425,6 +426,7 @@ export struct CameraDialog {
|
|
console.info(TAG,"Publish openSession err=" + JSON.stringify(err))
|
|
console.info(TAG,"Publish openSession err=" + JSON.stringify(err))
|
|
} else {
|
|
} else {
|
|
console.info(TAG,"Publish openSession succeed ")
|
|
console.info(TAG,"Publish openSession succeed ")
|
|
|
|
+ this.queryFlashMode();
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
@@ -432,19 +434,20 @@ export struct CameraDialog {
|
|
queryFlashMode = async () => {
|
|
queryFlashMode = async () => {
|
|
CommonEventManager.publish("queryflashmode", (err) => {
|
|
CommonEventManager.publish("queryflashmode", (err) => {
|
|
if (err?.code) {
|
|
if (err?.code) {
|
|
- console.info(TAG,"Publish openSession err=" + JSON.stringify(err))
|
|
|
|
|
|
+ console.info(TAG,"Publish queryflashmode err=" + JSON.stringify(err))
|
|
} else {
|
|
} else {
|
|
- console.info(TAG,"Publish openSession succeed ")
|
|
|
|
|
|
+ console.info(TAG,"Publish queryflashmode succeed ")
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
//开始预览
|
|
//开始预览
|
|
- startView=()=>{
|
|
|
|
|
|
+ startView=async()=>{
|
|
CommonEventManager.publish("startview", (err) => {
|
|
CommonEventManager.publish("startview", (err) => {
|
|
if (err?.code) {
|
|
if (err?.code) {
|
|
console.error(TAG, JSON.stringify(err));
|
|
console.error(TAG, JSON.stringify(err));
|
|
} else {
|
|
} else {
|
|
|
|
+ console.info(TAG, 'publish startview succeed');
|
|
this.isStopView =false;
|
|
this.isStopView =false;
|
|
this.liveShow();
|
|
this.liveShow();
|
|
}
|
|
}
|
|
@@ -458,6 +461,11 @@ export struct CameraDialog {
|
|
console.error(TAG, JSON.stringify(err));
|
|
console.error(TAG, JSON.stringify(err));
|
|
} else {
|
|
} else {
|
|
this.isStopView =true;
|
|
this.isStopView =true;
|
|
|
|
+ console.info(TAG, 'publish stopview succeed');
|
|
|
|
+ if (this.readTimer) {
|
|
|
|
+ clearInterval(this.readTimer);
|
|
|
|
+ this.readTimer = 0 ;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -494,58 +502,54 @@ export struct CameraDialog {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- //开始预览 50ms一张图片(20帧)
|
|
|
|
liveShow = async () => {
|
|
liveShow = async () => {
|
|
- if (this.previewManager) {
|
|
|
|
- this.previewManager.release();
|
|
|
|
- }
|
|
|
|
- if (this.readTimer) {
|
|
|
|
- clearInterval(this.readTimer);
|
|
|
|
- }
|
|
|
|
- this.previewManager = new PreviewManager(getContext(this));
|
|
|
|
let index = 0;
|
|
let index = 0;
|
|
let retryCount = 0;
|
|
let retryCount = 0;
|
|
- const MAX_RETRIES = 5; // 最大重试次数
|
|
|
|
- this.readTimer = setInterval(async () => {
|
|
|
|
|
|
+ const MAX_RETRIES = 10; // 最大重试次数
|
|
|
|
+
|
|
|
|
+ const previewLoop = 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();
|
|
|
|
- retryCount=0;
|
|
|
|
|
|
+ this.commodityPixelMap = await this.previewManager!.getActiveBuffer();
|
|
|
|
+ retryCount = 0;
|
|
|
|
+ } else {
|
|
|
|
+ retryCount++;
|
|
|
|
+ console.warn(TAG, "processFrame失败");
|
|
}
|
|
}
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- retryCount++
|
|
|
|
|
|
+ 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, "预览更新:");
|
|
|
|
|
|
+
|
|
|
|
+ if (retryCount === MAX_RETRIES) {
|
|
|
|
+ clearInterval(this.readTimer)
|
|
|
|
+ this.readTimer = 0;
|
|
|
|
+ console.info(TAG,"GG")
|
|
|
|
+ return;
|
|
|
|
+ //this.reconnectCamera();
|
|
|
|
+ }
|
|
|
|
+ if (this.readTimer !== 0) { // 检查是否应该继续循环
|
|
|
|
+ this.readTimer = setTimeout(previewLoop, 50);
|
|
}
|
|
}
|
|
- }, 50);
|
|
|
|
- };
|
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
+ this.readTimer = setTimeout(previewLoop, 50);
|
|
|
|
+ };
|
|
|
|
|
|
//断开相机(停止预览->关闭连接)
|
|
//断开相机(停止预览->关闭连接)
|
|
- disconnectCamera = () => {
|
|
|
|
- CommonEventManager.publish("stopview", (err) => {
|
|
|
|
|
|
+ disconnectCamera = async () => {
|
|
|
|
+ if(!this.isStopView)
|
|
|
|
+ {
|
|
|
|
+ await this.stopView()
|
|
|
|
+ }
|
|
|
|
+ CommonEventManager.publish("closesession", (err) => {
|
|
if (err?.code) {
|
|
if (err?.code) {
|
|
- console.info(TAG,"Publish stopview err=" + JSON.stringify(err))
|
|
|
|
|
|
+ console.info(TAG,"Publish closesession err=" + JSON.stringify(err))
|
|
} else {
|
|
} else {
|
|
- console.info(TAG,"Publish stopview succeed ")
|
|
|
|
- CommonEventManager.publish("closesession", (err) => {
|
|
|
|
- if (err?.code) {
|
|
|
|
- console.info(TAG,"Publish closesession err=" + JSON.stringify(err))
|
|
|
|
- } else {
|
|
|
|
- console.info(TAG,"Publish closesession succeed ")
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
|
|
+ console.info(TAG,"Publish closesession succeed ")
|
|
}
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|
|
@@ -625,29 +629,27 @@ export struct CameraDialog {
|
|
|
|
|
|
}
|
|
}
|
|
async aboutToAppear() {
|
|
async aboutToAppear() {
|
|
|
|
+ this.previewManager = new PreviewManager(getContext(this));
|
|
this.loadPhotos();
|
|
this.loadPhotos();
|
|
await this.createSubscriber();
|
|
await this.createSubscriber();
|
|
|
|
+ await sleep(50)
|
|
await this.connectCamera();
|
|
await this.connectCamera();
|
|
- await this.queryFlashMode();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
aboutToDisappear(): void {
|
|
aboutToDisappear(): void {
|
|
- this.isStopView = true;
|
|
|
|
this.disconnectCamera()
|
|
this.disconnectCamera()
|
|
|
|
+ if (this.previewManager) {
|
|
|
|
+ this.previewManager.release();
|
|
|
|
+ this.previewManager = null
|
|
|
|
+ }
|
|
if (this.subscriber) {
|
|
if (this.subscriber) {
|
|
CommonEventManager.unsubscribe(this.subscriber);
|
|
CommonEventManager.unsubscribe(this.subscriber);
|
|
}
|
|
}
|
|
this.releaseAllPixelMaps()
|
|
this.releaseAllPixelMaps()
|
|
- if (this.readTimer) {
|
|
|
|
- clearInterval(this.readTimer);
|
|
|
|
- }
|
|
|
|
if (this.commodityPixelMap) {
|
|
if (this.commodityPixelMap) {
|
|
this.commodityPixelMap.release();
|
|
this.commodityPixelMap.release();
|
|
this.commodityPixelMap = null;
|
|
this.commodityPixelMap = null;
|
|
}
|
|
}
|
|
- if (this.previewManager) {
|
|
|
|
- this.previewManager.release();
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
build() {
|
|
build() {
|
|
Row() {
|
|
Row() {
|