已合并
soundpool读取wav格式文件逻辑优化 #3513
AtomGit-Bot创建于 2024年6月21日
soundpool读取wav格式文件逻辑优化 #3513
已合并
AtomGit-Bot创建于 2024年6月21日
refs/pull/3513/head合入到master
6 个文件变更+149-49
@@ -15,20 +15,29 @@
15#include <fcntl.h>15#include <fcntl.h>
16#include <functional>16#include <functional>
17#include <cstdio>17#include <cstdio>
18+#include <string>
18#include "isoundpool.h"19#include "isoundpool.h"
19#include "sound_parser.h"20#include "sound_parser.h"
21+#include "string_ex.h"
20 22 
21namespace {23namespace {
22 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "SoundParser"};24 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "SoundParser"};
23 static constexpr int32_t MAX_SOUND_BUFFER_SIZE = 1 * 1024 * 1024;25 static constexpr int32_t MAX_SOUND_BUFFER_SIZE = 1 * 1024 * 1024;
24 static const std::string AUDIO_RAW_MIMETYPE_INFO = "audio/raw";26 static const std::string AUDIO_RAW_MIMETYPE_INFO = "audio/raw";
25 static const std::string AUDIO_MPEG_MIMETYPE_INFO = "audio/mpeg";27 static const std::string AUDIO_MPEG_MIMETYPE_INFO = "audio/mpeg";
28+ static constexpr int64_t WAV_HEADER_SIZE = 42;
26}29}
27 30 
28namespace OHOS {31namespace OHOS {
29namespace Media {32namespace Media {
30SoundParser::SoundParser(int32_t soundID, std::string url)33SoundParser::SoundParser(int32_t soundID, std::string url)
31{34{
35+ const std::string fdHead = "fd://";
36+ int32_t fd = -1;
37+ StrToInt(url.substr(fdHead.size()), fd);
38+ int32_t fdFile = fcntl(fd, F_DUPFD, minFd);
39+ 
40+ MEDIA_LOGI("SoundParser::SoundParser url::%{public}s, fdFile:%{public}d", url.c_str(), fdFile);
32 std::shared_ptr<MediaAVCodec::AVSource> source = MediaAVCodec::AVSourceFactory::CreateWithURI(url);41 std::shared_ptr<MediaAVCodec::AVSource> source = MediaAVCodec::AVSourceFactory::CreateWithURI(url);
33 CHECK_AND_RETURN_LOG(source != nullptr, "Create AVSource failed");42 CHECK_AND_RETURN_LOG(source != nullptr, "Create AVSource failed");
34 std::shared_ptr<MediaAVCodec::AVDemuxer> demuxer = MediaAVCodec::AVDemuxerFactory::CreateWithSource(source);43 std::shared_ptr<MediaAVCodec::AVDemuxer> demuxer = MediaAVCodec::AVDemuxerFactory::CreateWithSource(source);
@@ -36,14 +45,20 @@ SoundParser::SoundParser(int32_t soundID, std::string url)
36 soundID_ = soundID;45 soundID_ = soundID;
37 demuxer_ = demuxer;46 demuxer_ = demuxer;
38 source_ = source;47 source_ = source;
48+ fileReadLength_ = MAX_SOUND_BUFFER_SIZE;
49+ filePtr_ = fdopen(fdFile, "rb");
50+ CHECK_AND_RETURN_LOG(filePtr_ != nullptr, "SoundParser::SoundParser filePtr_ is nullptr");
39}51}
40 52 
41SoundParser::SoundParser(int32_t soundID, int32_t fd, int64_t offset, int64_t length)53SoundParser::SoundParser(int32_t soundID, int32_t fd, int64_t offset, int64_t length)
42{54{
43- fd = fcntl(fd, F_DUPFD_CLOEXEC, MIN_FD); // dup(fd) + close on exec to prevent leaks.55+ int32_t fdSource = fcntl(fd, F_DUPFD_CLOEXEC, minFd); // dup(fd) + close on exec to prevent leaks.
56+ int32_t fdFile = fcntl(fd, F_DUPFD, minFd);
44 offset = offset >= INT64_MAX ? INT64_MAX : offset;57 offset = offset >= INT64_MAX ? INT64_MAX : offset;
45 length = length >= INT64_MAX ? INT64_MAX : length;58 length = length >= INT64_MAX ? INT64_MAX : length;
46- std::shared_ptr<MediaAVCodec::AVSource> source = MediaAVCodec::AVSourceFactory::CreateWithFD(fd, offset, length);59+ MEDIA_LOGI("SoundParser fd:%{public}d, fdSource:%{public}d, fdFile:%{public}d", fd, fdSource, fdFile);
60+ std::shared_ptr<MediaAVCodec::AVSource> source =
61+ MediaAVCodec::AVSourceFactory::CreateWithFD(fdSource, offset, length);
47 CHECK_AND_RETURN_LOG(source != nullptr, "Create AVSource failed");62 CHECK_AND_RETURN_LOG(source != nullptr, "Create AVSource failed");
48 std::shared_ptr<MediaAVCodec::AVDemuxer> demuxer = MediaAVCodec::AVDemuxerFactory::CreateWithSource(source);63 std::shared_ptr<MediaAVCodec::AVDemuxer> demuxer = MediaAVCodec::AVDemuxerFactory::CreateWithSource(source);
49 CHECK_AND_RETURN_LOG(demuxer != nullptr, "Create AVDemuxer failed");64 CHECK_AND_RETURN_LOG(demuxer != nullptr, "Create AVDemuxer failed");
@@ -51,6 +66,10 @@ SoundParser::SoundParser(int32_t soundID, int32_t fd, int64_t offset, int64_t le
51 soundID_ = soundID;66 soundID_ = soundID;
52 demuxer_ = demuxer;67 demuxer_ = demuxer;
53 source_ = source;68 source_ = source;
69+ fileOffset_ = offset;
70+ fileReadLength_ = length > MAX_SOUND_BUFFER_SIZE ? MAX_SOUND_BUFFER_SIZE : static_cast<int32_t>(length);
71+ filePtr_ = fdopen(fdFile, "rb");
72+ CHECK_AND_RETURN_LOG(filePtr_ != nullptr, "SoundParser::SoundParser filePtr_ is nullptr");
54}73}
55 74 
56SoundParser::~SoundParser()75SoundParser::~SoundParser()
@@ -73,6 +92,13 @@ int32_t SoundParser::DoParser()
73 if (result != MSERR_OK && callback_ != nullptr) {92 if (result != MSERR_OK && callback_ != nullptr) {
74 callback_->OnError(MSERR_UNSUPPORT_FILE);93 callback_->OnError(MSERR_UNSUPPORT_FILE);
75 }94 }
95+ if (result == MSERR_OK && isRawFile_) {
96+ callback_->OnLoadCompleted(soundID_);
97+ }
98+ if (filePtr_ != nullptr) {
99+ fclose(filePtr_);
100+ filePtr_ = nullptr;
101+ }
76 return MSERR_OK;102 return MSERR_OK;
77}103}
78 104 
@@ -111,8 +137,7 @@ int32_t SoundParser::DoDemuxer(MediaAVCodec::Format *trackFormat)
111 MediaAVCodec::SAMPLE_S16LE);137 MediaAVCodec::SAMPLE_S16LE);
112 } else {138 } else {
113 isRawFile_ = true;139 isRawFile_ = true;
114- trackFormat->PutStringValue(MediaAVCodec::MediaDescriptionKey::MD_KEY_CODEC_MIME,140+ return GetAudioBuffers(trackFormat);
115- AUDIO_MPEG_MIMETYPE_INFO);
116 }141 }
117 break;142 break;
118 }143 }
@@ -120,11 +145,66 @@ int32_t SoundParser::DoDemuxer(MediaAVCodec::Format *trackFormat)
120 return MSERR_OK;145 return MSERR_OK;
121}146}
122 147 
148+int32_t SoundParser::GetAudioBuffers(MediaAVCodec::Format *trackFormat)
149+{
150+ trackFormat->PutStringValue(MediaAVCodec::MediaDescriptionKey::MD_KEY_CODEC_MIME,
151+ AUDIO_MPEG_MIMETYPE_INFO);
152+ int32_t trackSampleRate;
153+ int32_t trackChannels;
154+ int32_t trackBitPerSample;
155+ trackFormat->GetIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, trackSampleRate);
156+ trackFormat->GetIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, trackChannels);
157+ trackFormat->GetIntValue(MediaDescriptionKey::MD_KEY_BITS_PER_CODED_SAMPLE, trackBitPerSample);
158+ int32_t bufferLength = trackSampleRate * 20 / 1000 * trackChannels * trackBitPerSample / 8;
159+ MEDIA_LOGI("SoundParser SampleRate:%{public}d, Channels:%{public}d, BitRate:%{public}d, bufferLength:%{public}d",
160+ trackSampleRate, trackChannels, trackBitPerSample, bufferLength);
161+ 
162+ CHECK_AND_RETURN_RET_LOG(filePtr_ != NULL, MSERR_INVALID_VAL, "SoundParser::GetAudioBuffers filePtr_ is null");
163+ 
164+ (void)fseek(filePtr_, 0L, SEEK_END);
165+ long fileSize = ftell(filePtr_);
166+ CHECK_AND_RETURN_RET_LOG(fileSize > 0, MSERR_INVALID_VAL, "SoundParser::GetAudioBuffers fileSize <= 0");
167+ (void)fseek(filePtr_, 0L, SEEK_SET);
168+ 
169+ MEDIA_LOGI("SoundParser fileSize:%{public}ld , WAV_HEADER_SIZE:%{public}s , fileOffset_:%{public}s",
170+ fileSize, std::to_string(WAV_HEADER_SIZE).c_str(), std::to_string(fileOffset_).c_str());
171+ 
172+ CHECK_AND_RETURN_RET_LOG(WAV_HEADER_SIZE + fileOffset_ <= static_cast<int64_t>(fileSize), MSERR_INVALID_VAL,
173+ "SoundParser::GetAudioBuffers offset too large");
174+ (void)fseeko64(filePtr_, WAV_HEADER_SIZE + fileOffset_, SEEK_SET);
175+ bool isSuccess = false;
176+ while (!isSuccess) {
177+ if (feof(filePtr_)) {
178+ MEDIA_LOGI("SoundParser::GetAudioBuffers read WAV end");
179+ isSuccess = true;
180+ }
181+ uint8_t *buf = new(std::nothrow) uint8_t[bufferLength];
182+ if (buf != nullptr) {
183+ size_t bytesRead = fread(buf, 1, bufferLength, filePtr_);
184+ if (bytesRead > 0 && rawSoundBufferTotalSize_ < fileReadLength_) {
185+ rawAudioBuffers_.push_back(std::make_shared<AudioBufferEntry>(buf, bufferLength));
186+ rawSoundBufferTotalSize_ += bufferLength;
187+ } else {
188+ MEDIA_LOGI("SoundParser::GetAudioBuffers read WAV stop");
189+ isSuccess = true;
190+ }
191+ } else {
192+ MEDIA_LOGI("SoundParser::GetAudioBuffers buff is null");
193+ break;
194+ }
195+ }
196+ MEDIA_LOGI("raw size:%{public}zu , rawTotalSize_:%{public}d", rawAudioBuffers_.size(), rawSoundBufferTotalSize_);
197+ CHECK_AND_RETURN_RET_LOG(isSuccess == true, MSERR_INVALID_VAL, "SoundParser::GetAudioBuffers isSuccess == false");
198+ rawSoundParserCompleted_.store(true);
199+
200+ return MSERR_OK;
201+}
202+ 
123int32_t SoundParser::DoDecode(MediaAVCodec::Format trackFormat)203int32_t SoundParser::DoDecode(MediaAVCodec::Format trackFormat)
124{204{
125 int32_t trackTypeInfo;205 int32_t trackTypeInfo;
126 trackFormat.GetIntValue(MediaDescriptionKey::MD_KEY_TRACK_TYPE, trackTypeInfo);206 trackFormat.GetIntValue(MediaDescriptionKey::MD_KEY_TRACK_TYPE, trackTypeInfo);
127- if (trackTypeInfo == MEDIA_TYPE_AUD) {207+ if (trackTypeInfo == MEDIA_TYPE_AUD && !isRawFile_) {
128 std::string trackMimeTypeInfo;208 std::string trackMimeTypeInfo;
129 trackFormat.GetStringValue(MediaAVCodec::MediaDescriptionKey::MD_KEY_CODEC_MIME, trackMimeTypeInfo);209 trackFormat.GetStringValue(MediaAVCodec::MediaDescriptionKey::MD_KEY_CODEC_MIME, trackMimeTypeInfo);
130 MEDIA_LOGI("SoundParser mime type:%{public}s", trackMimeTypeInfo.c_str());210 MEDIA_LOGI("SoundParser mime type:%{public}s", trackMimeTypeInfo.c_str());
@@ -148,20 +228,36 @@ int32_t SoundParser::DoDecode(MediaAVCodec::Format trackFormat)
148 228 
149int32_t SoundParser::GetSoundData(std::deque<std::shared_ptr<AudioBufferEntry>> &soundData) const229int32_t SoundParser::GetSoundData(std::deque<std::shared_ptr<AudioBufferEntry>> &soundData) const
150{230{
151- CHECK_AND_RETURN_RET_LOG(soundParserListener_ != nullptr, MSERR_INVALID_VAL, "Invalid sound parser listener");231+ MEDIA_LOGI("SoundParser::GetSoundData isRawFile_:%{public}d", isRawFile_);
152- return soundParserListener_->GetSoundData(soundData);232+ if (isRawFile_) {
233+ soundData = rawAudioBuffers_;
234+ return MSERR_OK;
235+ } else {
236+ CHECK_AND_RETURN_RET_LOG(soundParserListener_ != nullptr, MSERR_INVALID_VAL, "Invalid sound parser listener");
237+ return soundParserListener_->GetSoundData(soundData);
238+ }
153}239}
154 240 
155size_t SoundParser::GetSoundDataTotalSize() const241size_t SoundParser::GetSoundDataTotalSize() const
156{242{
157- CHECK_AND_RETURN_RET_LOG(soundParserListener_ != nullptr, MSERR_INVALID_VAL, "Invalid sound parser listener");243+ MEDIA_LOGI("SoundParser::GetSoundDataTotalSize isRawFile_:%{public}d", isRawFile_);
158- return soundParserListener_->GetSoundDataTotalSize();244+ if (isRawFile_) {
245+ return rawSoundBufferTotalSize_;
246+ } else {
247+ CHECK_AND_RETURN_RET_LOG(soundParserListener_ != nullptr, MSERR_INVALID_VAL, "Invalid sound parser listener");
248+ return soundParserListener_->GetSoundDataTotalSize();
249+ }
159}250}
160 251 
161bool SoundParser::IsSoundParserCompleted() const252bool SoundParser::IsSoundParserCompleted() const
162{253{
163- CHECK_AND_RETURN_RET_LOG(soundParserListener_ != nullptr, MSERR_INVALID_VAL, "Invalid sound parser listener");254+ MEDIA_LOGI("SoundParser::IsSoundParserCompleted isRawFile_:%{public}d", isRawFile_);
164- return soundParserListener_->IsSoundParserCompleted();255+ if (isRawFile_) {
256+ return rawSoundParserCompleted_.load();
257+ } else {
258+ CHECK_AND_RETURN_RET_LOG(soundParserListener_ != nullptr, MSERR_INVALID_VAL, "Invalid sound parser listener");
259+ return soundParserListener_->IsSoundParserCompleted();
260+ }
165}261}
166 262 
167int32_t SoundParser::SetCallback(const std::shared_ptr<ISoundPoolCallback> &callback)263int32_t SoundParser::SetCallback(const std::shared_ptr<ISoundPoolCallback> &callback)
@@ -226,36 +322,6 @@ void SoundDecoderCallback::OnInputBufferAvailable(uint32_t index, std::shared_pt
226 CHECK_AND_RETURN_LOG(demuxer_ != nullptr, "Failed to obtain demuxer");322 CHECK_AND_RETURN_LOG(demuxer_ != nullptr, "Failed to obtain demuxer");
227 CHECK_AND_RETURN_LOG(audioDec_ != nullptr, "Failed to obtain audio decode.");323 CHECK_AND_RETURN_LOG(audioDec_ != nullptr, "Failed to obtain audio decode.");
228 324 
229- if (buffer != nullptr && isRawFile_ && !decodeShouldCompleted_) {
230- if (demuxer_->ReadSample(0, buffer, sampleInfo, bufferFlag) != AVCS_ERR_OK) {
231- MEDIA_LOGE("SoundDecoderCallback demuxer error.");
232- return;
233- }
234- if (!decodeShouldCompleted_ && (currentSoundBufferSize_ > MAX_SOUND_BUFFER_SIZE ||
235- bufferFlag == AVCODEC_BUFFER_FLAG_EOS)) {
236- decodeShouldCompleted_ = true;
237- CHECK_AND_RETURN_LOG(listener_ != nullptr, "sound decode listener invalid.");
238- listener_->OnSoundDecodeCompleted(availableAudioBuffers_);
239- listener_->SetSoundBufferTotalSize(static_cast<size_t>(currentSoundBufferSize_));
240- CHECK_AND_RETURN_LOG(callback_ != nullptr, "sound decode:soundpool callback invalid.");
241- callback_->OnLoadCompleted(soundID_);
242- return;
243- }
244- int32_t size = sampleInfo.size;
245- uint8_t *buf = new(std::nothrow) uint8_t[size];
246- if (buf != nullptr) {
247- if (memcpy_s(buf, size, buffer->GetBase(), size) != EOK) {
248- MEDIA_LOGI("audio buffer copy failed:%{public}s", strerror(errno));
249- } else {
250- availableAudioBuffers_.push_back(std::make_shared<AudioBufferEntry>(buf, size));
251- bufferCond_.notify_all();
252- }
253- }
254- currentSoundBufferSize_ += size;
255- audioDec_->QueueInputBuffer(index, sampleInfo, bufferFlag);
256- return;
257- }
258- 
259 if (buffer != nullptr && !eosFlag_ && !decodeShouldCompleted_) {325 if (buffer != nullptr && !eosFlag_ && !decodeShouldCompleted_) {
260 if (demuxer_->ReadSample(0, buffer, sampleInfo, bufferFlag) != AVCS_ERR_OK) {326 if (demuxer_->ReadSample(0, buffer, sampleInfo, bufferFlag) != AVCS_ERR_OK) {
261 MEDIA_LOGE("SoundDecoderCallback demuxer error.");327 MEDIA_LOGE("SoundDecoderCallback demuxer error.");
@@ -272,12 +338,7 @@ void SoundDecoderCallback::OnOutputBufferAvailable(uint32_t index, AVCodecBuffer
272 std::shared_ptr<AVSharedMemory> buffer)338 std::shared_ptr<AVSharedMemory> buffer)
273{339{
274 std::unique_lock<std::mutex> lock(amutex_);340 std::unique_lock<std::mutex> lock(amutex_);
275- if (isRawFile_) {341+ 
276- MEDIA_LOGI("audio raw data, return.");
277- CHECK_AND_RETURN_LOG(audioDec_ != nullptr, "Failed to obtain audio decode.");
278- audioDec_->ReleaseOutputBuffer(index);
279- return;
280- }
281 if (buffer != nullptr && !decodeShouldCompleted_) {342 if (buffer != nullptr && !decodeShouldCompleted_) {
282 if (currentSoundBufferSize_ > MAX_SOUND_BUFFER_SIZE || flag == AVCODEC_BUFFER_FLAG_EOS) {343 if (currentSoundBufferSize_ > MAX_SOUND_BUFFER_SIZE || flag == AVCODEC_BUFFER_FLAG_EOS) {
283 decodeShouldCompleted_ = true;344 decodeShouldCompleted_ = true;
@@ -174,6 +174,7 @@ private:
174 };174 };
175 175 
176 int32_t DoDemuxer(MediaAVCodec::Format *trackFormat);176 int32_t DoDemuxer(MediaAVCodec::Format *trackFormat);
177+ int32_t GetAudioBuffers(MediaAVCodec::Format *trackFormat);
177 int32_t DoDecode(MediaAVCodec::Format trackFormat);178 int32_t DoDecode(MediaAVCodec::Format trackFormat);
178 int32_t soundID_ = 0;179 int32_t soundID_ = 0;
179 std::shared_ptr<MediaAVCodec::AVDemuxer> demuxer_;180 std::shared_ptr<MediaAVCodec::AVDemuxer> demuxer_;
@@ -185,12 +186,18 @@ private:
185 std::shared_ptr<ISoundPoolCallback> callback_ = nullptr;186 std::shared_ptr<ISoundPoolCallback> callback_ = nullptr;
186 bool isRawFile_ = false;187 bool isRawFile_ = false;
187 std::atomic<bool> isParsing_ = false;188 std::atomic<bool> isParsing_ = false;
189+ FILE* filePtr_ = nullptr;
190+ int64_t fileOffset_ = 0;
191+ int32_t fileReadLength_ = 0;
192+ std::atomic<bool> rawSoundParserCompleted_ = false;
193+ int32_t rawSoundBufferTotalSize_ = 0;
194+ std::deque<std::shared_ptr<AudioBufferEntry>> rawAudioBuffers_;
188 195 
189 MediaAVCodec::Format trackFormat_;196 MediaAVCodec::Format trackFormat_;
190 197 
191 static constexpr int32_t AUDIO_SOURCE_TRACK_COUNT = 1;198 static constexpr int32_t AUDIO_SOURCE_TRACK_COUNT = 1;
192 static constexpr int32_t AUDIO_SOURCE_TRACK_INDEX = 0;199 static constexpr int32_t AUDIO_SOURCE_TRACK_INDEX = 0;
193- static constexpr int64_t MIN_FD = 0;200+ static constexpr int64_t minFd = 3;
zhangq444zhangever
zhangq444zhangq4442024年6月21日

常量命名用大写

如上图,原来的命名方式codeCheck过不了,门禁给出的建议是使用驼峰的命名方式

likedislike
zhangeverzhangever2024年6月21日

常量命名用大写

likedislike
194};201};
195} // namespace Media202} // namespace Media
196} // namespace OHOS203} // namespace OHOS
@@ -114,6 +114,8 @@ int32_t StreamIDManager::Play(std::shared_ptr<SoundParser> soundParser, PlayPara
114 std::deque<std::shared_ptr<AudioBufferEntry>> cacheData;114 std::deque<std::shared_ptr<AudioBufferEntry>> cacheData;
115 soundParser->GetSoundData(cacheData);115 soundParser->GetSoundData(cacheData);
116 size_t cacheDataTotalSize = soundParser->GetSoundDataTotalSize();116 size_t cacheDataTotalSize = soundParser->GetSoundDataTotalSize();
117+ MEDIA_LOGI("cacheData size:%{public}zu , cacheDataTotalSize:%{public}zu",
118+ cacheData.size(), cacheDataTotalSize);
117 auto cacheBuffer =119 auto cacheBuffer =
118 std::make_shared<CacheBuffer>(soundParser->GetSoundTrackFormat(), cacheData, cacheDataTotalSize,120 std::make_shared<CacheBuffer>(soundParser->GetSoundTrackFormat(), cacheData, cacheDataTotalSize,
119 soundID, streamID);121 soundID, streamID);
@@ -306,6 +306,7 @@
306 <option name="push" value="res_soundpool/test_04.mp3 -> /data/test" src="res"/>306 <option name="push" value="res_soundpool/test_04.mp3 -> /data/test" src="res"/>
307 <option name="push" value="res_soundpool/test_05.ogg -> /data/test" src="res"/>307 <option name="push" value="res_soundpool/test_05.ogg -> /data/test" src="res"/>
308 <option name="push" value="res_soundpool/test_06.ogg -> /data/test" src="res"/>308 <option name="push" value="res_soundpool/test_06.ogg -> /data/test" src="res"/>
309+ <option name="push" value="res_soundpool/test_07.wav -> /data/test" src="res"/>
309 <option name="shell" value="restorecon /data/test"/>310 <option name="shell" value="restorecon /data/test"/>
310 </preparer>311 </preparer>
311 </target>312 </target>
Binary files do not support preview
@@ -21,13 +21,14 @@ using namespace OHOS::Media;
21using namespace testing::ext;21using namespace testing::ext;
22using namespace std;22using namespace std;
23 23 
24-static const std::string g_fileName[6] = {24+static const std::string g_fileName[7] = {
zhangever
zhangeverzhangever2024年6月21日

这个大小可以不要吧

likedislike
25 {"/data/test/test_06.ogg"},25 {"/data/test/test_06.ogg"},
26 {"/data/test/test_02.mp3"},26 {"/data/test/test_02.mp3"},
27 {"/data/test/test_01.mp3"},27 {"/data/test/test_01.mp3"},
28 {"/data/test/test_05.ogg"},28 {"/data/test/test_05.ogg"},
29 {"/data/test/test_03.mp3"},29 {"/data/test/test_03.mp3"},
30 {"/data/test/test_04.mp3"},30 {"/data/test/test_04.mp3"},
31+ {"/data/test/test_07.wav"},
31};32};
32 33 
33namespace OHOS {34namespace OHOS {
@@ -1822,5 +1823,33 @@ HWTEST_F(SoundPoolUnitTest, soundpool_function_037, TestSize.Level2)
1822 MEDIA_LOGI("soundpool_unit_test soundpool_function_037 after");1823 MEDIA_LOGI("soundpool_unit_test soundpool_function_037 after");
1823}1824}
1824 1825 
1826+ /**
1827+ * @tc.name: soundpool_function_038
1828+ * @tc.desc: function test WAV file
1829+ * @tc.type: FUNC
1830+ * @tc.require:
1831+ */
1832+HWTEST_F(SoundPoolUnitTest, soundpool_function_038, TestSize.Level2)
1833+{
1834+ MEDIA_LOGI("soundpool_unit_test soundpool_function_038 before");
1835+ int maxStreams = 3;
1836+ create(maxStreams);
1837+ std::shared_ptr<SoundPoolCallbackTest> cb = std::make_shared<SoundPoolCallbackTest>(soundPool_);
1838+ soundPool_->SetSoundPoolCallback(cb);
1839+ loadUrl(g_fileName[6], loadNum_);
1840+ sleep(waitTime3);
1841+ struct PlayParams playParameters;
1842+ if (soundIDs_[0] > 0) {
1843+ streamIDs_[0] = soundPool_->Play(soundIDs_[0], playParameters);
1844+ EXPECT_GT(streamIDs_[0], 0);
1845+ sleep(waitTime2);
1846+ }
1847+ sleep(waitTime3);
1848+ if (streamIDs_[0] > 0) {
1849+ EXPECT_EQ(MSERR_OK, soundPool_->Stop(streamIDs_[0]));
1850+ }
1851+ MEDIA_LOGI("soundpool_unit_test soundpool_function_038 after");
1852+}
1853+ 
1825} // namespace Media1854} // namespace Media
1826} // namespace OHOS1855} // namespace OHOS