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

!3636 修复编解码测试套用例失败问题

Merge pull request !3636 from ling990/ling990
......@@ -19,6 +19,10 @@ import router from '@system.router'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
import fileio from '@ohos.fileio'
import featureAbility from '@ohos.ability.featureAbility'
const context = featureAbility.getContext();
// File operation
export async function getFileDescriptor(fileName) {
......@@ -52,6 +56,21 @@ export function isFileOpen(fileDescriptor, done) {
}
}
export async function getFdRead(pathName, done) {
let fdReturn;
await context.getFilesDir().then((fileDir) => {
console.info("case file dir is" + JSON.stringify(fileDir));
pathName = fileDir + '/' + pathName;
console.info("case pathName is" + pathName);
});
await fileio.open(pathName).then((fdNumber) => {
isFileOpen(fdNumber, done)
fdReturn = fdNumber;
console.info('[fileio]case open fd success, fd is ' + fdReturn);
})
return fdReturn;
}
// wait synchronously
export function msleep(time) {
for(let t = Date.now();Date.now() - t <= time;);
......
......@@ -15,11 +15,9 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import featureAbility from '@ohos.ability.featureAbility'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
import {getFileDescriptor, closeFileDescriptor} from './AudioFormatTestBase.test.js';
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('AudioDecoderFormatCompatibilityPromise', function () {
......@@ -2107,7 +2105,12 @@ describe('AudioDecoderFormatCompatibilityPromise', function () {
beforeAll(async function() {
console.info('beforeAll case 1');
await applyPermission();
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
permissionNameList = [permissionName1, permissionName2, permissionName3];
let appName = 'ohos.acts.multimedia.audio.codecformat';
await mediaTestBase.applyPermission(appName, permissionNameList);
console.info('beforeAll case after get permission');
})
......@@ -2142,7 +2145,6 @@ describe('AudioDecoderFormatCompatibilityPromise', function () {
audioDecodeProcessor = null;
}, failCallback).catch(failCatch);
}
await closeFileDescriptor(readPath);
await closeFdWrite();
})
......@@ -2187,39 +2189,9 @@ describe('AudioDecoderFormatCompatibilityPromise', function () {
audioDecodeProcessor = null;
}, failCallback).catch(failCatch);
}
await closeFileDescriptor(readPath);
await closeFdWrite();
}
async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.audio.codecformat', 0, 100);
let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
console.info('[permission] case accessTokenID is ' + tokenID);
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName3, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
}
async function getFdWrite(pathName) {
console.info('[mediaLibrary] case start getFdWrite');
console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName);
......@@ -2243,19 +2215,11 @@ describe('AudioDecoderFormatCompatibilityPromise', function () {
}
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
async function closeFdWrite() {
if (fileAssetWrite != null) {
......
......@@ -15,11 +15,9 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import featureAbility from '@ohos.ability.featureAbility'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
import {getFileDescriptor, closeFileDescriptor} from './AudioFormatTestBase.test.js';
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('AudioEncoderFormatCompatibilityPromise', function () {
......@@ -55,7 +53,12 @@ describe('AudioEncoderFormatCompatibilityPromise', function () {
beforeAll(async function() {
console.info('beforeAll case 1');
await applyPermission();
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
permissionNameList = [permissionName1, permissionName2, permissionName3];
let appName = 'ohos.acts.multimedia.audio.codecformat';
await mediaTestBase.applyPermission(appName, permissionNameList);
console.info('beforeAll case after get permission');
})
......@@ -72,7 +75,6 @@ describe('AudioEncoderFormatCompatibilityPromise', function () {
audioEncodeProcessor = null;
}, failCallback).catch(failCatch);
}
await closeFileDescriptor(readPath);
await closeFdWrite();
})
......@@ -137,39 +139,9 @@ describe('AudioEncoderFormatCompatibilityPromise', function () {
audioEncodeProcessor = null;
}, failCallback).catch(failCatch);
}
await closeFileDescriptor(readPath);
await closeFdWrite();
}
async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.audio.codecformat', 0, 100);
let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
console.info('[permission] case accessTokenID is ' + tokenID);
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName3, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
}
async function getFdWrite(pathName) {
console.info('[mediaLibrary] case start getFdWrite');
console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName);
......@@ -193,16 +165,9 @@ describe('AudioEncoderFormatCompatibilityPromise', function () {
}
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
......
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import resourceManager from '@ohos.resourceManager';
export async function getFileDescriptor(fileName) {
let fileDescriptor = undefined;
await resourceManager.getResourceManager().then(async (mgr) => {
await mgr.getRawFileDescriptor(fileName).then(value => {
fileDescriptor = {fd: value.fd, offset: value.offset, length: value.length};
}).catch(error => {
console.log('case getRawFileDescriptor err: ' + error);
});
});
return fileDescriptor;
}
export async function closeFileDescriptor(fileName) {
await resourceManager.getResourceManager().then(async (mgr) => {
await mgr.closeRawFileDescriptor(fileName).then(value => {
console.log('case closeRawFileDescriptor success for file:' + fileName);
}).catch(error => {
console.log('case closeRawFileDescriptor err: ' + error);
});
});
}
......@@ -18,8 +18,8 @@
"type": "ShellKit",
"run-command": [
"rm -rf /storage/media/100/local/files/*",
"mkdir -p /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audiodecoder/ohos.acts.multimedia.audio.audiodecoder/assets/entry/resources/rawfile/",
"chmod 777 -R /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audiodecoder/ohos.acts.multimedia.audio.audiodecoder/assets/entry/resources/rawfile/"
"mkdir -p /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/"
],
"teardown-command":[
]
......@@ -29,18 +29,18 @@
"pre-push": [
],
"push": [
"./resource/audio/audioDecode/AAC_48000_32_1.aac ->/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audiodecoder/ohos.acts.multimedia.audio.audiodecoder/assets/entry/resources/rawfile/",
"./resource/audio/audioDecode/AAC_16000_1.aac ->/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audiodecoder/ohos.acts.multimedia.audio.audiodecoder/assets/entry/resources/rawfile/",
"./resource/audio/audioDecode/FLAC_48000_32_1.flac ->/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audiodecoder/ohos.acts.multimedia.audio.audiodecoder/assets/entry/resources/rawfile/",
"./resource/audio/audioDecode/mp3.es ->/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audiodecoder/ohos.acts.multimedia.audio.audiodecoder/assets/entry/resources/rawfile/",
"./resource/audio/audioDecode/vorbis.es ->/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audiodecoder/ohos.acts.multimedia.audio.audiodecoder/assets/entry/resources/rawfile/"
"./resource/audio/audioDecode/AAC_48000_32_1.aac ->/data/app/el2/100/base/ohos.acts.multimedia.audio.audiodecoder/haps/entry/files/",
"./resource/audio/audioDecode/AAC_16000_1.aac ->/data/app/el2/100/base/ohos.acts.multimedia.audio.audiodecoder/haps/entry/files/",
"./resource/audio/audioDecode/FLAC_48000_32_1.flac ->/data/app/el2/100/base/ohos.acts.multimedia.audio.audiodecoder/haps/entry/files/",
"./resource/audio/audioDecode/mp3.es ->/data/app/el2/100/base/ohos.acts.multimedia.audio.audiodecoder/haps/entry/files/",
"./resource/audio/audioDecode/vorbis.es ->/data/app/el2/100/base/ohos.acts.multimedia.audio.audiodecoder/haps/entry/files/"
]
},
{
"type": "ShellKit",
"run-command": [
"chmod 777 -R /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audiodecoder/ohos.acts.multimedia.audio.audiodecoder/assets/entry/resources/rawfile/",
"chmod 777 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audiodecoder/ohos.acts.multimedia.audio.audiodecoder/assets/entry/resources/rawfile/*",
"chmod 777 -R /data/app/el2/100/base/ohos.acts.multimedia.audio.audiodecoder/haps/entry/files/",
"chmod 777 /data/app/el2/100/base/ohos.acts.multimedia.audio.audiodecoder/haps/entry/files/*",
"chmod 777 -R /storage/media/100/local/files/",
"chmod 777 /storage/media/100/local/files/*",
"killall com.ohos.medialibrary.MediaScannerAbilityA",
......
......@@ -144,20 +144,5 @@ describe('AudioDecoderEnum', function () {
expect(media.AVCodecType.AVCODEC_TYPE_AUDIO_ENCODER).assertEqual(2);
expect(media.AVCodecType.AVCODEC_TYPE_AUDIO_DECODER).assertEqual(3);
done();
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_DECODER_ENUM_CodecMimeType_0100
* @tc.name : 004.CodecMimeType
* @tc.desc : Test Enumerate CodecMimeType
* @tc.size : MediumTest
* @tc.type : Function test
* @tc.level : Level0
*/
it('SUB_MEDIA_AUDIO_DECODER_ENUM_CodecMimeType_0100', 0, async function (done) {
expect(media.CodecMimeType.AUDIO_AAC).assertEqual('audio/mp4a-latm');
expect(media.CodecMimeType.AUDIO_VORBIS).assertEqual('audio/vorbis');
expect(media.CodecMimeType.AUDIO_FLAC).assertEqual('audio/flac');
done();
})
})
\ No newline at end of file
......@@ -15,15 +15,12 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import featureAbility from '@ohos.ability.featureAbility'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
import {getFileDescriptor, closeFileDescriptor} from './AudioDecoderTestBase.test.js';
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('AudioDecoderFormatCallback', function () {
const RESOURCEPATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder/'
const AUDIOPATH1 = 'AAC_48000_32_1.aac';
const AUDIOPATH2 = 'FLAC_48000_32_1.flac'
const AUDIOPATH3 = 'mp3.es';
......@@ -54,7 +51,12 @@ describe('AudioDecoderFormatCallback', function () {
beforeAll(async function() {
console.info('beforeAll case 1');
await applyPermission();
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
permissionNameList = [permissionName1, permissionName2, permissionName3];
let appName = 'ohos.acts.multimedia.audio.audiodecoder';
await mediaTestBase.applyPermission(appName, permissionNameList);
console.info('beforeAll case after get permission');
})
......@@ -84,56 +86,18 @@ describe('AudioDecoderFormatCallback', function () {
audioDecodeProcessor = null;
}, failCallback).catch(failCatch);
}
await closeFileDescriptor(readpath);
await closeFdWrite();
})
afterAll(function() {
afterAll(async function() {
console.info('afterAll case');
})
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.audio.audiodecoder', 0, 100);
let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
console.info('[permission] case accessTokenID is ' + tokenID);
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName3, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
}
async function getFdWrite(pathName) {
console.info('[mediaLibrary] case start getFdWrite');
console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName);
......@@ -152,7 +116,7 @@ describe('AudioDecoderFormatCallback', function () {
console.info('[mediaLibrary] case getFdWrite getFileAssets() success');
fileAsset = await fetchWriteFileResult.getAllObject();
console.info('[mediaLibrary] case getFdWrite getAllObject() success');
fdWrite = await fileAsset[0].open('Rw');
fdWrite = await fileAsset[0].open('rw');
console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite);
}
}
......@@ -169,7 +133,6 @@ describe('AudioDecoderFormatCallback', function () {
}
}
function writeFile(path, buf, len) {
try{
let res = fileio.writeSync(fdWrite, buf, {length: len});
......@@ -250,7 +213,6 @@ describe('AudioDecoderFormatCallback', function () {
expect(err).assertUndefined();
console.log("case release success");
audioDecodeProcessor = null;
await closeFileDescriptor(readpath);
await closeFdWrite();
done();
})
......
......@@ -15,11 +15,9 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import featureAbility from '@ohos.ability.featureAbility'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
import {getFileDescriptor, closeFileDescriptor} from './AudioDecoderTestBase.test.js';
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('AudioDecoderFormatPromise', function () {
......@@ -53,7 +51,12 @@ describe('AudioDecoderFormatPromise', function () {
beforeAll(async function() {
console.info('beforeAll case 1');
await applyPermission();
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
permissionNameList = [permissionName1, permissionName2, permissionName3];
let appName = 'ohos.acts.multimedia.audio.audiodecoder';
await mediaTestBase.applyPermission(appName, permissionNameList);
console.info('beforeAll case after get permission');
})
......@@ -83,11 +86,9 @@ describe('AudioDecoderFormatPromise', function () {
audioDecodeProcessor = null;
}, failCallback).catch(failCatch);
}
await closeFileDescriptor(readpath);
await closeFdWrite();
})
afterAll(function() {
afterAll(async function() {
console.info('afterAll case');
})
......@@ -101,48 +102,12 @@ describe('AudioDecoderFormatPromise', function () {
expect(err).assertUndefined();
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.audio.audiodecoder', 0, 100);
let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
console.info('[permission] case accessTokenID is ' + tokenID);
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName3, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
}
async function getFdWrite(pathName) {
console.info('[mediaLibrary] case start getFdWrite');
console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName);
......@@ -161,7 +126,7 @@ describe('AudioDecoderFormatPromise', function () {
console.info('[mediaLibrary] case getFdWrite getFileAssets() success');
fileAsset = await fetchWriteFileResult.getAllObject();
console.info('[mediaLibrary] case getFdWrite getAllObject() success');
fdWrite = await fileAsset[0].open('Rw');
fdWrite = await fileAsset[0].open('rw');
console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite);
}
}
......@@ -178,7 +143,6 @@ describe('AudioDecoderFormatPromise', function () {
}
}
function writeFile(path, buf, len) {
try{
let res = fileio.writeSync(fdWrite, buf, {length: len});
......@@ -259,7 +223,6 @@ describe('AudioDecoderFormatPromise', function () {
console.info('release success');
audioDecodeProcessor = null;
}, failCallback).catch(failCatch);
await closeFileDescriptor(readpath);
await closeFdWrite();
done();
}
......
......@@ -15,19 +15,16 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import featureAbility from '@ohos.ability.featureAbility'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
import {getFileDescriptor, closeFileDescriptor} from './AudioDecoderTestBase.test.js';
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('AudioDecoderFuncCallback', function () {
const RESOURCEPATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder/'
const AUDIOPATH = 'AAC_48000_32_1.aac';
const AUDIOPATH2 = 'AAC_16000_1.aac';
const AUDIOPATH3 = 'FLAC_48000_32_1.flac';
const BASIC_PATH = RESOURCEPATH + 'results/decode_func_callback_';
const BASIC_PATH = 'results/decode_func_callback_';
let audioDecodeProcessor;
let readStreamSync;
let eosframenum = 0;
......@@ -145,7 +142,12 @@ describe('AudioDecoderFuncCallback', function () {
beforeAll(async function() {
console.info('beforeAll case 1');
await applyPermission();
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
permissionNameList = [permissionName1, permissionName2, permissionName3];
let appName = 'ohos.acts.multimedia.audio.audiodecoder';
await mediaTestBase.applyPermission(appName, permissionNameList);
console.info('beforeAll case after get permission');
})
......@@ -267,11 +269,9 @@ describe('AudioDecoderFuncCallback', function () {
audioDecodeProcessor = null;
}, failCallback).catch(failCatch);
}
await closeFileDescriptor(readpath);
await closeFdWrite();
})
afterAll(function() {
afterAll(async function() {
console.info('afterAll case');
})
......@@ -293,49 +293,12 @@ describe('AudioDecoderFuncCallback', function () {
outputQueue = [];
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case pathName is : " + pathName);
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.audio.audiodecoder', 0, 100);
let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
console.info('[permission] case accessTokenID is ' + tokenID);
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName3, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
}
async function getFdWrite(pathName) {
console.info('[mediaLibrary] case start getFdWrite');
console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName);
......@@ -354,7 +317,7 @@ describe('AudioDecoderFuncCallback', function () {
console.info('[mediaLibrary] case getFdWrite getFileAssets() success');
fileAsset = await fetchWriteFileResult.getAllObject();
console.info('[mediaLibrary] case getFdWrite getAllObject() success');
fdWrite = await fileAsset[0].open('Rw');
fdWrite = await fileAsset[0].open('rw');
console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite);
}
}
......@@ -423,7 +386,6 @@ describe('AudioDecoderFuncCallback', function () {
async function flushWork(done) {
inputQueue = [];
outputQueue = [];
await closeFileDescriptor(readpath);
await getFdRead(readpath, done);
audioDecodeProcessor.flush((err) => {
expect(err).assertUndefined();
......@@ -446,7 +408,6 @@ describe('AudioDecoderFuncCallback', function () {
expect(err).assertUndefined();
console.log("case release success");
audioDecodeProcessor = null;
await closeFileDescriptor(readpath);
await closeFdWrite();
done();
})
......@@ -907,7 +868,6 @@ describe('AudioDecoderFuncCallback', function () {
expect(err).assertUndefined();
console.info(`case release 1`);
audioDecodeProcessor = null;
await closeFileDescriptor(readpath);
await closeFdWrite();
done();
})
......@@ -987,7 +947,6 @@ describe('AudioDecoderFuncCallback', function () {
eventEmitter.on('restart', () => {
sleep(2000).then(async() => {
resetParam();
await closeFileDescriptor(readpath);
await getFdRead(readpath, done);
readFile(readpath);
audioDecodeProcessor.start((err) => {
......@@ -1071,7 +1030,6 @@ describe('AudioDecoderFuncCallback', function () {
eventEmitter.on('reconfigure', (mediaDescription2) => {
sleep(10000).then(async() => {
resetParam();
await closeFileDescriptor(readpath);
await closeFdWrite();
audioDecodeProcessor.configure(mediaDescription2, async(err) => {
expect(err).assertUndefined();
......@@ -1178,7 +1136,6 @@ describe('AudioDecoderFuncCallback', function () {
});
eventEmitter.on('recreate', () => {
sleep(10000).then(async() => {
await closeFileDescriptor(readpath);
await closeFdWrite();
media.createAudioDecoderByMime('audio/flac', (err, processor) => {
expect(err).assertUndefined();
......
......@@ -15,19 +15,15 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import featureAbility from '@ohos.ability.featureAbility'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
import {getFileDescriptor, closeFileDescriptor} from './AudioDecoderTestBase.test.js';
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('AudioDecoderFuncPromise', function () {
const RESOURCEPATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder/'
const AUDIOPATH = 'AAC_48000_32_1.aac';
const AUDIOPATH2 = 'AAC_16000_1.aac';
const AUDIOPATH3 = 'FLAC_48000_32_1.flac';
const BASIC_PATH = 'results/decode_func_promise_';
let audioDecodeProcessor;
let readStreamSync;
let eosframenum = 0;
......@@ -145,7 +141,12 @@ describe('AudioDecoderFuncPromise', function () {
beforeAll(async function() {
console.info('beforeAll case 1');
await applyPermission();
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
permissionNameList = [permissionName1, permissionName2, permissionName3];
let appName = 'ohos.acts.multimedia.audio.audiodecoder';
await mediaTestBase.applyPermission(appName, permissionNameList);
console.info('beforeAll case after get permission');
})
......@@ -267,11 +268,9 @@ describe('AudioDecoderFuncPromise', function () {
audioDecodeProcessor = null;
}, failCallback).catch(failCatch);
}
await closeFileDescriptor(readpath);
await closeFdWrite();
})
afterAll(function() {
afterAll(async function() {
console.info('afterAll case');
})
......@@ -303,49 +302,12 @@ describe('AudioDecoderFuncPromise', function () {
outputQueue = [];
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case pathName is: " + pathName);
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.audio.audiodecoder', 0, 100);
let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
console.info('[permission] case accessTokenID is ' + tokenID);
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName3, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
}
async function getFdWrite(pathName) {
console.info('[mediaLibrary] case start getFdWrite');
console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName);
......@@ -364,7 +326,7 @@ describe('AudioDecoderFuncPromise', function () {
console.info('[mediaLibrary] case getFdWrite getFileAssets() success');
fileAsset = await fetchWriteFileResult.getAllObject();
console.info('[mediaLibrary] case getFdWrite getAllObject() success');
fdWrite = await fileAsset[0].open('Rw');
fdWrite = await fileAsset[0].open('rw');
console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite);
}
}
......@@ -427,7 +389,6 @@ describe('AudioDecoderFuncPromise', function () {
async function flushWork(done) {
inputQueue = [];
outputQueue = [];
await closeFileDescriptor(readpath);
await getFdRead(readpath, done);
await audioDecodeProcessor.flush().then(() => {
console.info("case flush at inputeos success");
......@@ -497,7 +458,6 @@ describe('AudioDecoderFuncPromise', function () {
await flushWork(done);
} else if (workdoneAtEOS) {
await doneWork();
await closeFileDescriptor(readpath);
await closeFdWrite();
done();
} else {
......@@ -785,7 +745,6 @@ describe('AudioDecoderFuncPromise', function () {
console.info("case release success");
}, failCallback).catch(failCatch);
audioDecodeProcessor = null;
await closeFileDescriptor(readpath);
await closeFdWrite();
done();
})
......@@ -839,7 +798,6 @@ describe('AudioDecoderFuncPromise', function () {
console.info("case restart decoding after 2s");
});
resetParam();
await closeFileDescriptor(readpath);
await getFdRead(readpath, done);
readFile(readpath);
await audioDecodeProcessor.start().then(() => {
......@@ -898,7 +856,6 @@ describe('AudioDecoderFuncPromise', function () {
console.info("case start configure 2");
});
resetParam();
await closeFileDescriptor(readpath);
await closeFdWrite();
await audioDecodeProcessor.configure(mediaDescription2).then(() => {
console.info("case configure 2 success");
......@@ -984,7 +941,6 @@ describe('AudioDecoderFuncPromise', function () {
await sleep(10000).then(() => {
console.info("start createaudiodecoder 2");
});
await closeFileDescriptor(readpath);
await closeFdWrite();
await media.createAudioDecoderByMime('audio/flac').then((processor) => {
console.info("case create createAudioDecoder flac success");
......
......@@ -14,11 +14,10 @@
*/
import media from '@ohos.multimedia.media'
import Fileio from '@ohos.fileio'
import fileio from '@ohos.fileio'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('AudioDecoderMultiInstances', function () {
const RESOURCEPATH = '/data/app/el1/bundle/resources/'
const AUDIOPATH = 'AAC_48000_32_1.aac';
let readStreamSync;
let eosframenum = 0;
......@@ -84,7 +83,7 @@ describe('AudioDecoderMultiInstances', function () {
function writeFile(path, buf, len) {
try{
let writestream = Fileio.createStreamSync(path, "ab+");
let writestream = fileio.createStreamSync(path, "ab+");
let num = writestream.writeSync(buf, {length:len});
writestream.flushSync();
writestream.closeSync();
......@@ -97,7 +96,7 @@ describe('AudioDecoderMultiInstances', function () {
console.info('read file start execution');
try{
console.info('filepath: ' + path);
readStreamSync = Fileio.createStreamSync(path, 'rb');
readStreamSync = fileio.createStreamSync(path, 'rb');
}catch(e) {
console.info(e);
}
......
......@@ -15,13 +15,12 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import {getFileDescriptor, closeFileDescriptor} from './AudioDecoderTestBase.test.js'
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('AudioDecoderReliabilityCallback', function () {
const RESOURCEPATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder/'
const AUDIOPATH = 'AAC_48000_32_1.aac';
const BASIC_PATH = RESOURCEPATH + 'results/decode_reliability_callback';
const BASIC_PATH = 'results/decode_reliability_callback';
const END = 0;
const CONFIGURE = 1;
const PREPARE = 2;
......@@ -268,12 +267,10 @@ describe('AudioDecoderReliabilityCallback', function () {
audioDecodeProcessor = null;
}, failCallback).catch(failCatch);
}
await closeFileDescriptor(AUDIOPATH);
})
afterAll(async function() {
console.info('afterAll case');
await closeFileDescriptor(AUDIOPATH);
})
function resetParam() {
......@@ -303,16 +300,9 @@ describe('AudioDecoderReliabilityCallback', function () {
})
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
......@@ -396,7 +386,6 @@ describe('AudioDecoderReliabilityCallback', function () {
console.info(`case to start`);
if (sawOutputEOS) {
resetParam();
await closeFileDescriptor(AUDIOPATH);
await getFdRead(AUDIOPATH, done);
readFile(AUDIOPATH);
workdoneAtEOS = true;
......@@ -418,7 +407,6 @@ describe('AudioDecoderReliabilityCallback', function () {
console.info(`case flush 1`);
if (flushAtEOS) {
resetParam();
await closeFileDescriptor(AUDIOPATH);
await getFdRead(AUDIOPATH, done);
readFile(AUDIOPATH);
workdoneAtEOS = true;
......
......@@ -15,13 +15,12 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import {getFileDescriptor, closeFileDescriptor} from './AudioDecoderTestBase.test.js'
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('AudioDecoderReliabilityPromise', function () {
const RESOURCEPATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder/'
const AUDIOPATH = 'AAC_48000_32_1.aac';
const BASIC_PATH = RESOURCEPATH + 'results/decode_reliability_promise';
const BASIC_PATH = 'results/decode_reliability_promise';
const END = 0;
const CONFIGURE = 1;
const PREPARE = 2;
......@@ -272,12 +271,10 @@ describe('AudioDecoderReliabilityPromise', function () {
audioDecodeProcessor = null;
}, failCallback).catch(failCatch);
}
await closeFileDescriptor(AUDIOPATH);
})
afterAll(async function() {
console.info('afterAll case');
await closeFileDescriptor(AUDIOPATH);
})
let failCallback = function(err) {
......@@ -324,16 +321,9 @@ describe('AudioDecoderReliabilityPromise', function () {
})
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
......@@ -408,7 +398,6 @@ describe('AudioDecoderReliabilityPromise', function () {
console.info(`case to start`);
if (sawOutputEOS) {
resetParam();
await closeFileDescriptor(AUDIOPATH);
await getFdRead(AUDIOPATH, done);
readFile(AUDIOPATH);
workdoneAtEOS = true;
......@@ -427,7 +416,6 @@ describe('AudioDecoderReliabilityPromise', function () {
audioDecodeProcessor.flush().then(async() => {
console.info(`case flush 1`);
if (flushAtEOS) {
await closeFileDescriptor(AUDIOPATH);
await getFdRead(AUDIOPATH, done);
resetParam();
readFile(AUDIOPATH);
......
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import resourceManager from '@ohos.resourceManager';
export async function getFileDescriptor(fileName) {
let fileDescriptor = undefined;
await resourceManager.getResourceManager().then(async (mgr) => {
await mgr.getRawFileDescriptor(fileName).then(value => {
fileDescriptor = {fd: value.fd, offset: value.offset, length: value.length};
}).catch(error => {
console.log('case getRawFileDescriptor err: ' + error);
});
});
return fileDescriptor;
}
export async function closeFileDescriptor(fileName) {
await resourceManager.getResourceManager().then(async (mgr) => {
await mgr.closeRawFileDescriptor(fileName).then(value => {
console.log('case closeRawFileDescriptor success for file:' + fileName);
}).catch(error => {
console.log('case closeRawFileDescriptor err: ' + error);
});
});
}
......@@ -13,7 +13,7 @@
* limitations under the License.
*/
require('./AudioDecoderTestBase.test.js')
require('./AudioDecoderFuncPromiseTest.test.js')
require('./AudioDecoderFuncCallbackTest.test.js')
require('./AudioDecoderFormatPromiseTest.test.js')
......
......@@ -18,8 +18,8 @@
"type": "ShellKit",
"run-command": [
"rm -rf /storage/media/100/local/files/*",
"mkdir -p /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioencoder/ohos.acts.multimedia.audio.audioencoder/assets/entry/resources/rawfile/",
"chmod 777 -R /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioencoder/ohos.acts.multimedia.audio.audioencoder/assets/entry/resources/rawfile/"
"mkdir -p /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/"
],
"teardown-command":[
]
......@@ -29,14 +29,14 @@
"pre-push": [
],
"push": [
"./resource/audio/audioEncode/S16LE.pcm ->/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioencoder/ohos.acts.multimedia.audio.audioencoder/assets/entry/resources/rawfile/"
"./resource/audio/audioEncode/S16LE.pcm ->/data/app/el2/100/base/ohos.acts.multimedia.audio.audioencoder/haps/entry/files/"
]
},
{
"type": "ShellKit",
"run-command": [
"chmod 777 -R /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioencoder/ohos.acts.multimedia.audio.audioencoder/assets/entry/resources/rawfile/",
"chmod 777 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioencoder/ohos.acts.multimedia.audio.audioencoder/assets/entry/resources/rawfile/*",
"chmod 777 -R /data/app/el2/100/base/ohos.acts.multimedia.audio.audioencoder/haps/entry/files/",
"chmod 777 /data/app/el2/100/base/ohos.acts.multimedia.audio.audioencoder/haps/entry/files/*",
"chmod 777 -R /storage/media/100/local/files/",
"chmod 777 /storage/media/100/local/files/*",
"killall com.ohos.medialibrary.MediaScannerAbilityA",
......
......@@ -15,17 +15,13 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import featureAbility from '@ohos.ability.featureAbility'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
import {getFileDescriptor, closeFileDescriptor} from './AudioEncoderTestBase.test.js';
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('AudioEncoderFuncCallback', function () {
const RESOURCEPATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audioencoder/'
const AUDIOPATH = 'S16LE.pcm';
const BASIC_PATH = RESOURCEPATH + 'results/encode_func_callback_';
let audioEncodeProcessor;
let readStreamSync;
let eosframenum = 0;
......@@ -54,7 +50,12 @@ describe('AudioEncoderFuncCallback', function () {
beforeAll(async function() {
console.info('beforeAll case 1');
await applyPermission();
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
permissionNameList = [permissionName1, permissionName2, permissionName3];
let appName = 'ohos.acts.multimedia.audio.audioencoder';
await mediaTestBase.applyPermission(appName, permissionNameList);
console.info('beforeAll case after get permission');
})
......@@ -86,13 +87,10 @@ describe('AudioEncoderFuncCallback', function () {
audioEncodeProcessor = null;
}, failCallback).catch(failCatch);
}
await closeFileDescriptor(AUDIOPATH);
await closeFdWrite();
})
afterAll(async function() {
console.info('afterAll case');
await closeFileDescriptor(AUDIOPATH);
})
function resetParam() {
......@@ -112,49 +110,12 @@ describe('AudioEncoderFuncCallback', function () {
outputQueue = [];
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case pathName is: " + pathName);
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.audio.audioencoder', 0, 100);
let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
console.info('[permission] case accessTokenID is ' + tokenID);
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName3, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
}
async function getFdWrite(pathName) {
console.info('[mediaLibrary] case start getFdWrite');
console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName);
......@@ -173,7 +134,7 @@ describe('AudioEncoderFuncCallback', function () {
console.info('[mediaLibrary] case getFdWrite getFileAssets() success');
fileAsset = await fetchWriteFileResult.getAllObject();
console.info('[mediaLibrary] case getFdWrite getAllObject() success');
fdWrite = await fileAsset[0].open('Rw');
fdWrite = await fileAsset[0].open('rw');
console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite);
}
}
......@@ -269,7 +230,6 @@ describe('AudioEncoderFuncCallback', function () {
async function flushWork(done) {
inputQueue = [];
outputQueue = [];
await closeFileDescriptor(readpath);
await getFdRead(readpath, done);
audioEncodeProcessor.flush((err) => {
expect(err).assertUndefined();
......@@ -291,7 +251,6 @@ describe('AudioEncoderFuncCallback', function () {
expect(err).assertUndefined();
console.log("case release success");
audioEncodeProcessor = null;
await closeFileDescriptor(AUDIOPATH);
await closeFdWrite();
done();
})
......@@ -739,7 +698,6 @@ describe('AudioEncoderFuncCallback', function () {
expect(err).assertUndefined();
console.info(`case release 1`);
audioEncodeProcessor = null;
await closeFileDescriptor(AUDIOPATH);
await closeFdWrite();
done();
})
......@@ -819,7 +777,6 @@ describe('AudioEncoderFuncCallback', function () {
eventEmitter.on('restart', () => {
sleep(2000).then(async() => {
resetParam();
await closeFileDescriptor(readpath);
await getFdRead(readpath, done);
readFile(readpath);
audioEncodeProcessor.start((err) => {
......@@ -903,7 +860,6 @@ describe('AudioEncoderFuncCallback', function () {
eventEmitter.on('reconfigure', (mediaDescription2) => {
sleep(10000).then(async() => {
resetParam();
await closeFileDescriptor(readpath);
await closeFdWrite();
audioEncodeProcessor.configure(mediaDescription2, async(err) => {
expect(err).assertUndefined();
......
......@@ -15,17 +15,13 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import featureAbility from '@ohos.ability.featureAbility'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
import {getFileDescriptor, closeFileDescriptor} from './AudioEncoderTestBase.test.js';
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('AudioEncoderFuncPromise_audio_1', function () {
const RESOURCEPATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audioencoder/'
describe('AudioEncoderFuncPromise', function () {
const AUDIOPATH = 'S16LE.pcm';
const BASIC_PATH = RESOURCEPATH + 'results/encode_func_promise_';
let audioEncodeProcessor;
let readStreamSync;
let eosframenum = 0;
......@@ -54,7 +50,12 @@ describe('AudioEncoderFuncPromise_audio_1', function () {
beforeAll(async function() {
console.info('beforeAll case 1');
await applyPermission();
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
permissionNameList = [permissionName1, permissionName2, permissionName3];
let appName = 'ohos.acts.multimedia.audio.audioencoder';
await mediaTestBase.applyPermission(appName, permissionNameList);
console.info('beforeAll case after get permission');
})
......@@ -86,13 +87,10 @@ describe('AudioEncoderFuncPromise_audio_1', function () {
audioEncodeProcessor = null;
}, failCallback).catch(failCatch);
}
await closeFileDescriptor(AUDIOPATH);
await closeFdWrite();
})
afterAll(async function() {
console.info('afterAll case');
await closeFileDescriptor(AUDIOPATH);
})
let failCallback = function(err) {
......@@ -122,49 +120,12 @@ describe('AudioEncoderFuncPromise_audio_1', function () {
outputQueue = [];
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case pathName is: " + pathName);
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.audio.audioencoder', 0, 100);
let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
console.info('[permission] case accessTokenID is ' + tokenID);
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName3, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
}
async function getFdWrite(pathName) {
console.info('[mediaLibrary] case start getFdWrite');
console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName);
......@@ -183,7 +144,7 @@ describe('AudioEncoderFuncPromise_audio_1', function () {
console.info('[mediaLibrary] case getFdWrite getFileAssets() success');
fileAsset = await fetchWriteFileResult.getAllObject();
console.info('[mediaLibrary] case getFdWrite getAllObject() success');
fdWrite = await fileAsset[0].open('Rw');
fdWrite = await fileAsset[0].open('rw');
console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite);
}
}
......@@ -275,7 +236,6 @@ describe('AudioEncoderFuncPromise_audio_1', function () {
async function flushWork(done) {
inputQueue = [];
outputQueue = [];
await closeFileDescriptor(readpath);
await getFdRead(readpath, done);
await audioEncodeProcessor.flush().then(() => {
console.info("case flush at inputeos success");
......@@ -346,7 +306,6 @@ describe('AudioEncoderFuncPromise_audio_1', function () {
await flushWork(done);
} else if (workdoneAtEOS) {
await doneWork();
await closeFileDescriptor(AUDIOPATH);
await closeFdWrite();
done();
} else {
......@@ -640,7 +599,6 @@ describe('AudioEncoderFuncPromise_audio_1', function () {
console.info("case release success");
}, failCallback).catch(failCatch);
audioEncodeProcessor = null;
await closeFileDescriptor(AUDIOPATH);
await closeFdWrite();
done();
})
......@@ -694,7 +652,6 @@ describe('AudioEncoderFuncPromise_audio_1', function () {
console.info("restart encoding after 2s");
});
resetParam();
await closeFileDescriptor(readpath);
await getFdRead(readpath, done);
readFile(readpath);
await audioEncodeProcessor.start().then(() => {
......@@ -753,7 +710,6 @@ describe('AudioEncoderFuncPromise_audio_1', function () {
console.info("start configure 2");
});
resetParam();
await closeFileDescriptor(readpath);
await closeFdWrite();
await audioEncodeProcessor.configure(mediaDescription2).then(() => {
console.info("configure 2 success");
......
......@@ -15,13 +15,12 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import {getFileDescriptor, closeFileDescriptor} from './AudioEncoderTestBase.test.js';
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('AudioEncoderReliabilityCallback', function () {
const RESOURCEPATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audioencoder/'
const AUDIOPATH = 'S16LE.pcm';
const BASIC_PATH = RESOURCEPATH + 'results/encode_reliability_callback_';
const BASIC_PATH = 'results/encode_reliability_callback_';
const END = 0;
const CONFIGURE = 1;
const PREPARE = 2;
......@@ -91,12 +90,10 @@ describe('AudioEncoderReliabilityCallback', function () {
}, failCallback).catch(failCatch);
audioEncodeProcessor = null;
}
await closeFileDescriptor(AUDIOPATH);
})
afterAll(async function() {
console.info('afterAll case');
await closeFileDescriptor(AUDIOPATH);
})
function resetParam() {
......@@ -126,16 +123,9 @@ describe('AudioEncoderReliabilityCallback', function () {
})
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
......@@ -217,7 +207,6 @@ describe('AudioEncoderReliabilityCallback', function () {
console.info(`case to start`);
if (sawOutputEOS) {
resetParam();
await closeFileDescriptor(AUDIOPATH);
await getFdRead(AUDIOPATH, done);
readFile(AUDIOPATH);
workdoneAtEOS = true;
......@@ -238,7 +227,6 @@ describe('AudioEncoderReliabilityCallback', function () {
expect(err).assertUndefined();
console.info(`case flush 1`);
if (flushAtEOS) {
await closeFileDescriptor(AUDIOPATH);
await getFdRead(AUDIOPATH, done);
resetParam();
readFile(AUDIOPATH);
......
......@@ -15,13 +15,12 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import {getFileDescriptor, closeFileDescriptor} from './AudioEncoderTestBase.test.js';
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('AudioEncoderReliabilityPromise', function () {
const RESOURCEPATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audioencoder/'
const AUDIOPATH = 'S16LE.pcm';
const BASIC_PATH = RESOURCEPATH + 'results/encode_reliability_promise_';
const BASIC_PATH = 'results/encode_reliability_promise_';
const END = 0;
const CONFIGURE = 1;
const PREPARE = 2;
......@@ -93,12 +92,10 @@ describe('AudioEncoderReliabilityPromise', function () {
}, failCallback).catch(failCatch);
audioEncodeProcessor = null;
}
await closeFileDescriptor(AUDIOPATH);
})
afterAll(async function() {
console.info('afterAll case');
await closeFileDescriptor(AUDIOPATH);
})
let failCallback = function(err) {
......@@ -143,19 +140,12 @@ describe('AudioEncoderReliabilityPromise', function () {
}, failCallback).catch(failCatch);
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
function readFile(path) {
console.info('read file start execution');
try{
......@@ -227,7 +217,6 @@ describe('AudioEncoderReliabilityPromise', function () {
console.info(`case to start`);
if (sawOutputEOS) {
resetParam();
await closeFileDescriptor(AUDIOPATH);
await getFdRead(AUDIOPATH, done);
readFile(AUDIOPATH);
workdoneAtEOS = true;
......@@ -246,7 +235,6 @@ describe('AudioEncoderReliabilityPromise', function () {
audioEncodeProcessor.flush().then(async() => {
console.info(`case flush 1`);
if (flushAtEOS) {
await closeFileDescriptor(AUDIOPATH);
await getFdRead(AUDIOPATH, done);
resetParam();
readFile(AUDIOPATH);
......
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import resourceManager from '@ohos.resourceManager';
export async function getFileDescriptor(fileName) {
let fileDescriptor;
await resourceManager.getResourceManager().then(async (mgr) => {
await mgr.getRawFileDescriptor(fileName).then(value => {
fileDescriptor = {fd: value.fd, offset: value.offset, length: value.length};
}).catch(error => {
console.log('case getRawFileDescriptor err: ' + error);
});
});
return fileDescriptor;
}
export async function closeFileDescriptor(fileName) {
await resourceManager.getResourceManager().then(async (mgr) => {
await mgr.closeRawFileDescriptor(fileName).then(value => {
console.log('case closeRawFileDescriptor success for fileName:' + fileName);
}).catch(error => {
console.log('case closeRawFileDescriptor err: ' + error);
});
});
}
......@@ -13,7 +13,6 @@
* limitations under the License.
*/
require('./AudioEncoderTestBase.test.js')
require('./AudioEncoderFuncCallbackTest.test.js')
require('./AudioEncoderFuncPromiseTest.test.js')
require('./AudioEncoderReliabilityCallbackTest.test.js')
......
......@@ -66,4 +66,19 @@ describe('AudioRecorderEnumTest', function () {
expect(media.AudioEncoder.HE_AAC).assertEqual(4);
done();
})
/* *
* @tc.number : SUB_MEDIA_AUDIO_DECODER_ENUM_CodecMimeType_0100
* @tc.name : CodecMimeType
* @tc.desc : Test Enumerate CodecMimeType
* @tc.size : MediumTest
* @tc.type : Function test
* @tc.level : Level0
*/
it('SUB_MEDIA_AUDIO_DECODER_ENUM_CodecMimeType_0100', 0, async function (done) {
expect(media.CodecMimeType.AUDIO_AAC).assertEqual('audio/mp4a-latm');
expect(media.CodecMimeType.AUDIO_VORBIS).assertEqual('audio/vorbis');
expect(media.CodecMimeType.AUDIO_FLAC).assertEqual('audio/flac');
done();
})
})
\ No newline at end of file
......@@ -18,8 +18,8 @@
"type": "ShellKit",
"run-command": [
"rm -rf /storage/media/100/local/files/*",
"mkdir -p /data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/",
"chmod 777 -R /data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/"
"mkdir -p /data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/",
"chmod 777 -R /data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/"
],
"teardown-command":[
]
......@@ -29,24 +29,24 @@
"pre-push": [
],
"push": [
"./resource/media/es/H264_BP_720_480_10_3000000.h264 ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/",
"./resource/media/es/H264_BP_720_480_30_768000.h264 ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/",
"./resource/media/es/H264_BP_720_480_30_2000000.h264 ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/",
"./resource/media/es/H264_HP_352_288_30_3000000.h264 ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/",
"./resource/media/es/H264_HP_640_480_30_3000000.h264 ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/",
"./resource/media/es/H264_HP_720_480_25_3000000.h264 ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/",
"./resource/media/es/H264_HP_720_480_30_3000000.h264 ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/",
"./resource/media/es/H264_MP_720_480_30_64000.h264 ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/",
"./resource/media/es/H264_MP_720_480_30_128000.h264 ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/",
"./resource/media/es/H264_MP_720_480_30_192000.h264 ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/",
"./resource/media/es/H264_MP_720_480_30_384000.h264 ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/"
"./resource/media/es/H264_BP_720_480_10_3000000.h264 ->/data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/",
"./resource/media/es/H264_BP_720_480_30_768000.h264 ->/data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/",
"./resource/media/es/H264_BP_720_480_30_2000000.h264 ->/data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/",
"./resource/media/es/H264_HP_352_288_30_3000000.h264 ->/data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/",
"./resource/media/es/H264_HP_640_480_30_3000000.h264 ->/data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/",
"./resource/media/es/H264_HP_720_480_25_3000000.h264 ->/data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/",
"./resource/media/es/H264_HP_720_480_30_3000000.h264 ->/data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/",
"./resource/media/es/H264_MP_720_480_30_64000.h264 ->/data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/",
"./resource/media/es/H264_MP_720_480_30_128000.h264 ->/data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/",
"./resource/media/es/H264_MP_720_480_30_192000.h264 ->/data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/",
"./resource/media/es/H264_MP_720_480_30_384000.h264 ->/data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/"
]
},
{
"type": "ShellKit",
"run-command": [
"chmod 777 -R /data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/",
"chmod 777 /data/app/el1/bundle/public/ohos.acts.multimedia.video.codecformat/ohos.acts.multimedia.video.codecformat/assets/entry/resources/rawfile/*"
"chmod 777 -R /data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/",
"chmod 777 /data/app/el2/100/base/ohos.acts.multimedia.video.codecformat/haps/entry/files/*"
],
"teardown-command":[
]
......
......@@ -16,7 +16,7 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import router from '@system.router'
import {getFileDescriptor, closeFileDescriptor} from './VideoFormatTestBase.test.js'
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
......@@ -261,7 +261,6 @@ describe('VideoDecoderFormatPromise', function () {
}, failCallback).catch(failCatch);
videoDecodeProcessor = null;
}
await closeFileDescriptor(readPath);
await router.clear();
})
......@@ -294,16 +293,9 @@ describe('VideoDecoderFormatPromise', function () {
}
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
......
......@@ -16,8 +16,6 @@
import media from '@ohos.multimedia.media'
import mediademo from '@ohos.multimedia.mediademo'
import fileio from '@ohos.fileio'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
import featureAbility from '@ohos.ability.featureAbility'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
......@@ -42,7 +40,12 @@ describe('VideoEncoderFormatPromise', function () {
beforeAll(async function() {
console.info('beforeAll case 1');
await applyPermission();
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
permissionNameList = [permissionName1, permissionName2, permissionName3];
let appName = 'ohos.acts.multimedia.video.codecformat';
await mediaTestBase.applyPermission(appName, permissionNameList);
console.info('beforeAll case after get permission');
})
......@@ -97,35 +100,6 @@ describe('VideoEncoderFormatPromise', function () {
needGetMediaDes = false;
}
async function applyPermission() {
let appInfo = await bundle.getApplicationInfo('ohos.acts.multimedia.video.codecformat', 0, 100);
let atManager = abilityAccessCtrl.createAtManager();
if (atManager != null) {
let tokenID = appInfo.accessTokenId;
console.info('[permission] case accessTokenID is ' + tokenID);
let permissionName1 = 'ohos.permission.MEDIA_LOCATION';
let permissionName2 = 'ohos.permission.READ_MEDIA';
let permissionName3 = 'ohos.permission.WRITE_MEDIA';
await atManager.grantUserGrantedPermission(tokenID, permissionName1, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName2, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
await atManager.grantUserGrantedPermission(tokenID, permissionName3, 1).then((result) => {
console.info('[permission] case grantUserGrantedPermission success :' + result);
}).catch((err) => {
console.info('[permission] case grantUserGrantedPermission failed :' + err);
});
} else {
console.info('[permission] case apply permission failed, createAtManager failed');
}
}
async function getFdWrite(pathName) {
console.info('[mediaLibrary] case start getFdWrite');
console.info('[mediaLibrary] case getFdWrite pathName is ' + pathName);
......
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import resourceManager from '@ohos.resourceManager';
export async function getFileDescriptor(fileName) {
let fileDescriptor;
await resourceManager.getResourceManager().then(async (mgr) => {
await mgr.getRawFileDescriptor(fileName).then(value => {
fileDescriptor = {fd: value.fd, offset: value.offset, length: value.length};
}).catch(error => {
console.log('case getRawFileDescriptor err: ' + error);
});
});
return fileDescriptor;
}
export async function closeFileDescriptor(fileName) {
await resourceManager.getResourceManager().then(async (mgr) => {
await mgr.closeRawFileDescriptor(fileName).then(value => {
console.log('case closeRawFileDescriptor success for fileName: ' + fileName);
}).catch(error => {
console.log('case closeRawFileDescriptor err: ' + error);
});
});
}
......@@ -18,8 +18,8 @@
"type": "ShellKit",
"run-command": [
"rm -rf /storage/media/100/local/files/*",
"mkdir -p /data/app/el1/bundle/public/ohos.acts.multimedia.video.videodecoder/ohos.acts.multimedia.video.videodecoder/assets/entry/resources/rawfile/",
"chmod 777 -R /data/app/el1/bundle/public/ohos.acts.multimedia.video.videodecoder/ohos.acts.multimedia.video.videodecoder/assets/entry/resources/rawfile/"
"mkdir -p /data/app/el2/100/base/ohos.acts.multimedia.video.videodecoder/haps/entry/files/",
"chmod 777 -R /data/app/el2/100/base/ohos.acts.multimedia.video.videodecoder/haps/entry/files/"
],
"teardown-command":[
]
......@@ -29,18 +29,18 @@
"pre-push": [
],
"push": [
"./resource/media/es/out_1920_1080_30fps_3s.h264 ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.videodecoder/ohos.acts.multimedia.video.videodecoder/assets/entry/resources/rawfile/",
"./resource/media/es/h263_1408_1152.es ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.videodecoder/ohos.acts.multimedia.video.videodecoder/assets/entry/resources/rawfile/",
"./resource/media/es/MPEG2_720_480.es ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.videodecoder/ohos.acts.multimedia.video.videodecoder/assets/entry/resources/rawfile/",
"./resource/media/es/mpeg4_320_240.es ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.videodecoder/ohos.acts.multimedia.video.videodecoder/assets/entry/resources/rawfile/",
"./resource/media/es/out_320_240_10s.h264 ->/data/app/el1/bundle/public/ohos.acts.multimedia.video.videodecoder/ohos.acts.multimedia.video.videodecoder/assets/entry/resources/rawfile/"
"./resource/media/es/out_1920_1080_30fps_3s.h264 ->/data/app/el2/100/base/ohos.acts.multimedia.video.videodecoder/haps/entry/files/",
"./resource/media/es/h263_1408_1152.es ->/data/app/el2/100/base/ohos.acts.multimedia.video.videodecoder/haps/entry/files/",
"./resource/media/es/MPEG2_720_480.es ->/data/app/el2/100/base/ohos.acts.multimedia.video.videodecoder/haps/entry/files/",
"./resource/media/es/mpeg4_320_240.es ->/data/app/el2/100/base/ohos.acts.multimedia.video.videodecoder/haps/entry/files/",
"./resource/media/es/out_320_240_10s.h264 ->/data/app/el2/100/base/ohos.acts.multimedia.video.videodecoder/haps/entry/files/"
]
},
{
"type": "ShellKit",
"run-command": [
"chmod 777 -R /data/app/el1/bundle/public/ohos.acts.multimedia.video.videodecoder/ohos.acts.multimedia.video.videodecoder/assets/entry/resources/rawfile/",
"chmod 777 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videodecoder/ohos.acts.multimedia.video.videodecoder/assets/entry/resources/rawfile/*"
"chmod 777 -R /data/app/el2/100/base/ohos.acts.multimedia.video.videodecoder/haps/entry/files/",
"chmod 777 /data/app/el2/100/base/ohos.acts.multimedia.video.videodecoder/haps/entry/files/*"
],
"teardown-command":[
]
......
......@@ -21,5 +21,4 @@ require('./VideoDecoderSoftwareFuncCallbackTest.test.js')
require('./VideoDecoderSoftwareFuncPromiseTest.test.js')
require('./VideoDecoderSoftwareReliCallbackTest.test.js')
require('./VideoDecoderSoftwareReliPromiseTest.test.js')
require('./VideoDecoderEnumTest.test.js')
require('./VideoDecoderTestBase.test.js')
require('./VideoDecoderEnumTest.test.js')
\ No newline at end of file
......@@ -16,7 +16,7 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import router from '@system.router'
import {getFileDescriptor, closeFileDescriptor} from './VideoDecoderTestBase.test.js'
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
......@@ -34,7 +34,6 @@ describe('VideoDecoderEnum', function () {
let surfaceID = '';
const events = require('events');
const eventEmitter = new events.EventEmitter();
const BASIC_PATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder/';
let ES_FRAME_SIZE = [];
const H264_FRAME_SIZE_60FPS_320 =
[ 2106, 11465];
......@@ -43,7 +42,6 @@ describe('VideoDecoderEnum', function () {
beforeAll(function() {
console.info('beforeAll case');
// getSurfaceID();
})
beforeEach(async function() {
......@@ -289,7 +287,6 @@ describe('VideoDecoderEnum', function () {
}, failCallback).catch(failCatch);
videoDecodeProcessor = null;
console.info('in case : done');
await closeFileDescriptor(readpath);
done();
});
async function toPrepare() {
......@@ -316,15 +313,8 @@ describe('VideoDecoderEnum', function () {
isCodecData = true;
let srcPath = 'out_320_240_10s.h264';
readpath = srcPath;
await getFileDescriptor(readpath).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
await mediaTestBase.getFdRead(readpath, done).then((fdNumber) => {
fdRead = fdNumber;
})
let mediaDescription = {
'track_type': 1,
......@@ -345,22 +335,5 @@ describe('VideoDecoderEnum', function () {
await toPrepare();
await toStart();
})
/* *
* @tc.number : SUB_MEDIA_VIDEO_DECODER_ENUM_CodecMimeType_0100
* @tc.name : 002.CodecMimeType
* @tc.desc : Test Enumerate CodecMimeType
* @tc.size : MediumTest
* @tc.type : Function test
* @tc.level : Level0
*/
it('SUB_MEDIA_VIDEO_DECODER_ENUM_CodecMimeType_0100', 0, async function (done) {
expect(media.CodecMimeType.VIDEO_H263).assertEqual('video/h263');
expect(media.CodecMimeType.VIDEO_AVC).assertEqual('video/avc');
expect(media.CodecMimeType.VIDEO_MPEG2).assertEqual('video/mpeg2');
expect(media.CodecMimeType.VIDEO_MPEG4).assertEqual('video/mp4v-es');
expect(media.CodecMimeType.VIDEO_VP8).assertEqual('video/x-vnd.on2.vp8');
done();
})
})
......@@ -16,10 +16,10 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import router from '@system.router'
import {getFileDescriptor, closeFileDescriptor} from './VideoDecoderTestBase.test.js'
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('VideoDecoderFuncCallbackTest_video1', function () {
describe('VideoDecoderFuncCallbackTest', function () {
let videoDecodeProcessor = null;
let readStreamSync = undefined;
let frameCountIn = 0;
......@@ -157,16 +157,9 @@ describe('VideoDecoderFuncCallbackTest_video1', function () {
}
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
......@@ -345,7 +338,6 @@ describe('VideoDecoderFuncCallbackTest_video1', function () {
expect(err).assertUndefined();
console.info('in case : release success');
videoDecodeProcessor = null;
await closeFileDescriptor(readpath);
done();
});
});
......
......@@ -16,11 +16,11 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import router from '@system.router'
import {getFileDescriptor, closeFileDescriptor} from './VideoDecoderTestBase.test.js'
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('VideoDecoderFuncPromiseTest_video1', function () {
describe('VideoDecoderFuncPromiseTest', function () {
let videoDecodeProcessor = null;
let readStreamSync = undefined;
let frameCountIn = 0;
......@@ -33,7 +33,6 @@ describe('VideoDecoderFuncPromiseTest_video1', function () {
let surfaceID = '';
const events = require('events');
const eventEmitter = new events.EventEmitter();
const BASIC_PATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder/';
let ES_FRAME_SIZE = [];
const H264_FRAME_SIZE_60FPS_320 =
[ 2106, 11465, 321, 72, 472, 68, 76, 79, 509, 90, 677, 88, 956, 99, 347, 77, 452, 681, 81, 1263, 94, 106, 97,
......@@ -98,7 +97,6 @@ describe('VideoDecoderFuncPromiseTest_video1', function () {
beforeAll(function() {
console.info('beforeAll case');
// getSurfaceID();
})
beforeEach(async function() {
......@@ -156,16 +154,9 @@ describe('VideoDecoderFuncPromiseTest_video1', function () {
}
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
......@@ -317,7 +308,6 @@ describe('VideoDecoderFuncPromiseTest_video1', function () {
console.info('in case : release success');
}, failCallback).catch(failCatch);
videoDecodeProcessor = null;
await closeFileDescriptor(readpath);
console.info('in case : done');
done();
});
......@@ -466,7 +456,6 @@ describe('VideoDecoderFuncPromiseTest_video1', function () {
console.info('in case : release success');
}, failCallback).catch(failCatch);
videoDecodeProcessor = null;
await closeFileDescriptor(readpath);
done();
})
for (let i = 0; i < 3; i++) {
......
......@@ -16,7 +16,7 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import router from '@system.router'
import {getFileDescriptor, closeFileDescriptor} from './VideoDecoderTestBase.test.js'
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
const DECODE_STEP = {
......@@ -47,7 +47,6 @@ describe('VideoDecoderReliCallbackTest', function () {
let inputEosFlag = false;
let workdoneAtEOS = false;
let surfaceID = '';
const BASIC_PATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder/';
const SRCPATH = 'out_320_240_10s.h264';
let mediaDescription = {
'track_type': 1,
......@@ -110,12 +109,10 @@ describe('VideoDecoderReliCallbackTest', function () {
}
await router.clear().then(() => {
}, failCallback).catch(failCatch);
await closeFileDescriptor(SRCPATH);
})
afterAll(async function() {
console.info('afterAll case');
await closeFileDescriptor(SRCPATH);
})
let failCallback = function(err) {
console.info(`in case error failCallback called, errMessage is ${err.message}`);
......@@ -289,7 +286,6 @@ describe('VideoDecoderReliCallbackTest', function () {
printError(err, false);
console.info('in case : videoDecodeProcessor release callback');
videoDecodeProcessor = null;
await closeFileDescriptor(SRCPATH);
console.info('case to done');
done();
});
......@@ -416,17 +412,10 @@ describe('VideoDecoderReliCallbackTest', function () {
}
async function toCreateVideoDecoderByMime(mime, mySteps, done) {
await getFileDescriptor(SRCPATH).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
await mediaTestBase.getFdRead(SRCPATH, done).then((fdNumber) => {
fdRead = fdNumber;
})
media.createVideoDecoderByMime(mime, (err, processor) => {
await media.createVideoDecoderByMime(mime, (err, processor) => {
console.info(`case createVideoDecoderByMime callback`);
printError(err, false);
videoDecodeProcessor = processor;
......
......@@ -16,7 +16,7 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import router from '@system.router'
import {getFileDescriptor, closeFileDescriptor} from './VideoDecoderTestBase.test.js'
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
const DECODE_STEP = {
......@@ -47,7 +47,6 @@ describe('VideoDecoderReliPromiseTest', function () {
let inputEosFlag = false;
let workdoneAtEOS = false;
let surfaceID = '';
const BASIC_PATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder/';
const SRCPATH = 'out_320_240_10s.h264';
let mediaDescription = {
'track_type': 1,
......@@ -110,12 +109,10 @@ describe('VideoDecoderReliPromiseTest', function () {
}
await router.clear().then(() => {
}, failCallback).catch(failCatch);
await closeFileDescriptor(SRCPATH);
})
afterAll(async function() {
console.info('afterAll case');
await closeFileDescriptor(SRCPATH);
})
let caseCallback = function(err) {
console.info(`in case caseCallback called, caseMessage is ${err.message}`);
......@@ -286,7 +283,6 @@ describe('VideoDecoderReliPromiseTest', function () {
videoDecodeProcessor.release().then(async() => {
console.info('in case : videoDecodeProcessor release success');
videoDecodeProcessor = null;
await closeFileDescriptor(SRCPATH);
console.info('case to done');
done();
}, failCallback).catch(failCatch);
......@@ -375,11 +371,14 @@ describe('VideoDecoderReliPromiseTest', function () {
break;
case DECODE_STEP.WAIT_FOR_EOS:
mySteps.shift();
setTimeout(() =>{
setTimeout(async() =>{
expect(inputEosFlag).assertTrue();
if (inputEosFlag == false) {
console.info(`in case error inputEosFlag == false`);
}
await mediaTestBase.getFdRead(SRCPATH, done).then((fdNumber) => {
fdRead = fdNumber;
})
toNextStep(mySteps, done);
}, 7000); // wait 7000 ms for eos
break;
......@@ -413,17 +412,10 @@ describe('VideoDecoderReliPromiseTest', function () {
}
async function toCreateVideoDecoderByMime(mime, mySteps, done) {
await getFileDescriptor(SRCPATH).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
await mediaTestBase.getFdRead(SRCPATH, done).then((fdNumber) => {
fdRead = fdNumber;
})
media.createVideoDecoderByMime(mime).then((processor) => {
await media.createVideoDecoderByMime(mime).then((processor) => {
console.info(`case createVideoDecoderByMime success`);
videoDecodeProcessor = processor;
setCallback(done);
......
......@@ -16,7 +16,7 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import router from '@system.router'
import {getFileDescriptor, closeFileDescriptor} from './VideoDecoderTestBase.test.js'
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
describe('VideoDecoderFuncCallbackTest', function () {
......@@ -32,7 +32,6 @@ describe('VideoDecoderFuncCallbackTest', function () {
let surfaceID = '';
const events = require('events');
const eventEmitter = new events.EventEmitter();
const BASIC_PATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder/';
let ES_FRAME_SIZE = [];
const H264_FRAME_SIZE_240 =
[ 2106, 11465, 321, 72, 472, 68, 76, 79, 509, 90, 677, 88, 956, 99, 347, 77, 452, 681, 81, 1263, 94, 106, 97,
......@@ -141,7 +140,6 @@ describe('VideoDecoderFuncCallbackTest', function () {
}
await router.clear().then(() => {
}, failCallback).catch(failCatch);
await closeFileDescriptor(readpath);
})
afterAll(function() {
......@@ -171,16 +169,9 @@ describe('VideoDecoderFuncCallbackTest', function () {
}
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
......@@ -320,7 +311,6 @@ describe('VideoDecoderFuncCallbackTest', function () {
expect(err).assertUndefined();
console.info('in case : release success');
videoDecodeProcessor = null;
await closeFileDescriptor(readpath);
done();
});
});
......@@ -467,7 +457,6 @@ describe('VideoDecoderFuncCallbackTest', function () {
isCodecData = true;
inputEosFlag = false;
readStreamSync = null;
await closeFileDescriptor(readpath);
await getFdRead(readpath, done);
await toDisplayPage().then(() => {
}, failCallback).catch(failCatch);
......@@ -518,7 +507,6 @@ describe('VideoDecoderFuncCallbackTest', function () {
videoDecodeProcessor.stop(async(err) => {
expect(err).assertUndefined();
console.info('in case : stop_for_callback_01_0700 success');
await closeFileDescriptor(readpath);
eventEmitter.emit('reset_for_callback_01_0700', done);
});
});
......
......@@ -16,7 +16,7 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import router from '@system.router'
import {getFileDescriptor, closeFileDescriptor} from './VideoDecoderTestBase.test.js'
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
......@@ -33,7 +33,6 @@ describe('VideoDecoderFuncPromiseTest', function () {
let surfaceID = '';
const events = require('events');
const eventEmitter = new events.EventEmitter();
const BASIC_PATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder/';
let ES_FRAME_SIZE = [];
const H264_FRAME_SIZE_240 =
[ 2106, 11465, 321, 72, 472, 68, 76, 79, 509, 90, 677, 88, 956, 99, 347, 77, 452, 681, 81, 1263, 94, 106, 97,
......@@ -142,7 +141,6 @@ describe('VideoDecoderFuncPromiseTest', function () {
}
await router.clear().then(() => {
}, failCallback).catch(failCatch);
await closeFileDescriptor(readpath);
})
afterAll(function() {
......@@ -172,19 +170,12 @@ describe('VideoDecoderFuncPromiseTest', function () {
}
}
async function getFdRead(pathName, done) {
await getFileDescriptor(pathName).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
async function getFdRead(readPath, done) {
await mediaTestBase.getFdRead(readPath, done).then((fdNumber) => {
fdRead = fdNumber;
})
}
function readFile(path) {
console.info('case read file start execution');
try{
......@@ -311,7 +302,6 @@ describe('VideoDecoderFuncPromiseTest', function () {
console.info('in case : release success');
}, failCallback).catch(failCatch);
videoDecodeProcessor = null;
await closeFileDescriptor(readpath);
console.info('in case : done');
done();
});
......@@ -465,7 +455,6 @@ describe('VideoDecoderFuncPromiseTest', function () {
isCodecData = true;
inputEosFlag = false;
readStreamSync = null;
await closeFileDescriptor(readpath);
await getFdRead(readpath, done);
await toDisplayPage().then(() => {
}, failCallback).catch(failCatch);
......@@ -528,7 +517,6 @@ describe('VideoDecoderFuncPromiseTest', function () {
await videoDecodeProcessor.stop().then(() => {
console.info('in case : stop success');
}, failCallback).catch(failCatch);
await closeFileDescriptor(readpath);
await videoDecodeProcessor.reset().then(() => {
console.info('in case : reset success');
}, failCallback).catch(failCatch);
......
......@@ -16,7 +16,7 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import router from '@system.router'
import {getFileDescriptor, closeFileDescriptor} from './VideoDecoderTestBase.test.js'
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
const DECODE_STEP = {
......@@ -47,7 +47,6 @@ describe('VideoDecoderSoftwareReliCallbackTest', function () {
let inputEosFlag = false;
let workdoneAtEOS = false;
let surfaceID = '';
const BASIC_PATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder/';
const SRCPATH = 'out_320_240_10s.h264';
let mediaDescription = {
'track_type': 1,
......@@ -110,12 +109,10 @@ describe('VideoDecoderSoftwareReliCallbackTest', function () {
}
await router.clear().then(() => {
}, failCallback).catch(failCatch);
await closeFileDescriptor(SRCPATH);
})
afterAll(async function() {
console.info('afterAll case');
await closeFileDescriptor(SRCPATH);
})
let failCallback = function(err) {
console.info(`in case error failCallback called, errMessage is ${err.message}`);
......@@ -425,17 +422,10 @@ describe('VideoDecoderSoftwareReliCallbackTest', function () {
})
}
async function toCreateVideoDecoderByName(name, mySteps, done) {
await getFileDescriptor(SRCPATH).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
await mediaTestBase.getFdRead(SRCPATH, done).then((fdNumber) => {
fdRead = fdNumber;
})
media.createVideoDecoderByName(name, (err, processor) => {
await media.createVideoDecoderByName(name, (err, processor) => {
printError(err, false);
console.info(`case createVideoDecoderByName callback`);
videoDecodeProcessor = processor;
......
......@@ -16,7 +16,7 @@
import media from '@ohos.multimedia.media'
import fileio from '@ohos.fileio'
import router from '@system.router'
import {getFileDescriptor, closeFileDescriptor} from './VideoDecoderTestBase.test.js'
import * as mediaTestBase from '../../../../../MediaTestBase.js';
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
const DECODE_STEP = {
......@@ -47,7 +47,6 @@ describe('VideoDecoderSoftwareReliPromiseTest', function () {
let inputEosFlag = false;
let workdoneAtEOS = false;
let surfaceID = '';
const BASIC_PATH = '/data/accounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder/';
const SRCPATH = 'out_320_240_10s.h264';
let mediaDescription = {
'track_type': 1,
......@@ -110,12 +109,10 @@ describe('VideoDecoderSoftwareReliPromiseTest', function () {
}
await router.clear().then(() => {
}, failCallback).catch(failCatch);
await closeFileDescriptor(SRCPATH);
})
afterAll(async function() {
console.info('afterAll case');
await closeFileDescriptor(SRCPATH);
})
let caseCallback = function(err) {
console.info(`in case caseCallback called, caseMessage is ${err.message}`);
......@@ -376,11 +373,14 @@ describe('VideoDecoderSoftwareReliPromiseTest', function () {
break;
case DECODE_STEP.WAIT_FOR_EOS:
mySteps.shift();
setTimeout(() =>{
setTimeout(async() =>{
expect(inputEosFlag).assertTrue();
if (inputEosFlag == false) {
console.info(`in case error inputEosFlag == false`);
}
await mediaTestBase.getFdRead(SRCPATH, done).then((fdNumber) => {
fdRead = fdNumber;
})
toNextStep(mySteps, done);
}, 7000); // wait 7000 ms for eos
break;
......@@ -422,17 +422,10 @@ describe('VideoDecoderSoftwareReliPromiseTest', function () {
}, failCallback).catch(failCatch);
}
async function toCreateVideoDecoderByName(name, mySteps, done) {
await getFileDescriptor(SRCPATH).then((res) => {
if (res == undefined) {
expect().assertFail();
console.info('case error fileDescriptor undefined, open file fail');
done();
} else {
fdRead = res.fd;
console.info("case fdRead is: " + fdRead);
}
await mediaTestBase.getFdRead(SRCPATH, done).then((fdNumber) => {
fdRead = fdNumber;
})
media.createVideoDecoderByName(name).then((processor) => {
await media.createVideoDecoderByName(name).then((processor) => {
console.info(`case createVideoDecoderByName success`);
videoDecodeProcessor = processor;
setCallback(done);
......
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import resourceManager from '@ohos.resourceManager';
export async function getFileDescriptor(fileName) {
let fileDescriptor;
await resourceManager.getResourceManager().then(async (mgr) => {
await mgr.getRawFileDescriptor(fileName).then(value => {
fileDescriptor = {fd: value.fd, offset: value.offset, length: value.length};
}).catch(error => {
console.log('case getRawFileDescriptor err: ' + error);
});
});
return fileDescriptor;
}
export async function closeFileDescriptor(fileName) {
await resourceManager.getResourceManager().then(async (mgr) => {
await mgr.closeRawFileDescriptor(fileName).then(value => {
console.log('case closeRawFileDescriptor success for fileName: ' + fileName);
}).catch(error => {
console.log('case closeRawFileDescriptor err: ' + error);
});
});
}
......@@ -139,7 +139,7 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
console.info('[mediaLibrary] case getFdWrite getFileAssets() success');
fileAsset = await fetchWriteFileResult.getAllObject();
console.info('[mediaLibrary] case getFdWrite getAllObject() success');
fdWrite = await fileAsset[0].open('Rw');
fdWrite = await fileAsset[0].open('rw');
console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite);
}
}
......
......@@ -159,7 +159,7 @@ describe('videoSoftwareEncoderFuncPromise', function () {
console.info('[mediaLibrary] case getFdWrite getFileAssets() success');
fileAsset = await fetchWriteFileResult.getAllObject();
console.info('[mediaLibrary] case getFdWrite getAllObject() success');
fdWrite = await fileAsset[0].open('Rw');
fdWrite = await fileAsset[0].open('rw');
console.info('[mediaLibrary] case getFdWrite fdWrite is ' + fdWrite);
}
}
......
......@@ -60,4 +60,21 @@ describe('VideoRecorderEnumTest', function () {
expect(media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_ES).assertEqual(1);
done();
})
/* *
* @tc.number : SUB_MEDIA_VIDEO_DECODER_ENUM_CodecMimeType_0100
* @tc.name : CodecMimeType
* @tc.desc : Test Enumerate CodecMimeType
* @tc.size : MediumTest
* @tc.type : Function test
* @tc.level : Level0
*/
it('SUB_MEDIA_VIDEO_DECODER_ENUM_CodecMimeType_0100', 0, async function (done) {
expect(media.CodecMimeType.VIDEO_H263).assertEqual('video/h263');
expect(media.CodecMimeType.VIDEO_AVC).assertEqual('video/avc');
expect(media.CodecMimeType.VIDEO_MPEG2).assertEqual('video/mpeg2');
expect(media.CodecMimeType.VIDEO_MPEG4).assertEqual('video/mp4v-es');
expect(media.CodecMimeType.VIDEO_VP8).assertEqual('video/x-vnd.on2.vp8');
done();
})
})
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册