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

!4271 增加编解码出帧自动化校验

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