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 "gtest/gtest.h" 18 #include "AudioEncoderDemoCommon.h" 19 20 21 using namespace std; 22 using namespace testing::ext; 23 using namespace OHOS; 24 using namespace OHOS::MediaAVCodec; 25 26 namespace { 27 class NativeStablityTest : public testing::Test { 28 public: 29 static void SetUpTestCase(); 30 static void TearDownTestCase(); 31 void SetUp() override; 32 void TearDown() override; 33 }; 34 SetUpTestCase()35 void NativeStablityTest::SetUpTestCase() {} TearDownTestCase()36 void NativeStablityTest::TearDownTestCase() {} SetUp()37 void NativeStablityTest::SetUp() {} TearDown()38 void NativeStablityTest::TearDown() {} 39 40 constexpr int RUN_TIMES = 2000; 41 constexpr int RUN_TIME = 12 * 3600; 42 constexpr uint32_t DEFAULT_AAC_TYPE = 1; 43 44 constexpr int32_t CHANNEL_COUNT_AAC = 2; 45 constexpr int32_t SAMPLE_RATE_AAC = 44100; 46 constexpr int64_t BITS_RATE_AAC = 129000; 47 48 constexpr int32_t CHANNEL_COUNT_FLAC = 2; 49 constexpr int32_t SAMPLE_RATE_FLAC = 48000; 50 constexpr int64_t BITS_RATE_FLAC = 128000; 51 constexpr int32_t INPUT_SIZE_FLAC = COMMON_FLAC_NUM * CHANNEL_COUNT_FLAC * S16_BITS_PER_SAMPLE; 52 53 int32_t g_testResult[16] = { -1 }; 54 GetAVFormatByEncoder(string encoderName)55 OH_AVFormat* GetAVFormatByEncoder(string encoderName) 56 { 57 OH_AVFormat* format = OH_AVFormat_Create(); 58 if (encoderName == "OH.Media.Codec.Encoder.Audio.AAC") { 59 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT_AAC); 60 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE_AAC); 61 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 62 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 63 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 64 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE); 65 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, BITS_RATE_AAC); 66 } else { 67 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT_FLAC); 68 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE_FLAC); 69 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_S16LE); 70 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_S16LE); 71 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 72 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, BITS_RATE_FLAC); 73 OH_AVFormat_SetIntValue(format, OH_MD_KEY_MAX_INPUT_SIZE, INPUT_SIZE_FLAC); 74 } 75 return format; 76 } 77 RunEncode(string encoderName,string inputFile,string outputFile,int32_t threadId)78 void RunEncode(string encoderName, string inputFile, string outputFile, int32_t threadId) 79 { 80 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 81 82 OH_AVFormat* format = GetAVFormatByEncoder(encoderName); 83 84 encoderDemo->NativeRunCase(inputFile, outputFile, encoderName.c_str(), format); 85 86 OH_AVFormat_Destroy(format); 87 delete encoderDemo; 88 } 89 RunLongTimeFlush(string encoderName,string inputFile,string outputFile,int32_t threadId)90 void RunLongTimeFlush(string encoderName, string inputFile, string outputFile, int32_t threadId) 91 { 92 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 93 bool needConfigure = true; 94 95 time_t startTime = time(nullptr); 96 ASSERT_NE(startTime, -1); 97 time_t curTime = startTime; 98 99 OH_AVCodec* handle = encoderDemo->NativeCreateByName(encoderName.c_str()); 100 OH_AVFormat* format = GetAVFormatByEncoder(encoderName); 101 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 102 &OnOutputBufferAvailable}; 103 encoderDemo->NativeSetCallback(handle, cb); 104 105 while (difftime(curTime, startTime) < RUN_TIME) { 106 encoderDemo->NativeRunCaseWithoutCreate(handle, inputFile, outputFile, format, encoderName.c_str(), 107 needConfigure); 108 needConfigure = false; 109 encoderDemo->NativeFlush(handle); 110 curTime = time(nullptr); 111 ASSERT_NE(curTime, -1); 112 } 113 114 OH_AVFormat_Destroy(format); 115 encoderDemo->NativeDestroy(handle); 116 delete encoderDemo; 117 } 118 RunLongTimeReset(string encoderName,string inputFile,string outputFile,int32_t threadId)119 void RunLongTimeReset(string encoderName, string inputFile, string outputFile, int32_t threadId) 120 { 121 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 122 bool needConfigure = true; 123 124 time_t startTime = time(nullptr); 125 ASSERT_NE(startTime, -1); 126 time_t curTime = startTime; 127 128 OH_AVCodec* handle = encoderDemo->NativeCreateByName(encoderName.c_str()); 129 OH_AVFormat* format = GetAVFormatByEncoder(encoderName); 130 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 131 &OnOutputBufferAvailable}; 132 encoderDemo->NativeSetCallback(handle, cb); 133 134 while (difftime(curTime, startTime) < RUN_TIME) { 135 encoderDemo->NativeRunCaseWithoutCreate(handle, inputFile, outputFile, format, encoderName.c_str(), 136 needConfigure); 137 needConfigure = false; 138 encoderDemo->NativeFlush(handle); 139 curTime = time(nullptr); 140 ASSERT_NE(curTime, -1); 141 } 142 143 OH_AVFormat_Destroy(format); 144 encoderDemo->NativeDestroy(handle); 145 delete encoderDemo; 146 } 147 RunLongTimeStop(string encoderName,string inputFile,string outputFile,int32_t threadId)148 void RunLongTimeStop(string encoderName, string inputFile, string outputFile, int32_t threadId) 149 { 150 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 151 bool needConfigure = true; 152 153 time_t startTime = time(nullptr); 154 if (startTime < 0) { 155 return; 156 } 157 time_t curTime = startTime; 158 159 OH_AVCodec* handle = encoderDemo->NativeCreateByName(encoderName.c_str()); 160 OH_AVFormat* format = GetAVFormatByEncoder(encoderName); 161 struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 162 &OnOutputBufferAvailable }; 163 encoderDemo->NativeSetCallback(handle, cb); 164 165 while (difftime(curTime, startTime) < RUN_TIME) { 166 encoderDemo->NativeRunCaseWithoutCreate(handle, inputFile, outputFile, format, encoderName.c_str(), 167 needConfigure); 168 needConfigure = false; 169 encoderDemo->NativeStop(handle); 170 curTime = time(nullptr); 171 ASSERT_NE(curTime, -1); 172 } 173 174 OH_AVFormat_Destroy(format); 175 encoderDemo->NativeDestroy(handle); 176 delete encoderDemo; 177 } 178 } 179 180 181 /** 182 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_001 183 * @tc.name : OH_AudioEncoder_CreateByMime 2000 times 184 * @tc.desc : stability 185 */ 186 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_001, TestSize.Level2) 187 { 188 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 189 double totalTime = 0; 190 struct timeval start, end; 191 for (int i = 0; i < RUN_TIMES; i++) 192 { 193 gettimeofday(&start, NULL); 194 OH_AVCodec* handle = encoderDemo->NativeCreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC); 195 gettimeofday(&end, NULL); 196 totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0; 197 ASSERT_NE(nullptr, handle); 198 encoderDemo->NativeDestroy(handle); 199 } 200 cout << "2000 times finish, run time is " << totalTime << endl; 201 delete encoderDemo; 202 } 203 204 205 /** 206 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_002 207 * @tc.name : OH_AudioEncoder_CreateByName 2000 times 208 * @tc.desc : stability 209 */ 210 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_002, TestSize.Level2) 211 { 212 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 213 double totalTime = 0; 214 struct timeval start, end; 215 for (int i = 0; i < RUN_TIMES; i++) 216 { 217 gettimeofday(&start, NULL); 218 OH_AVCodec* handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 219 gettimeofday(&end, NULL); 220 totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0; 221 ASSERT_NE(nullptr, handle); 222 encoderDemo->NativeDestroy(handle); 223 } 224 cout << "2000 times finish, run time is " << totalTime << endl; 225 delete encoderDemo; 226 } 227 228 229 /** 230 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_003 231 * @tc.name : OH_AudioEncoder_Destroy 2000 times 232 * @tc.desc : stability 233 */ 234 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_003, TestSize.Level2) 235 { 236 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 237 double totalTime = 0; 238 struct timeval start, end; 239 240 for (int i = 0; i < RUN_TIMES; i++) 241 { 242 OH_AVCodec* handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 243 ASSERT_NE(nullptr, handle); 244 gettimeofday(&start, NULL); 245 encoderDemo->NativeDestroy(handle); 246 gettimeofday(&end, NULL); 247 totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0; 248 } 249 cout << "2000 times finish, run time is " << totalTime << endl; 250 delete encoderDemo; 251 } 252 253 254 /** 255 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_004 256 * @tc.name : OH_AudioEncoder_SetCallback 2000 times 257 * @tc.desc : stability 258 */ 259 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_004, TestSize.Level2) 260 { 261 OH_AVErrCode ret; 262 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 263 double totalTime = 0; 264 struct timeval start, end; 265 266 OH_AVCodec* handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 267 ASSERT_NE(nullptr, handle); 268 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 269 &OnOutputBufferAvailable}; 270 for (int i = 0; i < RUN_TIMES; i++) 271 { 272 gettimeofday(&start, NULL); 273 ret = encoderDemo->NativeSetCallback(handle, cb); 274 gettimeofday(&end, NULL); 275 totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0; 276 ASSERT_EQ(AV_ERR_OK, ret); 277 } 278 cout << "2000 times finish, run time is " << totalTime << endl; 279 encoderDemo->NativeDestroy(handle); 280 delete encoderDemo; 281 } 282 283 284 /** 285 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_005 286 * @tc.name : OH_AudioEncoder_Configure 2000 times 287 * @tc.desc : stability 288 */ 289 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_005, TestSize.Level2) 290 { 291 OH_AVErrCode ret; 292 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 293 double totalTime = 0; 294 struct timeval start, end; 295 296 OH_AVFormat* format = OH_AVFormat_Create(); 297 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 298 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 16000); 299 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 300 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 301 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 302 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE); 303 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 304 305 for (int i = 0; i < RUN_TIMES; i++) 306 { 307 OH_AVCodec* handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 308 ASSERT_NE(nullptr, handle); 309 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 310 &OnOutputBufferAvailable}; 311 ret = encoderDemo->NativeSetCallback(handle, cb); 312 ASSERT_EQ(AV_ERR_OK, ret); 313 gettimeofday(&start, NULL); 314 ret = encoderDemo->NativeConfigure(handle, format); 315 gettimeofday(&end, NULL); 316 totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0; 317 ASSERT_EQ(AV_ERR_OK, ret); 318 319 encoderDemo->NativeDestroy(handle); 320 } 321 cout << "2000 times finish, run time is " << totalTime << endl; 322 323 OH_AVFormat_Destroy(format); 324 delete encoderDemo; 325 } 326 327 /** 328 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_006 329 * @tc.name : OH_AudioEncoder_Prepare 2000 times 330 * @tc.desc : stability 331 */ 332 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_006, TestSize.Level2) 333 { 334 OH_AVErrCode ret; 335 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 336 double totalTime = 0; 337 struct timeval start, end; 338 339 OH_AVFormat* format = OH_AVFormat_Create(); 340 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 341 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 16000); 342 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 343 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 344 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 345 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE); 346 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 347 348 for (int i = 0; i < RUN_TIMES; i++) 349 { 350 OH_AVCodec* handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 351 ASSERT_NE(nullptr, handle); 352 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 353 &OnOutputBufferAvailable}; 354 ret = encoderDemo->NativeSetCallback(handle, cb); 355 ASSERT_EQ(AV_ERR_OK, ret); 356 ret = encoderDemo->NativeConfigure(handle, format); 357 ASSERT_EQ(AV_ERR_OK, ret); 358 gettimeofday(&start, NULL); 359 ret = encoderDemo->NativePrepare(handle); 360 gettimeofday(&end, NULL); 361 totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0; 362 ASSERT_EQ(AV_ERR_OK, ret); 363 encoderDemo->NativeDestroy(handle); 364 } 365 cout << "2000 times finish, run time is " << totalTime << endl; 366 367 OH_AVFormat_Destroy(format); 368 delete encoderDemo; 369 } 370 371 372 /** 373 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_007 374 * @tc.name : OH_AudioEncoder_Start 2000 times 375 * @tc.desc : stability 376 */ 377 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_007, TestSize.Level2) 378 { 379 OH_AVErrCode ret; 380 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 381 double totalTime = 0; 382 struct timeval start, end; 383 384 OH_AVFormat* format = OH_AVFormat_Create(); 385 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 386 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 16000); 387 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 388 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 389 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 390 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE); 391 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 392 393 for (int i = 0; i < RUN_TIMES; i++) 394 { 395 OH_AVCodec* handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 396 ASSERT_NE(nullptr, handle); 397 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 398 &OnOutputBufferAvailable}; 399 ret = encoderDemo->NativeSetCallback(handle, cb); 400 ASSERT_EQ(AV_ERR_OK, ret); 401 ret = encoderDemo->NativeConfigure(handle, format); 402 ASSERT_EQ(AV_ERR_OK, ret); 403 ret = encoderDemo->NativePrepare(handle); 404 ASSERT_EQ(AV_ERR_OK, ret); 405 gettimeofday(&start, NULL); 406 ret = OH_AudioEncoder_Start(handle); 407 gettimeofday(&end, NULL); 408 totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0; 409 ASSERT_EQ(AV_ERR_OK, ret); 410 encoderDemo->NativeDestroy(handle); 411 } 412 cout << "2000 times finish, run time is " << totalTime << endl; 413 414 OH_AVFormat_Destroy(format); 415 delete encoderDemo; 416 } 417 418 419 /** 420 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_008 421 * @tc.name : OH_AudioEncoder_Stop 2000 times 422 * @tc.desc : stability 423 */ 424 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_008, TestSize.Level2) 425 { 426 OH_AVErrCode ret; 427 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 428 double totalTime = 0; 429 struct timeval start, end; 430 431 OH_AVFormat* format = OH_AVFormat_Create(); 432 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 433 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 16000); 434 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 435 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 436 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 437 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE); 438 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 439 440 for (int i = 0; i < RUN_TIMES; i++) 441 { 442 OH_AVCodec* handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 443 ASSERT_NE(nullptr, handle); 444 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 445 &OnOutputBufferAvailable}; 446 ret = encoderDemo->NativeSetCallback(handle, cb); 447 ASSERT_EQ(AV_ERR_OK, ret); 448 ret = encoderDemo->NativeConfigure(handle, format); 449 ASSERT_EQ(AV_ERR_OK, ret); 450 ret = encoderDemo->NativePrepare(handle); 451 ASSERT_EQ(AV_ERR_OK, ret); 452 ret = OH_AudioEncoder_Start(handle); 453 ASSERT_EQ(AV_ERR_OK, ret); 454 gettimeofday(&start, NULL); 455 ret = OH_AudioEncoder_Stop(handle); 456 gettimeofday(&end, NULL); 457 totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0; 458 ASSERT_EQ(AV_ERR_OK, ret); 459 encoderDemo->NativeDestroy(handle); 460 } 461 cout << "2000 times finish, run time is " << totalTime << endl; 462 463 OH_AVFormat_Destroy(format); 464 delete encoderDemo; 465 } 466 467 468 /** 469 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_009 470 * @tc.name : OH_AudioEncoder_Flush 2000 times 471 * @tc.desc : stability 472 */ 473 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_009, TestSize.Level2) 474 { 475 OH_AVErrCode ret; 476 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 477 double totalTime = 0; 478 struct timeval start, end; 479 480 OH_AVFormat* format = OH_AVFormat_Create(); 481 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 482 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 16000); 483 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 484 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 485 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 486 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE); 487 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 488 489 for (int i = 0; i < RUN_TIMES; i++) 490 { 491 OH_AVCodec* handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 492 ASSERT_NE(nullptr, handle); 493 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 494 &OnOutputBufferAvailable}; 495 ret = encoderDemo->NativeSetCallback(handle, cb); 496 ASSERT_EQ(AV_ERR_OK, ret); 497 ret = encoderDemo->NativeConfigure(handle, format); 498 ASSERT_EQ(AV_ERR_OK, ret); 499 ret = encoderDemo->NativePrepare(handle); 500 ASSERT_EQ(AV_ERR_OK, ret); 501 ret = OH_AudioEncoder_Start(handle); 502 ASSERT_EQ(AV_ERR_OK, ret); 503 gettimeofday(&start, NULL); 504 ret = encoderDemo->NativeFlush(handle); 505 gettimeofday(&end, NULL); 506 totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0; 507 ASSERT_EQ(AV_ERR_OK, ret); 508 encoderDemo->NativeDestroy(handle); 509 } 510 cout << "2000 times finish, run time is " << totalTime << endl; 511 512 OH_AVFormat_Destroy(format); 513 delete encoderDemo; 514 } 515 516 517 /** 518 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_010 519 * @tc.name : OH_AudioEncoder_Reset 2000 times 520 * @tc.desc : stability 521 */ 522 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_010, TestSize.Level2) 523 { 524 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 525 double totalTime = 0; 526 struct timeval start, end; 527 528 OH_AVCodec* handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 529 ASSERT_NE(nullptr, handle); 530 531 for (int i = 0; i < RUN_TIMES; i++) 532 { 533 gettimeofday(&start, NULL); 534 OH_AudioEncoder_Reset(handle); 535 gettimeofday(&end, NULL); 536 totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0; 537 } 538 cout << "2000 times finish, run time is " << totalTime << endl; 539 delete encoderDemo; 540 } 541 542 543 /** 544 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_011 545 * @tc.name : OH_AudioEncoder_GetOutputDescription 2000 times 546 * @tc.desc : stability 547 */ 548 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_011, TestSize.Level2) 549 { 550 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 551 552 string encoderName = "OH.Media.Codec.Encoder.Audio.AAC"; 553 554 string inputFile = "f32le_44100_2_dayuhaitang.pcm"; 555 string outputFile = "STABILITY_011.aac"; 556 557 OH_AVFormat* format = OH_AVFormat_Create(); 558 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 559 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 560 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 561 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 562 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 563 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE); 564 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 565 ASSERT_NE(nullptr, format); 566 567 encoderDemo->setTimerFlag(TIMER_GETOUTPUTDESCRIPTION); 568 encoderDemo->NativeRunCase(inputFile, outputFile, encoderName.c_str(), format); 569 570 OH_AVFormat_Destroy(format); 571 delete encoderDemo; 572 } 573 574 575 /** 576 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_012 577 * @tc.name : OH_AudioEncoder_SetParameter 2000 times 578 * @tc.desc : stability 579 */ 580 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_012, TestSize.Level2) 581 { 582 OH_AVErrCode ret; 583 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 584 double totalTime = 0; 585 struct timeval start, end; 586 587 OH_AVFormat* format = OH_AVFormat_Create(); 588 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 589 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 590 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 591 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 592 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 593 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE); 594 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 595 596 OH_AVCodec* handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 597 ASSERT_NE(nullptr, handle); 598 599 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 600 &OnOutputBufferAvailable}; 601 ret = encoderDemo->NativeSetCallback(handle, cb); 602 ASSERT_EQ(AV_ERR_OK, ret); 603 ret = encoderDemo->NativeConfigure(handle, format); 604 ASSERT_EQ(AV_ERR_OK, ret); 605 ret = encoderDemo->NativePrepare(handle); 606 ASSERT_EQ(AV_ERR_OK, ret); 607 ret = encoderDemo->NativeStart(handle); 608 ASSERT_EQ(AV_ERR_OK, ret); 609 610 for (int i = 0; i < RUN_TIMES; i++) 611 { 612 gettimeofday(&start, NULL); 613 ret = encoderDemo->NativeSetParameter(handle, format); 614 gettimeofday(&end, NULL); 615 totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0; 616 ASSERT_EQ(AV_ERR_OK, ret); 617 } 618 619 cout << "2000 times finish, run time is " << totalTime << endl; 620 encoderDemo->NativeDestroy(handle); 621 OH_AVFormat_Destroy(format); 622 delete encoderDemo; 623 } 624 625 626 /** 627 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_013 628 * @tc.name : OH_AudioEncoder_PushInputData 2000 times 629 * @tc.desc : stability 630 */ 631 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_013, TestSize.Level2) 632 { 633 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 634 635 string encoderName = "OH.Media.Codec.Encoder.Audio.AAC"; 636 637 string inputFile = "f32le_44100_2_dayuhaitang.pcm"; 638 string outputFile = "STABILITY_013.aac"; 639 640 OH_AVFormat* format = OH_AVFormat_Create(); 641 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 642 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 643 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 644 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 645 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 646 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE); 647 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 648 ASSERT_NE(nullptr, format); 649 650 encoderDemo->setTimerFlag(TIMER_INPUT); 651 encoderDemo->NativeRunCase(inputFile, outputFile, encoderName.c_str(), format); 652 653 OH_AVFormat_Destroy(format); 654 delete encoderDemo; 655 } 656 657 658 /** 659 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_014 660 * @tc.name : OH_AudioEncoder_FreeOutputData 2000 times 661 * @tc.desc : stability 662 */ 663 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_014, TestSize.Level2) 664 { 665 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 666 667 string encoderName = "OH.Media.Codec.Encoder.Audio.AAC"; 668 669 string inputFile = "f32le_44100_2_dayuhaitang.pcm"; 670 string outputFile = "STABILITY_014.aac"; 671 672 OH_AVFormat* format = OH_AVFormat_Create(); 673 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 674 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 675 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 676 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 677 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 678 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE); 679 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 680 ASSERT_NE(nullptr, format); 681 682 encoderDemo->setTimerFlag(TIMER_FREEOUTPUT); 683 encoderDemo->NativeRunCase(inputFile, outputFile, encoderName.c_str(), format); 684 685 OH_AVFormat_Destroy(format); 686 delete encoderDemo; 687 } 688 689 690 /** 691 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_015 692 * @tc.name : OH_AudioEncoder_IsValid 2000 times 693 * @tc.desc : stability 694 */ 695 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_015, TestSize.Level2) 696 { 697 OH_AVErrCode ret; 698 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 699 double totalTime = 0; 700 struct timeval start, end; 701 bool isValid; 702 703 OH_AVFormat* format = OH_AVFormat_Create(); 704 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 705 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 706 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, OH_BitsPerSample::SAMPLE_F32LE); 707 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, OH_BitsPerSample::SAMPLE_F32LE); 708 OH_AVFormat_SetLongValue(format, OH_MD_KEY_CHANNEL_LAYOUT, STEREO); 709 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AAC_IS_ADTS, DEFAULT_AAC_TYPE); 710 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 711 712 OH_AVCodec* handle = encoderDemo->NativeCreateByName("OH.Media.Codec.Encoder.Audio.AAC"); 713 ASSERT_NE(nullptr, handle); 714 715 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 716 &OnOutputBufferAvailable}; 717 ret = encoderDemo->NativeSetCallback(handle, cb); 718 ASSERT_EQ(AV_ERR_OK, ret); 719 ret = encoderDemo->NativeConfigure(handle, format); 720 ASSERT_EQ(AV_ERR_OK, ret); 721 ret = encoderDemo->NativePrepare(handle); 722 ASSERT_EQ(AV_ERR_OK, ret); 723 ret = encoderDemo->NativeStart(handle); 724 ASSERT_EQ(AV_ERR_OK, ret); 725 726 for (int i = 0; i < RUN_TIMES; i++) 727 { 728 gettimeofday(&start, NULL); 729 ret = encoderDemo->NativeIsValid(handle, &isValid); 730 gettimeofday(&end, NULL); 731 totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0; 732 cout << "IsValid ret is " << ret << endl; 733 } 734 735 cout << "2000 times finish, run time is " << totalTime << endl; 736 encoderDemo->NativeDestroy(handle); 737 OH_AVFormat_Destroy(format); 738 delete encoderDemo; 739 } 740 741 742 /** 743 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_016 744 * @tc.name : encoder(long time) 745 * @tc.desc : stability 746 */ 747 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_016, TestSize.Level2) 748 { 749 string encoderList[] = { "OH.Media.Codec.Encoder.Audio.AAC", "OH.Media.Codec.Encoder.Audio.Flac"}; 750 string encoderName; 751 string inputFile; 752 string outputFile; 753 754 time_t startTime = time(nullptr); 755 ASSERT_NE(startTime, -1); 756 time_t curTime = startTime; 757 758 while (difftime(curTime, startTime) < RUN_TIME) 759 { 760 for (int i = 0; i < 2; i++) 761 { 762 encoderName = encoderList[i]; 763 if (encoderName == "OH.Media.Codec.Encoder.Audio.AAC") 764 { 765 inputFile = "f32le_44100_2_dayuhaitang.pcm"; 766 outputFile = "STABILITY_016.aac"; 767 } 768 else 769 { 770 inputFile = "s16_48000_2_dayuhaitang.pcm"; 771 outputFile = "STABILITY_016.flac"; 772 } 773 774 cout << "cur decoder name is " << encoderName << ", input file is " << inputFile << ", output file is " << 775 outputFile << endl; 776 RunEncode(encoderName, inputFile, outputFile, i); 777 } 778 curTime = time(nullptr); 779 ASSERT_NE(curTime, -1); 780 } 781 } 782 783 784 /** 785 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_017 786 * @tc.name : Flush(long time) 787 * @tc.desc : stability 788 */ 789 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_017, TestSize.Level2) 790 { 791 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 792 string encoderName = "OH.Media.Codec.Encoder.Audio.AAC"; 793 string inputFile = "f32le_44100_2_dayuhaitang.pcm"; 794 string outputFile = "STABILITY_017.aac"; 795 bool needConfigure = true; 796 797 time_t startTime = time(nullptr); 798 ASSERT_NE(startTime, -1); 799 time_t curTime = startTime; 800 801 OH_AVCodec* handle = encoderDemo->NativeCreateByName(encoderName.c_str()); 802 OH_AVFormat* format = GetAVFormatByEncoder(encoderName); 803 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 804 &OnOutputBufferAvailable}; 805 encoderDemo->NativeSetCallback(handle, cb); 806 807 while (difftime(curTime, startTime) < RUN_TIME) 808 { 809 encoderDemo->NativeRunCaseWithoutCreate(handle, inputFile, outputFile, format, encoderName.c_str(), 810 needConfigure); 811 needConfigure = false; 812 encoderDemo->NativeFlush(handle); 813 curTime = time(nullptr); 814 ASSERT_NE(curTime, -1); 815 } 816 817 OH_AVFormat_Destroy(format); 818 encoderDemo->NativeDestroy(handle); 819 delete encoderDemo; 820 } 821 822 823 /** 824 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_018 825 * @tc.name : Reset(long time) 826 * @tc.desc : stability 827 */ 828 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_018, TestSize.Level2) 829 { 830 AudioEncoderDemo* encoderDemo = new AudioEncoderDemo(); 831 string encoderName = "OH.Media.Codec.Encoder.Audio.AAC"; 832 string inputFile = "f32le_44100_2_dayuhaitang.pcm"; 833 string outputFile = "STABILITY_018.aac"; 834 bool needConfigure = true; 835 836 time_t startTime = time(nullptr); 837 ASSERT_NE(startTime, -1); 838 time_t curTime = startTime; 839 840 OH_AVCodec* handle = encoderDemo->NativeCreateByName(encoderName.c_str()); 841 OH_AVFormat* format = GetAVFormatByEncoder(encoderName); 842 struct OH_AVCodecAsyncCallback cb = {&OnError, &OnOutputFormatChanged, &OnInputBufferAvailable, 843 &OnOutputBufferAvailable}; 844 encoderDemo->NativeSetCallback(handle, cb); 845 846 while (difftime(curTime, startTime) < RUN_TIME) 847 { 848 encoderDemo->NativeRunCaseWithoutCreate(handle, inputFile, outputFile, format, encoderName.c_str(), 849 needConfigure); 850 encoderDemo->NativeReset(handle); 851 curTime = time(nullptr); 852 ASSERT_NE(curTime, -1); 853 } 854 855 OH_AVFormat_Destroy(format); 856 encoderDemo->NativeDestroy(handle); 857 delete encoderDemo; 858 } 859 860 861 /** 862 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_019 863 * @tc.name : thread decoder(long time) 864 * @tc.desc : stability 865 */ 866 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_019, TestSize.Level2) 867 { 868 string encoderList[] = { "OH.Media.Codec.Encoder.Audio.AAC", "OH.Media.Codec.Encoder.Audio.Flac" }; 869 string encoderName; 870 string inputFile; 871 string outputFile; 872 vector<thread> threadVec; 873 874 time_t startTime = time(nullptr); 875 ASSERT_NE(startTime, -1); 876 time_t curTime = startTime; 877 878 while (difftime(curTime, startTime) < RUN_TIME) 879 { 880 threadVec.clear(); 881 for (int32_t i = 0; i < 16; i++) 882 { 883 encoderName = encoderList[i % 2]; 884 if (encoderName == "OH.Media.Codec.Encoder.Audio.AAC") 885 { 886 inputFile = "f32le_44100_2_dayuhaitang.pcm"; 887 outputFile = "STABILITY_019_" + to_string(i) + ".aac"; 888 } 889 else 890 { 891 inputFile = "s16_48000_2_dayuhaitang.pcm"; 892 outputFile = "STABILITY_019_" + to_string(i) + ".flac"; 893 } 894 cout << "cur decoder name is " << encoderName << ", input file is " << inputFile << ", output file is " << 895 outputFile << endl; 896 threadVec.push_back(thread(RunEncode, encoderName, inputFile, outputFile, i)); 897 } 898 for (uint32_t i = 0; i < threadVec.size(); i++) 899 { 900 threadVec[i].join(); 901 } 902 for (int32_t i = 0; i < 16; i++) 903 { 904 ASSERT_EQ(AV_ERR_OK, g_testResult[i]); 905 } 906 curTime = time(nullptr); 907 ASSERT_NE(curTime, -1); 908 } 909 } 910 911 912 /** 913 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_020 914 * @tc.name : thread encoder Flush(long time) 915 * @tc.desc : stability 916 */ 917 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_020, TestSize.Level2) 918 { 919 string encoderList[] = { "OH.Media.Codec.Encoder.Audio.AAC", "OH.Media.Codec.Encoder.Audio.Flac" }; 920 string encoderName; 921 string inputFile; 922 string outputFile; 923 vector<thread> threadVec; 924 925 for (int32_t i = 0; i < 16; i++) 926 { 927 encoderName = encoderList[i % 2]; 928 if (encoderName == "OH.Media.Codec.Encoder.Audio.AAC") 929 { 930 inputFile = "f32le_44100_2_dayuhaitang.pcm"; 931 outputFile = "STABILITY_019_" + to_string(i) + ".aac"; 932 } 933 else 934 { 935 inputFile = "s16_48000_2_dayuhaitang.pcm"; 936 outputFile = "STABILITY_019_" + to_string(i) + ".flac"; 937 } 938 cout << "cur encoder name is " << encoderName << ", input file is " << inputFile << ", output file is " << 939 outputFile << endl; 940 threadVec.push_back(thread(RunLongTimeFlush, encoderName, inputFile, outputFile, i)); 941 } 942 for (uint32_t i = 0; i < threadVec.size(); i++) 943 { 944 threadVec[i].join(); 945 } 946 for (int32_t i = 0; i < 16; i++) 947 { 948 ASSERT_EQ(AV_ERR_OK, g_testResult[i]); 949 } 950 } 951 952 953 /** 954 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_021 955 * @tc.name : thread encoder Reset(long time) 956 * @tc.desc : stability 957 */ 958 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_021, TestSize.Level2) 959 { 960 string encoderList[] = { "OH.Media.Codec.Encoder.Audio.AAC", "OH.Media.Codec.Encoder.Audio.Flac" }; 961 string encoderName; 962 string inputFile; 963 string outputFile; 964 vector<thread> threadVec; 965 966 for (int32_t i = 0; i < 16; i++) 967 { 968 encoderName = encoderList[i % 2]; 969 if (encoderName == "OH.Media.Codec.Encoder.Audio.AAC") 970 { 971 inputFile = "f32le_44100_2_dayuhaitang.pcm"; 972 outputFile = "STABILITY_019_" + to_string(i) + ".aac"; 973 } 974 else 975 { 976 inputFile = "s16_48000_2_dayuhaitang.pcm"; 977 outputFile = "STABILITY_019_" + to_string(i) + ".flac"; 978 } 979 cout << "cur encoder name is " << encoderName << ", input file is " << inputFile << ", output file is " << 980 outputFile << endl; 981 threadVec.push_back(thread(RunLongTimeReset, encoderName, inputFile, outputFile, i)); 982 } 983 for (uint32_t i = 0; i < threadVec.size(); i++) 984 { 985 threadVec[i].join(); 986 } 987 for (int32_t i = 0; i < 16; i++) 988 { 989 ASSERT_EQ(AV_ERR_OK, g_testResult[i]); 990 } 991 } 992 993 994 /** 995 * @tc.number : SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_022 996 * @tc.name : thread encoder Reset(long time) 997 * @tc.desc : stability 998 */ 999 HWTEST_F(NativeStablityTest, SUB_MULTIMEDIA_AUDIO_ENCODER_STABILITY_022, TestSize.Level2) 1000 { 1001 string encoderList[] = { "OH.Media.Codec.Encoder.Audio.AAC", "OH.Media.Codec.Encoder.Audio.Flac" }; 1002 string encoderName; 1003 string inputFile; 1004 string outputFile; 1005 vector<thread> threadVec; 1006 1007 for (int32_t i = 0; i < 16; i++) 1008 { 1009 encoderName = encoderList[i % 2]; 1010 if (encoderName == "OH.Media.Codec.Encoder.Audio.AAC") 1011 { 1012 inputFile = "f32le_44100_2_dayuhaitang.pcm"; 1013 outputFile = "STABILITY_019_" + to_string(i) + ".aac"; 1014 } 1015 else 1016 { 1017 inputFile = "s16_48000_2_dayuhaitang.pcm"; 1018 outputFile = "STABILITY_019_" + to_string(i) + ".flac"; 1019 } 1020 cout << "cur encoder name is " << encoderName << ", input file is " << inputFile << ", output file is " << 1021 outputFile << endl; 1022 threadVec.push_back(thread(RunLongTimeStop, encoderName, inputFile, outputFile, i)); 1023 } 1024 for (uint32_t i = 0; i < threadVec.size(); i++) 1025 { 1026 threadVec[i].join(); 1027 } 1028 for (int32_t i = 0; i < 16; i++) 1029 { 1030 ASSERT_EQ(AV_ERR_OK, g_testResult[i]); 1031 } 1032 }