Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
8a36fea5
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
大约 1 年 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
8a36fea5
编写于
4月 12, 2022
作者:
O
openharmony_ci
提交者:
Gitee
4月 12, 2022
浏览文件
操作
浏览文件
下载
差异文件
!2970 沙箱路径修改
Merge pull request !2970 from ling990/ling990
上级
b8fb3aec
cb5f0020
变更
41
隐藏空白更改
内联
并排
Showing
41 changed file
with
2043 addition
and
683 deletion
+2043
-683
multimedia/media/media_js_standard/audioDecoder/Test.json
multimedia/media/media_js_standard/audioDecoder/Test.json
+21
-9
multimedia/media/media_js_standard/audioDecoder/signature/openharmony_sx.p7b
...dia_js_standard/audioDecoder/signature/openharmony_sx.p7b
+0
-0
multimedia/media/media_js_standard/audioDecoder/src/main/config.json
...media/media_js_standard/audioDecoder/src/main/config.json
+22
-0
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFormatCallbackTest.test.js
...r/src/main/js/test/AudioDecoderFormatCallbackTest.test.js
+148
-29
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFormatPromiseTest.test.js
...er/src/main/js/test/AudioDecoderFormatPromiseTest.test.js
+147
-29
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFuncCallbackTest.test.js
...der/src/main/js/test/AudioDecoderFuncCallbackTest.test.js
+179
-41
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFuncPromiseTest.test.js
...oder/src/main/js/test/AudioDecoderFuncPromiseTest.test.js
+170
-32
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderMultiInstancesTest.test.js
...r/src/main/js/test/AudioDecoderMultiInstancesTest.test.js
+2
-2
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderReliabilityCallbackTest.test.js
.../main/js/test/AudioDecoderReliabilityCallbackTest.test.js
+35
-23
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderReliabilityPromiseTest.test.js
...c/main/js/test/AudioDecoderReliabilityPromiseTest.test.js
+33
-22
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderTestBase.test.js
...udioDecoder/src/main/js/test/AudioDecoderTestBase.test.js
+38
-0
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/List.test.js
...ia_js_standard/audioDecoder/src/main/js/test/List.test.js
+1
-1
multimedia/media/media_js_standard/audioEncoder/Test.json
multimedia/media/media_js_standard/audioEncoder/Test.json
+17
-5
multimedia/media/media_js_standard/audioEncoder/signature/openharmony_sx.p7b
...dia_js_standard/audioEncoder/signature/openharmony_sx.p7b
+0
-0
multimedia/media/media_js_standard/audioEncoder/src/main/config.json
...media/media_js_standard/audioEncoder/src/main/config.json
+22
-0
multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderFuncCallbackTest.test.js
...der/src/main/js/test/AudioEncoderFuncCallbackTest.test.js
+178
-46
multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderFuncPromiseTest.test.js
...oder/src/main/js/test/AudioEncoderFuncPromiseTest.test.js
+168
-40
multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderReliabilityCallbackTest.test.js
.../main/js/test/AudioEncoderReliabilityCallbackTest.test.js
+34
-50
multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderReliabilityPromiseTest.test.js
...c/main/js/test/AudioEncoderReliabilityPromiseTest.test.js
+33
-51
multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderTestBase.test.js
...udioEncoder/src/main/js/test/AudioEncoderTestBase.test.js
+38
-0
multimedia/media/media_js_standard/audioEncoder/src/main/js/test/List.test.js
...ia_js_standard/audioEncoder/src/main/js/test/List.test.js
+1
-0
multimedia/media/media_js_standard/videoDecoder/Test.json
multimedia/media/media_js_standard/videoDecoder/Test.json
+17
-7
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/List.test.js
...ia_js_standard/videoDecoder/src/main/js/test/List.test.js
+1
-0
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderEnumTest.test.js
...ideoDecoder/src/main/js/test/VideoDecoderEnumTest.test.js
+33
-22
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderFuncCallbackTest.test.js
...der/src/main/js/test/VideoDecoderFuncCallbackTest.test.js
+42
-23
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderFuncPromiseTest.test.js
...oder/src/main/js/test/VideoDecoderFuncPromiseTest.test.js
+45
-35
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderReliCallbackTest.test.js
...der/src/main/js/test/VideoDecoderReliCallbackTest.test.js
+31
-14
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderReliPromiseTest.test.js
...oder/src/main/js/test/VideoDecoderReliPromiseTest.test.js
+30
-13
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareFuncCallbackTest.test.js
...main/js/test/VideoDecoderSoftwareFuncCallbackTest.test.js
+57
-27
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareFuncPromiseTest.test.js
.../main/js/test/VideoDecoderSoftwareFuncPromiseTest.test.js
+54
-25
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareReliCallbackTest.test.js
...main/js/test/VideoDecoderSoftwareReliCallbackTest.test.js
+28
-12
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareReliPromiseTest.test.js
.../main/js/test/VideoDecoderSoftwareReliPromiseTest.test.js
+28
-13
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderTestBase.test.js
...ideoDecoder/src/main/js/test/VideoDecoderTestBase.test.js
+38
-0
multimedia/media/media_js_standard/videoEncoder/Test.json
multimedia/media/media_js_standard/videoEncoder/Test.json
+5
-11
multimedia/media/media_js_standard/videoEncoder/signature/openharmony_sx.p7b
...dia_js_standard/videoEncoder/signature/openharmony_sx.p7b
+0
-0
multimedia/media/media_js_standard/videoEncoder/src/main/config.json
...media/media_js_standard/videoEncoder/src/main/config.json
+22
-0
multimedia/media/media_js_standard/videoEncoder/src/main/js/test/VideoEncoderMultiInstancesTest.test.js
...r/src/main/js/test/VideoEncoderMultiInstancesTest.test.js
+96
-22
multimedia/media/media_js_standard/videoEncoder/src/main/js/test/VideoEncoderSoftwareFuncCallbackTest.test.js
...main/js/test/VideoEncoderSoftwareFuncCallbackTest.test.js
+105
-29
multimedia/media/media_js_standard/videoEncoder/src/main/js/test/VideoEncoderSoftwareFuncPromiseTest.test.js
.../main/js/test/VideoEncoderSoftwareFuncPromiseTest.test.js
+119
-44
multimedia/media/media_js_standard/videoEncoder/src/main/js/test/VideoEncoderSoftwareReliabilityCallbackTest.test.js
.../test/VideoEncoderSoftwareReliabilityCallbackTest.test.js
+3
-3
multimedia/media/media_js_standard/videoEncoder/src/main/js/test/VideoEncoderSoftwareReliabilityPromiseTest.test.js
...s/test/VideoEncoderSoftwareReliabilityPromiseTest.test.js
+2
-3
未找到文件。
multimedia/media/media_js_standard/audioDecoder/Test.json
浏览文件 @
8a36fea5
...
...
@@ -14,25 +14,37 @@
"type"
:
"AppInstallKit"
,
"cleanup-apps"
:
true
},
{
"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/"
],
"teardown-command"
:[
]
},
{
"type"
:
"PushKit"
,
"pre-push"
:
[
],
"push"
:
[
"./resource/audio/audioDecode/AAC_48000_32_1.aac ->/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder
/"
,
"./resource/audio/audioDecode/AAC_16000_1.aac ->/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder
/"
,
"./resource/audio/audioDecode/FLAC_48000_32_1.flac ->/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder
/"
,
"./resource/audio/audioDecode/mp3.es ->/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder
/"
,
"./resource/audio/audioDecode/vorbis.es ->/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder
/"
"./resource/audio/audioDecode/AAC_48000_32_1.aac ->/data/a
pp/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/a
pp/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/a
pp/el1/bundle/public/ohos.acts.multimedia.audio.audiodecoder/ohos.acts.multimedia.audio.audiodecoder/assets/entry/resources/rawfile
/"
,
"./resource/audio/audioDecode/mp3.es ->/data/a
pp/el1/bundle/public/ohos.acts.multimedia.audio.audiodecoder/ohos.acts.multimedia.audio.audiodecoder/assets/entry/resources/rawfile
/"
,
"./resource/audio/audioDecode/vorbis.es ->/data/a
pp/el1/bundle/public/ohos.acts.multimedia.audio.audiodecoder/ohos.acts.multimedia.audio.audiodecoder/assets/entry/resources/rawfile
/"
]
},
{
"type"
:
"ShellKit"
,
"run-command"
:
[
"rm -R /data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder/results"
,
"mkdir -p /data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder/results/"
,
"chmod 777 -R /data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder"
,
"chmod 777 /data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder/*"
"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 /storage/media/100/local/files/"
,
"chmod 777 /storage/media/100/local/files/*"
,
"killall com.ohos.medialibrary.MediaScannerAbilityA"
,
"aa start -a MediaScannerAbility -b com.ohos.medialibrary.MediaScannerAbilityA"
],
"teardown-command"
:[
]
...
...
multimedia/media/media_js_standard/audioDecoder/signature/openharmony_sx.p7b
浏览文件 @
8a36fea5
无法预览此类型文件
multimedia/media/media_js_standard/audioDecoder/src/main/config.json
浏览文件 @
8a36fea5
...
...
@@ -49,6 +49,28 @@
"tv"
,
"wearable"
],
"reqPermissions"
:
[
{
"name"
:
"ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
,
"reason"
:
"use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
{
"name"
:
"ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
,
"reason"
:
"use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
},
{
"name"
:
"ohos.permission.MEDIA_LOCATION"
,
"reason"
:
"use ohos.permission.MEDIA_LOCATION"
},
{
"name"
:
"ohos.permission.READ_MEDIA"
,
"reason"
:
"use ohos.permission.READ_MEDIA"
},
{
"name"
:
"ohos.permission.WRITE_MEDIA"
,
"reason"
:
"use ohos.permission.WRITE_MEDIA"
}
],
"mainAbility"
:
"ohos.acts.multimedia.audio.audiodecoder.MainAbility"
,
"distro"
:
{
"moduleType"
:
"entry"
,
...
...
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFormatCallbackTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,16 +14,21 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
Fileio
from
'
@ohos.fileio
'
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
{
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
=
RESOURCEPATH
+
'
AAC_48000_32_1.aac
'
;
const
AUDIOPATH2
=
RESOURCEPATH
+
'
FLAC_48000_32_1.flac
'
const
AUDIOPATH3
=
RESOURCEPATH
+
'
mp3.es
'
;
const
AUDIOPATH4
=
RESOURCEPATH
+
'
vorbis.es
'
;
const
BASIC_PATH
=
RESOURCEPATH
+
'
results/decode_format_callback_
'
;
const
AUDIOPATH1
=
'
AAC_48000_32_1.aac
'
;
const
AUDIOPATH2
=
'
FLAC_48000_32_1.flac
'
const
AUDIOPATH3
=
'
mp3.es
'
;
const
AUDIOPATH4
=
'
vorbis.es
'
;
const
BASIC_PATH
=
'
results/decode_format_callback_
'
;
let
audioDecodeProcessor
;
let
readStreamSync
;
let
needGetMediaDes
=
false
;
...
...
@@ -38,9 +43,19 @@ describe('AudioDecoderFormatCallback', function () {
let
samplerate
=
44.1
;
let
isMp3
=
false
;
let
isVorbis
=
false
;
let
readpath
;
let
savepath
;
let
fdRead
;
let
fdWrite
;
let
fileAsset
;
const
context
=
featureAbility
.
getContext
();
const
mediaTest
=
mediaLibrary
.
getMediaLibrary
(
context
);
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
beforeAll
(
async
function
()
{
console
.
info
(
'
beforeAll case 1
'
);
await
applyPermission
();
console
.
info
(
'
beforeAll case after get permission
'
);
})
beforeEach
(
function
()
{
...
...
@@ -69,38 +84,116 @@ describe('AudioDecoderFormatCallback', function () {
audioDecodeProcessor
=
null
;
},
failCallback
).
catch
(
failCatch
);
}
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
})
afterAll
(
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
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
);
let
mediaType
=
mediaLibrary
.
MediaType
.
AUDIO
;
console
.
info
(
'
[mediaLibrary] case mediaType is
'
+
mediaType
);
let
publicPath
=
await
mediaTest
.
getPublicDirectory
(
mediaLibrary
.
DirectoryType
.
DIR_AUDIO
);
console
.
info
(
'
[mediaLibrary] case getFdWrite publicPath is
'
+
publicPath
);
let
dataUri
=
await
mediaTest
.
createAsset
(
mediaType
,
pathName
,
publicPath
);
if
(
dataUri
!=
undefined
)
{
let
args
=
dataUri
.
id
.
toString
();
let
fetchOp
=
{
selections
:
fileKeyObj
.
ID
+
"
=?
"
,
selectionArgs
:
[
args
],
}
let
fetchWriteFileResult
=
await
mediaTest
.
getFileAssets
(
fetchOp
);
console
.
info
(
'
[mediaLibrary] case getFdWrite getFileAssets() success
'
);
fileAsset
=
await
fetchWriteFileResult
.
getAllObject
();
console
.
info
(
'
[mediaLibrary] case getFdWrite getAllObject() success
'
);
fdWrite
=
await
fileAsset
[
0
].
open
(
'
Rw
'
);
console
.
info
(
'
[mediaLibrary] case getFdWrite fdWrite is
'
+
fdWrite
);
}
}
async
function
closeFdWrite
()
{
if
(
fileAsset
!=
null
)
{
await
fileAsset
[
0
].
close
(
fdWrite
).
then
(()
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite success, fd is
'
+
fdWrite
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite failed
'
);
});
}
else
{
console
.
info
(
'
[mediaLibrary] case fileAsset is null
'
);
}
}
function
writeFile
(
path
,
buf
,
len
)
{
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
num
=
writestream
.
writeSync
(
buf
,
{
length
:
len
});
writestream
.
flushSync
();
writestream
.
closeSync
();
let
res
=
fileio
.
writeSync
(
fdWrite
,
buf
,
{
length
:
len
});
console
.
info
(
'
case fileio.writeSync buffer success
'
);
}
catch
(
e
)
{
console
.
log
(
e
);
console
.
info
(
'
case fileio.writeSync buffer error is
'
+
e
);
}
}
function
readFile
(
path
)
{
console
.
log
(
'
read file start execution
'
);
console
.
info
(
'
read file start execution
'
);
try
{
console
.
log
(
'
filepath:
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
console
.
log
(
e
);
console
.
info
(
'
filepath:
'
+
path
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
function
getContent
(
buf
,
len
)
{
console
.
log
(
"
start get content
"
);
console
.
info
(
"
case
start get content
"
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
log
(
'
lengthreal:
'
+
lengthreal
);
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
async
function
enqueueAllInputs
(
queue
)
{
...
...
@@ -153,10 +246,12 @@ describe('AudioDecoderFormatCallback', function () {
audioDecodeProcessor
.
reset
((
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
log
(
"
reset success
"
);
audioDecodeProcessor
.
release
((
err
)
=>
{
audioDecodeProcessor
.
release
(
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
log
(
"
case release success
"
);
audioDecodeProcessor
=
null
;
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
done
();
})
})
...
...
@@ -215,7 +310,10 @@ describe('AudioDecoderFormatCallback', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
aac_01.pcm
'
;
savepath
=
'
format_callback_aac_01.pcm
'
;
readpath
=
AUDIOPATH1
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
ES
=
[
0
,
283
,
336
,
291
,
405
,
438
,
411
,
215
,
215
,
313
,
270
,
342
,
641
,
554
,
545
,
545
,
546
,
541
,
540
,
542
,
552
,
537
,
533
,
498
,
472
,
445
,
430
,
445
,
427
,
414
,
386
,
413
,
370
,
380
,
...
...
@@ -332,7 +430,10 @@ describe('AudioDecoderFormatCallback', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
aac_02.pcm
'
;
savepath
=
'
format_callback_aac_02.pcm
'
;
readpath
=
AUDIOPATH1
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
ES
=
[
0
,
283
,
336
,
291
,
405
,
438
,
411
,
215
,
215
,
313
,
270
,
342
,
641
,
554
,
545
,
545
,
546
,
541
,
540
,
542
,
552
,
537
,
533
,
498
,
472
,
445
,
430
,
445
,
427
,
414
,
386
,
413
,
370
,
380
,
...
...
@@ -449,7 +550,10 @@ describe('AudioDecoderFormatCallback', function () {
"
sample_rate
"
:
48000
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
flac_01.pcm
'
;
savepath
=
'
format_callback_flac_01.pcm
'
;
readpath
=
AUDIOPATH2
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
samplerate
=
48
;
ES
=
[
0
,
2116
,
2093
,
2886
,
2859
,
2798
,
2778
,
2752
,
2752
,
2754
,
2720
,
2898
,
2829
,
2806
,
...
...
@@ -523,7 +627,10 @@ describe('AudioDecoderFormatCallback', function () {
"
sample_rate
"
:
48000
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
flac_02.pcm
'
;
savepath
=
'
format_callback_flac_02.pcm
'
;
readpath
=
AUDIOPATH2
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
samplerate
=
48
;
ES
=
[
0
,
2116
,
2093
,
2886
,
2859
,
2798
,
2778
,
2752
,
2752
,
2754
,
2720
,
2898
,
2829
,
2806
,
...
...
@@ -597,7 +704,10 @@ describe('AudioDecoderFormatCallback', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
mp3_01.pcm
'
;
savepath
=
'
format_callback_mp3_01.pcm
'
;
readpath
=
AUDIOPATH3
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
isMp3
=
true
;
isVorbis
=
false
;
...
...
@@ -658,7 +768,10 @@ describe('AudioDecoderFormatCallback', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
mp3_02.pcm
'
;
savepath
=
'
format_callback_mp3_02.pcm
'
;
readpath
=
AUDIOPATH3
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
isMp3
=
true
;
isVorbis
=
false
;
...
...
@@ -719,7 +832,10 @@ describe('AudioDecoderFormatCallback', function () {
"
sample_rate
"
:
48000
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
vorbis_01.pcm
'
;
savepath
=
'
format_callback_vorbis_01.pcm
'
;
readpath
=
AUDIOPATH4
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
samplerate
=
48
;
isVorbis
=
true
;
...
...
@@ -823,7 +939,10 @@ describe('AudioDecoderFormatCallback', function () {
"
sample_rate
"
:
48000
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
vorbis_02.pcm
'
;
savepath
=
'
format_callback_vorbis_02.pcm
'
;
readpath
=
AUDIOPATH4
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
samplerate
=
48
;
isVorbis
=
true
;
...
...
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFormatPromiseTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,16 +14,20 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
Fileio
from
'
@ohos.fileio
'
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
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
describe
(
'
AudioDecoderFormatPromise
'
,
function
()
{
const
RESOURCEPATH
=
'
/data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder/
'
const
AUDIOPATH1
=
RESOURCEPATH
+
'
AAC_48000_32_1.aac
'
;
const
AUDIOPATH2
=
RESOURCEPATH
+
'
FLAC_48000_32_1.flac
'
const
AUDIOPATH3
=
RESOURCEPATH
+
'
mp3.es
'
;
const
AUDIOPATH4
=
RESOURCEPATH
+
'
vorbis.es
'
;
const
BASIC_PATH
=
RESOURCEPATH
+
'
results/decode_format_promise_
'
;
const
AUDIOPATH1
=
'
AAC_48000_32_1.aac
'
;
const
AUDIOPATH2
=
'
FLAC_48000_32_1.flac
'
const
AUDIOPATH3
=
'
mp3.es
'
;
const
AUDIOPATH4
=
'
vorbis.es
'
;
const
BASIC_PATH
=
'
results/decode_format_promise_
'
;
let
audioDecodeProcessor
;
let
readStreamSync
;
let
needGetMediaDes
=
false
;
...
...
@@ -38,9 +42,19 @@ describe('AudioDecoderFormatPromise', function () {
let
samplerate
=
44.1
;
let
isMp3
=
false
;
let
isVorbis
=
false
;
let
readpath
;
let
savepath
;
let
fdRead
;
let
fdWrite
;
let
fileAsset
;
const
context
=
featureAbility
.
getContext
();
const
mediaTest
=
mediaLibrary
.
getMediaLibrary
(
context
);
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
beforeAll
(
async
function
()
{
console
.
info
(
'
beforeAll case 1
'
);
await
applyPermission
();
console
.
info
(
'
beforeAll case after get permission
'
);
})
beforeEach
(
function
()
{
...
...
@@ -69,6 +83,8 @@ describe('AudioDecoderFormatPromise', function () {
audioDecodeProcessor
=
null
;
},
failCallback
).
catch
(
failCatch
);
}
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
})
afterAll
(
function
()
{
...
...
@@ -85,32 +101,108 @@ 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
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
);
let
mediaType
=
mediaLibrary
.
MediaType
.
AUDIO
;
console
.
info
(
'
[mediaLibrary] case mediaType is
'
+
mediaType
);
let
publicPath
=
await
mediaTest
.
getPublicDirectory
(
mediaLibrary
.
DirectoryType
.
DIR_AUDIO
);
console
.
info
(
'
[mediaLibrary] case getFdWrite publicPath is
'
+
publicPath
);
let
dataUri
=
await
mediaTest
.
createAsset
(
mediaType
,
pathName
,
publicPath
);
if
(
dataUri
!=
undefined
)
{
let
args
=
dataUri
.
id
.
toString
();
let
fetchOp
=
{
selections
:
fileKeyObj
.
ID
+
"
=?
"
,
selectionArgs
:
[
args
],
}
let
fetchWriteFileResult
=
await
mediaTest
.
getFileAssets
(
fetchOp
);
console
.
info
(
'
[mediaLibrary] case getFdWrite getFileAssets() success
'
);
fileAsset
=
await
fetchWriteFileResult
.
getAllObject
();
console
.
info
(
'
[mediaLibrary] case getFdWrite getAllObject() success
'
);
fdWrite
=
await
fileAsset
[
0
].
open
(
'
Rw
'
);
console
.
info
(
'
[mediaLibrary] case getFdWrite fdWrite is
'
+
fdWrite
);
}
}
async
function
closeFdWrite
()
{
if
(
fileAsset
!=
null
)
{
await
fileAsset
[
0
].
close
(
fdWrite
).
then
(()
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite success, fd is
'
+
fdWrite
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite failed
'
);
});
}
else
{
console
.
info
(
'
[mediaLibrary] case fileAsset is null
'
);
}
}
function
writeFile
(
path
,
buf
,
len
)
{
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
num
=
writestream
.
writeSync
(
buf
,
{
length
:
len
});
writestream
.
flushSync
();
writestream
.
closeSync
();
let
res
=
fileio
.
writeSync
(
fdWrite
,
buf
,
{
length
:
len
});
console
.
info
(
'
case fileio.writeSync buffer success
'
);
}
catch
(
e
)
{
console
.
log
(
e
)
console
.
info
(
'
case fileio.writeSync buffer error is
'
+
e
);
}
}
function
readFile
(
path
)
{
console
.
log
(
'
read file start execution
'
);
console
.
info
(
'
read file start execution
'
);
try
{
console
.
log
(
'
filepath:
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
console
.
log
(
e
);
console
.
info
(
'
filepath:
'
+
path
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
function
getContent
(
buf
,
len
)
{
console
.
log
(
"
start get content
"
);
console
.
info
(
"
case
start get content
"
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
log
(
'
lengthreal:
'
+
lengthreal
);
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
async
function
enqueueAllInputs
(
queue
)
{
...
...
@@ -167,6 +259,8 @@ describe('AudioDecoderFormatPromise', function () {
console
.
info
(
'
release success
'
);
audioDecodeProcessor
=
null
;
},
failCallback
).
catch
(
failCatch
);
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
done
();
}
else
{
...
...
@@ -220,7 +314,10 @@ describe('AudioDecoderFormatPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
aac_01.pcm
'
;
savepath
=
'
format_promise_aac_01.pcm
'
;
readpath
=
AUDIOPATH1
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
ES
=
[
0
,
283
,
336
,
291
,
405
,
438
,
411
,
215
,
215
,
313
,
270
,
342
,
641
,
554
,
545
,
545
,
546
,
541
,
540
,
542
,
552
,
537
,
533
,
498
,
472
,
445
,
430
,
445
,
427
,
414
,
386
,
413
,
370
,
380
,
...
...
@@ -318,7 +415,10 @@ describe('AudioDecoderFormatPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
aac_02.pcm
'
;
savepath
=
'
format_promise_aac_02.pcm
'
;
readpath
=
AUDIOPATH1
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
ES
=
[
0
,
283
,
336
,
291
,
405
,
438
,
411
,
215
,
215
,
313
,
270
,
342
,
641
,
554
,
545
,
545
,
546
,
541
,
540
,
542
,
552
,
537
,
533
,
498
,
472
,
445
,
430
,
445
,
427
,
414
,
386
,
413
,
370
,
380
,
...
...
@@ -416,7 +516,10 @@ describe('AudioDecoderFormatPromise', function () {
"
sample_rate
"
:
48000
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
flac_01.pcm
'
;
savepath
=
'
format_promise_flac_01.pcm
'
;
readpath
=
AUDIOPATH2
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
samplerate
=
48
;
ES
=
[
0
,
2116
,
2093
,
2886
,
2859
,
2798
,
2778
,
2752
,
2752
,
2754
,
2720
,
2898
,
2829
,
2806
,
...
...
@@ -472,7 +575,10 @@ describe('AudioDecoderFormatPromise', function () {
"
sample_rate
"
:
48000
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
flac_02.pcm
'
;
savepath
=
'
format_promise_flac_02.pcm
'
;
readpath
=
AUDIOPATH2
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
samplerate
=
48
;
ES
=
[
0
,
2116
,
2093
,
2886
,
2859
,
2798
,
2778
,
2752
,
2752
,
2754
,
2720
,
2898
,
2829
,
2806
,
...
...
@@ -528,7 +634,10 @@ describe('AudioDecoderFormatPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
mp3_01.pcm
'
;
savepath
=
'
format_promise_mp3_01.pcm
'
;
readpath
=
AUDIOPATH3
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
isMp3
=
true
;
ES
=
[
0
,
1044
];
...
...
@@ -569,7 +678,10 @@ describe('AudioDecoderFormatPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
mp3_02.pcm
'
;
savepath
=
'
format_promise_mp3_02.pcm
'
;
readpath
=
AUDIOPATH3
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
isMp3
=
true
;
ES
=
[
0
,
1044
];
...
...
@@ -610,7 +722,10 @@ describe('AudioDecoderFormatPromise', function () {
"
sample_rate
"
:
48000
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
vorbis_01.pcm
'
;
savepath
=
'
format_promise_vorbis_01.pcm
'
;
readpath
=
AUDIOPATH4
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
samplerate
=
48
;
isVorbis
=
true
;
...
...
@@ -695,7 +810,10 @@ describe('AudioDecoderFormatPromise', function () {
"
sample_rate
"
:
48000
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
vorbis_02.pcm
'
;
savepath
=
'
format_promise_vorbis_02.pcm
'
;
readpath
=
AUDIOPATH4
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
samplerate
=
48
;
isVorbis
=
true
;
...
...
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFuncCallbackTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,14 +14,19 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
Fileio
from
'
@ohos.fileio
'
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
{
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
=
RESOURCEPATH
+
'
AAC_48000_32_1.aac
'
;
const
AUDIOPATH2
=
RESOURCEPATH
+
'
AAC_16000_1.aac
'
;
const
AUDIOPATH3
=
RESOURCEPATH
+
'
FLAC_48000_32_1.flac
'
;
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_
'
;
let
audioDecodeProcessor
;
let
readStreamSync
;
...
...
@@ -129,9 +134,19 @@ describe('AudioDecoderFuncCallback', function () {
381
,
410
,
394
,
386
,
345
,
345
,
354
,
397
,
386
,
375
,
390
,
347
,
411
,
381
,
383
,
374
,
379
,
380
,
378
,
391
,
380
,
339
,
390
,
383
,
375
];
let
ES_LENGTH
=
1500
;
let
readpath
;
let
savepath
;
let
fdRead
;
let
fdWrite
;
let
fileAsset
;
const
context
=
featureAbility
.
getContext
();
const
mediaTest
=
mediaLibrary
.
getMediaLibrary
(
context
);
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
beforeAll
(
async
function
()
{
console
.
info
(
'
beforeAll case 1
'
);
await
applyPermission
();
console
.
info
(
'
beforeAll case after get permission
'
);
})
beforeEach
(
function
()
{
...
...
@@ -252,6 +267,8 @@ describe('AudioDecoderFuncCallback', function () {
audioDecodeProcessor
=
null
;
},
failCallback
).
catch
(
failCatch
);
}
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
})
afterAll
(
function
()
{
...
...
@@ -276,32 +293,109 @@ describe('AudioDecoderFuncCallback', function () {
outputQueue
=
[];
}
function
writeFile
(
path
,
buf
,
len
){
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
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
);
let
mediaType
=
mediaLibrary
.
MediaType
.
AUDIO
;
console
.
info
(
'
[mediaLibrary] case mediaType is
'
+
mediaType
);
let
publicPath
=
await
mediaTest
.
getPublicDirectory
(
mediaLibrary
.
DirectoryType
.
DIR_AUDIO
);
console
.
info
(
'
[mediaLibrary] case getFdWrite publicPath is
'
+
publicPath
);
let
dataUri
=
await
mediaTest
.
createAsset
(
mediaType
,
pathName
,
publicPath
);
if
(
dataUri
!=
undefined
)
{
let
args
=
dataUri
.
id
.
toString
();
let
fetchOp
=
{
selections
:
fileKeyObj
.
ID
+
"
=?
"
,
selectionArgs
:
[
args
],
}
let
fetchWriteFileResult
=
await
mediaTest
.
getFileAssets
(
fetchOp
);
console
.
info
(
'
[mediaLibrary] case getFdWrite getFileAssets() success
'
);
fileAsset
=
await
fetchWriteFileResult
.
getAllObject
();
console
.
info
(
'
[mediaLibrary] case getFdWrite getAllObject() success
'
);
fdWrite
=
await
fileAsset
[
0
].
open
(
'
Rw
'
);
console
.
info
(
'
[mediaLibrary] case getFdWrite fdWrite is
'
+
fdWrite
);
}
}
async
function
closeFdWrite
()
{
if
(
fileAsset
!=
null
)
{
await
fileAsset
[
0
].
close
(
fdWrite
).
then
(()
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite success, fd is
'
+
fdWrite
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite failed
'
);
});
}
else
{
console
.
info
(
'
[mediaLibrary] case fileAsset is null
'
);
}
}
function
writeFile
(
path
,
buf
,
len
)
{
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
num
=
writestream
.
writeSync
(
buf
,
{
length
:
len
});
writestream
.
flushSync
();
writestream
.
closeSync
();
}
catch
(
e
){
console
.
info
(
e
)
let
res
=
fileio
.
writeSync
(
fdWrite
,
buf
,
{
length
:
len
});
console
.
info
(
'
case fileio.writeSync buffer success
'
);
}
catch
(
e
)
{
console
.
info
(
'
case fileio.writeSync buffer error is
'
+
e
);
}
}
function
readFile
(
path
){
function
readFile
(
path
)
{
console
.
info
(
'
read file start execution
'
);
try
{
console
.
info
(
'
filepath:
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
){
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
function
getContent
(
buf
,
len
){
console
.
info
(
"
start get content
"
);
function
getContent
(
buf
,
len
)
{
console
.
info
(
"
case
start get content
"
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
info
(
'
lengthreal:
'
+
lengthreal
);
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
async
function
stopWork
()
{
...
...
@@ -326,9 +420,11 @@ describe('AudioDecoderFuncCallback', function () {
})
}
async
function
flushWork
()
{
async
function
flushWork
(
done
)
{
inputQueue
=
[];
outputQueue
=
[];
await
closeFileDescriptor
(
readpath
);
await
getFdRead
(
readpath
,
done
);
audioDecodeProcessor
.
flush
((
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
"
case flush at inputeos success
"
);
...
...
@@ -346,10 +442,12 @@ describe('AudioDecoderFuncCallback', function () {
audioDecodeProcessor
.
reset
((
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
log
(
"
case reset success
"
);
audioDecodeProcessor
.
release
((
err
)
=>
{
audioDecodeProcessor
.
release
(
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
log
(
"
case release success
"
);
audioDecodeProcessor
=
null
;
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
done
();
})
})
...
...
@@ -400,7 +498,7 @@ describe('AudioDecoderFuncCallback', function () {
}
else
if
(
resetAtEOS
)
{
await
resetWork
();
}
else
if
(
flushAtEOS
)
{
await
flushWork
();
await
flushWork
(
done
);
}
else
if
(
workdoneAtEOS
)
{
await
doneWork
(
done
);
}
else
{
...
...
@@ -464,7 +562,10 @@ describe('AudioDecoderFuncCallback', function () {
}
workdoneAtEOS
=
true
;
needGetMediaDes
=
true
;
let
savepath
=
BASIC_PATH
+
'
0000.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_callback_00.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eventEmitter
.
on
(
'
getAudioDecoderCaps
'
,
()
=>
{
audioDecodeProcessor
.
getAudioDecoderCaps
((
err
,
Audiocaps
)
=>
{
expect
(
err
).
assertUndefined
();
...
...
@@ -545,7 +646,10 @@ describe('AudioDecoderFuncCallback', function () {
}
eosframenum
=
500
;
workdoneAtEOS
=
true
;
let
savepath
=
BASIC_PATH
+
'
0100.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_callback_01.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eventEmitter
.
on
(
'
getAudioDecoderCaps
'
,
()
=>
{
audioDecodeProcessor
.
getAudioDecoderCaps
((
err
,
Audiocaps
)
=>
{
expect
(
err
).
assertUndefined
();
...
...
@@ -615,7 +719,10 @@ describe('AudioDecoderFuncCallback', function () {
"
audio_sample_format
"
:
1
,
}
workdoneAtEOS
=
true
;
let
savepath
=
BASIC_PATH
+
'
0200.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_callback_02.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eventEmitter
.
on
(
'
getAudioDecoderCaps
'
,
()
=>
{
audioDecodeProcessor
.
getAudioDecoderCaps
((
err
,
Audiocaps
)
=>
{
expect
(
err
).
assertUndefined
();
...
...
@@ -682,7 +789,10 @@ describe('AudioDecoderFuncCallback', function () {
}
eosframenum
=
200
;
flushAtEOS
=
true
;
let
savepath
=
BASIC_PATH
+
'
0300.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_callback_03.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eventEmitter
.
on
(
'
getAudioDecoderCaps
'
,
()
=>
{
audioDecodeProcessor
.
getAudioDecoderCaps
((
err
,
Audiocaps
)
=>
{
...
...
@@ -739,7 +849,10 @@ describe('AudioDecoderFuncCallback', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0400.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_callback_04.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eventEmitter
.
on
(
'
getAudioDecoderCaps
'
,
()
=>
{
audioDecodeProcessor
.
getAudioDecoderCaps
((
err
,
Audiocaps
)
=>
{
expect
(
err
).
assertUndefined
();
...
...
@@ -789,10 +902,12 @@ describe('AudioDecoderFuncCallback', function () {
})
});
eventEmitter
.
on
(
'
release
'
,
()
=>
{
audioDecodeProcessor
.
release
((
err
)
=>
{
audioDecodeProcessor
.
release
(
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
`case release 1`
);
audioDecodeProcessor
=
null
;
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
done
();
})
});
...
...
@@ -822,7 +937,10 @@ describe('AudioDecoderFuncCallback', function () {
"
audio_sample_format
"
:
1
,
}
eosframenum
=
200
;
let
savepath
=
BASIC_PATH
+
'
0500.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_callback_05.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eventEmitter
.
on
(
'
getAudioDecoderCaps
'
,
()
=>
{
audioDecodeProcessor
.
getAudioDecoderCaps
((
err
,
Audiocaps
)
=>
{
expect
(
err
).
assertUndefined
();
...
...
@@ -866,7 +984,11 @@ describe('AudioDecoderFuncCallback', function () {
})
});
eventEmitter
.
on
(
'
restart
'
,
()
=>
{
sleep
(
2000
).
then
(()
=>
{
sleep
(
2000
).
then
(
async
()
=>
{
resetParam
();
await
closeFileDescriptor
(
readpath
);
await
getFdRead
(
readpath
,
done
);
readFile
(
readpath
);
audioDecodeProcessor
.
start
((
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
`restart after 2s`
);
...
...
@@ -902,7 +1024,10 @@ describe('AudioDecoderFuncCallback', function () {
}
eosframenum
=
200
;
resetAtEOS
=
true
;
let
savepath
=
BASIC_PATH
+
'
0600.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_callback_06.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
let
mediaDescription2
=
{
"
channel_count
"
:
1
,
"
sample_rate
"
:
16000
,
...
...
@@ -943,14 +1068,20 @@ describe('AudioDecoderFuncCallback', function () {
})
});
eventEmitter
.
on
(
'
reconfigure
'
,
(
mediaDescription2
)
=>
{
sleep
(
10000
).
then
(()
=>
{
audioDecodeProcessor
.
configure
(
mediaDescription2
,
(
err
)
=>
{
sleep
(
10000
).
then
(
async
()
=>
{
resetParam
();
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
audioDecodeProcessor
.
configure
(
mediaDescription2
,
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
`case configure 2`
);
resetParam
();
console
.
info
(
'
resetParam success, resetAtEOS IS :
'
+
resetAtEOS
)
readFile
(
AUDIOPATH2
)
savepath
=
BASIC_PATH
+
'
0601.pcm
'
;
readpath
=
AUDIOPATH2
;
savepath
=
'
audioDecode_function_callback_06_2.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
readFile
(
AUDIOPATH2
);
workdoneAtEOS
=
true
;
ES
=
[
0
,
239
,
302
,
309
,
330
,
474
,
684
,
699
,
683
,
674
,
647
,
649
,
638
,
644
,
640
,
639
,
650
,
702
,
713
,
718
,
707
,
707
,
683
,
670
,
674
,
699
,
654
,
650
,
715
,
770
,
...
...
@@ -1007,7 +1138,10 @@ describe('AudioDecoderFuncCallback', function () {
eosframenum
=
200
;
resetAtEOS
=
true
;
needrelease
=
true
;
let
savepath
=
BASIC_PATH
+
'
0700.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_callback_07.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eventEmitter
.
on
(
'
getAudioDecoderCaps
'
,
()
=>
{
audioDecodeProcessor
.
getAudioDecoderCaps
((
err
,
Audiocaps
)
=>
{
expect
(
err
).
assertUndefined
();
...
...
@@ -1042,7 +1176,9 @@ describe('AudioDecoderFuncCallback', function () {
})
});
eventEmitter
.
on
(
'
recreate
'
,
()
=>
{
sleep
(
10000
).
then
(()
=>
{
sleep
(
10000
).
then
(
async
()
=>
{
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
media
.
createAudioDecoderByMime
(
'
audio/flac
'
,
(
err
,
processor
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
`case createAudioDecoder flac`
);
...
...
@@ -1053,12 +1189,15 @@ describe('AudioDecoderFuncCallback', function () {
})
});
eventEmitter
.
on
(
'
reconfigure
'
,
(
mediaDescription2
)
=>
{
audioDecodeProcessor
.
configure
(
mediaDescription2
,
(
err
)
=>
{
audioDecodeProcessor
.
configure
(
mediaDescription2
,
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
`case configure 2`
);
resetParam
();
readFile
(
AUDIOPATH3
)
savepath
=
BASIC_PATH
+
'
0701.pcm
'
;
readpath
=
AUDIOPATH3
;
savepath
=
'
audioDecode_function_callback_07_2.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
readFile
(
AUDIOPATH3
);
workdoneAtEOS
=
true
;
ES
=
[
0
,
2116
,
2093
,
2886
,
2859
,
2798
,
2778
,
2752
,
2752
,
2754
,
2720
,
2898
,
2829
,
2806
,
2796
,
2786
,
2774
,
2758
,
2741
,
3489
,
3342
,
3272
,
3167
,
3048
,
3060
,
2919
,
...
...
@@ -1081,4 +1220,3 @@ describe('AudioDecoderFuncCallback', function () {
})
})
})
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderFuncPromiseTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,15 +14,20 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
Fileio
from
'
@ohos.fileio
'
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
{
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
=
RESOURCEPATH
+
'
AAC_48000_32_1.aac
'
;
const
AUDIOPATH2
=
RESOURCEPATH
+
'
AAC_16000_1.aac
'
;
const
AUDIOPATH3
=
RESOURCEPATH
+
'
FLAC_48000_32_1.flac
'
;
const
BASIC_PATH
=
RESOURCEPATH
+
'
results/decode_func_promise_
'
;
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
;
...
...
@@ -129,13 +134,23 @@ describe('AudioDecoderFuncPromise', function () {
381
,
410
,
394
,
386
,
345
,
345
,
354
,
397
,
386
,
375
,
390
,
347
,
411
,
381
,
383
,
374
,
379
,
380
,
378
,
391
,
380
,
339
,
390
,
383
,
375
];
let
ES_LENGTH
=
1500
;
let
readpath
;
let
savepath
;
let
fdRead
;
let
fdWrite
;
let
fileAsset
;
const
context
=
featureAbility
.
getContext
();
const
mediaTest
=
mediaLibrary
.
getMediaLibrary
(
context
);
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
beforeAll
(
async
function
()
{
console
.
info
(
'
beforeAll case 1
'
);
await
applyPermission
();
console
.
info
(
'
beforeAll case after get permission
'
);
})
beforeEach
(
function
()
{
console
.
info
(
'
beforeEach case
'
);
console
.
info
(
'
beforeEach case
3
'
);
audioDecodeProcessor
=
undefined
;
readStreamSync
=
undefined
;
eosframenum
=
0
;
...
...
@@ -252,6 +267,8 @@ describe('AudioDecoderFuncPromise', function () {
audioDecodeProcessor
=
null
;
},
failCallback
).
catch
(
failCatch
);
}
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
})
afterAll
(
function
()
{
...
...
@@ -286,14 +303,91 @@ 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
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
);
let
mediaType
=
mediaLibrary
.
MediaType
.
AUDIO
;
console
.
info
(
'
[mediaLibrary] case mediaType is
'
+
mediaType
);
let
publicPath
=
await
mediaTest
.
getPublicDirectory
(
mediaLibrary
.
DirectoryType
.
DIR_AUDIO
);
console
.
info
(
'
[mediaLibrary] case getFdWrite publicPath is
'
+
publicPath
);
let
dataUri
=
await
mediaTest
.
createAsset
(
mediaType
,
pathName
,
publicPath
);
if
(
dataUri
!=
undefined
)
{
let
args
=
dataUri
.
id
.
toString
();
let
fetchOp
=
{
selections
:
fileKeyObj
.
ID
+
"
=?
"
,
selectionArgs
:
[
args
],
}
let
fetchWriteFileResult
=
await
mediaTest
.
getFileAssets
(
fetchOp
);
console
.
info
(
'
[mediaLibrary] case getFdWrite getFileAssets() success
'
);
fileAsset
=
await
fetchWriteFileResult
.
getAllObject
();
console
.
info
(
'
[mediaLibrary] case getFdWrite getAllObject() success
'
);
fdWrite
=
await
fileAsset
[
0
].
open
(
'
Rw
'
);
console
.
info
(
'
[mediaLibrary] case getFdWrite fdWrite is
'
+
fdWrite
);
}
}
async
function
closeFdWrite
()
{
if
(
fileAsset
!=
null
)
{
await
fileAsset
[
0
].
close
(
fdWrite
).
then
(()
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite success, fd is
'
+
fdWrite
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite failed
'
);
});
}
else
{
console
.
info
(
'
[mediaLibrary] case fileAsset is null
'
);
}
}
function
writeFile
(
path
,
buf
,
len
)
{
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
num
=
writestream
.
writeSync
(
buf
,
{
length
:
len
});
writestream
.
flushSync
();
writestream
.
closeSync
();
}
catch
(
e
)
{
console
.
info
(
e
)
let
res
=
fileio
.
writeSync
(
fdWrite
,
buf
,
{
length
:
len
});
console
.
info
(
'
case fileio.writeSync buffer success
'
);
}
catch
(
e
)
{
console
.
info
(
'
case fileio.writeSync buffer error is
'
+
e
);
}
}
...
...
@@ -301,7 +395,7 @@ describe('AudioDecoderFuncPromise', function () {
console
.
info
(
'
read file start execution
'
);
try
{
console
.
info
(
'
filepath:
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
...
...
@@ -311,6 +405,7 @@ describe('AudioDecoderFuncPromise', function () {
console
.
info
(
"
case start get content
"
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
async
function
stopWork
()
{
...
...
@@ -329,13 +424,15 @@ describe('AudioDecoderFuncPromise', function () {
},
failCallback
).
catch
(
failCatch
);
}
async
function
flushWork
()
{
async
function
flushWork
(
done
)
{
inputQueue
=
[];
outputQueue
=
[];
await
closeFileDescriptor
(
readpath
);
await
getFdRead
(
readpath
,
done
);
await
audioDecodeProcessor
.
flush
().
then
(()
=>
{
console
.
info
(
"
case flush at inputeos success
"
);
resetParam
();
readFile
(
AUDIOPATH
);
readFile
(
readpath
);
workdoneAtEOS
=
true
;
},
failCallback
).
catch
(
failCatch
);
}
...
...
@@ -397,9 +494,11 @@ describe('AudioDecoderFuncPromise', function () {
}
else
if
(
resetAtEOS
)
{
await
resetWork
();
}
else
if
(
flushAtEOS
)
{
await
flushWork
();
await
flushWork
(
done
);
}
else
if
(
workdoneAtEOS
)
{
await
doneWork
();
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
done
();
}
else
{
console
.
info
(
"
saw output EOS
"
);
...
...
@@ -457,7 +556,10 @@ describe('AudioDecoderFuncPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0000.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_promise_00.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
workdoneAtEOS
=
true
;
needGetMediaDes
=
true
;
await
media
.
getMediaCapability
().
then
((
mediaCaps
)
=>
{
...
...
@@ -515,7 +617,10 @@ describe('AudioDecoderFuncPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0100.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_promise_01.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eosframenum
=
500
;
workdoneAtEOS
=
true
;
await
media
.
createAudioDecoderByMime
(
'
audio/mp4a-latm
'
).
then
((
processor
)
=>
{
...
...
@@ -555,7 +660,10 @@ describe('AudioDecoderFuncPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0200.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_promise_02.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
workdoneAtEOS
=
true
;
await
media
.
createAudioDecoderByMime
(
'
audio/mp4a-latm
'
).
then
((
processor
)
=>
{
console
.
info
(
"
case create createAudioDecoder success
"
);
...
...
@@ -600,7 +708,10 @@ describe('AudioDecoderFuncPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0300.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_promise_03.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eosframenum
=
200
;
flushAtEOS
=
true
;
await
media
.
createAudioDecoderByMime
(
'
audio/mp4a-latm
'
).
then
((
processor
)
=>
{
...
...
@@ -639,7 +750,10 @@ describe('AudioDecoderFuncPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0400.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_promise_04.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
await
media
.
createAudioDecoderByMime
(
'
audio/mp4a-latm
'
).
then
((
processor
)
=>
{
console
.
info
(
"
case create createAudioDecoder success
"
);
audioDecodeProcessor
=
processor
;
...
...
@@ -671,6 +785,8 @@ describe('AudioDecoderFuncPromise', function () {
console
.
info
(
"
case release success
"
);
},
failCallback
).
catch
(
failCatch
);
audioDecodeProcessor
=
null
;
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
done
();
})
...
...
@@ -689,7 +805,10 @@ describe('AudioDecoderFuncPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0500.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_promise_05.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eosframenum
=
200
;
await
media
.
createAudioDecoderByMime
(
'
audio/mp4a-latm
'
).
then
((
processor
)
=>
{
console
.
info
(
"
case create createAudioDecoder success
"
);
...
...
@@ -718,9 +837,11 @@ describe('AudioDecoderFuncPromise', function () {
},
failCallback
).
catch
(
failCatch
);
await
sleep
(
2000
).
then
(()
=>
{
console
.
info
(
"
case restart decoding after 2s
"
);
resetParam
();
readFile
(
AUDIOPATH
);
});
resetParam
();
await
closeFileDescriptor
(
readpath
);
await
getFdRead
(
readpath
,
done
);
readFile
(
readpath
);
await
audioDecodeProcessor
.
start
().
then
(()
=>
{
console
.
info
(
"
case restart after 3s success
"
);
workdoneAtEOS
=
true
;
...
...
@@ -748,7 +869,10 @@ describe('AudioDecoderFuncPromise', function () {
"
sample_rate
"
:
16000
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0600.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_promise_06.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eosframenum
=
200
;
resetAtEOS
=
true
;
await
media
.
createAudioDecoderByMime
(
'
audio/mp4a-latm
'
).
then
((
processor
)
=>
{
...
...
@@ -773,12 +897,18 @@ describe('AudioDecoderFuncPromise', function () {
await
sleep
(
10000
).
then
(()
=>
{
console
.
info
(
"
case start configure 2
"
);
});
resetParam
();
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
await
audioDecodeProcessor
.
configure
(
mediaDescription2
).
then
(()
=>
{
console
.
info
(
"
case configure 2 success
"
);
resetParam
();
readFile
(
AUDIOPATH2
);
},
failCallback
).
catch
(
failCatch
);
savepath
=
BASIC_PATH
+
'
0601.pcm
'
;
readpath
=
AUDIOPATH2
;
savepath
=
'
audioDecode_function_promise_06_2.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
readFile
(
AUDIOPATH2
);
workdoneAtEOS
=
true
;
ES
=
[
0
,
239
,
302
,
309
,
330
,
474
,
684
,
699
,
683
,
674
,
647
,
649
,
638
,
644
,
640
,
639
,
650
,
702
,
713
,
718
,
707
,
707
,
683
,
670
,
674
,
699
,
654
,
650
,
715
,
770
,
...
...
@@ -825,7 +955,10 @@ describe('AudioDecoderFuncPromise', function () {
"
sample_rate
"
:
48000
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0700.pcm
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioDecode_function_promise_07.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eosframenum
=
200
;
resetAtEOS
=
true
;
needrelease
=
true
;
...
...
@@ -851,6 +984,8 @@ 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
"
);
audioDecodeProcessor
=
processor
;
...
...
@@ -858,9 +993,12 @@ describe('AudioDecoderFuncPromise', function () {
await
audioDecodeProcessor
.
configure
(
mediaDescription2
).
then
(()
=>
{
console
.
info
(
"
case configure 2 success
"
);
resetParam
();
readFile
(
AUDIOPATH3
);
},
failCallback
).
catch
(
failCatch
);
savepath
=
BASIC_PATH
+
'
0701.pcm
'
;
readpath
=
AUDIOPATH3
;
savepath
=
'
audioDecode_function_promise_07_2.pcm
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
readFile
(
AUDIOPATH3
);
workdoneAtEOS
=
true
;
ES
=
[
0
,
2116
,
2093
,
2886
,
2859
,
2798
,
2778
,
2752
,
2752
,
2754
,
2720
,
2898
,
2829
,
2806
,
2796
,
2786
,
2774
,
2758
,
2741
,
3489
,
3342
,
3272
,
3167
,
3048
,
3060
,
2919
,
...
...
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderMultiInstancesTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -18,8 +18,8 @@ import Fileio from '@ohos.fileio'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
describe
(
'
AudioDecoderMultiInstances
'
,
function
()
{
const
RESOURCEPATH
=
'
/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.audio.audiodecoder
/
'
const
AUDIOPATH
=
RESOURCEPATH
+
'
AAC_48000_32_1.aac
'
;
const
RESOURCEPATH
=
'
/data/a
pp/el1/bundle/resources
/
'
const
AUDIOPATH
=
'
AAC_48000_32_1.aac
'
;
let
readStreamSync
;
let
eosframenum
=
0
;
let
samplerate
=
44.1
;
...
...
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderReliabilityCallbackTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,12 +14,13 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
Fileio
from
'
@ohos.fileio
'
import
fileio
from
'
@ohos.fileio
'
import
{
getFileDescriptor
,
closeFileDescriptor
}
from
'
./AudioDecoderTestBase.test.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
=
RESOURCEPATH
+
'
AAC_48000_32_1.aac
'
;
const
AUDIOPATH
=
'
AAC_48000_32_1.aac
'
;
const
BASIC_PATH
=
RESOURCEPATH
+
'
results/decode_reliability_callback
'
;
const
END
=
0
;
const
CONFIGURE
=
1
;
...
...
@@ -146,12 +147,13 @@ describe('AudioDecoderReliabilityCallback', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
};
let
fdRead
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
})
beforeEach
(
function
()
{
beforeEach
(
async
function
()
{
console
.
info
(
'
beforeEach case
'
);
audioDecodeProcessor
=
null
;
readStreamSync
=
undefined
;
...
...
@@ -266,10 +268,12 @@ describe('AudioDecoderReliabilityCallback', function () {
audioDecodeProcessor
=
null
;
},
failCallback
).
catch
(
failCatch
);
}
await
closeFileDescriptor
(
AUDIOPATH
);
})
afterAll
(
function
()
{
afterAll
(
async
function
()
{
console
.
info
(
'
afterAll case
'
);
await
closeFileDescriptor
(
AUDIOPATH
);
})
function
resetParam
()
{
...
...
@@ -287,7 +291,8 @@ describe('AudioDecoderReliabilityCallback', function () {
outputQueue
=
[];
}
function
createAudioDecoder
(
savepath
,
mySteps
,
done
)
{
async
function
createAudioDecoder
(
savepath
,
mySteps
,
done
)
{
await
getFdRead
(
AUDIOPATH
,
done
);
media
.
createAudioDecoderByMime
(
mime
,
(
err
,
processor
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
`case createAudioDecoder 1`
);
...
...
@@ -298,32 +303,34 @@ describe('AudioDecoderReliabilityCallback', function () {
})
}
function
writeFile
(
path
,
buf
,
len
)
{
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
num
=
writestream
.
writeSync
(
buf
,
{
length
:
len
});
writestream
.
flushSync
();
writestream
.
closeSync
();
}
catch
(
e
)
{
console
.
info
(
e
)
}
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
);
}
})
}
function
readFile
(
path
)
{
console
.
info
(
'
read file start execution
'
);
console
.
info
(
'
case
read file start execution
'
);
try
{
console
.
info
(
'
filepath:
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
console
.
info
(
'
case
filepath:
'
+
path
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
function
getContent
(
buf
,
len
)
{
console
.
info
(
"
start get content
"
);
console
.
info
(
"
case
start get content
"
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
info
(
'
lengthreal:
'
+
lengthreal
);
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
async
function
doneWork
(
done
)
{
...
...
@@ -352,7 +359,7 @@ describe('AudioDecoderReliabilityCallback', function () {
for
(
let
t
=
Date
.
now
();
Date
.
now
()
-
t
<=
time
;);
}
function
nextStep
(
mySteps
,
mediaDescription
,
done
)
{
async
function
nextStep
(
mySteps
,
mediaDescription
,
done
)
{
console
.
info
(
"
case myStep[0]:
"
+
mySteps
[
0
]);
if
(
mySteps
[
0
]
==
END
)
{
console
.
info
(
'
case to done
'
);
...
...
@@ -367,6 +374,7 @@ describe('AudioDecoderReliabilityCallback', function () {
case
CONFIGURE
:
mySteps
.
shift
();
console
.
info
(
`case to configure`
);
await
getFdRead
(
AUDIOPATH
,
done
);
audioDecodeProcessor
.
configure
(
mediaDescription
,
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
`case configure 1`
);
...
...
@@ -388,6 +396,8 @@ describe('AudioDecoderReliabilityCallback', function () {
console
.
info
(
`case to start`
);
if
(
sawOutputEOS
)
{
resetParam
();
await
closeFileDescriptor
(
AUDIOPATH
);
await
getFdRead
(
AUDIOPATH
,
done
);
readFile
(
AUDIOPATH
);
workdoneAtEOS
=
true
;
enqueueAllInputs
(
inputQueue
);
...
...
@@ -403,11 +413,13 @@ describe('AudioDecoderReliabilityCallback', function () {
console
.
info
(
`case to flush`
);
inputQueue
=
[];
outputQueue
=
[];
audioDecodeProcessor
.
flush
((
err
)
=>
{
audioDecodeProcessor
.
flush
(
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
`case flush 1`
);
if
(
flushAtEOS
)
{
resetParam
();
await
closeFileDescriptor
(
AUDIOPATH
);
await
getFdRead
(
AUDIOPATH
,
done
);
readFile
(
AUDIOPATH
);
workdoneAtEOS
=
true
;
flushAtEOS
=
false
;
...
...
@@ -1295,7 +1307,7 @@ describe('AudioDecoderReliabilityCallback', function () {
*/
it
(
'
SUB_MEDIA_AUDIO_DECODER_API_EOS_CALLBACK_0200
'
,
0
,
async
function
(
done
)
{
let
savepath
=
BASIC_PATH
+
'
eos_0200.pcm
'
;
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
FLUSH
,
WAITFORALLOUTS
);
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
FLUSH
,
END
);
EOSFrameNum
=
2
;
flushAtEOS
=
true
;
createAudioDecoder
(
savepath
,
mySteps
,
done
);
...
...
@@ -1326,7 +1338,7 @@ describe('AudioDecoderReliabilityCallback', function () {
*/
it
(
'
SUB_MEDIA_AUDIO_DECODER_API_EOS_CALLBACK_0400
'
,
0
,
async
function
(
done
)
{
let
savepath
=
BASIC_PATH
+
'
eos_0400.pcm
'
;
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
STOP
,
START
,
WAITFORALLOUTS
);
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
STOP
,
START
,
END
);
EOSFrameNum
=
2
;
createAudioDecoder
(
savepath
,
mySteps
,
done
);
})
...
...
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderReliabilityPromiseTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,12 +14,13 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
Fileio
from
'
@ohos.fileio
'
import
fileio
from
'
@ohos.fileio
'
import
{
getFileDescriptor
,
closeFileDescriptor
}
from
'
./AudioDecoderTestBase.test.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
=
RESOURCEPATH
+
'
AAC_48000_32_1.aac
'
;
const
AUDIOPATH
=
'
AAC_48000_32_1.aac
'
;
const
BASIC_PATH
=
RESOURCEPATH
+
'
results/decode_reliability_promise
'
;
const
END
=
0
;
const
CONFIGURE
=
1
;
...
...
@@ -148,12 +149,13 @@ describe('AudioDecoderReliabilityPromise', function () {
"
audio_sample_format
"
:
1
,
};
let
expectError
=
false
;
let
fdRead
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
})
beforeEach
(
function
()
{
beforeEach
(
async
function
()
{
console
.
info
(
'
beforeEach case
'
);
audioDecodeProcessor
=
null
;
readStreamSync
=
undefined
;
...
...
@@ -270,10 +272,12 @@ describe('AudioDecoderReliabilityPromise', function () {
audioDecodeProcessor
=
null
;
},
failCallback
).
catch
(
failCatch
);
}
await
closeFileDescriptor
(
AUDIOPATH
);
})
afterAll
(
function
()
{
afterAll
(
async
function
()
{
console
.
info
(
'
afterAll case
'
);
await
closeFileDescriptor
(
AUDIOPATH
);
})
let
failCallback
=
function
(
err
)
{
...
...
@@ -308,7 +312,8 @@ describe('AudioDecoderReliabilityPromise', function () {
outputQueue
=
[];
}
function
createAudioDecoder
(
savepath
,
mySteps
,
done
)
{
async
function
createAudioDecoder
(
savepath
,
mySteps
,
done
)
{
await
getFdRead
(
AUDIOPATH
,
done
);
media
.
createAudioDecoderByMime
(
mime
,
(
err
,
processor
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
`case createAudioDecoder 1`
);
...
...
@@ -319,22 +324,24 @@ describe('AudioDecoderReliabilityPromise', function () {
})
}
function
writeFile
(
path
,
buf
,
len
)
{
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
num
=
writestream
.
writeSync
(
buf
,
{
length
:
len
});
writestream
.
flushSync
();
writestream
.
closeSync
();
}
catch
(
e
)
{
console
.
info
(
e
)
}
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
);
}
})
}
function
readFile
(
path
)
{
console
.
info
(
'
read file start execution
'
);
console
.
info
(
'
case
read file start execution
'
);
try
{
console
.
info
(
'
filepath:
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
console
.
info
(
'
case
filepath:
'
+
path
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
...
...
@@ -344,7 +351,7 @@ describe('AudioDecoderReliabilityPromise', function () {
console
.
info
(
"
case start get content
"
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
info
(
'
lengthreal:
'
+
lengthreal
);
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
async
function
doneWork
()
{
...
...
@@ -369,7 +376,7 @@ describe('AudioDecoderReliabilityPromise', function () {
for
(
let
t
=
Date
.
now
();
Date
.
now
()
-
t
<=
time
;);
}
function
nextStep
(
mySteps
,
done
)
{
async
function
nextStep
(
mySteps
,
done
)
{
console
.
info
(
"
case myStep[0]:
"
+
mySteps
[
0
]);
if
(
mySteps
[
0
]
==
END
)
{
audioDecodeProcessor
.
release
().
then
(()
=>
{
...
...
@@ -401,6 +408,8 @@ describe('AudioDecoderReliabilityPromise', function () {
console
.
info
(
`case to start`
);
if
(
sawOutputEOS
)
{
resetParam
();
await
closeFileDescriptor
(
AUDIOPATH
);
await
getFdRead
(
AUDIOPATH
,
done
);
readFile
(
AUDIOPATH
);
workdoneAtEOS
=
true
;
enqueueAllInputs
(
inputQueue
);
...
...
@@ -415,9 +424,11 @@ describe('AudioDecoderReliabilityPromise', function () {
console
.
info
(
`case to flush`
);
inputQueue
=
[];
outputQueue
=
[];
audioDecodeProcessor
.
flush
().
then
(()
=>
{
audioDecodeProcessor
.
flush
().
then
(
async
()
=>
{
console
.
info
(
`case flush 1`
);
if
(
flushAtEOS
)
{
await
closeFileDescriptor
(
AUDIOPATH
);
await
getFdRead
(
AUDIOPATH
,
done
);
resetParam
();
readFile
(
AUDIOPATH
);
workdoneAtEOS
=
true
;
...
...
@@ -1296,7 +1307,7 @@ describe('AudioDecoderReliabilityPromise', function () {
*/
it
(
'
SUB_MEDIA_AUDIO_DECODER_API_EOS_PROMISE_0200
'
,
0
,
async
function
(
done
)
{
let
savepath
=
BASIC_PATH
+
'
eos_0200.pcm
'
;
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
FLUSH
,
WAITFORALLOUTS
);
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
FLUSH
,
END
);
EOSFrameNum
=
2
;
flushAtEOS
=
true
;
createAudioDecoder
(
savepath
,
mySteps
,
done
);
...
...
@@ -1327,7 +1338,7 @@ describe('AudioDecoderReliabilityPromise', function () {
*/
it
(
'
SUB_MEDIA_AUDIO_DECODER_API_EOS_PROMISE_0400
'
,
0
,
async
function
(
done
)
{
let
savepath
=
BASIC_PATH
+
'
eos_0400.pcm
'
;
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
STOP
,
START
,
WAITFORALLOUTS
);
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
STOP
,
START
,
END
);
EOSFrameNum
=
2
;
createAudioDecoder
(
savepath
,
mySteps
,
done
);
})
...
...
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/AudioDecoderTestBase.test.js
0 → 100644
浏览文件 @
8a36fea5
/*
* 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
);
});
});
}
multimedia/media/media_js_standard/audioDecoder/src/main/js/test/List.test.js
浏览文件 @
8a36fea5
...
...
@@ -13,7 +13,7 @@
* limitations under the License.
*/
require
(
'
./AudioDecoderTestBase.test.js
'
)
require
(
'
./AudioDecoderFuncPromiseTest.test.js
'
)
require
(
'
./AudioDecoderFuncCallbackTest.test.js
'
)
require
(
'
./AudioDecoderFormatPromiseTest.test.js
'
)
...
...
multimedia/media/media_js_standard/audioEncoder/Test.json
浏览文件 @
8a36fea5
...
...
@@ -14,21 +14,33 @@
"type"
:
"AppInstallKit"
,
"cleanup-apps"
:
true
},
{
"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/"
],
"teardown-command"
:[
]
},
{
"type"
:
"PushKit"
,
"pre-push"
:
[
],
"push"
:
[
"./resource/audio/audioEncode/S16LE.pcm ->/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.audio.audioencoder
/"
"./resource/audio/audioEncode/S16LE.pcm ->/data/a
pp/el1/bundle/public/ohos.acts.multimedia.audio.audioencoder/ohos.acts.multimedia.audio.audioencoder/assets/entry/resources/rawfile
/"
]
},
{
"type"
:
"ShellKit"
,
"run-command"
:
[
"rm -R /data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audioencoder/results"
,
"mkdir -p /data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audioencoder/results/"
,
"chmod 777 -R /data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audioencoder"
,
"chmod 777 /data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audioencoder/*"
"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 /storage/media/100/local/files/"
,
"chmod 777 /storage/media/100/local/files/*"
,
"killall com.ohos.medialibrary.MediaScannerAbilityA"
,
"aa start -a MediaScannerAbility -b com.ohos.medialibrary.MediaScannerAbilityA"
],
"teardown-command"
:[
]
...
...
multimedia/media/media_js_standard/audioEncoder/signature/openharmony_sx.p7b
浏览文件 @
8a36fea5
无法预览此类型文件
multimedia/media/media_js_standard/audioEncoder/src/main/config.json
浏览文件 @
8a36fea5
...
...
@@ -49,6 +49,28 @@
"tv"
,
"wearable"
],
"reqPermissions"
:
[
{
"name"
:
"ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
,
"reason"
:
"use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
{
"name"
:
"ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
,
"reason"
:
"use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
},
{
"name"
:
"ohos.permission.MEDIA_LOCATION"
,
"reason"
:
"use ohos.permission.MEDIA_LOCATION"
},
{
"name"
:
"ohos.permission.READ_MEDIA"
,
"reason"
:
"use ohos.permission.READ_MEDIA"
},
{
"name"
:
"ohos.permission.WRITE_MEDIA"
,
"reason"
:
"use ohos.permission.WRITE_MEDIA"
}
],
"mainAbility"
:
"ohos.acts.multimedia.audio.audioencoder.MainAbility"
,
"distro"
:
{
"moduleType"
:
"entry"
,
...
...
multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderFuncCallbackTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,12 +14,17 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
Fileio
from
'
@ohos.fileio
'
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
{
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
=
RESOURCEPATH
+
'
S16LE.pcm
'
;
const
AUDIOPATH
=
'
S16LE.pcm
'
;
const
BASIC_PATH
=
RESOURCEPATH
+
'
results/encode_func_callback_
'
;
let
audioEncodeProcessor
;
let
readStreamSync
;
...
...
@@ -38,9 +43,19 @@ describe('AudioEncoderFuncCallback', function () {
let
outputQueue
=
[];
const
ES
=
[
0
,
4096
];
let
ES_LENGTH
=
1500
;
let
readpath
;
let
savepath
;
let
fdRead
;
let
fdWrite
;
let
fileAsset
;
const
context
=
featureAbility
.
getContext
();
const
mediaTest
=
mediaLibrary
.
getMediaLibrary
(
context
);
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
beforeAll
(
async
function
()
{
console
.
info
(
'
beforeAll case 1
'
);
await
applyPermission
();
console
.
info
(
'
beforeAll case after get permission
'
);
})
beforeEach
(
function
()
{
...
...
@@ -71,10 +86,13 @@ describe('AudioEncoderFuncCallback', function () {
audioEncodeProcessor
=
null
;
},
failCallback
).
catch
(
failCatch
);
}
await
closeFileDescriptor
(
AUDIOPATH
);
await
closeFdWrite
();
})
afterAll
(
function
()
{
afterAll
(
async
function
()
{
console
.
info
(
'
afterAll case
'
);
await
closeFileDescriptor
(
AUDIOPATH
);
})
function
resetParam
()
{
...
...
@@ -94,47 +112,124 @@ describe('AudioEncoderFuncCallback', function () {
outputQueue
=
[];
}
function
writeHead
(
path
,
len
)
{
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
head
=
new
ArrayBuffer
(
7
);
addADTStoPacket
(
head
,
len
);
let
num
=
writestream
.
writeSync
(
head
,
{
length
:
7
});
console
.
info
(
'
writeSync head num =
'
+
num
);
writestream
.
flushSync
();
writestream
.
closeSync
();
}
catch
(
e
)
{
console
.
info
(
e
);
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
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
'
);
}
}
function
writeFile
(
path
,
buf
,
len
)
{
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
num
=
writestream
.
writeSync
(
buf
,
{
length
:
len
});
writestream
.
flushSync
();
writestream
.
closeSync
();
}
catch
(
e
)
{
console
.
info
(
e
);
async
function
getFdWrite
(
pathName
)
{
console
.
info
(
'
[mediaLibrary] case start getFdWrite
'
);
console
.
info
(
'
[mediaLibrary] case getFdWrite pathName is
'
+
pathName
);
let
mediaType
=
mediaLibrary
.
MediaType
.
AUDIO
;
console
.
info
(
'
[mediaLibrary] case mediaType is
'
+
mediaType
);
let
publicPath
=
await
mediaTest
.
getPublicDirectory
(
mediaLibrary
.
DirectoryType
.
DIR_AUDIO
);
console
.
info
(
'
[mediaLibrary] case getFdWrite publicPath is
'
+
publicPath
);
let
dataUri
=
await
mediaTest
.
createAsset
(
mediaType
,
pathName
,
publicPath
);
if
(
dataUri
!=
undefined
)
{
let
args
=
dataUri
.
id
.
toString
();
let
fetchOp
=
{
selections
:
fileKeyObj
.
ID
+
"
=?
"
,
selectionArgs
:
[
args
],
}
let
fetchWriteFileResult
=
await
mediaTest
.
getFileAssets
(
fetchOp
);
console
.
info
(
'
[mediaLibrary] case getFdWrite getFileAssets() success
'
);
fileAsset
=
await
fetchWriteFileResult
.
getAllObject
();
console
.
info
(
'
[mediaLibrary] case getFdWrite getAllObject() success
'
);
fdWrite
=
await
fileAsset
[
0
].
open
(
'
Rw
'
);
console
.
info
(
'
[mediaLibrary] case getFdWrite fdWrite is
'
+
fdWrite
);
}
}
async
function
closeFdWrite
()
{
if
(
fileAsset
!=
null
)
{
await
fileAsset
[
0
].
close
(
fdWrite
).
then
(()
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite success, fd is
'
+
fdWrite
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite failed
'
);
});
}
else
{
console
.
info
(
'
[mediaLibrary] case fileAsset is null
'
);
}
}
function
readFile
(
path
)
{
console
.
info
(
'
case read file start execution
'
);
try
{
console
.
info
(
'
filepath:
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
'
case
filepath:
'
+
path
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
function
getContent
(
buf
,
len
)
{
console
.
info
(
"
case start get content
"
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
info
(
'
lengthreal:
'
+
lengthreal
);
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
function
writeHead
(
path
,
len
)
{
console
.
info
(
'
case writeFile buffer.length is:
'
+
len
);
try
{
let
head
=
new
ArrayBuffer
(
7
);
addADTStoPacket
(
head
,
len
);
let
res
=
fileio
.
writeSync
(
fdWrite
,
head
,
{
length
:
7
});
console
.
info
(
'
case fileio.write head success
'
);
}
catch
(
e
)
{
console
.
info
(
'
case fileio.write head error is
'
+
e
);
}
}
function
writeFile
(
path
,
buf
,
len
)
{
try
{
let
res
=
fileio
.
writeSync
(
fdWrite
,
buf
,
{
length
:
len
});
console
.
info
(
'
case fileio.write buffer success
'
);
}
catch
(
e
)
{
console
.
info
(
'
case fileio.write buffer error is
'
+
e
);
}
}
function
addADTStoPacket
(
head
,
len
)
{
let
view
=
new
Uint8Array
(
head
)
let
view
=
new
Uint8Array
(
head
)
;
console
.
info
(
"
start add ADTS to Packet
"
);
let
packetLen
=
len
+
7
;
// 7: head length
let
profile
=
2
;
// 2: AAC LC
...
...
@@ -171,9 +266,11 @@ describe('AudioEncoderFuncCallback', function () {
})
}
async
function
flushWork
()
{
async
function
flushWork
(
done
)
{
inputQueue
=
[];
outputQueue
=
[];
await
closeFileDescriptor
(
readpath
);
await
getFdRead
(
readpath
,
done
);
audioEncodeProcessor
.
flush
((
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
"
case flush at inputeos success
"
);
...
...
@@ -190,10 +287,12 @@ describe('AudioEncoderFuncCallback', function () {
resetParam
();
audioEncodeProcessor
.
reset
((
err
)
=>
{
expect
(
err
).
assertUndefined
();
audioEncodeProcessor
.
release
((
err
)
=>
{
audioEncodeProcessor
.
release
(
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
log
(
"
case release success
"
);
audioEncodeProcessor
=
null
;
await
closeFileDescriptor
(
AUDIOPATH
);
await
closeFdWrite
();
done
();
})
})
...
...
@@ -243,7 +342,7 @@ describe('AudioEncoderFuncCallback', function () {
}
else
if
(
resetAtEOS
)
{
await
resetWork
();
}
else
if
(
flushAtEOS
)
{
await
flushWork
();
await
flushWork
(
done
);
}
else
if
(
workdoneAtEOS
)
{
await
doneWork
(
done
);
}
else
{
...
...
@@ -309,7 +408,10 @@ describe('AudioEncoderFuncCallback', function () {
let
mediaDescription2
=
{
"
codec_mime
"
:
'
audio/mp4a-latm
'
,
}
let
savepath
=
BASIC_PATH
+
'
0000.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_callback_00.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needGetMediaDes
=
true
;
workdoneAtEOS
=
true
;
eventEmitter
.
on
(
'
getAudioEncoderCaps
'
,
()
=>
{
...
...
@@ -347,7 +449,7 @@ describe('AudioEncoderFuncCallback', function () {
console
.
info
(
`case getMediaCapability 1`
);
mediaCaps
.
getAudioEncoderCaps
((
err
,
audioCaps
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
'
getAudio
De
coderCaps success
'
);
console
.
info
(
'
getAudio
En
coderCaps success
'
);
if
(
typeof
(
audioCaps
)
!=
'
undefined
'
)
{
console
.
info
(
"
case audioCaps
"
+
audioCaps
);
}
else
{
...
...
@@ -389,7 +491,10 @@ describe('AudioEncoderFuncCallback', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0100.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_callback_01.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eosframenum
=
500
;
workdoneAtEOS
=
true
;
eventEmitter
.
on
(
'
getAudioEncoderCaps
'
,
()
=>
{
...
...
@@ -447,7 +552,10 @@ describe('AudioEncoderFuncCallback', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0200.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_callback_02.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
workdoneAtEOS
=
true
;
eventEmitter
.
on
(
'
getAudioEncoderCaps
'
,
()
=>
{
audioEncodeProcessor
.
getAudioEncoderCaps
((
err
,
Audiocaps
)
=>
{
...
...
@@ -513,7 +621,10 @@ describe('AudioEncoderFuncCallback', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0300.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_callback_03.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eosframenum
=
500
;
flushAtEOS
=
true
;
eventEmitter
.
on
(
'
getAudioEncoderCaps
'
,
()
=>
{
...
...
@@ -571,7 +682,10 @@ describe('AudioEncoderFuncCallback', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0400.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_callback_04.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eventEmitter
.
on
(
'
getAudioEncoderCaps
'
,
()
=>
{
audioEncodeProcessor
.
getAudioEncoderCaps
((
err
,
Audiocaps
)
=>
{
expect
(
err
).
assertUndefined
();
...
...
@@ -621,10 +735,12 @@ describe('AudioEncoderFuncCallback', function () {
})
});
eventEmitter
.
on
(
'
release
'
,
()
=>
{
audioEncodeProcessor
.
release
((
err
)
=>
{
audioEncodeProcessor
.
release
(
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
`case release 1`
);
audioEncodeProcessor
=
null
;
await
closeFileDescriptor
(
AUDIOPATH
);
await
closeFdWrite
();
done
();
})
});
...
...
@@ -653,7 +769,10 @@ describe('AudioEncoderFuncCallback', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0500.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_callback_05.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eosframenum
=
100
;
eventEmitter
.
on
(
'
getAudioEncoderCaps
'
,
()
=>
{
audioEncodeProcessor
.
getAudioEncoderCaps
((
err
,
Audiocaps
)
=>
{
...
...
@@ -698,7 +817,11 @@ describe('AudioEncoderFuncCallback', function () {
})
});
eventEmitter
.
on
(
'
restart
'
,
()
=>
{
sleep
(
2000
).
then
(()
=>
{
sleep
(
2000
).
then
(
async
()
=>
{
resetParam
();
await
closeFileDescriptor
(
readpath
);
await
getFdRead
(
readpath
,
done
);
readFile
(
readpath
);
audioEncodeProcessor
.
start
((
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
`restart after 2s`
);
...
...
@@ -732,7 +855,10 @@ describe('AudioEncoderFuncCallback', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0600.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_callback_06.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eosframenum
=
100
;
resetAtEOS
=
true
;
let
mediaDescription2
=
{
...
...
@@ -775,13 +901,19 @@ describe('AudioEncoderFuncCallback', function () {
})
});
eventEmitter
.
on
(
'
reconfigure
'
,
(
mediaDescription2
)
=>
{
sleep
(
10000
).
then
(()
=>
{
audioEncodeProcessor
.
configure
(
mediaDescription2
,
(
err
)
=>
{
sleep
(
10000
).
then
(
async
()
=>
{
resetParam
();
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
audioEncodeProcessor
.
configure
(
mediaDescription2
,
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
`case configure 2`
);
resetParam
();
readFile
(
AUDIOPATH
)
savepath
=
BASIC_PATH
+
'
0601.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_callback_06_2.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
readFile
(
AUDIOPATH
);
workdoneAtEOS
=
true
;
hasreconfigured
=
true
;
eventEmitter
.
emit
(
'
prepare
'
);
...
...
multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderFuncPromiseTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,12 +14,17 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
Fileio
from
'
@ohos.fileio
'
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
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
describe
(
'
AudioEncoderFuncPromise
'
,
function
()
{
const
RESOURCEPATH
=
'
/data/accounts/account_0/appdata/ohos.acts.multimedia.audio.audioencoder/
'
const
AUDIOPATH
=
RESOURCEPATH
+
'
S16LE.pcm
'
;
const
AUDIOPATH
=
'
S16LE.pcm
'
;
const
BASIC_PATH
=
RESOURCEPATH
+
'
results/encode_func_promise_
'
;
let
audioEncodeProcessor
;
let
readStreamSync
;
...
...
@@ -38,9 +43,19 @@ describe('AudioEncoderFuncPromise', function () {
let
outputQueue
=
[];
const
ES
=
[
0
,
4096
];
let
ES_LENGTH
=
1500
;
let
readpath
;
let
savepath
;
let
fdRead
;
let
fdWrite
;
let
fileAsset
;
const
context
=
featureAbility
.
getContext
();
const
mediaTest
=
mediaLibrary
.
getMediaLibrary
(
context
);
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
beforeAll
(
async
function
()
{
console
.
info
(
'
beforeAll case 1
'
);
await
applyPermission
();
console
.
info
(
'
beforeAll case after get permission
'
);
})
beforeEach
(
function
()
{
...
...
@@ -71,10 +86,13 @@ describe('AudioEncoderFuncPromise', function () {
audioEncodeProcessor
=
null
;
},
failCallback
).
catch
(
failCatch
);
}
await
closeFileDescriptor
(
AUDIOPATH
);
await
closeFdWrite
();
})
afterAll
(
function
()
{
afterAll
(
async
function
()
{
console
.
info
(
'
afterAll case
'
);
await
closeFileDescriptor
(
AUDIOPATH
);
})
let
failCallback
=
function
(
err
)
{
...
...
@@ -104,35 +122,90 @@ describe('AudioEncoderFuncPromise', function () {
outputQueue
=
[];
}
function
writeHead
(
path
,
len
)
{
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
head
=
new
ArrayBuffer
(
7
);
addADTStoPacket
(
head
,
len
);
let
num
=
writestream
.
writeSync
(
head
,
{
length
:
7
});
writestream
.
flushSync
();
writestream
.
closeSync
();
}
catch
(
e
)
{
console
.
info
(
e
)
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
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
'
);
}
}
function
writeFile
(
path
,
buf
,
len
)
{
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
num
=
writestream
.
writeSync
(
buf
,
{
length
:
len
});
writestream
.
flushSync
();
writestream
.
closeSync
();
}
catch
(
e
)
{
console
.
info
(
e
);
async
function
getFdWrite
(
pathName
)
{
console
.
info
(
'
[mediaLibrary] case start getFdWrite
'
);
console
.
info
(
'
[mediaLibrary] case getFdWrite pathName is
'
+
pathName
);
let
mediaType
=
mediaLibrary
.
MediaType
.
AUDIO
;
console
.
info
(
'
[mediaLibrary] case mediaType is
'
+
mediaType
);
let
publicPath
=
await
mediaTest
.
getPublicDirectory
(
mediaLibrary
.
DirectoryType
.
DIR_AUDIO
);
console
.
info
(
'
[mediaLibrary] case getFdWrite publicPath is
'
+
publicPath
);
let
dataUri
=
await
mediaTest
.
createAsset
(
mediaType
,
pathName
,
publicPath
);
if
(
dataUri
!=
undefined
)
{
let
args
=
dataUri
.
id
.
toString
();
let
fetchOp
=
{
selections
:
fileKeyObj
.
ID
+
"
=?
"
,
selectionArgs
:
[
args
],
}
let
fetchWriteFileResult
=
await
mediaTest
.
getFileAssets
(
fetchOp
);
console
.
info
(
'
[mediaLibrary] case getFdWrite getFileAssets() success
'
);
fileAsset
=
await
fetchWriteFileResult
.
getAllObject
();
console
.
info
(
'
[mediaLibrary] case getFdWrite getAllObject() success
'
);
fdWrite
=
await
fileAsset
[
0
].
open
(
'
Rw
'
);
console
.
info
(
'
[mediaLibrary] case getFdWrite fdWrite is
'
+
fdWrite
);
}
}
async
function
closeFdWrite
()
{
if
(
fileAsset
!=
null
)
{
await
fileAsset
[
0
].
close
(
fdWrite
).
then
(()
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite success, fd is
'
+
fdWrite
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite failed
'
);
});
}
else
{
console
.
info
(
'
[mediaLibrary] case fileAsset is null
'
);
}
}
function
readFile
(
path
)
{
console
.
info
(
'
read file start execution
'
);
try
{
console
.
info
(
'
filepath:
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
...
...
@@ -141,7 +214,27 @@ describe('AudioEncoderFuncPromise', function () {
console
.
info
(
"
case start get content
"
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
info
(
'
lengthreal:
'
+
lengthreal
);
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
function
writeHead
(
path
,
len
)
{
try
{
let
head
=
new
ArrayBuffer
(
7
);
addADTStoPacket
(
head
,
len
);
let
res
=
fileio
.
writeSync
(
fdWrite
,
head
,
{
length
:
7
});
console
.
info
(
'
case fileio.write head success
'
);
}
catch
(
e
)
{
console
.
info
(
'
case fileio.write head error is
'
+
e
);
}
}
function
writeFile
(
path
,
buf
,
len
)
{
try
{
let
res
=
fileio
.
writeSync
(
fdWrite
,
buf
,
{
length
:
len
});
console
.
info
(
'
case fileio.write buffer success
'
);
}
catch
(
e
)
{
console
.
info
(
'
case fileio.write buffer error is
'
+
e
);
}
}
function
addADTStoPacket
(
head
,
len
)
{
...
...
@@ -179,9 +272,11 @@ describe('AudioEncoderFuncPromise', function () {
},
failCallback
).
catch
(
failCatch
);
}
async
function
flushWork
()
{
async
function
flushWork
(
done
)
{
inputQueue
=
[];
outputQueue
=
[];
await
closeFileDescriptor
(
readpath
);
await
getFdRead
(
readpath
,
done
);
await
audioEncodeProcessor
.
flush
().
then
(()
=>
{
console
.
info
(
"
case flush at inputeos success
"
);
resetParam
();
...
...
@@ -248,9 +343,11 @@ describe('AudioEncoderFuncPromise', function () {
}
else
if
(
resetAtEOS
)
{
await
resetWork
();
}
else
if
(
flushAtEOS
)
{
await
flushWork
();
await
flushWork
(
done
);
}
else
if
(
workdoneAtEOS
)
{
await
doneWork
();
await
closeFileDescriptor
(
AUDIOPATH
);
await
closeFdWrite
();
done
();
}
else
{
console
.
info
(
'
sawOutputEOS = true
'
);
...
...
@@ -312,7 +409,10 @@ describe('AudioEncoderFuncPromise', function () {
let
mediaDescription2
=
{
"
codec_mime
"
:
'
audio/mp4a-latm
'
,
}
let
savepath
=
BASIC_PATH
+
'
0000.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_promise_00.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
needgetMediaDes
=
true
;
workdoneAtEOS
=
true
;
await
media
.
getMediaCapability
().
then
((
mediaCaps
)
=>
{
...
...
@@ -374,7 +474,10 @@ describe('AudioEncoderFuncPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0100.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_promise_01.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eosframenum
=
500
;
workdoneAtEOS
=
true
;
await
media
.
createAudioEncoderByMime
(
'
audio/mp4a-latm
'
).
then
((
processor
)
=>
{
...
...
@@ -413,7 +516,10 @@ describe('AudioEncoderFuncPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0200.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_promise_02.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
workdoneAtEOS
=
true
;
await
media
.
createAudioEncoderByMime
(
'
audio/mp4a-latm
'
).
then
((
processor
)
=>
{
console
.
info
(
"
case create createAudioEncoder success
"
);
...
...
@@ -458,7 +564,10 @@ describe('AudioEncoderFuncPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0300.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_promise_03.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eosframenum
=
500
;
flushAtEOS
=
true
;
await
media
.
createAudioEncoderByMime
(
'
audio/mp4a-latm
'
).
then
((
processor
)
=>
{
...
...
@@ -497,7 +606,10 @@ describe('AudioEncoderFuncPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0400.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_promise_04.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
await
media
.
createAudioEncoderByMime
(
'
audio/mp4a-latm
'
).
then
((
processor
)
=>
{
console
.
info
(
"
case create createAudioEncoder success
"
);
audioEncodeProcessor
=
processor
;
...
...
@@ -529,6 +641,8 @@ describe('AudioEncoderFuncPromise', function () {
console
.
info
(
"
case release success
"
);
},
failCallback
).
catch
(
failCatch
);
audioEncodeProcessor
=
null
;
await
closeFileDescriptor
(
AUDIOPATH
);
await
closeFdWrite
();
done
();
})
...
...
@@ -547,7 +661,10 @@ describe('AudioEncoderFuncPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0500.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_promise_05.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eosframenum
=
100
;
await
media
.
createAudioEncoderByMime
(
'
audio/mp4a-latm
'
).
then
((
processor
)
=>
{
console
.
info
(
"
case create createAudioEncoder success
"
);
...
...
@@ -576,9 +693,11 @@ describe('AudioEncoderFuncPromise', function () {
},
failCallback
).
catch
(
failCatch
);
await
sleep
(
2000
).
then
(()
=>
{
console
.
info
(
"
restart encoding after 2s
"
);
resetParam
();
readFile
(
AUDIOPATH
);
});
resetParam
();
await
closeFileDescriptor
(
readpath
);
await
getFdRead
(
readpath
,
done
);
readFile
(
readpath
);
await
audioEncodeProcessor
.
start
().
then
(()
=>
{
console
.
info
(
"
case restart after 3s success
"
);
workdoneAtEOS
=
true
;
...
...
@@ -601,7 +720,10 @@ describe('AudioEncoderFuncPromise', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
}
let
savepath
=
BASIC_PATH
+
'
0600.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_promise_06.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
eosframenum
=
100
;
resetAtEOS
=
true
;
await
media
.
createAudioEncoderByMime
(
'
audio/mp4a-latm
'
).
then
((
processor
)
=>
{
...
...
@@ -631,14 +753,20 @@ describe('AudioEncoderFuncPromise', function () {
await
sleep
(
10000
).
then
(()
=>
{
console
.
info
(
"
start configure 2
"
);
});
resetParam
();
await
closeFileDescriptor
(
readpath
);
await
closeFdWrite
();
await
audioEncodeProcessor
.
configure
(
mediaDescription2
).
then
(()
=>
{
console
.
info
(
"
configure 2 success
"
);
resetParam
();
readFile
(
AUDIOPATH
);
},
failCallback
).
catch
(
failCatch
);
let
savepath2
=
BASIC_PATH
+
'
0601.aac
'
;
readpath
=
AUDIOPATH
;
savepath
=
'
audioEncode_function_promise_06_2.aac
'
;
await
getFdWrite
(
savepath
);
await
getFdRead
(
readpath
,
done
);
readFile
(
AUDIOPATH
);
workdoneAtEOS
=
true
;
setCallback
(
savepath
2
,
done
);
setCallback
(
savepath
,
done
);
await
audioEncodeProcessor
.
prepare
().
then
(()
=>
{
console
.
info
(
"
prepare2 success
"
);
},
failCallback
).
catch
(
failCatch
);
...
...
multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderReliabilityCallbackTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,12 +14,13 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
Fileio
from
'
@ohos.fileio
'
import
fileio
from
'
@ohos.fileio
'
import
{
getFileDescriptor
,
closeFileDescriptor
}
from
'
./AudioEncoderTestBase.test.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
=
RESOURCEPATH
+
'
S16LE.pcm
'
;
const
AUDIOPATH
=
'
S16LE.pcm
'
;
const
BASIC_PATH
=
RESOURCEPATH
+
'
results/encode_reliability_callback_
'
;
const
END
=
0
;
const
CONFIGURE
=
1
;
...
...
@@ -58,12 +59,13 @@ describe('AudioEncoderReliabilityCallback', function () {
"
sample_rate
"
:
44100
,
"
audio_sample_format
"
:
1
,
};
let
fdRead
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
})
beforeEach
(
function
()
{
beforeEach
(
async
function
()
{
console
.
info
(
'
beforeEach case
'
);
audioEncodeProcessor
=
null
;
readStreamSync
=
undefined
;
...
...
@@ -89,10 +91,12 @@ describe('AudioEncoderReliabilityCallback', function () {
},
failCallback
).
catch
(
failCatch
);
audioEncodeProcessor
=
null
;
}
await
closeFileDescriptor
(
AUDIOPATH
);
})
afterAll
(
function
()
{
afterAll
(
async
function
()
{
console
.
info
(
'
afterAll case
'
);
await
closeFileDescriptor
(
AUDIOPATH
);
})
function
resetParam
()
{
...
...
@@ -110,7 +114,8 @@ describe('AudioEncoderReliabilityCallback', function () {
outputQueue
=
[];
}
function
createAudioEncoder
(
savepath
,
mySteps
,
done
)
{
async
function
createAudioEncoder
(
savepath
,
mySteps
,
done
)
{
await
getFdRead
(
AUDIOPATH
,
done
);
media
.
createAudioEncoderByMime
(
mime
,
(
err
,
processor
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
`case createAudioEncoder 1`
);
...
...
@@ -121,59 +126,34 @@ describe('AudioEncoderReliabilityCallback', function () {
})
}
function
writeHead
(
path
,
len
)
{
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
head
=
new
ArrayBuffer
(
7
);
addADTStoPacket
(
head
,
len
);
let
num
=
writestream
.
writeSync
(
head
,
{
length
:
7
});
console
.
info
(
'
writeSync head num =
'
+
num
);
writestream
.
flushSync
();
writestream
.
closeSync
();
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
function
writeFile
(
path
,
buf
,
len
)
{
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
num
=
writestream
.
writeSync
(
buf
,
{
length
:
len
});
writestream
.
flushSync
();
writestream
.
closeSync
();
}
catch
(
e
)
{
console
.
info
(
e
);
}
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
);
}
})
}
function
readFile
(
path
)
{
console
.
info
(
'
read file start execution
'
);
try
{
console
.
info
(
'
filepath:
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
function
getContent
(
buf
,
len
)
{
console
.
info
(
"
case start get content
"
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
info
(
'
lengthreal:
'
+
lengthreal
);
}
function
addADTStoPacket
(
head
,
len
)
{
let
view
=
new
Uint8Array
(
head
)
console
.
info
(
"
start add ADTS to Packet
"
);
let
packetLen
=
len
+
7
;
// 7: head length
let
profile
=
2
;
// 2: AAC LC
let
freqIdx
=
4
;
// 4: 44100HZ
let
chanCfg
=
2
;
// 2: 2 channel
view
[
0
]
=
0xFF
;
view
[
1
]
=
0xF9
;
view
[
2
]
=
((
profile
-
1
)
<<
6
)
+
(
freqIdx
<<
2
)
+
(
chanCfg
>>
2
);
view
[
3
]
=
((
chanCfg
&
3
)
<<
6
)
+
(
packetLen
>>
11
);
view
[
4
]
=
(
packetLen
&
0x7FF
)
>>
3
;
view
[
5
]
=
((
packetLen
&
7
)
<<
5
)
+
0x1F
;
view
[
6
]
=
0xFC
;
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
async
function
doneWork
(
done
)
{
...
...
@@ -202,7 +182,7 @@ describe('AudioEncoderReliabilityCallback', function () {
for
(
let
t
=
Date
.
now
();
Date
.
now
()
-
t
<=
time
;);
}
function
nextStep
(
mySteps
,
mediaDescription
,
done
)
{
async
function
nextStep
(
mySteps
,
mediaDescription
,
done
)
{
console
.
info
(
"
case myStep[0]:
"
+
mySteps
[
0
]);
if
(
mySteps
[
0
]
==
END
)
{
audioEncodeProcessor
.
release
((
err
)
=>
{
...
...
@@ -237,6 +217,8 @@ describe('AudioEncoderReliabilityCallback', function () {
console
.
info
(
`case to start`
);
if
(
sawOutputEOS
)
{
resetParam
();
await
closeFileDescriptor
(
AUDIOPATH
);
await
getFdRead
(
AUDIOPATH
,
done
);
readFile
(
AUDIOPATH
);
workdoneAtEOS
=
true
;
enqueueAllInputs
(
inputQueue
);
...
...
@@ -252,10 +234,12 @@ describe('AudioEncoderReliabilityCallback', function () {
console
.
info
(
`case to flush`
);
inputQueue
=
[];
outputQueue
=
[];
audioEncodeProcessor
.
flush
((
err
)
=>
{
audioEncodeProcessor
.
flush
(
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
`case flush 1`
);
if
(
flushAtEOS
)
{
await
closeFileDescriptor
(
AUDIOPATH
);
await
getFdRead
(
AUDIOPATH
,
done
);
resetParam
();
readFile
(
AUDIOPATH
);
workdoneAtEOS
=
true
;
...
...
@@ -1143,7 +1127,7 @@ describe('AudioEncoderReliabilityCallback', function () {
*/
it
(
'
SUB_MEDIA_AUDIO_ENCODER_API_EOS_CALLBACK_0200
'
,
0
,
async
function
(
done
)
{
let
savepath
=
BASIC_PATH
+
'
eos_0200.es
'
;
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
FLUSH
,
WAITFORALLOUTS
);
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
FLUSH
,
END
);
EOSFrameNum
=
2
;
flushAtEOS
=
true
;
createAudioEncoder
(
savepath
,
mySteps
,
done
);
...
...
@@ -1174,7 +1158,7 @@ describe('AudioEncoderReliabilityCallback', function () {
*/
it
(
'
SUB_MEDIA_AUDIO_ENCODER_API_EOS_CALLBACK_0400
'
,
0
,
async
function
(
done
)
{
let
savepath
=
BASIC_PATH
+
'
eos_0400.es
'
;
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
STOP
,
START
,
WAITFORALLOUTS
);
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
STOP
,
START
,
END
);
EOSFrameNum
=
2
;
createAudioEncoder
(
savepath
,
mySteps
,
done
);
})
...
...
multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderReliabilityPromiseTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,12 +14,13 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
Fileio
from
'
@ohos.fileio
'
import
fileio
from
'
@ohos.fileio
'
import
{
getFileDescriptor
,
closeFileDescriptor
}
from
'
./AudioEncoderTestBase.test.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
=
RESOURCEPATH
+
'
S16LE.pcm
'
;
const
AUDIOPATH
=
'
S16LE.pcm
'
;
const
BASIC_PATH
=
RESOURCEPATH
+
'
results/encode_reliability_promise_
'
;
const
END
=
0
;
const
CONFIGURE
=
1
;
...
...
@@ -59,12 +60,13 @@ describe('AudioEncoderReliabilityPromise', function () {
"
audio_sample_format
"
:
1
,
};
let
expectError
=
false
;
let
fdRead
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
})
beforeEach
(
function
()
{
beforeEach
(
async
function
()
{
console
.
info
(
'
beforeEach case
'
);
audioEncodeProcessor
=
null
;
readStreamSync
=
undefined
;
...
...
@@ -91,10 +93,12 @@ describe('AudioEncoderReliabilityPromise', function () {
},
failCallback
).
catch
(
failCatch
);
audioEncodeProcessor
=
null
;
}
await
closeFileDescriptor
(
AUDIOPATH
);
})
afterAll
(
function
()
{
afterAll
(
async
function
()
{
console
.
info
(
'
afterAll case
'
);
await
closeFileDescriptor
(
AUDIOPATH
);
})
let
failCallback
=
function
(
err
)
{
...
...
@@ -128,7 +132,8 @@ describe('AudioEncoderReliabilityPromise', function () {
outputQueue
=
[];
}
function
createAudioEncoder
(
savepath
,
mySteps
,
done
)
{
async
function
createAudioEncoder
(
savepath
,
mySteps
,
done
)
{
await
getFdRead
(
AUDIOPATH
,
done
);
media
.
createAudioEncoderByMime
(
mime
).
then
((
processor
)
=>
{
console
.
info
(
`case createAudioEncoder 1`
);
audioEncodeProcessor
=
processor
;
...
...
@@ -138,35 +143,25 @@ describe('AudioEncoderReliabilityPromise', function () {
},
failCallback
).
catch
(
failCatch
);
}
function
writeHead
(
path
,
len
)
{
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
head
=
new
ArrayBuffer
(
7
);
addADTStoPacket
(
head
,
len
);
let
num
=
writestream
.
writeSync
(
head
,
{
length
:
7
});
writestream
.
flushSync
();
writestream
.
closeSync
();
}
catch
(
e
)
{
console
.
info
(
e
)
}
}
function
writeFile
(
path
,
buf
,
len
)
{
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
num
=
writestream
.
writeSync
(
buf
,
{
length
:
len
});
writestream
.
flushSync
();
writestream
.
closeSync
();
}
catch
(
e
)
{
console
.
info
(
e
);
}
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
);
}
})
}
function
readFile
(
path
)
{
console
.
info
(
'
read file start execution
'
);
try
{
console
.
info
(
'
filepath:
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
...
...
@@ -175,23 +170,7 @@ describe('AudioEncoderReliabilityPromise', function () {
console
.
info
(
"
case start get content
"
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
info
(
'
lengthreal:
'
+
lengthreal
);
}
function
addADTStoPacket
(
head
,
len
)
{
let
view
=
new
Uint8Array
(
head
);
console
.
info
(
"
start add ADTS to Packet
"
);
let
packetLen
=
len
+
7
;
// 7: head length
let
profile
=
2
;
// 2: AAC LC
let
freqIdx
=
4
;
// 4: 44100HZ
let
chanCfg
=
2
;
// 2: 2 channel
view
[
0
]
=
0xFF
;
view
[
1
]
=
0xF9
;
view
[
2
]
=
((
profile
-
1
)
<<
6
)
+
(
freqIdx
<<
2
)
+
(
chanCfg
>>
2
);
view
[
3
]
=
((
chanCfg
&
3
)
<<
6
)
+
(
packetLen
>>
11
);
view
[
4
]
=
(
packetLen
&
0x7FF
)
>>
3
;
view
[
5
]
=
((
packetLen
&
7
)
<<
5
)
+
0x1F
;
view
[
6
]
=
0xFC
;
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
async
function
doneWork
()
{
...
...
@@ -208,7 +187,6 @@ describe('AudioEncoderReliabilityPromise', function () {
audioEncodeProcessor
=
null
;
}
function
sleep
(
time
)
{
return
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
time
));
}
...
...
@@ -217,7 +195,7 @@ describe('AudioEncoderReliabilityPromise', function () {
for
(
let
t
=
Date
.
now
();
Date
.
now
()
-
t
<=
time
;);
}
function
nextStep
(
mySteps
,
done
)
{
async
function
nextStep
(
mySteps
,
done
)
{
console
.
info
(
"
case myStep[0]:
"
+
mySteps
[
0
]);
if
(
mySteps
[
0
]
==
END
)
{
audioEncodeProcessor
.
release
().
then
(()
=>
{
...
...
@@ -249,6 +227,8 @@ describe('AudioEncoderReliabilityPromise', function () {
console
.
info
(
`case to start`
);
if
(
sawOutputEOS
)
{
resetParam
();
await
closeFileDescriptor
(
AUDIOPATH
);
await
getFdRead
(
AUDIOPATH
,
done
);
readFile
(
AUDIOPATH
);
workdoneAtEOS
=
true
;
enqueueInputs
(
inputQueue
);
...
...
@@ -263,9 +243,11 @@ describe('AudioEncoderReliabilityPromise', function () {
console
.
info
(
`case to flush`
);
inputQueue
=
[];
outputQueue
=
[];
audioEncodeProcessor
.
flush
().
then
(()
=>
{
audioEncodeProcessor
.
flush
().
then
(
async
()
=>
{
console
.
info
(
`case flush 1`
);
if
(
flushAtEOS
)
{
await
closeFileDescriptor
(
AUDIOPATH
);
await
getFdRead
(
AUDIOPATH
,
done
);
resetParam
();
readFile
(
AUDIOPATH
);
workdoneAtEOS
=
true
;
...
...
@@ -1147,7 +1129,7 @@ describe('AudioEncoderReliabilityPromise', function () {
*/
it
(
'
SUB_MEDIA_AUDIO_ENCODER_API_EOS_PROMISE_0200
'
,
0
,
async
function
(
done
)
{
let
savepath
=
BASIC_PATH
+
'
eos_0200.es
'
;
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
FLUSH
,
WAITFORALLOUTS
);
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
FLUSH
,
END
);
EOSFrameNum
=
2
;
flushAtEOS
=
true
;
createAudioEncoder
(
savepath
,
mySteps
,
done
);
...
...
@@ -1178,7 +1160,7 @@ describe('AudioEncoderReliabilityPromise', function () {
*/
it
(
'
SUB_MEDIA_AUDIO_ENCODER_API_EOS_PROMISE_0400
'
,
0
,
async
function
(
done
)
{
let
savepath
=
BASIC_PATH
+
'
eos_0400.es
'
;
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
STOP
,
START
,
WAITFORALLOUTS
);
let
mySteps
=
new
Array
(
CONFIGURE
,
PREPARE
,
START
,
HOLDON
,
JUDGE_EOS
,
STOP
,
START
,
END
);
EOSFrameNum
=
2
;
createAudioEncoder
(
savepath
,
mySteps
,
done
);
})
...
...
multimedia/media/media_js_standard/audioEncoder/src/main/js/test/AudioEncoderTestBase.test.js
0 → 100644
浏览文件 @
8a36fea5
/*
* 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
);
});
});
}
multimedia/media/media_js_standard/audioEncoder/src/main/js/test/List.test.js
浏览文件 @
8a36fea5
...
...
@@ -13,6 +13,7 @@
* limitations under the License.
*/
require
(
'
./AudioEncoderTestBase.test.js
'
)
require
(
'
./AudioEncoderFuncCallbackTest.test.js
'
)
require
(
'
./AudioEncoderFuncPromiseTest.test.js
'
)
require
(
'
./AudioEncoderReliabilityCallbackTest.test.js
'
)
...
...
multimedia/media/media_js_standard/videoDecoder/Test.json
浏览文件 @
8a36fea5
...
...
@@ -14,23 +14,33 @@
"type"
:
"AppInstallKit"
,
"cleanup-apps"
:
true
},
{
"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/"
],
"teardown-command"
:[
]
},
{
"type"
:
"PushKit"
,
"pre-push"
:
[
],
"push"
:
[
"./resource/media/es/out_1920_1080_30fps_3s.h264 ->/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder
/"
,
"./resource/media/es/h263_1408_1152.es ->/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder
/"
,
"./resource/media/es/MPEG2_720_480.es ->/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder
/"
,
"./resource/media/es/mpeg4_320_240.es ->/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder
/"
,
"./resource/media/es/out_320_240_10s.h264 ->/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder
/"
"./resource/media/es/out_1920_1080_30fps_3s.h264 ->/data/a
pp/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/a
pp/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/a
pp/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/a
pp/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/a
pp/el1/bundle/public/ohos.acts.multimedia.video.videodecoder/ohos.acts.multimedia.video.videodecoder/assets/entry/resources/rawfile
/"
]
},
{
"type"
:
"ShellKit"
,
"run-command"
:
[
"chmod 777 -R /data/a
ccounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder
"
,
"chmod 777 /data/a
ccounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder
/*"
"chmod 777 -R /data/a
pp/el1/bundle/public/ohos.acts.multimedia.video.videodecoder/ohos.acts.multimedia.video.videodecoder/assets/entry/resources/rawfile/
"
,
"chmod 777 /data/a
pp/el1/bundle/public/ohos.acts.multimedia.video.videodecoder/ohos.acts.multimedia.video.videodecoder/assets/entry/resources/rawfile
/*"
],
"teardown-command"
:[
]
...
...
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/List.test.js
浏览文件 @
8a36fea5
...
...
@@ -22,3 +22,4 @@ require('./VideoDecoderSoftwareFuncPromiseTest.test.js')
require
(
'
./VideoDecoderSoftwareReliCallbackTest.test.js
'
)
require
(
'
./VideoDecoderSoftwareReliPromiseTest.test.js
'
)
require
(
'
./VideoDecoderEnumTest.test.js
'
)
require
(
'
./VideoDecoderTestBase.test.js
'
)
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderEnumTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,8 +14,9 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
F
ileio
from
'
@ohos.fileio
'
import
f
ileio
from
'
@ohos.fileio
'
import
router
from
'
@system.router
'
import
{
getFileDescriptor
,
closeFileDescriptor
}
from
'
./VideoDecoderTestBase.test.js
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
...
...
@@ -37,6 +38,9 @@ describe('VideoDecoderEnum', function () {
let
ES_FRAME_SIZE
=
[];
const
H264_FRAME_SIZE_60FPS_320
=
[
2106
,
11465
];
let
readpath
;
let
fdRead
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
// getSurfaceID();
...
...
@@ -83,16 +87,24 @@ describe('VideoDecoderEnum', function () {
console
.
info
(
`in case error failCatch called,errMessage is
${
error
.
message
}
`
);
expect
(
err
).
assertUndefined
();
}
function
readFile
(
path
){
console
.
info
(
'
in case : read file start execution
'
);
try
{
console
.
info
(
'
in case: filepath
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
function
readFile
(
path
)
{
console
.
info
(
'
case read file start execution
'
);
try
{
console
.
info
(
'
case filepath:
'
+
path
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
error
(
'
in case readFile
'
+
e
);
}
}
function
getContent
(
buf
,
len
)
{
console
.
info
(
"
case start get content
"
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
function
msleep
(
ms
)
{
return
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
ms
));
}
...
...
@@ -109,22 +121,9 @@ describe('VideoDecoderEnum', function () {
}
}
function
getContent
(
buf
,
len
)
{
console
.
info
(
'
start get content, len
'
+
len
+
'
buf.byteLength
'
+
buf
.
byteLength
);
let
lengthReal
=
-
1
;
try
{
lengthReal
=
readStreamSync
.
readSync
(
buf
,
{
length
:
len
}
);
console
.
info
(
'
in case: lengthReal:
'
+
lengthReal
);
}
catch
(
e
)
{
console
.
error
(
'
in case error getContent
'
+
e
);
}
}
function
getSurfaceID
()
{
let
surfaceIDTest
=
new
ArrayBuffer
(
20
);
let
readSurfaceID
=
F
ileio
.
createStreamSync
(
'
/data/media/surfaceID.txt
'
,
'
rb
'
);
let
readSurfaceID
=
f
ileio
.
createStreamSync
(
'
/data/media/surfaceID.txt
'
,
'
rb
'
);
readSurfaceID
.
readSync
(
surfaceIDTest
,
{
length
:
13
});
let
view2
=
new
Uint8Array
(
surfaceIDTest
);
for
(
let
i
=
0
;
i
<
13
;
i
++
)
{
...
...
@@ -290,6 +289,7 @@ describe('VideoDecoderEnum', function () {
},
failCallback
).
catch
(
failCatch
);
videoDecodeProcessor
=
null
;
console
.
info
(
'
in case : done
'
);
await
closeFileDescriptor
(
readpath
);
done
();
});
async
function
toPrepare
()
{
...
...
@@ -314,7 +314,18 @@ describe('VideoDecoderEnum', function () {
it
(
'
SUB_MEDIA_VIDEO_DECODER_ENUM_CodecBuffer_0100
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
H264_FRAME_SIZE_60FPS_320
;
isCodecData
=
true
;
let
srcPath
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
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
);
}
})
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderFuncCallbackTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,8 +14,9 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
F
ileio
from
'
@ohos.fileio
'
import
f
ileio
from
'
@ohos.fileio
'
import
router
from
'
@system.router
'
import
{
getFileDescriptor
,
closeFileDescriptor
}
from
'
./VideoDecoderTestBase.test.js
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
describe
(
'
VideoDecoderFuncCallbackTest
'
,
function
()
{
...
...
@@ -91,6 +92,9 @@ describe('VideoDecoderFuncCallbackTest', function () {
295
,
206
,
264
,
349
,
4071
,
242
,
296
,
271
,
231
,
307
,
265
,
254
,
267
,
317
,
232
,
348
,
4077
,
259
,
222
,
268
,
235
,
324
,
266
,
256
,
312
,
246
,
248
,
325
,
4000
,
266
,
201
,
230
,
293
,
264
,
265
,
273
,
301
,
304
,
253
,
266
,
3978
,
228
,
232
,
250
,
248
,
281
,
219
,
243
,
293
,
287
,
253
,
328
,
3719
];
let
fdRead
;
let
readpath
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
})
...
...
@@ -153,27 +157,35 @@ describe('VideoDecoderFuncCallbackTest', function () {
}
}
function
readFile
(
path
){
console
.
info
(
'
in case : read file start execution
'
);
try
{
console
.
info
(
'
in case: filepath
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
'
in case error readFile
'
+
e
);
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
);
}
})
}
function
readFile
(
path
)
{
console
.
info
(
'
case read file start execution
'
);
try
{
console
.
info
(
'
case filepath:
'
+
path
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
function
getContent
(
buf
,
len
)
{
console
.
info
(
'
start get content, len
'
+
len
+
'
buf.byteLength
'
+
buf
.
byteLength
);
let
lengthReal
=
-
1
;
try
{
lengthReal
=
readStreamSync
.
readSync
(
buf
,
{
length
:
len
}
);
console
.
info
(
'
in case: lengthReal:
'
+
lengthReal
);
}
catch
(
e
)
{
console
.
error
(
'
in case error getContent:
'
+
e
);
}
console
.
info
(
"
case start get content
"
);
console
.
info
(
"
case getcontent length is:
"
+
len
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
/* push inputbuffers into codec */
...
...
@@ -329,10 +341,11 @@ describe('VideoDecoderFuncCallbackTest', function () {
});
});
eventEmitter
.
on
(
'
release
'
,
(
done
)
=>
{
videoDecodeProcessor
.
release
((
err
)
=>
{
videoDecodeProcessor
.
release
(
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
'
in case : release success
'
);
videoDecodeProcessor
=
null
;
await
closeFileDescriptor
(
readpath
);
done
();
});
});
...
...
@@ -348,7 +361,9 @@ describe('VideoDecoderFuncCallbackTest', function () {
it
(
'
SUB_MEDIA_VIDEO_DECODER_H264_CALLBACK_0100
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
H264_FRAME_SIZE_60FPS_320
;
isCodecData
=
true
;
let
srcPath
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
let
srcPath
=
'
out_320_240_10s.h264
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
@@ -380,7 +395,9 @@ describe('VideoDecoderFuncCallbackTest', function () {
*/
it
(
'
SUB_MEDIA_VIDEO_DECODER_MPEG2_CALLBACK_0100
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
MPEG2_FRAME_SIZE
;
let
srcPath
=
BASIC_PATH
+
'
MPEG2_720_480.es
'
;
let
srcPath
=
'
MPEG2_720_480.es
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/mpeg2
'
,
...
...
@@ -412,7 +429,9 @@ describe('VideoDecoderFuncCallbackTest', function () {
*/
it
(
'
SUB_MEDIA_VIDEO_DECODER_MPEG4_CALLBACK_0100
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
MPEG4_FRAME_SIZE
;
let
srcPath
=
BASIC_PATH
+
'
mpeg4_320_240.es
'
;
let
srcPath
=
'
mpeg4_320_240.es
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/mp4v-es
'
,
...
...
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderFuncPromiseTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,8 +14,9 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
F
ileio
from
'
@ohos.fileio
'
import
f
ileio
from
'
@ohos.fileio
'
import
router
from
'
@system.router
'
import
{
getFileDescriptor
,
closeFileDescriptor
}
from
'
./VideoDecoderTestBase.test.js
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
...
...
@@ -92,6 +93,9 @@ describe('VideoDecoderFuncPromiseTest', function () {
295
,
206
,
264
,
349
,
4071
,
242
,
296
,
271
,
231
,
307
,
265
,
254
,
267
,
317
,
232
,
348
,
4077
,
259
,
222
,
268
,
235
,
324
,
266
,
256
,
312
,
246
,
248
,
325
,
4000
,
266
,
201
,
230
,
293
,
264
,
265
,
273
,
301
,
304
,
253
,
266
,
3978
,
228
,
232
,
250
,
248
,
281
,
219
,
243
,
293
,
287
,
253
,
328
,
3719
];
let
fdRead
;
let
readpath
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
// getSurfaceID();
...
...
@@ -151,40 +155,36 @@ describe('VideoDecoderFuncPromiseTest', function () {
console
.
error
(
'
in case toDisplayPage
'
+
e
);
}
}
function
readFile
(
path
){
console
.
info
(
'
in case : read file start execution
'
);
try
{
console
.
info
(
'
in case: filepath
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
console
.
error
(
'
in case readFile
'
+
e
);
}
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
);
}
})
}
function
getContent
(
buf
,
len
)
{
console
.
info
(
'
start get content, len
'
+
len
+
'
buf.byteLength
'
+
buf
.
byteLength
);
let
lengthReal
=
-
1
;
try
{
lengthReal
=
readStreamSync
.
readSync
(
buf
,
{
length
:
len
}
);
console
.
info
(
'
in case: lengthReal:
'
+
lengthReal
);
}
catch
(
e
)
{
console
.
error
(
'
in case error getContent
'
+
e
);
function
readFile
(
path
)
{
console
.
info
(
'
case read file start execution
'
);
try
{
console
.
info
(
'
case filepath:
'
+
path
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
function
getSurfaceID
()
{
let
surfaceIDTest
=
new
ArrayBuffer
(
20
);
let
readSurfaceID
=
Fileio
.
createStreamSync
(
'
/data/media/surfaceID.txt
'
,
'
rb
'
);
readSurfaceID
.
readSync
(
surfaceIDTest
,
{
length
:
13
});
let
view2
=
new
Uint8Array
(
surfaceIDTest
);
for
(
let
i
=
0
;
i
<
13
;
i
++
)
{
let
value
=
view2
[
i
]
-
48
;
surfaceID
=
surfaceID
+
''
+
value
;
}
console
.
info
(
'
in case surfaceID
'
+
surfaceID
);
readSurfaceID
.
closeSync
();
function
getContent
(
buf
,
len
)
{
console
.
info
(
"
case start get content
"
);
console
.
info
(
"
case start get content length is:
"
+
len
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
/* push inputbuffers into codec */
...
...
@@ -317,6 +317,7 @@ describe('VideoDecoderFuncPromiseTest', function () {
console
.
info
(
'
in case : release success
'
);
},
failCallback
).
catch
(
failCatch
);
videoDecodeProcessor
=
null
;
await
closeFileDescriptor
(
readpath
);
console
.
info
(
'
in case : done
'
);
done
();
});
...
...
@@ -342,7 +343,9 @@ describe('VideoDecoderFuncPromiseTest', function () {
it
(
'
SUB_MEDIA_VIDEO_DECODER_H264_PROMISE_0100
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
H264_FRAME_SIZE_60FPS_320
;
isCodecData
=
true
;
let
srcPath
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
let
srcPath
=
'
out_320_240_10s.h264
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
@@ -373,7 +376,9 @@ describe('VideoDecoderFuncPromiseTest', function () {
*/
it
(
'
SUB_MEDIA_VIDEO_DECODER_MPEG2_PROMISE_0100
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
MPEG2_FRAME_SIZE
;
let
srcPath
=
BASIC_PATH
+
'
MPEG2_720_480.es
'
;
let
srcPath
=
'
MPEG2_720_480.es
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/mpeg2
'
,
...
...
@@ -404,7 +409,9 @@ describe('VideoDecoderFuncPromiseTest', function () {
*/
it
(
'
SUB_MEDIA_VIDEO_DECODER_MPEG4_PROMISE_0100
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
MPEG4_FRAME_SIZE
;
let
srcPath
=
BASIC_PATH
+
'
mpeg4_320_240.es
'
;
let
srcPath
=
'
mpeg4_320_240.es
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/mp4v-es
'
,
...
...
@@ -436,7 +443,9 @@ describe('VideoDecoderFuncPromiseTest', function () {
it
(
'
SUB_MEDIA_VIDEO_DECODER_MULTIINSTANCE_PROMISE_0100
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
H264_FRAME_SIZE_60FPS_320
;
isCodecData
=
true
;
let
srcPath
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
let
srcPath
=
'
out_320_240_10s.h264
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
@@ -457,6 +466,7 @@ describe('VideoDecoderFuncPromiseTest', function () {
console
.
info
(
'
in case : release success
'
);
},
failCallback
).
catch
(
failCatch
);
videoDecodeProcessor
=
null
;
await
closeFileDescriptor
(
readpath
);
done
();
})
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
...
...
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderReliCallbackTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,10 +14,11 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
F
ileio
from
'
@ohos.fileio
'
import
f
ileio
from
'
@ohos.fileio
'
import
router
from
'
@system.router
'
import
{
getFileDescriptor
,
closeFileDescriptor
}
from
'
./VideoDecoderTestBase.test.js
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
export
const
DECODE_STEP
=
{
WAIT_FOR_EOS
:
'
waitForEOS
'
,
CONFIGURE
:
'
configure
'
,
...
...
@@ -47,7 +48,7 @@ describe('VideoDecoderReliCallbackTest', function () {
let
workdoneAtEOS
=
false
;
let
surfaceID
=
''
;
const
BASIC_PATH
=
'
/data/accounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder/
'
;
const
SRCPATH
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
const
SRCPATH
=
'
out_320_240_10s.h264
'
;
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
@@ -74,6 +75,8 @@ describe('VideoDecoderReliCallbackTest', function () {
574
,
126
,
1242
,
188
,
130
,
119
,
1450
,
187
,
137
,
141
,
1116
,
124
,
1848
,
138
,
122
,
1605
,
186
,
127
,
140
,
1798
,
170
,
124
,
121
,
1666
,
157
,
128
,
130
,
1678
,
135
,
118
,
1804
,
169
,
135
,
125
,
1837
,
168
,
124
,
124
];
let
ES_FRAME_SIZE
=
H264_FRAME_SIZE_60FPS_320
;
let
fdRead
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
})
...
...
@@ -107,10 +110,12 @@ describe('VideoDecoderReliCallbackTest', function () {
}
await
router
.
clear
().
then
(()
=>
{
},
failCallback
).
catch
(
failCatch
);
await
closeFileDescriptor
(
SRCPATH
);
})
afterAll
(
function
()
{
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
}
`
);
...
...
@@ -141,18 +146,19 @@ describe('VideoDecoderReliCallbackTest', function () {
console
.
error
(
'
in case toDisplayPage
'
+
e
);
}
}
function
readFile
(
path
){
console
.
info
(
'
in case : read file start execution
'
);
try
{
console
.
info
(
'
in case: file path
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
'
in case readFile
'
+
e
);
function
readFile
(
path
)
{
console
.
info
(
'
case read file start execution
'
);
try
{
console
.
info
(
'
case filepath:
'
+
path
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
function
getContent
(
buf
,
pos
,
len
)
{
console
.
info
(
'
start get content, len
'
+
len
+
'
buf.byteLength
'
+
buf
.
byteLength
);
console
.
info
(
'
case
start get content, len
'
+
len
+
'
buf.byteLength
'
+
buf
.
byteLength
);
let
lengthReal
=
-
1
;
try
{
if
(
pos
==
-
1
)
{
...
...
@@ -279,10 +285,11 @@ describe('VideoDecoderReliCallbackTest', function () {
console
.
info
(
'
case myStep[0]:
'
+
mySteps
[
0
]);
if
(
mySteps
[
0
]
==
DECODE_STEP
.
RELEASE
)
{
if
(
videoDecodeProcessor
!=
null
){
videoDecodeProcessor
.
release
((
err
)
=>
{
videoDecodeProcessor
.
release
(
async
(
err
)
=>
{
printError
(
err
,
false
);
console
.
info
(
'
in case : videoDecodeProcessor release callback
'
);
videoDecodeProcessor
=
null
;
await
closeFileDescriptor
(
SRCPATH
);
console
.
info
(
'
case to done
'
);
done
();
});
...
...
@@ -408,7 +415,17 @@ describe('VideoDecoderReliCallbackTest', function () {
});
}
function
toCreateVideoDecoderByMime
(
mime
,
mySteps
,
done
)
{
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
);
}
})
media
.
createVideoDecoderByMime
(
mime
,
(
err
,
processor
)
=>
{
console
.
info
(
`case createVideoDecoderByMime callback`
);
printError
(
err
,
false
);
...
...
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderReliPromiseTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,10 +14,11 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
F
ileio
from
'
@ohos.fileio
'
import
f
ileio
from
'
@ohos.fileio
'
import
router
from
'
@system.router
'
import
{
getFileDescriptor
,
closeFileDescriptor
}
from
'
./VideoDecoderTestBase.test.js
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
export
const
DECODE_STEP
=
{
WAIT_FOR_EOS
:
'
waitForEOS
'
,
CONFIGURE
:
'
configure
'
,
...
...
@@ -47,7 +48,7 @@ describe('VideoDecoderReliPromiseTest', function () {
let
workdoneAtEOS
=
false
;
let
surfaceID
=
''
;
const
BASIC_PATH
=
'
/data/accounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder/
'
;
const
SRCPATH
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
const
SRCPATH
=
'
out_320_240_10s.h264
'
;
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
@@ -74,6 +75,8 @@ describe('VideoDecoderReliPromiseTest', function () {
574
,
126
,
1242
,
188
,
130
,
119
,
1450
,
187
,
137
,
141
,
1116
,
124
,
1848
,
138
,
122
,
1605
,
186
,
127
,
140
,
1798
,
170
,
124
,
121
,
1666
,
157
,
128
,
130
,
1678
,
135
,
118
,
1804
,
169
,
135
,
125
,
1837
,
168
,
124
,
124
];
let
ES_FRAME_SIZE
=
H264_FRAME_SIZE_60FPS_320
;
let
fdRead
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
})
...
...
@@ -107,10 +110,12 @@ describe('VideoDecoderReliPromiseTest', function () {
}
await
router
.
clear
().
then
(()
=>
{
},
failCallback
).
catch
(
failCatch
);
await
closeFileDescriptor
(
SRCPATH
);
})
afterAll
(
function
()
{
afterAll
(
async
function
()
{
console
.
info
(
'
afterAll case
'
);
await
closeFileDescriptor
(
SRCPATH
);
})
let
caseCallback
=
function
(
err
)
{
console
.
info
(
`in case caseCallback called, caseMessage is
${
err
.
message
}
`
);
...
...
@@ -147,13 +152,14 @@ describe('VideoDecoderReliPromiseTest', function () {
console
.
error
(
'
in case toDisplayPage
'
+
e
);
}
}
function
readFile
(
path
){
console
.
info
(
'
in case : read file start execution
'
);
try
{
console
.
info
(
'
in case: file path
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
'
in case readFile
'
+
e
);
function
readFile
(
path
)
{
console
.
info
(
'
case read file start execution
'
);
try
{
console
.
info
(
'
case filepath:
'
+
path
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
...
...
@@ -277,9 +283,10 @@ describe('VideoDecoderReliPromiseTest', function () {
console
.
info
(
'
case myStep[0]:
'
+
mySteps
[
0
]);
if
(
mySteps
[
0
]
==
DECODE_STEP
.
RELEASE
)
{
if
(
videoDecodeProcessor
!=
null
)
{
videoDecodeProcessor
.
release
().
then
(()
=>
{
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
);
...
...
@@ -405,7 +412,17 @@ describe('VideoDecoderReliPromiseTest', function () {
});
}
function
toCreateVideoDecoderByMime
(
mime
,
mySteps
,
done
)
{
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
);
}
})
media
.
createVideoDecoderByMime
(
mime
).
then
((
processor
)
=>
{
console
.
info
(
`case createVideoDecoderByMime success`
);
videoDecodeProcessor
=
processor
;
...
...
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareFuncCallbackTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,8 +14,9 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
F
ileio
from
'
@ohos.fileio
'
import
f
ileio
from
'
@ohos.fileio
'
import
router
from
'
@system.router
'
import
{
getFileDescriptor
,
closeFileDescriptor
}
from
'
./VideoDecoderTestBase.test.js
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
describe
(
'
VideoDecoderFuncCallbackTest
'
,
function
()
{
...
...
@@ -107,6 +108,9 @@ describe('VideoDecoderFuncCallbackTest', function () {
295
,
206
,
264
,
349
,
4071
,
242
,
296
,
271
,
231
,
307
,
265
,
254
,
267
,
317
,
232
,
348
,
4077
,
259
,
222
,
268
,
235
,
324
,
266
,
256
,
312
,
246
,
248
,
325
,
4000
,
266
,
201
,
230
,
293
,
264
,
265
,
273
,
301
,
304
,
253
,
266
,
3978
,
228
,
232
,
250
,
248
,
281
,
219
,
243
,
293
,
287
,
253
,
328
,
3719
];
let
fdRead
;
let
readpath
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
})
...
...
@@ -137,6 +141,7 @@ describe('VideoDecoderFuncCallbackTest', function () {
}
await
router
.
clear
().
then
(()
=>
{
},
failCallback
).
catch
(
failCatch
);
await
closeFileDescriptor
(
readpath
);
})
afterAll
(
function
()
{
...
...
@@ -165,27 +170,36 @@ describe('VideoDecoderFuncCallbackTest', function () {
console
.
error
(
'
in case toDisplayPage
'
+
e
);
}
}
function
readFile
(
path
){
console
.
info
(
'
in case : read file start execution
'
);
try
{
console
.
info
(
'
in case: filepath
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
'
in case error readFile
'
+
e
);
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
);
}
})
}
function
readFile
(
path
)
{
console
.
info
(
'
case read file start execution
'
);
try
{
console
.
info
(
'
case filepath:
'
+
path
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
function
getContent
(
buf
,
len
)
{
console
.
info
(
'
start get content, len
'
+
len
+
'
buf.byteLength
'
+
buf
.
byteLength
);
let
lengthReal
=
-
1
;
try
{
lengthReal
=
readStreamSync
.
readSync
(
buf
,
{
length
:
len
}
);
console
.
info
(
'
in case: lengthReal:
'
+
lengthReal
);
}
catch
(
e
)
{
console
.
error
(
'
in case error getContent:
'
+
e
);
}
console
.
info
(
"
case start get content
"
);
console
.
info
(
"
case start get content length is:
"
+
len
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
/* push inputbuffers into codec */
...
...
@@ -302,10 +316,11 @@ describe('VideoDecoderFuncCallbackTest', function () {
});
});
eventEmitter
.
on
(
'
release
'
,
(
done
)
=>
{
videoDecodeProcessor
.
release
((
err
)
=>
{
videoDecodeProcessor
.
release
(
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
'
in case : release success
'
);
videoDecodeProcessor
=
null
;
await
closeFileDescriptor
(
readpath
);
done
();
});
});
...
...
@@ -321,7 +336,9 @@ describe('VideoDecoderFuncCallbackTest', function () {
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_DECODER_H264_CALLBACK_0100
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
H264_FRAME_SIZE_240
;
isCodecData
=
true
;
let
srcPath
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
let
srcPath
=
'
out_320_240_10s.h264
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
@@ -352,7 +369,9 @@ describe('VideoDecoderFuncCallbackTest', function () {
*/
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_DECODER_MPEG2_CALLBACK_0100
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
MPEG2_FRAME_SIZE
;
let
srcPath
=
BASIC_PATH
+
'
MPEG2_720_480.es
'
;
let
srcPath
=
'
MPEG2_720_480.es
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/mpeg2
'
,
...
...
@@ -383,7 +402,9 @@ describe('VideoDecoderFuncCallbackTest', function () {
*/
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_DECODER_MPEG4_CALLBACK_0100
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
MPEG4_FRAME_SIZE
;
let
srcPath
=
BASIC_PATH
+
'
mpeg4_320_240.es
'
;
let
srcPath
=
'
mpeg4_320_240.es
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/mp4v-es
'
,
...
...
@@ -415,7 +436,9 @@ describe('VideoDecoderFuncCallbackTest', function () {
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_DECODER_FUNCTION_CALLBACK_01_0600
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
H264_FRAME_SIZE_240
;
isCodecData
=
true
;
let
srcPath
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
let
srcPath
=
'
out_320_240_10s.h264
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
@@ -444,6 +467,8 @@ describe('VideoDecoderFuncCallbackTest', function () {
isCodecData
=
true
;
inputEosFlag
=
false
;
readStreamSync
=
null
;
await
closeFileDescriptor
(
readpath
);
await
getFdRead
(
readpath
,
done
);
await
toDisplayPage
().
then
(()
=>
{
},
failCallback
).
catch
(
failCatch
);
await
msleep
(
1000
).
then
(()
=>
{
...
...
@@ -477,7 +502,9 @@ describe('VideoDecoderFuncCallbackTest', function () {
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_DECODER_FUNCTION_CALLBACK_01_0700
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
H264_FRAME_SIZE_240
;
isCodecData
=
true
;
let
srcPath
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
let
srcPath
=
'
out_320_240_10s.h264
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
@@ -488,9 +515,10 @@ describe('VideoDecoderFuncCallbackTest', function () {
'
max_input_size
'
:
150000
,
}
eventEmitter
.
on
(
'
stop_for_callback_01_0700
'
,
(
done
)
=>
{
videoDecodeProcessor
.
stop
((
err
)
=>
{
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
);
});
});
...
...
@@ -498,7 +526,9 @@ describe('VideoDecoderFuncCallbackTest', function () {
videoDecodeProcessor
.
reset
(
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
'
in case : reset_for_callback_01_0700 success
'
);
srcPath
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
srcPath
=
'
out_320_240_10s.h264
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareFuncPromiseTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,8 +14,9 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
F
ileio
from
'
@ohos.fileio
'
import
f
ileio
from
'
@ohos.fileio
'
import
router
from
'
@system.router
'
import
{
getFileDescriptor
,
closeFileDescriptor
}
from
'
./VideoDecoderTestBase.test.js
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
...
...
@@ -108,6 +109,9 @@ describe('VideoDecoderFuncPromiseTest', function () {
295
,
206
,
264
,
349
,
4071
,
242
,
296
,
271
,
231
,
307
,
265
,
254
,
267
,
317
,
232
,
348
,
4077
,
259
,
222
,
268
,
235
,
324
,
266
,
256
,
312
,
246
,
248
,
325
,
4000
,
266
,
201
,
230
,
293
,
264
,
265
,
273
,
301
,
304
,
253
,
266
,
3978
,
228
,
232
,
250
,
248
,
281
,
219
,
243
,
293
,
287
,
253
,
328
,
3719
];
let
fdRead
;
let
readpath
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
})
...
...
@@ -138,6 +142,7 @@ describe('VideoDecoderFuncPromiseTest', function () {
}
await
router
.
clear
().
then
(()
=>
{
},
failCallback
).
catch
(
failCatch
);
await
closeFileDescriptor
(
readpath
);
})
afterAll
(
function
()
{
...
...
@@ -166,28 +171,36 @@ describe('VideoDecoderFuncPromiseTest', function () {
console
.
error
(
'
in case toDisplayPage
'
+
e
);
}
}
function
readFile
(
path
){
console
.
info
(
'
in case : read file start execution
'
);
try
{
console
.
info
(
'
in case: filepath
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
console
.
error
(
'
in case readFile
'
+
e
);
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
);
}
})
}
function
readFile
(
path
)
{
console
.
info
(
'
case read file start execution
'
);
try
{
console
.
info
(
'
case filepath:
'
+
path
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
function
getContent
(
buf
,
len
)
{
console
.
info
(
'
start get content, len
'
+
len
+
'
buf.byteLength
'
+
buf
.
byteLength
);
let
lengthReal
=
-
1
;
try
{
lengthReal
=
readStreamSync
.
readSync
(
buf
,
{
length
:
len
}
);
console
.
info
(
'
in case: lengthReal:
'
+
lengthReal
);
}
catch
(
e
)
{
console
.
error
(
'
in case error getContent
'
+
e
);
}
console
.
info
(
"
case start get content
"
);
console
.
info
(
"
case start get content length is:
"
+
len
);
let
lengthreal
=
-
1
;
lengthreal
=
readStreamSync
.
readSync
(
buf
,{
length
:
len
});
console
.
info
(
'
case lengthreal is :
'
+
lengthreal
);
}
/* push inputbuffers into codec */
...
...
@@ -298,6 +311,7 @@ describe('VideoDecoderFuncPromiseTest', function () {
console
.
info
(
'
in case : release success
'
);
},
failCallback
).
catch
(
failCatch
);
videoDecodeProcessor
=
null
;
await
closeFileDescriptor
(
readpath
);
console
.
info
(
'
in case : done
'
);
done
();
});
...
...
@@ -323,7 +337,9 @@ describe('VideoDecoderFuncPromiseTest', function () {
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_DECODER_H264_PROMISE_0100
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
H264_FRAME_SIZE_240
;
isCodecData
=
true
;
let
srcPath
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
let
srcPath
=
'
out_320_240_10s.h264
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
@@ -353,7 +369,9 @@ describe('VideoDecoderFuncPromiseTest', function () {
*/
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_DECODER_MPEG2_PROMISE_0100
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
MPEG2_FRAME_SIZE
;
let
srcPath
=
BASIC_PATH
+
'
MPEG2_720_480.es
'
;
let
srcPath
=
'
MPEG2_720_480.es
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/mpeg2
'
,
...
...
@@ -383,7 +401,9 @@ describe('VideoDecoderFuncPromiseTest', function () {
*/
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_DECODER_MPEG4_PROMISE_0100
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
MPEG4_FRAME_SIZE
;
let
srcPath
=
BASIC_PATH
+
'
mpeg4_320_240.es
'
;
let
srcPath
=
'
mpeg4_320_240.es
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/mp4v-es
'
,
...
...
@@ -414,7 +434,9 @@ describe('VideoDecoderFuncPromiseTest', function () {
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_DECODER_FUNCTION_PROMISE_01_0600
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
H264_FRAME_SIZE_240
;
isCodecData
=
true
;
let
srcPath
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
let
srcPath
=
'
out_320_240_10s.h264
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
@@ -443,6 +465,8 @@ describe('VideoDecoderFuncPromiseTest', function () {
isCodecData
=
true
;
inputEosFlag
=
false
;
readStreamSync
=
null
;
await
closeFileDescriptor
(
readpath
);
await
getFdRead
(
readpath
,
done
);
await
toDisplayPage
().
then
(()
=>
{
},
failCallback
).
catch
(
failCatch
);
await
msleep
(
1000
).
then
(()
=>
{
...
...
@@ -474,7 +498,9 @@ describe('VideoDecoderFuncPromiseTest', function () {
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_DECODER_FUNCTION_PROMISE_01_0700
'
,
0
,
async
function
(
done
)
{
ES_FRAME_SIZE
=
H264_FRAME_SIZE_240
;
isCodecData
=
true
;
let
srcPath
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
let
srcPath
=
'
out_320_240_10s.h264
'
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
@@ -487,7 +513,7 @@ describe('VideoDecoderFuncPromiseTest', function () {
await
toCreateVideoDecoderByName
(
'
avdec_h264
'
,
done
);
await
toConfigure
(
mediaDescription
,
srcPath
);
await
toSetOutputSurface
(
true
);
srcPath
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
srcPath
=
'
out_320_240_10s.h264
'
;
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
@@ -502,6 +528,7 @@ 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
);
...
...
@@ -514,6 +541,8 @@ describe('VideoDecoderFuncPromiseTest', function () {
inputEosFlag
=
false
;
readStreamSync
=
null
;
ES_FRAME_SIZE
=
H264_FRAME_SIZE_240
;
readpath
=
srcPath
;
await
getFdRead
(
readpath
,
done
);
await
toDisplayPage
().
then
(()
=>
{
},
failCallback
).
catch
(
failCatch
);
await
msleep
(
1000
).
then
(()
=>
{
...
...
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareReliCallbackTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,10 +14,11 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
F
ileio
from
'
@ohos.fileio
'
import
f
ileio
from
'
@ohos.fileio
'
import
router
from
'
@system.router
'
import
{
getFileDescriptor
,
closeFileDescriptor
}
from
'
./VideoDecoderTestBase.test.js
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
export
const
DECODE_STEP
=
{
WAIT_FOR_EOS
:
'
waitForEOS
'
,
CONFIGURE
:
'
configure
'
,
...
...
@@ -47,7 +48,7 @@ describe('VideoDecoderSoftwareReliCallbackTest', function () {
let
workdoneAtEOS
=
false
;
let
surfaceID
=
''
;
const
BASIC_PATH
=
'
/data/accounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder/
'
;
const
SRCPATH
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
const
SRCPATH
=
'
out_320_240_10s.h264
'
;
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
@@ -74,6 +75,8 @@ describe('VideoDecoderSoftwareReliCallbackTest', function () {
574
,
126
,
1242
,
188
,
130
,
119
,
1450
,
187
,
137
,
141
,
1116
,
124
,
1848
,
138
,
122
,
1605
,
186
,
127
,
140
,
1798
,
170
,
124
,
121
,
1666
,
157
,
128
,
130
,
1678
,
135
,
118
,
1804
,
169
,
135
,
125
,
1837
,
168
,
124
,
124
];
let
ES_FRAME_SIZE
=
H264_FRAME_SIZE_60FPS_320
;
let
fdRead
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
})
...
...
@@ -107,10 +110,12 @@ describe('VideoDecoderSoftwareReliCallbackTest', function () {
}
await
router
.
clear
().
then
(()
=>
{
},
failCallback
).
catch
(
failCatch
);
await
closeFileDescriptor
(
SRCPATH
);
})
afterAll
(
function
()
{
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
}
`
);
...
...
@@ -141,13 +146,14 @@ describe('VideoDecoderSoftwareReliCallbackTest', function () {
console
.
error
(
'
in case toDisplayPage
'
+
e
);
}
}
function
readFile
(
path
){
console
.
info
(
'
in case : read file start execution
'
);
try
{
console
.
info
(
'
in case: file path
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
'
in case readFile
'
+
e
);
function
readFile
(
path
)
{
console
.
info
(
'
case read file start execution
'
);
try
{
console
.
info
(
'
case filepath:
'
+
path
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
...
...
@@ -418,7 +424,17 @@ describe('VideoDecoderSoftwareReliCallbackTest', function () {
toNextStep
(
mySteps
,
done
);
})
}
function
toCreateVideoDecoderByName
(
name
,
mySteps
,
done
)
{
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
);
}
})
media
.
createVideoDecoderByName
(
name
,
(
err
,
processor
)
=>
{
printError
(
err
,
false
);
console
.
info
(
`case createVideoDecoderByName callback`
);
...
...
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderSoftwareReliPromiseTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -14,10 +14,11 @@
*/
import
media
from
'
@ohos.multimedia.media
'
import
F
ileio
from
'
@ohos.fileio
'
import
f
ileio
from
'
@ohos.fileio
'
import
router
from
'
@system.router
'
import
{
getFileDescriptor
,
closeFileDescriptor
}
from
'
./VideoDecoderTestBase.test.js
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
export
const
DECODE_STEP
=
{
WAIT_FOR_EOS
:
'
waitForEOS
'
,
CONFIGURE
:
'
configure
'
,
...
...
@@ -47,7 +48,7 @@ describe('VideoDecoderSoftwareReliPromiseTest', function () {
let
workdoneAtEOS
=
false
;
let
surfaceID
=
''
;
const
BASIC_PATH
=
'
/data/accounts/account_0/appdata/ohos.acts.multimedia.video.videodecoder/
'
;
const
SRCPATH
=
BASIC_PATH
+
'
out_320_240_10s.h264
'
;
const
SRCPATH
=
'
out_320_240_10s.h264
'
;
let
mediaDescription
=
{
'
track_type
'
:
1
,
'
codec_mime
'
:
'
video/avc
'
,
...
...
@@ -74,7 +75,8 @@ describe('VideoDecoderSoftwareReliPromiseTest', function () {
574
,
126
,
1242
,
188
,
130
,
119
,
1450
,
187
,
137
,
141
,
1116
,
124
,
1848
,
138
,
122
,
1605
,
186
,
127
,
140
,
1798
,
170
,
124
,
121
,
1666
,
157
,
128
,
130
,
1678
,
135
,
118
,
1804
,
169
,
135
,
125
,
1837
,
168
,
124
,
124
];
let
ES_FRAME_SIZE
=
H264_FRAME_SIZE_60FPS_320
;
let
fdRead
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
})
...
...
@@ -108,10 +110,12 @@ describe('VideoDecoderSoftwareReliPromiseTest', function () {
}
await
router
.
clear
().
then
(()
=>
{
},
failCallback
).
catch
(
failCatch
);
await
closeFileDescriptor
(
SRCPATH
);
})
afterAll
(
function
()
{
afterAll
(
async
function
()
{
console
.
info
(
'
afterAll case
'
);
await
closeFileDescriptor
(
SRCPATH
);
})
let
caseCallback
=
function
(
err
)
{
console
.
info
(
`in case caseCallback called, caseMessage is
${
err
.
message
}
`
);
...
...
@@ -148,13 +152,14 @@ describe('VideoDecoderSoftwareReliPromiseTest', function () {
console
.
error
(
'
in case toDisplayPage
'
+
e
);
}
}
function
readFile
(
path
){
console
.
info
(
'
in case : read file start execution
'
);
try
{
console
.
info
(
'
in case: file path
'
+
path
);
readStreamSync
=
Fileio
.
createStreamSync
(
path
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
'
in case readFile
'
+
e
);
function
readFile
(
path
)
{
console
.
info
(
'
case read file start execution
'
);
try
{
console
.
info
(
'
case filepath:
'
+
path
);
readStreamSync
=
fileio
.
fdopenStreamSync
(
fdRead
,
'
rb
'
);
}
catch
(
e
)
{
console
.
info
(
e
);
}
}
...
...
@@ -416,7 +421,17 @@ describe('VideoDecoderSoftwareReliPromiseTest', function () {
toNextStep
(
mySteps
,
done
);
},
failCallback
).
catch
(
failCatch
);
}
function
toCreateVideoDecoderByName
(
name
,
mySteps
,
done
)
{
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
);
}
})
media
.
createVideoDecoderByName
(
name
).
then
((
processor
)
=>
{
console
.
info
(
`case createVideoDecoderByName success`
);
videoDecodeProcessor
=
processor
;
...
...
multimedia/media/media_js_standard/videoDecoder/src/main/js/test/VideoDecoderTestBase.test.js
0 → 100644
浏览文件 @
8a36fea5
/*
* 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
);
});
});
}
multimedia/media/media_js_standard/videoEncoder/Test.json
浏览文件 @
8a36fea5
...
...
@@ -14,20 +14,14 @@
"type"
:
"AppInstallKit"
,
"cleanup-apps"
:
true
},
{
"type"
:
"PushKit"
,
"pre-push"
:
[
],
"push"
:
[
]
},
{
"type"
:
"ShellKit"
,
"run-command"
:
[
"rm -R /data/accounts/account_0/appdata/ohos.acts.multimedia.video.videoencoder/results"
,
"mkdir -p /data/accounts/account_0/appdata/ohos.acts.multimedia.video.videoencoder/results/"
,
"chmod 777 -R /data/accounts/account_0/appdata/ohos.acts.multimedia.video.videoencoder"
,
"chmod 777 /data/accounts/account_0/appdata/ohos.acts.multimedia.video.videoencoder/*"
"rm -rf /storage/media/100/local/files/*"
,
"chmod 777 -R /storage/media/100/local/files/"
,
"chmod 777 /storage/media/100/local/files/*"
,
"killall com.ohos.medialibrary.MediaScannerAbilityA"
,
"aa start -a MediaScannerAbility -b com.ohos.medialibrary.MediaScannerAbilityA"
],
"teardown-command"
:[
]
...
...
multimedia/media/media_js_standard/videoEncoder/signature/openharmony_sx.p7b
浏览文件 @
8a36fea5
无法预览此类型文件
multimedia/media/media_js_standard/videoEncoder/src/main/config.json
浏览文件 @
8a36fea5
...
...
@@ -49,6 +49,28 @@
"tv"
,
"wearable"
],
"reqPermissions"
:
[
{
"name"
:
"ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
,
"reason"
:
"use ohos.permission.GRANT_SENSITIVE_PERMISSIONS"
},
{
"name"
:
"ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
,
"reason"
:
"use ohos.permission.REVOKE_SENSITIVE_PERMISSIONS"
},
{
"name"
:
"ohos.permission.MEDIA_LOCATION"
,
"reason"
:
"use ohos.permission.MEDIA_LOCATION"
},
{
"name"
:
"ohos.permission.READ_MEDIA"
,
"reason"
:
"use ohos.permission.READ_MEDIA"
},
{
"name"
:
"ohos.permission.WRITE_MEDIA"
,
"reason"
:
"use ohos.permission.WRITE_MEDIA"
}
],
"mainAbility"
:
"ohos.acts.multimedia.video.videoencoder.MainAbility"
,
"distro"
:
{
"moduleType"
:
"entry"
,
...
...
multimedia/media/media_js_standard/videoEncoder/src/main/js/test/VideoEncoderMultiInstancesTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -15,14 +15,18 @@
import
media
from
'
@ohos.multimedia.media
'
import
mediademo
from
'
@ohos.multimedia.mediademo
'
import
Fileio
from
'
@ohos.fileio
'
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
'
describe
(
'
videoEncoderSoftwareMultiInstances
'
,
function
()
{
const
events
=
require
(
'
events
'
);
const
eventEmitter
=
new
events
.
EventEmitter
();
const
ROOT
=
'
/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.video.videoencoder
/results/
'
;
const
BASIC_PATH
=
ROOT
+
'
video_multiinstances_
'
;
const
ROOT
=
'
/data/a
pp/el1/bundle
/results/
'
;
const
BASIC_PATH
=
'
video_multiinstances_
'
;
let
videoEncodeProcessor
;
let
mediaTest
;
let
surfaceID
=
''
;
...
...
@@ -34,9 +38,16 @@ describe('videoEncoderSoftwareMultiInstances', function () {
let
flushAtEOS
=
false
;
let
sawOutputEOS
=
false
;
let
needGetMediaDes
=
false
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
let
fdWrite
;
let
fileAsset
;
const
context
=
featureAbility
.
getContext
();
const
mediaLibraryTest
=
mediaLibrary
.
getMediaLibrary
(
context
);
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
beforeAll
(
async
function
()
{
console
.
info
(
'
beforeAll case 1
'
);
await
applyPermission
();
console
.
info
(
'
beforeAll case after get permission
'
);
})
beforeEach
(
function
()
{
...
...
@@ -56,6 +67,7 @@ describe('videoEncoderSoftwareMultiInstances', function () {
afterEach
(
async
function
()
{
console
.
info
(
'
afterEach case
'
);
await
closeFdWrite
();
})
afterAll
(
function
()
{
...
...
@@ -83,17 +95,6 @@ describe('videoEncoderSoftwareMultiInstances', function () {
needGetMediaDes
=
false
;
}
function
writeFile
(
path
,
buf
,
len
){
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
num
=
writestream
.
writeSync
(
buf
,
{
length
:
len
});
writestream
.
flushSync
();
writestream
.
closeSync
();
}
catch
(
e
)
{
console
.
info
(
e
)
}
}
function
sleep
(
time
)
{
return
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
time
));
}
...
...
@@ -102,19 +103,92 @@ describe('videoEncoderSoftwareMultiInstances', function () {
for
(
let
t
=
Date
.
now
();
Date
.
now
()
-
t
<=
time
;);
}
async
function
dequeueOutputs
(
path
,
nextStep
)
{
async
function
applyPermission
()
{
let
appInfo
=
await
bundle
.
getApplicationInfo
(
'
ohos.acts.multimedia.video.videoencoder
'
,
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
);
let
mediaType
=
mediaLibrary
.
MediaType
.
VIDEO
;
console
.
info
(
'
[mediaLibrary] case mediaType is
'
+
mediaType
);
let
publicPath
=
await
mediaLibraryTest
.
getPublicDirectory
(
mediaLibrary
.
DirectoryType
.
DIR_VIDEO
);
console
.
info
(
'
[mediaLibrary] case getFdWrite publicPath is
'
+
publicPath
);
let
dataUri
=
await
mediaLibraryTest
.
createAsset
(
mediaType
,
pathName
,
publicPath
);
if
(
dataUri
!=
undefined
)
{
let
args
=
dataUri
.
id
.
toString
();
let
fetchOp
=
{
selections
:
fileKeyObj
.
ID
+
"
=?
"
,
selectionArgs
:
[
args
],
}
let
fetchWriteFileResult
=
await
mediaLibraryTest
.
getFileAssets
(
fetchOp
);
console
.
info
(
'
[mediaLibrary] case getFdWrite getFileAssets() success
'
);
fileAsset
=
await
fetchWriteFileResult
.
getAllObject
();
console
.
info
(
'
[mediaLibrary] case getFdWrite getAllObject() success
'
);
fdWrite
=
await
fileAsset
[
0
].
open
(
'
Rw
'
);
console
.
info
(
'
[mediaLibrary] case getFdWrite fdWrite is
'
+
fdWrite
);
}
}
async
function
closeFdWrite
()
{
if
(
fileAsset
!=
null
)
{
await
fileAsset
[
0
].
close
(
fdWrite
).
then
(()
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite success, fd is
'
+
fdWrite
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite failed
'
);
});
}
else
{
console
.
info
(
'
[mediaLibrary] case fileAsset is null
'
);
}
}
function
writeFile
(
buf
,
len
)
{
try
{
let
res
=
fileio
.
write
(
fdWrite
,
buf
,
{
length
:
len
});
console
.
info
(
'
case fileio.write buffer success
'
);
}
catch
(
e
)
{
console
.
info
(
'
case fileio.write buffer error is
'
+
e
);
}
}
async
function
dequeueOutputs
(
nextStep
)
{
while
(
outputQueue
.
length
>
0
)
{
let
outputObject
=
outputQueue
.
shift
();
outputCnt
+=
1
;
if
(
outputObject
.
flags
==
1
)
{
console
.
info
(
"
case last frame
"
);
mediaTest
.
closeStream
(
surfaceID
);
toRelease
();
await
toRelease
();
nextStep
();
return
;
}
else
{
console
.
info
(
'
not last frame, write data to file
'
);
writeFile
(
path
,
outputObject
.
data
,
outputObject
.
length
);
writeFile
(
outputObject
.
data
,
outputObject
.
length
);
console
.
info
(
"
write to file success
"
);
videoEncodeProcessor
.
freeOutputBuffer
(
outputObject
).
then
(()
=>
{
console
.
info
(
'
release output success
'
);
...
...
@@ -136,7 +210,7 @@ describe('videoEncoderSoftwareMultiInstances', function () {
},
failCallback
).
catch
(
failCatch
);
}
outputQueue
.
push
(
outBuffer
);
dequeueOutputs
(
path
,
nextStep
);
dequeueOutputs
(
nextStep
);
});
videoEncodeProcessor
.
on
(
'
error
'
,(
err
)
=>
{
...
...
@@ -250,7 +324,6 @@ describe('videoEncoderSoftwareMultiInstances', function () {
await
videoEncodeProcessor
.
release
().
then
(()
=>
{
console
.
info
(
"
case release success
"
);
},
failCallback
).
catch
(
failCatch
);
videoEncodeProcessor
=
null
;
}
...
...
@@ -291,6 +364,7 @@ describe('videoEncoderSoftwareMultiInstances', function () {
toCreateStream
();
toSetStreamParam
(
width
,
height
,
framerate
,
frameTotal
);
await
toConfigure
(
mediaDescription
);
await
getFdWrite
(
savepath
);
setCallback
(
savepath
,
function
(){
eventEmitter
.
emit
(
'
nextStep
'
)});
await
toGetInputSurface
();
await
toPrepare
();
...
...
multimedia/media/media_js_standard/videoEncoder/src/main/js/test/VideoEncoderSoftwareFuncCallbackTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -15,7 +15,11 @@
import
media
from
'
@ohos.multimedia.media
'
import
mediademo
from
'
@ohos.multimedia.mediademo
'
import
Fileio
from
'
@ohos.fileio
'
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
'
describe
(
'
VideoEncoderSoftwareFuncCallbackTest
'
,
function
()
{
...
...
@@ -31,11 +35,18 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
let
stopBuffer
=
false
;
const
events
=
require
(
'
events
'
);
const
eventEmitter
=
new
events
.
EventEmitter
();
const
ROOT
=
'
/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.video.videoencoder
/results/
'
;
const
ROOT
=
'
/data/a
pp/el1/bundle
/results/
'
;
const
BASIC_PATH
=
ROOT
+
'
video_func_callback_
'
;
let
fdWrite
;
let
fileAsset
;
const
context
=
featureAbility
.
getContext
();
const
mediaLibraryTest
=
mediaLibrary
.
getMediaLibrary
(
context
);
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
beforeAll
(
async
function
()
{
console
.
info
(
'
beforeAll case 1
'
);
await
applyPermission
();
console
.
info
(
'
beforeAll case after get permission
'
);
})
beforeEach
(
async
function
()
{
...
...
@@ -62,6 +73,7 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
},
failCallback
).
catch
(
failCatch
);
videoEncodeProcessor
=
null
;
}
await
closeFdWrite
();
})
afterAll
(
function
()
{
...
...
@@ -80,18 +92,80 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
return
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
ms
));
}
function
writeFile
(
path
,
buf
,
len
){
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
'
ab+
'
);
let
num
=
writestream
.
writeSync
(
buf
,
{
length
:
len
});
writestream
.
flushSync
();
writestream
.
closeSync
();
async
function
applyPermission
()
{
let
appInfo
=
await
bundle
.
getApplicationInfo
(
'
ohos.acts.multimedia.video.videoencoder
'
,
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
);
let
mediaType
=
mediaLibrary
.
MediaType
.
VIDEO
;
console
.
info
(
'
[mediaLibrary] case mediaType is
'
+
mediaType
);
let
publicPath
=
await
mediaLibraryTest
.
getPublicDirectory
(
mediaLibrary
.
DirectoryType
.
DIR_VIDEO
);
console
.
info
(
'
[mediaLibrary] case getFdWrite publicPath is
'
+
publicPath
);
let
dataUri
=
await
mediaLibraryTest
.
createAsset
(
mediaType
,
pathName
,
publicPath
);
if
(
dataUri
!=
undefined
)
{
let
args
=
dataUri
.
id
.
toString
();
let
fetchOp
=
{
selections
:
fileKeyObj
.
ID
+
"
=?
"
,
selectionArgs
:
[
args
],
}
let
fetchWriteFileResult
=
await
mediaLibraryTest
.
getFileAssets
(
fetchOp
);
console
.
info
(
'
[mediaLibrary] case getFdWrite getFileAssets() success
'
);
fileAsset
=
await
fetchWriteFileResult
.
getAllObject
();
console
.
info
(
'
[mediaLibrary] case getFdWrite getAllObject() success
'
);
fdWrite
=
await
fileAsset
[
0
].
open
(
'
Rw
'
);
console
.
info
(
'
[mediaLibrary] case getFdWrite fdWrite is
'
+
fdWrite
);
}
}
async
function
closeFdWrite
()
{
if
(
fileAsset
!=
null
)
{
await
fileAsset
[
0
].
close
(
fdWrite
).
then
(()
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite success, fd is
'
+
fdWrite
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite failed
'
);
});
}
else
{
console
.
info
(
'
[mediaLibrary] case fileAsset is null
'
);
}
}
function
writeFile
(
buf
,
len
)
{
try
{
let
res
=
fileio
.
writeSync
(
fdWrite
,
buf
,
{
length
:
len
});
console
.
info
(
'
case fileio.write buffer success
'
);
}
catch
(
e
)
{
console
.
error
(
'
in case error writeFile:
'
+
e
);
console
.
info
(
'
case fileio.write buffer error is
'
+
e
);
}
}
async
function
dequeueOutputs
(
path
,
nextStep
)
{
async
function
dequeueOutputs
(
nextStep
)
{
while
(
outputQueue
.
length
>
0
)
{
let
outputObject
=
outputQueue
.
shift
();
if
(
outputObject
.
flags
==
1
||
frameCountOut
==
frameTotal
||
frameCountOut
==
finalFrameId
)
{
...
...
@@ -99,7 +173,7 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
return
;
}
frameCountOut
++
;
writeFile
(
path
,
outputObject
.
data
,
outputObject
.
length
);
writeFile
(
outputObject
.
data
,
outputObject
.
length
);
videoEncodeProcessor
.
freeOutputBuffer
(
outputObject
,
(
err
)
=>
{
if
(
typeof
(
err
)
==
'
undefined
'
)
{
console
.
log
(
'
in case release output count:
'
+
frameCountOut
);
...
...
@@ -116,16 +190,15 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
console
.
info
(
'
video encoder value is
'
+
property
);
}
}
function
setCallback
(
path
,
nextStep
)
{
function
setCallback
(
nextStep
)
{
console
.
info
(
'
case callback
'
);
videoEncodeProcessor
.
on
(
'
newOutputData
'
,
async
(
outBuffer
)
=>
{
console
.
info
(
'
outputBufferAvailable
'
);
if
(
stopBuffer
==
false
)
{
outputQueue
.
push
(
outBuffer
);
dequeueOutputs
(
path
,
nextStep
);
dequeueOutputs
(
nextStep
);
}
});
videoEncodeProcessor
.
on
(
'
error
'
,(
err
)
=>
{
console
.
info
(
'
in case error called, errName is
'
+
err
);
});
...
...
@@ -162,10 +235,12 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
eventEmitter
.
on
(
'
configure
'
,
(
mediaDescription
,
decPath
,
nextStep
,
done
)
=>
{
console
.
info
(
'
in case : configure in
'
);
videoEncodeProcessor
.
configure
(
mediaDescription
,
(
err
)
=>
{
videoEncodeProcessor
.
configure
(
mediaDescription
,
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
'
in case : configure success
'
);
setCallback
(
decPath
,
nextStep
);
await
getFdWrite
(
decPath
);
console
.
info
(
'
case getFdWrite success
'
);
setCallback
(
nextStep
);
eventEmitter
.
emit
(
'
getVideoEncoderCaps
'
,
done
);
});
});
...
...
@@ -270,7 +345,7 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
* @tc.level : Level0
*/
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_00_0100
'
,
0
,
async
function
(
done
)
{
let
decPath
=
BASIC_PATH
+
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_00_0100.es
'
;
let
decPath
=
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_00_0100.es
'
;
let
mime
=
'
video/mp4v-es
'
;
let
mediaDescription
=
{
"
codec_mime
"
:
'
video/mp4v-es
'
,
...
...
@@ -284,7 +359,7 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
console
.
info
(
`case getMediaCapability 1`
);
mediaCaps
.
getVideoEncoderCaps
((
err
,
videoCapsArray
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
'
getVideo
De
coderCaps success
'
);
console
.
info
(
'
getVideo
En
coderCaps success
'
);
if
(
typeof
(
videoCapsArray
)
!=
'
undefined
'
)
{
console
.
info
(
"
case videoCapsArray
"
+
videoCapsArray
);
}
else
{
...
...
@@ -332,7 +407,7 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
* @tc.level : Level0
*/
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0100
'
,
0
,
async
function
(
done
)
{
let
decPath
=
BASIC_PATH
+
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0100.es
'
;
let
decPath
=
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0100.es
'
;
let
name
=
'
avenc_mpeg4
'
;
let
mediaDescription
=
{
'
width
'
:
320
,
...
...
@@ -368,7 +443,7 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
* @tc.level : Level0
*/
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0200
'
,
0
,
async
function
(
done
)
{
let
decPath
=
BASIC_PATH
+
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0200.es
'
;
let
decPath
=
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0200.es
'
;
let
name
=
'
avenc_mpeg4
'
;
let
mediaDescription
=
{
'
width
'
:
320
,
...
...
@@ -404,7 +479,7 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
* @tc.level : Level0
*/
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0300
'
,
0
,
async
function
(
done
)
{
let
decPath
=
BASIC_PATH
+
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0300.es
'
;
let
decPath
=
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0300.es
'
;
let
name
=
'
avenc_mpeg4
'
;
let
mediaDescription
=
{
'
width
'
:
320
,
...
...
@@ -441,7 +516,7 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
* @tc.level : Level0
*/
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0400
'
,
0
,
async
function
(
done
)
{
let
decPath
=
BASIC_PATH
+
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0400.es
'
;
let
decPath
=
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0400.es
'
;
let
name
=
'
avenc_mpeg4
'
;
let
mediaDescription
=
{
'
width
'
:
320
,
...
...
@@ -477,7 +552,7 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
* @tc.level : Level0
*/
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0500
'
,
0
,
async
function
(
done
)
{
let
decPath
=
BASIC_PATH
+
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0500.es
'
;
let
decPath
=
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0500.es
'
;
let
name
=
'
avenc_mpeg4
'
;
let
mediaDescription
=
{
'
width
'
:
320
,
...
...
@@ -512,7 +587,7 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
* @tc.level : Level0
*/
it
(
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0600
'
,
0
,
async
function
(
done
)
{
let
decPath
=
BASIC_PATH
+
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0600.es
'
;
let
decPath
=
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0600.es
'
;
let
name
=
'
avenc_mpeg4
'
;
let
mediaDescription
=
{
'
width
'
:
320
,
...
...
@@ -520,18 +595,19 @@ describe('VideoEncoderSoftwareFuncCallbackTest', function () {
'
pixel_format
'
:
3
,
'
frame_rate
'
:
30.00
,
}
let
decPath2
=
BASIC_PATH
+
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0600_2.es
'
;
let
decPath2
=
'
SUB_MEDIA_VIDEO_SOFTWARE_ENCODER_FUNCTION_CALLBACK_01_0600_2.es
'
;
let
mediaDescription2
=
{
'
width
'
:
320
,
'
height
'
:
240
,
'
pixel_format
'
:
3
,
'
frame_rate
'
:
30.00
,
}
eventEmitter
.
on
(
'
reset_for_callback_01_0600
'
,
(
done
)
=>
{
videoEncodeProcessor
.
reset
((
err
)
=>
{
eventEmitter
.
on
(
'
reset_for_callback_01_0600
'
,
async
(
done
)
=>
{
videoEncodeProcessor
.
reset
(
async
(
err
)
=>
{
expect
(
err
).
assertUndefined
();
console
.
info
(
'
in case : reset_for_callback_01_0600 success
'
);
toStopStream
();
await
closeFdWrite
();
surfaceID
=
''
;
frameCountOut
=
0
;
outputQueue
=
[];
...
...
multimedia/media/media_js_standard/videoEncoder/src/main/js/test/VideoEncoderSoftwareFuncPromiseTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -15,12 +15,15 @@
import
media
from
'
@ohos.multimedia.media
'
import
mediademo
from
'
@ohos.multimedia.mediademo
'
import
Fileio
from
'
@ohos.fileio
'
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
'
describe
(
'
videoSoftwareEncoderFuncPromise
'
,
function
()
{
const
ROOT
=
'
/data/accounts/account_0/appdata/ohos.acts.multimedia.video.videoencoder/results/
'
;
const
BASIC_PATH
=
ROOT
+
'
video_func_promise_
'
;
const
BASIC_PATH
=
'
videoencode_func_promise_
'
;
let
videoEncodeProcessor
;
let
mediaTest
;
let
surfaceID
=
''
;
...
...
@@ -32,9 +35,16 @@ describe('videoSoftwareEncoderFuncPromise', function () {
let
flushAtEOS
=
false
;
let
sawOutputEOS
=
false
;
let
needGetMediaDes
=
false
;
beforeAll
(
function
()
{
console
.
info
(
'
beforeAll case
'
);
let
fdWrite
;
let
fileAsset
;
const
context
=
featureAbility
.
getContext
();
const
mediaLibraryTest
=
mediaLibrary
.
getMediaLibrary
(
context
);
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
beforeAll
(
async
function
()
{
console
.
info
(
'
beforeAll case 1
'
);
await
applyPermission
();
console
.
info
(
'
beforeAll case after get permission
'
);
})
beforeEach
(
async
function
()
{
...
...
@@ -62,6 +72,7 @@ describe('videoSoftwareEncoderFuncPromise', function () {
},
failCallback
).
catch
(
failCatch
);
videoEncodeProcessor
=
null
;
}
await
closeFdWrite
();
})
afterAll
(
function
()
{
...
...
@@ -93,17 +104,6 @@ describe('videoSoftwareEncoderFuncPromise', function () {
needGetMediaDes
=
false
;
}
function
writeFile
(
path
,
buf
,
len
){
try
{
let
writestream
=
Fileio
.
createStreamSync
(
path
,
"
ab+
"
);
let
num
=
writestream
.
writeSync
(
buf
,
{
length
:
len
});
writestream
.
flushSync
();
writestream
.
closeSync
();
}
catch
(
e
)
{
console
.
info
(
e
)
}
}
function
sleep
(
time
)
{
return
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
time
));
}
...
...
@@ -112,7 +112,80 @@ describe('videoSoftwareEncoderFuncPromise', function () {
for
(
let
t
=
Date
.
now
();
Date
.
now
()
-
t
<=
time
;);
}
async
function
dequeueOutputs
(
path
,
done
)
{
async
function
applyPermission
()
{
let
appInfo
=
await
bundle
.
getApplicationInfo
(
'
ohos.acts.multimedia.video.videoencoder
'
,
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
);
let
mediaType
=
mediaLibrary
.
MediaType
.
VIDEO
;
console
.
info
(
'
[mediaLibrary] case mediaType is
'
+
mediaType
);
let
publicPath
=
await
mediaLibraryTest
.
getPublicDirectory
(
mediaLibrary
.
DirectoryType
.
DIR_VIDEO
);
console
.
info
(
'
[mediaLibrary] case getFdWrite publicPath is
'
+
publicPath
);
let
dataUri
=
await
mediaLibraryTest
.
createAsset
(
mediaType
,
pathName
,
publicPath
);
if
(
dataUri
!=
undefined
)
{
let
args
=
dataUri
.
id
.
toString
();
let
fetchOp
=
{
selections
:
fileKeyObj
.
ID
+
"
=?
"
,
selectionArgs
:
[
args
],
}
let
fetchWriteFileResult
=
await
mediaLibraryTest
.
getFileAssets
(
fetchOp
);
console
.
info
(
'
[mediaLibrary] case getFdWrite getFileAssets() success
'
);
fileAsset
=
await
fetchWriteFileResult
.
getAllObject
();
console
.
info
(
'
[mediaLibrary] case getFdWrite getAllObject() success
'
);
fdWrite
=
await
fileAsset
[
0
].
open
(
'
Rw
'
);
console
.
info
(
'
[mediaLibrary] case getFdWrite fdWrite is
'
+
fdWrite
);
}
}
async
function
closeFdWrite
()
{
if
(
fileAsset
!=
null
)
{
await
fileAsset
[
0
].
close
(
fdWrite
).
then
(()
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite success, fd is
'
+
fdWrite
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
[mediaLibrary] case close fdWrite failed
'
);
});
}
else
{
console
.
info
(
'
[mediaLibrary] case fileAsset is null
'
);
}
}
function
writeFile
(
buf
,
len
)
{
try
{
let
res
=
fileio
.
writeSync
(
fdWrite
,
buf
,
{
length
:
len
});
console
.
info
(
'
case fileio.write buffer success
'
);
}
catch
(
e
)
{
console
.
info
(
'
case fileio.write buffer error is
'
+
e
);
}
}
async
function
dequeueOutputs
(
done
)
{
while
(
outputQueue
.
length
>
0
)
{
let
outputObject
=
outputQueue
.
shift
();
outputCnt
+=
1
;
...
...
@@ -132,9 +205,7 @@ describe('videoSoftwareEncoderFuncPromise', function () {
done
();
}
}
else
{
console
.
info
(
'
not last frame, write data to file
'
);
writeFile
(
path
,
outputObject
.
data
,
outputObject
.
length
);
console
.
info
(
"
write to file success
"
);
console
.
info
(
'
not last frame, continue
'
);
videoEncodeProcessor
.
freeOutputBuffer
(
outputObject
).
then
(()
=>
{
console
.
info
(
'
release output success
'
);
});
...
...
@@ -142,7 +213,7 @@ describe('videoSoftwareEncoderFuncPromise', function () {
}
}
function
setCallback
(
path
,
done
)
{
function
setCallback
(
done
)
{
console
.
info
(
'
case callback
'
);
videoEncodeProcessor
.
on
(
'
newOutputData
'
,
async
(
outBuffer
)
=>
{
console
.
info
(
'
outputBufferAvailable
'
);
...
...
@@ -155,7 +226,7 @@ describe('videoSoftwareEncoderFuncPromise', function () {
},
failCallback
).
catch
(
failCatch
);
}
outputQueue
.
push
(
outBuffer
);
dequeueOutputs
(
path
,
done
);
dequeueOutputs
(
done
);
});
videoEncodeProcessor
.
on
(
'
error
'
,(
err
)
=>
{
...
...
@@ -279,10 +350,12 @@ describe('videoSoftwareEncoderFuncPromise', function () {
mediaTest
.
closeStream
(
surfaceID
);
}
async
function
toConfigure
(
mediaDescription
)
{
async
function
toConfigure
(
mediaDescription
,
savepath
)
{
await
videoEncodeProcessor
.
configure
(
mediaDescription
).
then
(()
=>
{
console
.
info
(
"
case configure success
"
);
},
failCallback
).
catch
(
failCatch
);
await
getFdWrite
(
savepath
);
console
.
info
(
'
case getFdWrite success
'
);
}
async
function
toPrepare
()
{
...
...
@@ -382,8 +455,8 @@ describe('videoSoftwareEncoderFuncPromise', function () {
await
toGetVideoEncoderCaps
(
width
,
height
);
toCreateStream
();
toSetStreamParam
(
width
,
height
,
framerate
,
frameTotal
);
await
toConfigure
(
mediaDescription
);
setCallback
(
savepath
,
done
);
await
toConfigure
(
mediaDescription
,
savepath
);
setCallback
(
done
);
await
toGetInputSurface
();
await
toPrepare
();
toStartStream
();
...
...
@@ -415,8 +488,8 @@ describe('videoSoftwareEncoderFuncPromise', function () {
await
toGetVideoEncoderCaps
(
width
,
height
);
toCreateStream
();
toSetStreamParam
(
width
,
height
,
framerate
,
frameTotal
);
await
toConfigure
(
mediaDescription
);
setCallback
(
savepath
,
done
);
await
toConfigure
(
mediaDescription
,
savepath
);
setCallback
(
done
);
await
toGetInputSurface
();
await
toPrepare
();
toStartStream
();
...
...
@@ -456,8 +529,8 @@ describe('videoSoftwareEncoderFuncPromise', function () {
await
toGetVideoEncoderCaps
(
width
,
height
);
toCreateStream
();
toSetStreamParam
(
width
,
height
,
framerate
,
frameTotal
);
await
toConfigure
(
mediaDescription
);
setCallback
(
savepath
,
done
);
await
toConfigure
(
mediaDescription
,
savepath
);
setCallback
(
done
);
await
toGetInputSurface
();
await
toPrepare
();
toStartStream
();
...
...
@@ -495,8 +568,8 @@ describe('videoSoftwareEncoderFuncPromise', function () {
await
toGetVideoEncoderCaps
(
width
,
height
);
toCreateStream
();
toSetStreamParam
(
width
,
height
,
framerate
,
frameTotal
);
await
toConfigure
(
mediaDescription
);
setCallback
(
savepath
,
done
);
await
toConfigure
(
mediaDescription
,
savepath
);
setCallback
(
done
);
await
toGetInputSurface
();
await
toPrepare
();
toStartStream
();
...
...
@@ -536,8 +609,8 @@ describe('videoSoftwareEncoderFuncPromise', function () {
await
toGetVideoEncoderCaps
(
width
,
height
);
toCreateStream
();
toSetStreamParam
(
width
,
height
,
framerate
,
frameTotal
);
await
toConfigure
(
mediaDescription
);
setCallback
(
savepath
,
done
);
await
toConfigure
(
mediaDescription
,
savepath
);
setCallback
(
done
);
await
toGetInputSurface
();
await
toPrepare
();
toStartStream
();
...
...
@@ -573,8 +646,8 @@ describe('videoSoftwareEncoderFuncPromise', function () {
await
toGetVideoEncoderCaps
(
width
,
height
);
toCreateStream
();
toSetStreamParam
(
width
,
height
,
framerate
,
frameTotal
);
await
toConfigure
(
mediaDescription
);
setCallback
(
savepath
,
done
);
await
toConfigure
(
mediaDescription
,
savepath
);
setCallback
(
done
);
await
toGetInputSurface
();
await
toPrepare
();
toStartStream
();
...
...
@@ -612,14 +685,15 @@ describe('videoSoftwareEncoderFuncPromise', function () {
await
toGetVideoEncoderCaps
(
width
,
height
);
toCreateStream
();
toSetStreamParam
(
width
,
height
,
framerate
,
frameTotal
);
await
toConfigure
(
mediaDescription
);
setCallback
(
savepath
,
done
);
await
toConfigure
(
mediaDescription
,
savepath
);
setCallback
(
done
);
await
toGetInputSurface
();
await
toPrepare
();
toStartStream
();
await
toStart
();
await
sleep
(
5000
);
resetParam
();
await
closeFdWrite
();
width
=
320
;
height
=
240
;
framerate
=
30
;
...
...
@@ -631,8 +705,8 @@ describe('videoSoftwareEncoderFuncPromise', function () {
}
let
savepath2
=
BASIC_PATH
+
'
0601.es
'
;
toSetStreamParam
(
width
,
height
,
framerate
,
frameTotal
);
await
toConfigure
(
mediaDescription2
);
setCallback
(
savepath2
,
done
);
await
toConfigure
(
mediaDescription2
,
savepath2
);
setCallback
(
done
);
await
toGetInputSurface
();
await
toPrepare
();
toStartStream
();
...
...
@@ -666,8 +740,8 @@ describe('videoSoftwareEncoderFuncPromise', function () {
await
toGetVideoEncoderCaps
(
width
,
height
);
toCreateStream
();
toSetStreamParam
(
width
,
height
,
framerate
,
frameTotal
);
await
toConfigure
(
mediaDescription
);
setCallback
(
savepath
,
done
);
await
toConfigure
(
mediaDescription
,
savepath
);
setCallback
(
done
);
await
toGetInputSurface
();
await
toPrepare
();
toStartStream
();
...
...
@@ -675,6 +749,7 @@ describe('videoSoftwareEncoderFuncPromise', function () {
await
sleep
(
5000
);
await
toRelease
();
resetParam
();
await
closeFdWrite
();
width
=
320
;
height
=
240
;
framerate
=
30
;
...
...
@@ -687,8 +762,8 @@ describe('videoSoftwareEncoderFuncPromise', function () {
let
savepath2
=
BASIC_PATH
+
'
0701.es
'
;
await
toCreateByMime
(
mime
,
done
);
toSetStreamParam
(
width
,
height
,
framerate
,
frameTotal
);
await
toConfigure
(
mediaDescription2
);
setCallback
(
savepath2
,
done
);
await
toConfigure
(
mediaDescription2
,
savepath2
);
setCallback
(
done
);
await
toGetInputSurface
();
await
toPrepare
();
toStartStream
();
...
...
multimedia/media/media_js_standard/videoEncoder/src/main/js/test/VideoEncoderSoftwareReliabilityCallbackTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -17,7 +17,7 @@ import media from '@ohos.multimedia.media'
import
mediademo
from
'
@ohos.multimedia.mediademo
'
import
Fileio
from
'
@ohos.fileio
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
export
const
ENCODE_STEP
=
{
WAIT_FOR_EOS
:
'
encode:waitForEOS
'
,
CONFIGURE
:
'
encode:configure
'
,
...
...
@@ -50,7 +50,7 @@ describe('VideoEncoderSoftwareReliCallbackTest', function () {
let
isStreamRunning
=
false
;
let
workdoneAtEOS
=
false
;
let
stopBuffer
=
false
;
const
ROOT
=
'
/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.video.videoencoder
/results/
'
;
const
ROOT
=
'
/data/a
pp/el1/bundle
/results/
'
;
const
BASIC_PATH
=
ROOT
+
'
video_reliability_callback_
'
;
let
mediaDescription
=
{
'
width
'
:
320
,
...
...
@@ -136,7 +136,7 @@ describe('VideoEncoderSoftwareReliCallbackTest', function () {
return
;
}
frameCountOut
++
;
writeFile
(
path
,
outputObject
.
data
,
outputObject
.
length
);
console
.
info
(
'
not last frame, continue
'
);
videoEncodeProcessor
.
freeOutputBuffer
(
outputObject
,
(
err
)
=>
{
if
(
typeof
(
err
)
==
'
undefined
'
)
{
console
.
debug
(
'
in case release output count:
'
+
frameCountOut
);
...
...
multimedia/media/media_js_standard/videoEncoder/src/main/js/test/VideoEncoderSoftwareReliabilityPromiseTest.test.js
浏览文件 @
8a36fea5
...
...
@@ -19,7 +19,7 @@ import Fileio from '@ohos.fileio'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
describe
(
'
videoEncoderReliabilityPromise
'
,
function
()
{
const
ROOT
=
'
/data/a
ccounts/account_0/appdata/ohos.acts.multimedia.video.videoencoder
/results/
'
;
const
ROOT
=
'
/data/a
pp/el1/bundle
/results/
'
;
const
BASIC_PATH
=
ROOT
+
'
video_reliability_promise_
'
;
let
videoEncodeProcessor
;
let
mediaTest
=
mediademo
.
createMediaTest
();
...
...
@@ -250,8 +250,7 @@ describe('videoEncoderReliabilityPromise', function () {
console
.
info
(
"
sawOutputEOS = true;
"
);
}
}
else
{
writeFile
(
path
,
outputObject
.
data
,
outputObject
.
length
);
console
.
info
(
"
write to file success
"
);
console
.
info
(
'
not last frame, continue
'
);
videoEncodeProcessor
.
freeOutputBuffer
(
outputObject
).
then
(()
=>
{
console
.
info
(
'
release output success
'
);
frameCountOut
++
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录