From 4335ba882a100db086ad646ff1edee25ccf28cfe Mon Sep 17 00:00:00 2001 From: yygxr Date: Wed, 12 Oct 2022 05:01:26 -0700 Subject: [PATCH] fix camera session and manager test case error Signed-off-by: yygxr --- .../test/CameraManagerTest.test.ets | 90 ++++++++++--------- .../test/CameraSessionBaseTest.test.ets | 10 +-- .../test/CameraSessionExposureTest.test.ets | 2 +- .../test/CameraSessionFlashTest.test.ets | 2 +- .../test/CameraSessionFocusTest.test.ets | 2 +- ...meraSessionVideoStabilizationTest.test.ets | 2 +- .../test/CameraSessionZoomRatioTest.test.ets | 2 +- 7 files changed, 60 insertions(+), 50 deletions(-) diff --git a/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraManagerTest.test.ets b/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraManagerTest.test.ets index cb935600d..a21b4d1f5 100755 --- a/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraManagerTest.test.ets +++ b/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraManagerTest.test.ets @@ -26,40 +26,38 @@ const TAG = "CameraUnitTest: "; // Define global variables let mCameraManager; -let photoSurfaceId; -let videoSurfaceId; +let mPhotoSurfaceId; let mCameraDevicesArray; -let fdPath; -let fileAsset; -let fdNumber; +let mVideoSurface; +let mVideoRecorder; +let mFdPath; +let mFileAsset; +let mFdNumber; -// 创建视频录制的参数 -let videoProfile = { +let mVideoProfileCfg = { audioBitrate: 48000, audioChannels: 2, audioCodec: 'audio/mp4a-latm', audioSampleRate: 48000, + durationTime: 1000, fileFormat: 'mp4', videoBitrate: 48000, videoCodec: 'video/mp4v-es', videoFrameWidth: 640, videoFrameHeight: 480, videoFrameRate: 30 - } +} - let videoConfig = { +let mVideoConfig = { audioSourceType: 1, videoSourceType: 0, - profile: videoProfile, + profile: mVideoProfileCfg, url: 'file:///data/media/CameraManager.mp4', orientationHint: 0, location: { latitude: 30, longitude: 130 }, maxSize: 100, maxDuration: 500 - } - - // 创建录像输出流 - let videoRecorder +} export default function cameraManagerTest(surfaceId: any) { @@ -69,8 +67,8 @@ export default function cameraManagerTest(surfaceId: any) { console.log(TAG + 'before receiver check') if (receiver !== undefined) { console.log(TAG + 'Receiver is ok') - photoSurfaceId = await receiver.getReceivingSurfaceId() - console.log(TAG + 'Received id: ' + JSON.stringify(photoSurfaceId)) + mPhotoSurfaceId = await receiver.getReceivingSurfaceId() + console.log(TAG + 'Received id: ' + JSON.stringify(mPhotoSurfaceId)) } else { console.log(TAG + 'Receiver is not ok') } @@ -90,15 +88,15 @@ export default function cameraManagerTest(surfaceId: any) { selectionArgs: [args], } let fetchFileResult = await mediaTest.getFileAssets(fetchOp); - fileAsset = await fetchFileResult.getAllObject(); - fdNumber = await fileAsset[0].open('Rw'); - fdPath = "fd://" + fdNumber.toString(); + mFileAsset = await fetchFileResult.getAllObject(); + mFdNumber = await mFileAsset[0].open('Rw'); + mFdPath = "fd://" + mFdNumber.toString(); } } async function closeFd() { - if (fileAsset != null) { - await fileAsset[0].close(fdNumber).then(() => { + if (mFileAsset != null) { + await mFileAsset[0].close(mFdNumber).then(() => { console.info('[mediaLibrary] case close fd success'); }).catch((err) => { console.info('[mediaLibrary] case close fd failed'); @@ -108,24 +106,35 @@ export default function cameraManagerTest(surfaceId: any) { } } - async function getvideosurface() { + async function getVideoReceiveSurface() { + console.log(TAG + 'Entering getVideoReceiveSurface') await getFd('CameraManager.mp4'); - videoConfig.url = fdPath; + mVideoConfig.url = mFdPath; media.createVideoRecorder((err, recorder) => { - console.info(TAG + 'createVideoRecorder called') - videoRecorder = recorder - console.info(TAG + 'videoRecorder is :' + JSON.stringify(videoRecorder)) - console.info(TAG + 'videoRecorder.prepare called.') - videoRecorder.prepare(videoConfig, (err) => { - console.info(TAG + 'videoRecorder.prepare success.') - }) - videoRecorder.getInputSurface((err, id) => { - console.info(TAG + 'getInputSurface called') - videoSurfaceId = id - console.info(TAG + 'getInputSurface surfaceId: ' + JSON.stringify(videoSurfaceId)) - }) + console.info(TAG + 'Entering create video receiver') + mVideoRecorder = recorder + console.info(TAG + 'videoRecorder is :' + JSON.stringify(mVideoRecorder)) + console.info(TAG + 'videoRecorder.prepare called.') + mVideoRecorder.prepare(mVideoConfig, (err) => { + console.info(TAG + 'videoRecorder.prepare success.') + mVideoRecorder.getInputSurface((err, id) => { + console.info(TAG + 'getInputSurface called') + mVideoSurface = id + console.info(TAG + 'getInputSurface surfaceId: ' + JSON.stringify(mVideoSurface)) + }) + }) }) - } + console.log(TAG + 'Exit getVideoReceiveSurface') + } + + async function releaseVideoReceiveSurface() { + console.log(TAG + 'Entering releaseVideoReceiveSurface') + mVideoRecorder.release((err) => { + console.info(TAG + 'Entering release video receiver') + }) + await closeFd(); + console.log(TAG + 'Exit releaseVideoReceiveSurface') + } function sleep(ms) { console.info(TAG + "Entering sleep -> Promise constructor"); @@ -264,7 +273,7 @@ describe('CameraManagerTest', function () { await applyPermission(); await getCameraManagerInstance(); await getImageReceiverSurfaceId(); - await getvideosurface(); + await getVideoReceiveSurface(); console.info('beforeAll case'); }) @@ -278,7 +287,8 @@ describe('CameraManagerTest', function () { }) afterAll(function () { - closeFd(); + releaseVideoReceiveSurface(); + sleep(1000); console.info('afterAll case'); }) @@ -814,7 +824,7 @@ describe('CameraManagerTest', function () { expect().assertFail(); } for (let j = 0; j < photoProfilesArray.length; j++) { - mCameraManager.createPhotoOutput(photoProfilesArray[j], photoSurfaceId, async (err, data) => { + mCameraManager.createPhotoOutput(photoProfilesArray[j], mPhotoSurfaceId, async (err, data) => { if (isEmpty(data)) { console.info(TAG + "Entering SUB_MULTIMEDIA_CAMERA_CREATE_CAMERA_PHOTO_OUTPUT_CALLBACK_0100 data == null || undefined") expect().assertFail(); @@ -854,7 +864,7 @@ describe('CameraManagerTest', function () { expect().assertFail(); } for (let j = 0; j < photoProfilesArray.length; j++) { - let photoOutputPromise = await mCameraManager.createPhotoOutput(photoProfilesArray[j], photoSurfaceId); + let photoOutputPromise = await mCameraManager.createPhotoOutput(photoProfilesArray[j], mPhotoSurfaceId); if (isEmpty(photoOutputPromise)) { console.info(TAG + "Entering SUB_MULTIMEDIA_CAMERA_CREATE_CAMERA_PHOTO_OUTPUT_PROMISE_0100 photoOutputPromise == null || undefined") expect().assertFail(); diff --git a/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionBaseTest.test.ets b/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionBaseTest.test.ets index b6e686790..4fa577301 100755 --- a/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionBaseTest.test.ets +++ b/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionBaseTest.test.ets @@ -576,12 +576,12 @@ export default function cameraSessionTest(surfaceId: any) { await sleep(100); }) - afterAll(async function () { - await releaseInputs(); - await releaseOutputs(); - await releaseVideoReceiveSurface(); + afterAll(function () { + releaseInputs(); + releaseOutputs(); + releaseVideoReceiveSurface(); releaseCameraSessionInstance(); - await sleep(100); + sleep(1000); console.info('afterAll case'); }) diff --git a/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionExposureTest.test.ets b/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionExposureTest.test.ets index 85ca0bfe7..f0a8e7562 100755 --- a/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionExposureTest.test.ets +++ b/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionExposureTest.test.ets @@ -620,7 +620,7 @@ export default function cameraSessionExposureTest(surfaceId: any) { releaseOutputs(); releaseVideoReceiveSurface(); releaseCameraSessionInstance(); - sleep(100); + sleep(1000); console.info('afterAll case'); }) diff --git a/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionFlashTest.test.ets b/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionFlashTest.test.ets index 6cd9f106f..7efc3ba6a 100755 --- a/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionFlashTest.test.ets +++ b/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionFlashTest.test.ets @@ -571,7 +571,7 @@ export default function cameraSessionFlashTest(surfaceId: any) { releaseOutputs(); releaseVideoReceiveSurface(); releaseCameraSessionInstance(); - sleep(100); + sleep(1000); console.info('afterAll case'); }) diff --git a/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionFocusTest.test.ets b/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionFocusTest.test.ets index 5da2193d4..49b98d0de 100755 --- a/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionFocusTest.test.ets +++ b/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionFocusTest.test.ets @@ -616,7 +616,7 @@ export default function cameraSessionFocusTest(surfaceId: any) { releaseOutputs(); releaseVideoReceiveSurface(); releaseCameraSessionInstance(); - sleep(100); + sleep(1000); console.info('afterAll case'); }) diff --git a/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionVideoStabilizationTest.test.ets b/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionVideoStabilizationTest.test.ets index 8edfaa938..332d647ff 100755 --- a/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionVideoStabilizationTest.test.ets +++ b/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionVideoStabilizationTest.test.ets @@ -569,7 +569,7 @@ export default function cameraSessionVideoStabilizationTest(surfaceId: any) { releaseOutputs(); releaseVideoReceiveSurface(); releaseCameraSessionInstance(); - sleep(100); + sleep(1000); console.info('afterAll case'); }) diff --git a/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionZoomRatioTest.test.ets b/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionZoomRatioTest.test.ets index e93e50c85..c819950c9 100755 --- a/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionZoomRatioTest.test.ets +++ b/multimedia/camera/camera_js_standard/src/main/ets/MainAbility/test/CameraSessionZoomRatioTest.test.ets @@ -574,7 +574,7 @@ export default function cameraSessionZoomRatioTest(surfaceId: any) { releaseOutputs(); releaseVideoReceiveSurface(); releaseCameraSessionInstance(); - sleep(100); + sleep(1000); console.info('afterAll case'); }) -- GitLab