diff --git a/multimedia/media/media_js_standard/audioCodecFormat/Test.json b/multimedia/media/media_js_standard/audioCodecFormat/Test.json index 16c59c9bc7cec5dccbdfd6cbcf3b22bc63097397..74d3669dea700557b6dc43ac2a318ac9a8e177e2 100644 --- a/multimedia/media/media_js_standard/audioCodecFormat/Test.json +++ b/multimedia/media/media_js_standard/audioCodecFormat/Test.json @@ -108,9 +108,7 @@ "chmod 777 -R /data/app/el2/100/base/ohos.acts.multimedia.audio.codecformat/haps/entry/files/", "chmod 777 /data/app/el2/100/base/ohos.acts.multimedia.audio.codecformat/haps/entry/files/*", "chmod 777 -R /storage/media/100/local/files/", - "chmod 777 /storage/media/100/local/files/*", - "killall com.ohos.medialibrary.MediaScannerAbilityA", - "aa start -a MediaScannerAbility -b com.ohos.medialibrary.MediaScannerAbilityA" + "chmod 777 /storage/media/100/local/files/*" ], "teardown-command":[ ] diff --git a/multimedia/media/media_js_standard/audioCodecFormat/src/main/js/test/AudioDecoderFormatCompatibilityPromiseTest.test.js b/multimedia/media/media_js_standard/audioCodecFormat/src/main/js/test/AudioDecoderFormatCompatibilityPromiseTest.test.js index d54c5335f812e7030345ecf481bdd129268fe40d..a3f5842c41d9feb2a9b268d3b7cfd73f6a318817 100644 --- a/multimedia/media/media_js_standard/audioCodecFormat/src/main/js/test/AudioDecoderFormatCompatibilityPromiseTest.test.js +++ b/multimedia/media/media_js_standard/audioCodecFormat/src/main/js/test/AudioDecoderFormatCompatibilityPromiseTest.test.js @@ -16,7 +16,6 @@ import media from '@ohos.multimedia.media' import fileio from '@ohos.fileio' import featureAbility from '@ohos.ability.featureAbility' -import mediaLibrary from '@ohos.multimedia.mediaLibrary' import * as mediaTestBase from '../../../../../MediaTestBase.js'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' @@ -2100,18 +2099,12 @@ describe('AudioDecoderFormatCompatibilityPromise', function () { const events = require('events'); const eventEmitter = new events.EventEmitter(); const context = featureAbility.getContext(); - const mediaTest = mediaLibrary.getMediaLibrary(context); - let fileKeyObj = mediaLibrary.FileKey; + let outputCnt = 0; + let inputCnt = 0; + let frameThreshold = 10; beforeAll(async function() { console.info('beforeAll case 1'); - let permissionName1 = 'ohos.permission.MEDIA_LOCATION'; - let permissionName2 = 'ohos.permission.READ_MEDIA'; - let permissionName3 = 'ohos.permission.WRITE_MEDIA'; - let permissionNameList = [permissionName1, permissionName2, permissionName3]; - let appName = 'ohos.acts.multimedia.audio.codecformat'; - await mediaTestBase.applyPermission(appName, permissionNameList); - console.info('beforeAll case after get permission'); }) beforeEach(function() { @@ -2134,6 +2127,8 @@ describe('AudioDecoderFormatCompatibilityPromise', function () { isMp3 = false; isVorbis = false; ES_DICT = {} + outputCnt = 0; + inputCnt = 0; }) afterEach(async function() { @@ -2188,31 +2183,9 @@ describe('AudioDecoderFormatCompatibilityPromise', function () { audioDecodeProcessor = null; }, failCallback).catch(failCatch); } + inputCnt = 0; + outputCnt = 0; await closeFdRead(); - await closeFdWrite(); - } - - async function getFdWrite(pathName) { - console.info('[mediaLibrary] case start getFdWrite'); - console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName); - let mediaType = mediaLibrary.MediaType.AUDIO; - console.info('[mediaLibrary] case mediaType is ' + mediaType); - let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - console.info('[mediaLibrary] case getFdWrite publicPath is ' + publicPath); - let dataUri = await mediaTest.createAsset(mediaType, pathName, publicPath); - if (dataUri != undefined) { - let args = dataUri.id.toString(); - let fetchOp = { - selections : fileKeyObj.ID + "=?", - selectionArgs : [args], - } - let fetchWriteFileResult = await mediaTest.getFileAssets(fetchOp); - console.info('[mediaLibrary] case getFdWrite getFileAssets() success'); - fileAssetWrite = await fetchWriteFileResult.getAllObject(); - console.info('[mediaLibrary] case getFdWrite getAllObject() success'); - fdWrite = await fileAssetWrite[0].open('Rw'); - console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite); - } } async function getFdRead(readPath, done) { @@ -2221,18 +2194,6 @@ describe('AudioDecoderFormatCompatibilityPromise', function () { }) } - async function closeFdWrite() { - if (fileAssetWrite != null) { - await fileAssetWrite[0].close(fdWrite).then(() => { - console.info('[mediaLibrary] case close fdWrite success, fd is ' + fdWrite); - }).catch((err) => { - console.info('[mediaLibrary] case close fdWrite failed'); - }); - } else { - console.info('[mediaLibrary] case fileAssetWrite is null'); - } - } - async function closeFdRead() { await fileio.close(fdRead).then(() => { console.info('[fileio] case close fdRead success, fd is ' + fdRead); @@ -2297,7 +2258,8 @@ describe('AudioDecoderFormatCompatibilityPromise', function () { } frameCnt += 1; audioDecodeProcessor.pushInputData(inputobject).then(() => { - console.info("pushInputData success") + console.info("pushInputData success"); + inputCnt += 1; }) } } @@ -2307,6 +2269,7 @@ describe('AudioDecoderFormatCompatibilityPromise', function () { let outputobject = queue.shift(); if (outputobject.flags == 1) { sawOutputEOS = true; + expect(outputCnt).assertClose(inputCnt, frameThreshold); await audioDecodeProcessor.stop().then(() => { console.log("stop success"); }, failCallback).catch(failCatch); @@ -2327,7 +2290,6 @@ describe('AudioDecoderFormatCompatibilityPromise', function () { } } else{ - writeFile(outputobject.data, outputobject.length); console.log("write to file success"); } audioDecodeProcessor.freeOutputBuffer(outputobject).then(() => { @@ -2352,6 +2314,11 @@ describe('AudioDecoderFormatCompatibilityPromise', function () { }); audioDecodeProcessor.on('newOutputData', async(outBuffer) => { console.info("newOutputData"); + outputCnt += 1; + if (outputCnt == 1 && outBuffer.flags == 1) { + console.info("case error occurs! first output is EOS"); + expect().assertFail(); + } if (needGetMediaDes) { audioDecodeProcessor.getOutputMediaDescription().then((MediaDescription) => { console.log("get OutputMediaDescription success"); @@ -2447,9 +2414,6 @@ describe('AudioDecoderFormatCompatibilityPromise', function () { console.info('start test case'); let mediaDescription = config; let decodeMime = mime; - - await getFdWrite(savePath); - console.info('case getFdWrite success'); await getFdRead(readPath, done); console.info('case getFdRead success'); await media.createAudioDecoderByMime(decodeMime).then((processor) => { diff --git a/multimedia/media/media_js_standard/audioCodecFormat/src/main/js/test/AudioEncoderFormatCompatibilityPromiseTest.test.js b/multimedia/media/media_js_standard/audioCodecFormat/src/main/js/test/AudioEncoderFormatCompatibilityPromiseTest.test.js index 8fdf4ed629ead47152603a6a649e3e4bae369870..a166b59ab32c1b614d65d20feeecc7e6c556ff3c 100644 --- a/multimedia/media/media_js_standard/audioCodecFormat/src/main/js/test/AudioEncoderFormatCompatibilityPromiseTest.test.js +++ b/multimedia/media/media_js_standard/audioCodecFormat/src/main/js/test/AudioEncoderFormatCompatibilityPromiseTest.test.js @@ -16,7 +16,6 @@ import media from '@ohos.multimedia.media' import fileio from '@ohos.fileio' import featureAbility from '@ohos.ability.featureAbility' -import mediaLibrary from '@ohos.multimedia.mediaLibrary' import * as mediaTestBase from '../../../../../MediaTestBase.js'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' @@ -48,22 +47,18 @@ describe('AudioEncoderFormatCompatibilityPromise', function () { const events = require('events'); const eventEmitter = new events.EventEmitter(); const context = featureAbility.getContext(); - const mediaTest = mediaLibrary.getMediaLibrary(context); - let fileKeyObj = mediaLibrary.FileKey; + let outputCnt = 0; + let inputCnt = 0; + let frameThreshold = 10; beforeAll(async function() { console.info('beforeAll case 1'); - let permissionName1 = 'ohos.permission.MEDIA_LOCATION'; - let permissionName2 = 'ohos.permission.READ_MEDIA'; - let permissionName3 = 'ohos.permission.WRITE_MEDIA'; - let permissionNameList = [permissionName1, permissionName2, permissionName3]; - let appName = 'ohos.acts.multimedia.audio.codecformat'; - await mediaTestBase.applyPermission(appName, permissionNameList); - console.info('beforeAll case after get permission'); }) beforeEach(function() { console.info('beforeEach case'); + outputCnt = 0; + inputCnt = 0; }) afterEach(async function() { @@ -107,6 +102,8 @@ describe('AudioEncoderFormatCompatibilityPromise', function () { outputQueue = []; ES = [0, 4096] ES_LENGTH = 1000; + outputCnt = 0; + inputCnt = 0; } async function beforeTest() { @@ -139,30 +136,8 @@ describe('AudioEncoderFormatCompatibilityPromise', function () { }, failCallback).catch(failCatch); } await closeFdRead(); - await closeFdWrite(); - } - - async function getFdWrite(pathName) { - console.info('[mediaLibrary] case start getFdWrite'); - console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName); - let mediaType = mediaLibrary.MediaType.AUDIO; - console.info('[mediaLibrary] case mediaType is ' + mediaType); - let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - console.info('[mediaLibrary] case getFdWrite publicPath is ' + publicPath); - let dataUri = await mediaTest.createAsset(mediaType, pathName, publicPath); - if (dataUri != undefined) { - let args = dataUri.id.toString(); - let fetchOp = { - selections : fileKeyObj.ID + "=?", - selectionArgs : [args], - } - let fetchWriteFileResult = await mediaTest.getFileAssets(fetchOp); - console.info('[mediaLibrary] case getFdWrite getFileAssets() success'); - fileAssetWrite = await fetchWriteFileResult.getAllObject(); - console.info('[mediaLibrary] case getFdWrite getAllObject() success'); - fdWrite = await fileAssetWrite[0].open('Rw'); - console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite); - } + inputCnt = 0; + outputCnt = 0; } async function getFdRead(readPath, done) { @@ -176,29 +151,7 @@ describe('AudioEncoderFormatCompatibilityPromise', function () { console.info('[fileio] case close fdRead success, fd is ' + fdRead); }, failCallback).catch(failCatch); } - - async function closeFdWrite() { - if (fileAssetWrite != null) { - await fileAssetWrite[0].close(fdWrite).then(() => { - console.info('[mediaLibrary] case close fdWrite success, fd is ' + fdWrite); - }).catch((err) => { - console.info('[mediaLibrary] case close fdWrite failed'); - }); - } else { - console.info('[mediaLibrary] case fileAssetWrite is null'); - } - } - function writeHead(len) { - try{ - let head = new ArrayBuffer(7); - addADTStoPacket(head, len); - let res = fileio.writeSync(fdWrite, head, {length: 7}); - console.info('case fileio.write head success'); - } catch(e) { - console.info('case fileio.write head error is ' + e); - } - } function writeFile(buf, len) { try{ @@ -226,23 +179,6 @@ describe('AudioEncoderFormatCompatibilityPromise', function () { console.info('case lengthreal is :' + lengthreal); } - function addADTStoPacket(head, len) { - let view = new Uint8Array(head); - console.info("start add ADTS to Packet"); - let packetLen = len + 7; // 7: head length - let profile = 2; // 2: AAC LC - let freqIdx = rate; // 3: 48000HZ - let chanCfg = channelCount; // 1: 1 channel - console.info('rate: ' + rate); - view[0] = 0xFF; - view[1] = 0xF9; - view[2] = ((profile - 1) << 6) + (freqIdx << 2) + (chanCfg >> 2); - view[3] = ((chanCfg & 3) << 6) + (packetLen >> 11); - view[4] = (packetLen & 0x7FF) >> 3; - view[5] = ((packetLen & 7) << 5) + 0x1F; - view[6] = 0xFC; - } - async function resetWork() { resetParam(); await audioEncodeProcessor.reset().then(async() => { @@ -292,6 +228,7 @@ describe('AudioEncoderFormatCompatibilityPromise', function () { frameCnt += 1; audioEncodeProcessor.pushInputData(inputobject).then(() => { console.info('case queueInput success'); + inputCnt += 1; }); } } @@ -301,6 +238,7 @@ describe('AudioEncoderFormatCompatibilityPromise', function () { let outputObject = queue.shift(); if (outputObject.flags == 1) { sawOutputEOS = true; + expect(outputCnt).assertClose(inputCnt, frameThreshold); await doneWork(); if(sampleRateList == false && channelCountList[0] != undefined) { await aferTest(); @@ -318,7 +256,6 @@ describe('AudioEncoderFormatCompatibilityPromise', function () { return; } } else { - writeFile(outputObject.data, outputObject.length); console.info("write to file success"); } audioEncodeProcessor.freeOutputBuffer(outputObject).then(() => { @@ -343,6 +280,11 @@ describe('AudioEncoderFormatCompatibilityPromise', function () { }); audioEncodeProcessor.on('newOutputData', async(outBuffer) => { console.info('outputBufferAvailable'); + outputCnt += 1; + if (outputCnt == 1 && outBuffer.flags == 1) { + console.info("case error occurs! first output is EOS"); + expect().assertFail(); + } if (needgetMediaDes) { audioEncodeProcessor.getOutputMediaDescription().then((MediaDescription) => { console.info("get OutputMediaDescription success"); @@ -410,9 +352,6 @@ describe('AudioEncoderFormatCompatibilityPromise', function () { readPath = srcPath; needgetMediaDes = true; workdoneAtEOS = true; - - await getFdWrite(savePath); - console.info('case getFdWrite success'); await getFdRead(readPath, done); console.info('case getFdRead success'); await media.createAudioEncoderByMime('audio/mp4a-latm').then((processor) => { diff --git a/multimedia/media/media_js_standard/audioDecoder/Test.json b/multimedia/media/media_js_standard/audioDecoder/Test.json index 89e98f75deb6d120d38b28d78de6465d27317cd8..b226d97e5a96de813c1f431d4463e56dd9037c9a 100644 --- a/multimedia/media/media_js_standard/audioDecoder/Test.json +++ b/multimedia/media/media_js_standard/audioDecoder/Test.json @@ -42,9 +42,7 @@ "chmod 777 -R /data/app/el2/100/base/ohos.acts.multimedia.audio.audiodecoder/haps/entry/files/", "chmod 777 /data/app/el2/100/base/ohos.acts.multimedia.audio.audiodecoder/haps/entry/files/*", "chmod 777 -R /storage/media/100/local/files/", - "chmod 777 /storage/media/100/local/files/*", - "killall com.ohos.medialibrary.MediaScannerAbilityA", - "aa start -a MediaScannerAbility -b com.ohos.medialibrary.MediaScannerAbilityA" + "chmod 777 /storage/media/100/local/files/*" ], "teardown-command":[ ] diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFormatCallbackTest.test.js b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFormatCallbackTest.test.js index fc9f66edda42ff79a70f62f6b1cf41aaadad3643..dab41ddaf5656b814af17453b1d17c74c0256b8f 100644 --- a/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFormatCallbackTest.test.js +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFormatCallbackTest.test.js @@ -16,7 +16,6 @@ import media from '@ohos.multimedia.media' import fileio from '@ohos.fileio' import featureAbility from '@ohos.ability.featureAbility' -import mediaLibrary from '@ohos.multimedia.mediaLibrary' import * as mediaTestBase from '../../../../../MediaTestBase.js'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' @@ -46,18 +45,12 @@ describe('AudioDecoderFormatCallback', function () { let fdWrite; let fileAsset; const context = featureAbility.getContext(); - const mediaTest = mediaLibrary.getMediaLibrary(context); - let fileKeyObj = mediaLibrary.FileKey; + let outputCnt = 0; + let inputCnt = 0; + let frameThreshold = 10; beforeAll(async function() { console.info('beforeAll case 1'); - let permissionName1 = 'ohos.permission.MEDIA_LOCATION'; - let permissionName2 = 'ohos.permission.READ_MEDIA'; - let permissionName3 = 'ohos.permission.WRITE_MEDIA'; - let permissionNameList = [permissionName1, permissionName2, permissionName3]; - let appName = 'ohos.acts.multimedia.audio.audiodecoder'; - await mediaTestBase.applyPermission(appName, permissionNameList); - console.info('beforeAll case after get permission'); }) beforeEach(function() { @@ -76,6 +69,8 @@ describe('AudioDecoderFormatCallback', function () { samplerate = 44.1; isMp3 = false; isVorbis = false; + outputCnt = 0; + inputCnt = 0; }) afterEach(async function() { @@ -98,41 +93,6 @@ describe('AudioDecoderFormatCallback', function () { }) } - async function getFdWrite(pathName) { - console.info('[mediaLibrary] case start getFdWrite'); - console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName); - let mediaType = mediaLibrary.MediaType.AUDIO; - console.info('[mediaLibrary] case mediaType is ' + mediaType); - let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - console.info('[mediaLibrary] case getFdWrite publicPath is ' + publicPath); - let dataUri = await mediaTest.createAsset(mediaType, pathName, publicPath); - if (dataUri != undefined) { - let args = dataUri.id.toString(); - let fetchOp = { - selections : fileKeyObj.ID + "=?", - selectionArgs : [args], - } - let fetchWriteFileResult = await mediaTest.getFileAssets(fetchOp); - console.info('[mediaLibrary] case getFdWrite getFileAssets() success'); - fileAsset = await fetchWriteFileResult.getAllObject(); - console.info('[mediaLibrary] case getFdWrite getAllObject() success'); - fdWrite = await fileAsset[0].open('rw'); - console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite); - } - } - - async function closeFdWrite() { - if (fileAsset != null) { - await fileAsset[0].close(fdWrite).then(() => { - console.info('[mediaLibrary] case close fdWrite success, fd is ' + fdWrite); - }).catch((err) => { - console.info('[mediaLibrary] case close fdWrite failed'); - }); - } else { - console.info('[mediaLibrary] case fileAsset is null'); - } - } - function writeFile(path, buf, len) { try{ let res = fileio.writeSync(fdWrite, buf, {length: len}); @@ -192,6 +152,7 @@ describe('AudioDecoderFormatCallback', function () { frameCnt += 1; audioDecodeProcessor.pushInputData(inputobject, () => { console.info('queueInput success'); + inputCnt += 1; }) } } @@ -201,6 +162,7 @@ describe('AudioDecoderFormatCallback', function () { let outputobject = queue.shift(); if (outputobject.flags == 1) { sawOutputEOS = true; + expect(outputCnt).assertClose(inputCnt, frameThreshold); audioDecodeProcessor.stop((err) => { expect(err).assertUndefined(); console.log("stop success"); @@ -214,13 +176,11 @@ describe('AudioDecoderFormatCallback', function () { console.log("case release success"); audioDecodeProcessor = null; await fileio.close(fdRead); - await closeFdWrite(); done(); }) }) }) } else { - writeFile(savepath, outputobject.data, outputobject.length); console.log("write to file success"); } audioDecodeProcessor.freeOutputBuffer(outputobject, () => { @@ -238,6 +198,11 @@ describe('AudioDecoderFormatCallback', function () { }); audioDecodeProcessor.on('newOutputData', async(outBuffer) => { console.info("outputBufferAvailable"); + outputCnt += 1; + if (outputCnt == 1 && outBuffer.flags == 1) { + console.info("case error occurs! first output is EOS"); + expect().assertFail(); + } if (needGetMediaDes) { audioDecodeProcessor.getOutputMediaDescription((err, MediaDescription) => { console.log("get OutputMediaDescription success"); @@ -275,7 +240,6 @@ describe('AudioDecoderFormatCallback', function () { } savepath = 'format_callback_aac_01.pcm'; readpath = AUDIOPATH1; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, @@ -394,7 +358,6 @@ describe('AudioDecoderFormatCallback', function () { } savepath = 'format_callback_aac_02.pcm'; readpath = AUDIOPATH1; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, @@ -513,7 +476,6 @@ describe('AudioDecoderFormatCallback', function () { } savepath = 'format_callback_flac_01.pcm'; readpath = AUDIOPATH2; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; samplerate = 48; @@ -589,7 +551,6 @@ describe('AudioDecoderFormatCallback', function () { } savepath = 'format_callback_flac_02.pcm'; readpath = AUDIOPATH2; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; samplerate = 48; @@ -665,7 +626,6 @@ describe('AudioDecoderFormatCallback', function () { } savepath = 'format_callback_mp3_01.pcm'; readpath = AUDIOPATH3; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; isMp3 = true; @@ -728,7 +688,6 @@ describe('AudioDecoderFormatCallback', function () { } savepath = 'format_callback_mp3_02.pcm'; readpath = AUDIOPATH3; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; isMp3 = true; @@ -791,7 +750,6 @@ describe('AudioDecoderFormatCallback', function () { } savepath = 'format_callback_vorbis_01.pcm'; readpath = AUDIOPATH4; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; samplerate = 48; @@ -897,7 +855,6 @@ describe('AudioDecoderFormatCallback', function () { } savepath = 'format_callback_vorbis_02.pcm'; readpath = AUDIOPATH4; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; samplerate = 48; diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFormatPromiseTest.test.js b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFormatPromiseTest.test.js index 02f1ba4bba41e1b5085f962a6380d845d82c07cd..fa147655bc56ec3984f60382bd1190cd65fd1c23 100644 --- a/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFormatPromiseTest.test.js +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFormatPromiseTest.test.js @@ -16,7 +16,6 @@ import media from '@ohos.multimedia.media' import fileio from '@ohos.fileio' import featureAbility from '@ohos.ability.featureAbility' -import mediaLibrary from '@ohos.multimedia.mediaLibrary' import * as mediaTestBase from '../../../../../MediaTestBase.js'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' @@ -46,18 +45,12 @@ describe('AudioDecoderFormatPromise', function () { let fdWrite; let fileAsset; const context = featureAbility.getContext(); - const mediaTest = mediaLibrary.getMediaLibrary(context); - let fileKeyObj = mediaLibrary.FileKey; + let outputCnt = 0; + let inputCnt = 0; + let frameThreshold = 10; beforeAll(async function() { console.info('beforeAll case 1'); - let permissionName1 = 'ohos.permission.MEDIA_LOCATION'; - let permissionName2 = 'ohos.permission.READ_MEDIA'; - let permissionName3 = 'ohos.permission.WRITE_MEDIA'; - let permissionNameList = [permissionName1, permissionName2, permissionName3]; - let appName = 'ohos.acts.multimedia.audio.audiodecoder'; - await mediaTestBase.applyPermission(appName, permissionNameList); - console.info('beforeAll case after get permission'); }) beforeEach(function() { @@ -76,6 +69,8 @@ describe('AudioDecoderFormatPromise', function () { samplerate = 44.1; isMp3 = false; isVorbis = false; + outputCnt = 0; + inputCnt = 0; }) afterEach(async function() { @@ -108,41 +103,6 @@ describe('AudioDecoderFormatPromise', function () { }) } - async function getFdWrite(pathName) { - console.info('[mediaLibrary] case start getFdWrite'); - console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName); - let mediaType = mediaLibrary.MediaType.AUDIO; - console.info('[mediaLibrary] case mediaType is ' + mediaType); - let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - console.info('[mediaLibrary] case getFdWrite publicPath is ' + publicPath); - let dataUri = await mediaTest.createAsset(mediaType, pathName, publicPath); - if (dataUri != undefined) { - let args = dataUri.id.toString(); - let fetchOp = { - selections : fileKeyObj.ID + "=?", - selectionArgs : [args], - } - let fetchWriteFileResult = await mediaTest.getFileAssets(fetchOp); - console.info('[mediaLibrary] case getFdWrite getFileAssets() success'); - fileAsset = await fetchWriteFileResult.getAllObject(); - console.info('[mediaLibrary] case getFdWrite getAllObject() success'); - fdWrite = await fileAsset[0].open('rw'); - console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite); - } - } - - async function closeFdWrite() { - if (fileAsset != null) { - await fileAsset[0].close(fdWrite).then(() => { - console.info('[mediaLibrary] case close fdWrite success, fd is ' + fdWrite); - }).catch((err) => { - console.info('[mediaLibrary] case close fdWrite failed'); - }); - } else { - console.info('[mediaLibrary] case fileAsset is null'); - } - } - function writeFile(path, buf, len) { try{ let res = fileio.writeSync(fdWrite, buf, {length: len}); @@ -201,7 +161,8 @@ describe('AudioDecoderFormatPromise', function () { } frameCnt += 1; audioDecodeProcessor.pushInputData(inputobject).then(() => { - console.info("queueInput success") + console.info("queueInput success"); + inputCnt += 1; }) } } @@ -221,14 +182,13 @@ describe('AudioDecoderFormatPromise', function () { }, failCallback).catch(failCatch); await audioDecodeProcessor.release().then(() => { console.info('release success'); - audioDecodeProcessor = null; }, failCallback).catch(failCatch); + audioDecodeProcessor = null; + expect(outputCnt).assertClose(inputCnt, frameThreshold); await fileio.close(fdRead); - await closeFdWrite(); done(); } else{ - writeFile(savepath, outputobject.data, outputobject.length); console.log("write to file success"); } audioDecodeProcessor.freeOutputBuffer(outputobject).then(() => { @@ -246,6 +206,11 @@ describe('AudioDecoderFormatPromise', function () { }); audioDecodeProcessor.on('newOutputData', async(outBuffer) => { console.info("outputBufferAvailable"); + outputCnt += 1; + if (outputCnt == 1 && outBuffer.flags == 1) { + console.info("case error occurs! first output is EOS"); + expect().assertFail(); + } if (needGetMediaDes) { audioDecodeProcessor.getOutputMediaDescription().then((MediaDescription) => { console.log("get OutputMediaDescription success"); @@ -280,7 +245,6 @@ describe('AudioDecoderFormatPromise', function () { } savepath = 'format_promise_aac_01.pcm'; readpath = AUDIOPATH1; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, @@ -380,7 +344,6 @@ describe('AudioDecoderFormatPromise', function () { } savepath = 'format_promise_aac_02.pcm'; readpath = AUDIOPATH1; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, @@ -480,7 +443,6 @@ describe('AudioDecoderFormatPromise', function () { } savepath = 'format_promise_flac_01.pcm'; readpath = AUDIOPATH2; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; samplerate = 48; @@ -538,7 +500,6 @@ describe('AudioDecoderFormatPromise', function () { } savepath = 'format_promise_flac_02.pcm'; readpath = AUDIOPATH2; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; samplerate = 48; @@ -596,7 +557,6 @@ describe('AudioDecoderFormatPromise', function () { } savepath = 'format_promise_mp3_01.pcm'; readpath = AUDIOPATH3; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; isMp3 = true; @@ -639,7 +599,6 @@ describe('AudioDecoderFormatPromise', function () { } savepath = 'format_promise_mp3_02.pcm'; readpath = AUDIOPATH3; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; isMp3 = true; @@ -682,7 +641,6 @@ describe('AudioDecoderFormatPromise', function () { } savepath = 'format_promise_vorbis_01.pcm'; readpath = AUDIOPATH4; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; samplerate = 48; @@ -769,7 +727,6 @@ describe('AudioDecoderFormatPromise', function () { } savepath = 'format_promise_vorbis_02.pcm'; readpath = AUDIOPATH4; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; samplerate = 48; diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFuncCallbackTest.test.js b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFuncCallbackTest.test.js index 3485d6dde1793fe6955f7220b4c25fa91dce7d26..b0f88402530eca7f0f74544365baec3cd9e840ba 100644 --- a/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFuncCallbackTest.test.js +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFuncCallbackTest.test.js @@ -16,7 +16,6 @@ import media from '@ohos.multimedia.media' import fileio from '@ohos.fileio' import featureAbility from '@ohos.ability.featureAbility' -import mediaLibrary from '@ohos.multimedia.mediaLibrary' import * as mediaTestBase from '../../../../../MediaTestBase.js'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' @@ -137,18 +136,12 @@ describe('AudioDecoderFuncCallback', function () { let fdWrite; let fileAsset; const context = featureAbility.getContext(); - const mediaTest = mediaLibrary.getMediaLibrary(context); - let fileKeyObj = mediaLibrary.FileKey; + let outputCnt = 0; + let inputCnt = 0; + let frameThreshold = 10; beforeAll(async function() { console.info('beforeAll case 1'); - let permissionName1 = 'ohos.permission.MEDIA_LOCATION'; - let permissionName2 = 'ohos.permission.READ_MEDIA'; - let permissionName3 = 'ohos.permission.WRITE_MEDIA'; - let permissionNameList = [permissionName1, permissionName2, permissionName3]; - let appName = 'ohos.acts.multimedia.audio.audiodecoder'; - await mediaTestBase.applyPermission(appName, permissionNameList); - console.info('beforeAll case after get permission'); }) beforeEach(function() { @@ -259,6 +252,8 @@ describe('AudioDecoderFuncCallback', function () { 381, 410, 394, 386, 345, 345, 354, 397, 386, 375, 390, 347, 411, 381, 383, 374, 379, 380, 378, 391, 380, 339, 390, 383, 375]; ES_LENGTH = 1500; + outputCnt = 0; + inputCnt = 0; }) afterEach(async function() { @@ -291,6 +286,8 @@ describe('AudioDecoderFuncCallback', function () { sawOutputEOS = false; inputQueue = []; outputQueue = []; + outputCnt = 0; + inputCnt = 0; } async function getFdRead(readPath, done) { @@ -299,41 +296,6 @@ describe('AudioDecoderFuncCallback', function () { }) } - async function getFdWrite(pathName) { - console.info('[mediaLibrary] case start getFdWrite'); - console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName); - let mediaType = mediaLibrary.MediaType.AUDIO; - console.info('[mediaLibrary] case mediaType is ' + mediaType); - let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - console.info('[mediaLibrary] case getFdWrite publicPath is ' + publicPath); - let dataUri = await mediaTest.createAsset(mediaType, pathName, publicPath); - if (dataUri != undefined) { - let args = dataUri.id.toString(); - let fetchOp = { - selections : fileKeyObj.ID + "=?", - selectionArgs : [args], - } - let fetchWriteFileResult = await mediaTest.getFileAssets(fetchOp); - console.info('[mediaLibrary] case getFdWrite getFileAssets() success'); - fileAsset = await fetchWriteFileResult.getAllObject(); - console.info('[mediaLibrary] case getFdWrite getAllObject() success'); - fdWrite = await fileAsset[0].open('rw'); - console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite); - } - } - - async function closeFdWrite() { - if (fileAsset != null) { - await fileAsset[0].close(fdWrite).then(() => { - console.info('[mediaLibrary] case close fdWrite success, fd is ' + fdWrite); - }).catch((err) => { - console.info('[mediaLibrary] case close fdWrite failed'); - }); - } else { - console.info('[mediaLibrary] case fileAsset is null'); - } - } - function writeFile(path, buf, len) { try{ let res = fileio.writeSync(fdWrite, buf, {length: len}); @@ -407,7 +369,6 @@ describe('AudioDecoderFuncCallback', function () { console.log("case release success"); audioDecodeProcessor = null; await fileio.close(fdRead); - await closeFdWrite(); done(); }) }) @@ -444,6 +405,7 @@ describe('AudioDecoderFuncCallback', function () { frameCnt += 1; audioDecodeProcessor.pushInputData(inputobject, () => { console.info('queueInput success'); + inputCnt += 1; }) } } @@ -460,13 +422,13 @@ describe('AudioDecoderFuncCallback', function () { } else if (flushAtEOS) { await flushWork(done); } else if (workdoneAtEOS) { + expect(outputCnt).assertClose(inputCnt, frameThreshold); await doneWork(done); } else { console.info("saw output EOS"); } } else{ - writeFile(savepath, outputobject.data, outputobject.length); console.info("write to file success"); } audioDecodeProcessor.freeOutputBuffer(outputobject, () => { @@ -484,6 +446,11 @@ describe('AudioDecoderFuncCallback', function () { }); audioDecodeProcessor.on('newOutputData', async(outBuffer) => { console.info('outputBufferAvailable'); + outputCnt += 1; + if (outputCnt == 1 && outBuffer.flags == 1) { + console.info("case error occurs! first output is EOS"); + expect().assertFail(); + } if (needGetMediaDes){ audioDecodeProcessor.getOutputMediaDescription((err, MediaDescription) => { expect(err).assertUndefined(); @@ -524,7 +491,6 @@ describe('AudioDecoderFuncCallback', function () { needGetMediaDes = true; readpath = AUDIOPATH; savepath = 'audioDecode_function_callback_00.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); eventEmitter.on('getAudioDecoderCaps', () => { audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { @@ -607,7 +573,6 @@ describe('AudioDecoderFuncCallback', function () { workdoneAtEOS = true; readpath = AUDIOPATH; savepath = 'audioDecode_function_callback_01.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); eventEmitter.on('getAudioDecoderCaps', () => { audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { @@ -679,7 +644,6 @@ describe('AudioDecoderFuncCallback', function () { workdoneAtEOS = true; readpath = AUDIOPATH; savepath = 'audioDecode_function_callback_02.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); eventEmitter.on('getAudioDecoderCaps', () => { audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { @@ -749,7 +713,6 @@ describe('AudioDecoderFuncCallback', function () { flushAtEOS = true; readpath = AUDIOPATH; savepath = 'audioDecode_function_callback_03.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); eventEmitter.on('getAudioDecoderCaps', () => { @@ -808,7 +771,6 @@ describe('AudioDecoderFuncCallback', function () { } readpath = AUDIOPATH; savepath = 'audioDecode_function_callback_04.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); eventEmitter.on('getAudioDecoderCaps', () => { audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { @@ -863,7 +825,6 @@ describe('AudioDecoderFuncCallback', function () { console.info(`case release 1`); audioDecodeProcessor = null; await fileio.close(fdRead); - await closeFdWrite(); done(); }) }); @@ -895,7 +856,6 @@ describe('AudioDecoderFuncCallback', function () { eosframenum = 200; readpath = AUDIOPATH; savepath = 'audioDecode_function_callback_05.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); eventEmitter.on('getAudioDecoderCaps', () => { audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { @@ -978,7 +938,6 @@ describe('AudioDecoderFuncCallback', function () { resetAtEOS = true; readpath = AUDIOPATH; savepath = 'audioDecode_function_callback_06.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); let mediaDescription2 = { "channel_count": 1, @@ -1022,7 +981,6 @@ describe('AudioDecoderFuncCallback', function () { sleep(10000).then(async() => { resetParam(); await fileio.close(fdRead); - await closeFdWrite(); audioDecodeProcessor.configure(mediaDescription2, async(err) => { expect(err).assertUndefined(); console.info(`case configure 2`); @@ -1030,7 +988,6 @@ describe('AudioDecoderFuncCallback', function () { console.info('resetParam success, resetAtEOS IS :' + resetAtEOS) readpath = AUDIOPATH2; savepath = 'audioDecode_function_callback_06_2.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); workdoneAtEOS = true; ES = [0, 239, 302, 309, 330, 474, 684, 699, 683, 674, 647, 649, 638, 644, 640, @@ -1090,7 +1047,6 @@ describe('AudioDecoderFuncCallback', function () { needrelease = true; readpath = AUDIOPATH; savepath = 'audioDecode_function_callback_07.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); eventEmitter.on('getAudioDecoderCaps', () => { audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { @@ -1127,7 +1083,6 @@ describe('AudioDecoderFuncCallback', function () { eventEmitter.on('recreate', () => { sleep(10000).then(async() => { await fileio.close(fdRead); - await closeFdWrite(); media.createAudioDecoderByMime('audio/flac', (err, processor) => { expect(err).assertUndefined(); console.info(`case createAudioDecoder flac`); @@ -1144,7 +1099,6 @@ describe('AudioDecoderFuncCallback', function () { resetParam(); readpath = AUDIOPATH3; savepath = 'audioDecode_function_callback_07_2.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); workdoneAtEOS = true; ES = [0, 2116, 2093, 2886, 2859, 2798, 2778, 2752, 2752, 2754, 2720, 2898, 2829, diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFuncPromiseTest.test.js b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFuncPromiseTest.test.js index f08b8dcc75ff1e08477014a0b023f4ddf4b9781e..a4488194ee4d19b47bd79331411109261a62d572 100644 --- a/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFuncPromiseTest.test.js +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFuncPromiseTest.test.js @@ -16,7 +16,6 @@ import media from '@ohos.multimedia.media' import fileio from '@ohos.fileio' import featureAbility from '@ohos.ability.featureAbility' -import mediaLibrary from '@ohos.multimedia.mediaLibrary' import * as mediaTestBase from '../../../../../MediaTestBase.js'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' @@ -136,18 +135,13 @@ describe('AudioDecoderFuncPromise', function () { let fdWrite; let fileAsset; const context = featureAbility.getContext(); - const mediaTest = mediaLibrary.getMediaLibrary(context); - let fileKeyObj = mediaLibrary.FileKey; + let outputCnt = 0; + let inputCnt = 0; + let frameThreshold = 10; + beforeAll(async function() { console.info('beforeAll case 1'); - let permissionName1 = 'ohos.permission.MEDIA_LOCATION'; - let permissionName2 = 'ohos.permission.READ_MEDIA'; - let permissionName3 = 'ohos.permission.WRITE_MEDIA'; - let permissionNameList = [permissionName1, permissionName2, permissionName3]; - let appName = 'ohos.acts.multimedia.audio.audiodecoder'; - await mediaTestBase.applyPermission(appName, permissionNameList); - console.info('beforeAll case after get permission'); }) beforeEach(function() { @@ -258,6 +252,8 @@ describe('AudioDecoderFuncPromise', function () { 381, 410, 394, 386, 345, 345, 354, 397, 386, 375, 390, 347, 411, 381, 383, 374, 379, 380, 378, 391, 380, 339, 390, 383, 375]; ES_LENGTH = 1500; + outputCnt = 0; + inputCnt = 0; }) afterEach(async function() { @@ -300,6 +296,8 @@ describe('AudioDecoderFuncPromise', function () { sawOutputEOS = false; inputQueue = []; outputQueue = []; + outputCnt = 0; + inputCnt = 0; } async function getFdRead(readPath, done) { @@ -308,41 +306,6 @@ describe('AudioDecoderFuncPromise', function () { }) } - async function getFdWrite(pathName) { - console.info('[mediaLibrary] case start getFdWrite'); - console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName); - let mediaType = mediaLibrary.MediaType.AUDIO; - console.info('[mediaLibrary] case mediaType is ' + mediaType); - let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - console.info('[mediaLibrary] case getFdWrite publicPath is ' + publicPath); - let dataUri = await mediaTest.createAsset(mediaType, pathName, publicPath); - if (dataUri != undefined) { - let args = dataUri.id.toString(); - let fetchOp = { - selections : fileKeyObj.ID + "=?", - selectionArgs : [args], - } - let fetchWriteFileResult = await mediaTest.getFileAssets(fetchOp); - console.info('[mediaLibrary] case getFdWrite getFileAssets() success'); - fileAsset = await fetchWriteFileResult.getAllObject(); - console.info('[mediaLibrary] case getFdWrite getAllObject() success'); - fdWrite = await fileAsset[0].open('rw'); - console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite); - } - } - - async function closeFdWrite() { - if (fileAsset != null) { - await fileAsset[0].close(fdWrite).then(() => { - console.info('[mediaLibrary] case close fdWrite success, fd is ' + fdWrite); - }).catch((err) => { - console.info('[mediaLibrary] case close fdWrite failed'); - }); - } else { - console.info('[mediaLibrary] case fileAsset is null'); - } - } - function writeFile(path, buf, len) { try{ let res = fileio.writeSync(fdWrite, buf, {length: len}); @@ -438,6 +401,7 @@ describe('AudioDecoderFuncPromise', function () { frameCnt += 1; audioDecodeProcessor.pushInputData(inputobject).then(() => { console.info('case queueInput success'); + inputCnt += 1; }); } } @@ -455,16 +419,15 @@ describe('AudioDecoderFuncPromise', function () { } else if (flushAtEOS) { await flushWork(done); } else if (workdoneAtEOS) { + expect(outputCnt).assertClose(inputCnt, frameThreshold); await doneWork(); await fileio.close(fdRead); - await closeFdWrite(); done(); } else { console.info("saw output EOS"); } } else{ - writeFile(savapath, outputobject.data, outputobject.length); console.info("write to file success"); } audioDecodeProcessor.freeOutputBuffer(outputobject).then(() => { @@ -483,6 +446,11 @@ describe('AudioDecoderFuncPromise', function () { audioDecodeProcessor.on('newOutputData', async(outBuffer) => { console.info('outputBufferAvailable'); console.info("outputbuffer.flags: " + outBuffer.flags); + outputCnt += 1; + if (outputCnt == 1 && outBuffer.flags == 1) { + console.info("case error occurs! first output is EOS"); + expect().assertFail(); + } if (needGetMediaDes) { audioDecodeProcessor.getOutputMediaDescription().then((MediaDescription) => { console.info("get OutputMediaDescription success"); @@ -517,7 +485,6 @@ describe('AudioDecoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioDecode_function_promise_00.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); workdoneAtEOS = true; needGetMediaDes = true; @@ -577,7 +544,6 @@ describe('AudioDecoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioDecode_function_promise_01.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); eosframenum = 500; workdoneAtEOS = true; @@ -619,7 +585,6 @@ describe('AudioDecoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioDecode_function_promise_02.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); workdoneAtEOS = true; await media.createAudioDecoderByMime('audio/mp4a-latm').then((processor) => { @@ -666,7 +631,6 @@ describe('AudioDecoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioDecode_function_promise_03.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); eosframenum = 200; flushAtEOS = true; @@ -707,7 +671,6 @@ describe('AudioDecoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioDecode_function_promise_04.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); await media.createAudioDecoderByMime('audio/mp4a-latm').then((processor) => { console.info("case create createAudioDecoder success"); @@ -740,7 +703,6 @@ describe('AudioDecoderFuncPromise', function () { }, failCallback).catch(failCatch); audioDecodeProcessor = null; await fileio.close(fdRead); - await closeFdWrite(); done(); }) @@ -761,7 +723,6 @@ describe('AudioDecoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioDecode_function_promise_05.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); eosframenum = 200; await media.createAudioDecoderByMime('audio/mp4a-latm').then((processor) => { @@ -822,7 +783,6 @@ describe('AudioDecoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioDecode_function_promise_06.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); eosframenum = 200; resetAtEOS = true; @@ -849,14 +809,12 @@ describe('AudioDecoderFuncPromise', function () { }); resetParam(); await fileio.close(fdRead); - await closeFdWrite(); await audioDecodeProcessor.configure(mediaDescription2).then(() => { console.info("case configure 2 success"); resetParam(); }, failCallback).catch(failCatch); readpath = AUDIOPATH2; savepath = 'audioDecode_function_promise_06_2.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); workdoneAtEOS = true; ES = [0, 239, 302, 309, 330, 474, 684, 699, 683, 674, 647, 649, 638, 644, 640, @@ -906,7 +864,6 @@ describe('AudioDecoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioDecode_function_promise_07.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); eosframenum = 200; resetAtEOS = true; @@ -933,7 +890,6 @@ describe('AudioDecoderFuncPromise', function () { console.info("start createaudiodecoder 2"); }); await fileio.close(fdRead); - await closeFdWrite(); await media.createAudioDecoderByMime('audio/flac').then((processor) => { console.info("case create createAudioDecoder flac success"); audioDecodeProcessor = processor; @@ -944,7 +900,6 @@ describe('AudioDecoderFuncPromise', function () { }, failCallback).catch(failCatch); readpath = AUDIOPATH3; savepath = 'audioDecode_function_promise_07_2.pcm'; - await getFdWrite(savepath); await getFdRead(readpath, done); workdoneAtEOS = true; ES = [0, 2116, 2093, 2886, 2859, 2798, 2778, 2752, 2752, 2754, 2720, 2898, 2829, diff --git a/multimedia/media/media_js_standard/audioEncoder/Test.json b/multimedia/media/media_js_standard/audioEncoder/Test.json index 33c0307e33ac0e3a6894b3f15edea73e00dcc277..85cdfb43d82b55323821774548d2848911a59fdf 100644 --- a/multimedia/media/media_js_standard/audioEncoder/Test.json +++ b/multimedia/media/media_js_standard/audioEncoder/Test.json @@ -38,9 +38,7 @@ "chmod 777 -R /data/app/el2/100/base/ohos.acts.multimedia.audio.audioencoder/haps/entry/files/", "chmod 777 /data/app/el2/100/base/ohos.acts.multimedia.audio.audioencoder/haps/entry/files/*", "chmod 777 -R /storage/media/100/local/files/", - "chmod 777 /storage/media/100/local/files/*", - "killall com.ohos.medialibrary.MediaScannerAbilityA", - "aa start -a MediaScannerAbility -b com.ohos.medialibrary.MediaScannerAbilityA" + "chmod 777 /storage/media/100/local/files/*" ], "teardown-command":[ ] diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderFuncCallbackTest.test.js b/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderFuncCallbackTest.test.js index 3b2f3fdebb78e298b26a4e87ed188b51f9eb703c..cdfaef1b20e5b5a3c62ea76d2007183b56206729 100644 --- a/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderFuncCallbackTest.test.js +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderFuncCallbackTest.test.js @@ -16,7 +16,6 @@ import media from '@ohos.multimedia.media' import fileio from '@ohos.fileio' import featureAbility from '@ohos.ability.featureAbility' -import mediaLibrary from '@ohos.multimedia.mediaLibrary' import * as mediaTestBase from '../../../../../MediaTestBase.js'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' @@ -45,18 +44,12 @@ describe('AudioEncoderFuncCallback', function () { let fdWrite; let fileAsset; const context = featureAbility.getContext(); - const mediaTest = mediaLibrary.getMediaLibrary(context); - let fileKeyObj = mediaLibrary.FileKey; + let outputCnt = 0; + let inputCnt = 0; + let frameThreshold = 10; beforeAll(async function() { console.info('beforeAll case 1'); - let permissionName1 = 'ohos.permission.MEDIA_LOCATION'; - let permissionName2 = 'ohos.permission.READ_MEDIA'; - let permissionName3 = 'ohos.permission.WRITE_MEDIA'; - let permissionNameList = [permissionName1, permissionName2, permissionName3]; - let appName = 'ohos.acts.multimedia.audio.audioencoder'; - await mediaTestBase.applyPermission(appName, permissionNameList); - console.info('beforeAll case after get permission'); }) beforeEach(function() { @@ -77,6 +70,8 @@ describe('AudioEncoderFuncCallback', function () { inputQueue = []; outputQueue = []; ES_LENGTH = 1500; + outputCnt = 0; + inputCnt = 0; }) afterEach(async function() { @@ -108,6 +103,8 @@ describe('AudioEncoderFuncCallback', function () { sawOutputEOS = false; inputQueue = []; outputQueue = []; + outputCnt = 0; + inputCnt = 0; } async function getFdRead(readPath, done) { @@ -116,41 +113,6 @@ describe('AudioEncoderFuncCallback', function () { }) } - async function getFdWrite(pathName) { - console.info('[mediaLibrary] case start getFdWrite'); - console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName); - let mediaType = mediaLibrary.MediaType.AUDIO; - console.info('[mediaLibrary] case mediaType is ' + mediaType); - let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - console.info('[mediaLibrary] case getFdWrite publicPath is ' + publicPath); - let dataUri = await mediaTest.createAsset(mediaType, pathName, publicPath); - if (dataUri != undefined) { - let args = dataUri.id.toString(); - let fetchOp = { - selections : fileKeyObj.ID + "=?", - selectionArgs : [args], - } - let fetchWriteFileResult = await mediaTest.getFileAssets(fetchOp); - console.info('[mediaLibrary] case getFdWrite getFileAssets() success'); - fileAsset = await fetchWriteFileResult.getAllObject(); - console.info('[mediaLibrary] case getFdWrite getAllObject() success'); - fdWrite = await fileAsset[0].open('rw'); - console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite); - } - } - - async function closeFdWrite() { - if (fileAsset != null) { - await fileAsset[0].close(fdWrite).then(() => { - console.info('[mediaLibrary] case close fdWrite success, fd is ' + fdWrite); - }).catch((err) => { - console.info('[mediaLibrary] case close fdWrite failed'); - }); - } else { - console.info('[mediaLibrary] case fileAsset is null'); - } - } - function readFile(path) { console.info('case read file start execution'); try{ @@ -168,18 +130,6 @@ describe('AudioEncoderFuncCallback', function () { console.info('case lengthreal is :' + lengthreal); } - function writeHead(path, len) { - console.info('case writeFile buffer.length is: ' + len); - try{ - let head = new ArrayBuffer(7); - addADTStoPacket(head, len); - let res = fileio.writeSync(fdWrite, head, {length: 7}); - console.info('case fileio.write head success'); - } catch(e) { - console.info('case fileio.write head error is ' + e); - } - } - function writeFile(path, buf, len) { try{ let res = fileio.writeSync(fdWrite, buf, {length: len}); @@ -189,22 +139,6 @@ describe('AudioEncoderFuncCallback', function () { } } - function addADTStoPacket(head, len) { - let view = new Uint8Array(head); - console.info("start add ADTS to Packet"); - let packetLen = len + 7; // 7: head length - let profile = 2; // 2: AAC LC - let freqIdx = 4; // 4: 44100HZ - let chanCfg = 2; // 2: 2 channel - view[0] = 0xFF; - view[1] = 0xF9; - view[2] = ((profile - 1) << 6) + (freqIdx << 2) + (chanCfg >> 2); - view[3] = ((chanCfg & 3) << 6) + (packetLen >> 11); - view[4] = (packetLen & 0x7FF) >> 3; - view[5] = ((packetLen & 7) << 5) + 0x1F; - view[6] = 0xFC; - } - async function stopWork() { audioEncodeProcessor.stop((err) => { expect(err).assertUndefined(); @@ -251,7 +185,6 @@ describe('AudioEncoderFuncCallback', function () { console.log("case release success"); audioEncodeProcessor = null; await fileio.close(fdRead); - await closeFdWrite(); done(); }) }) @@ -287,6 +220,7 @@ describe('AudioEncoderFuncCallback', function () { frameCnt += 1; audioEncodeProcessor.pushInputData(inputobject, () => { console.info('queueInput success'); + inputCnt += 1; }) } } @@ -303,13 +237,13 @@ describe('AudioEncoderFuncCallback', function () { } else if (flushAtEOS) { await flushWork(done); } else if (workdoneAtEOS) { + expect(outputCnt).assertClose(inputCnt, frameThreshold); await doneWork(done); } else { console.info("sawOutputEOS = true"); } } else{ - writeFile(savepath, outputobject.data, outputobject.length); console.info("write to file success"); } audioEncodeProcessor.freeOutputBuffer(outputobject, () => { @@ -327,6 +261,11 @@ describe('AudioEncoderFuncCallback', function () { }); audioEncodeProcessor.on('newOutputData', async(outBuffer) => { console.info('case outputBufferAvailable'); + outputCnt += 1; + if (outputCnt == 1 && outBuffer.flags == 1) { + console.info("case error occurs! first output is EOS"); + expect().assertFail(); + } if (needGetMediaDes) { audioEncodeProcessor.getOutputMediaDescription((err, MediaDescription) => { expect(err).assertUndefined(); @@ -368,7 +307,6 @@ describe('AudioEncoderFuncCallback', function () { } readpath = AUDIOPATH; savepath = 'audioEncode_function_callback_00.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); needGetMediaDes = true; workdoneAtEOS = true; @@ -450,7 +388,6 @@ describe('AudioEncoderFuncCallback', function () { } readpath = AUDIOPATH; savepath = 'audioEncode_function_callback_01.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); eosframenum = 500; workdoneAtEOS = true; @@ -510,7 +447,6 @@ describe('AudioEncoderFuncCallback', function () { } readpath = AUDIOPATH; savepath = 'audioEncode_function_callback_02.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); workdoneAtEOS = true; eventEmitter.on('getAudioEncoderCaps', () => { @@ -579,7 +515,6 @@ describe('AudioEncoderFuncCallback', function () { } readpath = AUDIOPATH; savepath = 'audioEncode_function_callback_03.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); eosframenum = 500; flushAtEOS = true; @@ -639,7 +574,6 @@ describe('AudioEncoderFuncCallback', function () { } readpath = AUDIOPATH; savepath = 'audioEncode_function_callback_04.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); eventEmitter.on('getAudioEncoderCaps', () => { audioEncodeProcessor.getAudioEncoderCaps((err, Audiocaps) => { @@ -694,7 +628,6 @@ describe('AudioEncoderFuncCallback', function () { console.info(`case release 1`); audioEncodeProcessor = null; await fileio.close(fdRead); - await closeFdWrite(); done(); }) }); @@ -725,7 +658,6 @@ describe('AudioEncoderFuncCallback', function () { } readpath = AUDIOPATH; savepath = 'audioEncode_function_callback_05.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); eosframenum = 100; eventEmitter.on('getAudioEncoderCaps', () => { @@ -807,7 +739,6 @@ describe('AudioEncoderFuncCallback', function () { } readpath = AUDIOPATH; savepath = 'audioEncode_function_callback_06.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); eosframenum = 100; resetAtEOS = true; @@ -853,14 +784,12 @@ describe('AudioEncoderFuncCallback', function () { sleep(10000).then(async() => { resetParam(); await fileio.close(fdRead); - await closeFdWrite(); audioEncodeProcessor.configure(mediaDescription2, async(err) => { expect(err).assertUndefined(); console.info(`case configure 2`); resetParam(); readpath = AUDIOPATH; savepath = 'audioEncode_function_callback_06_2.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); workdoneAtEOS = true; hasreconfigured = true; diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderFuncPromiseTest.test.js b/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderFuncPromiseTest.test.js index bc1408259bb535ef21354cce4abd62209510d435..8053f5ea080d3426541616b5d2e5a227cf193320 100644 --- a/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderFuncPromiseTest.test.js +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderFuncPromiseTest.test.js @@ -16,7 +16,6 @@ import media from '@ohos.multimedia.media' import fileio from '@ohos.fileio' import featureAbility from '@ohos.ability.featureAbility' -import mediaLibrary from '@ohos.multimedia.mediaLibrary' import * as mediaTestBase from '../../../../../MediaTestBase.js'; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' @@ -45,18 +44,13 @@ describe('AudioEncoderFuncPromise', function () { let fdWrite; let fileAsset; const context = featureAbility.getContext(); - const mediaTest = mediaLibrary.getMediaLibrary(context); - let fileKeyObj = mediaLibrary.FileKey; + let outputCnt = 0; + let inputCnt = 0; + let frameThreshold = 10; + beforeAll(async function() { console.info('beforeAll case 1'); - let permissionName1 = 'ohos.permission.MEDIA_LOCATION'; - let permissionName2 = 'ohos.permission.READ_MEDIA'; - let permissionName3 = 'ohos.permission.WRITE_MEDIA'; - let permissionNameList = [permissionName1, permissionName2, permissionName3]; - let appName = 'ohos.acts.multimedia.audio.audioencoder'; - await mediaTestBase.applyPermission(appName, permissionNameList); - console.info('beforeAll case after get permission'); }) beforeEach(function() { @@ -77,6 +71,8 @@ describe('AudioEncoderFuncPromise', function () { inputQueue = []; outputQueue = []; ES_LENGTH = 1500; + outputCnt = 0; + inputCnt = 0; }) afterEach(async function() { @@ -118,6 +114,8 @@ describe('AudioEncoderFuncPromise', function () { sawOutputEOS = false; inputQueue = []; outputQueue = []; + outputCnt = 0; + inputCnt = 0; } async function getFdRead(readPath, done) { @@ -125,52 +123,7 @@ describe('AudioEncoderFuncPromise', function () { fdRead = fdNumber; }) } - - async function getFdWrite(pathName) { - console.info('[mediaLibrary] case start getFdWrite'); - console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName); - let mediaType = mediaLibrary.MediaType.AUDIO; - console.info('[mediaLibrary] case mediaType is ' + mediaType); - let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_AUDIO); - console.info('[mediaLibrary] case getFdWrite publicPath is ' + publicPath); - let dataUri = await mediaTest.createAsset(mediaType, pathName, publicPath); - if (dataUri != undefined) { - let args = dataUri.id.toString(); - let fetchOp = { - selections : fileKeyObj.ID + "=?", - selectionArgs : [args], - } - let fetchWriteFileResult = await mediaTest.getFileAssets(fetchOp); - console.info('[mediaLibrary] case getFdWrite getFileAssets() success'); - fileAsset = await fetchWriteFileResult.getAllObject(); - console.info('[mediaLibrary] case getFdWrite getAllObject() success'); - fdWrite = await fileAsset[0].open('rw'); - console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite); - } - } - - async function closeFdWrite() { - if (fileAsset != null) { - await fileAsset[0].close(fdWrite).then(() => { - console.info('[mediaLibrary] case close fdWrite success, fd is ' + fdWrite); - }).catch((err) => { - console.info('[mediaLibrary] case close fdWrite failed'); - }); - } else { - console.info('[mediaLibrary] case fileAsset is null'); - } - } - - function readFile(path) { - console.info('read file start execution'); - try{ - console.info('filepath: ' + path); - readStreamSync = fileio.fdopenStreamSync(fdRead, 'rb'); - }catch(e) { - console.info(e); - } - } - + function getContent(buf, len) { console.info("case start get content"); let lengthreal = -1; @@ -178,17 +131,6 @@ describe('AudioEncoderFuncPromise', function () { console.info('case lengthreal is :' + lengthreal); } - function writeHead(path, len) { - try{ - let head = new ArrayBuffer(7); - addADTStoPacket(head, len); - let res = fileio.writeSync(fdWrite, head, {length: 7}); - console.info('case fileio.write head success'); - } catch(e) { - console.info('case fileio.write head error is ' + e); - } - } - function writeFile(path, buf, len) { try{ let res = fileio.writeSync(fdWrite, buf, {length: len}); @@ -198,22 +140,6 @@ describe('AudioEncoderFuncPromise', function () { } } - function addADTStoPacket(head, len) { - let view = new Uint8Array(head); - console.info("start add ADTS to Packet"); - let packetLen = len + 7; // 7: head length - let profile = 2; // 2: AAC LC - let freqIdx = 4; // 4: 44100HZ - let chanCfg = 2; // 2: 2 channel - view[0] = 0xFF; - view[1] = 0xF9; - view[2] = ((profile - 1) << 6) + (freqIdx << 2) + (chanCfg >> 2); - view[3] = ((chanCfg & 3) << 6) + (packetLen >> 11); - view[4] = (packetLen & 0x7FF) >> 3; - view[5] = ((packetLen & 7) << 5) + 0x1F; - view[6] = 0xFC; - } - async function stopWork() { await audioEncodeProcessor.stop().then(() => { console.info("case stop success") @@ -288,6 +214,7 @@ describe('AudioEncoderFuncPromise', function () { frameCnt += 1; audioEncodeProcessor.pushInputData(inputobject).then(() => { console.info('case queueInput success'); + inputCnt += 1; }); } } @@ -304,16 +231,15 @@ describe('AudioEncoderFuncPromise', function () { } else if (flushAtEOS) { await flushWork(done); } else if (workdoneAtEOS) { + expect(outputCnt).assertClose(inputCnt, frameThreshold); await doneWork(); await fileio.close(fdRead); - await closeFdWrite(); done(); } else { console.info('sawOutputEOS = true'); } } else{ - writeFile(savepath, outputobject.data, outputobject.length); console.info("write to file success"); } audioEncodeProcessor.freeOutputBuffer(outputobject).then(() => { @@ -331,6 +257,11 @@ describe('AudioEncoderFuncPromise', function () { }); audioEncodeProcessor.on('newOutputData', async(outBuffer) => { console.info('outputBufferAvailable'); + outputCnt += 1; + if (outputCnt == 1 && outBuffer.flags == 1) { + console.info("case error occurs! first output is EOS"); + expect().assertFail(); + } if (needgetMediaDes) { audioEncodeProcessor.getOutputMediaDescription().then((MediaDescription) => { console.info("get OutputMediaDescription success"); @@ -369,7 +300,6 @@ describe('AudioEncoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioEncode_function_promise_00.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); needgetMediaDes = true; workdoneAtEOS = true; @@ -433,7 +363,6 @@ describe('AudioEncoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioEncode_function_promise_01.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); eosframenum = 500; workdoneAtEOS = true; @@ -474,7 +403,6 @@ describe('AudioEncoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioEncode_function_promise_02.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); workdoneAtEOS = true; await media.createAudioEncoderByMime('audio/mp4a-latm').then((processor) => { @@ -521,7 +449,6 @@ describe('AudioEncoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioEncode_function_promise_03.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); eosframenum = 500; flushAtEOS = true; @@ -562,7 +489,6 @@ describe('AudioEncoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioEncode_function_promise_04.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); await media.createAudioEncoderByMime('audio/mp4a-latm').then((processor) => { console.info("case create createAudioEncoder success"); @@ -595,7 +521,6 @@ describe('AudioEncoderFuncPromise', function () { }, failCallback).catch(failCatch); audioEncodeProcessor = null; await fileio.close(fdRead); - await closeFdWrite(); done(); }) @@ -616,7 +541,6 @@ describe('AudioEncoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioEncode_function_promise_05.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); eosframenum = 100; await media.createAudioEncoderByMime('audio/mp4a-latm').then((processor) => { @@ -672,7 +596,6 @@ describe('AudioEncoderFuncPromise', function () { } readpath = AUDIOPATH; savepath = 'audioEncode_function_promise_06.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); eosframenum = 100; resetAtEOS = true; @@ -704,14 +627,12 @@ describe('AudioEncoderFuncPromise', function () { }); resetParam(); await fileio.close(fdRead); - await closeFdWrite(); await audioEncodeProcessor.configure(mediaDescription2).then(() => { console.info("configure 2 success"); resetParam(); }, failCallback).catch(failCatch); readpath = AUDIOPATH; savepath = 'audioEncode_function_promise_06_2.aac'; - await getFdWrite(savepath); await getFdRead(readpath, done); workdoneAtEOS = true; setCallback(savepath, done); diff --git a/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderFuncCallbackTest.test.js b/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderFuncCallbackTest.test.js index 6f11543d5d2054ea394afc0af3f8fab2e595189a..830e07122ce98f4b12aa513a3269846b2712d628 100644 --- a/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderFuncCallbackTest.test.js +++ b/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderFuncCallbackTest.test.js @@ -94,6 +94,9 @@ describe('VideoDecoderFuncCallbackTest', function () { 232, 250, 248, 281, 219, 243, 293, 287, 253, 328, 3719]; let fdRead; let readpath; + let outputCnt = 0; + let inputCnt = 0; + let frameThreshold = 10; beforeAll(function() { console.info('beforeAll case'); @@ -113,6 +116,8 @@ describe('VideoDecoderFuncCallbackTest', function () { isCodecData = false; inputEosFlag = false; surfaceID = globalThis.value; + outputCnt = 0; + inputCnt = 0; }) afterEach(async function() { @@ -215,6 +220,7 @@ describe('VideoDecoderFuncCallbackTest', function () { videoDecodeProcessor.pushInputData(inputObject, (err) => { if (typeof (err) == 'undefined') { console.info('in case: queueInput success '); + inputCnt += 1; } else { console.info(`in case queueInput err called,errMessage is ${error.message}`); } @@ -246,6 +252,11 @@ describe('VideoDecoderFuncCallbackTest', function () { videoDecodeProcessor.on('newOutputData', async (outBuffer) => { console.info('in case: outputBufferAvailable outBuffer.index: '+ outBuffer.index); + outputCnt += 1; + if (outputCnt == 1 && outBuffer.flags == 1) { + console.info("case error occurs! first output is EOS"); + expect().assertFail(); + } videoDecodeProcessor.getOutputMediaDescription((err, MediaDescription) => { expect(err).assertUndefined(); console.info('get outputMediaDescription : ' + MediaDescription); @@ -338,6 +349,7 @@ describe('VideoDecoderFuncCallbackTest', function () { expect(err).assertUndefined(); console.info('in case : release success'); videoDecodeProcessor = null; + expect(outputCnt).assertClose(inputCnt, frameThreshold); done(); }); }); @@ -348,7 +360,7 @@ describe('VideoDecoderFuncCallbackTest', function () { * @tc.desc : start-> EOS -> stop -> reset * @tc.size : MediumTest * @tc.type : Function test - * @tc.level : Level0 + * @tc.level : Level0s */ it('SUB_MEDIA_VIDEO_DECODER_H264_CALLBACK_0100', 0, async function (done) { ES_FRAME_SIZE = H264_FRAME_SIZE_60FPS_320; diff --git a/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderFuncPromiseTest.test.js b/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderFuncPromiseTest.test.js index 44203acdc93b7962b085050d2ed38ec67e0cb52e..db620f797a3530fc5ea33eb935497148d57bc3a7 100644 --- a/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderFuncPromiseTest.test.js +++ b/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderFuncPromiseTest.test.js @@ -94,6 +94,9 @@ describe('VideoDecoderFuncPromiseTest', function () { 232, 250, 248, 281, 219, 243, 293, 287, 253, 328, 3719]; let fdRead; let readpath; + let outputCnt = 0; + let inputCnt = 0; + let frameThreshold = 10; beforeAll(function() { console.info('beforeAll case'); @@ -113,6 +116,8 @@ describe('VideoDecoderFuncPromiseTest', function () { isCodecData = false; inputEosFlag = false; surfaceID = globalThis.value; + outputCnt = 0; + inputCnt = 0; }) afterEach(async function() { @@ -210,6 +215,7 @@ describe('VideoDecoderFuncPromiseTest', function () { } videoDecodeProcessor.pushInputData(inputObject).then(() => { console.info('in case: queueInput success '); + inputCnt += 1; }, failCallback).catch(failCatch); } @@ -234,6 +240,11 @@ describe('VideoDecoderFuncPromiseTest', function () { videoDecodeProcessor.on('newOutputData', async (outBuffer) => { console.info('in case: outputBufferAvailable outBuffer.index: '+ outBuffer.index); + outputCnt += 1; + if (outputCnt == 1 && outBuffer.flags == 1) { + console.info("case error occurs! first output is EOS"); + expect().assertFail(); + } videoDecodeProcessor.getOutputMediaDescription().then((MediaDescription) => { console.info('get outputMediaDescription : ' + MediaDescription); }, failCallback).catch(failCatch); @@ -308,6 +319,7 @@ describe('VideoDecoderFuncPromiseTest', function () { console.info('in case : release success'); }, failCallback).catch(failCatch); videoDecodeProcessor = null; + expect(outputCnt).assertClose(inputCnt, frameThreshold); console.info('in case : done'); done(); }); diff --git a/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareFuncCallbackTest.test.js b/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareFuncCallbackTest.test.js index ca1bb92fc95c0f9136619edb604cc9b75eec0b07..9e9c601902ab74abe462673a98cc4b6b384fdc95 100644 --- a/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareFuncCallbackTest.test.js +++ b/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareFuncCallbackTest.test.js @@ -109,6 +109,9 @@ describe('VideoSoftwareDecoderFuncCallbackTest', function () { 232, 250, 248, 281, 219, 243, 293, 287, 253, 328, 3719]; let fdRead; let readpath; + let outputCnt = 0; + let inputCnt = 0; + let frameThreshold = 10; beforeAll(function() { console.info('beforeAll case'); @@ -128,6 +131,8 @@ describe('VideoSoftwareDecoderFuncCallbackTest', function () { isCodecData = false; inputEosFlag = false; surfaceID = globalThis.value; + outputCnt = 0; + inputCnt = 0; }) afterEach(async function() { @@ -219,7 +224,7 @@ describe('VideoSoftwareDecoderFuncCallbackTest', function () { videoDecodeProcessor.pushInputData(inputObject, (err) => { if (typeof (err) == 'undefined') { console.info('in case: queueInput success '); - + inputCnt += 1; } else { console.info(`in case queueInput err called,errMessage is ${error.message}`); } @@ -251,6 +256,11 @@ describe('VideoSoftwareDecoderFuncCallbackTest', function () { videoDecodeProcessor.on('newOutputData', async (outBuffer) => { console.info('in case: outputBufferAvailable outBuffer.index: '+ outBuffer.index); + outputCnt += 1; + if (outputCnt == 1 && outBuffer.flags == 1) { + console.info("case error occurs! first output is EOS"); + expect().assertFail(); + } dequeueOutputs(nextStep, outBuffer); }); @@ -311,6 +321,7 @@ describe('VideoSoftwareDecoderFuncCallbackTest', function () { expect(err).assertUndefined(); console.info('in case : release success'); videoDecodeProcessor = null; + expect(outputCnt).assertClose(inputCnt, frameThreshold); done(); }); }); diff --git a/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareFuncPromiseTest.test.js b/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareFuncPromiseTest.test.js index 79fc91f898155b95ca171df3fc42d1e7a3610f9d..cccf57fa7778e04ea663587e78ea289b1c271bf3 100644 --- a/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareFuncPromiseTest.test.js +++ b/multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareFuncPromiseTest.test.js @@ -110,6 +110,9 @@ describe('VideoSoftwareDecoderFuncPromiseTest', function () { 232, 250, 248, 281, 219, 243, 293, 287, 253, 328, 3719]; let fdRead; let readpath; + let outputCnt = 0; + let inputCnt = 0; + let frameThreshold = 10; beforeAll(function() { console.info('beforeAll case'); @@ -129,6 +132,8 @@ describe('VideoSoftwareDecoderFuncPromiseTest', function () { isCodecData = false; inputEosFlag = false; surfaceID = globalThis.value; + outputCnt = 0; + inputCnt = 0; }) afterEach(async function() { @@ -219,6 +224,7 @@ describe('VideoSoftwareDecoderFuncPromiseTest', function () { } videoDecodeProcessor.pushInputData(inputObject).then(() => { console.info('in case: queueInput success '); + inputCnt += 1; }, failCallback).catch(failCatch); } @@ -243,6 +249,11 @@ describe('VideoSoftwareDecoderFuncPromiseTest', function () { videoDecodeProcessor.on('newOutputData', async (outBuffer) => { console.info('in case: outputBufferAvailable outBuffer.index: '+ outBuffer.index); + outputCnt += 1; + if (outputCnt == 1 && outBuffer.flags == 1) { + console.info("case error occurs! first output is EOS"); + expect().assertFail(); + } dequeueOutputs(nextStep, outBuffer); }); @@ -302,6 +313,7 @@ describe('VideoSoftwareDecoderFuncPromiseTest', function () { console.info('in case : release success'); }, failCallback).catch(failCatch); videoDecodeProcessor = null; + expect(outputCnt).assertClose(inputCnt, frameThreshold); console.info('in case : done'); done(); });