未验证 提交 0adadfc0 编写于 作者: O openharmony_ci 提交者: Gitee

!1665 audio decoder and encode testcases

Merge pull request !1665 from ling990/ling990
...@@ -20,6 +20,9 @@ group("multimedia") { ...@@ -20,6 +20,9 @@ group("multimedia") {
"audio/audio_js_standard/audioManager:audio_manager_js_hap", "audio/audio_js_standard/audioManager:audio_manager_js_hap",
"media/media_js_standard/audioPlayer:audio_player_js_hap", "media/media_js_standard/audioPlayer:audio_player_js_hap",
"media/media_js_standard/audioRecorder:audio_recorder_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 { } else {
deps = [ deps = [
......
# 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"
}
{
"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
}
]
}
{
"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
/*
* 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');
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
}
}
\ No newline at end of file
.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;
}
}
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* 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
/*
* 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
/*
* 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')
{
"string": [
{
"name": "entry_MainAbility",
"value": "entry_MainAbility"
},
{
"name": "mainability_description",
"value": "JS_Empty Ability"
}
]
}
\ No newline at end of file
# 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"
}
{
"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
}
]
}
{
"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
/*
* 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');
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
}
}
\ No newline at end of file
.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;
}
}
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* 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
/*
* 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
/*
* 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
{
"string": [
{
"name": "entry_MainAbility",
"value": "entry_MainAbility"
},
{
"name": "mainability_description",
"value": "JS_Empty Ability"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册