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 <iostream> 18 #include <thread> 19 #include <vector> 20 #include <ctime> 21 #include "gtest/gtest.h" 22 #include "AudioDecoderDemoCommon.h" 23 #include "fcntl.h" 24 #include "media_description.h" 25 #include "avcodec_info.h" 26 #include "avcodec_errors.h" 27 #include "av_common.h" 28 #include "format.h" 29 30 using namespace std; 31 using namespace testing::ext; 32 using namespace OHOS; 33 using namespace OHOS::MediaAVCodec; 34 35 36 namespace { 37 class InnerStablityTest : public testing::Test { 38 public: 39 static void SetUpTestCase(); 40 static void TearDownTestCase(); 41 void SetUp() override; 42 void TearDown() override; 43 }; 44 SetUpTestCase()45 void InnerStablityTest::SetUpTestCase() {} TearDownTestCase()46 void InnerStablityTest::TearDownTestCase() {} SetUp()47 void InnerStablityTest::SetUp() {} TearDown()48 void InnerStablityTest::TearDown() {} 49 50 constexpr int RUN_TIMES = 100000; 51 constexpr int RUN_TIME = 12 * 3600; 52 } 53 54 /** 55 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_001 56 * @tc.name : InnerCreateByMime(1000 times) 57 * @tc.desc : Stability test 58 */ 59 HWTEST_F(InnerStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_001, TestSize.Level2) 60 { 61 srand(time(nullptr) * 10); 62 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 63 64 string mimeType[] = { "audio/mp4a-latm", "audio/mpeg", "audio/vorbis", "audio/flac" }; 65 66 for (int i = 0; i < RUN_TIMES; i++) 67 { 68 int typeIndex = rand() % 4; 69 decoderDemo->InnerCreateByMime(mimeType[typeIndex].c_str()); 70 cout << "run time is: " << i << endl; 71 int32_t ret = decoderDemo->InnerDestroy(); 72 ASSERT_EQ(AVCS_ERR_OK, ret); 73 } 74 75 delete decoderDemo; 76 } 77 78 79 /** 80 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_002 81 * @tc.name : InnerCreateByName(1000 times) 82 * @tc.desc : Stability test 83 */ 84 HWTEST_F(InnerStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_002, TestSize.Level2) 85 { 86 srand(time(nullptr) * 10); 87 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 88 89 for (int i = 0; i < RUN_TIMES; i++) 90 { 91 decoderDemo->InnerCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 92 cout << "run time is: " << i << endl; 93 int32_t ret = decoderDemo->InnerDestroy(); 94 ASSERT_EQ(AVCS_ERR_OK, ret); 95 } 96 delete decoderDemo; 97 } 98 99 100 /** 101 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_003 102 * @tc.name : InnerPrepare(1000 times) 103 * @tc.desc : Stability test 104 */ 105 HWTEST_F(InnerStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_003, TestSize.Level2) 106 { 107 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 108 int32_t ret = decoderDemo->InnerCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 109 ASSERT_EQ(AVCS_ERR_OK, ret); 110 std::shared_ptr<ADecSignal> signal_ = decoderDemo->getSignal(); 111 std::shared_ptr<InnerADecDemoCallback> cb_ = make_unique<InnerADecDemoCallback>(signal_); 112 decoderDemo->InnerSetCallback(cb_); 113 114 Format format; 115 116 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 320000); 117 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 118 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 119 120 decoderDemo->InnerConfigure(format); 121 122 for (int i = 0; i < RUN_TIMES; i++) 123 { 124 ret = decoderDemo->InnerPrepare(); 125 cout << "run time is: " << i << ", ret is:" << ret << endl; 126 } 127 128 decoderDemo->InnerDestroy(); 129 130 delete decoderDemo; 131 } 132 133 134 /** 135 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_004 136 * @tc.name : InnerStart(1000 times) 137 * @tc.desc : Stability test 138 */ 139 HWTEST_F(InnerStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_004, TestSize.Level2) 140 { 141 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 142 int32_t ret = decoderDemo->InnerCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 143 ASSERT_EQ(AVCS_ERR_OK, ret); 144 std::shared_ptr<ADecSignal> signal_ = decoderDemo->getSignal(); 145 std::shared_ptr<InnerADecDemoCallback> cb_ = make_unique<InnerADecDemoCallback>(signal_); 146 decoderDemo->InnerSetCallback(cb_); 147 Format format; 148 149 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 320000); 150 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 151 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 152 153 decoderDemo->InnerConfigure(format); 154 decoderDemo->InnerPrepare(); 155 156 for (int i = 0; i < RUN_TIMES; i++) 157 { 158 ret = decoderDemo->InnerStart(); 159 cout << "run time is: " << i << ", ret is:" << ret << endl; 160 } 161 162 decoderDemo->InnerDestroy(); 163 164 delete decoderDemo; 165 } 166 167 168 /** 169 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_005 170 * @tc.name : InnerStop(1000 times) 171 * @tc.desc : Stability test 172 */ 173 HWTEST_F(InnerStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_005, TestSize.Level2) 174 { 175 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 176 int32_t ret = decoderDemo->InnerCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 177 ASSERT_EQ(AVCS_ERR_OK, ret); 178 std::shared_ptr<ADecSignal> signal_ = decoderDemo->getSignal(); 179 std::shared_ptr<InnerADecDemoCallback> cb_ = make_unique<InnerADecDemoCallback>(signal_); 180 decoderDemo->InnerSetCallback(cb_); 181 Format format; 182 183 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 320000); 184 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 185 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 186 187 decoderDemo->InnerConfigure(format); 188 decoderDemo->InnerPrepare(); 189 decoderDemo->InnerStart(); 190 191 for (int i = 0; i < RUN_TIMES; i++) 192 { 193 ret = decoderDemo->InnerStop(); 194 cout << "run time is: " << i << ", ret is:" << ret << endl; 195 } 196 197 decoderDemo->InnerDestroy(); 198 199 delete decoderDemo; 200 } 201 202 /** 203 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_006 204 * @tc.name : InnerDestroy(1000 times) 205 * @tc.desc : Stability test 206 */ 207 HWTEST_F(InnerStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_006, TestSize.Level2) 208 { 209 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 210 int32_t ret = decoderDemo->InnerCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 211 ASSERT_EQ(AVCS_ERR_OK, ret); 212 std::shared_ptr<ADecSignal> signal_ = decoderDemo->getSignal(); 213 std::shared_ptr<InnerADecDemoCallback> cb_ = make_unique<InnerADecDemoCallback>(signal_); 214 decoderDemo->InnerSetCallback(cb_); 215 Format format; 216 217 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 320000); 218 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 219 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 220 221 decoderDemo->InnerConfigure(format); 222 decoderDemo->InnerPrepare(); 223 decoderDemo->InnerStart(); 224 decoderDemo->InnerStop(); 225 226 for (int i = 0; i < RUN_TIMES; i++) 227 { 228 ret = decoderDemo->InnerDestroy(); 229 cout << "run time is: " << i << ", ret is:" << ret << endl; 230 } 231 delete decoderDemo; 232 } 233 234 235 /** 236 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_007 237 * @tc.name : InnerReset(1000 times) 238 * @tc.desc : Stability test 239 */ 240 HWTEST_F(InnerStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_007, TestSize.Level2) 241 { 242 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 243 int32_t ret = decoderDemo->InnerCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 244 ASSERT_EQ(AVCS_ERR_OK, ret); 245 std::shared_ptr<ADecSignal> signal_ = decoderDemo->getSignal(); 246 std::shared_ptr<InnerADecDemoCallback> cb_ = make_unique<InnerADecDemoCallback>(signal_); 247 decoderDemo->InnerSetCallback(cb_); 248 Format format; 249 250 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 320000); 251 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 252 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 253 254 decoderDemo->InnerConfigure(format); 255 decoderDemo->InnerPrepare(); 256 decoderDemo->InnerStart(); 257 258 for (int i = 0; i < RUN_TIMES; i++) 259 { 260 ret = decoderDemo->InnerReset(); 261 cout << "run time is: " << i << ", ret is:" << ret << endl; 262 } 263 decoderDemo->InnerDestroy(); 264 delete decoderDemo; 265 } 266 267 268 /** 269 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_008 270 * @tc.name : InnerFlush(1000 times) 271 * @tc.desc : Stability test 272 */ 273 HWTEST_F(InnerStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_008, TestSize.Level2) 274 { 275 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 276 int32_t ret = decoderDemo->InnerCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 277 ASSERT_EQ(AVCS_ERR_OK, ret); 278 std::shared_ptr<ADecSignal> signal_ = decoderDemo->getSignal(); 279 std::shared_ptr<InnerADecDemoCallback> cb_ = make_unique<InnerADecDemoCallback>(signal_); 280 decoderDemo->InnerSetCallback(cb_); 281 Format format; 282 283 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 320000); 284 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 285 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 286 287 decoderDemo->InnerConfigure(format); 288 decoderDemo->InnerPrepare(); 289 decoderDemo->InnerStart(); 290 291 for (int i = 0; i < RUN_TIMES; i++) 292 { 293 ret = decoderDemo->InnerFlush(); 294 cout << "run time is: " << i << ", ret is:" << ret << endl; 295 } 296 decoderDemo->InnerDestroy(); 297 delete decoderDemo; 298 } 299 300 301 /** 302 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_009 303 * @tc.name : InnerRelease(1000 times) 304 * @tc.desc : Stability test 305 */ 306 HWTEST_F(InnerStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_009, TestSize.Level2) 307 { 308 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 309 int32_t ret = decoderDemo->InnerCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 310 ASSERT_EQ(AVCS_ERR_OK, ret); 311 std::shared_ptr<ADecSignal> signal_ = decoderDemo->getSignal(); 312 std::shared_ptr<InnerADecDemoCallback> cb_ = make_unique<InnerADecDemoCallback>(signal_); 313 decoderDemo->InnerSetCallback(cb_); 314 Format format; 315 316 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 320000); 317 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 318 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 48000); 319 320 decoderDemo->InnerConfigure(format); 321 decoderDemo->InnerPrepare(); 322 decoderDemo->InnerStart(); 323 324 for (int i = 0; i < RUN_TIMES; i++) 325 { 326 ret = decoderDemo->InnerRelease(); 327 cout << "run time is: " << i << ", ret is:" << ret << endl; 328 } 329 decoderDemo->InnerDestroy(); 330 delete decoderDemo; 331 } 332 333 334 /** 335 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_010 336 * @tc.name : MP3(long time) 337 * @tc.desc : Stability test 338 */ 339 HWTEST_F(InnerStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_010, TestSize.Level2) 340 { 341 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 342 time_t startTime = time(nullptr); 343 ASSERT_NE(startTime, -1); 344 time_t curTime = startTime; 345 346 while (difftime(curTime, startTime) < RUN_TIME) 347 { 348 cout << "run time: " << difftime(curTime, startTime) << " seconds" << endl; 349 std::string inputFilePath = "s16p_128k_16000_1_dayuhaitang.mp3"; 350 std::string outputFilePath = "SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_010.pcm"; 351 352 Format format; 353 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 128000); 354 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 1); 355 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 16000); 356 357 decoderDemo->InnerRunCase(inputFilePath, outputFilePath, "OH.Media.Codec.Decoder.Audio.Mpeg", format); 358 curTime = time(nullptr); 359 ASSERT_NE(curTime, -1); 360 } 361 delete decoderDemo; 362 } 363 364 365 /** 366 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_011 367 * @tc.name : aac(long time) 368 * @tc.desc : Stability test 369 */ 370 HWTEST_F(InnerStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_011, TestSize.Level2) 371 { 372 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 373 time_t startTime = time(nullptr); 374 ASSERT_NE(startTime, -1); 375 time_t curTime = startTime; 376 377 while (difftime(curTime, startTime) < RUN_TIME) 378 { 379 cout << "run time: " << difftime(curTime, startTime) << " seconds" << endl; 380 std::string inputFilePath = "fltp_aac_low_128k_16000_2_dayuhaitang.aac"; 381 std::string outputFilePath = "SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_011.pcm"; 382 383 Format format; 384 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2); 385 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 16000); 386 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 128000); 387 format.PutIntValue(MediaDescriptionKey::MD_KEY_AAC_IS_ADTS, 1); 388 389 decoderDemo->InnerRunCase(inputFilePath, outputFilePath, "avdec_aac", format); 390 curTime = time(nullptr); 391 ASSERT_NE(curTime, -1); 392 } 393 delete decoderDemo; 394 } 395 396 397 /** 398 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_012 399 * @tc.name : avdec_vorbis(long time) 400 * @tc.desc : Stability test 401 */ 402 HWTEST_F(InnerStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_012, TestSize.Level2) 403 { 404 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 405 time_t startTime = time(nullptr); 406 ASSERT_NE(startTime, -1); 407 time_t curTime = startTime; 408 409 while (difftime(curTime, startTime) < RUN_TIME) 410 { 411 cout << "run time: " << difftime(curTime, startTime) << " seconds" << endl; 412 std::string inputFilePath = "fltp_128k_16000_2_dayuhaitang.ogg"; 413 std::string outputFilePath = "SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_012.pcm"; 414 415 Format format; 416 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 128000); 417 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2); 418 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 16000); 419 420 decoderDemo->InnerRunCase(inputFilePath, outputFilePath, "avdec_vorbis", format); 421 curTime = time(nullptr); 422 ASSERT_NE(curTime, -1); 423 } 424 delete decoderDemo; 425 } 426 427 428 /** 429 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_013 430 * @tc.name : avdec_flac(long time) 431 * @tc.desc : Stability test 432 */ 433 HWTEST_F(InnerStablityTest, SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_013, TestSize.Level2) 434 { 435 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 436 time_t startTime = time(nullptr); 437 ASSERT_NE(startTime, -1); 438 time_t curTime = startTime; 439 440 while (difftime(curTime, startTime) < RUN_TIME) 441 { 442 cout << "run time: " << difftime(curTime, startTime) << " seconds" << endl; 443 std::string inputFilePath = "s32_16000_2_dayuhaitang.flac"; 444 std::string outputFilePath = "SUB_MULTIMEDIA_AUDIO_DECODER_STABILITY_013.pcm"; 445 446 Format format; 447 format.PutLongValue(MediaDescriptionKey::MD_KEY_BITRATE, 357000); 448 format.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, 2); 449 format.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, 16000); 450 format.PutIntValue("bits_per_coded_sample", 24); 451 452 decoderDemo->InnerRunCase(inputFilePath, outputFilePath, "avdec_flac", format); 453 curTime = time(nullptr); 454 ASSERT_NE(curTime, -1); 455 } 456 delete decoderDemo; 457 }