diff --git a/multimedia/BUILD.gn b/multimedia/BUILD.gn index fcb389f05e38723aa77d4414bddbf44694f2ed80..108d7fb9c179d1b53abf54ffac123e9f33acff72 100755 --- a/multimedia/BUILD.gn +++ b/multimedia/BUILD.gn @@ -20,6 +20,9 @@ group("multimedia") { "audio/audio_js_standard/audioManager:audio_manager_js_hap", "media/media_js_standard/audioPlayer:audio_player_js_hap", "media/media_js_standard/audioRecorder:audio_recorder_js_hap", + + #"media/media_js_standard/audioDecoder:audio_decoder_js_hap", + #"media/media_js_standard/audioEncoder:audio_encoder_js_hap", ] } else { deps = [ diff --git a/multimedia/media/media_js_standard/audioDecoder/BUILD.gn b/multimedia/media/media_js_standard/audioDecoder/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..38041cdb4994534e142bf5d9bae25aeed6e767c6 --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/BUILD.gn @@ -0,0 +1,32 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("audio_decoder_js_hap") { + hap_profile = "./src/main/config.json" + js2abc = true + deps = [ + ":audio_decoder_js_assets", + ":audio_decoder_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsAudioDecoderJsTest" +} +ohos_js_assets("audio_decoder_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("audio_decoder_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/multimedia/media/media_js_standard/audioDecoder/Test.json b/multimedia/media/media_js_standard/audioDecoder/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..12d42f63a93887df671c96c107c57a9a5169bcd4 --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/Test.json @@ -0,0 +1,43 @@ +{ + "description": "Configuration for audioDecoder Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "2000000", + "package": "ohos.acts.multimedia.audio.audiodecoder", + "shell-timeout": "60000" + }, + "kits": [ + { + "type": "PushKit", + "pre-push": [ + ], + "push": [ + "./resource/audio/AAC_48000_32_1.aac ->/data/media/", + "./resource/audio/AAC_16000_1.aac ->/data/media/", + "./resource/audio/FLAC_48000_32_1.flac ->/data/media/", + "./resource/audio/mp3.es ->/data/media/", + "./resource/audio/vorbis.es ->/data/media/" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "rm -R /data/media/results", + "chmod 777 -R /data/media", + "chmod 777 /data/media/*", + "mkdir /data/media/results", + "setenforce 0" + ], + "teardown-command":[ + "setenforce 1" + ] + }, + { + "test-file-name": [ + "ActsAudioDecoderJsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/multimedia/media/media_js_standard/audioDecoder/signature/openharmony_sx.p7b b/multimedia/media/media_js_standard/audioDecoder/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/multimedia/media/media_js_standard/audioDecoder/signature/openharmony_sx.p7b differ diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/config.json b/multimedia/media/media_js_standard/audioDecoder/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..ac9aca6e85c6993d4aaf474e07f56b6063638fd1 --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/config.json @@ -0,0 +1,74 @@ +{ + "app": { + "apiVersion": { + "compatible": 6, + "releaseType": "Beta1", + "target": 7 + }, + "vendor": "acts", + "bundleName": "ohos.acts.multimedia.audio.audiodecoder", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": { + "default": { + "debug": true + } + }, + "module": { + "abilities": [ + { + "iconId": 16777218, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "descriptionId": 16777217, + "visible": true, + "labelId": 16777216, + "icon": "$media:icon", + "name": "ohos.acts.multimedia.audio.audiodecoder.MainAbility", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "homeAbility": true, + "launchType": "standard" + } + ], + "deviceType": [ + "phone", + "tablet", + "tv", + "wearable" + ], + "mainAbility": "ohos.acts.multimedia.audio.audiodecoder.MainAbility", + "distro": { + "moduleType": "entry", + "installationFree": false, + "deliveryWithInstall": true, + "moduleName": "entry" + }, + "package": "ohos.acts.multimedia.audio.audiodecoder", + "name": ".MyApplication", + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": true + } + } + ] + } +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/app.js b/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..e423f4bce4698ec1d7dc86c3eea3990a5e7b1085 --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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. + */ + +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/i18n/en-US.json b/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/i18n/zh-CN.json b/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/pages/index/index.css b/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..5bd7567028568bd522193b2519d545ca6dcf397d --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/pages/index/index.css @@ -0,0 +1,46 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + width: 100%; + height: 100%; +} + +.title { + font-size: 40px; + color: #000000; + opacity: 0.9; +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} + +@media screen and (device-type: wearable) { + .title { + font-size: 28px; + color: #FFFFFF; + } +} + +@media screen and (device-type: tv) { + .container { + background-image: url("/common/images/Wallpaper.png"); + background-size: cover; + background-repeat: no-repeat; + background-position: center; + } + + .title { + font-size: 100px; + color: #FFFFFF; + } +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/pages/index/index.hml b/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/pages/index/index.js b/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..a0719cee588ac4b0f56efbf784b19647bc6645de --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/default/pages/index/index.js @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2021 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 {Core, ExpectExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + const configService = core.getDefaultService('config') + this.timeout = 60000 + configService.setConfig(this) + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file 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 new file mode 100644 index 0000000000000000000000000000000000000000..faa60be080dae84b1688cdcdf909f572368cd16f --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFormatCallbackTest.test.js @@ -0,0 +1,902 @@ +/* + * Copyright (C) 2021 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 media from '@ohos.multimedia.media' +import Fileio from '@ohos.fileio' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('AudioDecoderFormatCallback', function () { + const AUDIOPATH1 = '/data/media/AAC_48000_32_1.aac'; + const AUDIOPATH2 = '/data/media/FLAC_48000_32_1.flac'; + const AUDIOPATH3 = '/data/media/mp3.es'; + const AUDIOPATH4 = '/data/media/vorbis.es'; + const BASIC_PATH = '/data/media/results/decode_format_callback_'; + let audioDecodeProcessor; + let readStreamSync; + let needGetMediaDes = false; + let frameCnt = 1; + let timestamp = 0; + let sawInputEOS = false; + let sawOutputEOS = false; + let inputQueue = []; + let outputQueue = []; + let ES = []; + let ES_LENGTH = 0; + let samplerate = 44.1; + let isMp3 = false; + let isVorbis = false; + + beforeAll(function() { + console.info('beforeAll case'); + }) + + beforeEach(function() { + console.info('beforeEach case'); + audioDecodeProcessor = null; + readStreamSync = undefined; + needGetMediaDes = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + inputQueue = []; + outputQueue = []; + ES = []; + ES_LENGTH = 0; + samplerate = 44.1; + isMp3 = false; + isVorbis = false; + }) + + afterEach(function() { + console.info('afterEach case'); + if (audioDecodeProcessor != null) { + audioDecodeProcessor = null + } + }) + + afterAll(function() { + console.info('afterAll case'); + }) + + function writeFile(path, buf, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let num = writestream.writeSync(buf, {length:len}); + writestream.flushSync(); + writestream.closeSync(); + } catch(e) { + console.log(e); + } + } + + function readFile(path) { + console.log('read file start execution'); + try{ + console.log('filepath: ' + path); + readStreamSync = Fileio.createStreamSync(path, 'rb'); + } catch(e) { + console.log(e); + } + } + + function getContent(buf, len) { + console.log("start get content"); + let lengthreal = -1; + lengthreal = readStreamSync.readSync(buf,{length:len}); + console.log('lengthreal: ' + lengthreal); + } + + async function enqueueAllInputs(audioDecodeProcessor, queue) { + while (queue.length > 0 && !sawInputEOS) { + let inputobject = queue.shift(); + if (frameCnt == ES_LENGTH + 1) { + inputobject.flags = 1; + inputobject.timeMs = 0; + inputobject.length = 0; + sawInputEOS = true; + } else { + inputobject.timeMs = timestamp; + inputobject.offset = 0; + if (frameCnt==1 && isVorbis) { + inputobject.length = ES[frameCnt]; + getContent(inputobject.data, ES[frameCnt]); + inputobject.flags = 8; + } else if (isMp3) { + inputobject.length = ES[1]; + getContent(inputobject.data, ES[1]); + inputobject.flags = 0; + } else { + inputobject.length = ES[frameCnt]; + getContent(inputobject.data, ES[frameCnt]); + inputobject.flags = 0; + } + } + if (isMp3) { + timestamp += ES[1]/samplerate; + } else { + timestamp += ES[frameCnt]/samplerate; + } + frameCnt += 1; + audioDecodeProcessor.queueInput(inputobject, () => { + console.info('queueInput success'); + }) + } + } + + async function dequeueAllOutputs(audioDecodeProcessor, queue, savepath, done) { + while (queue.length > 0 && !sawOutputEOS) { + let outputobject = queue.shift(); + if (outputobject.flags == 1) { + sawOutputEOS = true; + audioDecodeProcessor.stop((err) => { + expect(err).assertUndefined(); + console.log("stop success"); + audioDecodeProcessor.reset((err) => { + expect(err).assertUndefined(); + console.log("reset success"); + audioDecodeProcessor = null; + done(); + }) + }) + } else { + writeFile(savepath, outputobject.data, outputobject.length); + console.log("write to file success"); + } + audioDecodeProcessor.releaseOutput(outputobject, () => { + console.info('release output success'); + }) + } + } + + function setCallback(audioDecodeProcessor, savepath, done) { + console.info('case callback'); + audioDecodeProcessor.on('inputBufferAvailable', async(inBuffer) => { + console.info("inputBufferAvailable"); + inputQueue.push(inBuffer); + await enqueueAllInputs(audioDecodeProcessor, inputQueue); + }); + audioDecodeProcessor.on('outputBufferAvailable', async(outBuffer) => { + console.info("outputBufferAvailable"); + if (needGetMediaDes) { + audioDecodeProcessor.getOutputMediaDescription((err, MediaDescription) => { + console.log("get OutputMediaDescription success"); + console.log('get outputMediaDescription : ' + MediaDescription); + needGetMediaDes=false; + }) + } + outputQueue.push(outBuffer); + await dequeueAllOutputs(audioDecodeProcessor, outputQueue, savepath, done); + }); + audioDecodeProcessor.on('error',(err) => { + console.info('case error called,errName is' + err); + }); + audioDecodeProcessor.on('outputFormatChanged',(format) => { + console.info('Output format changed: ' + format); + }); + } + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0100 + * @tc.name : 001.test aac format(createbymime) + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0100', 0, async function (done) { + console.log("case test aac format"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'aac_01.pcm'; + needGetMediaDes = true; + ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, + 541, 540, 542, 552, 537, 533, 498, 472, 445, 430, 445, 427, 414, 386, 413, 370, 380, + 401, 393, 369, 391, 367, 395, 396, 396, 385, 391, 384, 395, 392, 386, 388, 384, 379, + 376, 381, 375, 373, 349, 391, 357, 384, 395, 384, 380, 386, 372, 386, 383, 378, 385, + 385, 384, 342, 390, 379, 387, 386, 393, 397, 362, 393, 394, 391, 383, 385, 377, 379, + 381, 369, 375, 379, 346, 382, 356, 361, 366, 394, 393, 385, 362, 406, 399, 384, 377, + 385, 389, 375, 346, 396, 388, 381, 383, 352, 357, 397, 382, 395, 376, 388, 373, 374, + 353, 383, 384, 393, 379, 348, 364, 389, 380, 381, 388, 423, 392, 381, 368, 351, 391, + 355, 358, 395, 390, 385, 382, 383, 388, 388, 389, 376, 379, 376, 384, 369, 354, 390, + 389, 396, 393, 382, 385, 353, 383, 381, 377, 411, 387, 390, 377, 349, 381, 390, 378, + 373, 375, 381, 351, 392, 381, 380, 381, 378, 387, 379, 383, 348, 386, 364, 386, 371, + 399, 399, 385, 380, 355, 397, 395, 382, 380, 386, 352, 387, 390, 373, 372, 388, 378, + 385, 368, 385, 370, 378, 373, 383, 368, 373, 388, 351, 384, 391, 387, 389, 383, 355, + 361, 392, 386, 354, 394, 392, 397, 392, 352, 381, 395, 349, 383, 390, 392, 350, 393, + 393, 385, 389, 393, 382, 378, 384, 378, 375, 373, 375, 389, 377, 383, 387, 373, 344, + 388, 379, 391, 373, 384, 358, 361, 391, 394, 363, 350, 361, 395, 399, 389, 398, 375, + 398, 400, 381, 354, 363, 366, 400, 400, 356, 370, 400, 394, 398, 385, 378, 372, 354, + 359, 393, 381, 363, 396, 396, 355, 390, 356, 355, 371, 399, 367, 406, 375, 377, 405, + 401, 390, 393, 392, 384, 386, 374, 358, 397, 389, 393, 385, 345, 379, 357, 388, 356, + 381, 389, 367, 358, 391, 360, 394, 396, 357, 395, 388, 394, 383, 357, 383, 392, 394, + 376, 379, 356, 386, 395, 387, 377, 377, 389, 377, 385, 351, 387, 350, 388, 384, 345, + 358, 368, 399, 394, 385, 384, 395, 378, 387, 386, 386, 376, 375, 382, 351, 359, 356, + 401, 388, 363, 406, 363, 374, 435, 366, 400, 393, 392, 371, 391, 359, 359, 397, 388, + 390, 420, 411, 369, 384, 382, 383, 383, 375, 381, 361, 380, 348, 379, 386, 379, 379, + 386, 371, 352, 378, 378, 388, 384, 385, 352, 355, 387, 383, 379, 362, 386, 399, 376, + 390, 350, 387, 357, 403, 398, 397, 360, 351, 394, 400, 399, 393, 388, 395, 370, 377, + 395, 360, 346, 381, 370, 390, 380, 391, 387, 382, 384, 383, 354, 349, 394, 358, 387, + 400, 386, 402, 354, 396, 387, 391, 365, 377, 359, 361, 365, 395, 388, 388, 384, 388, + 378, 374, 382, 376, 377, 389, 378, 341, 390, 376, 381, 375, 414, 368, 369, 387, 411, + 396, 391, 378, 389, 349, 383, 344, 381, 387, 380, 353, 361, 391, 365, 390, 396, 382, + 386, 385, 385, 409, 387, 386, 378, 372, 372, 374, 349, 388, 389, 348, 395, 380, 382, + 388, 375, 347, 383, 359, 389, 368, 361, 405, 398, 393, 395, 359, 360, 395, 395, 362, + 354, 388, 348, 388, 386, 390, 350, 388, 356, 369, 364, 404, 404, 391, 394, 385, 439, + 432, 375, 366, 441, 362, 367, 382, 374, 346, 391, 371, 354, 376, 390, 373, 382, 385, + 389, 378, 377, 347, 414, 338, 348, 385, 352, 385, 386, 381, 388, 387, 364, 465, 405, + 443, 387, 339, 376, 337, 379, 387, 370, 374, 358, 354, 357, 393, 356, 381, 357, 407, + 361, 397, 362, 394, 394, 392, 394, 391, 381, 386, 379, 354, 351, 392, 408, 393, 389, + 388, 385, 375, 388, 375, 388, 375, 354, 384, 379, 386, 394, 383, 359, 405, 395, 352, + 345, 403, 427, 373, 380, 350, 415, 378, 434, 385, 388, 387, 400, 405, 329, 391, 356, + 419, 358, 359, 375, 367, 391, 359, 369, 361, 376, 378, 379, 348, 390, 345, 388, 390, + 406, 349, 368, 364, 391, 384, 401, 384, 391, 361, 399, 359, 386, 392, 382, 386, 380, + 383, 345, 376, 393, 400, 395, 343, 352, 354, 381, 388, 357, 393, 389, 384, 389, 388, + 384, 404, 372, 358, 381, 352, 355, 485, 393, 371, 376, 389, 377, 391, 387, 376, 342, + 390, 375, 379, 396, 376, 402, 353, 392, 382, 383, 387, 386, 372, 377, 382, 388, 381, + 387, 357, 393, 385, 346, 389, 388, 357, 362, 404, 398, 397, 402, 371, 351, 370, 362, + 350, 388, 399, 402, 406, 377, 396, 359, 372, 390, 392, 368, 383, 346, 384, 381, 379, + 367, 384, 389, 381, 371, 358, 422, 372, 382, 374, 444, 412, 369, 362, 373, 389, 401, + 383, 380, 366, 365, 361, 379, 372, 345, 382, 375, 376, 375, 382, 356, 395, 383, 384, + 391, 361, 396, 407, 365, 351, 385, 378, 403, 344, 352, 387, 397, 399, 377, 371, 381, + 415, 382, 388, 368, 383, 405, 390, 386, 384, 374, 375, 381, 371, 372, 374, 377, 346, + 358, 381, 377, 359, 385, 396, 385, 390, 389, 391, 375, 357, 389, 390, 377, 370, 379, + 351, 381, 381, 380, 371, 386, 389, 389, 383, 362, 393, 388, 355, 396, 383, 352, 384, + 352, 383, 362, 396, 385, 396, 357, 388, 382, 377, 373, 379, 383, 386, 350, 393, 355, + 380, 401, 392, 391, 402, 391, 427, 407, 394, 332, 398, 367, 373, 343, 381, 383, 386, + 382, 349, 353, 393, 378, 386, 375, 390, 356, 392, 384, 387, 380, 381, 385, 386, 383, + 378, 379, 359, 381, 382, 388, 357, 357, 397, 358, 424, 382, 352, 409, 374, 368, 365, + 399, 352, 393, 389, 385, 352, 380, 398, 389, 385, 387, 387, 353, 402, 396, 386, 357, + 395, 368, 369, 407, 394, 383, 362, 380, 385, 368, 375, 365, 379, 377, 388, 380, 346, + 383, 381, 399, 359, 386, 455, 368, 406, 377, 339, 381, 377, 373, 371, 338]; + ES_LENGTH = 1000; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.log("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH1); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + }) + }); + media.createAudioDecoderByMime('audio/mp4a-latm', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0101 + * @tc.name : 001.test aac format(createbyname) + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0101', 0, async function (done) { + console.log("case test aac format"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'aac_02.pcm'; + needGetMediaDes = true; + ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, + 541, 540, 542, 552, 537, 533, 498, 472, 445, 430, 445, 427, 414, 386, 413, 370, 380, + 401, 393, 369, 391, 367, 395, 396, 396, 385, 391, 384, 395, 392, 386, 388, 384, 379, + 376, 381, 375, 373, 349, 391, 357, 384, 395, 384, 380, 386, 372, 386, 383, 378, 385, + 385, 384, 342, 390, 379, 387, 386, 393, 397, 362, 393, 394, 391, 383, 385, 377, 379, + 381, 369, 375, 379, 346, 382, 356, 361, 366, 394, 393, 385, 362, 406, 399, 384, 377, + 385, 389, 375, 346, 396, 388, 381, 383, 352, 357, 397, 382, 395, 376, 388, 373, 374, + 353, 383, 384, 393, 379, 348, 364, 389, 380, 381, 388, 423, 392, 381, 368, 351, 391, + 355, 358, 395, 390, 385, 382, 383, 388, 388, 389, 376, 379, 376, 384, 369, 354, 390, + 389, 396, 393, 382, 385, 353, 383, 381, 377, 411, 387, 390, 377, 349, 381, 390, 378, + 373, 375, 381, 351, 392, 381, 380, 381, 378, 387, 379, 383, 348, 386, 364, 386, 371, + 399, 399, 385, 380, 355, 397, 395, 382, 380, 386, 352, 387, 390, 373, 372, 388, 378, + 385, 368, 385, 370, 378, 373, 383, 368, 373, 388, 351, 384, 391, 387, 389, 383, 355, + 361, 392, 386, 354, 394, 392, 397, 392, 352, 381, 395, 349, 383, 390, 392, 350, 393, + 393, 385, 389, 393, 382, 378, 384, 378, 375, 373, 375, 389, 377, 383, 387, 373, 344, + 388, 379, 391, 373, 384, 358, 361, 391, 394, 363, 350, 361, 395, 399, 389, 398, 375, + 398, 400, 381, 354, 363, 366, 400, 400, 356, 370, 400, 394, 398, 385, 378, 372, 354, + 359, 393, 381, 363, 396, 396, 355, 390, 356, 355, 371, 399, 367, 406, 375, 377, 405, + 401, 390, 393, 392, 384, 386, 374, 358, 397, 389, 393, 385, 345, 379, 357, 388, 356, + 381, 389, 367, 358, 391, 360, 394, 396, 357, 395, 388, 394, 383, 357, 383, 392, 394, + 376, 379, 356, 386, 395, 387, 377, 377, 389, 377, 385, 351, 387, 350, 388, 384, 345, + 358, 368, 399, 394, 385, 384, 395, 378, 387, 386, 386, 376, 375, 382, 351, 359, 356, + 401, 388, 363, 406, 363, 374, 435, 366, 400, 393, 392, 371, 391, 359, 359, 397, 388, + 390, 420, 411, 369, 384, 382, 383, 383, 375, 381, 361, 380, 348, 379, 386, 379, 379, + 386, 371, 352, 378, 378, 388, 384, 385, 352, 355, 387, 383, 379, 362, 386, 399, 376, + 390, 350, 387, 357, 403, 398, 397, 360, 351, 394, 400, 399, 393, 388, 395, 370, 377, + 395, 360, 346, 381, 370, 390, 380, 391, 387, 382, 384, 383, 354, 349, 394, 358, 387, + 400, 386, 402, 354, 396, 387, 391, 365, 377, 359, 361, 365, 395, 388, 388, 384, 388, + 378, 374, 382, 376, 377, 389, 378, 341, 390, 376, 381, 375, 414, 368, 369, 387, 411, + 396, 391, 378, 389, 349, 383, 344, 381, 387, 380, 353, 361, 391, 365, 390, 396, 382, + 386, 385, 385, 409, 387, 386, 378, 372, 372, 374, 349, 388, 389, 348, 395, 380, 382, + 388, 375, 347, 383, 359, 389, 368, 361, 405, 398, 393, 395, 359, 360, 395, 395, 362, + 354, 388, 348, 388, 386, 390, 350, 388, 356, 369, 364, 404, 404, 391, 394, 385, 439, + 432, 375, 366, 441, 362, 367, 382, 374, 346, 391, 371, 354, 376, 390, 373, 382, 385, + 389, 378, 377, 347, 414, 338, 348, 385, 352, 385, 386, 381, 388, 387, 364, 465, 405, + 443, 387, 339, 376, 337, 379, 387, 370, 374, 358, 354, 357, 393, 356, 381, 357, 407, + 361, 397, 362, 394, 394, 392, 394, 391, 381, 386, 379, 354, 351, 392, 408, 393, 389, + 388, 385, 375, 388, 375, 388, 375, 354, 384, 379, 386, 394, 383, 359, 405, 395, 352, + 345, 403, 427, 373, 380, 350, 415, 378, 434, 385, 388, 387, 400, 405, 329, 391, 356, + 419, 358, 359, 375, 367, 391, 359, 369, 361, 376, 378, 379, 348, 390, 345, 388, 390, + 406, 349, 368, 364, 391, 384, 401, 384, 391, 361, 399, 359, 386, 392, 382, 386, 380, + 383, 345, 376, 393, 400, 395, 343, 352, 354, 381, 388, 357, 393, 389, 384, 389, 388, + 384, 404, 372, 358, 381, 352, 355, 485, 393, 371, 376, 389, 377, 391, 387, 376, 342, + 390, 375, 379, 396, 376, 402, 353, 392, 382, 383, 387, 386, 372, 377, 382, 388, 381, + 387, 357, 393, 385, 346, 389, 388, 357, 362, 404, 398, 397, 402, 371, 351, 370, 362, + 350, 388, 399, 402, 406, 377, 396, 359, 372, 390, 392, 368, 383, 346, 384, 381, 379, + 367, 384, 389, 381, 371, 358, 422, 372, 382, 374, 444, 412, 369, 362, 373, 389, 401, + 383, 380, 366, 365, 361, 379, 372, 345, 382, 375, 376, 375, 382, 356, 395, 383, 384, + 391, 361, 396, 407, 365, 351, 385, 378, 403, 344, 352, 387, 397, 399, 377, 371, 381, + 415, 382, 388, 368, 383, 405, 390, 386, 384, 374, 375, 381, 371, 372, 374, 377, 346, + 358, 381, 377, 359, 385, 396, 385, 390, 389, 391, 375, 357, 389, 390, 377, 370, 379, + 351, 381, 381, 380, 371, 386, 389, 389, 383, 362, 393, 388, 355, 396, 383, 352, 384, + 352, 383, 362, 396, 385, 396, 357, 388, 382, 377, 373, 379, 383, 386, 350, 393, 355, + 380, 401, 392, 391, 402, 391, 427, 407, 394, 332, 398, 367, 373, 343, 381, 383, 386, + 382, 349, 353, 393, 378, 386, 375, 390, 356, 392, 384, 387, 380, 381, 385, 386, 383, + 378, 379, 359, 381, 382, 388, 357, 357, 397, 358, 424, 382, 352, 409, 374, 368, 365, + 399, 352, 393, 389, 385, 352, 380, 398, 389, 385, 387, 387, 353, 402, 396, 386, 357, + 395, 368, 369, 407, 394, 383, 362, 380, 385, 368, 375, 365, 379, 377, 388, 380, 346, + 383, 381, 399, 359, 386, 455, 368, 406, 377, 339, 381, 377, 373, 371, 338]; + ES_LENGTH = 1000; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.log("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH1); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + }) + }); + media.createAudioDecoderByName('avdec_aac', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0200 + * @tc.name : 002.test flac format(createbymime) + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0200', 0, async function (done) { + console.log("case test flac format"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'flac_01.pcm'; + needGetMediaDes = true; + samplerate = 48; + ES = [0, 2116, 2093, 2886, 2859, 2798, 2778, 2752, 2752, 2754, 2720, 2898, 2829, 2806, + 2796,2786, 2774, 2758, 2741, 3489, 3342, 3272, 3167, 3048, 3060, 2919, 2839, 2794, + 2770, 2763,2756, 2722, 2950, 2876, 2842, 2827, 2792, 3121, 3075, 2969, 3240, 3199, + 3082, 2975, 2895, 3135, 3024, 2970, 2902, 2860, 2802, 2778, 2779, 2963, 2893, 2870, + 2831, 2800, 2762, 2752, 2760, 2759, 2726, 2889, 2960, 2876, 3223, 3040, 3006, 3042, + 2980, 3097, 3069, 3215, 3365, 3296, 3653, 3480, 3300, 3140, 3014, 2975, 2952, 2896, + 2897, 2842, 2929, 3567, 3929, 3485, 3082, 3625, 4953, 5239, 5094, 4993, 4821, 4431, + 5195, 5542, 5557, 4894, 4414, 5085, 5496, 5089, 4459, 4532, 4778, 5460, 5372, 5224, + 4395, 4701, 5512, 5304, 4798, 7128, 6534, 5704, 5562, 5539, 5675, 5780, 6058, 6194, + 6076, 5971, 5758, 5202, 4438, 3821, 4267, 5550, 4896, 3841, 5166, 4904, 4504, 5530, + 5354, 5047, 5695, 5422, 5168, 5338, 5154, 5385, 5322, 4934, 4512, 4001, 3793, 3624, + 3589, 3562, 4346, 5407, 5582, 5645, 5581, 5605, 5520, 5399, 5164, 4991, 4556, 4058, + 3662, 3757, 4627, 5183, 5061, 4114, 5840, 5051, 5126, 4573, 5269, 4437, 5021, 5508, + 5289, 5171, 5153, 5118, 5721, 5375, 4863, 6353, 5477, 5608, 5614, 5737, 5178, 4614, + 4671, 5204, 5027, 4977, 3922, 5904]; + ES_LENGTH = 200; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.log("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH2); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + }) + }); + media.createAudioDecoderByMime('audio/flac', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0201 + * @tc.name : 002.test flac format(createbyname) + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0201', 0, async function (done) { + console.log("case test flac format"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'flac_02.pcm'; + needGetMediaDes = true; + samplerate = 48; + ES = [0, 2116, 2093, 2886, 2859, 2798, 2778, 2752, 2752, 2754, 2720, 2898, 2829, 2806, + 2796,2786, 2774, 2758, 2741, 3489, 3342, 3272, 3167, 3048, 3060, 2919, 2839, 2794, + 2770, 2763,2756, 2722, 2950, 2876, 2842, 2827, 2792, 3121, 3075, 2969, 3240, 3199, + 3082, 2975, 2895, 3135, 3024, 2970, 2902, 2860, 2802, 2778, 2779, 2963, 2893, 2870, + 2831, 2800, 2762, 2752, 2760, 2759, 2726, 2889, 2960, 2876, 3223, 3040, 3006, 3042, + 2980, 3097, 3069, 3215, 3365, 3296, 3653, 3480, 3300, 3140, 3014, 2975, 2952, 2896, + 2897, 2842, 2929, 3567, 3929, 3485, 3082, 3625, 4953, 5239, 5094, 4993, 4821, 4431, + 5195, 5542, 5557, 4894, 4414, 5085, 5496, 5089, 4459, 4532, 4778, 5460, 5372, 5224, + 4395, 4701, 5512, 5304, 4798, 7128, 6534, 5704, 5562, 5539, 5675, 5780, 6058, 6194, + 6076, 5971, 5758, 5202, 4438, 3821, 4267, 5550, 4896, 3841, 5166, 4904, 4504, 5530, + 5354, 5047, 5695, 5422, 5168, 5338, 5154, 5385, 5322, 4934, 4512, 4001, 3793, 3624, + 3589, 3562, 4346, 5407, 5582, 5645, 5581, 5605, 5520, 5399, 5164, 4991, 4556, 4058, + 3662, 3757, 4627, 5183, 5061, 4114, 5840, 5051, 5126, 4573, 5269, 4437, 5021, 5508, + 5289, 5171, 5153, 5118, 5721, 5375, 4863, 6353, 5477, 5608, 5614, 5737, 5178, 4614, + 4671, 5204, 5027, 4977, 3922, 5904]; + ES_LENGTH = 200; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.log("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH2); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + }) + }); + media.createAudioDecoderByName('avdec_flac', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0300 + * @tc.name : 003.test mp3 format(createbymime) + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0300', 0, async function (done) { + console.log("test mp3 format"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'mp3_01.pcm'; + needGetMediaDes = true; + isMp3 = true; + isVorbis = false; + ES = [0, 1044]; + ES_LENGTH = 1000; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.log("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH3); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + }) + }); + media.createAudioDecoderByMime('audio/mpeg', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0301 + * @tc.name : 003.test mp3 format(createbyname) + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0301', 0, async function (done) { + console.log("test mp3 format"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'mp3_02.pcm'; + needGetMediaDes = true; + isMp3 = true; + isVorbis = false; + ES = [0, 1044]; + ES_LENGTH = 1000; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.log("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH3); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + }) + }); + media.createAudioDecoderByName('avdec_mp3', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0400 + * @tc.name : 004.test vorbis format(createbymime) + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0400', 0, async function (done) { + console.log("test vorbis format"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'vorbis_01.pcm'; + needGetMediaDes = true; + samplerate = 48; + isVorbis = true; + ES = [0, 3251, 33, 160, 162, 159, 148, 160, 160, 159, 167, 156, 162, 173, 135, 137, 133, + 126, 126, 130, 127, 133, 138, 132, 124, 129, 134, 136, 146, 135, 137, 144, 137, 128, + 124, 127, 129, 127, 130, 127, 134, 130, 135, 146, 142, 140, 134, 134, 128, 119, 122, + 122, 123, 121, 128, 125, 128, 122, 137, 141, 136, 135, 127, 128, 125, 128, 122, 126, + 132, 127, 127, 135, 143, 134, 148, 133, 131, 140, 143, 135, 140, 141, 135, 149, 27, + 30, 36, 32, 157, 155, 158, 154, 136, 150, 149, 142, 150, 142, 149, 139, 142, 146, 138, + 138, 144, 138, 139, 132, 120, 130, 134, 124, 127, 130, 130, 123, 133, 141, 137, 135, + 140, 147, 139, 141, 134, 131, 146, 139, 136, 136, 130, 143, 147, 144, 138, 145, 137, + 137, 138, 142, 148, 149, 138, 141, 148, 139, 139, 139, 134, 135, 131, 124, 131, 131, + 120, 121, 132, 128, 127, 130, 136, 129, 130, 123, 133, 132, 141, 147, 147, 139, 127, + 149, 157, 165, 154, 143, 153, 141, 157, 144, 146, 135, 142, 133, 134, 140, 142, 133, + 136, 133, 141, 143, 128, 127, 136, 144, 138, 141, 133, 127, 123, 138, 131, 126, 130, + 131, 135, 131, 137, 136, 125, 127, 126, 143, 142, 127, 134, 140, 144, 128, 125, 139, + 144, 135, 141, 123, 130, 127, 126, 140, 136, 140, 139, 140, 133, 132, 146, 142, 138, + 134, 130, 125, 130, 130, 129, 137, 133, 128, 130, 130, 132, 135, 126, 129, 142, 129, + 151, 150, 146, 130, 130, 144, 137, 145, 140, 126, 123, 128, 138, 136, 140, 137, 137, + 147, 146, 141, 137, 139, 117, 133, 140, 126, 137, 138, 143, 141, 141, 132, 128, 132, + 145, 148, 151, 160, 162, 154, 140, 147, 30, 28, 28, 26, 27, 27, 31, 33, 32, 145, 132, + 130, 124, 142, 140, 128, 124, 131, 127, 130, 128, 135, 125, 137, 137, 127, 128, 127, + 125, 127, 130, 124, 134, 137, 129, 127, 146, 136, 131, 124, 125, 130, 131, 135, 147, + 148, 151, 147, 143, 148, 145, 158, 142, 137, 129, 127, 156, 147, 143, 137, 135, 142, + 141, 140, 137, 136, 132, 134, 130, 124, 127, 130, 127, 126, 127, 129, 132, 134, 141, + 147, 136, 141, 141, 134, 126, 127, 136, 135, 134, 122, 130, 128, 140, 133, 124, 128, + 137, 128, 141, 135, 141, 147, 153, 151, 151, 154, 150, 147, 157, 153, 153, 153, 151, + 155, 154, 153, 150, 143, 157, 146, 150, 154, 152, 153, 28, 35, 33, 34, 37, 36, 30, 31, + 27, 37, 38, 36, 38, 37, 36, 39, 38, 36, 172, 172, 179, 178, 172, 171, 180, 173, 163, + 164, 159, 159, 155, 163, 184, 187, 176, 176, 184, 179, 174, 167, 165, 166, 160, 166, + 169, 169, 159, 165, 166, 168, 162, 180, 174, 186, 179, 180, 186, 187, 178, 156, 158, + 156, 161, 165, 163, 160, 169, 160, 160, 168, 161, 159, 167, 173, 177, 170, 172, 172, + 169, 157, 161, 155, 165, 164, 154, 161, 160, 31, 30, 28, 31, 31, 29, 38, 36, 40, 31, + 33, 37, 39, 179, 30, 28, 27, 30, 28, 30, 30, 37, 42, 39, 184, 163, 158, 172, 166, 161, + 160, 167, 174, 175, 183, 176, 192, 176, 170, 179, 173, 164, 156, 160, 162, 152, 155, + 157, 174, 176, 184, 173, 180, 177, 182, 190, 170, 167, 154, 156, 171, 169, 172, 177, + 190, 192, 186, 188, 192, 192, 176, 179, 175, 191, 174, 197, 194, 203, 198, 190, 185, + 202, 179, 169, 179, 184, 193, 185, 185, 181, 197, 188, 189, 188, 189, 193, 197, 198, + 203, 188, 189, 198, 190, 196, 191, 191, 197, 202, 182, 178, 186, 194, 192, 186, 187, + 188, 186, 179, 179, 168, 165, 173, 165, 160, 161, 145, 162, 149, 155, 154, 145, 154, + 152, 152, 163, 174, 175, 170, 181, 177, 162, 167, 164, 162, 147, 147, 157, 159, 27, + 28, 28, 36, 36, 37, 35, 35, 35, 35, 37, 37, 35, 35, 36, 171, 40, 40, 176, 178, 171, + 174, 165, 161, 157, 160, 154, 167, 163, 174, 172, 155, 158, 165, 166, 181, 190, 160, + 158, 160, 30, 39, 36, 174, 157, 180, 174, 167, 178, 177, 171, 175, 173, 166, 28, 28, + 28, 29, 30, 34, 35, 36, 29, 36, 37, 38, 32, 29, 41, 38, 38, 35, 34, 34, 36, 34, 35, + 30, 30, 31, 31, 28, 30, 31, 36, 36, 36, 40, 38, 44, 41, 34, 38, 38, 38, 39, 184, 157, + 155, 167, 178]; + ES_LENGTH = 757; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.log("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH4); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + }) + }); + media.createAudioDecoderByMime('audio/vorbis', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0401 + * @tc.name : 004.test vorbis format(createbyname) + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_CALLBACK_01_0401', 0, async function (done) { + console.log("test vorbis format"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'vorbis_02.pcm'; + needGetMediaDes = true; + samplerate = 48; + isVorbis = true; + ES = [0, 3251, 33, 160, 162, 159, 148, 160, 160, 159, 167, 156, 162, 173, 135, 137, 133, + 126, 126, 130, 127, 133, 138, 132, 124, 129, 134, 136, 146, 135, 137, 144, 137, 128, + 124, 127, 129, 127, 130, 127, 134, 130, 135, 146, 142, 140, 134, 134, 128, 119, 122, + 122, 123, 121, 128, 125, 128, 122, 137, 141, 136, 135, 127, 128, 125, 128, 122, 126, + 132, 127, 127, 135, 143, 134, 148, 133, 131, 140, 143, 135, 140, 141, 135, 149, 27, + 30, 36, 32, 157, 155, 158, 154, 136, 150, 149, 142, 150, 142, 149, 139, 142, 146, 138, + 138, 144, 138, 139, 132, 120, 130, 134, 124, 127, 130, 130, 123, 133, 141, 137, 135, + 140, 147, 139, 141, 134, 131, 146, 139, 136, 136, 130, 143, 147, 144, 138, 145, 137, + 137, 138, 142, 148, 149, 138, 141, 148, 139, 139, 139, 134, 135, 131, 124, 131, 131, + 120, 121, 132, 128, 127, 130, 136, 129, 130, 123, 133, 132, 141, 147, 147, 139, 127, + 149, 157, 165, 154, 143, 153, 141, 157, 144, 146, 135, 142, 133, 134, 140, 142, 133, + 136, 133, 141, 143, 128, 127, 136, 144, 138, 141, 133, 127, 123, 138, 131, 126, 130, + 131, 135, 131, 137, 136, 125, 127, 126, 143, 142, 127, 134, 140, 144, 128, 125, 139, + 144, 135, 141, 123, 130, 127, 126, 140, 136, 140, 139, 140, 133, 132, 146, 142, 138, + 134, 130, 125, 130, 130, 129, 137, 133, 128, 130, 130, 132, 135, 126, 129, 142, 129, + 151, 150, 146, 130, 130, 144, 137, 145, 140, 126, 123, 128, 138, 136, 140, 137, 137, + 147, 146, 141, 137, 139, 117, 133, 140, 126, 137, 138, 143, 141, 141, 132, 128, 132, + 145, 148, 151, 160, 162, 154, 140, 147, 30, 28, 28, 26, 27, 27, 31, 33, 32, 145, 132, + 130, 124, 142, 140, 128, 124, 131, 127, 130, 128, 135, 125, 137, 137, 127, 128, 127, + 125, 127, 130, 124, 134, 137, 129, 127, 146, 136, 131, 124, 125, 130, 131, 135, 147, + 148, 151, 147, 143, 148, 145, 158, 142, 137, 129, 127, 156, 147, 143, 137, 135, 142, + 141, 140, 137, 136, 132, 134, 130, 124, 127, 130, 127, 126, 127, 129, 132, 134, 141, + 147, 136, 141, 141, 134, 126, 127, 136, 135, 134, 122, 130, 128, 140, 133, 124, 128, + 137, 128, 141, 135, 141, 147, 153, 151, 151, 154, 150, 147, 157, 153, 153, 153, 151, + 155, 154, 153, 150, 143, 157, 146, 150, 154, 152, 153, 28, 35, 33, 34, 37, 36, 30, 31, + 27, 37, 38, 36, 38, 37, 36, 39, 38, 36, 172, 172, 179, 178, 172, 171, 180, 173, 163, + 164, 159, 159, 155, 163, 184, 187, 176, 176, 184, 179, 174, 167, 165, 166, 160, 166, + 169, 169, 159, 165, 166, 168, 162, 180, 174, 186, 179, 180, 186, 187, 178, 156, 158, + 156, 161, 165, 163, 160, 169, 160, 160, 168, 161, 159, 167, 173, 177, 170, 172, 172, + 169, 157, 161, 155, 165, 164, 154, 161, 160, 31, 30, 28, 31, 31, 29, 38, 36, 40, 31, + 33, 37, 39, 179, 30, 28, 27, 30, 28, 30, 30, 37, 42, 39, 184, 163, 158, 172, 166, 161, + 160, 167, 174, 175, 183, 176, 192, 176, 170, 179, 173, 164, 156, 160, 162, 152, 155, + 157, 174, 176, 184, 173, 180, 177, 182, 190, 170, 167, 154, 156, 171, 169, 172, 177, + 190, 192, 186, 188, 192, 192, 176, 179, 175, 191, 174, 197, 194, 203, 198, 190, 185, + 202, 179, 169, 179, 184, 193, 185, 185, 181, 197, 188, 189, 188, 189, 193, 197, 198, + 203, 188, 189, 198, 190, 196, 191, 191, 197, 202, 182, 178, 186, 194, 192, 186, 187, + 188, 186, 179, 179, 168, 165, 173, 165, 160, 161, 145, 162, 149, 155, 154, 145, 154, + 152, 152, 163, 174, 175, 170, 181, 177, 162, 167, 164, 162, 147, 147, 157, 159, 27, + 28, 28, 36, 36, 37, 35, 35, 35, 35, 37, 37, 35, 35, 36, 171, 40, 40, 176, 178, 171, + 174, 165, 161, 157, 160, 154, 167, 163, 174, 172, 155, 158, 165, 166, 181, 190, 160, + 158, 160, 30, 39, 36, 174, 157, 180, 174, 167, 178, 177, 171, 175, 173, 166, 28, 28, + 28, 29, 30, 34, 35, 36, 29, 36, 37, 38, 32, 29, 41, 38, 38, 35, 34, 34, 36, 34, 35, + 30, 30, 31, 31, 28, 30, 31, 36, 36, 36, 40, 38, 44, 41, 34, 38, 38, 38, 39, 184, 157, + 155, 167, 178]; + ES_LENGTH = 757; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.log("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH4); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + }) + }); + media.createAudioDecoderByName('avdec_vorbis', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) +}) \ No newline at end of file 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 new file mode 100644 index 0000000000000000000000000000000000000000..b9f3645195e6596b52ebafe841b82ec5a1f235cf --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFormatPromiseTest.test.js @@ -0,0 +1,758 @@ +/* + * Copyright (C) 2021 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 media from '@ohos.multimedia.media' +import Fileio from '@ohos.fileio' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('AudioDecoderFormatPromise', function () { + const AUDIOPATH1 = '/data/media/AAC_48000_32_1.aac' + const AUDIOPATH2 = '/data/media/FLAC_48000_32_1.flac' + const AUDIOPATH3 = '/data/media/mp3.es'; + const AUDIOPATH4 = '/data/media/vorbis.es'; + const BASIC_PATH = '/data/media/results/decode_format_promise_'; + let audioDecodeProcessor; + let readStreamSync; + let needGetMediaDes = false; + let frameCnt = 1; + let timestamp = 0; + let sawInputEOS = false; + let sawOutputEOS = false; + let inputQueue = []; + let outputQueue = []; + let ES = []; + let ES_LENGTH = 0; + let samplerate = 44.1; + let isMp3 = false; + let isVorbis = false; + + beforeAll(function() { + console.info('beforeAll case'); + }) + + beforeEach(function() { + console.info('beforeEach case'); + audioDecodeProcessor = null; + readStreamSync = undefined; + needGetMediaDes = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + inputQueue = []; + outputQueue = []; + ES = []; + ES_LENGTH = 0; + samplerate = 44.1; + isMp3 = false; + isVorbis = false; + }) + + afterEach(function() { + console.info('afterEach case'); + if (audioDecodeProcessor != null) { + audioDecodeProcessor = null + } + }) + + afterAll(function() { + console.info('afterAll case'); + }) + + let failCallback = function(err) { + console.info('case callback err : ' + err); + expect(err).assertUndefined(); + } + + let failCatch = function(err) { + console.info('case catch err : ' + err); + expect(err).assertUndefined(); + } + + function writeFile(path, buf, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let num = writestream.writeSync(buf, {length:len}); + writestream.flushSync(); + writestream.closeSync(); + } catch(e) { + console.log(e) + } + } + + function readFile(path) { + console.log('read file start execution'); + try{ + console.log('filepath: ' + path); + readStreamSync = Fileio.createStreamSync(path, 'rb'); + } catch(e) { + console.log(e); + } + } + + function getContent(buf, len) { + console.log("start get content"); + let lengthreal = -1; + lengthreal = readStreamSync.readSync(buf,{length:len}); + console.log('lengthreal: ' + lengthreal); + } + + async function enqueueAllInputs(audioDecodeProcessor, queue) { + while (queue.length > 0 && !sawInputEOS) { + let inputobject = queue.shift(); + if (frameCnt == ES_LENGTH + 1) { + inputobject.flags = 1; + inputobject.timeMs = 0; + inputobject.length = 0; + sawInputEOS = true; + } else { + inputobject.timeMs = timestamp; + inputobject.offset = 0; + if (frameCnt==1 && isVorbis) { + inputobject.length = ES[frameCnt]; + getContent(inputobject.data, ES[frameCnt]); + inputobject.flags = 8; + } else if (isMp3) { + inputobject.length = ES[1]; + getContent(inputobject.data, ES[1]); + inputobject.flags = 0; + } else { + inputobject.length = ES[frameCnt]; + getContent(inputobject.data, ES[frameCnt]); + inputobject.flags = 0; + } + } + if (isMp3) { + timestamp += ES[1]/samplerate; + } else { + timestamp += ES[frameCnt]/samplerate; + } + frameCnt += 1; + audioDecodeProcessor.queueInput(inputobject).then(() => { + console.info("queueInput success") + }) + } + } + + async function dequeueAllOutputs(audioDecodeProcessor, queue, savepath, done) { + while (queue.length > 0 && !sawOutputEOS) { + let outputobject = queue.shift(); + if (outputobject.flags == 1) { + sawOutputEOS = true; + await audioDecodeProcessor.stop().then(() => { + console.log("stop success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.reset().then(() => { + console.log("reset success"); + }, failCallback).catch(failCatch); + audioDecodeProcessor = null; + done(); + } + else{ + writeFile(savepath, outputobject.data, outputobject.length); + console.log("write to file success"); + } + audioDecodeProcessor.releaseOutput(outputobject).then(() => { + console.info('release output success'); + }) + } + } + + function setCallback(audioDecodeProcessor, savepath, done) { + console.info('case callback'); + audioDecodeProcessor.on('inputBufferAvailable', async(inBuffer) => { + console.info("inputBufferAvailable"); + inputQueue.push(inBuffer); + await enqueueAllInputs(audioDecodeProcessor, inputQueue); + }); + audioDecodeProcessor.on('outputBufferAvailable', async(outBuffer) => { + console.info("outputBufferAvailable"); + if (needGetMediaDes) { + audioDecodeProcessor.getOutputMediaDescription().then((MediaDescription) => { + console.log("get OutputMediaDescription success"); + console.log('get outputMediaDescription : ' + MediaDescription); + needGetMediaDes=false; + }, failCallback).catch(failCatch);} + outputQueue.push(outBuffer); + await dequeueAllOutputs(audioDecodeProcessor, outputQueue, savepath, done); + }); + audioDecodeProcessor.on('error',(err) => { + console.info('case error called,errName is' + err); + }); + audioDecodeProcessor.on('outputFormatChanged',(format) => { + console.info('Output format changed: ' + format); + }); + } + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0100 + * @tc.name : 001.test aac format(createbymime) + * @tc.desc : decode format test + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0100', 0, async function (done) { + console.log("case test aac format"); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'aac_01.pcm'; + needGetMediaDes = true; + ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, + 541, 540, 542, 552, 537, 533, 498, 472, 445, 430, 445, 427, 414, 386, 413, 370, 380, + 401, 393, 369, 391, 367, 395, 396, 396, 385, 391, 384, 395, 392, 386, 388, 384, 379, + 376, 381, 375, 373, 349, 391, 357, 384, 395, 384, 380, 386, 372, 386, 383, 378, 385, + 385, 384, 342, 390, 379, 387, 386, 393, 397, 362, 393, 394, 391, 383, 385, 377, 379, + 381, 369, 375, 379, 346, 382, 356, 361, 366, 394, 393, 385, 362, 406, 399, 384, 377, + 385, 389, 375, 346, 396, 388, 381, 383, 352, 357, 397, 382, 395, 376, 388, 373, 374, + 353, 383, 384, 393, 379, 348, 364, 389, 380, 381, 388, 423, 392, 381, 368, 351, 391, + 355, 358, 395, 390, 385, 382, 383, 388, 388, 389, 376, 379, 376, 384, 369, 354, 390, + 389, 396, 393, 382, 385, 353, 383, 381, 377, 411, 387, 390, 377, 349, 381, 390, 378, + 373, 375, 381, 351, 392, 381, 380, 381, 378, 387, 379, 383, 348, 386, 364, 386, 371, + 399, 399, 385, 380, 355, 397, 395, 382, 380, 386, 352, 387, 390, 373, 372, 388, 378, + 385, 368, 385, 370, 378, 373, 383, 368, 373, 388, 351, 384, 391, 387, 389, 383, 355, + 361, 392, 386, 354, 394, 392, 397, 392, 352, 381, 395, 349, 383, 390, 392, 350, 393, + 393, 385, 389, 393, 382, 378, 384, 378, 375, 373, 375, 389, 377, 383, 387, 373, 344, + 388, 379, 391, 373, 384, 358, 361, 391, 394, 363, 350, 361, 395, 399, 389, 398, 375, + 398, 400, 381, 354, 363, 366, 400, 400, 356, 370, 400, 394, 398, 385, 378, 372, 354, + 359, 393, 381, 363, 396, 396, 355, 390, 356, 355, 371, 399, 367, 406, 375, 377, 405, + 401, 390, 393, 392, 384, 386, 374, 358, 397, 389, 393, 385, 345, 379, 357, 388, 356, + 381, 389, 367, 358, 391, 360, 394, 396, 357, 395, 388, 394, 383, 357, 383, 392, 394, + 376, 379, 356, 386, 395, 387, 377, 377, 389, 377, 385, 351, 387, 350, 388, 384, 345, + 358, 368, 399, 394, 385, 384, 395, 378, 387, 386, 386, 376, 375, 382, 351, 359, 356, + 401, 388, 363, 406, 363, 374, 435, 366, 400, 393, 392, 371, 391, 359, 359, 397, 388, + 390, 420, 411, 369, 384, 382, 383, 383, 375, 381, 361, 380, 348, 379, 386, 379, 379, + 386, 371, 352, 378, 378, 388, 384, 385, 352, 355, 387, 383, 379, 362, 386, 399, 376, + 390, 350, 387, 357, 403, 398, 397, 360, 351, 394, 400, 399, 393, 388, 395, 370, 377, + 395, 360, 346, 381, 370, 390, 380, 391, 387, 382, 384, 383, 354, 349, 394, 358, 387, + 400, 386, 402, 354, 396, 387, 391, 365, 377, 359, 361, 365, 395, 388, 388, 384, 388, + 378, 374, 382, 376, 377, 389, 378, 341, 390, 376, 381, 375, 414, 368, 369, 387, 411, + 396, 391, 378, 389, 349, 383, 344, 381, 387, 380, 353, 361, 391, 365, 390, 396, 382, + 386, 385, 385, 409, 387, 386, 378, 372, 372, 374, 349, 388, 389, 348, 395, 380, 382, + 388, 375, 347, 383, 359, 389, 368, 361, 405, 398, 393, 395, 359, 360, 395, 395, 362, + 354, 388, 348, 388, 386, 390, 350, 388, 356, 369, 364, 404, 404, 391, 394, 385, 439, + 432, 375, 366, 441, 362, 367, 382, 374, 346, 391, 371, 354, 376, 390, 373, 382, 385, + 389, 378, 377, 347, 414, 338, 348, 385, 352, 385, 386, 381, 388, 387, 364, 465, 405, + 443, 387, 339, 376, 337, 379, 387, 370, 374, 358, 354, 357, 393, 356, 381, 357, 407, + 361, 397, 362, 394, 394, 392, 394, 391, 381, 386, 379, 354, 351, 392, 408, 393, 389, + 388, 385, 375, 388, 375, 388, 375, 354, 384, 379, 386, 394, 383, 359, 405, 395, 352, + 345, 403, 427, 373, 380, 350, 415, 378, 434, 385, 388, 387, 400, 405, 329, 391, 356, + 419, 358, 359, 375, 367, 391, 359, 369, 361, 376, 378, 379, 348, 390, 345, 388, 390, + 406, 349, 368, 364, 391, 384, 401, 384, 391, 361, 399, 359, 386, 392, 382, 386, 380, + 383, 345, 376, 393, 400, 395, 343, 352, 354, 381, 388, 357, 393, 389, 384, 389, 388, + 384, 404, 372, 358, 381, 352, 355, 485, 393, 371, 376, 389, 377, 391, 387, 376, 342, + 390, 375, 379, 396, 376, 402, 353, 392, 382, 383, 387, 386, 372, 377, 382, 388, 381, + 387, 357, 393, 385, 346, 389, 388, 357, 362, 404, 398, 397, 402, 371, 351, 370, 362, + 350, 388, 399, 402, 406, 377, 396, 359, 372, 390, 392, 368, 383, 346, 384, 381, 379, + 367, 384, 389, 381, 371, 358, 422, 372, 382, 374, 444, 412, 369, 362, 373, 389, 401, + 383, 380, 366, 365, 361, 379, 372, 345, 382, 375, 376, 375, 382, 356, 395, 383, 384, + 391, 361, 396, 407, 365, 351, 385, 378, 403, 344, 352, 387, 397, 399, 377, 371, 381, + 415, 382, 388, 368, 383, 405, 390, 386, 384, 374, 375, 381, 371, 372, 374, 377, 346, + 358, 381, 377, 359, 385, 396, 385, 390, 389, 391, 375, 357, 389, 390, 377, 370, 379, + 351, 381, 381, 380, 371, 386, 389, 389, 383, 362, 393, 388, 355, 396, 383, 352, 384, + 352, 383, 362, 396, 385, 396, 357, 388, 382, 377, 373, 379, 383, 386, 350, 393, 355, + 380, 401, 392, 391, 402, 391, 427, 407, 394, 332, 398, 367, 373, 343, 381, 383, 386, + 382, 349, 353, 393, 378, 386, 375, 390, 356, 392, 384, 387, 380, 381, 385, 386, 383, + 378, 379, 359, 381, 382, 388, 357, 357, 397, 358, 424, 382, 352, 409, 374, 368, 365, + 399, 352, 393, 389, 385, 352, 380, 398, 389, 385, 387, 387, 353, 402, 396, 386, 357, + 395, 368, 369, 407, 394, 383, 362, 380, 385, 368, 375, 365, 379, 377, 388, 380, 346, + 383, 381, 399, 359, 386, 455, 368, 406, 377, 339, 381, 377, 373, 371, 338]; + ES_LENGTH = 1000; + await media.createAudioDecoderByMime('audio/mp4a-latm').then((processor) => { + console.log("create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.log("get AudioDecoderCaps success"); + console.log("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.log("configure success"); + readFile(AUDIOPATH1); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.log("prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.log("start success"); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0101 + * @tc.name : 001.test aac format(createbyname) + * @tc.desc : decode format test + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0101', 0, async function (done) { + console.log("case test aac format"); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'aac_02.pcm'; + needGetMediaDes = true; + ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, + 541, 540, 542, 552, 537, 533, 498, 472, 445, 430, 445, 427, 414, 386, 413, 370, 380, + 401, 393, 369, 391, 367, 395, 396, 396, 385, 391, 384, 395, 392, 386, 388, 384, 379, + 376, 381, 375, 373, 349, 391, 357, 384, 395, 384, 380, 386, 372, 386, 383, 378, 385, + 385, 384, 342, 390, 379, 387, 386, 393, 397, 362, 393, 394, 391, 383, 385, 377, 379, + 381, 369, 375, 379, 346, 382, 356, 361, 366, 394, 393, 385, 362, 406, 399, 384, 377, + 385, 389, 375, 346, 396, 388, 381, 383, 352, 357, 397, 382, 395, 376, 388, 373, 374, + 353, 383, 384, 393, 379, 348, 364, 389, 380, 381, 388, 423, 392, 381, 368, 351, 391, + 355, 358, 395, 390, 385, 382, 383, 388, 388, 389, 376, 379, 376, 384, 369, 354, 390, + 389, 396, 393, 382, 385, 353, 383, 381, 377, 411, 387, 390, 377, 349, 381, 390, 378, + 373, 375, 381, 351, 392, 381, 380, 381, 378, 387, 379, 383, 348, 386, 364, 386, 371, + 399, 399, 385, 380, 355, 397, 395, 382, 380, 386, 352, 387, 390, 373, 372, 388, 378, + 385, 368, 385, 370, 378, 373, 383, 368, 373, 388, 351, 384, 391, 387, 389, 383, 355, + 361, 392, 386, 354, 394, 392, 397, 392, 352, 381, 395, 349, 383, 390, 392, 350, 393, + 393, 385, 389, 393, 382, 378, 384, 378, 375, 373, 375, 389, 377, 383, 387, 373, 344, + 388, 379, 391, 373, 384, 358, 361, 391, 394, 363, 350, 361, 395, 399, 389, 398, 375, + 398, 400, 381, 354, 363, 366, 400, 400, 356, 370, 400, 394, 398, 385, 378, 372, 354, + 359, 393, 381, 363, 396, 396, 355, 390, 356, 355, 371, 399, 367, 406, 375, 377, 405, + 401, 390, 393, 392, 384, 386, 374, 358, 397, 389, 393, 385, 345, 379, 357, 388, 356, + 381, 389, 367, 358, 391, 360, 394, 396, 357, 395, 388, 394, 383, 357, 383, 392, 394, + 376, 379, 356, 386, 395, 387, 377, 377, 389, 377, 385, 351, 387, 350, 388, 384, 345, + 358, 368, 399, 394, 385, 384, 395, 378, 387, 386, 386, 376, 375, 382, 351, 359, 356, + 401, 388, 363, 406, 363, 374, 435, 366, 400, 393, 392, 371, 391, 359, 359, 397, 388, + 390, 420, 411, 369, 384, 382, 383, 383, 375, 381, 361, 380, 348, 379, 386, 379, 379, + 386, 371, 352, 378, 378, 388, 384, 385, 352, 355, 387, 383, 379, 362, 386, 399, 376, + 390, 350, 387, 357, 403, 398, 397, 360, 351, 394, 400, 399, 393, 388, 395, 370, 377, + 395, 360, 346, 381, 370, 390, 380, 391, 387, 382, 384, 383, 354, 349, 394, 358, 387, + 400, 386, 402, 354, 396, 387, 391, 365, 377, 359, 361, 365, 395, 388, 388, 384, 388, + 378, 374, 382, 376, 377, 389, 378, 341, 390, 376, 381, 375, 414, 368, 369, 387, 411, + 396, 391, 378, 389, 349, 383, 344, 381, 387, 380, 353, 361, 391, 365, 390, 396, 382, + 386, 385, 385, 409, 387, 386, 378, 372, 372, 374, 349, 388, 389, 348, 395, 380, 382, + 388, 375, 347, 383, 359, 389, 368, 361, 405, 398, 393, 395, 359, 360, 395, 395, 362, + 354, 388, 348, 388, 386, 390, 350, 388, 356, 369, 364, 404, 404, 391, 394, 385, 439, + 432, 375, 366, 441, 362, 367, 382, 374, 346, 391, 371, 354, 376, 390, 373, 382, 385, + 389, 378, 377, 347, 414, 338, 348, 385, 352, 385, 386, 381, 388, 387, 364, 465, 405, + 443, 387, 339, 376, 337, 379, 387, 370, 374, 358, 354, 357, 393, 356, 381, 357, 407, + 361, 397, 362, 394, 394, 392, 394, 391, 381, 386, 379, 354, 351, 392, 408, 393, 389, + 388, 385, 375, 388, 375, 388, 375, 354, 384, 379, 386, 394, 383, 359, 405, 395, 352, + 345, 403, 427, 373, 380, 350, 415, 378, 434, 385, 388, 387, 400, 405, 329, 391, 356, + 419, 358, 359, 375, 367, 391, 359, 369, 361, 376, 378, 379, 348, 390, 345, 388, 390, + 406, 349, 368, 364, 391, 384, 401, 384, 391, 361, 399, 359, 386, 392, 382, 386, 380, + 383, 345, 376, 393, 400, 395, 343, 352, 354, 381, 388, 357, 393, 389, 384, 389, 388, + 384, 404, 372, 358, 381, 352, 355, 485, 393, 371, 376, 389, 377, 391, 387, 376, 342, + 390, 375, 379, 396, 376, 402, 353, 392, 382, 383, 387, 386, 372, 377, 382, 388, 381, + 387, 357, 393, 385, 346, 389, 388, 357, 362, 404, 398, 397, 402, 371, 351, 370, 362, + 350, 388, 399, 402, 406, 377, 396, 359, 372, 390, 392, 368, 383, 346, 384, 381, 379, + 367, 384, 389, 381, 371, 358, 422, 372, 382, 374, 444, 412, 369, 362, 373, 389, 401, + 383, 380, 366, 365, 361, 379, 372, 345, 382, 375, 376, 375, 382, 356, 395, 383, 384, + 391, 361, 396, 407, 365, 351, 385, 378, 403, 344, 352, 387, 397, 399, 377, 371, 381, + 415, 382, 388, 368, 383, 405, 390, 386, 384, 374, 375, 381, 371, 372, 374, 377, 346, + 358, 381, 377, 359, 385, 396, 385, 390, 389, 391, 375, 357, 389, 390, 377, 370, 379, + 351, 381, 381, 380, 371, 386, 389, 389, 383, 362, 393, 388, 355, 396, 383, 352, 384, + 352, 383, 362, 396, 385, 396, 357, 388, 382, 377, 373, 379, 383, 386, 350, 393, 355, + 380, 401, 392, 391, 402, 391, 427, 407, 394, 332, 398, 367, 373, 343, 381, 383, 386, + 382, 349, 353, 393, 378, 386, 375, 390, 356, 392, 384, 387, 380, 381, 385, 386, 383, + 378, 379, 359, 381, 382, 388, 357, 357, 397, 358, 424, 382, 352, 409, 374, 368, 365, + 399, 352, 393, 389, 385, 352, 380, 398, 389, 385, 387, 387, 353, 402, 396, 386, 357, + 395, 368, 369, 407, 394, 383, 362, 380, 385, 368, 375, 365, 379, 377, 388, 380, 346, + 383, 381, 399, 359, 386, 455, 368, 406, 377, 339, 381, 377, 373, 371, 338]; + ES_LENGTH = 1000; + await media.createAudioDecoderByName('avdec_aac').then((processor) => { + console.log("create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.log("get AudioDecoderCaps success"); + console.log("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.log("configure success"); + readFile(AUDIOPATH1); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.log("prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.log("start success"); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0200 + * @tc.name : 002.test flac format(createbymime) + * @tc.desc : decode format test + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0200', 0, async function (done) { + console.log("case test flac format"); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'flac_01.pcm'; + needGetMediaDes = true; + samplerate = 48; + ES = [0, 2116, 2093, 2886, 2859, 2798, 2778, 2752, 2752, 2754, 2720, 2898, 2829, 2806, + 2796,2786, 2774, 2758, 2741, 3489, 3342, 3272, 3167, 3048, 3060, 2919, 2839, 2794, + 2770, 2763,2756, 2722, 2950, 2876, 2842, 2827, 2792, 3121, 3075, 2969, 3240, 3199, + 3082, 2975, 2895, 3135, 3024, 2970, 2902, 2860, 2802, 2778, 2779, 2963, 2893, 2870, + 2831, 2800, 2762, 2752, 2760, 2759, 2726, 2889, 2960, 2876, 3223, 3040, 3006, 3042, + 2980, 3097, 3069, 3215, 3365, 3296, 3653, 3480, 3300, 3140, 3014, 2975, 2952, 2896, + 2897, 2842, 2929, 3567, 3929, 3485, 3082, 3625, 4953, 5239, 5094, 4993, 4821, 4431, + 5195, 5542, 5557, 4894, 4414, 5085, 5496, 5089, 4459, 4532, 4778, 5460, 5372, 5224, + 4395, 4701, 5512, 5304, 4798, 7128, 6534, 5704, 5562, 5539, 5675, 5780, 6058, 6194, + 6076, 5971, 5758, 5202, 4438, 3821, 4267, 5550, 4896, 3841, 5166, 4904, 4504, 5530, + 5354, 5047, 5695, 5422, 5168, 5338, 5154, 5385, 5322, 4934, 4512, 4001, 3793, 3624, + 3589, 3562, 4346, 5407, 5582, 5645, 5581, 5605, 5520, 5399, 5164, 4991, 4556, 4058, + 3662, 3757, 4627, 5183, 5061, 4114, 5840, 5051, 5126, 4573, 5269, 4437, 5021, 5508, + 5289, 5171, 5153, 5118, 5721, 5375, 4863, 6353, 5477, 5608, 5614, 5737, 5178, 4614, + 4671, 5204, 5027, 4977, 3922, 5904]; + ES_LENGTH = 200; + await media.createAudioDecoderByMime('audio/flac').then((processor) => { + console.log("create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.log("get AudioDecoderCaps success"); + console.log("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + console.log("start configure"); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.log("configure success"); + readFile(AUDIOPATH2); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.log("prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.log("start success"); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0201 + * @tc.name : 002.test flac format(createbyname) + * @tc.desc : decode format test + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0201', 0, async function (done) { + console.log("case test flac format"); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'flac_02.pcm'; + needGetMediaDes = true; + samplerate = 48; + ES = [0, 2116, 2093, 2886, 2859, 2798, 2778, 2752, 2752, 2754, 2720, 2898, 2829, 2806, + 2796,2786, 2774, 2758, 2741, 3489, 3342, 3272, 3167, 3048, 3060, 2919, 2839, 2794, + 2770, 2763,2756, 2722, 2950, 2876, 2842, 2827, 2792, 3121, 3075, 2969, 3240, 3199, + 3082, 2975, 2895, 3135, 3024, 2970, 2902, 2860, 2802, 2778, 2779, 2963, 2893, 2870, + 2831, 2800, 2762, 2752, 2760, 2759, 2726, 2889, 2960, 2876, 3223, 3040, 3006, 3042, + 2980, 3097, 3069, 3215, 3365, 3296, 3653, 3480, 3300, 3140, 3014, 2975, 2952, 2896, + 2897, 2842, 2929, 3567, 3929, 3485, 3082, 3625, 4953, 5239, 5094, 4993, 4821, 4431, + 5195, 5542, 5557, 4894, 4414, 5085, 5496, 5089, 4459, 4532, 4778, 5460, 5372, 5224, + 4395, 4701, 5512, 5304, 4798, 7128, 6534, 5704, 5562, 5539, 5675, 5780, 6058, 6194, + 6076, 5971, 5758, 5202, 4438, 3821, 4267, 5550, 4896, 3841, 5166, 4904, 4504, 5530, + 5354, 5047, 5695, 5422, 5168, 5338, 5154, 5385, 5322, 4934, 4512, 4001, 3793, 3624, + 3589, 3562, 4346, 5407, 5582, 5645, 5581, 5605, 5520, 5399, 5164, 4991, 4556, 4058, + 3662, 3757, 4627, 5183, 5061, 4114, 5840, 5051, 5126, 4573, 5269, 4437, 5021, 5508, + 5289, 5171, 5153, 5118, 5721, 5375, 4863, 6353, 5477, 5608, 5614, 5737, 5178, 4614, + 4671, 5204, 5027, 4977, 3922, 5904]; + ES_LENGTH = 200; + await media.createAudioDecoderByName('avdec_flac').then((processor) => { + console.log("create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.log("get AudioDecoderCaps success"); + console.log("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + console.log("start configure"); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.log("configure success"); + readFile(AUDIOPATH2); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.log("prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.log("start success"); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0300 + * @tc.name : 003.test mp3 format(createbymime) + * @tc.desc : decode format test + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0300', 0, async function (done) { + console.log("case test mp3 format"); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'mp3_01.pcm'; + needGetMediaDes = true; + isMp3 = true; + ES = [0, 1044]; + ES_LENGTH = 1000; + await media.createAudioDecoderByMime('audio/mpeg').then((processor) => { + console.log("create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.log("get AudioDecoderCaps success"); + console.log("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.log("configure success"); + readFile(AUDIOPATH3); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.log("prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.log("start success"); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0301 + * @tc.name : 003.test mp3 format(createbyname) + * @tc.desc : decode format test + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0301', 0, async function (done) { + console.log("case test mp3 format"); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'mp3_02.pcm'; + needGetMediaDes = true; + isMp3 = true; + ES = [0, 1044]; + ES_LENGTH = 1000; + await media.createAudioDecoderByName('avdec_mp3').then((processor) => { + console.log("create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.log("get AudioDecoderCaps success"); + console.log("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.log("configure success"); + readFile(AUDIOPATH3); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.log("prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.log("start success"); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0400 + * @tc.name : 004.test vorbis format(createbymime) + * @tc.desc : decode format test + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0400', 0, async function (done) { + console.log("case test vorbis format"); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'vorbis_01.pcm'; + needGetMediaDes = true; + samplerate = 48; + isVorbis = true; + ES = [0, 3251, 33, 160, 162, 159, 148, 160, 160, 159, 167, 156, 162, 173, 135, 137, 133, + 126, 126, 130, 127, 133, 138, 132, 124, 129, 134, 136, 146, 135, 137, 144, 137, 128, + 124, 127, 129, 127, 130, 127, 134, 130, 135, 146, 142, 140, 134, 134, 128, 119, 122, + 122, 123, 121, 128, 125, 128, 122, 137, 141, 136, 135, 127, 128, 125, 128, 122, 126, + 132, 127, 127, 135, 143, 134, 148, 133, 131, 140, 143, 135, 140, 141, 135, 149, 27, + 30, 36, 32, 157, 155, 158, 154, 136, 150, 149, 142, 150, 142, 149, 139, 142, 146, 138, + 138, 144, 138, 139, 132, 120, 130, 134, 124, 127, 130, 130, 123, 133, 141, 137, 135, + 140, 147, 139, 141, 134, 131, 146, 139, 136, 136, 130, 143, 147, 144, 138, 145, 137, + 137, 138, 142, 148, 149, 138, 141, 148, 139, 139, 139, 134, 135, 131, 124, 131, 131, + 120, 121, 132, 128, 127, 130, 136, 129, 130, 123, 133, 132, 141, 147, 147, 139, 127, + 149, 157, 165, 154, 143, 153, 141, 157, 144, 146, 135, 142, 133, 134, 140, 142, 133, + 136, 133, 141, 143, 128, 127, 136, 144, 138, 141, 133, 127, 123, 138, 131, 126, 130, + 131, 135, 131, 137, 136, 125, 127, 126, 143, 142, 127, 134, 140, 144, 128, 125, 139, + 144, 135, 141, 123, 130, 127, 126, 140, 136, 140, 139, 140, 133, 132, 146, 142, 138, + 134, 130, 125, 130, 130, 129, 137, 133, 128, 130, 130, 132, 135, 126, 129, 142, 129, + 151, 150, 146, 130, 130, 144, 137, 145, 140, 126, 123, 128, 138, 136, 140, 137, 137, + 147, 146, 141, 137, 139, 117, 133, 140, 126, 137, 138, 143, 141, 141, 132, 128, 132, + 145, 148, 151, 160, 162, 154, 140, 147, 30, 28, 28, 26, 27, 27, 31, 33, 32, 145, 132, + 130, 124, 142, 140, 128, 124, 131, 127, 130, 128, 135, 125, 137, 137, 127, 128, 127, + 125, 127, 130, 124, 134, 137, 129, 127, 146, 136, 131, 124, 125, 130, 131, 135, 147, + 148, 151, 147, 143, 148, 145, 158, 142, 137, 129, 127, 156, 147, 143, 137, 135, 142, + 141, 140, 137, 136, 132, 134, 130, 124, 127, 130, 127, 126, 127, 129, 132, 134, 141, + 147, 136, 141, 141, 134, 126, 127, 136, 135, 134, 122, 130, 128, 140, 133, 124, 128, + 137, 128, 141, 135, 141, 147, 153, 151, 151, 154, 150, 147, 157, 153, 153, 153, 151, + 155, 154, 153, 150, 143, 157, 146, 150, 154, 152, 153, 28, 35, 33, 34, 37, 36, 30, 31, + 27, 37, 38, 36, 38, 37, 36, 39, 38, 36, 172, 172, 179, 178, 172, 171, 180, 173, 163, + 164, 159, 159, 155, 163, 184, 187, 176, 176, 184, 179, 174, 167, 165, 166, 160, 166, + 169, 169, 159, 165, 166, 168, 162, 180, 174, 186, 179, 180, 186, 187, 178, 156, 158, + 156, 161, 165, 163, 160, 169, 160, 160, 168, 161, 159, 167, 173, 177, 170, 172, 172, + 169, 157, 161, 155, 165, 164, 154, 161, 160, 31, 30, 28, 31, 31, 29, 38, 36, 40, 31, + 33, 37, 39, 179, 30, 28, 27, 30, 28, 30, 30, 37, 42, 39, 184, 163, 158, 172, 166, 161, + 160, 167, 174, 175, 183, 176, 192, 176, 170, 179, 173, 164, 156, 160, 162, 152, 155, + 157, 174, 176, 184, 173, 180, 177, 182, 190, 170, 167, 154, 156, 171, 169, 172, 177, + 190, 192, 186, 188, 192, 192, 176, 179, 175, 191, 174, 197, 194, 203, 198, 190, 185, + 202, 179, 169, 179, 184, 193, 185, 185, 181, 197, 188, 189, 188, 189, 193, 197, 198, + 203, 188, 189, 198, 190, 196, 191, 191, 197, 202, 182, 178, 186, 194, 192, 186, 187, + 188, 186, 179, 179, 168, 165, 173, 165, 160, 161, 145, 162, 149, 155, 154, 145, 154, + 152, 152, 163, 174, 175, 170, 181, 177, 162, 167, 164, 162, 147, 147, 157, 159, 27, + 28, 28, 36, 36, 37, 35, 35, 35, 35, 37, 37, 35, 35, 36, 171, 40, 40, 176, 178, 171, + 174, 165, 161, 157, 160, 154, 167, 163, 174, 172, 155, 158, 165, 166, 181, 190, 160, + 158, 160, 30, 39, 36, 174, 157, 180, 174, 167, 178, 177, 171, 175, 173, 166, 28, 28, + 28, 29, 30, 34, 35, 36, 29, 36, 37, 38, 32, 29, 41, 38, 38, 35, 34, 34, 36, 34, 35, + 30, 30, 31, 31, 28, 30, 31, 36, 36, 36, 40, 38, 44, 41, 34, 38, 38, 38, 39, 184, 157, + 155, 167, 178]; + ES_LENGTH = 757; + await media.createAudioDecoderByMime('audio/vorbis').then((processor) => { + console.log("create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.log("get AudioDecoderCaps success"); + console.log("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.log("configure success"); + readFile(AUDIOPATH4); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.log("prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.log("start success"); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0401 + * @tc.name : 004.test vorbis format(createbyname) + * @tc.desc : decode format test + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FORMAT_PROMISE_01_0401', 0, async function (done) { + console.log("case test vorbis format"); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + 'vorbis_02.pcm'; + needGetMediaDes = true; + samplerate = 48; + isVorbis = true; + ES = [0, 3251, 33, 160, 162, 159, 148, 160, 160, 159, 167, 156, 162, 173, 135, 137, 133, + 126, 126, 130, 127, 133, 138, 132, 124, 129, 134, 136, 146, 135, 137, 144, 137, 128, + 124, 127, 129, 127, 130, 127, 134, 130, 135, 146, 142, 140, 134, 134, 128, 119, 122, + 122, 123, 121, 128, 125, 128, 122, 137, 141, 136, 135, 127, 128, 125, 128, 122, 126, + 132, 127, 127, 135, 143, 134, 148, 133, 131, 140, 143, 135, 140, 141, 135, 149, 27, + 30, 36, 32, 157, 155, 158, 154, 136, 150, 149, 142, 150, 142, 149, 139, 142, 146, 138, + 138, 144, 138, 139, 132, 120, 130, 134, 124, 127, 130, 130, 123, 133, 141, 137, 135, + 140, 147, 139, 141, 134, 131, 146, 139, 136, 136, 130, 143, 147, 144, 138, 145, 137, + 137, 138, 142, 148, 149, 138, 141, 148, 139, 139, 139, 134, 135, 131, 124, 131, 131, + 120, 121, 132, 128, 127, 130, 136, 129, 130, 123, 133, 132, 141, 147, 147, 139, 127, + 149, 157, 165, 154, 143, 153, 141, 157, 144, 146, 135, 142, 133, 134, 140, 142, 133, + 136, 133, 141, 143, 128, 127, 136, 144, 138, 141, 133, 127, 123, 138, 131, 126, 130, + 131, 135, 131, 137, 136, 125, 127, 126, 143, 142, 127, 134, 140, 144, 128, 125, 139, + 144, 135, 141, 123, 130, 127, 126, 140, 136, 140, 139, 140, 133, 132, 146, 142, 138, + 134, 130, 125, 130, 130, 129, 137, 133, 128, 130, 130, 132, 135, 126, 129, 142, 129, + 151, 150, 146, 130, 130, 144, 137, 145, 140, 126, 123, 128, 138, 136, 140, 137, 137, + 147, 146, 141, 137, 139, 117, 133, 140, 126, 137, 138, 143, 141, 141, 132, 128, 132, + 145, 148, 151, 160, 162, 154, 140, 147, 30, 28, 28, 26, 27, 27, 31, 33, 32, 145, 132, + 130, 124, 142, 140, 128, 124, 131, 127, 130, 128, 135, 125, 137, 137, 127, 128, 127, + 125, 127, 130, 124, 134, 137, 129, 127, 146, 136, 131, 124, 125, 130, 131, 135, 147, + 148, 151, 147, 143, 148, 145, 158, 142, 137, 129, 127, 156, 147, 143, 137, 135, 142, + 141, 140, 137, 136, 132, 134, 130, 124, 127, 130, 127, 126, 127, 129, 132, 134, 141, + 147, 136, 141, 141, 134, 126, 127, 136, 135, 134, 122, 130, 128, 140, 133, 124, 128, + 137, 128, 141, 135, 141, 147, 153, 151, 151, 154, 150, 147, 157, 153, 153, 153, 151, + 155, 154, 153, 150, 143, 157, 146, 150, 154, 152, 153, 28, 35, 33, 34, 37, 36, 30, 31, + 27, 37, 38, 36, 38, 37, 36, 39, 38, 36, 172, 172, 179, 178, 172, 171, 180, 173, 163, + 164, 159, 159, 155, 163, 184, 187, 176, 176, 184, 179, 174, 167, 165, 166, 160, 166, + 169, 169, 159, 165, 166, 168, 162, 180, 174, 186, 179, 180, 186, 187, 178, 156, 158, + 156, 161, 165, 163, 160, 169, 160, 160, 168, 161, 159, 167, 173, 177, 170, 172, 172, + 169, 157, 161, 155, 165, 164, 154, 161, 160, 31, 30, 28, 31, 31, 29, 38, 36, 40, 31, + 33, 37, 39, 179, 30, 28, 27, 30, 28, 30, 30, 37, 42, 39, 184, 163, 158, 172, 166, 161, + 160, 167, 174, 175, 183, 176, 192, 176, 170, 179, 173, 164, 156, 160, 162, 152, 155, + 157, 174, 176, 184, 173, 180, 177, 182, 190, 170, 167, 154, 156, 171, 169, 172, 177, + 190, 192, 186, 188, 192, 192, 176, 179, 175, 191, 174, 197, 194, 203, 198, 190, 185, + 202, 179, 169, 179, 184, 193, 185, 185, 181, 197, 188, 189, 188, 189, 193, 197, 198, + 203, 188, 189, 198, 190, 196, 191, 191, 197, 202, 182, 178, 186, 194, 192, 186, 187, + 188, 186, 179, 179, 168, 165, 173, 165, 160, 161, 145, 162, 149, 155, 154, 145, 154, + 152, 152, 163, 174, 175, 170, 181, 177, 162, 167, 164, 162, 147, 147, 157, 159, 27, + 28, 28, 36, 36, 37, 35, 35, 35, 35, 37, 37, 35, 35, 36, 171, 40, 40, 176, 178, 171, + 174, 165, 161, 157, 160, 154, 167, 163, 174, 172, 155, 158, 165, 166, 181, 190, 160, + 158, 160, 30, 39, 36, 174, 157, 180, 174, 167, 178, 177, 171, 175, 173, 166, 28, 28, + 28, 29, 30, 34, 35, 36, 29, 36, 37, 38, 32, 29, 41, 38, 38, 35, 34, 34, 36, 34, 35, + 30, 30, 31, 31, 28, 30, 31, 36, 36, 36, 40, 38, 44, 41, 34, 38, 38, 38, 39, 184, 157, + 155, 167, 178]; + ES_LENGTH = 757; + await media.createAudioDecoderByName('avdec_vorbis').then((processor) => { + console.log("create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.log("get AudioDecoderCaps success"); + console.log("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.log("configure success"); + readFile(AUDIOPATH4); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.log("prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.log("start success"); + }, failCallback).catch(failCatch); + }) +}) \ No newline at end of file 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 new file mode 100644 index 0000000000000000000000000000000000000000..659a38627a4e7d0187cc839efc3545910678bc4c --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFuncCallbackTest.test.js @@ -0,0 +1,1053 @@ +/* + * Copyright (C) 2021 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 media from '@ohos.multimedia.media' +import Fileio from '@ohos.fileio' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('AudioDecoderFunc', function () { + const AUDIOPATH = '/data/media/AAC_48000_32_1.aac'; + const AUDIOPATH2 = '/data/media/AAC_16000_1.aac'; + const AUDIOPATH3 = '/data/media/FLAC_48000_32_1.flac'; + const BASIC_PATH = '/data/media/results/decode_func_callback_'; + let audioDecodeProcessor; + let readStreamSync; + let eosframenum = 0; + let samplerate = 44.1; + let workdoneAtEOS = false; + let stopAtEOS = false; + let resetAtEOS = false; + let flushAtEOS = false; + let needGetMediaDes = false; + let needrelease = false; + let frameCnt = 1; + let timestamp = 0; + let sawInputEOS = false; + let sawOutputEOS = false; + let inputQueue = []; + let outputQueue = []; + let ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, + 541, 540, 542, 552, 537, 533, 498, 472, 445, 430, 445, 427, 414, 386, 413, 370, 380, + 401, 393, 369, 391, 367, 395, 396, 396, 385, 391, 384, 395, 392, 386, 388, 384, 379, + 376, 381, 375, 373, 349, 391, 357, 384, 395, 384, 380, 386, 372, 386, 383, 378, 385, + 385, 384, 342, 390, 379, 387, 386, 393, 397, 362, 393, 394, 391, 383, 385, 377, 379, + 381, 369, 375, 379, 346, 382, 356, 361, 366, 394, 393, 385, 362, 406, 399, 384, 377, + 385, 389, 375, 346, 396, 388, 381, 383, 352, 357, 397, 382, 395, 376, 388, 373, 374, + 353, 383, 384, 393, 379, 348, 364, 389, 380, 381, 388, 423, 392, 381, 368, 351, 391, + 355, 358, 395, 390, 385, 382, 383, 388, 388, 389, 376, 379, 376, 384, 369, 354, 390, + 389, 396, 393, 382, 385, 353, 383, 381, 377, 411, 387, 390, 377, 349, 381, 390, 378, + 373, 375, 381, 351, 392, 381, 380, 381, 378, 387, 379, 383, 348, 386, 364, 386, 371, + 399, 399, 385, 380, 355, 397, 395, 382, 380, 386, 352, 387, 390, 373, 372, 388, 378, + 385, 368, 385, 370, 378, 373, 383, 368, 373, 388, 351, 384, 391, 387, 389, 383, 355, + 361, 392, 386, 354, 394, 392, 397, 392, 352, 381, 395, 349, 383, 390, 392, 350, 393, + 393, 385, 389, 393, 382, 378, 384, 378, 375, 373, 375, 389, 377, 383, 387, 373, 344, + 388, 379, 391, 373, 384, 358, 361, 391, 394, 363, 350, 361, 395, 399, 389, 398, 375, + 398, 400, 381, 354, 363, 366, 400, 400, 356, 370, 400, 394, 398, 385, 378, 372, 354, + 359, 393, 381, 363, 396, 396, 355, 390, 356, 355, 371, 399, 367, 406, 375, 377, 405, + 401, 390, 393, 392, 384, 386, 374, 358, 397, 389, 393, 385, 345, 379, 357, 388, 356, + 381, 389, 367, 358, 391, 360, 394, 396, 357, 395, 388, 394, 383, 357, 383, 392, 394, + 376, 379, 356, 386, 395, 387, 377, 377, 389, 377, 385, 351, 387, 350, 388, 384, 345, + 358, 368, 399, 394, 385, 384, 395, 378, 387, 386, 386, 376, 375, 382, 351, 359, 356, + 401, 388, 363, 406, 363, 374, 435, 366, 400, 393, 392, 371, 391, 359, 359, 397, 388, + 390, 420, 411, 369, 384, 382, 383, 383, 375, 381, 361, 380, 348, 379, 386, 379, 379, + 386, 371, 352, 378, 378, 388, 384, 385, 352, 355, 387, 383, 379, 362, 386, 399, 376, + 390, 350, 387, 357, 403, 398, 397, 360, 351, 394, 400, 399, 393, 388, 395, 370, 377, + 395, 360, 346, 381, 370, 390, 380, 391, 387, 382, 384, 383, 354, 349, 394, 358, 387, + 400, 386, 402, 354, 396, 387, 391, 365, 377, 359, 361, 365, 395, 388, 388, 384, 388, + 378, 374, 382, 376, 377, 389, 378, 341, 390, 376, 381, 375, 414, 368, 369, 387, 411, + 396, 391, 378, 389, 349, 383, 344, 381, 387, 380, 353, 361, 391, 365, 390, 396, 382, + 386, 385, 385, 409, 387, 386, 378, 372, 372, 374, 349, 388, 389, 348, 395, 380, 382, + 388, 375, 347, 383, 359, 389, 368, 361, 405, 398, 393, 395, 359, 360, 395, 395, 362, + 354, 388, 348, 388, 386, 390, 350, 388, 356, 369, 364, 404, 404, 391, 394, 385, 439, + 432, 375, 366, 441, 362, 367, 382, 374, 346, 391, 371, 354, 376, 390, 373, 382, 385, + 389, 378, 377, 347, 414, 338, 348, 385, 352, 385, 386, 381, 388, 387, 364, 465, 405, + 443, 387, 339, 376, 337, 379, 387, 370, 374, 358, 354, 357, 393, 356, 381, 357, 407, + 361, 397, 362, 394, 394, 392, 394, 391, 381, 386, 379, 354, 351, 392, 408, 393, 389, + 388, 385, 375, 388, 375, 388, 375, 354, 384, 379, 386, 394, 383, 359, 405, 395, 352, + 345, 403, 427, 373, 380, 350, 415, 378, 434, 385, 388, 387, 400, 405, 329, 391, 356, + 419, 358, 359, 375, 367, 391, 359, 369, 361, 376, 378, 379, 348, 390, 345, 388, 390, + 406, 349, 368, 364, 391, 384, 401, 384, 391, 361, 399, 359, 386, 392, 382, 386, 380, + 383, 345, 376, 393, 400, 395, 343, 352, 354, 381, 388, 357, 393, 389, 384, 389, 388, + 384, 404, 372, 358, 381, 352, 355, 485, 393, 371, 376, 389, 377, 391, 387, 376, 342, + 390, 375, 379, 396, 376, 402, 353, 392, 382, 383, 387, 386, 372, 377, 382, 388, 381, + 387, 357, 393, 385, 346, 389, 388, 357, 362, 404, 398, 397, 402, 371, 351, 370, 362, + 350, 388, 399, 402, 406, 377, 396, 359, 372, 390, 392, 368, 383, 346, 384, 381, 379, + 367, 384, 389, 381, 371, 358, 422, 372, 382, 374, 444, 412, 369, 362, 373, 389, 401, + 383, 380, 366, 365, 361, 379, 372, 345, 382, 375, 376, 375, 382, 356, 395, 383, 384, + 391, 361, 396, 407, 365, 351, 385, 378, 403, 344, 352, 387, 397, 399, 377, 371, 381, + 415, 382, 388, 368, 383, 405, 390, 386, 384, 374, 375, 381, 371, 372, 374, 377, 346, + 358, 381, 377, 359, 385, 396, 385, 390, 389, 391, 375, 357, 389, 390, 377, 370, 379, + 351, 381, 381, 380, 371, 386, 389, 389, 383, 362, 393, 388, 355, 396, 383, 352, 384, + 352, 383, 362, 396, 385, 396, 357, 388, 382, 377, 373, 379, 383, 386, 350, 393, 355, + 380, 401, 392, 391, 402, 391, 427, 407, 394, 332, 398, 367, 373, 343, 381, 383, 386, + 382, 349, 353, 393, 378, 386, 375, 390, 356, 392, 384, 387, 380, 381, 385, 386, 383, + 378, 379, 359, 381, 382, 388, 357, 357, 397, 358, 424, 382, 352, 409, 374, 368, 365, + 399, 352, 393, 389, 385, 352, 380, 398, 389, 385, 387, 387, 353, 402, 396, 386, 357, + 395, 368, 369, 407, 394, 383, 362, 380, 385, 368, 375, 365, 379, 377, 388, 380, 346, + 383, 381, 399, 359, 386, 455, 368, 406, 377, 339, 381, 377, 373, 371, 338, 371, 387, + 376, 386, 388, 382, 381, 377, 389, 352, 391, 396, 398, 374, 352, 358, 387, 368, 401, + 395, 387, 387, 354, 393, 401, 382, 390, 371, 374, 387, 377, 379, 377, 383, 374, 367, + 372, 393, 365, 392, 350, 378, 385, 377, 382, 388, 353, 389, 359, 366, 404, 390, 381, + 396, 388, 394, 380, 379, 372, 355, 397, 382, 351, 397, 378, 375, 378, 369, 387, 380, + 383, 346, 357, 362, 371, 413, 393, 365, 395, 391, 384, 386, 385, 390, 355, 385, 394, + 384, 383, 431, 369, 373, 392, 397, 396, 353, 391, 352, 375, 382, 397, 393, 371, 403, + 375, 338, 418, 368, 372, 370, 344, 392, 360, 402, 402, 425, 374, 378, 376, 380, 378, + 347, 379, 414, 377, 390, 383, 357, 390, 385, 377, 378, 368, 399, 389, 383, 368, 372, + 358, 386, 355, 380, 386, 349, 381, 379, 380, 351, 389, 380, 353, 359, 365, 370, 407, + 388, 381, 358, 364, 396, 369, 407, 391, 358, 440, 419, 412, 395, 344, 382, 391, 353, + 403, 391, 371, 354, 362, 407, 411, 397, 385, 388, 357, 348, 368, 401, 404, 380, 370, + 369, 365, 349, 373, 346, 351, 394, 399, 387, 393, 363, 402, 394, 375, 389, 386, 395, + 386, 386, 353, 403, 363, 376, 398, 383, 372, 350, 381, 353, 445, 386, 369, 383, 351, + 392, 397, 384, 389, 354, 400, 392, 379, 386, 355, 391, 388, 361, 390, 408, 357, 390, + 387, 352, 393, 357, 358, 401, 383, 391, 384, 388, 377, 380, 354, 393, 387, 357, 396, + 360, 362, 388, 390, 359, 367, 366, 396, 388, 394, 363, 391, 394, 351, 391, 391, 350, + 360, 365, 397, 366, 375, 400, 412, 372, 380, 383, 384, 383, 390, 380, 361, 363, 387, + 358, 385, 359, 385, 399, 351, 392, 388, 385, 384, 350, 379, 385, 383, 375, 389, 381, + 382, 376, 389, 390, 375, 381, 382, 390, 385, 380, 359, 351, 383, 391, 388, 379, 354, + 387, 382, 358, 381, 381, 386, 397, 373, 381, 387, 387, 381, 378, 383, 370, 360, 386, + 362, 402, 357, 398, 398, 397, 378, 394, 381, 375, 380, 390, 373, 369, 388, 347, 356, + 384, 391, 386, 394, 388, 357, 403, 381, 376, 414, 383, 387, 349, 379, 383, 384, 377, + 394, 426, 373, 392, 367, 381, 378, 378, 374, 373, 369, 368, 332, 335, 381, 392, 388, + 381, 424, 367, 398, 399, 392, 379, 391, 379, 370, 343, 405, 378, 367, 345, 379, 347, + 388, 353, 392, 382, 384, 387, 350, 363, 398, 398, 359, 402, 454, 440, 341, 383, 381, + 385, 355, 349, 369, 360, 388, 383, 354, 435, 405, 404, 399, 385, 386, 364, 388, 373, + 376, 384, 395, 400, 408, 390, 375, 341, 372, 371, 407, 345, 378, 345, 407, 365, 398, + 396, 339, 379, 375, 410, 386, 407, 387, 365, 375, 384, 347, 393, 377, 350, 376, 375, + 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]; + let ES_LENGTH = 1500; + + beforeAll(function() { + console.info('beforeAll case'); + }) + + beforeEach(function() { + console.info('beforeEach case'); + audioDecodeProcessor = null; + readStreamSync = undefined; + eosframenum = 0; + samplerate = 44.1; + workdoneAtEOS = false; + stopAtEOS = false; + resetAtEOS = false; + flushAtEOS = false; + needGetMediaDes = false; + needrelease = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + inputQueue = []; + outputQueue = []; + ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, + 541, 540, 542, 552, 537, 533, 498, 472, 445, 430, 445, 427, 414, 386, 413, 370, 380, + 401, 393, 369, 391, 367, 395, 396, 396, 385, 391, 384, 395, 392, 386, 388, 384, 379, + 376, 381, 375, 373, 349, 391, 357, 384, 395, 384, 380, 386, 372, 386, 383, 378, 385, + 385, 384, 342, 390, 379, 387, 386, 393, 397, 362, 393, 394, 391, 383, 385, 377, 379, + 381, 369, 375, 379, 346, 382, 356, 361, 366, 394, 393, 385, 362, 406, 399, 384, 377, + 385, 389, 375, 346, 396, 388, 381, 383, 352, 357, 397, 382, 395, 376, 388, 373, 374, + 353, 383, 384, 393, 379, 348, 364, 389, 380, 381, 388, 423, 392, 381, 368, 351, 391, + 355, 358, 395, 390, 385, 382, 383, 388, 388, 389, 376, 379, 376, 384, 369, 354, 390, + 389, 396, 393, 382, 385, 353, 383, 381, 377, 411, 387, 390, 377, 349, 381, 390, 378, + 373, 375, 381, 351, 392, 381, 380, 381, 378, 387, 379, 383, 348, 386, 364, 386, 371, + 399, 399, 385, 380, 355, 397, 395, 382, 380, 386, 352, 387, 390, 373, 372, 388, 378, + 385, 368, 385, 370, 378, 373, 383, 368, 373, 388, 351, 384, 391, 387, 389, 383, 355, + 361, 392, 386, 354, 394, 392, 397, 392, 352, 381, 395, 349, 383, 390, 392, 350, 393, + 393, 385, 389, 393, 382, 378, 384, 378, 375, 373, 375, 389, 377, 383, 387, 373, 344, + 388, 379, 391, 373, 384, 358, 361, 391, 394, 363, 350, 361, 395, 399, 389, 398, 375, + 398, 400, 381, 354, 363, 366, 400, 400, 356, 370, 400, 394, 398, 385, 378, 372, 354, + 359, 393, 381, 363, 396, 396, 355, 390, 356, 355, 371, 399, 367, 406, 375, 377, 405, + 401, 390, 393, 392, 384, 386, 374, 358, 397, 389, 393, 385, 345, 379, 357, 388, 356, + 381, 389, 367, 358, 391, 360, 394, 396, 357, 395, 388, 394, 383, 357, 383, 392, 394, + 376, 379, 356, 386, 395, 387, 377, 377, 389, 377, 385, 351, 387, 350, 388, 384, 345, + 358, 368, 399, 394, 385, 384, 395, 378, 387, 386, 386, 376, 375, 382, 351, 359, 356, + 401, 388, 363, 406, 363, 374, 435, 366, 400, 393, 392, 371, 391, 359, 359, 397, 388, + 390, 420, 411, 369, 384, 382, 383, 383, 375, 381, 361, 380, 348, 379, 386, 379, 379, + 386, 371, 352, 378, 378, 388, 384, 385, 352, 355, 387, 383, 379, 362, 386, 399, 376, + 390, 350, 387, 357, 403, 398, 397, 360, 351, 394, 400, 399, 393, 388, 395, 370, 377, + 395, 360, 346, 381, 370, 390, 380, 391, 387, 382, 384, 383, 354, 349, 394, 358, 387, + 400, 386, 402, 354, 396, 387, 391, 365, 377, 359, 361, 365, 395, 388, 388, 384, 388, + 378, 374, 382, 376, 377, 389, 378, 341, 390, 376, 381, 375, 414, 368, 369, 387, 411, + 396, 391, 378, 389, 349, 383, 344, 381, 387, 380, 353, 361, 391, 365, 390, 396, 382, + 386, 385, 385, 409, 387, 386, 378, 372, 372, 374, 349, 388, 389, 348, 395, 380, 382, + 388, 375, 347, 383, 359, 389, 368, 361, 405, 398, 393, 395, 359, 360, 395, 395, 362, + 354, 388, 348, 388, 386, 390, 350, 388, 356, 369, 364, 404, 404, 391, 394, 385, 439, + 432, 375, 366, 441, 362, 367, 382, 374, 346, 391, 371, 354, 376, 390, 373, 382, 385, + 389, 378, 377, 347, 414, 338, 348, 385, 352, 385, 386, 381, 388, 387, 364, 465, 405, + 443, 387, 339, 376, 337, 379, 387, 370, 374, 358, 354, 357, 393, 356, 381, 357, 407, + 361, 397, 362, 394, 394, 392, 394, 391, 381, 386, 379, 354, 351, 392, 408, 393, 389, + 388, 385, 375, 388, 375, 388, 375, 354, 384, 379, 386, 394, 383, 359, 405, 395, 352, + 345, 403, 427, 373, 380, 350, 415, 378, 434, 385, 388, 387, 400, 405, 329, 391, 356, + 419, 358, 359, 375, 367, 391, 359, 369, 361, 376, 378, 379, 348, 390, 345, 388, 390, + 406, 349, 368, 364, 391, 384, 401, 384, 391, 361, 399, 359, 386, 392, 382, 386, 380, + 383, 345, 376, 393, 400, 395, 343, 352, 354, 381, 388, 357, 393, 389, 384, 389, 388, + 384, 404, 372, 358, 381, 352, 355, 485, 393, 371, 376, 389, 377, 391, 387, 376, 342, + 390, 375, 379, 396, 376, 402, 353, 392, 382, 383, 387, 386, 372, 377, 382, 388, 381, + 387, 357, 393, 385, 346, 389, 388, 357, 362, 404, 398, 397, 402, 371, 351, 370, 362, + 350, 388, 399, 402, 406, 377, 396, 359, 372, 390, 392, 368, 383, 346, 384, 381, 379, + 367, 384, 389, 381, 371, 358, 422, 372, 382, 374, 444, 412, 369, 362, 373, 389, 401, + 383, 380, 366, 365, 361, 379, 372, 345, 382, 375, 376, 375, 382, 356, 395, 383, 384, + 391, 361, 396, 407, 365, 351, 385, 378, 403, 344, 352, 387, 397, 399, 377, 371, 381, + 415, 382, 388, 368, 383, 405, 390, 386, 384, 374, 375, 381, 371, 372, 374, 377, 346, + 358, 381, 377, 359, 385, 396, 385, 390, 389, 391, 375, 357, 389, 390, 377, 370, 379, + 351, 381, 381, 380, 371, 386, 389, 389, 383, 362, 393, 388, 355, 396, 383, 352, 384, + 352, 383, 362, 396, 385, 396, 357, 388, 382, 377, 373, 379, 383, 386, 350, 393, 355, + 380, 401, 392, 391, 402, 391, 427, 407, 394, 332, 398, 367, 373, 343, 381, 383, 386, + 382, 349, 353, 393, 378, 386, 375, 390, 356, 392, 384, 387, 380, 381, 385, 386, 383, + 378, 379, 359, 381, 382, 388, 357, 357, 397, 358, 424, 382, 352, 409, 374, 368, 365, + 399, 352, 393, 389, 385, 352, 380, 398, 389, 385, 387, 387, 353, 402, 396, 386, 357, + 395, 368, 369, 407, 394, 383, 362, 380, 385, 368, 375, 365, 379, 377, 388, 380, 346, + 383, 381, 399, 359, 386, 455, 368, 406, 377, 339, 381, 377, 373, 371, 338, 371, 387, + 376, 386, 388, 382, 381, 377, 389, 352, 391, 396, 398, 374, 352, 358, 387, 368, 401, + 395, 387, 387, 354, 393, 401, 382, 390, 371, 374, 387, 377, 379, 377, 383, 374, 367, + 372, 393, 365, 392, 350, 378, 385, 377, 382, 388, 353, 389, 359, 366, 404, 390, 381, + 396, 388, 394, 380, 379, 372, 355, 397, 382, 351, 397, 378, 375, 378, 369, 387, 380, + 383, 346, 357, 362, 371, 413, 393, 365, 395, 391, 384, 386, 385, 390, 355, 385, 394, + 384, 383, 431, 369, 373, 392, 397, 396, 353, 391, 352, 375, 382, 397, 393, 371, 403, + 375, 338, 418, 368, 372, 370, 344, 392, 360, 402, 402, 425, 374, 378, 376, 380, 378, + 347, 379, 414, 377, 390, 383, 357, 390, 385, 377, 378, 368, 399, 389, 383, 368, 372, + 358, 386, 355, 380, 386, 349, 381, 379, 380, 351, 389, 380, 353, 359, 365, 370, 407, + 388, 381, 358, 364, 396, 369, 407, 391, 358, 440, 419, 412, 395, 344, 382, 391, 353, + 403, 391, 371, 354, 362, 407, 411, 397, 385, 388, 357, 348, 368, 401, 404, 380, 370, + 369, 365, 349, 373, 346, 351, 394, 399, 387, 393, 363, 402, 394, 375, 389, 386, 395, + 386, 386, 353, 403, 363, 376, 398, 383, 372, 350, 381, 353, 445, 386, 369, 383, 351, + 392, 397, 384, 389, 354, 400, 392, 379, 386, 355, 391, 388, 361, 390, 408, 357, 390, + 387, 352, 393, 357, 358, 401, 383, 391, 384, 388, 377, 380, 354, 393, 387, 357, 396, + 360, 362, 388, 390, 359, 367, 366, 396, 388, 394, 363, 391, 394, 351, 391, 391, 350, + 360, 365, 397, 366, 375, 400, 412, 372, 380, 383, 384, 383, 390, 380, 361, 363, 387, + 358, 385, 359, 385, 399, 351, 392, 388, 385, 384, 350, 379, 385, 383, 375, 389, 381, + 382, 376, 389, 390, 375, 381, 382, 390, 385, 380, 359, 351, 383, 391, 388, 379, 354, + 387, 382, 358, 381, 381, 386, 397, 373, 381, 387, 387, 381, 378, 383, 370, 360, 386, + 362, 402, 357, 398, 398, 397, 378, 394, 381, 375, 380, 390, 373, 369, 388, 347, 356, + 384, 391, 386, 394, 388, 357, 403, 381, 376, 414, 383, 387, 349, 379, 383, 384, 377, + 394, 426, 373, 392, 367, 381, 378, 378, 374, 373, 369, 368, 332, 335, 381, 392, 388, + 381, 424, 367, 398, 399, 392, 379, 391, 379, 370, 343, 405, 378, 367, 345, 379, 347, + 388, 353, 392, 382, 384, 387, 350, 363, 398, 398, 359, 402, 454, 440, 341, 383, 381, + 385, 355, 349, 369, 360, 388, 383, 354, 435, 405, 404, 399, 385, 386, 364, 388, 373, + 376, 384, 395, 400, 408, 390, 375, 341, 372, 371, 407, 345, 378, 345, 407, 365, 398, + 396, 339, 379, 375, 410, 386, 407, 387, 365, 375, 384, 347, 393, 377, 350, 376, 375, + 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; + }) + + afterEach(async function() { + console.info('afterEach case'); + if (audioDecodeProcessor != null) { + audioDecodeProcessor = null; + } + }) + + afterAll(function() { + console.info('afterAll case'); + }) + + function resetParam(){ + readStreamSync = undefined; + eosframenum = 0; + samplerate = 44.1; + workdoneAtEOS = false; + stopAtEOS = false; + resetAtEOS = false; + flushAtEOS = false; + needGetMediaDes = false; + needrelease = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + } + + function writeFile(path, buf, len){ + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let num = writestream.writeSync(buf, {length:len}); + writestream.flushSync(); + writestream.closeSync(); + }catch(e){ + console.info(e) + } + } + + function readFile(path){ + console.info('read file start execution'); + try{ + console.info('filepath: ' + path); + readStreamSync = Fileio.createStreamSync(path, 'rb'); + }catch(e){ + console.info(e); + } + } + + function getContent(buf, len){ + console.info("start get content"); + let lengthreal = -1; + lengthreal = readStreamSync.readSync(buf,{length:len}); + console.info('lengthreal: ' + lengthreal); + } + + async function stopWork(audioDecodeProcessor) { + audioDecodeProcessor.stop((err) => { + expect(err).assertUndefined(); + console.info("case stop success") + }) + } + + async function resetWork(audioDecodeProcessor) { + audioDecodeProcessor.reset((err) => { + expect(err).assertUndefined(); + console.info("case reset success"); + if (needrelease) { + audioDecodeProcessor = null; + } + }) + } + + async function flushWork(audioDecodeProcessor) { + audioDecodeProcessor.flush((err) => { + expect(err).assertUndefined(); + console.info("case flush at inputeos success"); + resetParam(); + readFile(AUDIOPATH); + workdoneAtEOS =true; + }) + } + + async function doneWork(audioDecodeProcessor, done) { + audioDecodeProcessor.stop((err) => { + expect(err).assertUndefined(); + console.info("case stop success"); + audioDecodeProcessor.reset((err) => { + expect(err).assertUndefined(); + console.log("case reset success"); + done(); + }) + }) + } + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + function wait(time) { + for(let t = Date.now(); Date.now() - t <= time;); + } + + async function enqueueAllInputs(audioDecodeProcessor, queue){ + while (queue.length > 0 && !sawInputEOS){ + let inputobject = queue.shift(); + console.info("frameCnt:" + frameCnt); + if (frameCnt == eosframenum || frameCnt == ES_LENGTH + 1){ + inputobject.flags = 1; + inputobject.timeMs = 0; + inputobject.length = 0; + sawInputEOS = true; + } + else{ + console.info("read frame from file"); + inputobject.timeMs = timestamp; + inputobject.offset = 0; + inputobject.length = ES[frameCnt]; + getContent(inputobject.data, ES[frameCnt]); + inputobject.flags = 0; + } + timestamp += ES[frameCnt]/samplerate; + frameCnt += 1; + audioDecodeProcessor.queueInput(inputobject, () => { + console.info('queueInput success'); + }) + } + } + + async function dequeueAllOutputs(audioDecodeProcessor, queue, savepath, done) { + while (queue.length > 0 && !sawOutputEOS) { + let outputobject = queue.shift(); + if (outputobject.flags == 1) { + sawOutputEOS = true; + if (stopAtEOS) { + await stopWork(audioDecodeProcessor); + } else if (resetAtEOS) { + await resetWork(audioDecodeProcessor); + } else if (flushAtEOS) { + await flushWork(audioDecodeProcessor); + } else if (workdoneAtEOS) { + await doneWork(audioDecodeProcessor, done); + } else {} + } + else{ + writeFile(savepath, outputobject.data, outputobject.length); + console.info("write to file success"); + } + audioDecodeProcessor.releaseOutput(outputobject, () => { + console.info('release output success'); + }) + } + } + + function setCallback(audioDecodeProcessor, savepath, done){ + console.info('case callback'); + audioDecodeProcessor.on('inputBufferAvailable', async(inBuffer) => { + console.info('inputBufferAvailable'); + inputQueue.push(inBuffer); + await enqueueAllInputs(audioDecodeProcessor, inputQueue); + }); + audioDecodeProcessor.on('outputBufferAvailable', async(outBuffer) => { + console.info('outputBufferAvailable'); + if (needGetMediaDes){ + audioDecodeProcessor.getOutputMediaDescription((err, MediaDescription) => { + expect(err).assertUndefined(); + console.info("get OutputMediaDescription success"); + console.info('get outputMediaDescription : ' + MediaDescription); + needGetMediaDes=false; + }); + } + outputQueue.push(outBuffer); + await dequeueAllOutputs(audioDecodeProcessor, outputQueue, savepath, done); + }); + audioDecodeProcessor.on('error',(err) => { + console.info('case error called,errName is' + err); + }); + audioDecodeProcessor.on('outputFormatChanged',(format) => { + console.info('Output format changed: ' + format); + }); + } + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_00_0100 + * @tc.name : 000.test set EOS after last frame and reset + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_00_0100', 0, async function (done) { + console.info("case test set EOS after last frame and reset"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + workdoneAtEOS = true; + needGetMediaDes = true; + let savepath = BASIC_PATH + '0000.pcm'; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.info("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + }) + }); + eventEmitter.on('createAudioDecoder', () => { + media.createAudioDecoderByName('avdec_aac', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }); + media.getMediaCapability((err, mediaCaps) => { + expect(err).assertUndefined(); + console.info('getMediaCapability success'); + if (typeof (mediaCaps) != 'undefined') { + mediaCaps.getAudioDecoderCaps((err, audioCapsArray) => { + expect(err).assertUndefined(); + console.info('getAudioDecoderCaps success'); + if (typeof (audioCapsArray) != 'undefined') { + console.info('get first audioCaps'+ audioCapsArray[0]); + console.info('codecInfo: '+ audioCapsArray[0].codecInfo); + console.info('supportedBitrate: '+ audioCapsArray[0].supportedBitrate); + console.info('supportedBitrate.min: '+ audioCapsArray[0].supportedBitrate.min); + } else { + console.info('audioCaps is not defined'); + } + }) + } else { + console.info('mediaCaps is not defined'); + } + eventEmitter.emit('createAudioDecoder'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_01_0100 + * @tc.name : 001.test set EOS manually before last frame and reset + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_01_0100', 0, async function (done) { + console.info("case test set EOS manually before last frame and reset"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + eosframenum = 500; + workdoneAtEOS = true; + let savepath = BASIC_PATH + '0100.pcm'; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.info("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + }) + }); + media.getMediaCapability((err, mediaCaps) => { + expect(err).assertUndefined(); + console.info(`case getMediaCapability 1`); + mediaCaps.getAudioDecoderCaps((err, audioCaps) => { + expect(err).assertUndefined(); + console.info('getAudioDecoderCaps success'); + if (typeof (audioCaps) != 'undefined') { + console.info("case audioCaps " + audioCaps); + } else { + console.info("case audioCaps is not defined"); + } + }) + }) + media.createAudioDecoderByName('avdec_aac', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_01_0200 + * @tc.name : 002.test flush at running state + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_01_0200', 0, async function (done) { + console.info("case test flush at running state"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + workdoneAtEOS = true; + let savepath = BASIC_PATH + '0200.pcm'; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.info("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + setTimeout(() => {eventEmitter.emit('flush')},2000) + }) + }); + eventEmitter.on('flush', () => { + audioDecodeProcessor.flush((err) => { + expect(err).assertUndefined(); + console.info(`case flush after 2s`); + }) + }); + media.createAudioDecoderByMime('audio/mp4a-latm', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_01_0300 + * @tc.name : 003. test flush at EOS state + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_01_0300', 0, async function (done) { + console.info("case test flush at EOS state"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + eosframenum = 200; + flushAtEOS = true; + let savepath = BASIC_PATH + '0300.pcm'; + + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.info("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + }) + }); + media.createAudioDecoderByMime('audio/mp4a-latm', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_01_0400 + * @tc.name : 004. test stop at running state and reset + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_01_0400', 0, async function (done) { + console.info("case test stop at running state and reset"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + '0400.pcm'; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.info("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + eventEmitter.emit('stop'); + }) + }); + eventEmitter.on('stop', () => { + sleep(5000).then(() => { + audioDecodeProcessor.stop((err) => { + expect(err).assertUndefined(); + console.info(`case stop 1`); + eventEmitter.emit('reset'); + }) + }) + }); + eventEmitter.on('reset', () => { + audioDecodeProcessor.reset((err) => { + expect(err).assertUndefined(); + console.info(`case reset 1`); + audioDecodeProcessor = null; + done(); + }) + }); + media.createAudioDecoderByMime('audio/mp4a-latm', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_01_0500 + * @tc.name : 005. test stop and restart + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_01_0500', 0, async function (done) { + console.info("case test start - stop - restart"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + eosframenum = 200; + let savepath = BASIC_PATH + '0500.pcm'; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.info("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + eventEmitter.emit('stop'); + }) + }); + eventEmitter.on('stop', () => { + sleep(5000).then(() => { + audioDecodeProcessor.stop((err) => { + expect(err).assertUndefined(); + console.info(`stop after 5s`); + resetParam(); + readFile(AUDIOPATH); + eventEmitter.emit('restart'); + }) + }) + }); + eventEmitter.on('restart', () => { + sleep(2000).then(() => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`restart after 2s`); + workdoneAtEOS=true; + enqueueAllInputs(audioDecodeProcessor, inputQueue); + }) + }) + }); + media.createAudioDecoderByMime('audio/mp4a-latm', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_01_0600 + * @tc.name : 006. test reconfigure for new file with the same format + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_01_0600', 0, async function (done) { + console.info("case test reconfigure codec for new file with the same format"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + eosframenum = 200; + resetAtEOS = true; + let savepath = BASIC_PATH + '0600.pcm'; + let mediaDescription2 = { + "channel_count": 1, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let hasreconfigured = false; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.info("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + if (!hasreconfigured){ + eventEmitter.emit('reconfigure', mediaDescription2); + } + }) + }); + eventEmitter.on('reconfigure', (mediaDescription2) => { + sleep(10000).then(() => { + audioDecodeProcessor.configure(mediaDescription2, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 2`); + resetParam(); + console.info('resetParam success, resetAtEOS IS :' + resetAtEOS) + readFile(AUDIOPATH2) + savepath = BASIC_PATH + '0601.pcm'; + workdoneAtEOS = true; + ES = [0, 239, 302, 309, 330, 474, 684, 699, 683, 674, 647, 649, 638, 644, 640, + 639, 650, 702, 713, 718, 707, 707, 683, 670, 674, 699, 654, 650, 715, 770, + 764, 736, 697, 664, 643, 649, 704, 730, 720, 710, 689, 670, 673, 653, 635, + 643, 638, 653, 658, 683, 683, 705, 690, 681, 648, 659, 743, 681, 706, 707, + 718, 714, 746, 725, 741, 709, 675, 675, 751, 698, 736, 738, 711, 702, 691, + 668, 668, 650, 661, 678, 694, 719, 685, 700, 657, 671, 668, 701, 689, 685, + 682, 668, 696, 690, 683, 739, 704, 667, 694, 716, 757, 714, 701, 664, 619, + 609, 591, 644, 573, 572, 605, 595, 597, 529, 581, 578, 586, 537, 577, 535, + 572, 570, 534, 547, 581, 530, 591, 521, 556, 570, 557, 541, 506, 572, 579, + 502, 516, 582, 540, 584, 548, 555, 539, 578, 588, 541, 539, 526, 575, 535, + 571, 525, 569, 560, 584, 551, 574, 572, 537, 550, 582, 512, 559, 593, 601, + 594, 546, 560, 567, 547, 529, 576, 577, 556, 551, 530, 542, 575, 510, 559, + 613, 628, 511, 566, 515, 539, 594, 536, 565, 551, 533, 613, 557, 523, 574, + 582, 616, 610, 573, 509, 535]; + ES_LENGTH = 200; + samplerate = 16; + hasreconfigured = true; + eventEmitter.emit('prepare'); + }) + }) + }); + media.createAudioDecoderByMime('audio/mp4a-latm', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_01_0700 + * @tc.name : 007. test reconfigure for new file with different formats + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_CALLBACK_01_0700', 0, async function (done) { + console.info("case test reconfigure codec for new file with different format"); + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let mediaDescription2 = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 4, + } + let hasrecreate = false; + eosframenum = 200; + resetAtEOS = true; + needrelease = true; + let savepath = BASIC_PATH + '0700.pcm'; + eventEmitter.on('getAudioDecoderCaps', () => { + audioDecodeProcessor.getAudioDecoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioDecoderCaps 1`); + console.info("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioDecodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + if (!hasrecreate){ + eventEmitter.emit('recreate'); + } + }) + }); + eventEmitter.on('recreate', () => { + sleep(10000).then(() => { + media.createAudioDecoderByMime('audio/flac', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder flac`); + audioDecodeProcessor = processor; + hasrecreate = true; + eventEmitter.emit('reconfigure', mediaDescription2); + }) + }) + }); + eventEmitter.on('reconfigure', (mediaDescription2) => { + audioDecodeProcessor.configure(mediaDescription2, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 2`); + resetParam(); + readFile(AUDIOPATH3) + savepath = BASIC_PATH + '0701.pcm'; + workdoneAtEOS = true; + ES = [0, 2116, 2093, 2886, 2859, 2798, 2778, 2752, 2752, 2754, 2720, 2898, 2829, + 2806, 2796, 2786, 2774, 2758, 2741, 3489, 3342, 3272, 3167, 3048, 3060, 2919, + 2839, 2794, 2770, 2763, 2756, 2722, 2950, 2876, 2842, 2827, 2792, 3121, 3075, + 2969, 3240, 3199, 3082, 2975, 2895, 3135, 3024, 2970, 2902, 2860, 2802, 2778, + 2779, 2963, 2893, 2870, 2831, 2800, 2762, 2752, 2760, 2759, 2726, 2889, 2960, + 2876, 3223, 3040, 3006, 3042, 2980, 3097, 3069, 3215, 3365, 3296, 3653, 3480, + 3300, 3140, 3014, 2975, 2952, 2896, 2897, 2842, 2929, 3567, 3929, 3485, 3082, + 3625, 4953, 5239, 5094, 4993, 4821, 4431, 5195, 5542, 5557, 4894, 4414]; + ES_LENGTH = 100; + samplerate = 48; + eventEmitter.emit('prepare'); + }) + }); + media.createAudioDecoderByName('avdec_aac', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + eventEmitter.emit('getAudioDecoderCaps'); + }) + }) +}) + 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 new file mode 100644 index 0000000000000000000000000000000000000000..151da108bfb0f841dc924beaa5c4f46d3c8ecb4a --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFuncPromiseTest.test.js @@ -0,0 +1,871 @@ +/* + * Copyright (C) 2021 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 media from '@ohos.multimedia.media' +import Fileio from '@ohos.fileio' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('AudioDecoderFunc', function () { + const AUDIOPATH = '/data/media/AAC_48000_32_1.aac'; + const AUDIOPATH2 = '/data/media/AAC_16000_1.aac'; + const AUDIOPATH3 = '/data/media/FLAC_48000_32_1.flac'; + const BASIC_PATH = '/data/media/results/decode_func_promise_'; + let readStreamSync; + let eosframenum = 0; + let samplerate = 44.1; + let stopAtEOS = false; + let resetAtEOS = false; + let flushAtEOS = false; + let workdoneAtEOS = false; + let needGetMediaDes = false; + let needrelease = false; + let frameCnt = 1; + let timestamp = 0; + let sawInputEOS = false; + let sawOutputEOS = false; + let inputQueue = []; + let outputQueue = []; + let ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, + 541, 540, 542, 552, 537, 533, 498, 472, 445, 430, 445, 427, 414, 386, 413, 370, 380, + 401, 393, 369, 391, 367, 395, 396, 396, 385, 391, 384, 395, 392, 386, 388, 384, 379, + 376, 381, 375, 373, 349, 391, 357, 384, 395, 384, 380, 386, 372, 386, 383, 378, 385, + 385, 384, 342, 390, 379, 387, 386, 393, 397, 362, 393, 394, 391, 383, 385, 377, 379, + 381, 369, 375, 379, 346, 382, 356, 361, 366, 394, 393, 385, 362, 406, 399, 384, 377, + 385, 389, 375, 346, 396, 388, 381, 383, 352, 357, 397, 382, 395, 376, 388, 373, 374, + 353, 383, 384, 393, 379, 348, 364, 389, 380, 381, 388, 423, 392, 381, 368, 351, 391, + 355, 358, 395, 390, 385, 382, 383, 388, 388, 389, 376, 379, 376, 384, 369, 354, 390, + 389, 396, 393, 382, 385, 353, 383, 381, 377, 411, 387, 390, 377, 349, 381, 390, 378, + 373, 375, 381, 351, 392, 381, 380, 381, 378, 387, 379, 383, 348, 386, 364, 386, 371, + 399, 399, 385, 380, 355, 397, 395, 382, 380, 386, 352, 387, 390, 373, 372, 388, 378, + 385, 368, 385, 370, 378, 373, 383, 368, 373, 388, 351, 384, 391, 387, 389, 383, 355, + 361, 392, 386, 354, 394, 392, 397, 392, 352, 381, 395, 349, 383, 390, 392, 350, 393, + 393, 385, 389, 393, 382, 378, 384, 378, 375, 373, 375, 389, 377, 383, 387, 373, 344, + 388, 379, 391, 373, 384, 358, 361, 391, 394, 363, 350, 361, 395, 399, 389, 398, 375, + 398, 400, 381, 354, 363, 366, 400, 400, 356, 370, 400, 394, 398, 385, 378, 372, 354, + 359, 393, 381, 363, 396, 396, 355, 390, 356, 355, 371, 399, 367, 406, 375, 377, 405, + 401, 390, 393, 392, 384, 386, 374, 358, 397, 389, 393, 385, 345, 379, 357, 388, 356, + 381, 389, 367, 358, 391, 360, 394, 396, 357, 395, 388, 394, 383, 357, 383, 392, 394, + 376, 379, 356, 386, 395, 387, 377, 377, 389, 377, 385, 351, 387, 350, 388, 384, 345, + 358, 368, 399, 394, 385, 384, 395, 378, 387, 386, 386, 376, 375, 382, 351, 359, 356, + 401, 388, 363, 406, 363, 374, 435, 366, 400, 393, 392, 371, 391, 359, 359, 397, 388, + 390, 420, 411, 369, 384, 382, 383, 383, 375, 381, 361, 380, 348, 379, 386, 379, 379, + 386, 371, 352, 378, 378, 388, 384, 385, 352, 355, 387, 383, 379, 362, 386, 399, 376, + 390, 350, 387, 357, 403, 398, 397, 360, 351, 394, 400, 399, 393, 388, 395, 370, 377, + 395, 360, 346, 381, 370, 390, 380, 391, 387, 382, 384, 383, 354, 349, 394, 358, 387, + 400, 386, 402, 354, 396, 387, 391, 365, 377, 359, 361, 365, 395, 388, 388, 384, 388, + 378, 374, 382, 376, 377, 389, 378, 341, 390, 376, 381, 375, 414, 368, 369, 387, 411, + 396, 391, 378, 389, 349, 383, 344, 381, 387, 380, 353, 361, 391, 365, 390, 396, 382, + 386, 385, 385, 409, 387, 386, 378, 372, 372, 374, 349, 388, 389, 348, 395, 380, 382, + 388, 375, 347, 383, 359, 389, 368, 361, 405, 398, 393, 395, 359, 360, 395, 395, 362, + 354, 388, 348, 388, 386, 390, 350, 388, 356, 369, 364, 404, 404, 391, 394, 385, 439, + 432, 375, 366, 441, 362, 367, 382, 374, 346, 391, 371, 354, 376, 390, 373, 382, 385, + 389, 378, 377, 347, 414, 338, 348, 385, 352, 385, 386, 381, 388, 387, 364, 465, 405, + 443, 387, 339, 376, 337, 379, 387, 370, 374, 358, 354, 357, 393, 356, 381, 357, 407, + 361, 397, 362, 394, 394, 392, 394, 391, 381, 386, 379, 354, 351, 392, 408, 393, 389, + 388, 385, 375, 388, 375, 388, 375, 354, 384, 379, 386, 394, 383, 359, 405, 395, 352, + 345, 403, 427, 373, 380, 350, 415, 378, 434, 385, 388, 387, 400, 405, 329, 391, 356, + 419, 358, 359, 375, 367, 391, 359, 369, 361, 376, 378, 379, 348, 390, 345, 388, 390, + 406, 349, 368, 364, 391, 384, 401, 384, 391, 361, 399, 359, 386, 392, 382, 386, 380, + 383, 345, 376, 393, 400, 395, 343, 352, 354, 381, 388, 357, 393, 389, 384, 389, 388, + 384, 404, 372, 358, 381, 352, 355, 485, 393, 371, 376, 389, 377, 391, 387, 376, 342, + 390, 375, 379, 396, 376, 402, 353, 392, 382, 383, 387, 386, 372, 377, 382, 388, 381, + 387, 357, 393, 385, 346, 389, 388, 357, 362, 404, 398, 397, 402, 371, 351, 370, 362, + 350, 388, 399, 402, 406, 377, 396, 359, 372, 390, 392, 368, 383, 346, 384, 381, 379, + 367, 384, 389, 381, 371, 358, 422, 372, 382, 374, 444, 412, 369, 362, 373, 389, 401, + 383, 380, 366, 365, 361, 379, 372, 345, 382, 375, 376, 375, 382, 356, 395, 383, 384, + 391, 361, 396, 407, 365, 351, 385, 378, 403, 344, 352, 387, 397, 399, 377, 371, 381, + 415, 382, 388, 368, 383, 405, 390, 386, 384, 374, 375, 381, 371, 372, 374, 377, 346, + 358, 381, 377, 359, 385, 396, 385, 390, 389, 391, 375, 357, 389, 390, 377, 370, 379, + 351, 381, 381, 380, 371, 386, 389, 389, 383, 362, 393, 388, 355, 396, 383, 352, 384, + 352, 383, 362, 396, 385, 396, 357, 388, 382, 377, 373, 379, 383, 386, 350, 393, 355, + 380, 401, 392, 391, 402, 391, 427, 407, 394, 332, 398, 367, 373, 343, 381, 383, 386, + 382, 349, 353, 393, 378, 386, 375, 390, 356, 392, 384, 387, 380, 381, 385, 386, 383, + 378, 379, 359, 381, 382, 388, 357, 357, 397, 358, 424, 382, 352, 409, 374, 368, 365, + 399, 352, 393, 389, 385, 352, 380, 398, 389, 385, 387, 387, 353, 402, 396, 386, 357, + 395, 368, 369, 407, 394, 383, 362, 380, 385, 368, 375, 365, 379, 377, 388, 380, 346, + 383, 381, 399, 359, 386, 455, 368, 406, 377, 339, 381, 377, 373, 371, 338, 371, 387, + 376, 386, 388, 382, 381, 377, 389, 352, 391, 396, 398, 374, 352, 358, 387, 368, 401, + 395, 387, 387, 354, 393, 401, 382, 390, 371, 374, 387, 377, 379, 377, 383, 374, 367, + 372, 393, 365, 392, 350, 378, 385, 377, 382, 388, 353, 389, 359, 366, 404, 390, 381, + 396, 388, 394, 380, 379, 372, 355, 397, 382, 351, 397, 378, 375, 378, 369, 387, 380, + 383, 346, 357, 362, 371, 413, 393, 365, 395, 391, 384, 386, 385, 390, 355, 385, 394, + 384, 383, 431, 369, 373, 392, 397, 396, 353, 391, 352, 375, 382, 397, 393, 371, 403, + 375, 338, 418, 368, 372, 370, 344, 392, 360, 402, 402, 425, 374, 378, 376, 380, 378, + 347, 379, 414, 377, 390, 383, 357, 390, 385, 377, 378, 368, 399, 389, 383, 368, 372, + 358, 386, 355, 380, 386, 349, 381, 379, 380, 351, 389, 380, 353, 359, 365, 370, 407, + 388, 381, 358, 364, 396, 369, 407, 391, 358, 440, 419, 412, 395, 344, 382, 391, 353, + 403, 391, 371, 354, 362, 407, 411, 397, 385, 388, 357, 348, 368, 401, 404, 380, 370, + 369, 365, 349, 373, 346, 351, 394, 399, 387, 393, 363, 402, 394, 375, 389, 386, 395, + 386, 386, 353, 403, 363, 376, 398, 383, 372, 350, 381, 353, 445, 386, 369, 383, 351, + 392, 397, 384, 389, 354, 400, 392, 379, 386, 355, 391, 388, 361, 390, 408, 357, 390, + 387, 352, 393, 357, 358, 401, 383, 391, 384, 388, 377, 380, 354, 393, 387, 357, 396, + 360, 362, 388, 390, 359, 367, 366, 396, 388, 394, 363, 391, 394, 351, 391, 391, 350, + 360, 365, 397, 366, 375, 400, 412, 372, 380, 383, 384, 383, 390, 380, 361, 363, 387, + 358, 385, 359, 385, 399, 351, 392, 388, 385, 384, 350, 379, 385, 383, 375, 389, 381, + 382, 376, 389, 390, 375, 381, 382, 390, 385, 380, 359, 351, 383, 391, 388, 379, 354, + 387, 382, 358, 381, 381, 386, 397, 373, 381, 387, 387, 381, 378, 383, 370, 360, 386, + 362, 402, 357, 398, 398, 397, 378, 394, 381, 375, 380, 390, 373, 369, 388, 347, 356, + 384, 391, 386, 394, 388, 357, 403, 381, 376, 414, 383, 387, 349, 379, 383, 384, 377, + 394, 426, 373, 392, 367, 381, 378, 378, 374, 373, 369, 368, 332, 335, 381, 392, 388, + 381, 424, 367, 398, 399, 392, 379, 391, 379, 370, 343, 405, 378, 367, 345, 379, 347, + 388, 353, 392, 382, 384, 387, 350, 363, 398, 398, 359, 402, 454, 440, 341, 383, 381, + 385, 355, 349, 369, 360, 388, 383, 354, 435, 405, 404, 399, 385, 386, 364, 388, 373, + 376, 384, 395, 400, 408, 390, 375, 341, 372, 371, 407, 345, 378, 345, 407, 365, 398, + 396, 339, 379, 375, 410, 386, 407, 387, 365, 375, 384, 347, 393, 377, 350, 376, 375, + 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]; + let ES_LENGTH = 1500; + + beforeAll(function() { + console.info('beforeAll case'); + }) + + beforeEach(function() { + console.info('beforeEach case'); + readStreamSync = undefined; + eosframenum = 0; + samplerate = 44.1; + stopAtEOS = false; + resetAtEOS = false; + flushAtEOS = false; + workdoneAtEOS = false; + needGetMediaDes = false; + needrelease = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + inputQueue = []; + outputQueue = []; + ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, + 541, 540, 542, 552, 537, 533, 498, 472, 445, 430, 445, 427, 414, 386, 413, 370, 380, + 401, 393, 369, 391, 367, 395, 396, 396, 385, 391, 384, 395, 392, 386, 388, 384, 379, + 376, 381, 375, 373, 349, 391, 357, 384, 395, 384, 380, 386, 372, 386, 383, 378, 385, + 385, 384, 342, 390, 379, 387, 386, 393, 397, 362, 393, 394, 391, 383, 385, 377, 379, + 381, 369, 375, 379, 346, 382, 356, 361, 366, 394, 393, 385, 362, 406, 399, 384, 377, + 385, 389, 375, 346, 396, 388, 381, 383, 352, 357, 397, 382, 395, 376, 388, 373, 374, + 353, 383, 384, 393, 379, 348, 364, 389, 380, 381, 388, 423, 392, 381, 368, 351, 391, + 355, 358, 395, 390, 385, 382, 383, 388, 388, 389, 376, 379, 376, 384, 369, 354, 390, + 389, 396, 393, 382, 385, 353, 383, 381, 377, 411, 387, 390, 377, 349, 381, 390, 378, + 373, 375, 381, 351, 392, 381, 380, 381, 378, 387, 379, 383, 348, 386, 364, 386, 371, + 399, 399, 385, 380, 355, 397, 395, 382, 380, 386, 352, 387, 390, 373, 372, 388, 378, + 385, 368, 385, 370, 378, 373, 383, 368, 373, 388, 351, 384, 391, 387, 389, 383, 355, + 361, 392, 386, 354, 394, 392, 397, 392, 352, 381, 395, 349, 383, 390, 392, 350, 393, + 393, 385, 389, 393, 382, 378, 384, 378, 375, 373, 375, 389, 377, 383, 387, 373, 344, + 388, 379, 391, 373, 384, 358, 361, 391, 394, 363, 350, 361, 395, 399, 389, 398, 375, + 398, 400, 381, 354, 363, 366, 400, 400, 356, 370, 400, 394, 398, 385, 378, 372, 354, + 359, 393, 381, 363, 396, 396, 355, 390, 356, 355, 371, 399, 367, 406, 375, 377, 405, + 401, 390, 393, 392, 384, 386, 374, 358, 397, 389, 393, 385, 345, 379, 357, 388, 356, + 381, 389, 367, 358, 391, 360, 394, 396, 357, 395, 388, 394, 383, 357, 383, 392, 394, + 376, 379, 356, 386, 395, 387, 377, 377, 389, 377, 385, 351, 387, 350, 388, 384, 345, + 358, 368, 399, 394, 385, 384, 395, 378, 387, 386, 386, 376, 375, 382, 351, 359, 356, + 401, 388, 363, 406, 363, 374, 435, 366, 400, 393, 392, 371, 391, 359, 359, 397, 388, + 390, 420, 411, 369, 384, 382, 383, 383, 375, 381, 361, 380, 348, 379, 386, 379, 379, + 386, 371, 352, 378, 378, 388, 384, 385, 352, 355, 387, 383, 379, 362, 386, 399, 376, + 390, 350, 387, 357, 403, 398, 397, 360, 351, 394, 400, 399, 393, 388, 395, 370, 377, + 395, 360, 346, 381, 370, 390, 380, 391, 387, 382, 384, 383, 354, 349, 394, 358, 387, + 400, 386, 402, 354, 396, 387, 391, 365, 377, 359, 361, 365, 395, 388, 388, 384, 388, + 378, 374, 382, 376, 377, 389, 378, 341, 390, 376, 381, 375, 414, 368, 369, 387, 411, + 396, 391, 378, 389, 349, 383, 344, 381, 387, 380, 353, 361, 391, 365, 390, 396, 382, + 386, 385, 385, 409, 387, 386, 378, 372, 372, 374, 349, 388, 389, 348, 395, 380, 382, + 388, 375, 347, 383, 359, 389, 368, 361, 405, 398, 393, 395, 359, 360, 395, 395, 362, + 354, 388, 348, 388, 386, 390, 350, 388, 356, 369, 364, 404, 404, 391, 394, 385, 439, + 432, 375, 366, 441, 362, 367, 382, 374, 346, 391, 371, 354, 376, 390, 373, 382, 385, + 389, 378, 377, 347, 414, 338, 348, 385, 352, 385, 386, 381, 388, 387, 364, 465, 405, + 443, 387, 339, 376, 337, 379, 387, 370, 374, 358, 354, 357, 393, 356, 381, 357, 407, + 361, 397, 362, 394, 394, 392, 394, 391, 381, 386, 379, 354, 351, 392, 408, 393, 389, + 388, 385, 375, 388, 375, 388, 375, 354, 384, 379, 386, 394, 383, 359, 405, 395, 352, + 345, 403, 427, 373, 380, 350, 415, 378, 434, 385, 388, 387, 400, 405, 329, 391, 356, + 419, 358, 359, 375, 367, 391, 359, 369, 361, 376, 378, 379, 348, 390, 345, 388, 390, + 406, 349, 368, 364, 391, 384, 401, 384, 391, 361, 399, 359, 386, 392, 382, 386, 380, + 383, 345, 376, 393, 400, 395, 343, 352, 354, 381, 388, 357, 393, 389, 384, 389, 388, + 384, 404, 372, 358, 381, 352, 355, 485, 393, 371, 376, 389, 377, 391, 387, 376, 342, + 390, 375, 379, 396, 376, 402, 353, 392, 382, 383, 387, 386, 372, 377, 382, 388, 381, + 387, 357, 393, 385, 346, 389, 388, 357, 362, 404, 398, 397, 402, 371, 351, 370, 362, + 350, 388, 399, 402, 406, 377, 396, 359, 372, 390, 392, 368, 383, 346, 384, 381, 379, + 367, 384, 389, 381, 371, 358, 422, 372, 382, 374, 444, 412, 369, 362, 373, 389, 401, + 383, 380, 366, 365, 361, 379, 372, 345, 382, 375, 376, 375, 382, 356, 395, 383, 384, + 391, 361, 396, 407, 365, 351, 385, 378, 403, 344, 352, 387, 397, 399, 377, 371, 381, + 415, 382, 388, 368, 383, 405, 390, 386, 384, 374, 375, 381, 371, 372, 374, 377, 346, + 358, 381, 377, 359, 385, 396, 385, 390, 389, 391, 375, 357, 389, 390, 377, 370, 379, + 351, 381, 381, 380, 371, 386, 389, 389, 383, 362, 393, 388, 355, 396, 383, 352, 384, + 352, 383, 362, 396, 385, 396, 357, 388, 382, 377, 373, 379, 383, 386, 350, 393, 355, + 380, 401, 392, 391, 402, 391, 427, 407, 394, 332, 398, 367, 373, 343, 381, 383, 386, + 382, 349, 353, 393, 378, 386, 375, 390, 356, 392, 384, 387, 380, 381, 385, 386, 383, + 378, 379, 359, 381, 382, 388, 357, 357, 397, 358, 424, 382, 352, 409, 374, 368, 365, + 399, 352, 393, 389, 385, 352, 380, 398, 389, 385, 387, 387, 353, 402, 396, 386, 357, + 395, 368, 369, 407, 394, 383, 362, 380, 385, 368, 375, 365, 379, 377, 388, 380, 346, + 383, 381, 399, 359, 386, 455, 368, 406, 377, 339, 381, 377, 373, 371, 338, 371, 387, + 376, 386, 388, 382, 381, 377, 389, 352, 391, 396, 398, 374, 352, 358, 387, 368, 401, + 395, 387, 387, 354, 393, 401, 382, 390, 371, 374, 387, 377, 379, 377, 383, 374, 367, + 372, 393, 365, 392, 350, 378, 385, 377, 382, 388, 353, 389, 359, 366, 404, 390, 381, + 396, 388, 394, 380, 379, 372, 355, 397, 382, 351, 397, 378, 375, 378, 369, 387, 380, + 383, 346, 357, 362, 371, 413, 393, 365, 395, 391, 384, 386, 385, 390, 355, 385, 394, + 384, 383, 431, 369, 373, 392, 397, 396, 353, 391, 352, 375, 382, 397, 393, 371, 403, + 375, 338, 418, 368, 372, 370, 344, 392, 360, 402, 402, 425, 374, 378, 376, 380, 378, + 347, 379, 414, 377, 390, 383, 357, 390, 385, 377, 378, 368, 399, 389, 383, 368, 372, + 358, 386, 355, 380, 386, 349, 381, 379, 380, 351, 389, 380, 353, 359, 365, 370, 407, + 388, 381, 358, 364, 396, 369, 407, 391, 358, 440, 419, 412, 395, 344, 382, 391, 353, + 403, 391, 371, 354, 362, 407, 411, 397, 385, 388, 357, 348, 368, 401, 404, 380, 370, + 369, 365, 349, 373, 346, 351, 394, 399, 387, 393, 363, 402, 394, 375, 389, 386, 395, + 386, 386, 353, 403, 363, 376, 398, 383, 372, 350, 381, 353, 445, 386, 369, 383, 351, + 392, 397, 384, 389, 354, 400, 392, 379, 386, 355, 391, 388, 361, 390, 408, 357, 390, + 387, 352, 393, 357, 358, 401, 383, 391, 384, 388, 377, 380, 354, 393, 387, 357, 396, + 360, 362, 388, 390, 359, 367, 366, 396, 388, 394, 363, 391, 394, 351, 391, 391, 350, + 360, 365, 397, 366, 375, 400, 412, 372, 380, 383, 384, 383, 390, 380, 361, 363, 387, + 358, 385, 359, 385, 399, 351, 392, 388, 385, 384, 350, 379, 385, 383, 375, 389, 381, + 382, 376, 389, 390, 375, 381, 382, 390, 385, 380, 359, 351, 383, 391, 388, 379, 354, + 387, 382, 358, 381, 381, 386, 397, 373, 381, 387, 387, 381, 378, 383, 370, 360, 386, + 362, 402, 357, 398, 398, 397, 378, 394, 381, 375, 380, 390, 373, 369, 388, 347, 356, + 384, 391, 386, 394, 388, 357, 403, 381, 376, 414, 383, 387, 349, 379, 383, 384, 377, + 394, 426, 373, 392, 367, 381, 378, 378, 374, 373, 369, 368, 332, 335, 381, 392, 388, + 381, 424, 367, 398, 399, 392, 379, 391, 379, 370, 343, 405, 378, 367, 345, 379, 347, + 388, 353, 392, 382, 384, 387, 350, 363, 398, 398, 359, 402, 454, 440, 341, 383, 381, + 385, 355, 349, 369, 360, 388, 383, 354, 435, 405, 404, 399, 385, 386, 364, 388, 373, + 376, 384, 395, 400, 408, 390, 375, 341, 372, 371, 407, 345, 378, 345, 407, 365, 398, + 396, 339, 379, 375, 410, 386, 407, 387, 365, 375, 384, 347, 393, 377, 350, 376, 375, + 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; + }) + + afterEach(function() { + console.info('afterEach case'); + if (audioDecodeProcessor != null){ + audioDecodeProcessor.release().then(() => { + console.info('audioDecodeProcessor release success'); + audioDecodeProcessor = null; + }) + } + }) + + afterAll(function() { + console.info('afterAll case'); + }) + + let failCallback = function(err) { + console.info('case callback err : ' + err); + expect(err).assertUndefined(); + } + + let failCatch = function(err) { + console.info('case catch err : ' + err); + expect(err).assertUndefined(); + } + + function resetParam() { + readStreamSync = undefined; + eosframenum = 0; + samplerate = 44.1; + stopAtEOS = false; + resetAtEOS = false; + flushAtEOS = false; + workdoneAtEOS = false; + needGetMediaDes = false; + needrelease = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + } + + function writeFile(path, buf, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let num = writestream.writeSync(buf, {length:len}); + writestream.flushSync(); + writestream.closeSync(); + }catch(e) { + console.info(e) + } + } + + function readFile(path) { + console.info('read file start execution'); + try{ + console.info('filepath: ' + path); + readStreamSync = Fileio.createStreamSync(path, 'rb'); + }catch(e) { + console.info(e); + } + } + + function getContent(buf, len) { + console.info("case start get content"); + let lengthreal = -1; + lengthreal = readStreamSync.readSync(buf,{length:len}); + } + + async function stopWork(audioDecodeProcessor) { + await audioDecodeProcessor.stop().then(() => { + console.info("case stop success") + }, failCallback).catch(failCatch); + } + + async function resetWork(audioDecodeProcessor) { + await audioDecodeProcessor.reset().then(() => { + console.info("case reset success"); + if (needrelease) { + audioDecodeProcessor = null; + } + }, failCallback).catch(failCatch); + } + + async function flushWork(audioDecodeProcessor) { + await audioDecodeProcessor.flush().then(() => { + console.info("case flush at inputeos success"); + resetParam(); + readFile(AUDIOPATH); + workdoneAtEOS =true; + }, failCallback).catch(failCatch); + } + + async function doneWork(audioDecodeProcessor) { + await audioDecodeProcessor.stop().then(() => { + console.info("case stop success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.reset().then(() => { + console.info("case reset success"); + }, failCallback).catch(failCatch); + audioDecodeProcessor = null; + } + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + function wait(time) { + for(let t = Date.now(); Date.now() - t <= time;); + } + + async function enqueueAllInputs(audioDecodeProcessor, queue) { + while (queue.length > 0 && !sawInputEOS) { + let inputobject = queue.shift(); + if (frameCnt == eosframenum || frameCnt == ES_LENGTH + 1) { + inputobject.flags = 1; + inputobject.timeMs = 0; + inputobject.length = 0; + sawInputEOS = true; + } else { + console.info("case read frame from file"); + inputobject.timeMs = timestamp; + inputobject.offset = 0; + inputobject.length = ES[frameCnt]; + getContent(inputobject.data, ES[frameCnt]); + inputobject.flags = 0; + } + timestamp += ES[frameCnt]/samplerate; + frameCnt += 1; + audioDecodeProcessor.queueInput(inputobject).then(() => { + console.info('case queueInput success'); + }); + } + } + + async function dequeueAllOutputs(audioDecodeProcessor, queue, savapath, done) { + while (queue.length > 0 && !sawOutputEOS) { + let outputobject = queue.shift(); + if (outputobject.flags == 1) { + sawOutputEOS = true; + console.info("sawOutputEOS == true"); + if (stopAtEOS) { + await stopWork(audioDecodeProcessor); + } else if (resetAtEOS) { + await resetWork(audioDecodeProcessor); + } else if (flushAtEOS) { + await flushWork(audioDecodeProcessor); + } else if (workdoneAtEOS) { + await doneWork(audioDecodeProcessor); + done(); + } else {} + } + else{ + writeFile(savapath, outputobject.data, outputobject.length); + console.info("write to file success"); + } + audioDecodeProcessor.releaseOutput(outputobject).then(() => { + console.info('release output success'); + }); + } + } + + function setCallback(audioDecodeProcessor, savepath, done) { + console.info('case callback'); + audioDecodeProcessor.on('inputBufferAvailable', async(inBuffer) => { + console.info('inputBufferAvailable'); + inputQueue.push(inBuffer); + await enqueueAllInputs(audioDecodeProcessor, inputQueue); + }); + audioDecodeProcessor.on('outputBufferAvailable', async(outBuffer) => { + console.info('outputBufferAvailable'); + console.info("outputbuffer.flags: " + outBuffer.flags); + if (needGetMediaDes) { + audioDecodeProcessor.getOutputMediaDescription().then((MediaDescription) => { + console.info("get OutputMediaDescription success"); + console.info('get outputMediaDescription : ' + MediaDescription); + needGetMediaDes=false; + }, failCallback).catch(failCatch);} + outputQueue.push(outBuffer); + await dequeueAllOutputs(audioDecodeProcessor, outputQueue, savepath, done); + }); + audioDecodeProcessor.on('error',(err) => { + console.info('case error called,errName is' + err); + }); + audioDecodeProcessor.on('outputFormatChanged',(format) => { + console.info('Output format changed: ' + format); + }); + } + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_00_0100 + * @tc.name : 000.test set EOS after last frame and reset + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_00_0100', 0, async function (done) { + console.info("case test set EOS after last frame and reset"); + let audioDecodeProcessor; + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + '0000.pcm'; + workdoneAtEOS = true; + needGetMediaDes = true; + await media.getMediaCapability().then((mediaCaps) => { + console.info('getMediaCapability success'); + if (typeof (mediaCaps) != 'undefined') { + mediaCaps.getAudioDecoderCaps().then((audioCapsArray) => { + console.info('getAudioDecoderCaps success'); + if (typeof (audioCapsArray) != 'undefined') { + console.info('audioCapsArray is not null'); + console.info('get first audioCaps'+ audioCapsArray[0]); + console.info('codecInfo: '+ audioCapsArray[0].codecInfo); + console.info('supportedBitrate: '+ audioCapsArray[0].supportedBitrate); + console.info('supportedBitrate.min: '+ audioCapsArray[0].supportedBitrate.min); + } else { + console.info('audioCaps is not defined'); + } + }, failCallback).catch(failCatch); + } else { + console.info('mediaCaps is not defined'); + } + }, failCallback).catch(failCatch); + await media.createAudioDecoderByName('avdec_aac').then((processor) => { + console.info("case create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.info("case get AudioDecoderCaps success"); + console.info("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.info("case prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.info("case start success"); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_01_0100 + * @tc.name : 001.test set EOS manually before last frame and reset + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_01_0100', 0, async function (done) { + console.info("case test set EOS manually before last frame and reset"); + let audioDecodeProcessor; + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + '0100.pcm'; + eosframenum = 500; + workdoneAtEOS = true; + await media.createAudioDecoderByMime('audio/mp4a-latm').then((processor) => { + console.info("case create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + console.info("get AudioDecoderCaps:"); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.info("case get AudioDecoderCaps success"); + console.info("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.info("case prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.info("case start success"); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_01_0200 + * @tc.name : 002.test flush at running state + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_01_0200', 0, async function (done) { + console.info("case test flush at running state"); + let audioDecodeProcessor; + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + '0200.pcm'; + workdoneAtEOS = true; + await media.createAudioDecoderByMime('audio/mp4a-latm').then((processor) => { + console.info("case create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.info("case get AudioDecoderCaps success"); + console.info("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.info("case prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.info("case start success"); + }, failCallback).catch(failCatch); + await sleep(3000).then(() => { + audioDecodeProcessor.flush().then(() => { + console.info("case flush after 5s"); + }, failCallback).catch(failCatch); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_01_0300 + * @tc.name : 003. test flush at EOS state + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_01_0300', 0, async function (done) { + console.info("case test flush at EOS state"); + let audioDecodeProcessor; + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + '0300.pcm'; + eosframenum = 200; + flushAtEOS = true; + await media.createAudioDecoderByMime('audio/mp4a-latm').then((processor) => { + console.info("case create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.info("case get AudioDecoderCaps success"); + console.info("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.info("case prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.info("case start success"); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_01_0400 + * @tc.name : 004. test stop at running state and reset + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_01_0400', 0, async function (done) { + console.info("case test stop at running state and reset"); + let audioDecodeProcessor; + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + '0400.pcm'; + await media.createAudioDecoderByMime('audio/mp4a-latm').then((processor) => { + console.info("case create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.info("case get AudioDecoderCaps success"); + console.info("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.info("case prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.info("case start success"); + }, failCallback).catch(failCatch); + await sleep(5000).then(() => { + audioDecodeProcessor.stop().then(() => { + console.info("case stop after 5s success"); + }, failCallback).catch(failCatch);}); + await audioDecodeProcessor.reset().then(() => { + console.info("case reset success"); + }, failCallback).catch(failCatch); + audioDecodeProcessor = null; + done(); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_01_0500 + * @tc.name : 005. test stop and restart + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_01_0500', 0, async function (done) { + console.info("case test stop and restart"); + let audioDecodeProcessor; + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + '0500.pcm'; + eosframenum = 200; + await media.createAudioDecoderByMime('audio/mp4a-latm').then((processor) => { + console.info("case create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.info("case get AudioDecoderCaps success"); + console.info("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.info("case prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.info("case start success"); + }, failCallback).catch(failCatch); + await sleep(5000).then(() => { + console.info("case stop decoding after 5s"); + }); + await audioDecodeProcessor.stop().then(() => { + console.info("case stop after 5s success"); + }, failCallback).catch(failCatch); + await sleep(2000).then(() => { + console.info("case restart decoding after 2s"); + resetParam(); + readFile(AUDIOPATH); + }); + await audioDecodeProcessor.start().then(() => { + console.info("case restart after 3s success"); + workdoneAtEOS = true; + enqueueAllInputs(audioDecodeProcessor, inputQueue); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_01_0600 + * @tc.name : 006. test reconfigure for new file with the same format + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_01_0600', 0, async function (done) { + console.info("case test reconfigure codec for new file with the same format"); + let audioDecodeProcessor; + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let mediaDescription2 = { + "channel_count": 1, + "sample_rate": 16000, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + '0600.pcm'; + eosframenum = 200; + resetAtEOS = true; + await media.createAudioDecoderByMime('audio/mp4a-latm').then((processor) => { + console.info("case create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.info("case get AudioDecoderCaps success"); + console.info("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.info("case prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.info("case start success"); + }, failCallback).catch(failCatch); + await sleep(10000).then(() => { + console.info("case start configure 2"); + }); + await audioDecodeProcessor.configure(mediaDescription2).then(() => { + console.info("case configure 2 success"); + resetParam(); + readFile(AUDIOPATH2); + }, failCallback).catch(failCatch); + savepath = BASIC_PATH + '0601.pcm'; + workdoneAtEOS = true; + ES = [0, 239, 302, 309, 330, 474, 684, 699, 683, 674, 647, 649, 638, 644, 640, + 639, 650, 702, 713, 718, 707, 707, 683, 670, 674, 699, 654, 650, 715, 770, + 764, 736, 697, 664, 643, 649, 704, 730, 720, 710, 689, 670, 673, 653, 635, + 643, 638, 653, 658, 683, 683, 705, 690, 681, 648, 659, 743, 681, 706, 707, + 718, 714, 746, 725, 741, 709, 675, 675, 751, 698, 736, 738, 711, 702, 691, + 668, 668, 650, 661, 678, 694, 719, 685, 700, 657, 671, 668, 701, 689, 685, + 682, 668, 696, 690, 683, 739, 704, 667, 694, 716, 757, 714, 701, 664, 619, + 609, 591, 644, 573, 572, 605, 595, 597, 529, 581, 578, 586, 537, 577, 535, + 572, 570, 534, 547, 581, 530, 591, 521, 556, 570, 557, 541, 506, 572, 579, + 502, 516, 582, 540, 584, 548, 555, 539, 578, 588, 541, 539, 526, 575, 535, + 571, 525, 569, 560, 584, 551, 574, 572, 537, 550, 582, 512, 559, 593, 601, + 594, 546, 560, 567, 547, 529, 576, 577, 556, 551, 530, 542, 575, 510, 559, + 613, 628, 511, 566, 515, 539, 594, 536, 565, 551, 533, 613, 557, 523, 574, + 582, 616, 610, 573, 509, 535]; + ES_LENGTH = 200; + samplerate = 16; + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.info("case prepare2 success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.info("case start2 success"); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_01_0700 + * @tc.name : 007. test reconfigure for new file with different formats + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_DECODER_FUNCTION_PROMISE_01_0700', 0, async function (done) { + console.info("case test reconfigure codec for new file with different formats"); + let audioDecodeProcessor; + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + } + let mediaDescription2 = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 4, + } + let savepath = BASIC_PATH + '0700.pcm'; + eosframenum = 200; + resetAtEOS = true; + needrelease = true; + await media.createAudioDecoderByMime('audio/mp4a-latm').then((processor) => { + console.info("case create createAudioDecoder success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.getAudioDecoderCaps().then((AudioCaps) => { + console.info("case get AudioDecoderCaps success"); + console.info("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH); + }, failCallback).catch(failCatch); + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.info("case prepare success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.info("case start success"); + }, failCallback).catch(failCatch); + await sleep(10000).then(() => { + console.info("start createaudiodecoder 2"); + }); + await media.createAudioDecoderByMime('audio/flac').then((processor) => { + console.info("case create createAudioDecoder flac success"); + audioDecodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioDecodeProcessor.configure(mediaDescription2).then(() => { + console.info("case configure 2 success"); + resetParam(); + readFile(AUDIOPATH3); + }, failCallback).catch(failCatch); + savepath = BASIC_PATH + '0701.pcm'; + workdoneAtEOS = true; + ES = [0, 2116, 2093, 2886, 2859, 2798, 2778, 2752, 2752, 2754, 2720, 2898, 2829, + 2806, 2796, 2786, 2774, 2758, 2741, 3489, 3342, 3272, 3167, 3048, 3060, 2919, + 2839, 2794, 2770, 2763, 2756, 2722, 2950, 2876, 2842, 2827, 2792, 3121, 3075, + 2969, 3240, 3199, 3082, 2975, 2895, 3135, 3024, 2970, 2902, 2860, 2802, 2778, + 2779, 2963, 2893, 2870, 2831, 2800, 2762, 2752, 2760, 2759, 2726, 2889, 2960, + 2876, 3223, 3040, 3006, 3042, 2980, 3097, 3069, 3215, 3365, 3296, 3653, 3480, + 3300, 3140, 3014, 2975, 2952, 2896, 2897, 2842, 2929, 3567, 3929, 3485, 3082, + 3625, 4953, 5239, 5094, 4993, 4821, 4431, 5195, 5542, 5557, 4894, 4414]; + ES_LENGTH = 100; + samplerate = 48; + setCallback(audioDecodeProcessor, savepath, done); + await audioDecodeProcessor.prepare().then(() => { + console.info("case prepare2 success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.start().then(() => { + console.info("case start2 success"); + }, failCallback).catch(failCatch); + }) +}) diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderMultiInstancesTest.test.js b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderMultiInstancesTest.test.js new file mode 100644 index 0000000000000000000000000000000000000000..903959951d977452aee6f55776eee386c5da2162 --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderMultiInstancesTest.test.js @@ -0,0 +1,262 @@ +/* + * Copyright (C) 2021 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 media from '@ohos.multimedia.media' +import Fileio from '@ohos.fileio' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('AudioDecoderMultiInstances', function () { + const AUDIOPATH = '/data/media/AAC_48000_32_1.aac'; + const BASIC_PATH = '/data/media/results/decode_multiInstances_'; + let readStreamSync; + let eosframenum = 0; + let samplerate = 44.1; + let stopAtEOS = false; + let resetAtEOS = false; + let flushAtEOS = false; + let workdoneAtEOS = false; + let needGetMediaDes = false; + let needrelease = false; + let frameCnt = 1; + let timestamp = 0; + let sawInputEOS = false; + let sawOutputEOS = false; + let inputQueue = []; + let outputQueue = []; + let ES = []; + let ES_LENGTH = 1500; + + beforeAll(function() { + console.info('beforeAll case'); + }) + + beforeEach(function() { + console.info('beforeEach case'); + }) + + afterEach(function() { + console.info('afterEach case'); + wait(2000); + }) + + afterAll(function() { + console.info('afterAll case'); + }) + + let failCallback = function(err) { + console.info('case callback err : ' + err); + expect(err).assertUndefined(); + } + + let failCatch = function(err) { + console.info('case catch err : ' + err); + expect(err).assertUndefined(); + } + + function resetParam() { + readStreamSync = undefined; + eosframenum = 0; + samplerate = 44.1; + stopAtEOS = false; + resetAtEOS = false; + flushAtEOS = false; + workdoneAtEOS = false; + needGetMediaDes = false; + needrelease = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + } + + function writeFile(path, buf, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let num = writestream.writeSync(buf, {length:len}); + writestream.flushSync(); + writestream.closeSync(); + }catch(e) { + console.info(e) + } + } + + function readFile(path) { + console.info('read file start execution'); + try{ + console.info('filepath: ' + path); + readStreamSync = Fileio.createStreamSync(path, 'rb'); + }catch(e) { + console.info(e); + } + } + + function getContent(buf, len) { + console.info("case start get content"); + let lengthreal = -1; + lengthreal = readStreamSync.readSync(buf,{length:len}); + } + + async function stopWork(audioDecodeProcessor) { + await audioDecodeProcessor.stop().then(() => { + console.info("case stop success") + }, failCallback).catch(failCatch); + } + + async function resetWork(audioDecodeProcessor) { + await audioDecodeProcessor.reset().then(() => { + console.info("case reset success"); + if (needrelease) { + audioDecodeProcessor = null; + } + }, failCallback).catch(failCatch); + } + + async function flushWork(audioDecodeProcessor) { + await audioDecodeProcessor.flush().then(() => { + console.info("case flush at inputeos success"); + resetParam(); + readFile(AUDIOPATH); + workdoneAtEOS =true; + }, failCallback).catch(failCatch); + } + + async function doneWork(audioDecodeProcessor) { + await audioDecodeProcessor.stop().then(() => { + console.info("case stop success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.reset().then(() => { + console.info("case reset success"); + }, failCallback).catch(failCatch); + audioDecodeProcessor = null; + } + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + function wait(time) { + for(let t = Date.now(); Date.now() - t <= time;); + } + + async function enqueueAllInputs(audioDecodeProcessor, queue) { + while (queue.length > 0 && !sawInputEOS) { + let inputobject = queue.shift(); + if (frameCnt == eosframenum || frameCnt == ES_LENGTH + 1) { + inputobject.flags = 1; + inputobject.timeMs = 0; + inputobject.length = 0; + sawInputEOS = true; + } else { + console.info("case read frame from file"); + inputobject.timeMs = timestamp; + inputobject.offset = 0; + inputobject.length = ES[frameCnt]; + getContent(inputobject.data, ES[frameCnt]); + inputobject.flags = 0; + } + timestamp += ES[frameCnt]/samplerate; + frameCnt += 1; + audioDecodeProcessor.queueInput(inputobject).then(() => { + console.info('case queueInput success'); + }); + } + } + + async function dequeueAllOutputs(audioDecodeProcessor, queue, savapath, done) { + while (queue.length > 0 && !sawOutputEOS) { + let outputobject = queue.shift(); + if (outputobject.flags == 1) { + sawOutputEOS = true; + console.info("sawOutputEOS == true"); + if (stopAtEOS) { + await stopWork(audioDecodeProcessor); + } else if (resetAtEOS) { + await resetWork(audioDecodeProcessor); + } else if (flushAtEOS) { + await flushWork(audioDecodeProcessor); + } else if (workdoneAtEOS) { + await doneWork(audioDecodeProcessor); + done(); + } else {} + } + else{ + writeFile(savapath, outputobject.data, outputobject.length); + console.info("write to file success"); + } + audioDecodeProcessor.releaseOutput(outputobject).then(() => { + console.info('release output success'); + }); + } + } + + function setCallback(audioDecodeProcessor, savepath, done) { + console.info('case callback'); + audioDecodeProcessor.on('inputBufferAvailable', async(inBuffer) => { + console.info('inputBufferAvailable'); + inputQueue.push(inBuffer); + await enqueueAllInputs(audioDecodeProcessor, inputQueue); + }); + audioDecodeProcessor.on('outputBufferAvailable', async(outBuffer) => { + console.info('outputBufferAvailable'); + console.info("outputbuffer.flags: " + outBuffer.flags); + if (needGetMediaDes) { + audioDecodeProcessor.getOutputMediaDescription().then((MediaDescription) => { + console.info("get OutputMediaDescription success"); + console.info('get outputMediaDescription : ' + MediaDescription); + needGetMediaDes=false; + }, failCallback).catch(failCatch);} + outputQueue.push(outBuffer); + await dequeueAllOutputs(audioDecodeProcessor, outputQueue, savepath, done); + }); + audioDecodeProcessor.on('error',(err) => { + console.info('case error called,errName is' + err); + }); + audioDecodeProcessor.on('outputFormatChanged',(format) => { + console.info('Output format changed: ' + format); + }); + } + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_MULTIINSTANCE_0100 + * @tc.name : 001.create 16 decoder + * @tc.desc : basic decode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_MULTIINSTANCE_0100', 0, async function (done) { + console.info("case test multiple instances"); + let array = new Array(); + for (let i = 0; i < 16; i += 1) { + await media.createAudioDecoderByMime('audio/mp4a-latm').then((processor) => { + if (typeof(processor) != 'undefined') { + console.info("case create createAudioDecoder success: " + i); + array[i] = processor; + } else { + console.info("case create createAudioDecoder failed: " + i); + } + }, failCallback).catch(failCatch); + } + console.info('case has created 16 decoders'); + console.info('case array: ' + array); + for (let j = 0; j < 16; j++) { + await array[j].reset().then(() => { + console.info("reset decoder " + j); + array[j] = null; + }, failCallback).catch(failCatch); + } + done(); + }) +}) \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderReliabilityCallbackTest.test.js b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderReliabilityCallbackTest.test.js new file mode 100644 index 0000000000000000000000000000000000000000..014192f0b23cc8401fce34f52173c724b30b3d3f --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderReliabilityCallbackTest.test.js @@ -0,0 +1,1332 @@ +/* + * Copyright (C) 2021 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 media from '@ohos.multimedia.media' +import Fileio from '@ohos.fileio' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('AudioDecoderReliabilityCallback', function () { + const AUDIOPATH = '/data/media/AAC_48000_32_1.aac'; + const BASIC_PATH = '/data/media/results/decode_reliability_callback_'; + const END = 0; + const CONFIGURE = 1; + const PREPARE = 2; + const START = 3; + const FLUSH = 4; + const STOP = 5; + const RESET = 6; + const HOLDON = 7; + const WAITFORALLOUTS = 8; + const CONFIGURE_ERROR = 9; + const PREPARE_ERROR = 10; + const START_ERROR = 11; + const FLUSH_ERROR = 12; + const STOP_ERROR = 13; + const JUDGE_EOS = 14; + const WAITTIME = 3000; + let audioDecodeProcessor; + let readStreamSync; + let EOSFrameNum = 0; + let samplerate = 44.1; + let workdoneAtEOS = false; + let flushAtEOS = false; + let needGetMediaDes = false; + let frameCnt = 1; + let timestamp = 0; + let sawInputEOS = false; + let sawOutputEOS = false; + let inputQueue = []; + let outputQueue = []; + let ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, + 541, 540, 542, 552, 537, 533, 498, 472, 445, 430, 445, 427, 414, 386, 413, 370, 380, + 401, 393, 369, 391, 367, 395, 396, 396, 385, 391, 384, 395, 392, 386, 388, 384, 379, + 376, 381, 375, 373, 349, 391, 357, 384, 395, 384, 380, 386, 372, 386, 383, 378, 385, + 385, 384, 342, 390, 379, 387, 386, 393, 397, 362, 393, 394, 391, 383, 385, 377, 379, + 381, 369, 375, 379, 346, 382, 356, 361, 366, 394, 393, 385, 362, 406, 399, 384, 377, + 385, 389, 375, 346, 396, 388, 381, 383, 352, 357, 397, 382, 395, 376, 388, 373, 374, + 353, 383, 384, 393, 379, 348, 364, 389, 380, 381, 388, 423, 392, 381, 368, 351, 391, + 355, 358, 395, 390, 385, 382, 383, 388, 388, 389, 376, 379, 376, 384, 369, 354, 390, + 389, 396, 393, 382, 385, 353, 383, 381, 377, 411, 387, 390, 377, 349, 381, 390, 378, + 373, 375, 381, 351, 392, 381, 380, 381, 378, 387, 379, 383, 348, 386, 364, 386, 371, + 399, 399, 385, 380, 355, 397, 395, 382, 380, 386, 352, 387, 390, 373, 372, 388, 378, + 385, 368, 385, 370, 378, 373, 383, 368, 373, 388, 351, 384, 391, 387, 389, 383, 355, + 361, 392, 386, 354, 394, 392, 397, 392, 352, 381, 395, 349, 383, 390, 392, 350, 393, + 393, 385, 389, 393, 382, 378, 384, 378, 375, 373, 375, 389, 377, 383, 387, 373, 344, + 388, 379, 391, 373, 384, 358, 361, 391, 394, 363, 350, 361, 395, 399, 389, 398, 375, + 398, 400, 381, 354, 363, 366, 400, 400, 356, 370, 400, 394, 398, 385, 378, 372, 354, + 359, 393, 381, 363, 396, 396, 355, 390, 356, 355, 371, 399, 367, 406, 375, 377, 405, + 401, 390, 393, 392, 384, 386, 374, 358, 397, 389, 393, 385, 345, 379, 357, 388, 356, + 381, 389, 367, 358, 391, 360, 394, 396, 357, 395, 388, 394, 383, 357, 383, 392, 394, + 376, 379, 356, 386, 395, 387, 377, 377, 389, 377, 385, 351, 387, 350, 388, 384, 345, + 358, 368, 399, 394, 385, 384, 395, 378, 387, 386, 386, 376, 375, 382, 351, 359, 356, + 401, 388, 363, 406, 363, 374, 435, 366, 400, 393, 392, 371, 391, 359, 359, 397, 388, + 390, 420, 411, 369, 384, 382, 383, 383, 375, 381, 361, 380, 348, 379, 386, 379, 379, + 386, 371, 352, 378, 378, 388, 384, 385, 352, 355, 387, 383, 379, 362, 386, 399, 376, + 390, 350, 387, 357, 403, 398, 397, 360, 351, 394, 400, 399, 393, 388, 395, 370, 377, + 395, 360, 346, 381, 370, 390, 380, 391, 387, 382, 384, 383, 354, 349, 394, 358, 387, + 400, 386, 402, 354, 396, 387, 391, 365, 377, 359, 361, 365, 395, 388, 388, 384, 388, + 378, 374, 382, 376, 377, 389, 378, 341, 390, 376, 381, 375, 414, 368, 369, 387, 411, + 396, 391, 378, 389, 349, 383, 344, 381, 387, 380, 353, 361, 391, 365, 390, 396, 382, + 386, 385, 385, 409, 387, 386, 378, 372, 372, 374, 349, 388, 389, 348, 395, 380, 382, + 388, 375, 347, 383, 359, 389, 368, 361, 405, 398, 393, 395, 359, 360, 395, 395, 362, + 354, 388, 348, 388, 386, 390, 350, 388, 356, 369, 364, 404, 404, 391, 394, 385, 439, + 432, 375, 366, 441, 362, 367, 382, 374, 346, 391, 371, 354, 376, 390, 373, 382, 385, + 389, 378, 377, 347, 414, 338, 348, 385, 352, 385, 386, 381, 388, 387, 364, 465, 405, + 443, 387, 339, 376, 337, 379, 387, 370, 374, 358, 354, 357, 393, 356, 381, 357, 407, + 361, 397, 362, 394, 394, 392, 394, 391, 381, 386, 379, 354, 351, 392, 408, 393, 389, + 388, 385, 375, 388, 375, 388, 375, 354, 384, 379, 386, 394, 383, 359, 405, 395, 352, + 345, 403, 427, 373, 380, 350, 415, 378, 434, 385, 388, 387, 400, 405, 329, 391, 356, + 419, 358, 359, 375, 367, 391, 359, 369, 361, 376, 378, 379, 348, 390, 345, 388, 390, + 406, 349, 368, 364, 391, 384, 401, 384, 391, 361, 399, 359, 386, 392, 382, 386, 380, + 383, 345, 376, 393, 400, 395, 343, 352, 354, 381, 388, 357, 393, 389, 384, 389, 388, + 384, 404, 372, 358, 381, 352, 355, 485, 393, 371, 376, 389, 377, 391, 387, 376, 342, + 390, 375, 379, 396, 376, 402, 353, 392, 382, 383, 387, 386, 372, 377, 382, 388, 381, + 387, 357, 393, 385, 346, 389, 388, 357, 362, 404, 398, 397, 402, 371, 351, 370, 362, + 350, 388, 399, 402, 406, 377, 396, 359, 372, 390, 392, 368, 383, 346, 384, 381, 379, + 367, 384, 389, 381, 371, 358, 422, 372, 382, 374, 444, 412, 369, 362, 373, 389, 401, + 383, 380, 366, 365, 361, 379, 372, 345, 382, 375, 376, 375, 382, 356, 395, 383, 384, + 391, 361, 396, 407, 365, 351, 385, 378, 403, 344, 352, 387, 397, 399, 377, 371, 381, + 415, 382, 388, 368, 383, 405, 390, 386, 384, 374, 375, 381, 371, 372, 374, 377, 346, + 358, 381, 377, 359, 385, 396, 385, 390, 389, 391, 375, 357, 389, 390, 377, 370, 379, + 351, 381, 381, 380, 371, 386, 389, 389, 383, 362, 393, 388, 355, 396, 383, 352, 384, + 352, 383, 362, 396, 385, 396, 357, 388, 382, 377, 373, 379, 383, 386, 350, 393, 355, + 380, 401, 392, 391, 402, 391, 427, 407, 394, 332, 398, 367, 373, 343, 381, 383, 386, + 382, 349, 353, 393, 378, 386, 375, 390, 356, 392, 384, 387, 380, 381, 385, 386, 383, + 378, 379, 359, 381, 382, 388, 357, 357, 397, 358, 424, 382, 352, 409, 374, 368, 365, + 399, 352, 393, 389, 385, 352, 380, 398, 389, 385, 387, 387, 353, 402, 396, 386, 357, + 395, 368, 369, 407, 394, 383, 362, 380, 385, 368, 375, 365, 379, 377, 388, 380, 346, + 383, 381, 399, 359, 386, 455, 368, 406, 377, 339, 381, 377, 373, 371, 338, 371, 387, + 376, 386, 388, 382, 381, 377, 389, 352, 391, 396, 398, 374, 352, 358, 387, 368, 401, + 395, 387, 387, 354, 393, 401, 382, 390, 371, 374, 387, 377, 379, 377, 383, 374, 367, + 372, 393, 365, 392, 350, 378, 385, 377, 382, 388, 353, 389, 359, 366, 404, 390, 381, + 396, 388, 394, 380, 379, 372, 355, 397, 382, 351, 397, 378, 375, 378, 369, 387, 380, + 383, 346, 357, 362, 371, 413, 393, 365, 395, 391, 384, 386, 385, 390, 355, 385, 394, + 384, 383, 431, 369, 373, 392, 397, 396, 353, 391, 352, 375, 382, 397, 393, 371, 403, + 375, 338, 418, 368, 372, 370, 344, 392, 360, 402, 402, 425, 374, 378, 376, 380, 378, + 347, 379, 414, 377, 390, 383, 357, 390, 385, 377, 378, 368, 399, 389, 383, 368, 372, + 358, 386, 355, 380, 386, 349, 381, 379, 380, 351, 389, 380, 353, 359, 365, 370, 407, + 388, 381, 358, 364, 396, 369, 407, 391, 358, 440, 419, 412, 395, 344, 382, 391, 353, + 403, 391, 371, 354, 362, 407, 411, 397, 385, 388, 357, 348, 368, 401, 404, 380, 370, + 369, 365, 349, 373, 346, 351, 394, 399, 387, 393, 363, 402, 394, 375, 389, 386, 395, + 386, 386, 353, 403, 363, 376, 398, 383, 372, 350, 381, 353, 445, 386, 369, 383, 351, + 392, 397, 384, 389, 354, 400, 392, 379, 386, 355, 391, 388, 361, 390, 408, 357, 390, + 387, 352, 393, 357, 358, 401, 383, 391, 384, 388, 377, 380, 354, 393, 387, 357, 396, + 360, 362, 388, 390, 359, 367, 366, 396, 388, 394, 363, 391, 394, 351, 391, 391, 350, + 360, 365, 397, 366, 375, 400, 412, 372, 380, 383, 384, 383, 390, 380, 361, 363, 387, + 358, 385, 359, 385, 399, 351, 392, 388, 385, 384, 350, 379, 385, 383, 375, 389, 381, + 382, 376, 389, 390, 375, 381, 382, 390, 385, 380, 359, 351, 383, 391, 388, 379, 354, + 387, 382, 358, 381, 381, 386, 397, 373, 381, 387, 387, 381, 378, 383, 370, 360, 386, + 362, 402, 357, 398, 398, 397, 378, 394, 381, 375, 380, 390, 373, 369, 388, 347, 356, + 384, 391, 386, 394, 388, 357, 403, 381, 376, 414, 383, 387, 349, 379, 383, 384, 377, + 394, 426, 373, 392, 367, 381, 378, 378, 374, 373, 369, 368, 332, 335, 381, 392, 388, + 381, 424, 367, 398, 399, 392, 379, 391, 379, 370, 343, 405, 378, 367, 345, 379, 347, + 388, 353, 392, 382, 384, 387, 350, 363, 398, 398, 359, 402, 454, 440, 341, 383, 381, + 385, 355, 349, 369, 360, 388, 383, 354, 435, 405, 404, 399, 385, 386, 364, 388, 373, + 376, 384, 395, 400, 408, 390, 375, 341, 372, 371, 407, 345, 378, 345, 407, 365, 398, + 396, 339, 379, 375, 410, 386, 407, 387, 365, 375, 384, 347, 393, 377, 350, 376, 375, + 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]; + let ES_LENGTH = 500; + let mime = 'audio/mp4a-latm'; + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + }; + + beforeAll(function() { + console.info('beforeAll case'); + }) + + beforeEach(function() { + console.info('beforeEach case'); + audioDecodeProcessor = null; + readStreamSync = undefined; + EOSFrameNum = 0; + samplerate = 44.1; + workdoneAtEOS = false; + flushAtEOS = false; + needGetMediaDes = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + inputQueue = []; + outputQueue = []; + ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, + 541, 540, 542, 552, 537, 533, 498, 472, 445, 430, 445, 427, 414, 386, 413, 370, 380, + 401, 393, 369, 391, 367, 395, 396, 396, 385, 391, 384, 395, 392, 386, 388, 384, 379, + 376, 381, 375, 373, 349, 391, 357, 384, 395, 384, 380, 386, 372, 386, 383, 378, 385, + 385, 384, 342, 390, 379, 387, 386, 393, 397, 362, 393, 394, 391, 383, 385, 377, 379, + 381, 369, 375, 379, 346, 382, 356, 361, 366, 394, 393, 385, 362, 406, 399, 384, 377, + 385, 389, 375, 346, 396, 388, 381, 383, 352, 357, 397, 382, 395, 376, 388, 373, 374, + 353, 383, 384, 393, 379, 348, 364, 389, 380, 381, 388, 423, 392, 381, 368, 351, 391, + 355, 358, 395, 390, 385, 382, 383, 388, 388, 389, 376, 379, 376, 384, 369, 354, 390, + 389, 396, 393, 382, 385, 353, 383, 381, 377, 411, 387, 390, 377, 349, 381, 390, 378, + 373, 375, 381, 351, 392, 381, 380, 381, 378, 387, 379, 383, 348, 386, 364, 386, 371, + 399, 399, 385, 380, 355, 397, 395, 382, 380, 386, 352, 387, 390, 373, 372, 388, 378, + 385, 368, 385, 370, 378, 373, 383, 368, 373, 388, 351, 384, 391, 387, 389, 383, 355, + 361, 392, 386, 354, 394, 392, 397, 392, 352, 381, 395, 349, 383, 390, 392, 350, 393, + 393, 385, 389, 393, 382, 378, 384, 378, 375, 373, 375, 389, 377, 383, 387, 373, 344, + 388, 379, 391, 373, 384, 358, 361, 391, 394, 363, 350, 361, 395, 399, 389, 398, 375, + 398, 400, 381, 354, 363, 366, 400, 400, 356, 370, 400, 394, 398, 385, 378, 372, 354, + 359, 393, 381, 363, 396, 396, 355, 390, 356, 355, 371, 399, 367, 406, 375, 377, 405, + 401, 390, 393, 392, 384, 386, 374, 358, 397, 389, 393, 385, 345, 379, 357, 388, 356, + 381, 389, 367, 358, 391, 360, 394, 396, 357, 395, 388, 394, 383, 357, 383, 392, 394, + 376, 379, 356, 386, 395, 387, 377, 377, 389, 377, 385, 351, 387, 350, 388, 384, 345, + 358, 368, 399, 394, 385, 384, 395, 378, 387, 386, 386, 376, 375, 382, 351, 359, 356, + 401, 388, 363, 406, 363, 374, 435, 366, 400, 393, 392, 371, 391, 359, 359, 397, 388, + 390, 420, 411, 369, 384, 382, 383, 383, 375, 381, 361, 380, 348, 379, 386, 379, 379, + 386, 371, 352, 378, 378, 388, 384, 385, 352, 355, 387, 383, 379, 362, 386, 399, 376, + 390, 350, 387, 357, 403, 398, 397, 360, 351, 394, 400, 399, 393, 388, 395, 370, 377, + 395, 360, 346, 381, 370, 390, 380, 391, 387, 382, 384, 383, 354, 349, 394, 358, 387, + 400, 386, 402, 354, 396, 387, 391, 365, 377, 359, 361, 365, 395, 388, 388, 384, 388, + 378, 374, 382, 376, 377, 389, 378, 341, 390, 376, 381, 375, 414, 368, 369, 387, 411, + 396, 391, 378, 389, 349, 383, 344, 381, 387, 380, 353, 361, 391, 365, 390, 396, 382, + 386, 385, 385, 409, 387, 386, 378, 372, 372, 374, 349, 388, 389, 348, 395, 380, 382, + 388, 375, 347, 383, 359, 389, 368, 361, 405, 398, 393, 395, 359, 360, 395, 395, 362, + 354, 388, 348, 388, 386, 390, 350, 388, 356, 369, 364, 404, 404, 391, 394, 385, 439, + 432, 375, 366, 441, 362, 367, 382, 374, 346, 391, 371, 354, 376, 390, 373, 382, 385, + 389, 378, 377, 347, 414, 338, 348, 385, 352, 385, 386, 381, 388, 387, 364, 465, 405, + 443, 387, 339, 376, 337, 379, 387, 370, 374, 358, 354, 357, 393, 356, 381, 357, 407, + 361, 397, 362, 394, 394, 392, 394, 391, 381, 386, 379, 354, 351, 392, 408, 393, 389, + 388, 385, 375, 388, 375, 388, 375, 354, 384, 379, 386, 394, 383, 359, 405, 395, 352, + 345, 403, 427, 373, 380, 350, 415, 378, 434, 385, 388, 387, 400, 405, 329, 391, 356, + 419, 358, 359, 375, 367, 391, 359, 369, 361, 376, 378, 379, 348, 390, 345, 388, 390, + 406, 349, 368, 364, 391, 384, 401, 384, 391, 361, 399, 359, 386, 392, 382, 386, 380, + 383, 345, 376, 393, 400, 395, 343, 352, 354, 381, 388, 357, 393, 389, 384, 389, 388, + 384, 404, 372, 358, 381, 352, 355, 485, 393, 371, 376, 389, 377, 391, 387, 376, 342, + 390, 375, 379, 396, 376, 402, 353, 392, 382, 383, 387, 386, 372, 377, 382, 388, 381, + 387, 357, 393, 385, 346, 389, 388, 357, 362, 404, 398, 397, 402, 371, 351, 370, 362, + 350, 388, 399, 402, 406, 377, 396, 359, 372, 390, 392, 368, 383, 346, 384, 381, 379, + 367, 384, 389, 381, 371, 358, 422, 372, 382, 374, 444, 412, 369, 362, 373, 389, 401, + 383, 380, 366, 365, 361, 379, 372, 345, 382, 375, 376, 375, 382, 356, 395, 383, 384, + 391, 361, 396, 407, 365, 351, 385, 378, 403, 344, 352, 387, 397, 399, 377, 371, 381, + 415, 382, 388, 368, 383, 405, 390, 386, 384, 374, 375, 381, 371, 372, 374, 377, 346, + 358, 381, 377, 359, 385, 396, 385, 390, 389, 391, 375, 357, 389, 390, 377, 370, 379, + 351, 381, 381, 380, 371, 386, 389, 389, 383, 362, 393, 388, 355, 396, 383, 352, 384, + 352, 383, 362, 396, 385, 396, 357, 388, 382, 377, 373, 379, 383, 386, 350, 393, 355, + 380, 401, 392, 391, 402, 391, 427, 407, 394, 332, 398, 367, 373, 343, 381, 383, 386, + 382, 349, 353, 393, 378, 386, 375, 390, 356, 392, 384, 387, 380, 381, 385, 386, 383, + 378, 379, 359, 381, 382, 388, 357, 357, 397, 358, 424, 382, 352, 409, 374, 368, 365, + 399, 352, 393, 389, 385, 352, 380, 398, 389, 385, 387, 387, 353, 402, 396, 386, 357, + 395, 368, 369, 407, 394, 383, 362, 380, 385, 368, 375, 365, 379, 377, 388, 380, 346, + 383, 381, 399, 359, 386, 455, 368, 406, 377, 339, 381, 377, 373, 371, 338, 371, 387, + 376, 386, 388, 382, 381, 377, 389, 352, 391, 396, 398, 374, 352, 358, 387, 368, 401, + 395, 387, 387, 354, 393, 401, 382, 390, 371, 374, 387, 377, 379, 377, 383, 374, 367, + 372, 393, 365, 392, 350, 378, 385, 377, 382, 388, 353, 389, 359, 366, 404, 390, 381, + 396, 388, 394, 380, 379, 372, 355, 397, 382, 351, 397, 378, 375, 378, 369, 387, 380, + 383, 346, 357, 362, 371, 413, 393, 365, 395, 391, 384, 386, 385, 390, 355, 385, 394, + 384, 383, 431, 369, 373, 392, 397, 396, 353, 391, 352, 375, 382, 397, 393, 371, 403, + 375, 338, 418, 368, 372, 370, 344, 392, 360, 402, 402, 425, 374, 378, 376, 380, 378, + 347, 379, 414, 377, 390, 383, 357, 390, 385, 377, 378, 368, 399, 389, 383, 368, 372, + 358, 386, 355, 380, 386, 349, 381, 379, 380, 351, 389, 380, 353, 359, 365, 370, 407, + 388, 381, 358, 364, 396, 369, 407, 391, 358, 440, 419, 412, 395, 344, 382, 391, 353, + 403, 391, 371, 354, 362, 407, 411, 397, 385, 388, 357, 348, 368, 401, 404, 380, 370, + 369, 365, 349, 373, 346, 351, 394, 399, 387, 393, 363, 402, 394, 375, 389, 386, 395, + 386, 386, 353, 403, 363, 376, 398, 383, 372, 350, 381, 353, 445, 386, 369, 383, 351, + 392, 397, 384, 389, 354, 400, 392, 379, 386, 355, 391, 388, 361, 390, 408, 357, 390, + 387, 352, 393, 357, 358, 401, 383, 391, 384, 388, 377, 380, 354, 393, 387, 357, 396, + 360, 362, 388, 390, 359, 367, 366, 396, 388, 394, 363, 391, 394, 351, 391, 391, 350, + 360, 365, 397, 366, 375, 400, 412, 372, 380, 383, 384, 383, 390, 380, 361, 363, 387, + 358, 385, 359, 385, 399, 351, 392, 388, 385, 384, 350, 379, 385, 383, 375, 389, 381, + 382, 376, 389, 390, 375, 381, 382, 390, 385, 380, 359, 351, 383, 391, 388, 379, 354, + 387, 382, 358, 381, 381, 386, 397, 373, 381, 387, 387, 381, 378, 383, 370, 360, 386, + 362, 402, 357, 398, 398, 397, 378, 394, 381, 375, 380, 390, 373, 369, 388, 347, 356, + 384, 391, 386, 394, 388, 357, 403, 381, 376, 414, 383, 387, 349, 379, 383, 384, 377, + 394, 426, 373, 392, 367, 381, 378, 378, 374, 373, 369, 368, 332, 335, 381, 392, 388, + 381, 424, 367, 398, 399, 392, 379, 391, 379, 370, 343, 405, 378, 367, 345, 379, 347, + 388, 353, 392, 382, 384, 387, 350, 363, 398, 398, 359, 402, 454, 440, 341, 383, 381, + 385, 355, 349, 369, 360, 388, 383, 354, 435, 405, 404, 399, 385, 386, 364, 388, 373, + 376, 384, 395, 400, 408, 390, 375, 341, 372, 371, 407, 345, 378, 345, 407, 365, 398, + 396, 339, 379, 375, 410, 386, 407, 387, 365, 375, 384, 347, 393, 377, 350, 376, 375, + 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 = 500; + }) + + afterEach(function() { + console.info('afterEach case'); + if (audioDecodeProcessor != null) { + audioDecodeProcessor = null + } + wait(2000); + }) + + afterAll(function() { + console.info('afterAll case'); + }) + + function resetParam() { + readStreamSync = undefined; + EOSFrameNum = 0; + samplerate = 44.1; + workdoneAtEOS = false; + flushAtEOS = false; + needGetMediaDes = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + } + + function createAudioDecoder(savepath, mySteps, done) { + media.createAudioDecoderByMime(mime, (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + setCallback(savepath, done); + console.info("case start api test"); + nextStep(mySteps, mediaDescription, done); + }) + } + + function writeFile(path, buf, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let num = writestream.writeSync(buf, {length:len}); + writestream.flushSync(); + writestream.closeSync(); + }catch(e) { + console.info(e) + } + } + + function readFile(path) { + console.info('read file start execution'); + try{ + console.info('filepath: ' + path); + readStreamSync = Fileio.createStreamSync(path, 'rb'); + }catch(e) { + console.info(e); + } + } + + function getContent(buf, len) { + console.info("start get content"); + let lengthreal = -1; + lengthreal = readStreamSync.readSync(buf,{length:len}); + console.info('lengthreal: ' + lengthreal); + } + + async function doneWork(done) { + audioDecodeProcessor.stop((err) => { + expect(err).assertUndefined(); + console.info("case stop success"); + audioDecodeProcessor.reset((err) => { + expect(err).assertUndefined(); + console.log("case reset success"); + audioDecodeProcessor = null; + done(); + }) + }) + } + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + function wait(time) { + for(let t = Date.now(); Date.now() - t <= time;); + } + + function nextStep(mySteps, mediaDescription, done) { + console.info("case myStep[0]: " + mySteps[0]); + if (mySteps[0] == END) { + done(); + console.info('case to done'); + return; + } + switch (mySteps[0]) { + case CONFIGURE: + mySteps.shift(); + console.info(`case to configure`); + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + nextStep(mySteps, mediaDescription, done); + }); + break; + case PREPARE: + mySteps.shift(); + console.info(`case to prepare`); + audioDecodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case START: + mySteps.shift(); + console.info(`case to start`); + if (sawOutputEOS) { + resetParam(); + readFile(AUDIOPATH); + workdoneAtEOS = true; + enqueueAllInputs(inputQueue); + } + audioDecodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case FLUSH: + mySteps.shift(); + console.info(`case to flush`); + audioDecodeProcessor.flush((err) => { + expect(err).assertUndefined(); + console.info(`case flush 1`); + if (flushAtEOS) { + resetParam(); + readFile(AUDIOPATH); + workdoneAtEOS = true; + flushAtEOS = false; + } + nextStep(mySteps, mediaDescription, done); + }); + break; + case STOP: + mySteps.shift(); + console.info(`case to stop`); + audioDecodeProcessor.stop((err) => { + expect(err).assertUndefined(); + console.info(`case stop 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case RESET: + mySteps.shift(); + console.info(`case to reset`); + audioDecodeProcessor.reset((err) => { + expect(err).assertUndefined(); + console.info(`case reset 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case HOLDON: + mySteps.shift(); + setTimeout(() =>{ + nextStep(mySteps, mediaDescription, done); + }, WAITTIME); + break; + case WAITFORALLOUTS: + mySteps.shift(); + console.info(`case wait for all outputs`); + break; + case CONFIGURE_ERROR: + mySteps.shift(); + console.info(`case to configure 2`); + audioDecodeProcessor.configure(mediaDescription, (err) => { + expect(err != undefined).assertTrue(); + console.info(`case configure error 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case PREPARE_ERROR: + mySteps.shift(); + console.info(`case to prepare`); + audioDecodeProcessor.prepare((err) => { + expect(err != undefined).assertTrue(); + console.info(`case prepare error 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case START_ERROR: + mySteps.shift(); + console.info(`case to start`); + audioDecodeProcessor.start((err) => { + expect(err != undefined).assertTrue(); + console.info(`case start error 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case FLUSH_ERROR: + mySteps.shift(); + console.info(`case to flush`); + audioDecodeProcessor.flush((err) => { + expect(err != undefined).assertTrue(); + console.info(`case flush error 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case STOP_ERROR: + mySteps.shift(); + console.info(`case to stop`); + audioDecodeProcessor.stop((err) => { + expect(err != undefined).assertTrue(); + console.info(`case stop error 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case JUDGE_EOS: + mySteps.shift(); + console.info(`case judge EOS state`); + expect(sawOutputEOS).assertTrue(); + nextStep(mySteps, mediaDescription, done); + break; + default: + break; + } + } + + async function enqueueAllInputs(queue) { + while (queue.length > 0 && !sawInputEOS) { + let inputobject = queue.shift(); + console.info("frameCnt:" + frameCnt); + if (frameCnt == EOSFrameNum || frameCnt == ES_LENGTH + 1) { + inputobject.flags = 1; + inputobject.timeMs = 0; + inputobject.length = 0; + sawInputEOS = true; + } + else{ + console.info("read frame from file"); + inputobject.timeMs = timestamp; + inputobject.offset = 0; + inputobject.length = ES[frameCnt]; + getContent(inputobject.data, ES[frameCnt]); + inputobject.flags = 0; + } + timestamp += ES[frameCnt]/samplerate; + frameCnt += 1; + audioDecodeProcessor.queueInput(inputobject, () => { + console.info('queueInput success'); + }) + } + } + + async function dequeueAllOutputs(queue, savepath, done) { + while (queue.length > 0 && !sawOutputEOS) { + let outputobject = queue.shift(); + if (outputobject.flags == 1) { + sawOutputEOS = true; + if (workdoneAtEOS) { + await doneWork(done); + } else { + console.info("sawOutputEOS = true"); + } + } + else{ + writeFile(savepath, outputobject.data, outputobject.length); + console.info("write to file success"); + } + audioDecodeProcessor.releaseOutput(outputobject, () => { + console.info('release output success'); + }) + } + } + + function setCallback(savepath, done) { + console.info('case callback'); + audioDecodeProcessor.on('inputBufferAvailable', async(inBuffer) => { + console.info('inputBufferAvailable'); + inputQueue.push(inBuffer); + await enqueueAllInputs(inputQueue); + }); + audioDecodeProcessor.on('outputBufferAvailable', async(outBuffer) => { + console.info('outputBufferAvailable'); + if (needGetMediaDes) { + audioDecodeProcessor.getOutputMediaDescription((err, MediaDescription) => { + expect(err).assertUndefined(); + console.info("get OutputMediaDescription success"); + console.info('get outputMediaDescription : ' + MediaDescription); + needGetMediaDes=false; + }); + } + outputQueue.push(outBuffer); + await dequeueAllOutputs(outputQueue, savepath, done); + }); + audioDecodeProcessor.on('error',(err) => { + console.info('case error called,errName is' + err); + }); + audioDecodeProcessor.on('outputFormatChanged',(format) => { + console.info('Output format changed: ' + format); + }); + } + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0100 + * @tc.name : 001.create -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0100.txt'; + let mySteps = new Array(CONFIGURE, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0200 + * @tc.name : 002.prepare -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0200.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, CONFIGURE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0300 + * @tc.name : 003.start -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, CONFIGURE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0400 + * @tc.name : 004.flush -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, CONFIGURE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0500 + * @tc.name : 005.stop -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP ,CONFIGURE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0600 + * @tc.name : 006.EOS -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, CONFIGURE_ERROR, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0700 + * @tc.name : 007.reset -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0700.txt'; + let mySteps = new Array(RESET, CONFIGURE, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0800 + * @tc.name : 008.configure -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0800.txt'; + let mySteps = new Array(CONFIGURE, CONFIGURE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0900 + * @tc.name : 009.configure -> reset -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_CALLBACK_0900', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0900.txt'; + let mySteps = new Array(CONFIGURE, RESET, CONFIGURE, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0100 + * @tc.name : 001.create -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0100.txt'; + let mySteps = new Array(PREPARE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0200 + * @tc.name : 002.configure -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0200.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0300 + * @tc.name : 003.prepare -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, PREPARE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0400 + * @tc.name : 004.start -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, PREPARE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0500 + * @tc.name : 005.flush -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, PREPARE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0600 + * @tc.name : 006.stop -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, PREPARE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0700 + * @tc.name : 007.EOS -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, PREPARE_ERROR, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0800 + * @tc.name : 008.reset -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_CALLBACK_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, PREPARE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0100 + * @tc.name : 001.create -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0100.txt'; + let mySteps = new Array(START_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0200 + * @tc.name : 002.configure -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0200.txt'; + let mySteps = new Array(CONFIGURE, START_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0300 + * @tc.name : 003.prepare -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0400 + * @tc.name : 004.start -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, START_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0500 + * @tc.name : 005.flush -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, START_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0600 + * @tc.name : 006.stop -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, START, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0700 + * @tc.name : 007.EOS -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, START_ERROR, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0800 + * @tc.name : 008.reset -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_CALLBACK_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, START_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0100 + * @tc.name : 001.create -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0100.txt'; + let mySteps = new Array(FLUSH_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0200 + * @tc.name : 002.configure -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0200.txt'; + let mySteps = new Array(CONFIGURE, FLUSH_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0300 + * @tc.name : 003.prepare -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, FLUSH_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0400 + * @tc.name : 004.start -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0500 + * @tc.name : 005.flush -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, FLUSH, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0600 + * @tc.name : 006.stop -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP ,FLUSH_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0700 + * @tc.name : 007.EOS -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, FLUSH, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0800 + * @tc.name : 008.reset -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_CALLBACK_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, FLUSH_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0100 + * @tc.name : 001.create -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0100.txt'; + let mySteps = new Array(STOP_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0200 + * @tc.name : 002.configure -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0200.txt'; + let mySteps = new Array(CONFIGURE, STOP_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0300 + * @tc.name : 003.prepare -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, STOP_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0400 + * @tc.name : 004.start -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0500 + * @tc.name : 005.flush -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, STOP, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0600 + * @tc.name : 006.stop -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, STOP_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0700 + * @tc.name : 007.EOS -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, STOP, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0800 + * @tc.name : 008.reset -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_CALLBACK_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, STOP_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0100 + * @tc.name : 001.create -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0100.txt'; + let mySteps = new Array(RESET, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0200 + * @tc.name : 002.configure -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0200.txt'; + let mySteps = new Array(CONFIGURE, RESET, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0300 + * @tc.name : 003.prepare -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, RESET, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0400 + * @tc.name : 004.start -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0500 + * @tc.name : 005.flush -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, RESET, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0600 + * @tc.name : 006.stop -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, RESET, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0700 + * @tc.name : 007.EOS -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, RESET, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0800 + * @tc.name : 008.reset -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_CALLBACK_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, RESET, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_EOS_CALLBACK_0100 + * @tc.name : 001.EOS -> flush -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_EOS_CALLBACK_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0100.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, FLUSH, STOP, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_EOS_CALLBACK_0200 + * @tc.name : 002.EOS -> flush -> EOS + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_EOS_CALLBACK_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0200.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, FLUSH, WAITFORALLOUTS); + EOSFrameNum = 2; + flushAtEOS = true; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_EOS_CALLBACK_0300 + * @tc.name : 003.EOS -> reset -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_EOS_CALLBACK_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, RESET, CONFIGURE, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_EOS_CALLBACK_0400 + * @tc.name : 004.EOS -> stop -> start -> EOS + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_EOS_CALLBACK_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, STOP, START, WAITFORALLOUTS); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_EOS_CALLBACK_0500 + * @tc.name : 005.EOS -> stop -> start -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_EOS_CALLBACK_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, STOP, START, STOP, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) +}) \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderReliabilityPromiseTest.test.js b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderReliabilityPromiseTest.test.js new file mode 100644 index 0000000000000000000000000000000000000000..ea29ebaa18ed78b0a8675af612fd9dffa5b3482a --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderReliabilityPromiseTest.test.js @@ -0,0 +1,1336 @@ +/* + * Copyright (C) 2021 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 media from '@ohos.multimedia.media' +import Fileio from '@ohos.fileio' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('AudioDecoderReliabilityPromise', function () { + const AUDIOPATH = '/data/media/AAC_48000_32_1.aac'; + const BASIC_PATH = '/data/media/results/decode_reliability_promise_'; + const END = 0; + const CONFIGURE = 1; + const PREPARE = 2; + const START = 3; + const FLUSH = 4; + const STOP = 5; + const RESET = 6; + const HOLDON = 7; + const WAITFORALLOUTS = 8; + const CONFIGURE_ERROR = 9; + const PREPARE_ERROR = 10; + const START_ERROR = 11; + const FLUSH_ERROR = 12; + const STOP_ERROR = 13; + const JUDGE_EOS = 14; + const WAITTIME = 3000; + let audioDecodeProcessor; + let readStreamSync; + let EOSFrameNum = 0; + let samplerate = 44.1; + let flushAtEOS = false; + let workdoneAtEOS = false; + let needGetMediaDes = false; + let needrelease = false; + let frameCnt = 1; + let timestamp = 0; + let sawInputEOS = false; + let sawOutputEOS = false; + let inputQueue = []; + let outputQueue = []; + let ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, + 541, 540, 542, 552, 537, 533, 498, 472, 445, 430, 445, 427, 414, 386, 413, 370, 380, + 401, 393, 369, 391, 367, 395, 396, 396, 385, 391, 384, 395, 392, 386, 388, 384, 379, + 376, 381, 375, 373, 349, 391, 357, 384, 395, 384, 380, 386, 372, 386, 383, 378, 385, + 385, 384, 342, 390, 379, 387, 386, 393, 397, 362, 393, 394, 391, 383, 385, 377, 379, + 381, 369, 375, 379, 346, 382, 356, 361, 366, 394, 393, 385, 362, 406, 399, 384, 377, + 385, 389, 375, 346, 396, 388, 381, 383, 352, 357, 397, 382, 395, 376, 388, 373, 374, + 353, 383, 384, 393, 379, 348, 364, 389, 380, 381, 388, 423, 392, 381, 368, 351, 391, + 355, 358, 395, 390, 385, 382, 383, 388, 388, 389, 376, 379, 376, 384, 369, 354, 390, + 389, 396, 393, 382, 385, 353, 383, 381, 377, 411, 387, 390, 377, 349, 381, 390, 378, + 373, 375, 381, 351, 392, 381, 380, 381, 378, 387, 379, 383, 348, 386, 364, 386, 371, + 399, 399, 385, 380, 355, 397, 395, 382, 380, 386, 352, 387, 390, 373, 372, 388, 378, + 385, 368, 385, 370, 378, 373, 383, 368, 373, 388, 351, 384, 391, 387, 389, 383, 355, + 361, 392, 386, 354, 394, 392, 397, 392, 352, 381, 395, 349, 383, 390, 392, 350, 393, + 393, 385, 389, 393, 382, 378, 384, 378, 375, 373, 375, 389, 377, 383, 387, 373, 344, + 388, 379, 391, 373, 384, 358, 361, 391, 394, 363, 350, 361, 395, 399, 389, 398, 375, + 398, 400, 381, 354, 363, 366, 400, 400, 356, 370, 400, 394, 398, 385, 378, 372, 354, + 359, 393, 381, 363, 396, 396, 355, 390, 356, 355, 371, 399, 367, 406, 375, 377, 405, + 401, 390, 393, 392, 384, 386, 374, 358, 397, 389, 393, 385, 345, 379, 357, 388, 356, + 381, 389, 367, 358, 391, 360, 394, 396, 357, 395, 388, 394, 383, 357, 383, 392, 394, + 376, 379, 356, 386, 395, 387, 377, 377, 389, 377, 385, 351, 387, 350, 388, 384, 345, + 358, 368, 399, 394, 385, 384, 395, 378, 387, 386, 386, 376, 375, 382, 351, 359, 356, + 401, 388, 363, 406, 363, 374, 435, 366, 400, 393, 392, 371, 391, 359, 359, 397, 388, + 390, 420, 411, 369, 384, 382, 383, 383, 375, 381, 361, 380, 348, 379, 386, 379, 379, + 386, 371, 352, 378, 378, 388, 384, 385, 352, 355, 387, 383, 379, 362, 386, 399, 376, + 390, 350, 387, 357, 403, 398, 397, 360, 351, 394, 400, 399, 393, 388, 395, 370, 377, + 395, 360, 346, 381, 370, 390, 380, 391, 387, 382, 384, 383, 354, 349, 394, 358, 387, + 400, 386, 402, 354, 396, 387, 391, 365, 377, 359, 361, 365, 395, 388, 388, 384, 388, + 378, 374, 382, 376, 377, 389, 378, 341, 390, 376, 381, 375, 414, 368, 369, 387, 411, + 396, 391, 378, 389, 349, 383, 344, 381, 387, 380, 353, 361, 391, 365, 390, 396, 382, + 386, 385, 385, 409, 387, 386, 378, 372, 372, 374, 349, 388, 389, 348, 395, 380, 382, + 388, 375, 347, 383, 359, 389, 368, 361, 405, 398, 393, 395, 359, 360, 395, 395, 362, + 354, 388, 348, 388, 386, 390, 350, 388, 356, 369, 364, 404, 404, 391, 394, 385, 439, + 432, 375, 366, 441, 362, 367, 382, 374, 346, 391, 371, 354, 376, 390, 373, 382, 385, + 389, 378, 377, 347, 414, 338, 348, 385, 352, 385, 386, 381, 388, 387, 364, 465, 405, + 443, 387, 339, 376, 337, 379, 387, 370, 374, 358, 354, 357, 393, 356, 381, 357, 407, + 361, 397, 362, 394, 394, 392, 394, 391, 381, 386, 379, 354, 351, 392, 408, 393, 389, + 388, 385, 375, 388, 375, 388, 375, 354, 384, 379, 386, 394, 383, 359, 405, 395, 352, + 345, 403, 427, 373, 380, 350, 415, 378, 434, 385, 388, 387, 400, 405, 329, 391, 356, + 419, 358, 359, 375, 367, 391, 359, 369, 361, 376, 378, 379, 348, 390, 345, 388, 390, + 406, 349, 368, 364, 391, 384, 401, 384, 391, 361, 399, 359, 386, 392, 382, 386, 380, + 383, 345, 376, 393, 400, 395, 343, 352, 354, 381, 388, 357, 393, 389, 384, 389, 388, + 384, 404, 372, 358, 381, 352, 355, 485, 393, 371, 376, 389, 377, 391, 387, 376, 342, + 390, 375, 379, 396, 376, 402, 353, 392, 382, 383, 387, 386, 372, 377, 382, 388, 381, + 387, 357, 393, 385, 346, 389, 388, 357, 362, 404, 398, 397, 402, 371, 351, 370, 362, + 350, 388, 399, 402, 406, 377, 396, 359, 372, 390, 392, 368, 383, 346, 384, 381, 379, + 367, 384, 389, 381, 371, 358, 422, 372, 382, 374, 444, 412, 369, 362, 373, 389, 401, + 383, 380, 366, 365, 361, 379, 372, 345, 382, 375, 376, 375, 382, 356, 395, 383, 384, + 391, 361, 396, 407, 365, 351, 385, 378, 403, 344, 352, 387, 397, 399, 377, 371, 381, + 415, 382, 388, 368, 383, 405, 390, 386, 384, 374, 375, 381, 371, 372, 374, 377, 346, + 358, 381, 377, 359, 385, 396, 385, 390, 389, 391, 375, 357, 389, 390, 377, 370, 379, + 351, 381, 381, 380, 371, 386, 389, 389, 383, 362, 393, 388, 355, 396, 383, 352, 384, + 352, 383, 362, 396, 385, 396, 357, 388, 382, 377, 373, 379, 383, 386, 350, 393, 355, + 380, 401, 392, 391, 402, 391, 427, 407, 394, 332, 398, 367, 373, 343, 381, 383, 386, + 382, 349, 353, 393, 378, 386, 375, 390, 356, 392, 384, 387, 380, 381, 385, 386, 383, + 378, 379, 359, 381, 382, 388, 357, 357, 397, 358, 424, 382, 352, 409, 374, 368, 365, + 399, 352, 393, 389, 385, 352, 380, 398, 389, 385, 387, 387, 353, 402, 396, 386, 357, + 395, 368, 369, 407, 394, 383, 362, 380, 385, 368, 375, 365, 379, 377, 388, 380, 346, + 383, 381, 399, 359, 386, 455, 368, 406, 377, 339, 381, 377, 373, 371, 338, 371, 387, + 376, 386, 388, 382, 381, 377, 389, 352, 391, 396, 398, 374, 352, 358, 387, 368, 401, + 395, 387, 387, 354, 393, 401, 382, 390, 371, 374, 387, 377, 379, 377, 383, 374, 367, + 372, 393, 365, 392, 350, 378, 385, 377, 382, 388, 353, 389, 359, 366, 404, 390, 381, + 396, 388, 394, 380, 379, 372, 355, 397, 382, 351, 397, 378, 375, 378, 369, 387, 380, + 383, 346, 357, 362, 371, 413, 393, 365, 395, 391, 384, 386, 385, 390, 355, 385, 394, + 384, 383, 431, 369, 373, 392, 397, 396, 353, 391, 352, 375, 382, 397, 393, 371, 403, + 375, 338, 418, 368, 372, 370, 344, 392, 360, 402, 402, 425, 374, 378, 376, 380, 378, + 347, 379, 414, 377, 390, 383, 357, 390, 385, 377, 378, 368, 399, 389, 383, 368, 372, + 358, 386, 355, 380, 386, 349, 381, 379, 380, 351, 389, 380, 353, 359, 365, 370, 407, + 388, 381, 358, 364, 396, 369, 407, 391, 358, 440, 419, 412, 395, 344, 382, 391, 353, + 403, 391, 371, 354, 362, 407, 411, 397, 385, 388, 357, 348, 368, 401, 404, 380, 370, + 369, 365, 349, 373, 346, 351, 394, 399, 387, 393, 363, 402, 394, 375, 389, 386, 395, + 386, 386, 353, 403, 363, 376, 398, 383, 372, 350, 381, 353, 445, 386, 369, 383, 351, + 392, 397, 384, 389, 354, 400, 392, 379, 386, 355, 391, 388, 361, 390, 408, 357, 390, + 387, 352, 393, 357, 358, 401, 383, 391, 384, 388, 377, 380, 354, 393, 387, 357, 396, + 360, 362, 388, 390, 359, 367, 366, 396, 388, 394, 363, 391, 394, 351, 391, 391, 350, + 360, 365, 397, 366, 375, 400, 412, 372, 380, 383, 384, 383, 390, 380, 361, 363, 387, + 358, 385, 359, 385, 399, 351, 392, 388, 385, 384, 350, 379, 385, 383, 375, 389, 381, + 382, 376, 389, 390, 375, 381, 382, 390, 385, 380, 359, 351, 383, 391, 388, 379, 354, + 387, 382, 358, 381, 381, 386, 397, 373, 381, 387, 387, 381, 378, 383, 370, 360, 386, + 362, 402, 357, 398, 398, 397, 378, 394, 381, 375, 380, 390, 373, 369, 388, 347, 356, + 384, 391, 386, 394, 388, 357, 403, 381, 376, 414, 383, 387, 349, 379, 383, 384, 377, + 394, 426, 373, 392, 367, 381, 378, 378, 374, 373, 369, 368, 332, 335, 381, 392, 388, + 381, 424, 367, 398, 399, 392, 379, 391, 379, 370, 343, 405, 378, 367, 345, 379, 347, + 388, 353, 392, 382, 384, 387, 350, 363, 398, 398, 359, 402, 454, 440, 341, 383, 381, + 385, 355, 349, 369, 360, 388, 383, 354, 435, 405, 404, 399, 385, 386, 364, 388, 373, + 376, 384, 395, 400, 408, 390, 375, 341, 372, 371, 407, 345, 378, 345, 407, 365, 398, + 396, 339, 379, 375, 410, 386, 407, 387, 365, 375, 384, 347, 393, 377, 350, 376, 375, + 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]; + let ES_LENGTH = 500; + let mime = 'audio/mp4a-latm'; + let mediaDescription = { + "channel_count": 2, + "sample_rate": 44100, + "audio_raw_format": 4, + }; + let expectError = false; + + beforeAll(function() { + console.info('beforeAll case'); + }) + + beforeEach(function() { + console.info('beforeEach case'); + audioDecodeProcessor = null; + readStreamSync = undefined; + EOSFrameNum = 0; + samplerate = 44.1; + flushAtEOS = false; + workdoneAtEOS = false; + needGetMediaDes = false; + needrelease = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + inputQueue = []; + outputQueue = []; + ES = [0, 283, 336, 291, 405, 438, 411, 215, 215, 313, 270, 342, 641, 554, 545, 545, 546, + 541, 540, 542, 552, 537, 533, 498, 472, 445, 430, 445, 427, 414, 386, 413, 370, 380, + 401, 393, 369, 391, 367, 395, 396, 396, 385, 391, 384, 395, 392, 386, 388, 384, 379, + 376, 381, 375, 373, 349, 391, 357, 384, 395, 384, 380, 386, 372, 386, 383, 378, 385, + 385, 384, 342, 390, 379, 387, 386, 393, 397, 362, 393, 394, 391, 383, 385, 377, 379, + 381, 369, 375, 379, 346, 382, 356, 361, 366, 394, 393, 385, 362, 406, 399, 384, 377, + 385, 389, 375, 346, 396, 388, 381, 383, 352, 357, 397, 382, 395, 376, 388, 373, 374, + 353, 383, 384, 393, 379, 348, 364, 389, 380, 381, 388, 423, 392, 381, 368, 351, 391, + 355, 358, 395, 390, 385, 382, 383, 388, 388, 389, 376, 379, 376, 384, 369, 354, 390, + 389, 396, 393, 382, 385, 353, 383, 381, 377, 411, 387, 390, 377, 349, 381, 390, 378, + 373, 375, 381, 351, 392, 381, 380, 381, 378, 387, 379, 383, 348, 386, 364, 386, 371, + 399, 399, 385, 380, 355, 397, 395, 382, 380, 386, 352, 387, 390, 373, 372, 388, 378, + 385, 368, 385, 370, 378, 373, 383, 368, 373, 388, 351, 384, 391, 387, 389, 383, 355, + 361, 392, 386, 354, 394, 392, 397, 392, 352, 381, 395, 349, 383, 390, 392, 350, 393, + 393, 385, 389, 393, 382, 378, 384, 378, 375, 373, 375, 389, 377, 383, 387, 373, 344, + 388, 379, 391, 373, 384, 358, 361, 391, 394, 363, 350, 361, 395, 399, 389, 398, 375, + 398, 400, 381, 354, 363, 366, 400, 400, 356, 370, 400, 394, 398, 385, 378, 372, 354, + 359, 393, 381, 363, 396, 396, 355, 390, 356, 355, 371, 399, 367, 406, 375, 377, 405, + 401, 390, 393, 392, 384, 386, 374, 358, 397, 389, 393, 385, 345, 379, 357, 388, 356, + 381, 389, 367, 358, 391, 360, 394, 396, 357, 395, 388, 394, 383, 357, 383, 392, 394, + 376, 379, 356, 386, 395, 387, 377, 377, 389, 377, 385, 351, 387, 350, 388, 384, 345, + 358, 368, 399, 394, 385, 384, 395, 378, 387, 386, 386, 376, 375, 382, 351, 359, 356, + 401, 388, 363, 406, 363, 374, 435, 366, 400, 393, 392, 371, 391, 359, 359, 397, 388, + 390, 420, 411, 369, 384, 382, 383, 383, 375, 381, 361, 380, 348, 379, 386, 379, 379, + 386, 371, 352, 378, 378, 388, 384, 385, 352, 355, 387, 383, 379, 362, 386, 399, 376, + 390, 350, 387, 357, 403, 398, 397, 360, 351, 394, 400, 399, 393, 388, 395, 370, 377, + 395, 360, 346, 381, 370, 390, 380, 391, 387, 382, 384, 383, 354, 349, 394, 358, 387, + 400, 386, 402, 354, 396, 387, 391, 365, 377, 359, 361, 365, 395, 388, 388, 384, 388, + 378, 374, 382, 376, 377, 389, 378, 341, 390, 376, 381, 375, 414, 368, 369, 387, 411, + 396, 391, 378, 389, 349, 383, 344, 381, 387, 380, 353, 361, 391, 365, 390, 396, 382, + 386, 385, 385, 409, 387, 386, 378, 372, 372, 374, 349, 388, 389, 348, 395, 380, 382, + 388, 375, 347, 383, 359, 389, 368, 361, 405, 398, 393, 395, 359, 360, 395, 395, 362, + 354, 388, 348, 388, 386, 390, 350, 388, 356, 369, 364, 404, 404, 391, 394, 385, 439, + 432, 375, 366, 441, 362, 367, 382, 374, 346, 391, 371, 354, 376, 390, 373, 382, 385, + 389, 378, 377, 347, 414, 338, 348, 385, 352, 385, 386, 381, 388, 387, 364, 465, 405, + 443, 387, 339, 376, 337, 379, 387, 370, 374, 358, 354, 357, 393, 356, 381, 357, 407, + 361, 397, 362, 394, 394, 392, 394, 391, 381, 386, 379, 354, 351, 392, 408, 393, 389, + 388, 385, 375, 388, 375, 388, 375, 354, 384, 379, 386, 394, 383, 359, 405, 395, 352, + 345, 403, 427, 373, 380, 350, 415, 378, 434, 385, 388, 387, 400, 405, 329, 391, 356, + 419, 358, 359, 375, 367, 391, 359, 369, 361, 376, 378, 379, 348, 390, 345, 388, 390, + 406, 349, 368, 364, 391, 384, 401, 384, 391, 361, 399, 359, 386, 392, 382, 386, 380, + 383, 345, 376, 393, 400, 395, 343, 352, 354, 381, 388, 357, 393, 389, 384, 389, 388, + 384, 404, 372, 358, 381, 352, 355, 485, 393, 371, 376, 389, 377, 391, 387, 376, 342, + 390, 375, 379, 396, 376, 402, 353, 392, 382, 383, 387, 386, 372, 377, 382, 388, 381, + 387, 357, 393, 385, 346, 389, 388, 357, 362, 404, 398, 397, 402, 371, 351, 370, 362, + 350, 388, 399, 402, 406, 377, 396, 359, 372, 390, 392, 368, 383, 346, 384, 381, 379, + 367, 384, 389, 381, 371, 358, 422, 372, 382, 374, 444, 412, 369, 362, 373, 389, 401, + 383, 380, 366, 365, 361, 379, 372, 345, 382, 375, 376, 375, 382, 356, 395, 383, 384, + 391, 361, 396, 407, 365, 351, 385, 378, 403, 344, 352, 387, 397, 399, 377, 371, 381, + 415, 382, 388, 368, 383, 405, 390, 386, 384, 374, 375, 381, 371, 372, 374, 377, 346, + 358, 381, 377, 359, 385, 396, 385, 390, 389, 391, 375, 357, 389, 390, 377, 370, 379, + 351, 381, 381, 380, 371, 386, 389, 389, 383, 362, 393, 388, 355, 396, 383, 352, 384, + 352, 383, 362, 396, 385, 396, 357, 388, 382, 377, 373, 379, 383, 386, 350, 393, 355, + 380, 401, 392, 391, 402, 391, 427, 407, 394, 332, 398, 367, 373, 343, 381, 383, 386, + 382, 349, 353, 393, 378, 386, 375, 390, 356, 392, 384, 387, 380, 381, 385, 386, 383, + 378, 379, 359, 381, 382, 388, 357, 357, 397, 358, 424, 382, 352, 409, 374, 368, 365, + 399, 352, 393, 389, 385, 352, 380, 398, 389, 385, 387, 387, 353, 402, 396, 386, 357, + 395, 368, 369, 407, 394, 383, 362, 380, 385, 368, 375, 365, 379, 377, 388, 380, 346, + 383, 381, 399, 359, 386, 455, 368, 406, 377, 339, 381, 377, 373, 371, 338, 371, 387, + 376, 386, 388, 382, 381, 377, 389, 352, 391, 396, 398, 374, 352, 358, 387, 368, 401, + 395, 387, 387, 354, 393, 401, 382, 390, 371, 374, 387, 377, 379, 377, 383, 374, 367, + 372, 393, 365, 392, 350, 378, 385, 377, 382, 388, 353, 389, 359, 366, 404, 390, 381, + 396, 388, 394, 380, 379, 372, 355, 397, 382, 351, 397, 378, 375, 378, 369, 387, 380, + 383, 346, 357, 362, 371, 413, 393, 365, 395, 391, 384, 386, 385, 390, 355, 385, 394, + 384, 383, 431, 369, 373, 392, 397, 396, 353, 391, 352, 375, 382, 397, 393, 371, 403, + 375, 338, 418, 368, 372, 370, 344, 392, 360, 402, 402, 425, 374, 378, 376, 380, 378, + 347, 379, 414, 377, 390, 383, 357, 390, 385, 377, 378, 368, 399, 389, 383, 368, 372, + 358, 386, 355, 380, 386, 349, 381, 379, 380, 351, 389, 380, 353, 359, 365, 370, 407, + 388, 381, 358, 364, 396, 369, 407, 391, 358, 440, 419, 412, 395, 344, 382, 391, 353, + 403, 391, 371, 354, 362, 407, 411, 397, 385, 388, 357, 348, 368, 401, 404, 380, 370, + 369, 365, 349, 373, 346, 351, 394, 399, 387, 393, 363, 402, 394, 375, 389, 386, 395, + 386, 386, 353, 403, 363, 376, 398, 383, 372, 350, 381, 353, 445, 386, 369, 383, 351, + 392, 397, 384, 389, 354, 400, 392, 379, 386, 355, 391, 388, 361, 390, 408, 357, 390, + 387, 352, 393, 357, 358, 401, 383, 391, 384, 388, 377, 380, 354, 393, 387, 357, 396, + 360, 362, 388, 390, 359, 367, 366, 396, 388, 394, 363, 391, 394, 351, 391, 391, 350, + 360, 365, 397, 366, 375, 400, 412, 372, 380, 383, 384, 383, 390, 380, 361, 363, 387, + 358, 385, 359, 385, 399, 351, 392, 388, 385, 384, 350, 379, 385, 383, 375, 389, 381, + 382, 376, 389, 390, 375, 381, 382, 390, 385, 380, 359, 351, 383, 391, 388, 379, 354, + 387, 382, 358, 381, 381, 386, 397, 373, 381, 387, 387, 381, 378, 383, 370, 360, 386, + 362, 402, 357, 398, 398, 397, 378, 394, 381, 375, 380, 390, 373, 369, 388, 347, 356, + 384, 391, 386, 394, 388, 357, 403, 381, 376, 414, 383, 387, 349, 379, 383, 384, 377, + 394, 426, 373, 392, 367, 381, 378, 378, 374, 373, 369, 368, 332, 335, 381, 392, 388, + 381, 424, 367, 398, 399, 392, 379, 391, 379, 370, 343, 405, 378, 367, 345, 379, 347, + 388, 353, 392, 382, 384, 387, 350, 363, 398, 398, 359, 402, 454, 440, 341, 383, 381, + 385, 355, 349, 369, 360, 388, 383, 354, 435, 405, 404, 399, 385, 386, 364, 388, 373, + 376, 384, 395, 400, 408, 390, 375, 341, 372, 371, 407, 345, 378, 345, 407, 365, 398, + 396, 339, 379, 375, 410, 386, 407, 387, 365, 375, 384, 347, 393, 377, 350, 376, 375, + 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 = 500; + expectError = false; + }) + + afterEach(function() { + console.info('afterEach case'); + if (audioDecodeProcessor != null) { + audioDecodeProcessor = null + } + wait(2000); + }) + + afterAll(function() { + console.info('afterAll case'); + }) + + let failCallback = function(err) { + console.info('case callback err : ' + err); + expect(err).assertUndefined(); + } + + let failCallbackTrue = function(err, mySteps, done) { + console.info('case callback err : ' + err); + expect(err != undefined).assertTrue(); + nextStep(mySteps, done); + } + + let failCatch = function(err) { + console.info('case catch err : ' + err); + expect(err).assertUndefined(); + } + + function resetParam() { + readStreamSync = undefined; + EOSFrameNum = 0; + samplerate = 44.1; + flushAtEOS = false; + workdoneAtEOS = false; + needGetMediaDes = false; + needrelease = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + } + + function createAudioDecoder(savepath, mySteps, done) { + media.createAudioDecoderByMime(mime, (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioDecoder 1`); + audioDecodeProcessor = processor; + setCallback(savepath, done); + console.info("case start api test"); + nextStep(mySteps, done); + }) + } + + function writeFile(path, buf, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let num = writestream.writeSync(buf, {length:len}); + writestream.flushSync(); + writestream.closeSync(); + }catch(e) { + console.info(e) + } + } + + function readFile(path) { + console.info('read file start execution'); + try{ + console.info('filepath: ' + path); + readStreamSync = Fileio.createStreamSync(path, 'rb'); + }catch(e) { + console.info(e); + } + } + + function getContent(buf, len) { + console.info("case start get content"); + let lengthreal = -1; + lengthreal = readStreamSync.readSync(buf,{length:len}); + console.info('lengthreal: ' + lengthreal); + } + + async function doneWork() { + await audioDecodeProcessor.stop().then(() => { + console.info("case stop success"); + }, failCallback).catch(failCatch); + await audioDecodeProcessor.reset().then(() => { + console.info("case reset success"); + }, failCallback).catch(failCatch); + audioDecodeProcessor = null; + } + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + function wait(time) { + for(let t = Date.now(); Date.now() - t <= time;); + } + + function nextStep(mySteps, done) { + console.info("case myStep[0]: " + mySteps[0]); + if (mySteps[0] == END) { + done(); + console.info('case to done'); + return; + } + switch (mySteps[0]) { + case CONFIGURE: + mySteps.shift(); + console.info(`case to configure`); + audioDecodeProcessor.configure(mediaDescription).then(() => { + console.info(`case configure 1`); + readFile(AUDIOPATH); + nextStep(mySteps, done); + }, failCallback).catch(failCatch); + break; + case PREPARE: + mySteps.shift(); + console.info(`case to prepare`); + audioDecodeProcessor.prepare().then(() => { + console.info(`case prepare 1`); + nextStep(mySteps, done); + }, failCallback).catch(failCatch); + break; + case START: + mySteps.shift(); + console.info(`case to start`); + if (sawOutputEOS) { + resetParam(); + readFile(AUDIOPATH); + workdoneAtEOS = true; + enqueueAllInputs(inputQueue); + } + audioDecodeProcessor.start().then(() => { + console.info(`case start 1`); + nextStep(mySteps, done); + }, failCallback).catch(failCatch); + break; + case FLUSH: + mySteps.shift(); + console.info(`case to flush`); + audioDecodeProcessor.flush().then(() => { + console.info(`case flush 1`); + if (flushAtEOS) { + resetParam(); + readFile(AUDIOPATH); + workdoneAtEOS = true; + flushAtEOS = false; + } + nextStep(mySteps, done); + }, failCallback).catch(failCatch); + break; + case STOP: + mySteps.shift(); + console.info(`case to stop`); + audioDecodeProcessor.stop().then(() => { + console.info(`case stop 1`); + nextStep(mySteps, done); + }, failCallback).catch(failCatch); + break; + case RESET: + mySteps.shift(); + console.info(`case to reset`); + audioDecodeProcessor.reset().then(() => { + console.info(`case reset 1`); + nextStep(mySteps, done); + }, failCallback).catch(failCatch); + break; + case HOLDON: + mySteps.shift(); + setTimeout(() =>{ + nextStep(mySteps, done); + }, WAITTIME); + break; + case WAITFORALLOUTS: + mySteps.shift(); + console.info(`case wait for all outputs`); + break; + case CONFIGURE_ERROR: + mySteps.shift(); + console.info(`case to configure 2`); + audioDecodeProcessor.configure(mediaDescription).then(() => { + console.info(`case configure error 1`); + expect(expectError).assertTrue(); + }, (err) => {failCallbackTrue(err, mySteps, done)}).catch(failCatch); + break; + case PREPARE_ERROR: + mySteps.shift(); + console.info(`case to prepare 2`); + audioDecodeProcessor.prepare().then(() => { + console.info(`case prepare error 1`); + expect(expectError).assertTrue(); + }, (err) => {failCallbackTrue(err, mySteps, done)}).catch(failCatch); + break; + case START_ERROR: + mySteps.shift(); + console.info(`case to start 2`); + audioDecodeProcessor.start().then(() => { + console.info(`case start error 1`); + expect(expectError).assertTrue(); + }, (err) => {failCallbackTrue(err, mySteps, done)}).catch(failCatch); + break; + case FLUSH_ERROR: + mySteps.shift(); + console.info(`case to flush 2`); + audioDecodeProcessor.flush().then(() => { + console.info(`case flush error 1`); + expect(expectError).assertTrue(); + }, (err) => {failCallbackTrue(err, mySteps, done)}).catch(failCatch); + break; + case STOP_ERROR: + mySteps.shift(); + console.info(`case to stop 2`); + audioDecodeProcessor.stop().then(() => { + console.info(`case stop error 1`); + expect(expectError).assertTrue(); + }, (err) => {failCallbackTrue(err, mySteps, done)}).catch(failCatch); + break; + case JUDGE_EOS: + mySteps.shift(); + console.info(`case judge EOS state`); + expect(sawOutputEOS).assertTrue(); + nextStep(mySteps, done); + break; + default: + break; + } + } + + async function enqueueAllInputs(queue) { + while (queue.length > 0 && !sawInputEOS) { + let inputobject = queue.shift(); + if (frameCnt == EOSFrameNum || frameCnt == ES_LENGTH + 1) { + inputobject.flags = 1; + inputobject.timeMs = 0; + inputobject.length = 0; + sawInputEOS = true; + } else { + console.info("case read frame from file"); + inputobject.timeMs = timestamp; + inputobject.offset = 0; + inputobject.length = ES[frameCnt]; + getContent(inputobject.data, ES[frameCnt]); + inputobject.flags = 0; + } + timestamp += ES[frameCnt]/samplerate; + frameCnt += 1; + audioDecodeProcessor.queueInput(inputobject).then(() => { + console.info('case queueInput success'); + }); + } + } + + async function dequeueAllOutputs(queue, savapath, done) { + while (queue.length > 0 && !sawOutputEOS) { + let outputobject = queue.shift(); + if (outputobject.flags == 1) { + sawOutputEOS = true; + if (workdoneAtEOS) { + await doneWork(); + done(); + } else { + console.info("sawOutputEOS = true") + } + } + else{ + writeFile(savapath, outputobject.data, outputobject.length); + console.info("write to file success"); + } + audioDecodeProcessor.releaseOutput(outputobject).then(() => { + console.info('release output success'); + }); + } + } + + function setCallback(savepath, done) { + console.info('case callback'); + audioDecodeProcessor.on('inputBufferAvailable', async(inBuffer) => { + console.info('inputBufferAvailable'); + inputQueue.push(inBuffer); + await enqueueAllInputs(inputQueue); + }); + audioDecodeProcessor.on('outputBufferAvailable', async(outBuffer) => { + console.info('outputBufferAvailable'); + if (needGetMediaDes) { + audioDecodeProcessor.getOutputMediaDescription().then((MediaDescription) => { + console.info("get OutputMediaDescription success"); + console.info('get outputMediaDescription : ' + MediaDescription); + needGetMediaDes=false; + }, failCallback).catch(failCatch);} + outputQueue.push(outBuffer); + await dequeueAllOutputs(outputQueue, savepath, done); + }); + audioDecodeProcessor.on('error',(err) => { + console.info('case error called,errName is' + err); + }); + audioDecodeProcessor.on('outputFormatChanged',(format) => { + console.info('Output format changed: ' + format); + }); + } + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0100 + * @tc.name : 001.create -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0100.txt'; + let mySteps = new Array(CONFIGURE, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0200 + * @tc.name : 002.prepare -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0200.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, CONFIGURE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0300 + * @tc.name : 003.start -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, CONFIGURE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0400 + * @tc.name : 004.flush -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, CONFIGURE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0500 + * @tc.name : 005.stop -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP ,CONFIGURE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0600 + * @tc.name : 006.EOS -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, CONFIGURE_ERROR, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0700 + * @tc.name : 007.reset -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0700.txt'; + let mySteps = new Array(RESET, CONFIGURE, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0800 + * @tc.name : 008.configure -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0800.txt'; + let mySteps = new Array(CONFIGURE, CONFIGURE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0900 + * @tc.name : 009.configure -> reset -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_CONFIGURE_PROMISE_0900', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0900.txt'; + let mySteps = new Array(CONFIGURE, RESET, CONFIGURE, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0100 + * @tc.name : 001.create -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0100.txt'; + let mySteps = new Array(PREPARE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0200 + * @tc.name : 002.configure -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0200.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0300 + * @tc.name : 003.prepare -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, PREPARE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0400 + * @tc.name : 004.start -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, PREPARE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0500 + * @tc.name : 005.flush -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, PREPARE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0600 + * @tc.name : 006.stop -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, PREPARE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0700 + * @tc.name : 007.EOS -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, PREPARE_ERROR, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0800 + * @tc.name : 008.reset -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_PREPARE_PROMISE_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, PREPARE_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0100 + * @tc.name : 001.create -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0100.txt'; + let mySteps = new Array(START_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0200 + * @tc.name : 002.configure -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0200.txt'; + let mySteps = new Array(CONFIGURE, START_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0300 + * @tc.name : 003.prepare -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0400 + * @tc.name : 004.start -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, START_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0500 + * @tc.name : 005.flush -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, START_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0600 + * @tc.name : 006.stop -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, START, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0700 + * @tc.name : 007.EOS -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, START_ERROR, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0800 + * @tc.name : 008.reset -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_START_PROMISE_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, START_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0100 + * @tc.name : 001.create -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0100.txt'; + let mySteps = new Array(FLUSH_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0200 + * @tc.name : 002.configure -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0200.txt'; + let mySteps = new Array(CONFIGURE, FLUSH_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0300 + * @tc.name : 003.prepare -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, FLUSH_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0400 + * @tc.name : 004.start -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0500 + * @tc.name : 005.flush -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, FLUSH, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0600 + * @tc.name : 006.stop -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP ,FLUSH_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0700 + * @tc.name : 007.EOS -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, FLUSH, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0800 + * @tc.name : 008.reset -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_FLUSH_PROMISE_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, FLUSH_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0100 + * @tc.name : 001.create -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0100.txt'; + let mySteps = new Array(STOP_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0200 + * @tc.name : 002.configure -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0200.txt'; + let mySteps = new Array(CONFIGURE, STOP_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0300 + * @tc.name : 003.prepare -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, STOP_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0400 + * @tc.name : 004.start -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0500 + * @tc.name : 005.flush -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, STOP, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0600 + * @tc.name : 006.stop -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, STOP_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0700 + * @tc.name : 007.EOS -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, STOP, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0800 + * @tc.name : 008.reset -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_STOP_PROMISE_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, STOP_ERROR, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0100 + * @tc.name : 001.create -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0100.txt'; + let mySteps = new Array(RESET, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0200 + * @tc.name : 002.configure -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0200.txt'; + let mySteps = new Array(CONFIGURE, RESET, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0300 + * @tc.name : 003.prepare -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, RESET, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0400 + * @tc.name : 004.start -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0500 + * @tc.name : 005.flush -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, RESET, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0600 + * @tc.name : 006.stop -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, RESET, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0700 + * @tc.name : 007.EOS -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, RESET, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0800 + * @tc.name : 008.reset -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_RESET_PROMISE_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, RESET, END); + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_EOS_PROMISE_0100 + * @tc.name : 001.EOS -> flush -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_EOS_PROMISE_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0100.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, FLUSH, STOP, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_EOS_PROMISE_0200 + * @tc.name : 002.EOS -> flush -> EOS + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_EOS_PROMISE_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0200.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, FLUSH, WAITFORALLOUTS); + EOSFrameNum = 2; + flushAtEOS = true; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_EOS_PROMISE_0300 + * @tc.name : 003.EOS -> reset -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_EOS_PROMISE_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, RESET, CONFIGURE, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_EOS_PROMISE_0400 + * @tc.name : 004.EOS -> stop -> start -> EOS + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_EOS_PROMISE_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, STOP, START, WAITFORALLOUTS); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_DECODER_API_EOS_PROMISE_0500 + * @tc.name : 005.EOS -> stop -> start -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_DECODER_API_EOS_PROMISE_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, STOP, START, STOP, END); + EOSFrameNum = 2; + createAudioDecoder(savepath, mySteps, done); + }) +}) \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/List.test.js b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..3874a6b726b05b8f8eafd69cdf285b73c26b982a --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/js/test/List.test.js @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2021 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. + */ + + +require('./AudioDecoderFuncPromiseTest.test.js') +require('./AudioDecoderFuncCallbackTest.test.js') +require('./AudioDecoderFormatPromiseTest.test.js') +require('./AudioDecoderFormatCallbackTest.test.js') +require('./AudioDecoderReliabilityPromiseTest.test.js') +require('./AudioDecoderReliabilityCallbackTest.test.js') +require('./AudioDecoderMultiInstancesTest.test.js') + diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/resources/base/element/string.json b/multimedia/media/media_js_standard/audioDecoder/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0bae6bd40f7360d5d818998221b199d3ec0f69c0 --- /dev/null +++ b/multimedia/media/media_js_standard/audioDecoder/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainability_description", + "value": "JS_Empty Ability" + } + ] +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioDecoder/src/main/resources/base/media/icon.png b/multimedia/media/media_js_standard/audioDecoder/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/media/media_js_standard/audioDecoder/src/main/resources/base/media/icon.png differ diff --git a/multimedia/media/media_js_standard/audioEncoder/BUILD.gn b/multimedia/media/media_js_standard/audioEncoder/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a3b1236bca736fbf3b4c3fb22309c5e43a1b0c41 --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/BUILD.gn @@ -0,0 +1,32 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("audio_encoder_js_hap") { + hap_profile = "./src/main/config.json" + js2abc = true + deps = [ + ":audio_encoder_js_assets", + ":audio_encoder_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsAudioEncoderJsTest" +} +ohos_js_assets("audio_encoder_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("audio_encoder_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/multimedia/media/media_js_standard/audioEncoder/Test.json b/multimedia/media/media_js_standard/audioEncoder/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..0a6353d15e8153ae96291bdebc4062dd6ee1e58d --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/Test.json @@ -0,0 +1,40 @@ +{ + "description": "Configuration for audioPlayer Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "2000000", + "package": "ohos.acts.multimedia.audio.audioencoder", + "shell-timeout": "60000" + }, + "kits": [ + { + "type": "PushKit", + "pre-push": [ + ], + "push": [ + "./resource/audio/S32LE.pcm ->/data/media/", + "./resource/audio/S32LE_2.pcm ->/data/media/" + ] + }, + { + "type": "ShellKit", + "run-command": [ + "rm -R /data/media/results", + "chmod 777 -R /data/media", + "chmod 777 /data/media/*", + "mkdir /data/media/results", + "setenforce 0" + ], + "teardown-command":[ + "setenforce 1" + ] + }, + { + "test-file-name": [ + "ActsAudioEncoderJsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/multimedia/media/media_js_standard/audioEncoder/signature/openharmony_sx.p7b b/multimedia/media/media_js_standard/audioEncoder/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/multimedia/media/media_js_standard/audioEncoder/signature/openharmony_sx.p7b differ diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/config.json b/multimedia/media/media_js_standard/audioEncoder/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..04226482df0376f8d6dce28cda94068c0b6fab98 --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/config.json @@ -0,0 +1,74 @@ +{ + "app": { + "apiVersion": { + "compatible": 6, + "releaseType": "Beta1", + "target": 7 + }, + "vendor": "acts", + "bundleName": "ohos.acts.multimedia.audio.audioencoder", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": { + "default": { + "debug": true + } + }, + "module": { + "abilities": [ + { + "iconId": 16777218, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "descriptionId": 16777217, + "visible": true, + "labelId": 16777216, + "icon": "$media:icon", + "name": "ohos.acts.multimedia.audio.audioencoder.MainAbility", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "homeAbility": true, + "launchType": "standard" + } + ], + "deviceType": [ + "phone", + "tablet", + "tv", + "wearable" + ], + "mainAbility": "ohos.acts.multimedia.audio.audioencoder.MainAbility", + "distro": { + "moduleType": "entry", + "installationFree": false, + "deliveryWithInstall": true, + "moduleName": "entry" + }, + "package": "ohos.acts.multimedia.audio.audioencoder", + "name": ".MyApplication", + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": true + } + } + ] + } +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/app.js b/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..e423f4bce4698ec1d7dc86c3eea3990a5e7b1085 --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2021 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. + */ + +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/i18n/en-US.json b/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/i18n/zh-CN.json b/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/pages/index/index.css b/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..5bd7567028568bd522193b2519d545ca6dcf397d --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/pages/index/index.css @@ -0,0 +1,46 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; + width: 100%; + height: 100%; +} + +.title { + font-size: 40px; + color: #000000; + opacity: 0.9; +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} + +@media screen and (device-type: wearable) { + .title { + font-size: 28px; + color: #FFFFFF; + } +} + +@media screen and (device-type: tv) { + .container { + background-image: url("/common/images/Wallpaper.png"); + background-size: cover; + background-repeat: no-repeat; + background-position: center; + } + + .title { + font-size: 100px; + color: #FFFFFF; + } +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/pages/index/index.hml b/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/pages/index/index.js b/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..a0719cee588ac4b0f56efbf784b19647bc6645de --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/js/default/pages/index/index.js @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2021 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 {Core, ExpectExtend} from 'deccjsunit/index' + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + const configService = core.getDefaultService('config') + this.timeout = 60000 + configService.setConfig(this) + require('../../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file 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 new file mode 100644 index 0000000000000000000000000000000000000000..d238c5868b19c8a4c5634d3ac07c2e38647264e4 --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderFuncCallbackTest.test.js @@ -0,0 +1,775 @@ +/* + * Copyright (C) 2021 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 media from '@ohos.multimedia.media' +import Fileio from '@ohos.fileio' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('AudioEncoderFuncCallback', function () { + const AUDIOPATH = '/data/media/S32LE.pcm'; + const AUDIOPATH2 = '/data/media/S32LE_2.pcm'; + const BASIC_PATH = '/data/media/results/encode_func_'; + let readStreamSync; + let eosframenum = 0; + let stopAtEOS = false; + let resetAtEOS = false; + let flushAtEOS = false; + let workdoneAtEOS = false; + let needGetMediaDes = false; + let needrelease = false; + let frameCnt = 1; + let timestamp = 0; + let sawInputEOS = false; + let sawOutputEOS = false; + let inputQueue = []; + let outputQueue = []; + const ES = [0, 4096]; + let ES_LENGTH = 1500; + + beforeAll(function() { + console.info('beforeAll case'); + }) + + beforeEach(function() { + console.info('beforeEach case'); + readStreamSync = undefined; + eosframenum = 0; + stopAtEOS = false; + resetAtEOS = false; + flushAtEOS = false; + workdoneAtEOS = false; + needGetMediaDes = false; + needrelease = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + inputQueue = []; + outputQueue = []; + ES_LENGTH = 2000; + }) + + afterEach(function() { + console.info('afterEach case'); + wait(2000); + }) + + afterAll(function() { + console.info('afterAll case'); + }) + + function resetParam() { + readStreamSync = undefined; + eosframenum = 0; + stopAtEOS = false; + resetAtEOS = false; + flushAtEOS = false; + workdoneAtEOS = false; + needGetMediaDes = false; + needrelease = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + } + + function writeHead(path, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let head = new ArrayBuffer(7); + addADTStoPacket(head, len); + let num = writestream.writeSync(head, {length:7}); + console.info(' writeSync head num = ' + num); + writestream.flushSync(); + writestream.closeSync(); + } catch(e) { + console.info(e); + } + } + function writeFile(path, buf, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let num = writestream.writeSync(buf, {length:len}); + writestream.flushSync(); + writestream.closeSync(); + } catch(e) { + console.info(e); + } + } + + function readFile(path) { + try{ + console.info('filepath: ' + path); + readStreamSync = Fileio.createStreamSync(path, 'rb'); + } catch(e) { + console.info(e); + } + } + + function getContent(buf, len) { + let lengthreal = -1; + lengthreal = readStreamSync.readSync(buf,{length:len}); + console.info('lengthreal: ' + 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 = 3; // 3: 48000HZ + let chanCfg = 1; // 1: 1 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) { + audioEncodeProcessor.stop((err) => { + expect(err).assertUndefined(); + console.info("case stop success") + }) + } + + async function resetWork(audioEncodeProcessor) { + audioEncodeProcessor.reset((err) => { + expect(err).assertUndefined(); + console.info("case reset success"); + if (needrelease) { + audioEncodeProcessor = null + } + }) + } + + async function flushWork(audioEncodeProcessor) { + audioEncodeProcessor.flush((err) => { + expect(err).assertUndefined(); + console.info("case flush at inputeos success"); + resetParam(); + readFile(AUDIOPATH); + workdoneAtEOS =true; + }) + } + + async function doneWork(audioEncodeProcessor, done) { + audioEncodeProcessor.stop((err) => { + expect(err).assertUndefined(); + console.info("case stop success"); + audioEncodeProcessor.reset((err) => { + expect(err).assertUndefined(); + console.log("case reset success"); + audioEncodeProcessor = null; + done(); + }) + }) + } + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + function wait(time) { + for(let t = Date.now(); Date.now() - t <= time;); + } + + async function enqueueAllInputs(audioEncodeProcessor, queue) { + while (queue.length > 0 && !sawInputEOS) { + let inputobject = queue.shift(); + if (frameCnt == eosframenum || frameCnt == ES_LENGTH + 1) { + console.info("EOS frame seperately") + inputobject.flags = 1; + inputobject.timeMs = 0; + inputobject.length = 0; + sawInputEOS = true; + } else { + console.info("read frame from file"); + inputobject.timeMs = timestamp; + inputobject.offset = 0; + inputobject.length = ES[1]; + getContent(inputobject.data, ES[1]); + inputobject.flags = 0; + } + timestamp += 23; + frameCnt += 1; + audioEncodeProcessor.queueInput(inputobject, () => { + console.info('queueInput success'); + }) + } + } + + async function dequeueAllOutputs(audioEncodeProcessor, queue, savepath, done) { + while (queue.length > 0 && !sawOutputEOS) { + let outputobject = queue.shift(); + if (outputobject.flags == 1) { + sawOutputEOS = true; + if (stopAtEOS) { + await stopWork(audioEncodeProcessor); + } else if (resetAtEOS) { + await resetWork(audioEncodeProcessor); + } else if (flushAtEOS) { + await flushWork(audioEncodeProcessor); + } else if (workdoneAtEOS) { + await doneWork(audioEncodeProcessor, done); + } else { + console.info("sawOutputEOS = true"); + } + } + else{ + writeHead(savepath, outputobject.length); + writeFile(savepath, outputobject.data, outputobject.length); + console.info("write to file success"); + } + audioEncodeProcessor.releaseOutput(outputobject, () => { + console.info('release output success'); + }) + } + } + + function setCallback(audioEncodeProcessor, savepath, done) { + console.info('case callback'); + audioEncodeProcessor.on('inputBufferAvailable', async(inBuffer) => { + console.info('case inputBufferAvailable'); + inputQueue.push(inBuffer); + await enqueueAllInputs(audioEncodeProcessor, inputQueue); + }); + audioEncodeProcessor.on('outputBufferAvailable', async(outBuffer) => { + console.info('case outputBufferAvailable'); + if (needGetMediaDes) { + audioEncodeProcessor.getOutputMediaDescription((err, MediaDescription) => { + expect(err).assertUndefined(); + console.info("case get OutputMediaDescription success"); + console.info('get outputMediaDescription : ' + MediaDescription); + needGetMediaDes=false; + }); + } + outputQueue.push(outBuffer); + await dequeueAllOutputs(audioEncodeProcessor, outputQueue, savepath, done); + }); + audioEncodeProcessor.on('error',(err) => { + console.info('case error called,errName is' + err); + }); + audioEncodeProcessor.on('outputFormatChanged',(format) => { + console.info('case Output format changed: ' + format); + }); + } + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_FUNCTION_CALLBACK_00_0100 + * @tc.name : 000.test set EOS after last frame and reset + * @tc.desc : basic Encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_ENCODER_FUNCTION_CALLBACK_00_0100', 0, async function (done) { + console.info("test set EOS after last frame and reset"); + let audioEncodeProcessor; + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let mediaDescription2 = { + "codec_mime": 'audio/mp4a-latm', + } + let savepath = BASIC_PATH + 'callback0000.txt'; + needGetMediaDes = true; + workdoneAtEOS = true; + eventEmitter.on('getAudioEncoderCaps', () => { + audioEncodeProcessor.getAudioEncoderCaps((err, AudioCaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioEncoderCaps 1`); + console.info(`AudioCaps: ` + AudioCaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioEncodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioEncodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioEncodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioEncodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + }) + }); + media.getMediaCapability((err, mediaCaps) => { + expect(err).assertUndefined(); + console.info(`case getMediaCapability 1`); + mediaCaps.getAudioEncoderCaps((err, audioCaps) => { + expect(err).assertUndefined(); + console.info('getAudioDecoderCaps success'); + if (typeof (audioCaps) != 'undefined') { + console.info("case audioCaps " + audioCaps); + } else { + console.info("case audioCaps is not defined"); + } + }) + mediaCaps.findAudioEncoder(mediaDescription2, (err, codecname) => { + expect(err).assertUndefined(); + console.info('findAudioEncoder success'); + if (typeof (codecname) != 'undefined') { + console.info("case codecname " + codecname); + } else { + console.info("case codecname is not defined"); + } + }) + }) + media.createAudioEncoderByName('avdec_aac', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioEncoder by mime 1`); + audioEncodeProcessor = processor; + eventEmitter.emit('getAudioEncoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_FUNCTION_CALLBACK_01_0100 + * @tc.name : 001.test set EOS manually before last frame and reset + * @tc.desc : basic Encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_ENCODER_FUNCTION_CALLBACK_01_0100', 0, async function (done) { + console.info("case test set EOS manually before last frame and reset"); + let audioEncodeProcessor; + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let savepath = BASIC_PATH + 'callback0100.txt'; + eosframenum = 500; + workdoneAtEOS = true; + eventEmitter.on('getAudioEncoderCaps', () => { + audioEncodeProcessor.getAudioEncoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioEncoderCaps 1`); + console.info("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioEncodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioEncodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioEncodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioEncodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + }) + }); + media.createAudioEncoderByMime('audio/mp4a-latm', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioEncoder 1`); + audioEncodeProcessor = processor; + eventEmitter.emit('getAudioEncoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_FUNCTION_CALLBACK_01_0200 + * @tc.name : 002.test flush at running state + * @tc.desc : basic Encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_ENCODER_FUNCTION_CALLBACK_01_0200', 0, async function (done) { + console.info("case test flush at running state"); + let audioEncodeProcessor; + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let savepath = BASIC_PATH + 'callback0200.txt'; + workdoneAtEOS = true; + eventEmitter.on('getAudioEncoderCaps', () => { + audioEncodeProcessor.getAudioEncoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioEncoderCaps 1`); + console.info("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioEncodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioEncodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioEncodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioEncodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + setTimeout(() => {eventEmitter.emit('flush')},5000) + }) + }); + eventEmitter.on('flush', () => { + audioEncodeProcessor.flush((err) => { + expect(err).assertUndefined(); + console.info(`case flush after 5s`); + }) + }); + media.createAudioEncoderByMime('audio/mp4a-latm', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioEncoder 1`); + audioEncodeProcessor = processor; + eventEmitter.emit('getAudioEncoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_FUNCTION_CALLBACK_01_0300 + * @tc.name : 003. test flush at EOS state + * @tc.desc : basic Encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_ENCODER_FUNCTION_CALLBACK_01_0300', 0, async function (done) { + console.info("case test flush at EOS state"); + let audioEncodeProcessor; + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let savepath = BASIC_PATH + 'callback0300.txt'; + eosframenum = 500; + flushAtEOS = true; + eventEmitter.on('getAudioEncoderCaps', () => { + audioEncodeProcessor.getAudioEncoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioEncoderCaps 1`); + console.info("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioEncodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioEncodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioEncodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioEncodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + }) + }); + media.createAudioEncoderByMime('audio/mp4a-latm', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioEncoder 1`); + audioEncodeProcessor = processor; + eventEmitter.emit('getAudioEncoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_FUNCTION_CALLBACK_01_0400 + * @tc.name : 004.test stop at running state and reset + * @tc.desc : basic Encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_ENCODER_FUNCTION_CALLBACK_01_0400', 0, async function (done) { + console.info("case test stop at running state and reset"); + let audioEncodeProcessor; + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let savepath = BASIC_PATH + 'callback0400.txt'; + eventEmitter.on('getAudioEncoderCaps', () => { + audioEncodeProcessor.getAudioEncoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioEncoderCaps 1`); + console.info("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioEncodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioEncodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioEncodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioEncodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + eventEmitter.emit('stop'); + }) + }); + eventEmitter.on('stop', () => { + sleep(5000).then(() => { + audioEncodeProcessor.stop((err) => { + expect(err).assertUndefined(); + console.info(`case stop 1`); + eventEmitter.emit('reset'); + }) + }) + }); + eventEmitter.on('reset', () => { + audioEncodeProcessor.reset((err) => { + expect(err).assertUndefined(); + console.info(`case reset 1`); + audioEncodeProcessor = null; + done(); + }) + }); + media.createAudioEncoderByMime('audio/mp4a-latm', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioEncoder 1`); + audioEncodeProcessor = processor; + eventEmitter.emit('getAudioEncoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_FUNCTION_CALLBACK_01_0500 + * @tc.name : 005.test stop and restart + * @tc.desc : basic Encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_ENCODER_FUNCTION_CALLBACK_01_0500', 0, async function (done) { + console.info("case test stop and restart"); + let audioEncodeProcessor; + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let savepath = BASIC_PATH + 'callback0500.txt'; + eosframenum = 100; + eventEmitter.on('getAudioEncoderCaps', () => { + audioEncodeProcessor.getAudioEncoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioEncoderCaps 1`); + console.info("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioEncodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioEncodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioEncodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioEncodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + eventEmitter.emit('stop'); + }) + }); + eventEmitter.on('stop', () => { + sleep(5000).then(() => { + audioEncodeProcessor.stop((err) => { + expect(err).assertUndefined(); + console.info(`stop after 5s`); + resetParam(); + readFile(AUDIOPATH); + eventEmitter.emit('restart'); + }) + }) + }); + eventEmitter.on('restart', () => { + sleep(2000).then(() => { + audioEncodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`restart after 2s`); + workdoneAtEOS = true; + enqueueAllInputs(audioEncodeProcessor, inputQueue); + }) + }) + }); + media.createAudioEncoderByMime('audio/mp4a-latm', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioEncoder 1`); + audioEncodeProcessor = processor; + eventEmitter.emit('getAudioEncoderCaps'); + }) + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_FUNCTION_CALLBACK_01_0600 + * @tc.name : 006.test reconfigure for new file with the same format + * @tc.desc : basic Encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_ENCODER_FUNCTION_CALLBACK_01_0600', 0, async function (done) { + console.info("case test reconfigure for new file with the same format"); + let audioEncodeProcessor; + let events = require('events'); + let eventEmitter = new events.EventEmitter(); + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let savepath = BASIC_PATH + 'callback0600.txt'; + eosframenum = 100; + resetAtEOS = true; + let mediaDescription2 = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let hasreconfigured = false; + eventEmitter.on('getAudioEncoderCaps', () => { + audioEncodeProcessor.getAudioEncoderCaps((err, Audiocaps) => { + expect(err).assertUndefined(); + console.info(`case getAudioEncoderCaps 1`); + console.info("AudioCaps: " + Audiocaps); + eventEmitter.emit('configure', mediaDescription); + }) + }); + eventEmitter.on('configure', (mediaDescription) => { + audioEncodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + eventEmitter.emit('prepare'); + }) + }); + eventEmitter.on('prepare', () => { + audioEncodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + setCallback(audioEncodeProcessor, savepath, done); + eventEmitter.emit('start'); + }) + }); + eventEmitter.on('start', () => { + audioEncodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + if (!hasreconfigured) { + eventEmitter.emit('reconfigure', mediaDescription2); + } + }) + }); + eventEmitter.on('reconfigure', (mediaDescription2) => { + sleep(10000).then(() => { + audioEncodeProcessor.configure(mediaDescription2, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 2`); + resetParam(); + readFile(AUDIOPATH2) + savepath = BASIC_PATH + 'callback0601.txt'; + workdoneAtEOS = true; + hasreconfigured = true; + eventEmitter.emit('prepare'); + }) + }) + }); + media.createAudioEncoderByMime('audio/mp4a-latm', (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioEncoder 1`); + audioEncodeProcessor = processor; + eventEmitter.emit('getAudioEncoderCaps'); + }) + }) +}) \ No newline at end of file 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 new file mode 100644 index 0000000000000000000000000000000000000000..f241fe15bad698f39fff282bdb2c6f8264b25292 --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderFuncPromiseTest.test.js @@ -0,0 +1,632 @@ +/* + * Copyright (C) 2021 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 media from '@ohos.multimedia.media' +import Fileio from '@ohos.fileio' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('AudioEncoderFuncPromise', function () { + const AUDIOPATH = '/data/media/S32LE.pcm'; + const AUDIOPATH2 = '/data/media/S32LE_2.pcm'; + const BASIC_PATH = '/data/media/results/encode_func_promise_'; + let readStreamSync; + let eosframenum = 0; + let stopAtEOS = false; + let resetAtEOS = false; + let flushAtEOS = false; + let workdoneAtEOS = false; + let needgetMediaDes = false; + let needrelease = false; + let frameCnt = 1; + let timestamp = 0; + let sawInputEOS = false; + let sawOutputEOS = false; + let inputQueue = []; + let outputQueue = []; + const ES = [0, 4096]; + let ES_LENGTH = 2000; + + beforeAll(function() { + console.info('beforeAll case'); + }) + + beforeEach(function() { + console.info('beforeEach case'); + readStreamSync = undefined; + eosframenum = 0; + stopAtEOS = false; + resetAtEOS = false; + flushAtEOS = false; + workdoneAtEOS = false; + needgetMediaDes = false; + needrelease = false + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + inputQueue = []; + outputQueue = []; + ES_LENGTH = 2000; + }) + + afterEach(function() { + console.info('afterEach case'); + wait(2000); + }) + + afterAll(function() { + console.info('afterAll case'); + }) + + let failCallback = function(err) { + console.info('case callback err : ' + err); + expect(err).assertUndefined(); + } + + let failCatch = function(err) { + console.info('case catch err : ' + err); + expect(err).assertUndefined(); + } + + function resetParam() { + readStreamSync = undefined; + eosframenum = 0; + stopAtEOS = false; + resetAtEOS = false; + flushAtEOS = false; + workdoneAtEOS = false; + needgetMediaDes = false; + needrelease = false + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + } + + function writeHead(path, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let head = new ArrayBuffer(7); + addADTStoPacket(head, len); + let num = writestream.writeSync(head, {length:7}); + writestream.flushSync(); + writestream.closeSync(); + } catch(e) { + console.info(e) + } + } + + function writeFile(path, buf, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let num = writestream.writeSync(buf, {length:len}); + writestream.flushSync(); + writestream.closeSync(); + } catch(e) { + console.info(e); + } + } + + function readFile(path) { + try{ + console.info('filepath: ' + path); + readStreamSync = Fileio.createStreamSync(path, 'rb'); + } catch(e) { + console.info(e); + } + } + + function getContent(buf, len) { + console.info("case start get content"); + let lengthreal = -1; + lengthreal = readStreamSync.readSync(buf,{length:len}); + console.info('lengthreal: ' + 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 = 3; // 3: 48000HZ + let chanCfg = 1; // 1: 1 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) { + await audioEncodeProcessor.stop().then(() => { + console.info("case stop success") + }, failCallback).catch(failCatch); + } + + async function resetWork(audioEncodeProcessor) { + await audioEncodeProcessor.reset().then(() => { + console.info("case reset success"); + if (needrelease) { + audioEncodeProcessor = null; + } + }, failCallback).catch(failCatch); + } + + async function flushWork(audioEncodeProcessor) { + await audioEncodeProcessor.flush().then(() => { + console.info("case flush at inputeos success"); + resetParam(); + readFile(AUDIOPATH); + workdoneAtEOS =true; + }, failCallback).catch(failCatch); + } + + async function doneWork(audioEncodeProcessor) { + await audioEncodeProcessor.stop().then(() => { + console.info("case stop success"); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.reset().then(() => { + console.info("case reset success"); + }, failCallback).catch(failCatch); + audioEncodeProcessor = null; + } + + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + function wait(time) { + for(let t = Date.now();Date.now() - t <= time;); + } + + async function enqueueInputs(audioEncodeProcessor, queue) { + while (queue.length > 0 && !sawInputEOS) { + let inputobject = queue.shift(); + console.info("case frameCnt:" + frameCnt); + if (frameCnt == eosframenum || frameCnt == ES_LENGTH + 1) { + console.info("case EOS frame seperately") + inputobject.flags = 1; + inputobject.timeMs = 0; + inputobject.length = 0; + sawInputEOS = true; + } else { + console.info("case read frame from file"); + inputobject.timeMs = timestamp; + inputobject.offset = 0; + inputobject.length = ES[1]; + getContent(inputobject.data, ES[1]); + inputobject.flags = 0; + } + timestamp += 23; + frameCnt += 1; + audioEncodeProcessor.queueInput(inputobject).then(() => { + console.info('case queueInput success'); + }); + } + } + + async function dequeueOutputs(audioEncodeProcessor, queue, savepath, done) { + while (queue.length > 0 && !sawOutputEOS) { + let outputobject = queue.shift(); + if (outputobject.flags == 1) { + sawOutputEOS = true; + if (stopAtEOS) { + await stopWork(audioEncodeProcessor); + } else if (resetAtEOS) { + await resetWork(audioEncodeProcessor); + } else if (flushAtEOS) { + await flushWork(audioEncodeProcessor); + } else if (workdoneAtEOS) { + await doneWork(audioEncodeProcessor); + done(); + } else { + console.info('sawOutputEOS = true'); + } + } + else{ + writeHead(savepath, outputobject.length); + writeFile(savepath, outputobject.data, outputobject.length); + console.info("write to file success"); + } + audioEncodeProcessor.releaseOutput(outputobject).then(() => { + console.info('release output success'); + }); + } + } + + function setCallback(audioEncodeProcessor, savepath, done) { + console.info('case callback'); + audioEncodeProcessor.on('inputBufferAvailable', async(inBuffer) => { + console.info('inputBufferAvailable'); + inputQueue.push(inBuffer); + await enqueueInputs(audioEncodeProcessor, inputQueue); + }); + audioEncodeProcessor.on('outputBufferAvailable', async(outBuffer) => { + console.info('outputBufferAvailable'); + if (needgetMediaDes) { + audioEncodeProcessor.getOutputMediaDescription().then((MediaDescription) => { + console.info("get OutputMediaDescription success"); + console.info('get outputMediaDescription : ' + MediaDescription); + needgetMediaDes=false; + }, failCallback).catch(failCatch); + } + outputQueue.push(outBuffer); + await dequeueOutputs(audioEncodeProcessor, outputQueue, savepath, done); + }); + audioEncodeProcessor.on('error',(err) => { + console.info('case error called,errName is' + err); + }); + audioEncodeProcessor.on('outputFormatChanged',(format) => { + console.info('Output format changed: ' + format); + }); + } + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_FUNCTION_PROMISE_00_0100 + * @tc.name : 000.test set EOS after last frame and reset + * @tc.desc : basic encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level0 + */ + it('SUB_MEDIA_AUDIO_ENCODER_FUNCTION_PROMISE_00_0100', 0, async function (done) { + console.info("case test set EOS after last frame and reset"); + let audioEncodeProcessor; + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let mediaDescription2 = { + "codec_mime": 'audio/mp4a-latm', + } + let savepath = BASIC_PATH + '0000.txt'; + needgetMediaDes = true; + workdoneAtEOS = true; + await media.getMediaCapability().then((mediaCaps) => { + console.info('getMediaCapability success'); + if (typeof (mediaCaps) != 'undefined') { + mediaCaps.getAudioEncoderCaps().then((audioCaps) => { + console.info('getAudioEncoderCaps success'); + if (typeof (audioCaps) != 'undefined') { + console.info("case audioCaps " + audioCaps); + } else { + console.info("case audioCaps is not defined"); + } + }, failCallback).catch(failCatch); + mediaCaps.findAudioEncoder(mediaDescription2).then((codecname) => { + console.info('getAudioEncoderCaps success'); + if (typeof (codecname) != 'undefined') { + console.info("case codecname " + codecname); + } else { + console.info("case codecname is not defined"); + } + }, failCallback).catch(failCatch); + } else { + console.info('mediaCaps is not defined'); + } + }, failCallback).catch(failCatch); + await media.createAudioEncoderByMime('audio/mp4a-latm').then((processor) => { + console.info("case create createAudioEncoder success"); + audioEncodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioEncodeProcessor.getAudioEncoderCaps().then((AudioCaps) => { + console.info("case get AudioEncoderCaps success"); + console.info("print AudioCaps: " + AudioCaps) + }, failCallback).catch(failCatch); + await audioEncodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH); + }, failCallback).catch(failCatch); + setCallback(audioEncodeProcessor, savepath, done); + await audioEncodeProcessor.prepare().then(() => { + console.info("case prepare success"); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.start().then(() => { + console.info("case start success") + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_FUNCTION_PROMISE_01_0100 + * @tc.name : 001.test set EOS manually before last frame and reset + * @tc.desc : basic encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_ENCODER_FUNCTION_PROMISE_01_0100', 0, async function (done) { + console.info("case test set EOS manually before last frame and reset"); + let audioEncodeProcessor; + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let savepath = BASIC_PATH + '0100.txt'; + eosframenum = 500; + workdoneAtEOS = true; + await media.createAudioEncoderByMime('audio/mp4a-latm').then((processor) => { + console.info("case create createAudioEncoder success"); + audioEncodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioEncodeProcessor.getAudioEncoderCaps().then((AudioCaps) => { + console.info("case get AudioEncoderCaps success"); + console.info("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH); + }, failCallback).catch(failCatch); + setCallback(audioEncodeProcessor, savepath, done); + await audioEncodeProcessor.prepare().then(() => { + console.info("case prepare success"); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.start().then(() => { + console.info("case start success"); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_FUNCTION_PROMISE_01_0200 + * @tc.name : 002.test flush at running state + * @tc.desc : basic encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_ENCODER_FUNCTION_PROMISE_01_0200', 0, async function (done) { + console.info("case test flush at running state"); + let audioEncodeProcessor; + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let savepath = BASIC_PATH + '0200.txt'; + workdoneAtEOS = true; + await media.createAudioEncoderByMime('audio/mp4a-latm').then((processor) => { + console.info("case create createAudioEncoder success"); + audioEncodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioEncodeProcessor.getAudioEncoderCaps().then((AudioCaps) => { + console.info("case get AudioEncoderCaps success"); + console.info("print AudioCaps: " + AudioCaps) + }, failCallback).catch(failCatch); + await audioEncodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH) + }, failCallback).catch(failCatch); + setCallback(audioEncodeProcessor, savepath, done); + await audioEncodeProcessor.prepare().then(() => { + console.info("case prepare success") + }, failCallback).catch(failCatch); + await audioEncodeProcessor.start().then(() => { + console.info("case start success") + }, failCallback).catch(failCatch); + await sleep(5000).then(() => { + audioEncodeProcessor.flush().then(() => { + console.info("case flush after 5s") + }, failCallback).catch(failCatch); + }); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_FUNCTION_PROMISE_01_0300 + * @tc.name : 003.test flush at EOS state + * @tc.desc : basic encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_ENCODER_FUNCTION_PROMISE_01_0300', 0, async function (done) { + console.info("case test flush at EOS state"); + let audioEncodeProcessor; + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let savepath = BASIC_PATH + '0300.txt'; + eosframenum = 500; + flushAtEOS = true; + await media.createAudioEncoderByMime('audio/mp4a-latm').then((processor) => { + console.info("case create createAudioEncoder success"); + audioEncodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioEncodeProcessor.getAudioEncoderCaps().then((AudioCaps) => { + console.info("case get AudioEncoderCaps success"); + console.info("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH); + }, failCallback).catch(failCatch); + setCallback(audioEncodeProcessor, savepath, done); + await audioEncodeProcessor.prepare().then(() => { + console.info("case prepare success"); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.start().then(() => { + console.info("case start success"); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_FUNCTION_PROMISE_01_0400 + * @tc.name : 004.test stop at running state and reset + * @tc.desc : basic encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_ENCODER_FUNCTION_PROMISE_01_0400', 0, async function (done) { + console.info("case test stop at running state and reset"); + let audioEncodeProcessor; + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let savepath = BASIC_PATH + '0400.txt'; + await media.createAudioEncoderByMime('audio/mp4a-latm').then((processor) => { + console.info("case create createAudioEncoder success"); + audioEncodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioEncodeProcessor.getAudioEncoderCaps().then((AudioCaps) => { + console.info("case get AudioEncoderCaps success"); + console.info("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH); + }, failCallback).catch(failCatch); + setCallback(audioEncodeProcessor, savepath, done); + await audioEncodeProcessor.prepare().then(() => { + console.info("case prepare success"); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.start().then(() => { + console.info("case start success"); + }, failCallback).catch(failCatch); + await sleep(5000).then(() => { + audioEncodeProcessor.stop().then(() => { + console.info("stop after 5s success"); + }, failCallback).catch(failCatch);}); + await audioEncodeProcessor.reset().then(() => { + console.info("reset success"); + }, failCallback).catch(failCatch); + audioEncodeProcessor = null; + done(); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_FUNCTION_PROMISE_01_0500 + * @tc.name : 005.test stop and restart + * @tc.desc : basic encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_ENCODER_FUNCTION_PROMISE_01_0500', 0, async function (done) { + console.info("case test stop and restart"); + let audioEncodeProcessor; + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let savepath = BASIC_PATH + '0500.txt'; + eosframenum = 100; + await media.createAudioEncoderByMime('audio/mp4a-latm').then((processor) => { + console.info("case create createAudioEncoder success"); + audioEncodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioEncodeProcessor.getAudioEncoderCaps().then((AudioCaps) => { + console.info("case get AudioEncoderCaps success"); + console.info("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH); + }, failCallback).catch(failCatch); + setCallback(audioEncodeProcessor, savepath, done); + await audioEncodeProcessor.prepare().then(() => { + console.info("case prepare success"); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.start().then(() => { + console.info("case start success"); + }, failCallback).catch(failCatch); + await sleep(5000).then(() => { + console.info("stop encoding after 5s"); + }); + await audioEncodeProcessor.stop().then(() => { + console.info("case stop after 5s success"); + }, failCallback).catch(failCatch); + await sleep(2000).then(() => { + console.info("restart encoding after 2s"); + resetParam(); + readFile(AUDIOPATH); + }); + await audioEncodeProcessor.start().then(() => { + console.info("case restart after 3s success"); + workdoneAtEOS = true; + enqueueInputs(audioEncodeProcessor, inputQueue); + }, failCallback).catch(failCatch); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_FUNCTION_PROMISE_01_0600 + * @tc.name : 006.test reconfigure for new file with the same format + * @tc.desc : basic encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level1 + */ + it('SUB_MEDIA_AUDIO_ENCODER_FUNCTION_PROMISE_01_0600', 0, async function (done) { + console.info("case test reconfigure for new file with the same format"); + let audioEncodeProcessor; + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + let savepath = BASIC_PATH + '0600.txt'; + eosframenum = 100; + resetAtEOS = true; + await media.createAudioEncoderByMime('audio/mp4a-latm').then((processor) => { + console.info("case create createAudioEncoder success"); + audioEncodeProcessor = processor; + }, failCallback).catch(failCatch); + await audioEncodeProcessor.getAudioEncoderCaps().then((AudioCaps) => { + console.info("case get AudioEncoderCaps success"); + console.info("print AudioCaps: " + AudioCaps); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.configure(mediaDescription).then(() => { + console.info("case configure success"); + readFile(AUDIOPATH); + }, failCallback).catch(failCatch); + setCallback(audioEncodeProcessor, savepath, done); + await audioEncodeProcessor.prepare().then(() => { + console.info("case prepare success"); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.start().then(() => { + console.info("case start success"); + }, failCallback).catch(failCatch); + let mediaDescription2 = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + } + await sleep(10000).then(() => { + console.info("start configure 2"); + }); + await audioEncodeProcessor.configure(mediaDescription2).then(() => { + console.info("configure 2 success"); + resetParam(); + readFile(AUDIOPATH2); + }, failCallback).catch(failCatch); + let savepath2 = BASIC_PATH + '0601.txt'; + workdoneAtEOS = true; + setCallback(audioEncodeProcessor, savepath2, done); + await audioEncodeProcessor.prepare().then(() => { + console.info("prepare2 success"); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.start().then(() => { + console.info("start2 success"); + }, failCallback).catch(failCatch); + }) +}) \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderMultiInstancesTest.test.js b/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderMultiInstancesTest.test.js new file mode 100644 index 0000000000000000000000000000000000000000..7622e92f90f76f9277be248a2b50ead59beb39f5 --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderMultiInstancesTest.test.js @@ -0,0 +1,312 @@ +/* + * Copyright (C) 2021 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 media from '@ohos.multimedia.media' +import Fileio from '@ohos.fileio' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('AudioEncoderFuncPromise', function () { + const AUDIOPATH = '/data/media/S32LE.pcm'; + const AUDIOPATH2 = '/data/media/S32LE_2.pcm'; + const BASIC_PATH = '/data/media/results/encode_func_promise_'; + let readStreamSync; + let eosframenum = 0; + let stopAtEOS = false; + let resetAtEOS = false; + let flushAtEOS = false; + let workdoneAtEOS = false; + let needgetMediaDes = false; + let needrelease = false; + let frameCnt = 1; + let timestamp = 0; + let sawInputEOS = false; + let sawOutputEOS = false; + let inputQueue = []; + let outputQueue = []; + const ES = [0, 4096]; + let ES_LENGTH = 2000; + + beforeAll(function() { + console.info('beforeAll case'); + }) + + beforeEach(function() { + console.info('beforeEach case'); + readStreamSync = undefined; + eosframenum = 0; + stopAtEOS = false; + resetAtEOS = false; + flushAtEOS = false; + workdoneAtEOS = false; + needgetMediaDes = false; + needrelease = false + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + inputQueue = []; + outputQueue = []; + ES_LENGTH = 2000; + }) + + afterEach(function() { + console.info('afterEach case'); + wait(2000); + }) + + afterAll(function() { + console.info('afterAll case'); + }) + + let failCallback = function(err) { + console.info('case callback err : ' + err); + expect(err).assertUndefined(); + } + + let failCatch = function(err) { + console.info('case catch err : ' + err); + expect(err).assertUndefined(); + } + + function resetParam() { + readStreamSync = undefined; + eosframenum = 0; + stopAtEOS = false; + resetAtEOS = false; + flushAtEOS = false; + workdoneAtEOS = false; + needgetMediaDes = false; + needrelease = false + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + } + + function writeHead(path, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let head = new ArrayBuffer(7); + addADTStoPacket(head, len); + let num = writestream.writeSync(head, {length:7}); + writestream.flushSync(); + writestream.closeSync(); + } catch(e) { + console.info(e) + } + } + + function writeFile(path, buf, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let num = writestream.writeSync(buf, {length:len}); + writestream.flushSync(); + writestream.closeSync(); + } catch(e) { + console.info(e); + } + } + + function readFile(path) { + try{ + console.info('filepath: ' + path); + readStreamSync = Fileio.createStreamSync(path, 'rb'); + } catch(e) { + console.info(e); + } + } + + function getContent(buf, len) { + console.info("case start get content"); + let lengthreal = -1; + lengthreal = readStreamSync.readSync(buf,{length:len}); + console.info('lengthreal: ' + 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 = 3; // 3: 48000HZ + let chanCfg = 1; // 1: 1 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) { + await audioEncodeProcessor.stop().then(() => { + console.info("case stop success") + }, failCallback).catch(failCatch); + } + + async function resetWork(audioEncodeProcessor) { + await audioEncodeProcessor.reset().then(() => { + console.info("case reset success"); + if (needrelease) { + audioEncodeProcessor = null; + } + }, failCallback).catch(failCatch); + } + + async function flushWork(audioEncodeProcessor) { + await audioEncodeProcessor.flush().then(() => { + console.info("case flush at inputeos success"); + resetParam(); + readFile(AUDIOPATH); + workdoneAtEOS =true; + }, failCallback).catch(failCatch); + } + + async function doneWork(audioEncodeProcessor) { + await audioEncodeProcessor.stop().then(() => { + console.info("case stop success"); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.reset().then(() => { + console.info("case reset success"); + }, failCallback).catch(failCatch); + audioEncodeProcessor = null; + } + + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + function wait(time) { + for(let t = Date.now();Date.now() - t <= time;); + } + + async function enqueueInputs(audioEncodeProcessor, queue) { + while (queue.length > 0 && !sawInputEOS) { + let inputobject = queue.shift(); + console.info("case frameCnt:" + frameCnt); + if (frameCnt == eosframenum || frameCnt == ES_LENGTH + 1) { + console.info("case EOS frame seperately") + inputobject.flags = 1; + inputobject.timeMs = 0; + inputobject.length = 0; + sawInputEOS = true; + } else { + console.info("case read frame from file"); + inputobject.timeMs = timestamp; + inputobject.offset = 0; + inputobject.length = ES[1]; + getContent(inputobject.data, ES[1]); + inputobject.flags = 0; + } + timestamp += 23; + frameCnt += 1; + audioEncodeProcessor.queueInput(inputobject).then(() => { + console.info('case queueInput success'); + }); + } + } + + async function dequeueOutputs(audioEncodeProcessor, queue, savepath, done) { + while (queue.length > 0 && !sawOutputEOS) { + let outputobject = queue.shift(); + if (outputobject.flags == 1) { + sawOutputEOS = true; + if (stopAtEOS) { + await stopWork(audioEncodeProcessor); + } else if (resetAtEOS) { + await resetWork(audioEncodeProcessor); + } else if (flushAtEOS) { + await flushWork(audioEncodeProcessor); + } else if (workdoneAtEOS) { + await doneWork(audioEncodeProcessor); + done(); + } else { + console.info('sawOutputEOS = true'); + } + } + else{ + writeHead(savepath, outputobject.length); + writeFile(savepath, outputobject.data, outputobject.length); + console.info("write to file success"); + } + audioEncodeProcessor.releaseOutput(outputobject).then(() => { + console.info('release output success'); + }); + } + } + + function setCallback(audioEncodeProcessor, savepath, done) { + console.info('case callback'); + audioEncodeProcessor.on('inputBufferAvailable', async(inBuffer) => { + console.info('inputBufferAvailable'); + inputQueue.push(inBuffer); + await enqueueInputs(audioEncodeProcessor, inputQueue); + }); + audioEncodeProcessor.on('outputBufferAvailable', async(outBuffer) => { + console.info('outputBufferAvailable'); + if (needgetMediaDes) { + audioEncodeProcessor.getOutputMediaDescription().then((MediaDescription) => { + console.info("get OutputMediaDescription success"); + console.info('get outputMediaDescription : ' + MediaDescription); + needgetMediaDes=false; + }, failCallback).catch(failCatch); + } + outputQueue.push(outBuffer); + await dequeueOutputs(audioEncodeProcessor, outputQueue, savepath, done); + }); + audioEncodeProcessor.on('error',(err) => { + console.info('case error called,errName is' + err); + }); + audioEncodeProcessor.on('outputFormatChanged',(format) => { + console.info('Output format changed: ' + format); + }); + } + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_MULTIINSTANCE_PROMISE_0100 + * @tc.name : 001.create 16 encoder + * @tc.desc : basic encode function + * @tc.size : MediumTest + * @tc.type : Function test + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_MULTIINSTANCE_PROMISE_0100', 0, async function (done) { + console.info("case test multiple encoder instances"); + let array = new Array(); + for (let i = 0; i < 16; i += 1) { + await media.createAudioEncoderByMime('audio/mp4a-latm').then((processor) => { + if (typeof(processor) != 'undefined') { + console.info("case create createAudioEncoder success: " + i); + array[i] = processor; + } else { + console.info("case create createAudioEncoder failed: " + i); + } + }, failCallback).catch(failCatch); + } + console.info('case has created 16 encoders'); + console.info('case array: ' + array); + for (let j = 0; j < 16; j++) { + await array[j].reset().then(() => { + console.info("reset encoder " + j); + array[j] = null; + }, failCallback).catch(failCatch); + } + done(); + }) +}) + + \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderReliabilityCallbackTest.test.js b/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderReliabilityCallbackTest.test.js new file mode 100644 index 0000000000000000000000000000000000000000..df3fda8d97e61867b70bf45c5824fa39492137a4 --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderReliabilityCallbackTest.test.js @@ -0,0 +1,1182 @@ +/* + * Copyright (C) 2021 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 media from '@ohos.multimedia.media' +import Fileio from '@ohos.fileio' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('AudioEncoderSTTCallback', function () { + const AUDIOPATH = '/data/media/S32LE.pcm'; + const BASIC_PATH = '/data/media/results/encode_reliability_callback_'; + const END = 0; + const CONFIGURE = 1; + const PREPARE = 2; + const START = 3; + const FLUSH = 4; + const STOP = 5; + const RESET = 6; + const HOLDON = 7; + const WAITFORALLOUTS = 8; + const CONFIGURE_ERROR = 9; + const PREPARE_ERROR = 10; + const START_ERROR = 11; + const FLUSH_ERROR = 12; + const STOP_ERROR = 13; + const JUDGE_EOS = 14; + const WAITTIME = 3000; + let audioEncodeProcessor; + let readStreamSync; + let EOSFrameNum = 0; + let flushAtEOS = false; + let workdoneAtEOS = false; + let needGetMediaDes = false; + let needRelease = false; + let frameCnt = 1; + let timestamp = 0; + let sawInputEOS = false; + let sawOutputEOS = false; + let inputQueue = []; + let outputQueue = []; + const ES_SIZE = [0, 4096]; + let ES_LENGTH = 200; + let mime = 'audio/mp4a-latm'; + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + }; + + beforeAll(function() { + console.info('beforeAll case'); + }) + + beforeEach(function() { + console.info('beforeEach case'); + audioEncodeProcessor = null; + readStreamSync = undefined; + EOSFrameNum = 0; + flushAtEOS = false; + workdoneAtEOS = false; + needGetMediaDes = false; + needRelease = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + inputQueue = []; + outputQueue = []; + ES_LENGTH = 200; + }) + + afterEach(function() { + console.info('afterEach case'); + if (audioEncodeProcessor != null) { + audioEncodeProcessor = null + } + wait(2000); + }) + + afterAll(function() { + console.info('afterAll case'); + }) + + function resetParam() { + readStreamSync = undefined; + EOSFrameNum = 0; + flushAtEOS = false; + workdoneAtEOS = false; + needGetMediaDes = false; + needRelease = false; + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + } + + function createAudioEncoder(savepath, mySteps, done) { + media.createAudioEncoderByMime(mime, (err, processor) => { + expect(err).assertUndefined(); + console.info(`case createAudioEncoder 1`); + audioEncodeProcessor = processor; + setCallback(savepath, done); + console.info("case start api test"); + nextStep(mySteps, mediaDescription, done); + }) + } + + function writeHead(path, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let head = new ArrayBuffer(7); + addADTStoPacket(head, len); + let num = writestream.writeSync(head, {length:7}); + console.info(' writeSync head num = ' + num); + writestream.flushSync(); + writestream.closeSync(); + } catch(e) { + console.info(e); + } + } + function writeFile(path, buf, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let num = writestream.writeSync(buf, {length:len}); + writestream.flushSync(); + writestream.closeSync(); + } catch(e) { + console.info(e); + } + } + + function readFile(path) { + try{ + console.info('filepath: ' + path); + readStreamSync = Fileio.createStreamSync(path, 'rb'); + } catch(e) { + console.info(e); + } + } + + function getContent(buf, len) { + let lengthreal = -1; + lengthreal = readStreamSync.readSync(buf,{length:len}); + console.info('lengthreal: ' + 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 = 3; // 3: 48000HZ + let chanCfg = 1; // 1: 1 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 doneWork(done) { + audioEncodeProcessor.stop((err) => { + expect(err).assertUndefined(); + console.info("case stop success"); + audioEncodeProcessor.reset((err) => { + expect(err).assertUndefined(); + console.log("case reset success"); + audioEncodeProcessor = null; + done(); + }) + }) + } + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + function wait(time) { + for(let t = Date.now(); Date.now() - t <= time;); + } + + function nextStep(mySteps, mediaDescription, done) { + console.info("case myStep[0]: " + mySteps[0]); + if (mySteps[0] == END) { + done(); + console.info('case to done'); + return; + } + switch (mySteps[0]) { + case CONFIGURE: + mySteps.shift(); + console.info(`case to configure`); + audioEncodeProcessor.configure(mediaDescription, (err) => { + expect(err).assertUndefined(); + console.info(`case configure 1`); + readFile(AUDIOPATH); + nextStep(mySteps, mediaDescription, done); + }); + break; + case PREPARE: + mySteps.shift(); + console.info(`case to prepare`); + audioEncodeProcessor.prepare((err) => { + expect(err).assertUndefined(); + console.info(`case prepare 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case START: + mySteps.shift(); + console.info(`case to start`); + if (sawOutputEOS) { + resetParam(); + readFile(AUDIOPATH); + workdoneAtEOS = true; + enqueueAllInputs(inputQueue); + } + audioEncodeProcessor.start((err) => { + expect(err).assertUndefined(); + console.info(`case start 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case FLUSH: + mySteps.shift(); + console.info(`case to flush`); + audioEncodeProcessor.flush((err) => { + expect(err).assertUndefined(); + console.info(`case flush 1`); + if (flushAtEOS) { + resetParam(); + readFile(AUDIOPATH); + workdoneAtEOS = true; + flushAtEOS = false; + } + nextStep(mySteps, mediaDescription, done); + }); + break; + case STOP: + mySteps.shift(); + console.info(`case to stop`); + audioEncodeProcessor.stop((err) => { + expect(err).assertUndefined(); + console.info(`case stop 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case RESET: + mySteps.shift(); + console.info(`case to reset`); + audioEncodeProcessor.reset((err) => { + expect(err).assertUndefined(); + console.info(`case reset 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case HOLDON: + mySteps.shift(); + setTimeout(() =>{ + nextStep(mySteps, mediaDescription, done); + }, WAITTIME); + break; + case WAITFORALLOUTS: + mySteps.shift(); + console.info(`case wait for all outputs`); + break; + case CONFIGURE_ERROR: + mySteps.shift(); + console.info(`case to configure`); + audioEncodeProcessor.configure(mediaDescription, (err) => { + expect(err != undefined).assertTrue(); + console.info(`case configure error 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case PREPARE_ERROR: + mySteps.shift(); + console.info(`case to prepare`); + audioEncodeProcessor.prepare((err) => { + expect(err != undefined).assertTrue(); + console.info(`case prepare error 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case START_ERROR: + mySteps.shift(); + console.info(`case to start`); + audioEncodeProcessor.start((err) => { + expect(err != undefined).assertTrue(); + console.info(`case start error 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case FLUSH_ERROR: + mySteps.shift(); + console.info(`case to flush`); + audioEncodeProcessor.flush((err) => { + expect(err != undefined).assertTrue(); + console.info(`case flush error 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case STOP_ERROR: + mySteps.shift(); + console.info(`case to stop`); + audioEncodeProcessor.stop((err) => { + expect(err != undefined).assertTrue(); + console.info(`case stop error 1`); + nextStep(mySteps, mediaDescription, done); + }); + break; + case JUDGE_EOS: + mySteps.shift(); + console.info(`case judge EOS state`); + expect(sawOutputEOS).assertTrue(); + nextStep(mySteps, mediaDescription, done); + break; + default: + break; + } + } + + async function enqueueAllInputs(queue) { + while (queue.length > 0 && !sawInputEOS) { + let inputobject = queue.shift(); + if (frameCnt == EOSFrameNum || frameCnt == ES_LENGTH + 1) { + console.info("EOS frame seperately") + inputobject.flags = 1; + inputobject.timeMs = 0; + inputobject.length = 0; + sawInputEOS = true; + } else { + console.info("read frame from file"); + inputobject.timeMs = timestamp; + inputobject.offset = 0; + inputobject.length = ES_SIZE[1]; + getContent(inputobject.data, ES_SIZE[1]); + inputobject.flags = 0; + } + timestamp += 23; + frameCnt += 1; + audioEncodeProcessor.queueInput(inputobject, () => { + console.info('queueInput success'); + }) + } + } + + async function dequeueAllOutputs(queue, savepath, done) { + while (queue.length > 0 && !sawOutputEOS) { + let outputobject = queue.shift(); + if (outputobject.flags == 1) { + sawOutputEOS = true; + if (workdoneAtEOS) { + await doneWork(done); + } else { + console.info("sawOutputEOS = true"); + } + } + else{ + writeHead(savepath, outputobject.length); + writeFile(savepath, outputobject.data, outputobject.length); + console.info("write to file success"); + } + audioEncodeProcessor.releaseOutput(outputobject, () => { + console.info('release output success'); + }) + } + } + + function setCallback(savepath, done) { + console.info('case callback'); + audioEncodeProcessor.on('inputBufferAvailable', async(inBuffer) => { + console.info('case inputBufferAvailable'); + inputQueue.push(inBuffer); + await enqueueAllInputs(inputQueue); + }); + audioEncodeProcessor.on('outputBufferAvailable', async(outBuffer) => { + console.info('case outputBufferAvailable'); + if (needGetMediaDes) { + audioEncodeProcessor.getOutputMediaDescription((err, MediaDescription) => { + expect(err).assertUndefined(); + console.info("case get OutputMediaDescription success"); + console.info('get outputMediaDescription : ' + MediaDescription); + needGetMediaDes=false; + }); + } + outputQueue.push(outBuffer); + await dequeueAllOutputs(outputQueue, savepath, done); + }); + audioEncodeProcessor.on('error',(err) => { + console.info('case error called,errName is' + err); + }); + audioEncodeProcessor.on('outputFormatChanged',(format) => { + console.info('case Output format changed: ' + format); + }); + } + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0100 + * @tc.name : 001.create -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0100.txt'; + let mySteps = new Array(CONFIGURE, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0200 + * @tc.name : 002.prepare -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0200.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, CONFIGURE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0300 + * @tc.name : 003.start -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, CONFIGURE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0400 + * @tc.name : 004.flush -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, CONFIGURE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0500 + * @tc.name : 005.stop -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP ,CONFIGURE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0600 + * @tc.name : 006.EOS -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, CONFIGURE_ERROR, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0700 + * @tc.name : 007.reset -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0700.txt'; + let mySteps = new Array(RESET, CONFIGURE, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0800 + * @tc.name : 008.configure -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0800.txt'; + let mySteps = new Array(CONFIGURE, CONFIGURE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0900 + * @tc.name : 009.configure -> reset -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_CALLBACK_0900', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0900.txt'; + let mySteps = new Array(CONFIGURE, RESET, CONFIGURE, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0100 + * @tc.name : 001.create -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0100.txt'; + let mySteps = new Array(PREPARE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0200 + * @tc.name : 002.configure -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0200.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0300 + * @tc.name : 003.prepare -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, PREPARE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0400 + * @tc.name : 004.start -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, PREPARE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0500 + * @tc.name : 005.flush -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, PREPARE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0600 + * @tc.name : 006.stop -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, PREPARE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0700 + * @tc.name : 007.EOS -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, PREPARE_ERROR, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0800 + * @tc.name : 008.reset -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_CALLBACK_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, PREPARE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0100 + * @tc.name : 001.create -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0100.txt'; + let mySteps = new Array(START_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0200 + * @tc.name : 002.configure -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0200.txt'; + let mySteps = new Array(CONFIGURE, START_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0300 + * @tc.name : 003.prepare -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0400 + * @tc.name : 004.start -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, START_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0500 + * @tc.name : 005.flush -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, START_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0600 + * @tc.name : 006.stop -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, START, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0700 + * @tc.name : 007.EOS -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, START_ERROR, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0800 + * @tc.name : 008.reset -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_CALLBACK_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, START_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0100 + * @tc.name : 001.create -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0100.txt'; + let mySteps = new Array(FLUSH_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0200 + * @tc.name : 002.configure -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0200.txt'; + let mySteps = new Array(CONFIGURE, FLUSH_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0300 + * @tc.name : 003.prepare -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, FLUSH_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0400 + * @tc.name : 004.start -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0500 + * @tc.name : 005.flush -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, FLUSH, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0600 + * @tc.name : 006.stop -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP ,FLUSH_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0700 + * @tc.name : 007.EOS -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, FLUSH, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0800 + * @tc.name : 008.reset -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_CALLBACK_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, FLUSH_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0100 + * @tc.name : 001.create -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0100.txt'; + let mySteps = new Array(STOP_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0200 + * @tc.name : 002.configure -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0200.txt'; + let mySteps = new Array(CONFIGURE, STOP_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0300 + * @tc.name : 003.prepare -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, STOP_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0400 + * @tc.name : 004.start -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0500 + * @tc.name : 005.flush -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, STOP, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0600 + * @tc.name : 006.stop -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, STOP_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0700 + * @tc.name : 007.EOS -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, STOP, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0800 + * @tc.name : 008.reset -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_CALLBACK_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, STOP_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0100 + * @tc.name : 001.create -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0100.txt'; + let mySteps = new Array(RESET, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0200 + * @tc.name : 002.configure -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0200.txt'; + let mySteps = new Array(CONFIGURE, RESET, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0300 + * @tc.name : 003.prepare -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, RESET, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0400 + * @tc.name : 004.start -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0500 + * @tc.name : 005.flush -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, RESET, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0600 + * @tc.name : 006.stop -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, RESET, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0700 + * @tc.name : 007.EOS -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, RESET, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0800 + * @tc.name : 008.reset -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_CALLBACK_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, RESET, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_EOS_CALLBACK_0100 + * @tc.name : 001.EOS -> flush -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_EOS_CALLBACK_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0100.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, FLUSH, STOP, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_EOS_CALLBACK_0200 + * @tc.name : 002.EOS -> flush -> EOS + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_EOS_CALLBACK_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0200.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, FLUSH, WAITFORALLOUTS); + EOSFrameNum = 2; + flushAtEOS = true; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_EOS_CALLBACK_0300 + * @tc.name : 003.EOS -> reset -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_EOS_CALLBACK_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, RESET, CONFIGURE, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_EOS_CALLBACK_0400 + * @tc.name : 004.EOS -> stop -> start -> EOS + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_EOS_CALLBACK_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, STOP, START, WAITFORALLOUTS); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_EOS_CALLBACK_0500 + * @tc.name : 005.EOS -> stop -> start -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_EOS_CALLBACK_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, STOP, START, STOP, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) +}) \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderReliabilityPromiseTest.test.js b/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderReliabilityPromiseTest.test.js new file mode 100644 index 0000000000000000000000000000000000000000..48aa41f1e271ec3a1aba0cdc7562a6ec3a9a18e9 --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderReliabilityPromiseTest.test.js @@ -0,0 +1,1188 @@ +/* + * Copyright (C) 2021 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 media from '@ohos.multimedia.media' +import Fileio from '@ohos.fileio' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('AudioEncoderSTTPromise', function () { + const AUDIOPATH = '/data/media/S32LE.pcm'; + const BASIC_PATH = '/data/media/results/encode_reliability_promise_'; + const END = 0; + const CONFIGURE = 1; + const PREPARE = 2; + const START = 3; + const FLUSH = 4; + const STOP = 5; + const RESET = 6; + const HOLDON = 7; + const WAITFORALLOUTS = 8; + const CONFIGURE_ERROR = 9; + const PREPARE_ERROR = 10; + const START_ERROR = 11; + const FLUSH_ERROR = 12; + const STOP_ERROR = 13; + const JUDGE_EOS = 14; + const WAITTIME = 3000; + let audioEncodeProcessor; + let readStreamSync; + let EOSFrameNum = 0; + let flushAtEOS = false; + let workdoneAtEOS = false; + let needGetMediaDes = false; + let needRelease = false; + let frameCnt = 1; + let timestamp = 0; + let sawInputEOS = false; + let sawOutputEOS = false; + let inputQueue = []; + let outputQueue = []; + const ES_SIZE = [0, 4096]; + let ES_LENGTH = 200; + let mime = 'audio/mp4a-latm'; + let mediaDescription = { + "channel_count": 1, + "sample_rate": 48000, + "audio_raw_format": 16, + }; + let expectError = false; + + beforeAll(function() { + console.info('beforeAll case'); + }) + + beforeEach(function() { + console.info('beforeEach case'); + audioEncodeProcessor = null; + readStreamSync = undefined; + EOSFrameNum = 0; + flushAtEOS = false; + workdoneAtEOS = false; + needGetMediaDes = false; + needRelease = false + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + inputQueue = []; + outputQueue = []; + ES_LENGTH = 200; + expectError = false; + }) + + afterEach(function() { + console.info('afterEach case'); + if (audioEncodeProcessor != null) { + audioEncodeProcessor = null + } + wait(2000); + }) + + afterAll(function() { + console.info('afterAll case'); + }) + + let failCallback = function(err) { + console.info('case callback err : ' + err); + expect(err).assertUndefined(); + } + + let failCallbackTrue = function(err, mySteps, done) { + console.info('case callback err : ' + err); + expect(err != undefined).assertTrue(); + nextStep(mySteps, done); + } + + let failCatch = function(err) { + console.info('case catch err : ' + err); + expect(err).assertUndefined(); + } + + function resetParam() { + readStreamSync = undefined; + EOSFrameNum = 0; + flushAtEOS = false; + workdoneAtEOS = false; + needGetMediaDes = false; + needRelease = false + frameCnt = 1; + timestamp = 0; + sawInputEOS = false; + sawOutputEOS = false; + } + + function createAudioEncoder(savepath, mySteps, done) { + media.createAudioEncoderByMime(mime).then((processor) => { + console.info(`case createAudioEncoder 1`); + audioEncodeProcessor = processor; + setCallback(savepath, done); + console.info("case start api test"); + nextStep(mySteps, done); + }, failCallback).catch(failCatch); + } + + function writeHead(path, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let head = new ArrayBuffer(7); + addADTStoPacket(head, len); + let num = writestream.writeSync(head, {length:7}); + writestream.flushSync(); + writestream.closeSync(); + } catch(e) { + console.info(e) + } + } + + function writeFile(path, buf, len) { + try{ + let writestream = Fileio.createStreamSync(path, "ab+"); + let num = writestream.writeSync(buf, {length:len}); + writestream.flushSync(); + writestream.closeSync(); + } catch(e) { + console.info(e); + } + } + + function readFile(path) { + try{ + console.info('filepath: ' + path); + readStreamSync = Fileio.createStreamSync(path, 'rb'); + } catch(e) { + console.info(e); + } + } + + function getContent(buf, len) { + console.info("case start get content"); + let lengthreal = -1; + lengthreal = readStreamSync.readSync(buf,{length:len}); + console.info('lengthreal: ' + 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 = 3; // 3: 48000HZ + let chanCfg = 1; // 1: 1 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 doneWork() { + await audioEncodeProcessor.stop().then(() => { + console.info("case stop success"); + }, failCallback).catch(failCatch); + await audioEncodeProcessor.reset().then(() => { + console.info("case reset success"); + }, failCallback).catch(failCatch); + audioEncodeProcessor = null; + } + + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + function wait(time) { + for(let t = Date.now();Date.now() - t <= time;); + } + + function nextStep(mySteps, done) { + console.info("case myStep[0]: " + mySteps[0]); + if (mySteps[0] == END) { + done(); + console.info('case to done'); + return; + } + switch (mySteps[0]) { + case CONFIGURE: + mySteps.shift(); + console.info(`case to configure`); + audioEncodeProcessor.configure(mediaDescription).then(() => { + console.info(`case configure 1`); + readFile(AUDIOPATH); + nextStep(mySteps, done); + }, failCallback).catch(failCatch); + break; + case PREPARE: + mySteps.shift(); + console.info(`case to prepare`); + audioEncodeProcessor.prepare().then(() => { + console.info(`case prepare 1`); + nextStep(mySteps, done); + }, failCallback).catch(failCatch); + break; + case START: + mySteps.shift(); + console.info(`case to start`); + if (sawOutputEOS) { + resetParam(); + readFile(AUDIOPATH); + workdoneAtEOS = true; + enqueueInputs(inputQueue); + } + audioEncodeProcessor.start().then(() => { + console.info(`case start 1`); + nextStep(mySteps, done); + }, failCallback).catch(failCatch); + break; + case FLUSH: + mySteps.shift(); + console.info(`case to flush`); + audioEncodeProcessor.flush().then(() => { + console.info(`case flush 1`); + if (flushAtEOS) { + resetParam(); + readFile(AUDIOPATH); + workdoneAtEOS = true; + flushAtEOS = false; + } + nextStep(mySteps, done); + }, failCallback).catch(failCatch); + break; + case STOP: + mySteps.shift(); + console.info(`case to stop`); + audioEncodeProcessor.stop().then(() => { + console.info(`case stop 1`); + nextStep(mySteps, done); + }, failCallback).catch(failCatch); + break; + case RESET: + mySteps.shift(); + console.info(`case to reset`); + audioEncodeProcessor.reset().then(() => { + console.info(`case reset 1`); + nextStep(mySteps, done); + }, failCallback).catch(failCatch); + break; + case HOLDON: + mySteps.shift(); + setTimeout(() =>{ + nextStep(mySteps, done); + }, WAITTIME); + break; + case WAITFORALLOUTS: + mySteps.shift(); + console.info(`case wait for all outputs`); + break; + case CONFIGURE_ERROR: + mySteps.shift(); + console.info(`case to configure 2`); + audioEncodeProcessor.configure(mediaDescription).then(() => { + console.info(`case configure error 1`); + expect(expectError).assertTrue(); + }, (err) => {failCallbackTrue(err, mySteps, done)}).catch(failCatch); + break; + case PREPARE_ERROR: + mySteps.shift(); + console.info(`case to prepare 2`); + audioEncodeProcessor.prepare().then(() => { + console.info(`case prepare error 1`); + expect(expectError).assertTrue(); + }, (err) => {failCallbackTrue(err, mySteps, done)}).catch(failCatch); + break; + case START_ERROR: + mySteps.shift(); + console.info(`case to start 2`); + audioEncodeProcessor.start().then(() => { + console.info(`case start error 1`); + expect(expectError).assertTrue(); + }, (err) => {failCallbackTrue(err, mySteps, done)}).catch(failCatch); + break; + case FLUSH_ERROR: + mySteps.shift(); + console.info(`case to flush 2`); + audioEncodeProcessor.flush().then(() => { + console.info(`case flush error 1`); + expect(expectError).assertTrue(); + }, (err) => {failCallbackTrue(err, mySteps, done)}).catch(failCatch); + break; + case STOP_ERROR: + mySteps.shift(); + console.info(`case to stop 2`); + audioEncodeProcessor.stop().then(() => { + console.info(`case stop error 1`); + expect(expectError).assertTrue(); + }, (err) => {failCallbackTrue(err, mySteps, done)}).catch(failCatch); + break; + case JUDGE_EOS: + mySteps.shift(); + console.info(`case judge EOS state`); + expect(sawOutputEOS).assertTrue(); + nextStep(mySteps, done); + break; + default: + break; + } + } + + async function enqueueInputs(queue) { + while (queue.length > 0 && !sawInputEOS) { + let inputobject = queue.shift(); + console.info("case frameCnt:" + frameCnt); + if (frameCnt == EOSFrameNum || frameCnt == ES_LENGTH + 1) { + console.info("case EOS frame seperately") + inputobject.flags = 1; + inputobject.timeMs = 0; + inputobject.length = 0; + sawInputEOS = true; + } else { + console.info("case read frame from file"); + inputobject.timeMs = timestamp; + inputobject.offset = 0; + inputobject.length = ES_SIZE[1]; + getContent(inputobject.data, ES_SIZE[1]); + inputobject.flags = 0; + } + timestamp += 23; + frameCnt += 1; + audioEncodeProcessor.queueInput(inputobject).then(() => { + console.info('case queueInput success'); + }); + } + } + + async function dequeueOutputs(queue, savepath, done) { + while (queue.length > 0 && !sawOutputEOS) { + let outputobject = queue.shift(); + if (outputobject.flags == 1) { + sawOutputEOS = true; + if (workdoneAtEOS) { + await doneWork(); + done(); + } else { + console.info('sawOutputEOS = true'); + } + } + else{ + writeHead(savepath, outputobject.length); + writeFile(savepath, outputobject.data, outputobject.length); + console.info("write to file success"); + } + audioEncodeProcessor.releaseOutput(outputobject).then(() => { + console.info('release output success'); + }); + } + } + + function setCallback(savepath, done) { + console.info('case callback'); + audioEncodeProcessor.on('inputBufferAvailable', async(inBuffer) => { + console.info('inputBufferAvailable'); + inputQueue.push(inBuffer); + await enqueueInputs(inputQueue); + }); + audioEncodeProcessor.on('outputBufferAvailable', async(outBuffer) => { + console.info('outputBufferAvailable'); + if (needGetMediaDes) { + audioEncodeProcessor.getOutputMediaDescription().then((MediaDescription) => { + console.info("get OutputMediaDescription success"); + console.info('get outputMediaDescription : ' + MediaDescription); + needGetMediaDes=false; + }, failCallback).catch(failCatch); + } + outputQueue.push(outBuffer); + await dequeueOutputs(outputQueue, savepath, done); + }); + audioEncodeProcessor.on('error',(err) => { + console.info('case error called,errName is' + err); + }); + audioEncodeProcessor.on('outputFormatChanged',(format) => { + console.info('Output format changed: ' + format); + }); + } + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0100 + * @tc.name : 001.create -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0100.txt'; + let mySteps = new Array(CONFIGURE, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0200 + * @tc.name : 002.prepare -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0200.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, CONFIGURE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0300 + * @tc.name : 003.start -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, CONFIGURE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0400 + * @tc.name : 004.flush -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, CONFIGURE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0500 + * @tc.name : 005.stop -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP ,CONFIGURE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0600 + * @tc.name : 006.EOS -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, CONFIGURE_ERROR, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0700 + * @tc.name : 007.reset -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0700.txt'; + let mySteps = new Array(RESET, CONFIGURE, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0800 + * @tc.name : 008.configure -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0800.txt'; + let mySteps = new Array(CONFIGURE, CONFIGURE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0900 + * @tc.name : 009.configure -> reset -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_CONFIGURE_PROMISE_0900', 0, async function (done) { + let savepath = BASIC_PATH + 'configure_0900.txt'; + let mySteps = new Array(CONFIGURE, RESET, CONFIGURE, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0100 + * @tc.name : 001.create -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0100.txt'; + let mySteps = new Array(PREPARE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0200 + * @tc.name : 002.configure -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0200.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0300 + * @tc.name : 003.prepare -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, PREPARE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0400 + * @tc.name : 004.start -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, PREPARE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0500 + * @tc.name : 005.flush -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, PREPARE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0600 + * @tc.name : 006.stop -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, PREPARE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0700 + * @tc.name : 007.EOS -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, PREPARE_ERROR, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0800 + * @tc.name : 008.reset -> prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_PREPARE_PROMISE_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'prepare_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, PREPARE_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0100 + * @tc.name : 001.create -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0100.txt'; + let mySteps = new Array(START_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0200 + * @tc.name : 002.configure -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0200.txt'; + let mySteps = new Array(CONFIGURE, START_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0300 + * @tc.name : 003.prepare -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0400 + * @tc.name : 004.start -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, START_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0500 + * @tc.name : 005.flush -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, START_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0600 + * @tc.name : 006.stop -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, START, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0700 + * @tc.name : 007.EOS -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, START_ERROR, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0800 + * @tc.name : 008.reset -> start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_START_PROMISE_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'start_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, START_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0100 + * @tc.name : 001.create -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0100.txt'; + let mySteps = new Array(FLUSH_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0200 + * @tc.name : 002.configure -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0200.txt'; + let mySteps = new Array(CONFIGURE, FLUSH_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0300 + * @tc.name : 003.prepare -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, FLUSH_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0400 + * @tc.name : 004.start -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0500 + * @tc.name : 005.flush -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, FLUSH, WAITFORALLOUTS); + workdoneAtEOS = true; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0600 + * @tc.name : 006.stop -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP ,FLUSH_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0700 + * @tc.name : 007.EOS -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, FLUSH, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0800 + * @tc.name : 008.reset -> flush + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_FLUSH_PROMISE_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'flush_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, FLUSH_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0100 + * @tc.name : 001.create -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0100.txt'; + let mySteps = new Array(STOP_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0200 + * @tc.name : 002.configure -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0200.txt'; + let mySteps = new Array(CONFIGURE, STOP_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0300 + * @tc.name : 003.prepare -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, STOP_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0400 + * @tc.name : 004.start -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0500 + * @tc.name : 005.flush -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, STOP, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0600 + * @tc.name : 006.stop -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, STOP_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0700 + * @tc.name : 007.EOS -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, STOP, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0800 + * @tc.name : 008.reset -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_STOP_PROMISE_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'stop_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, STOP_ERROR, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0100 + * @tc.name : 001.create -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0100.txt'; + let mySteps = new Array(RESET, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0200 + * @tc.name : 002.configure -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0200.txt'; + let mySteps = new Array(CONFIGURE, RESET, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0300 + * @tc.name : 003.prepare -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, RESET, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0400 + * @tc.name : 004.start -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0500 + * @tc.name : 005.flush -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, FLUSH, RESET, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0600 + * @tc.name : 006.stop -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0600', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0600.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, STOP, RESET, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0700 + * @tc.name : 007.EOS -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0700', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0700.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, RESET, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0800 + * @tc.name : 008.reset -> reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_RESET_PROMISE_0800', 0, async function (done) { + let savepath = BASIC_PATH + 'reset_0800.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, RESET, RESET, END); + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_EOS_PROMISE_0100 + * @tc.name : 001.EOS -> flush -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_EOS_PROMISE_0100', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0100.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, FLUSH, STOP, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_EOS_PROMISE_0200 + * @tc.name : 002.EOS -> flush -> EOS + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_EOS_PROMISE_0200', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0200.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, FLUSH, WAITFORALLOUTS); + EOSFrameNum = 2; + flushAtEOS = true; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_EOS_PROMISE_0300 + * @tc.name : 003.EOS -> reset -> configure + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_EOS_PROMISE_0300', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0300.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, RESET, CONFIGURE, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_EOS_PROMISE_0400 + * @tc.name : 004.EOS -> stop -> start -> EOS + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_EOS_PROMISE_0400', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0400.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, STOP, START, WAITFORALLOUTS); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) + + /* * + * @tc.number : SUB_MEDIA_AUDIO_ENCODER_API_EOS_PROMISE_0500 + * @tc.name : 005.EOS -> stop -> start -> stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_AUDIO_ENCODER_API_EOS_PROMISE_0500', 0, async function (done) { + let savepath = BASIC_PATH + 'eos_0500.txt'; + let mySteps = new Array(CONFIGURE, PREPARE, START, HOLDON, JUDGE_EOS, STOP, START, STOP, END); + EOSFrameNum = 2; + createAudioEncoder(savepath, mySteps, done); + }) +}) \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/List.test.js b/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..2d245bee70bd9aa3665db93308c0de6290ace01e --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/js/test/List.test.js @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2021 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. + */ + +require('./AudioEncoderFuncCallbackTest.test.js') +require('./AudioEncoderFuncPromiseTest.test.js') +require('./AudioEncoderReliabilityCallbackTest.test.js') +require('./AudioEncoderReliabilityPromiseTest.test.js') +require('./AudioEncoderMultiInstancesTest.test.js') \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/resources/base/element/string.json b/multimedia/media/media_js_standard/audioEncoder/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..0bae6bd40f7360d5d818998221b199d3ec0f69c0 --- /dev/null +++ b/multimedia/media/media_js_standard/audioEncoder/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainability_description", + "value": "JS_Empty Ability" + } + ] +} \ No newline at end of file diff --git a/multimedia/media/media_js_standard/audioEncoder/src/main/resources/base/media/icon.png b/multimedia/media/media_js_standard/audioEncoder/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/multimedia/media/media_js_standard/audioEncoder/src/main/resources/base/media/icon.png differ