1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <string>
17 #include <ctime>
18 #include <sys/time.h>
19 #include "gtest/gtest.h"
20 #include "AudioDecoderDemoCommon.h"
21 
22 using namespace std;
23 using namespace testing::ext;
24 using namespace OHOS;
25 using namespace OHOS::MediaAVCodec;
26 constexpr uint32_t SIZE_7 = 7;
27 constexpr uint32_t SIZE_5 = 5;
28 constexpr uint32_t SIZE_4 = 4;
29 constexpr uint32_t PER_CODED_SAMPL = 16;
30 
31 namespace {
32     class NativeStablityTest : public testing::Test {
33     public:
34         static void SetUpTestCase();
35         static void TearDownTestCase();
36         void SetUp() override;
37         void TearDown() override;
38     };
39 
SetUpTestCase()40     void NativeStablityTest::SetUpTestCase() {}
TearDownTestCase()41     void NativeStablityTest::TearDownTestCase() {}
SetUp()42     void NativeStablityTest::SetUp() {}
TearDown()43     void NativeStablityTest::TearDown() {}
44 
45     constexpr int RUN_TIMES = 2000;
46     constexpr int RUN_TIME = 12 * 3600;
47     constexpr uint32_t DEFAULT_AAC_TYPE = 1;
48 
49     constexpr int32_t SPLIT_INDEX_1 = 1;
50     constexpr int32_t SPLIT_INDEX_2 = 2;
51     constexpr int32_t SPLIT_INDEX_3 = 3;
52     constexpr int32_t SPLIT_INDEX_4 = 4;
53     constexpr int32_t SPLIT_INDEX_5 = 5;
54 
55     int32_t g_testResult[16] = { -1 };
56 
SplitStringFully(const string & str,const string & separator)57     vector<string> SplitStringFully(const string& str, const string& separator)
58     {
59         vector<string> dest;
60         string substring;
61         string::size_type start = 0;
62         string::size_type index = str.find_first_of(separator, start);
63 
64         while (index != string::npos) {
65             substring = str.substr(start, index - start);
66             dest.push_back(substring);
67             start = str.find_first_not_of(separator, index);
68             if (start == string::npos) {
69                 return dest;
70             }
71 
72             index = str.find_first_of(separator, start);
73         }
74         substring = str.substr(start);
75         dest.push_back(substring);
76 
77         return dest;
78     }
79 
StringReplace(std::string & strBig,const std::string & strsrc,const std::string & strdst)80     void StringReplace(std::string& strBig, const std::string& strsrc, const std::string& strdst)
81     {
82         std::string::size_type pos = 0;
83         std::string::size_type srclen = strsrc.size();
84         std::string::size_type dstlen = strdst.size();
85 
86         while ((pos = strBig.find(strsrc, pos)) != std::string::npos) {
87             strBig.replace(pos, srclen, strdst);
88             pos += dstlen;
89         }
90     }
91 
GetParamsByName(string decoderName,string inputFile,int32_t & channelCount,int32_t & sampleRate,long & bitrate)92     void GetParamsByName(string decoderName, string inputFile, int32_t& channelCount,
93         int32_t& sampleRate, long& bitrate)
94     {
95         vector<string> dest = SplitStringFully(inputFile, "_");
96         if (decoderName == "OH.Media.Codec.Decoder.Audio.AAC") {
97             if (dest.size() < SIZE_7) {
98                 cout << "split error !!!" << endl;
99                 return;
100             }
101             channelCount = stoi(dest[SPLIT_INDEX_5]);
102             sampleRate = stoi(dest[SPLIT_INDEX_4]);
103 
104             string bitStr = dest[SPLIT_INDEX_3];
105             StringReplace(bitStr, "k", "000");
106             bitrate = atol(bitStr.c_str());
107         } else if (decoderName == "OH.Media.Codec.Decoder.Audio.Mpeg") {
108             if (dest.size() < SIZE_5) {
109                 cout << "split error !!!" << endl;
110                 return;
111             }
112             channelCount = stoi(dest[SPLIT_INDEX_3]);
113             sampleRate = stoi(dest[SPLIT_INDEX_2]);
114 
115             string bitStr = dest[SPLIT_INDEX_1];
116             StringReplace(bitStr, "k", "000");
117             bitrate = atol(bitStr.c_str());
118         } else if (decoderName == "OH.Media.Codec.Decoder.Audio.Flac") {
119             if (dest.size() < SIZE_4) {
120                 cout << "split error !!!" << endl;
121                 return;
122             }
123             channelCount = stoi(dest[SPLIT_INDEX_2]);
124             sampleRate = stoi(dest[SPLIT_INDEX_1]);
125 
126             string bitStr = dest[SPLIT_INDEX_1];
127             StringReplace(bitStr, "k", "000");
128             bitrate = atol(bitStr.c_str());
129         } else {
130             if (dest.size() < SIZE_5) {
131                 cout << "split error !!!" << endl;
132                 return;
133             }
134             channelCount = stoi(dest[SPLIT_INDEX_3]);
135             sampleRate = stoi(dest[SPLIT_INDEX_2]);
136 
137             string bitStr = dest[SPLIT_INDEX_1];
138             StringReplace(bitStr, "k", "000");
139             bitrate = atol(bitStr.c_str());
140         }
141     }
142 
GetAVFormatByDecoder(string decoderName,string inputFile)143     OH_AVFormat* GetAVFormatByDecoder(string decoderName, string inputFile)
144     {
145         OH_AVFormat* format;
146         int32_t channelCount;
147         int32_t sampleRate;
148         long bitrate;
149         GetParamsByName(decoderName, inputFile, channelCount, sampleRate, bitrate);
150         if (decoderName == "OH.Media.Codec.Decoder.Audio.AAC") {
151             format = OH_AVFormat_Create();
152             OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, channelCount);
153             OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, sampleRate);
154             OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
155             OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, bitrate);
156         } else if (decoderName == "OH.Media.Codec.Decoder.Audio.Mpeg") {
157             format = OH_AVFormat_Create();
158             OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, channelCount);
159             OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, sampleRate);
160             OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, bitrate);
161         } else if (decoderName == "OH.Media.Codec.Decoder.Audio.Flac") {
162             format = OH_AVFormat_Create();
163             OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, channelCount);
164             OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, sampleRate);
165             OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, PER_CODED_SAMPL);
166             OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, bitrate);
167         } else {
168             format = OH_AVFormat_Create();
169             OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, channelCount);
170             OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, sampleRate);
171             OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, bitrate);
172         }
173         return format;
174     }
175 
RunDecode(string decoderName,string inputFile,string outputFile,int32_t threadId)176     void RunDecode(string decoderName, string inputFile, string outputFile, int32_t threadId)
177     {
178         AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
179 
180         OH_AVFormat* format = GetAVFormatByDecoder(decoderName, inputFile);
181 
182         decoderDemo->NativeRunCase(inputFile, outputFile, decoderName.c_str(), format);
183         OH_AVFormat_Destroy(format);
184 
185         g_testResult[threadId] = AV_ERR_OK;
186 
187         delete decoderDemo;
188     }
189 
TestFFmpeg()190     void TestFFmpeg()
191     {
192         AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
193 
194         decoderDemo->TestFFmpeg("fltp_aac_low_128k_16000_1_dayuhaitang.aac");
195 
196         delete decoderDemo;
197     }
198 
RunLongTimeFlush(string decoderName,string inputFile,string outputFile,int32_t threadId)199     void RunLongTimeFlush(string decoderName, string inputFile, string outputFile, int32_t threadId)
200     {
201         AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
202         bool needConfigure = true;
203 
204         time_t startTime = time(nullptr);
205         ASSERT_NE(startTime, -1);
206         time_t curTime = startTime;
207 
208         OH_AVCodec* handle = decoderDemo->NativeCreateByName(decoderName.c_str());
209         OH_AVFormat* format = GetAVFormatByDecoder(decoderName, inputFile);
210         struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged,
211             &OnInputBufferAvailable, &OnOutputBufferAvailable };
212         decoderDemo->NativeSetCallback(handle, cb);
213 
214         while (difftime(curTime, startTime) < RUN_TIME) {
215             decoderDemo->NativeRunCaseWithoutCreate(handle, inputFile, outputFile,
216                 format, decoderName.c_str(), needConfigure);
217             needConfigure = false;
218             decoderDemo->NativeFlush(handle);
219             curTime = time(nullptr);
220             ASSERT_NE(curTime, -1);
221         }
222         OH_AVFormat_Destroy(format);
223         decoderDemo->NativeDestroy(handle);
224         delete decoderDemo;
225         g_testResult[threadId] = AV_ERR_OK;
226     }
227 
RunLongTimeReset(string decoderName,string inputFile,string outputFile,int32_t threadId)228     void RunLongTimeReset(string decoderName, string inputFile, string outputFile, int32_t threadId)
229     {
230         AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
231         bool needConfigure = true;
232 
233         time_t startTime = time(nullptr);
234         ASSERT_NE(startTime, -1);
235         time_t curTime = startTime;
236 
237         OH_AVCodec* handle = decoderDemo->NativeCreateByName(decoderName.c_str());
238         OH_AVFormat* format = GetAVFormatByDecoder(decoderName, inputFile);
239         struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged,
240             &OnInputBufferAvailable, &OnOutputBufferAvailable };
241         decoderDemo->NativeSetCallback(handle, cb);
242 
243         while (difftime(curTime, startTime) < RUN_TIME) {
244             decoderDemo->NativeRunCaseWithoutCreate(handle, inputFile, outputFile,
245                 format, decoderName.c_str(), needConfigure);
246             needConfigure = false;
247             decoderDemo->NativeFlush(handle);
248             curTime = time(nullptr);
249             ASSERT_NE(curTime, -1);
250         }
251 
252         OH_AVFormat_Destroy(format);
253         decoderDemo->NativeDestroy(handle);
254         delete decoderDemo;
255         g_testResult[threadId] = AV_ERR_OK;
256     }
257 
RunLongTimeStop(string decoderName,string inputFile,string outputFile,int32_t threadId)258     void RunLongTimeStop(string decoderName, string inputFile, string outputFile, int32_t threadId)
259     {
260         AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
261         bool needConfigure = true;
262 
263         time_t startTime = time(nullptr);
264         ASSERT_NE(startTime, -1);
265         time_t curTime = startTime;
266 
267         OH_AVCodec* handle = decoderDemo->NativeCreateByName(decoderName.c_str());
268         OH_AVFormat* format = GetAVFormatByDecoder(decoderName, inputFile);
269         struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged,
270             &OnInputBufferAvailable, &OnOutputBufferAvailable };
271         decoderDemo->NativeSetCallback(handle, cb);
272 
273         while (difftime(curTime, startTime) < RUN_TIME) {
274             decoderDemo->NativeRunCaseWithoutCreate(handle, inputFile, outputFile,
275                 format, decoderName.c_str(), needConfigure);
276             needConfigure = false;
277             decoderDemo->NativeStop(handle);
278             curTime = time(nullptr);
279             ASSERT_NE(curTime, -1);
280         }
281 
282         OH_AVFormat_Destroy(format);
283         decoderDemo->NativeDestroy(handle);
284         delete decoderDemo;
285         g_testResult[threadId] = AV_ERR_OK;
286     }
287 }
288 
289 
290 /**
291  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_001
292  * @tc.name      : OH_AudioDecoder_CreateByMime 2000 times
293  * @tc.desc      : stability
294  */
295 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_001, TestSize.Level2)
296 {
297     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
298     double totalTime = 0;
299     struct timeval start, end;
300     for (int i = 0; i < RUN_TIMES; i++)
301     {
302         gettimeofday(&start, nullptr);
303         OH_AVCodec* handle = decoderDemo->NativeCreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
304         gettimeofday(&end, nullptr);
305         totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
306         ASSERT_NE(nullptr, handle);
307         decoderDemo->NativeDestroy(handle);
308     }
309     cout << "2000 times finish, run time is " << totalTime << endl;
310     delete decoderDemo;
311 }
312 
313 
314 /**
315  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_002
316  * @tc.name      : OH_AudioDecoder_CreateByName 2000 times
317  * @tc.desc      : stability
318  */
319 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_002, TestSize.Level2)
320 {
321     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
322     double totalTime = 0;
323     struct timeval start, end;
324     for (int i = 0; i < RUN_TIMES; i++)
325     {
326         gettimeofday(&start, nullptr);
327         OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
328         gettimeofday(&end, nullptr);
329         totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
330         ASSERT_NE(nullptr, handle);
331         decoderDemo->NativeDestroy(handle);
332     }
333     cout << "2000 times finish, run time is " << totalTime << endl;
334     delete decoderDemo;
335 }
336 
337 
338 /**
339  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_003
340  * @tc.name      : OH_AudioDecoder_Destroy 2000 times
341  * @tc.desc      : stability
342  */
343 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_003, TestSize.Level2)
344 {
345     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
346     double totalTime = 0;
347     struct timeval start, end;
348 
349     for (int i = 0; i < RUN_TIMES; i++)
350     {
351         OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
352         ASSERT_NE(nullptr, handle);
353         gettimeofday(&start, nullptr);
354         decoderDemo->NativeDestroy(handle);
355         gettimeofday(&end, nullptr);
356         totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
357     }
358     cout << "2000 times finish, run time is " << totalTime << endl;
359     delete decoderDemo;
360 }
361 
362 
363 /**
364  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_004
365  * @tc.name      : OH_AudioDecoder_SetCallback 2000 times
366  * @tc.desc      : stability
367  */
368 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_004, TestSize.Level2)
369 {
370     OH_AVErrCode ret;
371     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
372     double totalTime = 0;
373     struct timeval start, end;
374 
375     OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
376     ASSERT_NE(nullptr, handle);
377     struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged,
378     &OnInputBufferAvailable, &OnOutputBufferAvailable };
379     for (int i = 0; i < RUN_TIMES; i++)
380     {
381         gettimeofday(&start, nullptr);
382         ret = decoderDemo->NativeSetCallback(handle, cb);
383         gettimeofday(&end, nullptr);
384         totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
385         ASSERT_EQ(AV_ERR_OK, ret);
386     }
387     cout << "2000 times finish, run time is " << totalTime << endl;
388     decoderDemo->NativeDestroy(handle);
389     delete decoderDemo;
390 }
391 
392 
393 /**
394  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_005
395  * @tc.name      : OH_AudioDecoder_Configure 2000 times
396  * @tc.desc      : stability
397  */
398 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_005, TestSize.Level2)
399 {
400     OH_AVErrCode ret;
401     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
402     double totalTime = 0;
403     struct timeval start, end;
404 
405     OH_AVFormat* format = OH_AVFormat_Create();
406     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
407     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
408     OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
409 
410     for (int i = 0; i < RUN_TIMES; i++)
411     {
412         OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
413         ASSERT_NE(nullptr, handle);
414         struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged,
415         &OnInputBufferAvailable, &OnOutputBufferAvailable };
416         ret = decoderDemo->NativeSetCallback(handle, cb);
417         ASSERT_EQ(AV_ERR_OK, ret);
418         gettimeofday(&start, nullptr);
419         ret = decoderDemo->NativeConfigure(handle, format);
420         gettimeofday(&end, nullptr);
421         totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
422         ASSERT_EQ(AV_ERR_OK, ret);
423 
424         decoderDemo->NativeDestroy(handle);
425     }
426     cout << "2000 times finish, run time is " << totalTime << endl;
427 
428     OH_AVFormat_Destroy(format);
429     delete decoderDemo;
430 }
431 
432 /**
433  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_006
434  * @tc.name      : OH_AudioDecoder_Prepare 2000 times
435  * @tc.desc      : stability
436  */
437 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_006, TestSize.Level2)
438 {
439     OH_AVErrCode ret;
440     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
441     double totalTime = 0;
442     struct timeval start, end;
443 
444     OH_AVFormat* format = OH_AVFormat_Create();
445     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
446     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
447     OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
448 
449     for (int i = 0; i < RUN_TIMES; i++)
450     {
451         OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
452         ASSERT_NE(nullptr, handle);
453         struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged,
454         &OnInputBufferAvailable, &OnOutputBufferAvailable };
455         ret = decoderDemo->NativeSetCallback(handle, cb);
456         ASSERT_EQ(AV_ERR_OK, ret);
457         ret = decoderDemo->NativeConfigure(handle, format);
458         ASSERT_EQ(AV_ERR_OK, ret);
459         gettimeofday(&start, nullptr);
460         ret = decoderDemo->NativePrepare(handle);
461         gettimeofday(&end, nullptr);
462         totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
463         ASSERT_EQ(AV_ERR_OK, ret);
464         decoderDemo->NativeDestroy(handle);
465     }
466     cout << "2000 times finish, run time is " << totalTime << endl;
467 
468     OH_AVFormat_Destroy(format);
469     delete decoderDemo;
470 }
471 
472 
473 /**
474  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_007
475  * @tc.name      : OH_AudioDecoder_Start 2000 times
476  * @tc.desc      : stability
477  */
478 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_007, TestSize.Level2)
479 {
480     OH_AVErrCode ret;
481     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
482     double totalTime = 0;
483     struct timeval start, end;
484 
485     OH_AVFormat* format = OH_AVFormat_Create();
486     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
487     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
488     OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
489 
490     for (int i = 0; i < RUN_TIMES; i++)
491     {
492         OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
493         ASSERT_NE(nullptr, handle);
494         struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged,
495         &OnInputBufferAvailable, &OnOutputBufferAvailable };
496         ret = decoderDemo->NativeSetCallback(handle, cb);
497         ASSERT_EQ(AV_ERR_OK, ret);
498         ret = decoderDemo->NativeConfigure(handle, format);
499         ASSERT_EQ(AV_ERR_OK, ret);
500         ret = decoderDemo->NativePrepare(handle);
501         ASSERT_EQ(AV_ERR_OK, ret);
502         gettimeofday(&start, nullptr);
503         ret = OH_AudioDecoder_Start(handle);
504         gettimeofday(&end, nullptr);
505         totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
506         ASSERT_EQ(AV_ERR_OK, ret);
507         decoderDemo->NativeDestroy(handle);
508     }
509     cout << "2000 times finish, run time is " << totalTime << endl;
510 
511     OH_AVFormat_Destroy(format);
512     delete decoderDemo;
513 }
514 
515 
516 /**
517  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_008
518  * @tc.name      : OH_AudioDecoder_Stop 2000 times
519  * @tc.desc      : stability
520  */
521 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_008, TestSize.Level2)
522 {
523     OH_AVErrCode ret;
524     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
525     double totalTime = 0;
526     struct timeval start, end;
527 
528     OH_AVFormat* format = OH_AVFormat_Create();
529     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
530     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
531     OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
532 
533     for (int i = 0; i < RUN_TIMES; i++)
534     {
535         OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
536         ASSERT_NE(nullptr, handle);
537         struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged,
538         &OnInputBufferAvailable, &OnOutputBufferAvailable };
539         ret = decoderDemo->NativeSetCallback(handle, cb);
540         ASSERT_EQ(AV_ERR_OK, ret);
541         ret = decoderDemo->NativeConfigure(handle, format);
542         ASSERT_EQ(AV_ERR_OK, ret);
543         ret = decoderDemo->NativePrepare(handle);
544         ASSERT_EQ(AV_ERR_OK, ret);
545         ret = OH_AudioDecoder_Start(handle);
546         ASSERT_EQ(AV_ERR_OK, ret);
547         gettimeofday(&start, nullptr);
548         ret = OH_AudioDecoder_Stop(handle);
549         gettimeofday(&end, nullptr);
550         totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
551         ASSERT_EQ(AV_ERR_OK, ret);
552         decoderDemo->NativeDestroy(handle);
553     }
554     cout << "2000 times finish, run time is " << totalTime << endl;
555 
556     OH_AVFormat_Destroy(format);
557     delete decoderDemo;
558 }
559 
560 
561 /**
562  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_009
563  * @tc.name      : OH_AudioDecoder_Flush 2000 times
564  * @tc.desc      : stability
565  */
566 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_009, TestSize.Level2)
567 {
568     OH_AVErrCode ret;
569     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
570     double totalTime = 0;
571     struct timeval start, end;
572 
573     OH_AVFormat* format = OH_AVFormat_Create();
574     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
575     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
576     OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
577 
578     for (int i = 0; i < RUN_TIMES; i++)
579     {
580         OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
581         ASSERT_NE(nullptr, handle);
582         struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged,
583         &OnInputBufferAvailable, &OnOutputBufferAvailable };
584         ret = decoderDemo->NativeSetCallback(handle, cb);
585         ASSERT_EQ(AV_ERR_OK, ret);
586         ret = decoderDemo->NativeConfigure(handle, format);
587         ASSERT_EQ(AV_ERR_OK, ret);
588         ret = decoderDemo->NativePrepare(handle);
589         ASSERT_EQ(AV_ERR_OK, ret);
590         ret = OH_AudioDecoder_Start(handle);
591         ASSERT_EQ(AV_ERR_OK, ret);
592         gettimeofday(&start, nullptr);
593         ret = decoderDemo->NativeFlush(handle);
594         gettimeofday(&end, nullptr);
595         totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
596         ASSERT_EQ(AV_ERR_OK, ret);
597         decoderDemo->NativeDestroy(handle);
598     }
599     cout << "2000 times finish, run time is " << totalTime << endl;
600 
601     OH_AVFormat_Destroy(format);
602     delete decoderDemo;
603 }
604 
605 
606 /**
607  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_010
608  * @tc.name      : OH_AudioDecoder_Reset 2000 times
609  * @tc.desc      : stability
610  */
611 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_010, TestSize.Level2)
612 {
613     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
614     double totalTime = 0;
615     struct timeval start, end;
616 
617     OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
618     ASSERT_NE(nullptr, handle);
619 
620     for (int i = 0; i < RUN_TIMES; i++)
621     {
622         gettimeofday(&start, nullptr);
623         OH_AudioDecoder_Reset(handle);
624         gettimeofday(&end, nullptr);
625         totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
626     }
627     cout << "2000 times finish, run time is " << totalTime << endl;
628     delete decoderDemo;
629 }
630 
631 
632 /**
633  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_011
634  * @tc.name      : OH_AudioDecoder_GetOutputDescription 2000 times
635  * @tc.desc      : stability
636  */
637 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_011, TestSize.Level2)
638 {
639     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
640 
641     string decoderName = "OH.Media.Codec.Decoder.Audio.AAC";
642 
643     string inputFile = "fltp_aac_low_500k_96000_2_dayuhaitang.aac";
644     string outputFile = "STABILITY_010.pcm";
645 
646     vector<string> dest = SplitStringFully(inputFile, "_");
647     if (dest.size() < SIZE_7)
648     {
649         cout << "split error !!!" << endl;
650         return;
651     }
652     int32_t channelCount = stoi(dest[5]);
653     int32_t sampleRate = stoi(dest[4]);
654 
655     string bitStr = dest[3];
656     StringReplace(bitStr, "k", "000");
657     long bitrate = atol(bitStr.c_str());
658 
659     OH_AVFormat* format = OH_AVFormat_Create();
660     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, channelCount);
661     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, sampleRate);
662     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
663     OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, bitrate);
664     ASSERT_NE(nullptr, format);
665 
666     decoderDemo->setTimerFlag(TIMER_GETOUTPUTDESCRIPTION);
667     decoderDemo->NativeRunCase(inputFile, outputFile, decoderName.c_str(), format);
668 
669     OH_AVFormat_Destroy(format);
670     delete decoderDemo;
671 }
672 
673 
674 /**
675  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_012
676  * @tc.name      : OH_AudioDecoder_SetParameter 2000 times
677  * @tc.desc      : stability
678  */
679 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_012, TestSize.Level2)
680 {
681     OH_AVErrCode ret;
682     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
683     double totalTime = 0;
684     struct timeval start, end;
685 
686     OH_AVFormat* format = OH_AVFormat_Create();
687     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
688     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
689     OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
690 
691     OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
692     ASSERT_NE(nullptr, handle);
693 
694     struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged,
695     &OnInputBufferAvailable, &OnOutputBufferAvailable };
696     ret = decoderDemo->NativeSetCallback(handle, cb);
697     ASSERT_EQ(AV_ERR_OK, ret);
698     ret = decoderDemo->NativeConfigure(handle, format);
699     ASSERT_EQ(AV_ERR_OK, ret);
700     ret = decoderDemo->NativePrepare(handle);
701     ASSERT_EQ(AV_ERR_OK, ret);
702     ret = decoderDemo->NativeStart(handle);
703     ASSERT_EQ(AV_ERR_OK, ret);
704 
705     for (int i = 0; i < RUN_TIMES; i++)
706     {
707         gettimeofday(&start, nullptr);
708         ret = decoderDemo->NativeSetParameter(handle, format);
709         gettimeofday(&end, nullptr);
710         totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
711         ASSERT_EQ(AV_ERR_OK, ret);
712     }
713 
714     cout << "2000 times finish, run time is " << totalTime << endl;
715     decoderDemo->NativeDestroy(handle);
716     OH_AVFormat_Destroy(format);
717     delete decoderDemo;
718 }
719 
720 
721 /**
722  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_013
723  * @tc.name      : OH_AudioDecoder_PushInputData 2000 times
724  * @tc.desc      : stability
725  */
726 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_013, TestSize.Level2)
727 {
728     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
729 
730     string decoderName = "OH.Media.Codec.Decoder.Audio.AAC";
731 
732     string inputFile = "fltp_aac_low_500k_96000_2_dayuhaitang.aac";
733     string outputFile = "STABILITY_010.pcm";
734 
735     vector<string> dest = SplitStringFully(inputFile, "_");
736     if (dest.size() < 7)
737     {
738         cout << "split error !!!" << endl;
739         return;
740     }
741     int32_t channelCount = stoi(dest[5]);
742     int32_t sampleRate = stoi(dest[4]);
743 
744     string bitStr = dest[3];
745     StringReplace(bitStr, "k", "000");
746     long bitrate = atol(bitStr.c_str());
747 
748     OH_AVFormat* format = OH_AVFormat_Create();
749     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, channelCount);
750     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, sampleRate);
751     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
752     OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, bitrate);
753     ASSERT_NE(nullptr, format);
754 
755     decoderDemo->setTimerFlag(TIMER_INPUT);
756     decoderDemo->NativeRunCase(inputFile, outputFile, decoderName.c_str(), format);
757 
758     OH_AVFormat_Destroy(format);
759     delete decoderDemo;
760 }
761 
762 
763 /**
764  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_014
765  * @tc.name      : OH_AudioDecoder_FreeOutputData 2000 times
766  * @tc.desc      : stability
767  */
768 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_014, TestSize.Level2)
769 {
770     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
771 
772     string decoderName = "OH.Media.Codec.Decoder.Audio.AAC";
773 
774     string inputFile = "fltp_aac_low_500k_96000_2_dayuhaitang.aac";
775     string outputFile = "STABILITY_010.pcm";
776 
777     vector<string> dest = SplitStringFully(inputFile, "_");
778     if (dest.size() < 7)
779     {
780         cout << "split error !!!" << endl;
781         return;
782     }
783     int32_t channelCount = stoi(dest[5]);
784     int32_t sampleRate = stoi(dest[4]);
785 
786     string bitStr = dest[3];
787     StringReplace(bitStr, "k", "000");
788     long bitrate = atol(bitStr.c_str());
789 
790     OH_AVFormat* format = OH_AVFormat_Create();
791     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, channelCount);
792     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, sampleRate);
793     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE);
794     OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, bitrate);
795     ASSERT_NE(nullptr, format);
796 
797     decoderDemo->setTimerFlag(TIMER_FREEOUTPUT);
798     decoderDemo->NativeRunCase(inputFile, outputFile, decoderName.c_str(), format);
799 
800     OH_AVFormat_Destroy(format);
801     delete decoderDemo;
802 }
803 
804 
805 /**
806  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_015
807  * @tc.name      : OH_AudioDecoder_IsValid 2000 times
808  * @tc.desc      : stability
809  */
810 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_015, TestSize.Level2)
811 {
812     OH_AVErrCode ret;
813     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
814     double totalTime = 0;
815     struct timeval start, end;
816     bool isValid;
817 
818     OH_AVFormat* format = OH_AVFormat_Create();
819     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2);
820     OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100);
821     OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000);
822 
823     OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg");
824     ASSERT_NE(nullptr, handle);
825 
826     struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged,
827     &OnInputBufferAvailable, &OnOutputBufferAvailable };
828     ret = decoderDemo->NativeSetCallback(handle, cb);
829     ASSERT_EQ(AV_ERR_OK, ret);
830     ret = decoderDemo->NativeConfigure(handle, format);
831     ASSERT_EQ(AV_ERR_OK, ret);
832     ret = decoderDemo->NativePrepare(handle);
833     ASSERT_EQ(AV_ERR_OK, ret);
834     ret = decoderDemo->NativeStart(handle);
835     ASSERT_EQ(AV_ERR_OK, ret);
836 
837     for (int i = 0; i < RUN_TIMES; i++)
838     {
839         gettimeofday(&start, nullptr);
840         ret = decoderDemo->NativeIsValid(handle, &isValid);
841         gettimeofday(&end, nullptr);
842         totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
843         cout << "IsValid ret is " << ret << endl;
844     }
845 
846     cout << "2000 times finish, run time is " << totalTime << endl;
847     decoderDemo->NativeDestroy(handle);
848     OH_AVFormat_Destroy(format);
849     delete decoderDemo;
850 }
851 
852 
853 /**
854  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_016
855  * @tc.name      : decoder(long time)
856  * @tc.desc      : stability
857  */
858 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_016, TestSize.Level2)
859 {
860     string decoderList[] = { "OH.Media.Codec.Decoder.Audio.AAC", "OH.Media.Codec.Decoder.Audio.Mpeg",
861     "OH.Media.Codec.Decoder.Audio.Flac", "OH.Media.Codec.Decoder.Audio.Vorbis" };
862     string decoderName;
863     string inputFile;
864     string outputFile = "STABILITY_016.pcm";
865 
866     time_t startTime = time(nullptr);
867     ASSERT_NE(startTime, -1);
868     time_t curTime = startTime;
869 
870     while (difftime(curTime, startTime) < RUN_TIME)
871     {
872         for (int i = 0; i < 4; i++)
873         {
874             decoderName = decoderList[i];
875             if (decoderName == "OH.Media.Codec.Decoder.Audio.AAC") {
876                 inputFile = "fltp_aac_low_128k_16000_1_dayuhaitang.aac";
877             } else if (decoderName == "OH.Media.Codec.Decoder.Audio.Mpeg") {
878                 inputFile = "fltp_40k_16000_2_dayuhaitang.mp3";
879             } else if (decoderName == "OH.Media.Codec.Decoder.Audio.Flac") {
880                 inputFile = "s16_8000_2_dayuhaitang.flac";
881             } else {
882                 inputFile = "fltp_45k_48000_2_dayuhaitang.ogg";
883             }
884 
885             cout << "cur decoder name is " << decoderName << ", input file is "
886             << inputFile << ", output file is " << outputFile << endl;
887             RunDecode(decoderName, inputFile, outputFile, i);
888             ASSERT_EQ(AV_ERR_OK, g_testResult[i]);
889         }
890         curTime = time(nullptr);
891         ASSERT_NE(curTime, -1);
892     }
893 }
894 
895 
896 /**
897  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_017
898  * @tc.name      : Flush(long time)
899  * @tc.desc      : stability
900  */
901 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_017, TestSize.Level2)
902 {
903     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
904     string decoderName = "OH.Media.Codec.Decoder.Audio.AAC";
905     string inputFile = "fltp_aac_low_128k_16000_1_dayuhaitang.aac";
906     string outputFile = "STABILITY_017.pcm";
907     bool needConfigure = true;
908 
909     time_t startTime = time(nullptr);
910     ASSERT_NE(startTime, -1);
911     time_t curTime = startTime;
912 
913     OH_AVCodec* handle = decoderDemo->NativeCreateByName(decoderName.c_str());
914     OH_AVFormat* format = GetAVFormatByDecoder(decoderName, inputFile);
915     struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged,
916     &OnInputBufferAvailable, &OnOutputBufferAvailable };
917     decoderDemo->NativeSetCallback(handle, cb);
918 
919     while (difftime(curTime, startTime) < RUN_TIME)
920     {
921         decoderDemo->NativeRunCaseWithoutCreate(handle, inputFile, outputFile,
922         format, decoderName.c_str(), needConfigure);
923         needConfigure = false;
924         decoderDemo->NativeFlush(handle);
925         curTime = time(nullptr);
926         ASSERT_NE(curTime, -1);
927     }
928 
929     OH_AVFormat_Destroy(format);
930     decoderDemo->NativeDestroy(handle);
931     delete decoderDemo;
932 }
933 
934 
935 /**
936  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_018
937  * @tc.name      : Reset(long time)
938  * @tc.desc      : stability
939  */
940 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_018, TestSize.Level2)
941 {
942     AudioDecoderDemo* decoderDemo = new AudioDecoderDemo();
943     string decoderName = "OH.Media.Codec.Decoder.Audio.AAC";
944     string inputFile = "fltp_aac_low_128k_16000_1_dayuhaitang.aac";
945     string outputFile = "STABILITY_018.pcm";
946     bool needConfigure = true;
947 
948     time_t startTime = time(nullptr);
949     ASSERT_NE(startTime, -1);
950     time_t curTime = startTime;
951 
952     OH_AVCodec* handle = decoderDemo->NativeCreateByName(decoderName.c_str());
953     OH_AVFormat* format = GetAVFormatByDecoder(decoderName, inputFile);
954     struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged,
955     &OnInputBufferAvailable, &OnOutputBufferAvailable };
956     decoderDemo->NativeSetCallback(handle, cb);
957 
958     while (difftime(curTime, startTime) < RUN_TIME)
959     {
960         decoderDemo->NativeRunCaseWithoutCreate(handle, inputFile, outputFile,
961         format, decoderName.c_str(), needConfigure);
962         decoderDemo->NativeReset(handle);
963         curTime = time(nullptr);
964         ASSERT_NE(curTime, -1);
965     }
966 
967     OH_AVFormat_Destroy(format);
968     decoderDemo->NativeDestroy(handle);
969     delete decoderDemo;
970 }
971 
972 
973 /**
974  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_019
975  * @tc.name      : thread decoder(long time)
976  * @tc.desc      : stability
977  */
978 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_019, TestSize.Level2)
979 {
980     string decoderList[] = { "OH.Media.Codec.Decoder.Audio.AAC", "OH.Media.Codec.Decoder.Audio.Mpeg",
981     "OH.Media.Codec.Decoder.Audio.Flac", "OH.Media.Codec.Decoder.Audio.Vorbis" };
982     string decoderName;
983     string inputFile;
984     vector<thread> threadVec;
985 
986     time_t startTime = time(nullptr);
987     ASSERT_NE(startTime, -1);
988     time_t curTime = startTime;
989 
990     while (difftime(curTime, startTime) < RUN_TIME)
991     {
992         threadVec.clear();
993         for (int32_t i = 0; i < 16; i++)
994         {
995             decoderName = decoderList[i % 4];
996             if (decoderName == "OH.Media.Codec.Decoder.Audio.AAC") {
997                 inputFile = "fltp_aac_low_128k_16000_1_dayuhaitang.aac";
998             } else if (decoderName == "OH.Media.Codec.Decoder.Audio.Mpeg") {
999                 inputFile = "fltp_40k_16000_2_dayuhaitang.mp3";
1000             } else if (decoderName == "OH.Media.Codec.Decoder.Audio.Flac") {
1001                 inputFile = "s16_8000_2_dayuhaitang.flac";
1002             } else {
1003                 inputFile = "fltp_45k_48000_2_dayuhaitang.ogg";
1004             }
1005 
1006             string outputFile = "STABILITY_019_" + to_string(i) + ".pcm";
1007             cout << "cur decoder name is " << decoderName << ", input file is "
1008             << inputFile << ", output file is " << outputFile << endl;
1009             threadVec.push_back(thread(RunDecode, decoderName, inputFile, outputFile, i));
1010         }
1011         for (uint32_t i = 0; i < threadVec.size(); i++)
1012         {
1013             threadVec[i].join();
1014         }
1015         for (int32_t i = 0; i < 16; i++)
1016         {
1017             ASSERT_EQ(AV_ERR_OK, g_testResult[i]);
1018         }
1019         curTime = time(nullptr);
1020         ASSERT_NE(curTime, -1);
1021     }
1022 }
1023 
1024 
1025 /**
1026  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_020
1027  * @tc.name      : thread decoder Flush(long time)
1028  * @tc.desc      : stability
1029  */
1030 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_020, TestSize.Level2)
1031 {
1032     string decoderList[] = { "OH.Media.Codec.Decoder.Audio.AAC", "OH.Media.Codec.Decoder.Audio.Mpeg",
1033     "OH.Media.Codec.Decoder.Audio.Flac", "OH.Media.Codec.Decoder.Audio.Vorbis" };
1034     string decoderName;
1035     string inputFile;
1036     vector<thread> threadVec;
1037 
1038     for (int32_t i = 0; i < 16; i++)
1039     {
1040         decoderName = decoderList[i % 4];
1041         if (decoderName == "OH.Media.Codec.Decoder.Audio.AAC") {
1042             inputFile = "fltp_aac_low_128k_16000_1_dayuhaitang.aac";
1043         } else if (decoderName == "OH.Media.Codec.Decoder.Audio.Mpeg") {
1044             inputFile = "fltp_40k_16000_2_dayuhaitang.mp3";
1045         } else if (decoderName == "OH.Media.Codec.Decoder.Audio.Flac") {
1046             inputFile = "s16_8000_2_dayuhaitang.flac";
1047         } else {
1048             inputFile = "fltp_45k_48000_2_dayuhaitang.ogg";
1049         }
1050 
1051         string outputFile = "STABILITY_020_" + to_string(i) + ".pcm";
1052         cout << "cur decoder name is " << decoderName << ", input file is " << inputFile
1053         << ", output file is " << outputFile << endl;
1054         threadVec.push_back(thread(RunLongTimeFlush, decoderName, inputFile, outputFile, i));
1055     }
1056     for (uint32_t i = 0; i < threadVec.size(); i++)
1057     {
1058         threadVec[i].join();
1059     }
1060     for (int32_t i = 0; i < 16; i++)
1061     {
1062         ASSERT_EQ(AV_ERR_OK, g_testResult[i]);
1063     }
1064 }
1065 
1066 
1067 /**
1068  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_021
1069  * @tc.name      : thread decoder Reset(long time)
1070  * @tc.desc      : stability
1071  */
1072 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_021, TestSize.Level2)
1073 {
1074     string decoderList[] = { "OH.Media.Codec.Decoder.Audio.AAC", "OH.Media.Codec.Decoder.Audio.Mpeg",
1075     "OH.Media.Codec.Decoder.Audio.Flac", "OH.Media.Codec.Decoder.Audio.Vorbis" };
1076     string decoderName;
1077     string inputFile;
1078     vector<thread> threadVec;
1079 
1080     for (int32_t i = 0; i < 16; i++)
1081     {
1082         decoderName = decoderList[i % 4];
1083         if (decoderName == "OH.Media.Codec.Decoder.Audio.AAC") {
1084             inputFile = "fltp_aac_low_128k_16000_1_dayuhaitang.aac";
1085         } else if (decoderName == "OH.Media.Codec.Decoder.Audio.Mpeg") {
1086             inputFile = "fltp_40k_16000_2_dayuhaitang.mp3";
1087         } else if (decoderName == "OH.Media.Codec.Decoder.Audio.Flac") {
1088             inputFile = "s16_8000_2_dayuhaitang.flac";
1089         } else {
1090             inputFile = "fltp_45k_48000_2_dayuhaitang.ogg";
1091         }
1092 
1093         string outputFile = "STABILITY_021_" + to_string(i) + ".pcm";
1094         cout << "cur decoder name is " << decoderName << ", input file is "
1095         << inputFile << ", output file is " << outputFile << endl;
1096         threadVec.push_back(thread(RunLongTimeReset, decoderName, inputFile, outputFile, i));
1097     }
1098     for (uint32_t i = 0; i < threadVec.size(); i++)
1099     {
1100         threadVec[i].join();
1101     }
1102     for (int32_t i = 0; i < 16; i++)
1103     {
1104         ASSERT_EQ(AV_ERR_OK, g_testResult[i]);
1105     }
1106 }
1107 
1108 
1109 /**
1110  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_022
1111  * @tc.name      : Flush(long time)
1112  * @tc.desc      : stability
1113  */
1114 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_022, TestSize.Level2)
1115 {
1116     string decoderList[] = { "OH.Media.Codec.Decoder.Audio.AAC", "OH.Media.Codec.Decoder.Audio.Mpeg",
1117     "OH.Media.Codec.Decoder.Audio.Flac", "OH.Media.Codec.Decoder.Audio.Vorbis" };
1118     string decoderName;
1119     string inputFile;
1120     vector<thread> threadVec;
1121 
1122     for (int32_t i = 0; i < 16; i++)
1123     {
1124         decoderName = decoderList[i % 4];
1125         if (decoderName == "OH.Media.Codec.Decoder.Audio.AAC") {
1126             inputFile = "fltp_aac_low_128k_16000_1_dayuhaitang.aac";
1127         }
1128         else if (decoderName == "OH.Media.Codec.Decoder.Audio.Mpeg") {
1129             inputFile = "fltp_40k_16000_2_dayuhaitang.mp3";
1130         }
1131         else if (decoderName == "OH.Media.Codec.Decoder.Audio.Flac") {
1132             inputFile = "s16_8000_2_dayuhaitang.flac";
1133         }
1134         else {
1135             inputFile = "fltp_45k_48000_2_dayuhaitang.ogg";
1136         }
1137 
1138         string outputFile = "STABILITY_021_" + to_string(i) + ".pcm";
1139         cout << "cur decoder name is " << decoderName << ", input file is "
1140             << inputFile << ", output file is " << outputFile << endl;
1141         threadVec.push_back(thread(RunLongTimeStop, decoderName, inputFile, outputFile, i));
1142     }
1143     for (uint32_t i = 0; i < threadVec.size(); i++)
1144     {
1145         threadVec[i].join();
1146     }
1147     for (int32_t i = 0; i < 16; i++)
1148     {
1149         ASSERT_EQ(AV_ERR_OK, g_testResult[i]);
1150     }
1151 }
1152 
1153 
1154 /**
1155  * @tc.number    : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_100
1156  * @tc.name      : decoder(long time)
1157  * @tc.desc      : stability
1158  */
1159 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_100, TestSize.Level2)
1160 {
1161     time_t startTime = time(nullptr);
1162     ASSERT_NE(startTime, -1);
1163     time_t curTime = startTime;
1164 
1165     while (difftime(curTime, startTime) < RUN_TIME)
1166     {
1167         TestFFmpeg();
1168         curTime = time(nullptr);
1169         ASSERT_NE(curTime, -1);
1170     }
1171 }