diff --git a/camera/oh-package-lock.json5 b/camera/oh-package-lock.json5 deleted file mode 100644 index ebb8b315c3eb0c6696e7e8e12bd9aaab4c3dd2d2..0000000000000000000000000000000000000000 --- a/camera/oh-package-lock.json5 +++ /dev/null @@ -1,19 +0,0 @@ -{ - "meta": { - "stableOrder": true, - "enableUnifiedLockfile": false - }, - "lockfileVersion": 3, - "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", - "specifiers": { - "commons@../commons": "commons@../commons" - }, - "packages": { - "commons@../commons": { - "name": "commons", - "version": "1.0.0", - "resolved": "../commons", - "registryType": "local" - } - } -} \ No newline at end of file diff --git a/camera/src/main/ets/cameramanagers/CameraManager.ets b/camera/src/main/ets/cameramanagers/CameraManager.ets index 942e6a50eeb6a3d00c9ce8aa24bb4d7261fa503c..afa66c2f16c55000671b4b500828a79d7a17226e 100644 --- a/camera/src/main/ets/cameramanagers/CameraManager.ets +++ b/camera/src/main/ets/cameramanagers/CameraManager.ets @@ -14,8 +14,8 @@ */ import { camera } from '@kit.CameraKit'; -import { Logger } from 'commons/src/main/ets/utils/Logger'; import { BusinessError } from '@kit.BasicServicesKit'; +import { Logger } from 'commons'; import OutputManager, { CreateOutputConfig } from './OutputManager'; const TAG = 'CameraManager'; @@ -36,8 +36,8 @@ export class CameraManager { addCameraStatusListener() { this.cameraManager.on('cameraStatus', (err: BusinessError, statusInfo: camera.CameraStatusInfo) => { - if (err && err.code) { - Logger.error(TAG, 'cameraStatus with errorCode = ' + err.code); + if (err && err.message) { + Logger.error(TAG, 'cameraStatus with errorMessage = ' + err.message); return; } Logger.info(TAG, `cameraStatusInfo: camera is ${statusInfo.camera.cameraId}, status is ${statusInfo.status}`); diff --git a/camera/src/main/ets/cameramanagers/ImageReceiverManager.ets b/camera/src/main/ets/cameramanagers/ImageReceiverManager.ets index c6943617cf3386cf7340fa7e2e6d80f3e9204bf6..2fc79bcd036503e7bacb97bba2b26b0a7b890bd6 100644 --- a/camera/src/main/ets/cameramanagers/ImageReceiverManager.ets +++ b/camera/src/main/ets/cameramanagers/ImageReceiverManager.ets @@ -15,10 +15,10 @@ import { image } from '@kit.ImageKit'; import { camera } from '@kit.CameraKit'; +import { display } from '@kit.ArkUI'; import { BusinessError } from '@kit.BasicServicesKit'; -import { Logger } from 'commons/src/main/ets/utils/Logger'; +import { Logger } from 'commons'; import OutputManager, { CreateOutputConfig } from './OutputManager'; -import { display } from '@kit.ArkUI'; import CameraConstant from '../constants/CameraConstants'; const TAG = 'ImageReceiverManager'; diff --git a/camera/src/main/ets/cameramanagers/PhotoManager.ets b/camera/src/main/ets/cameramanagers/PhotoManager.ets index 01956edacd6497001cccbec8376cceed4a23ca5a..88401e6727752b181acee40622200ec2be45b7bd 100644 --- a/camera/src/main/ets/cameramanagers/PhotoManager.ets +++ b/camera/src/main/ets/cameramanagers/PhotoManager.ets @@ -19,10 +19,11 @@ import { photoAccessHelper } from '@kit.MediaLibraryKit'; import { sensor } from '@kit.SensorServiceKit'; import { Decimal } from '@kit.ArkTS'; import { image } from '@kit.ImageKit'; -import OutputManager, { CreateOutputConfig } from './OutputManager'; import { colorSpaceManager } from '@kit.ArkGraphics2D'; import { geoLocationManager } from '@kit.LocationKit'; -import { Logger } from 'commons/src/main/ets/utils/Logger'; +import { Logger } from 'commons'; +import OutputManager, { CreateOutputConfig } from './OutputManager'; +import CameraConstant from '../constants/CameraConstants'; const TAG_LOG = 'PhotoManager'; @@ -62,11 +63,10 @@ export class PhotoManager implements OutputManager { // [Start create_photo_output] public createPhotoOutput(cameraManager: camera.CameraManager, cameraDevice: camera.CameraDevice, profile: camera.Profile) { - const PROFILE_DIFFERENCE = 1e-10; let cameraPhotoOutput: camera.PhotoOutput | undefined = undefined; const cameraOutputCapability = cameraManager.getSupportedOutputCapability(cameraDevice, camera.SceneMode.NORMAL_PHOTO); - let photoProfilesArray: Array | undefined = cameraOutputCapability?.photoProfiles; + let photoProfilesArray: camera.Profile[] | undefined = cameraOutputCapability?.photoProfiles; if (photoProfilesArray?.length) { try { const displayRatio = profile.size.width / profile.size.height; @@ -75,7 +75,7 @@ export class PhotoManager implements OutputManager { .sort((a, b) => Math.abs(a.size.width - profileWidth) - Math.abs(b.size.width - profileWidth)) .find(pf => { const pfDisplayRatio = pf.size.width / pf.size.height; - return Math.abs(pfDisplayRatio - displayRatio) <= PROFILE_DIFFERENCE && + return Math.abs(pfDisplayRatio - displayRatio) <= CameraConstant.PROFILE_DIFFERENCE && pf.format === camera.CameraFormat.CAMERA_FORMAT_JPEG; }); if (!PhotoProfile) { @@ -84,8 +84,7 @@ export class PhotoManager implements OutputManager { } cameraPhotoOutput = cameraManager.createPhotoOutput(PhotoProfile); } catch (error) { - let err = error as BusinessError; - Logger.error(TAG_LOG, `Failed to createPhotoOutput. error: ${JSON.stringify(err)}`); + Logger.error(TAG_LOG, `Failed to createPhotoOutput. error: ${JSON.stringify(error)}`); } } this.output = cameraPhotoOutput; @@ -103,8 +102,8 @@ export class PhotoManager implements OutputManager { assetChangeRequest.saveCameraPhoto(); await phAccessHelper.applyChanges(assetChangeRequest); phAccessHelper.release(); - } catch (err) { - Logger.error(TAG_LOG, `apply saveCameraPhoto failed with error: ${err.code}, ${err.message}`); + } catch (error) { + Logger.error(TAG_LOG, `apply saveCameraPhoto failed with error: ${error.code}, ${error.message}`); } } @@ -117,12 +116,10 @@ export class PhotoManager implements OutputManager { return; } let imageSource = image.createImageSource(data); - imageSource.createPixelMap((err: BusinessError, data: image.PixelMap) => { - if (err) { - Logger.error(TAG_LOG, `createPixelMap err:${err.code}`); - return; - } - callback(data, photoAsset.uri); + imageSource.createPixelMap().then((pixelMap: image.PixelMap) => { + callback(pixelMap, photoAsset.uri); + }).catch((err: BusinessError) => { + Logger.error(TAG_LOG, `createPixelMap err:${err.code}`); }) } } @@ -165,10 +162,8 @@ export class PhotoManager implements OutputManager { Logger.error(TAG_LOG, 'getComponent failed'); return; } - let buffer: ArrayBuffer; - if (component.byteBuffer) { - buffer = component.byteBuffer; - } else { + const buffer: ArrayBuffer = component.byteBuffer; + if (!buffer) { Logger.error(TAG_LOG, 'byteBuffer is null'); return; } @@ -191,7 +186,6 @@ export class PhotoManager implements OutputManager { imageObj.release(); }); } - // [End save_photo_single] setPhotoOutputCallback(isSingle: boolean) { @@ -223,15 +217,19 @@ export class PhotoManager implements OutputManager { try { colorSpaces = session.getSupportedColorSpaces(); } catch (error) { - let err = error as BusinessError; - Logger.error(TAG_LOG, `The getSupportedColorSpaces call failed. error code: ${err.code}`); + Logger.error(TAG_LOG, `The getSupportedColorSpaces call failed. error code: ${error.code}`); } - let isSupportedColorSpaces = colorSpaces.indexOf(colorSpace) >= 0; - if (isSupportedColorSpaces) { - session.setColorSpace(colorSpace); + if (!colorSpaces.includes(colorSpace)) { + Logger.info(TAG_LOG, `colorSpace: ${colorSpace} is not support`); + return; + } + Logger.info(TAG_LOG, `setColorSpace: ${colorSpace}`); + session.setColorSpace(colorSpace); + try { let activeColorSpace: colorSpaceManager.ColorSpace = session.getActiveColorSpace(); - } else { - Logger.error(TAG_LOG, `colorSpace: ${colorSpace} is not support`); + Logger.info(TAG_LOG, `activeColorSpace: ${activeColorSpace}`); + } catch (error) { + Logger.error(TAG_LOG, `getActiveColorSpace Faild: ${error.message}`); } } // [End set_color_space] @@ -250,8 +248,7 @@ export class PhotoManager implements OutputManager { photoSession.setFlashMode(flashMode || camera.FlashMode.FLASH_MODE_CLOSE); } } catch (error) { - let err = error as BusinessError; - Logger.error(TAG_LOG, `Failed to hasFlash. error: ${JSON.stringify(err)}`); + Logger.error(TAG_LOG, `Failed to hasFlash. error: ${JSON.stringify(error)}`); } } @@ -263,9 +260,8 @@ export class PhotoManager implements OutputManager { photoSession.setFocusMode(focusMode || defaultMode); } } catch (error) { - let err = error as BusinessError; Logger.error(TAG_LOG, - `Failed to check whether the focus mode is supported. error: ${JSON.stringify(err)}`); + `Failed to check whether the focus mode is supported. error: ${JSON.stringify(error)}`); } } @@ -273,8 +269,7 @@ export class PhotoManager implements OutputManager { try { photoSession.setFocusPoint(focusPoint); } catch (error) { - let err = error as BusinessError; - Logger.error(TAG_LOG, `The setFocusPoint call failed. error code: ${err.code}`); + Logger.error(TAG_LOG, `The setFocusPoint call failed. error code: ${error.code}`); } } @@ -287,8 +282,7 @@ export class PhotoManager implements OutputManager { photoZoomRatio = zoomRatioRange[0]; } } catch (error) { - let err = error as BusinessError; - Logger.error(TAG_LOG, `Failed to get the zoom ratio range. error: ${JSON.stringify(err)}`); + Logger.error(TAG_LOG, `Failed to get the zoom ratio range. error: ${JSON.stringify(error)}`); } } photoSession.setZoomRatio(zoomRatio || photoZoomRatio); @@ -299,8 +293,7 @@ export class PhotoManager implements OutputManager { try { colorSpaces = session.getSupportedColorSpaces(); } catch (error) { - let err = error as BusinessError; - Logger.error(TAG_LOG,`The getSupportedColorSpaces call failed. error code: ${err.code}`); + Logger.error(TAG_LOG,`The getSupportedColorSpaces call failed. error code: ${error.code}`); } return colorSpaces; } @@ -311,8 +304,7 @@ export class PhotoManager implements OutputManager { try { photoRotation = photoOutput.getPhotoRotation(deviceDegree); } catch (error) { - let err = error as BusinessError; - Logger.error(TAG_LOG, `The photoOutput.getPhotoRotation call failed. error code: ${err.code}`); + Logger.error(TAG_LOG, `The photoOutput.getPhotoRotation call failed. error code: ${error.code}`); } return photoRotation; } @@ -372,8 +364,7 @@ export class PhotoManager implements OutputManager { try { isSupported = photoOutput.isMovingPhotoSupported(); } catch (error) { - let err = error as BusinessError; - Logger.error(TAG_LOG, `The isMovingPhotoSupported call failed. error code: ${err.code}`); + Logger.error(TAG_LOG, `The isMovingPhotoSupported call failed. error code: ${error.code}`); } return isSupported; } @@ -385,8 +376,7 @@ export class PhotoManager implements OutputManager { try { this.output?.enableMovingPhoto(enabled); } catch (error) { - let err = error as BusinessError; - Logger.error(TAG_LOG, `The enableMovingPhoto call failed. error code: ${err.code}`); + Logger.error(TAG_LOG, `The enableMovingPhoto call failed. error code: ${error.code}`); } } diff --git a/camera/src/main/ets/cameramanagers/PreviewManager.ets b/camera/src/main/ets/cameramanagers/PreviewManager.ets index 4b270250682f7008fc6d06007237f03d6130fd28..bcdb1db5c093f8b77e4dbca8b0082aac92a2bcd0 100644 --- a/camera/src/main/ets/cameramanagers/PreviewManager.ets +++ b/camera/src/main/ets/cameramanagers/PreviewManager.ets @@ -14,8 +14,8 @@ */ import { camera } from '@kit.CameraKit'; -import { Logger } from 'commons/src/main/ets/utils/Logger'; import { BusinessError } from '@kit.BasicServicesKit'; +import { Logger } from 'commons'; import OutputManager, { CreateOutputConfig } from './OutputManager'; import CameraConstant from '../constants/CameraConstants'; @@ -61,7 +61,7 @@ export class PreviewManager implements OutputManager { addFrameStartEventListener(output: camera.PreviewOutput) { output.on('frameStart', (err: BusinessError) => { if (err !== undefined && err.code !== 0) { - Logger.error(TAG_LOG, `FrameStart callback Error, errorCode: ${err.code}`); + Logger.error(TAG_LOG, `FrameStart callback Error, errorMessage: ${err.message}`); return; } Logger.info(TAG_LOG, 'Preview frame started'); @@ -72,7 +72,7 @@ export class PreviewManager implements OutputManager { addFrameEndEventListener(output: camera.PreviewOutput) { output.on('frameEnd', (err: BusinessError) => { if (err !== undefined && err.code !== 0) { - Logger.error(TAG_LOG, `FrameStart callback Error, errorCode: ${err.code}`); + Logger.error(TAG_LOG, `FrameStart callback Error, errorMessage: ${err.message}`); return; } Logger.info(TAG_LOG, 'Preview frame end'); diff --git a/camera/src/main/ets/cameramanagers/VideoManager.ets b/camera/src/main/ets/cameramanagers/VideoManager.ets index 7dff1afb577ee39cf17e5761a50cfc243daac12d..805c9c8f372922451b9360fe4a35f58930615644 100644 --- a/camera/src/main/ets/cameramanagers/VideoManager.ets +++ b/camera/src/main/ets/cameramanagers/VideoManager.ets @@ -20,11 +20,10 @@ import { fileIo } from '@kit.CoreFileKit'; import { sensor } from '@kit.SensorServiceKit'; import { Decimal } from '@kit.ArkTS'; import { image } from '@kit.ImageKit'; -import { BusinessError } from '@kit.BasicServicesKit'; +import { colorSpaceManager } from '@kit.ArkGraphics2D'; +import { Logger } from 'commons'; import OutputManager, { CreateOutputConfig } from './OutputManager'; import CameraConstant from '../constants/CameraConstants'; -import { colorSpaceManager } from '@kit.ArkGraphics2D'; -import { Logger } from 'commons/src/main/ets/utils/Logger'; const TAG_LOG = 'video'; @@ -75,7 +74,7 @@ export class VideoManager implements OutputManager { Logger.info(TAG_LOG, 'on avRecorder state change: ', state) }); } catch (error) { - Logger.info(TAG_LOG, 'createAVRecorder call failed. error code: %{public}s', (error as BusinessError).code); + Logger.info(TAG_LOG, 'createAVRecorder call failed. error code: %{public}s', error.code); } if (this.avRecorder === undefined || this.avRecorder === null) { return; @@ -95,14 +94,22 @@ export class VideoManager implements OutputManager { Logger.info(TAG_LOG, 'Succeeded in preparing'); } } catch (error) { - Logger.info(TAG_LOG, `Failed to prepare and catch error is ${error.message}`); + Logger.info(TAG_LOG, `Failed to prepare and catch error is ${error.message}`); } } + isSupportMirror() { + let isSupported: boolean | undefined = this.output?.isMirrorSupported(); + return isSupported; + } + // [Start start_video] - async start() { + async start(isFront: boolean) { try { if (this.avRecorder?.state === AVRecorderState.PREPARED) { + if (this.isSupportMirror() && isFront) { + this.output?.enableMirror(true) + } // [StartExclude start_video] await this.avRecorder.updateRotation(this.getVideoRotation(await this.getGravity())); // [EndExclude start_video] @@ -110,7 +117,7 @@ export class VideoManager implements OutputManager { await this.avRecorder?.start(); } } catch (error) { - Logger.info(TAG_LOG, `Failed to start and catch error is ${error.message}`); + Logger.info(TAG_LOG, `Failed to start and catch error is ${error.message}`); } } // [End start_video] @@ -128,7 +135,7 @@ export class VideoManager implements OutputManager { } } } catch (error) { - Logger.info(TAG_LOG, `Failed to stop and catch error is ${error.message}`); + Logger.info(TAG_LOG, `Failed to stop and catch error is ${error.message}`); } } // [End stop_video] @@ -141,7 +148,7 @@ export class VideoManager implements OutputManager { await this.output?.stop(); } } catch (error) { - Logger.info(TAG_LOG, `Failed to pause and catch error is ${error.message}`); + Logger.info(TAG_LOG, `Failed to pause and catch error is ${error.message}`); } } // [End pause_video] @@ -154,7 +161,7 @@ export class VideoManager implements OutputManager { await this.avRecorder.resume(); } } catch (error) { - Logger.info(TAG_LOG, `Failed to resume and catch error is ${error.message}`); + Logger.info(TAG_LOG, `Failed to resume and catch error is ${error.message}`); } } // [End resume_video] @@ -191,7 +198,7 @@ export class VideoManager implements OutputManager { this.output = cameraManager.createVideoOutput(this.videoProfile, videoSurfaceId); } catch (error) { Logger.error(TAG_LOG, - `Failed to create the output instance. error code: ${(error as BusinessError).code}`); + `Failed to create the output instance. error code: ${error.code}`); } } @@ -202,33 +209,35 @@ export class VideoManager implements OutputManager { cameraManager.getSupportedOutputCapability(device, camera.SceneMode.NORMAL_VIDEO); let videoProfilesArray: camera.VideoProfile[] | undefined = cameraOutputCap?.videoProfiles; - const displayRatio = targetProfile.size.height / targetProfile.size.width; - const videoProfile = videoProfilesArray?.find((profile: camera.VideoProfile) => { - const profileRatio = profile.size.height / profile.size.width - if (this.cameraPosition === 1) { - return profile.size.width >= 1080 && profile.size.height >= 1080 && - Math.abs(profileRatio - displayRatio) <= CameraConstant.PROFILE_DIFFERENCE && - profile.frameRateRange.max === 30 && profile.format === camera.CameraFormat.CAMERA_FORMAT_YUV_420_SP; - } - if (this.qualityLevel === QualityLevel.NORMAL) { - return profile.size.width <= 1920 && profile.size.width >= 1080 && profile.size.height >= 1080 && - Math.abs(profileRatio - displayRatio) <= CameraConstant.PROFILE_DIFFERENCE * profile.size.width && - profile.frameRateRange.max === 60 && profile.format === camera.CameraFormat.CAMERA_FORMAT_YUV_420_SP; - } - if (this.qualityLevel === QualityLevel.HIGHER && this.cameraPosition === 0) { - return profile.size.width <= 4096 && profile.size.width >= 3000 && - Math.abs(profileRatio - displayRatio) <= CameraConstant.PROFILE_DIFFERENCE * profile.size.width && - profile.frameRateRange.max === 60 && profile.format === camera.CameraFormat.CAMERA_FORMAT_YUV_420_SP; + if (videoProfilesArray?.length) { + try { + const displayRatio = targetProfile.size.width / targetProfile.size.height; + const profileWidth = targetProfile.size.width; + const videoProfile = videoProfilesArray + .sort((a, b) => Math.abs(a.size.width - profileWidth) - Math.abs(b.size.width - profileWidth)) + .find(pf => { + const pfDisplayRatio = pf.size.width / pf.size.height; + return Math.abs(pfDisplayRatio - displayRatio) <= CameraConstant.PROFILE_DIFFERENCE && + pf.format === camera.CameraFormat.CAMERA_FORMAT_YUV_420_SP; + }); + if (!videoProfile) { + Logger.error(TAG_LOG, 'Failed to get video profile'); + return; + } + this.videoProfile = videoProfile; + } catch (error) { + Logger.error(TAG_LOG, `Failed to createPhotoOutput. error: ${JSON.stringify(error)}`); } - return false; - }) - if (!videoProfile) { - Logger.info(TAG_LOG, 'Failed to get videoProfile') } - this.videoProfile = videoProfile; } // [End create_video_output] + getCameraImageRotation(): camera.ImageRotation { + return this.cameraPosition === camera.CameraPosition.CAMERA_POSITION_FRONT + ? camera.ImageRotation.ROTATION_270 + : camera.ImageRotation.ROTATION_90 + } + async setAVConfig() { // [Start create_file] let options: photoAccessHelper.CreateOptions = { @@ -262,8 +271,7 @@ export class VideoManager implements OutputManager { profile: this.avProfile, url: `fd://${this.file.fd}`, metadata: { - videoOrientation: this.cameraPosition === camera.CameraPosition.CAMERA_POSITION_FRONT ? - camera.ImageRotation.ROTATION_270.toString() : camera.ImageRotation.ROTATION_90.toString(), + videoOrientation: this.getCameraImageRotation().toString() } } // [End av_config] @@ -316,23 +324,19 @@ export class VideoManager implements OutputManager { return promise; } } catch (error) { - Logger.info(TAG_LOG, `Failed to getGravity and catch error is ${error.message}`); + Logger.info(TAG_LOG, `Failed to getGravity and catch error is ${error.message}`); return 0 } } // [Start get_video_rotation] getVideoRotation(deviceDegree: number): camera.ImageRotation { - let videoRotation: camera.ImageRotation = - this.cameraPosition === camera.CameraPosition.CAMERA_POSITION_FRONT ? camera.ImageRotation.ROTATION_270 : - camera.ImageRotation.ROTATION_90; + let videoRotation: camera.ImageRotation = this.getCameraImageRotation(); try { - if (this.output) { - videoRotation = this.output.getVideoRotation(deviceDegree); + videoRotation = this.output!.getVideoRotation(deviceDegree); Logger.info(TAG_LOG, `Video rotation is: ${videoRotation}`); - } } catch (error) { - Logger.info(TAG_LOG, `Failed to getVideoRotation and catch error is: ${error.message}`); + Logger.info(TAG_LOG, `Failed to getVideoRotation and catch error is: ${error.message}`); } return videoRotation; } @@ -355,7 +359,7 @@ export class VideoManager implements OutputManager { pixelMap = await avImageGenerator.fetchFrameByTime(timeUs, queryOption, param); avImageGenerator.release(); } catch (error) { - Logger.info(TAG_LOG, `Failed to getVideoThumbnail and catch error is ${error.message}`); + Logger.info(TAG_LOG, `Failed to getVideoThumbnail and catch error is ${error.message}`); } return pixelMap; } @@ -366,46 +370,49 @@ export class VideoManager implements OutputManager { // [Start set_video_stabilization] - setVideoStabilizationMode(session: camera.VideoSession): boolean { + setVideoStabilizationMode(session: camera.VideoSession): boolean { let mode: camera.VideoStabilizationMode = camera.VideoStabilizationMode.AUTO; // Check whether video stabilization is supported let isSupported: boolean = session.isVideoStabilizationModeSupported(mode); - if (isSupported) { - Logger.info(TAG_LOG, `setVideoStabilizationMode: ${mode}`); - // Set video stabilization - session.setVideoStabilizationMode(mode); - let activeVideoStabilizationMode = session.getActiveVideoStabilizationMode(); - Logger.info(TAG_LOG, `activeVideoStabilizationMode: ${activeVideoStabilizationMode}`); - } else { + if (!isSupported) { Logger.info(TAG_LOG, `videoStabilizationMode: ${mode} is not support`); + return false; } + Logger.info(TAG_LOG, `setVideoStabilizationMode: ${mode}`); + // Set video stabilization + session.setVideoStabilizationMode(mode); + let activeVideoStabilizationMode = session.getActiveVideoStabilizationMode(); + Logger.info(TAG_LOG, `activeVideoStabilizationMode: ${activeVideoStabilizationMode}`); return isSupported; } // [End set_video_stabilization] // [Start set_video_color_space] getSupportedColorSpaces(session: camera.VideoSession): Array { - let colorSpaces: Array = []; + let colorSpaces: colorSpaceManager.ColorSpace[] = []; try { colorSpaces = session.getSupportedColorSpaces(); } catch (error) { - let err = error as BusinessError; - Logger.error(TAG_LOG, `The getSupportedColorSpaces call failed. error code: ${err.code}`); + Logger.error(TAG_LOG, `The getSupportedColorSpaces call failed. error code: ${error.message}`); } return colorSpaces; } setColorSpaceAfterCommitConfig(session: camera.VideoSession, isHdr: boolean): void { - let colorSpace: colorSpaceManager.ColorSpace = isHdr? colorSpaceManager.ColorSpace.BT2020_HLG_LIMIT : colorSpaceManager.ColorSpace.BT709_LIMIT; - let colorSpaces: Array = this.getSupportedColorSpaces(session); - let isSupportedColorSpaces = colorSpaces.indexOf(colorSpace) >= 0; - if (isSupportedColorSpaces) { - Logger.info(TAG_LOG, `setColorSpace: ${colorSpace}`); - session.setColorSpace(colorSpace); - let activeColorSpace:colorSpaceManager.ColorSpace = session.getActiveColorSpace(); - Logger.info(TAG_LOG, `activeColorSpace: ${activeColorSpace}`); - } else { + let colorSpace: colorSpaceManager.ColorSpace = + isHdr ? colorSpaceManager.ColorSpace.BT2020_HLG_LIMIT : colorSpaceManager.ColorSpace.BT709_LIMIT; + let colorSpaces: colorSpaceManager.ColorSpace[] = this.getSupportedColorSpaces(session); + if (!colorSpaces.includes(colorSpace)) { Logger.info(TAG_LOG, `colorSpace: ${colorSpace} is not support`); + return; + } + Logger.info(TAG_LOG, `setColorSpace: ${colorSpace}`); + session.setColorSpace(colorSpace); + try { + let activeColorSpace: colorSpaceManager.ColorSpace = session.getActiveColorSpace(); + Logger.info(TAG_LOG, `activeColorSpace: ${activeColorSpace}`); + } catch (error) { + Logger.error(TAG_LOG, `getActiveColorSpace Faild: ${error.message}`); } } // [Start set_video_color_space] diff --git a/entry/oh-package-lock.json5 b/entry/oh-package-lock.json5 deleted file mode 100644 index 01723a1209faf07a9d88680f47976b49b776a0e9..0000000000000000000000000000000000000000 --- a/entry/oh-package-lock.json5 +++ /dev/null @@ -1,29 +0,0 @@ -{ - "meta": { - "stableOrder": true, - "enableUnifiedLockfile": false - }, - "lockfileVersion": 3, - "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", - "specifiers": { - "camera@../camera": "camera@../camera", - "commons@../commons": "commons@../commons" - }, - "packages": { - "camera@../camera": { - "name": "camera", - "version": "1.0.0", - "resolved": "../camera", - "registryType": "local", - "dependencies": { - "commons": "file:../commons" - } - }, - "commons@../commons": { - "name": "commons", - "version": "1.0.0", - "resolved": "../commons", - "registryType": "local" - } - } -} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 0d236628a89673d6d577a18788614e47eb19e141..c03def17a669be99dd3b5d2f72a2ec59f3ee69c4 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -13,6 +13,19 @@ * limitations under the License. */ +import { sensor } from '@kit.SensorServiceKit'; +import { common } from '@kit.AbilityKit'; +import { display } from '@kit.ArkUI'; +import { curves } from '@kit.ArkUI'; +import { + CameraManager, + GridLine, + ImageReceiverManager, + LevelIndicator, + PhotoManager, + PreviewManager, + VideoManager +} from 'camera'; import CameraConstant from '../constants/Constants'; import { calCameraPoint, getClampedChildPosition, limitNumberInRange, showToast } from '../utils/CommonUtil'; import RefreshableTimer from '../utils/RefreshableTimer'; @@ -21,16 +34,7 @@ import ZoomButtonsView from '../views/ZoomButtonsView'; import ModeButtonsView from '../views/ModeButtonsView'; import SettingButtonsView from '../views/SettingButtonsView'; import OperateButtonsView from '../views/OperateButtonsView'; -import { sensor } from '@kit.SensorServiceKit'; -import { common } from '@kit.AbilityKit'; -import { display } from '@kit.ArkUI'; import PreviewViewModel from '../viewmodels/PreviewViewModel'; -import { CameraManager, - GridLine, - ImageReceiverManager, - LevelIndicator, - PhotoManager, PreviewManager, VideoManager } from 'camera'; -import { curves } from '@kit.ArkUI'; @Extend(SymbolGlyph) function funcButtonStyle() { @@ -385,9 +389,7 @@ struct Index { @Builder previewImageButton() { - SymbolGlyph( - this.isPreviewImageVisible ? $r('sys.symbol.eye') : $r('sys.symbol.eye_slash') - ) + SymbolGlyph(this.isPreviewImageVisible ? $r('sys.symbol.eye') : $r('sys.symbol.eye_slash')) .funcButtonStyle() .onClick(() => { this.isPreviewImageVisible = !this.isPreviewImageVisible; diff --git a/entry/src/main/ets/utils/PermissionManager.ets b/entry/src/main/ets/utils/PermissionManager.ets index af0c98fd9278d25d60e26f37b875c4edf2ca3a88..c65190ea0ecc9ad527f4e576bd6db88a79d4ef40 100644 --- a/entry/src/main/ets/utils/PermissionManager.ets +++ b/entry/src/main/ets/utils/PermissionManager.ets @@ -14,7 +14,7 @@ */ import { abilityAccessCtrl, Context, Permissions } from '@kit.AbilityKit'; -import { Logger } from 'commons/src/main/ets/utils/Logger'; +import { Logger } from 'commons'; const TAG = 'PermissionManager'; diff --git a/entry/src/main/ets/utils/WindowUtil.ets b/entry/src/main/ets/utils/WindowUtil.ets index bad30c83ff61c3837b08fad9b0e9c36949e2f73e..9d54a733dca804e4bf57fbf7831e3b4c50f6f284 100644 --- a/entry/src/main/ets/utils/WindowUtil.ets +++ b/entry/src/main/ets/utils/WindowUtil.ets @@ -14,7 +14,7 @@ */ import { display, window } from '@kit.ArkUI'; -import { Logger } from 'commons/src/main/ets/utils/Logger'; +import { Logger } from 'commons'; const TAG = 'WindowUtil' diff --git a/entry/src/main/ets/viewmodels/PreviewViewModel.ets b/entry/src/main/ets/viewmodels/PreviewViewModel.ets index 60fa3e0a9e08e7f3cf7b1de386597f37614d0eb2..3f87a897049e5c95fb9ceb9aeb12f23b6a70ba59 100644 --- a/entry/src/main/ets/viewmodels/PreviewViewModel.ets +++ b/entry/src/main/ets/viewmodels/PreviewViewModel.ets @@ -1,7 +1,22 @@ -import CameraConstant from '../constants/Constants'; +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 ("the License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { curves, display } from '@kit.ArkUI'; import { camera } from '@kit.CameraKit'; import WindowUtil from '../utils/WindowUtil'; -import { curves, display } from '@kit.ArkUI'; +import CameraConstant from '../constants/Constants'; export enum CameraMode { PHOTO, diff --git a/entry/src/main/ets/views/OperateButtonsView.ets b/entry/src/main/ets/views/OperateButtonsView.ets index 067d1514f13e1785b9cdb7ba7e4fcbb30427a0c2..a9a73575239b4b1bc5bdbf374519aeddf961de4a 100644 --- a/entry/src/main/ets/views/OperateButtonsView.ets +++ b/entry/src/main/ets/views/OperateButtonsView.ets @@ -15,9 +15,8 @@ import { image } from '@kit.ImageKit'; import { common } from '@kit.AbilityKit'; -import { camera } from '@kit.CameraKit'; -import PreviewViewModel from '../viewmodels/PreviewViewModel'; import { AVRecorderState, CameraManager, PhotoManager, VideoManager } from 'camera'; +import PreviewViewModel from '../viewmodels/PreviewViewModel'; @Component struct OperateButtonsView { @@ -106,7 +105,7 @@ struct OperateButtonsView { }) .justifyContent(FlexAlign.Center) .onClick(() => { - this.videoManager.start(); + this.videoManager.start(this.previewVM.isFront); }) }