import { printErrorDetail } from '@normalized:N&&&harmonyCameraLib/src/main/ets/Utils&1.2.1'; import hilog from '@ohos:hilog'; export var DeviceState; (function (p2) { p2[p2["UNINITIALIZED"] = 0] = "UNINITIALIZED"; p2[p2["INITIALIZED"] = 1] = "INITIALIZED"; p2[p2["OPENING"] = 2] = "OPENING"; p2[p2["OPENED"] = 3] = "OPENED"; p2[p2["STARTING"] = 4] = "STARTING"; p2[p2["STARTED"] = 5] = "STARTED"; p2[p2["INTERRUPT"] = 6] = "INTERRUPT"; p2[p2["STOPING"] = 7] = "STOPING"; p2[p2["STOPED"] = 8] = "STOPED"; p2[p2["CLOSING"] = 9] = "CLOSING"; p2[p2["CLOSED"] = 10] = "CLOSED"; p2[p2["REOPENING"] = 11] = "REOPENING"; p2[p2["RELEASING"] = 12] = "RELEASING"; p2[p2["RELEASED"] = 13] = "RELEASED"; })(DeviceState || (DeviceState = {})); export class CameraDeviceCallback { constructor(o2) { this.mState = DeviceState.UNINITIALIZED; this.device = o2; } setState(n2) { this.mState = n2; hilog.debug(0x0000, "CameraX", `CameraDeviceCallback state change: ${DeviceState[n2]}`); } getState() { return this.mState; } async onOpen() { switch (this.mState) { case DeviceState.CLOSING: { await this.device.close(); break; } case DeviceState.RELEASING: { await this.device.release(); break; } case DeviceState.OPENING: case DeviceState.REOPENING: { await this.device.open().then(() => this.mState = DeviceState.OPENED); break; } } } async onClose() { switch (this.mState) { case DeviceState.CLOSING: { this.mState = DeviceState.INITIALIZED; break; } case DeviceState.RELEASING: { this.mState = DeviceState.RELEASED; break; } case DeviceState.REOPENING: { this.mState = DeviceState.OPENING; await this.device.open(); break; } } } async onRelease() { switch (this.mState) { case DeviceState.CLOSING: { this.mState = DeviceState.INITIALIZED; break; } case DeviceState.RELEASING: { this.mState = DeviceState.RELEASED; await this.device.close(); break; } case DeviceState.OPENING: case DeviceState.OPENED: case DeviceState.REOPENING: { this.mState = DeviceState.CLOSING; await this.device.close(); break; } } } async onError(l2) { printErrorDetail(l2); switch (this.mState) { case DeviceState.CLOSING: { this.mState = DeviceState.INITIALIZED; break; } case DeviceState.RELEASING: { this.mState = DeviceState.RELEASED; await this.device.release(); break; } case DeviceState.OPENING: case DeviceState.OPENED: case DeviceState.REOPENING: { this.mState = DeviceState.CLOSING; await this.device.close(); await this.device.release(); break; } } } } 