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 "AVMuxerDemo.h"
23 #include "fcntl.h"
24 #include "avcodec_info.h"
25 #include "avcodec_errors.h"
26 #include "securec.h"
27
28 using namespace std;
29 using namespace testing::ext;
30 using namespace OHOS;
31 using namespace OHOS::MediaAVCodec;
32 constexpr int32_t SAMPLE_RATE_44100 = 44100;
33 constexpr int32_t CHANNEL_COUNT = 2;
34 constexpr int32_t BUFFER_SIZE = 100;
35 constexpr int32_t SAMPLE_RATE_352 = 352;
36 constexpr int32_t SAMPLE_RATE_288 = 288;
37
38 namespace {
39 class InnerAVMuxerStablityTest : public testing::Test {
40 public:
41 static void SetUpTestCase();
42 static void TearDownTestCase();
43 void SetUp() override;
44 void TearDown() override;
45 };
46
SetUpTestCase()47 void InnerAVMuxerStablityTest::SetUpTestCase() {}
TearDownTestCase()48 void InnerAVMuxerStablityTest::TearDownTestCase() {}
SetUp()49 void InnerAVMuxerStablityTest::SetUp() {}
TearDown()50 void InnerAVMuxerStablityTest::TearDown() {}
51
52 static int g_inputFile = -1;
53 static const int DATA_AUDIO_ID = 0;
54 static const int DATA_VIDEO_ID = 1;
55
56 constexpr int RUN_TIMES = 1000;
57 constexpr int RUN_TIME = 8 * 3600;
58
59 int32_t g_testResult[10] = { -1 };
60
SetRotation(AVMuxerDemo * muxerDemo)61 int32_t SetRotation(AVMuxerDemo *muxerDemo)
62 {
63 int32_t rotation = 0;
64 int32_t ret = muxerDemo->InnerSetRotation(rotation);
65 return ret;
66 }
67
AddTrack(AVMuxerDemo * muxerDemo,int32_t & trackIndex)68 int32_t AddTrack(AVMuxerDemo *muxerDemo, int32_t &trackIndex)
69 {
70 MediaDescription audioParams;
71 int extraSize = 0;
72 unsigned char buffer[100] = {0};
73
74 read(g_inputFile, static_cast<void *>(&extraSize), sizeof(extraSize));
75 if (extraSize <= BUFFER_SiZE && extraSize > 0) {
76 read(g_inputFile, buffer, extraSize);
77 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, buffer, extraSize);
78 }
79 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_AAC);
80 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
81 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
82 int32_t trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams);
83 return trackId;
84 }
85
WriteSample(AVMuxerDemo * muxerDemo)86 int32_t WriteSample(AVMuxerDemo *muxerDemo)
87 {
88 uint8_t data[100];
89
90 AVCodecBufferInfo info;
91 info.presentationTimeUs = 0;
92 info.size = BUFFER_SiZE;
93 uint32_t trackIndex = 0;
94 AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_NONE;
95 info.offset = 0;
96 std::shared_ptr<AVSharedMemoryBase> avMemBuffer =
97 std::make_shared<AVSharedMemoryBase>(info.size, AVSharedMemory::FLAGS_READ_ONLY, "sampleData");
98 avMemBuffer->Init();
99 auto memRet = memcpy_s(avMemBuffer->GetBase(), avMemBuffer->GetSize(), data, info.size);
100 if (memRet != EOK) {
101 printf("WriteSample memcpy_s failed, memRet:%d\n", memRet);
102 return memRet;
103 }
104 int32_t ret = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag);
105
106 return ret;
107 }
108
AddAudioTrack(AVMuxerDemo * muxerDemo,int32_t & trackIndex)109 int32_t AddAudioTrack(AVMuxerDemo *muxerDemo, int32_t &trackIndex)
110 {
111 MediaDescription audioParams;
112 int extraSize = 0;
113 unsigned char buffer[100] = {0};
114
115 read(g_inputFile, static_cast<void*>(&extraSize), sizeof(extraSize));
116 if (extraSize <= BUFFER_SiZE && extraSize > 0) {
117 read(g_inputFile, buffer, extraSize);
118 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, buffer, extraSize);
119 }
120 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_MPEG);
121 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
122 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
123
124 int32_t trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams);
125 return trackId;
126 }
127
AddAudioTrackAAC(AVMuxerDemo * muxerDemo,int32_t & trackIndex)128 int32_t AddAudioTrackAAC(AVMuxerDemo *muxerDemo, int32_t &trackIndex)
129 {
130 MediaDescription audioParams;
131 int extraSize = 0;
132 unsigned char buffer[100] = {0};
133
134 read(g_inputFile, static_cast<void*>(&extraSize), sizeof(extraSize));
135 if (extraSize <= BUFFER_SiZE && extraSize > 0) {
136 read(g_inputFile, buffer, extraSize);
137 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, buffer, extraSize);
138 }
139 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_AAC);
140 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
141 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
142 int32_t trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams);
143 return trackId;
144 }
145
AddVideoTrack(AVMuxerDemo * muxerDemo,int32_t & trackIndex)146 int32_t AddVideoTrack(AVMuxerDemo *muxerDemo, int32_t &trackIndex)
147 {
148 MediaDescription videoParams;
149
150 int extraSize = 0;
151 unsigned char buffer[100] = {0};
152
153 read(g_inputFile, static_cast<void*>(&extraSize), sizeof(extraSize));
154 if (extraSize <= BUFFER_SiZE && extraSize > 0) {
155 read(g_inputFile, buffer, extraSize);
156 videoParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, (uint8_t *)buffer, extraSize);
157 }
158 videoParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_MPEG4);
159 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, SAMPLE_RATE_352);
160 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, SAMPLE_RATE_288);
161
162 int32_t trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams);
163 return trackId;
164 }
165
RemoveHeader()166 void RemoveHeader()
167 {
168 int extraSize = 0;
169 unsigned char buffer[100] = {0};
170 read(g_inputFile, static_cast<void*>(&extraSize), sizeof(extraSize));
171 if (extraSize <= BUFFER_SiZE && extraSize > 0) {
172 read(g_inputFile, buffer, extraSize);
173 }
174 }
175
WriteTrackSample(AVMuxerDemo * muxerDemo,int audioTrackIndex,int videoTrackIndex)176 void WriteTrackSample(AVMuxerDemo *muxerDemo, int audioTrackIndex, int videoTrackIndex)
177 {
178 int dataTrackId = 0;
179 int dataSize = 0;
180 int ret = 0;
181 int trackId = 0;
182 AVCodecBufferInfo info;
183 uint32_t trackIndex;
184 AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_NONE;
185 uint8_t data[1024 * 1024] = {0};
186 while (1) {
187 ret = read(g_inputFile, static_cast<void*>(&dataTrackId), sizeof(dataTrackId));
188 if (ret <= 0) {
189 return;
190 }
191 ret = read(g_inputFile, static_cast<void*>(&info.presentationTimeUs), sizeof(info.presentationTimeUs));
192 if (ret <= 0) {
193 return;
194 }
195 ret = read(g_inputFile, static_cast<void*>(&dataSize), sizeof(dataSize));
196 if (ret <= 0) {
197 return;
198 }
199 ret = read(g_inputFile, static_cast<void*>(data), dataSize);
200 if (ret <= 0) {
201 return;
202 }
203
204 info.size = dataSize;
205 if (dataTrackId == DATA_AUDIO_ID) {
206 trackId = audioTrackIndex;
207 } else if (dataTrackId == DATA_VIDEO_ID) {
208 trackId = videoTrackIndex;
209 } else {
210 cout << "error dataTrackId : " << trackId << endl;
211 }
212 if (trackId >= 0) {
213 trackIndex = trackId;
214 std::shared_ptr<AVSharedMemoryBase> avMemBuffer =
215 std::make_shared<AVSharedMemoryBase>(info.size, AVSharedMemory::FLAGS_READ_ONLY, "sampleData");
216 avMemBuffer->Init();
217 (void)memcpy_s(avMemBuffer->GetBase(), avMemBuffer->GetSize(), data, info.size);
218 int32_t result = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag);
219 if (result != AVCS_ERR_OK) {
220 return;
221 }
222 }
223 }
224 }
225
AddAudioTrackByFd(AVMuxerDemo * muxerDemo,int32_t inputFile,int32_t & trackIndex)226 int32_t AddAudioTrackByFd(AVMuxerDemo *muxerDemo, int32_t inputFile, int32_t &trackIndex)
227 {
228 MediaDescription audioParams;
229
230 int extraSize = 0;
231 unsigned char buffer[100] = {0};
232
233 read(inputFile, static_cast<void*>(&extraSize), sizeof(extraSize));
234 if (extraSize <= BUFFER_SiZE && extraSize > 0) {
235 read(inputFile, buffer, extraSize);
236 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, static_cast<uint8_t*>buffer, extraSize);
237 }
238 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_MPEG);
239 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
240 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
241
242 int32_t trackId = muxerDemo->InnerAddTrack(trackIndex, audioParams);
243 return trackId;
244 }
245
AddAudioTrackAACByFd(AVMuxerDemo * muxerDemo,int32_t inputFile,int32_t & trackIndex)246 int32_t AddAudioTrackAACByFd(AVMuxerDemo *muxerDemo, int32_t inputFile, int32_t &trackIndex)
247 {
248 MediaDescription audioParams;
249
250 int extraSize = 0;
251 unsigned char buffer[100] = {0};
252
253 read(inputFile, static_cast<void*>(&extraSize), sizeof(extraSize));
254 if (extraSize <= BUFFER_SiZE && extraSize > 0) {
255 read(inputFile, buffer, extraSize);
256 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, static_cast<uint8_t*>buffer, extraSize);
257 }
258 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_AAC);
259 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
260 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
261
262 int32_t ret = muxerDemo->InnerAddTrack(trackIndex, audioParams);
263 return ret;
264 }
265
AddVideoTrackByFd(AVMuxerDemo * muxerDemo,int32_t inputFile,int32_t & trackIndex)266 int32_t AddVideoTrackByFd(AVMuxerDemo *muxerDemo, int32_t inputFile, int32_t &trackIndex)
267 {
268 MediaDescription videoParams;
269
270 int extraSize = 0;
271 unsigned char buffer[100] = {0};
272
273 read(inputFile, static_cast<void*>(&extraSize), sizeof(extraSize));
274 if (extraSize <= BUFFER_SiZE && extraSize > 0) {
275 read(inputFile, buffer, extraSize);
276 videoParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, static_cast<uint8_t*>buffer, extraSize);
277 }
278 videoParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_MPEG4);
279 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, SAMPLE_RATE_352);
280 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, SAMPLE_RATE_288);
281
282 int32_t trackId = muxerDemo->InnerAddTrack(trackIndex, videoParams);
283 return trackId;
284 }
285
WriteTrackSampleByFdRead(int * inputFile,AVCodecBufferInfo * info,int * dataSize,int * dataTrackId)286 int WriteTrackSampleByFdRead(int *inputFile, AVCodecBufferInfo *info, int *dataSize, int *dataTrackId)
287 {
288 int ret = read(*inputFile, static_cast<void*>(dataTrackId), sizeof(*dataTrackId));
289 if (ret <= 0) {
290 cout << "read dataTrackId error, ret is: " << ret << endl;
291 return -1;
292 }
293 ret = read(*inputFile, static_cast<void*>(&info->presentationTimeUs), sizeof(info->presentationTimeUs));
294 if (ret <= 0) {
295 cout << "read info.presentationTimeUs error, ret is: " << ret << endl;
296 return -1;
297 }
298 ret = read(*inputFile, static_cast<void*>(dataSize), sizeof(*dataSize));
299 if (ret <= 0) {
300 cout << "read dataSize error, ret is: " << ret << endl;
301 return -1;
302 }
303 return 0;
304 }
305
WriteTrackSampleByFdMem(int * dataSize,unsigned char * avMuxerDemoBuffer,int * avMuxerDemoBufferSize)306 int WriteTrackSampleByFdMem(int *dataSize, unsigned char *avMuxerDemoBuffer, int *avMuxerDemoBufferSize)
307 {
308 if (avMuxerDemoBuffer != nullptr && *dataSize > *avMuxerDemoBufferSize) {
309 free(avMuxerDemoBuffer);
310 *avMuxerDemoBufferSize = 0;
311 avMuxerDemoBuffer = nullptr;
312 }
313 if (avMuxerDemoBuffer == nullptr) {
314 avMuxerDemoBuffer = (unsigned char *)malloc(*dataSize);
315 *avMuxerDemoBufferSize = *dataSize;
316 if (avMuxerDemoBuffer == nullptr) {
317 printf("error malloc memory!\n");
318 return -1;
319 }
320 }
321 return 0;
322 }
323
WriteTrackSampleByFdGetIndex(int32_t * dataSize,int32_t * dataTrackId,AVCodecBufferInfo * info,int32_t * audioTrackIndex,int32_t * videoTrackIndex)324 int WriteTrackSampleByFdGetIndex(int32_t* dataSize, int32_t* dataTrackId, AVCodecBufferInfo *info,
325 int32_t* audioTrackIndex, int32_t* videoTrackIndex)
326 {
327 int trackId = 0;
328 info->size = *dataSize;
329 if (*dataTrackId == DATA_AUDIO_ID) {
330 trackId = *audioTrackIndex;
331 } else if (*dataTrackId == DATA_VIDEO_ID) {
332 trackId = *videoTrackIndex;
333 } else {
334 cout << "error dataTrackId : " << *dataTrackId << endl;
335 }
336
337 return trackId;
338 }
339
WriteTrackSampleByFd(AVMuxerDemo * muxerDemo,int audioTrackIndex,int videoTrackIndex,int32_t inputFile)340 void WriteTrackSampleByFd(AVMuxerDemo *muxerDemo, int audioTrackIndex, int videoTrackIndex, int32_t inputFile)
341 {
342 int dataTrackId = 0;
343 int dataSize = 0;
344 int ret = 0;
345 int trackId = 0;
346 AVCodecBufferInfo info;
347 uint32_t trackIndex;
348 AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_NONE;
349 unsigned char *avMuxerDemoBuffer = nullptr;
350 int avMuxerDemoBufferSize = 0;
351 string resultStr = "";
352 while (1) {
353 ret = WriteTrackSampleByFdRead(&inputFile, &info, &dataSize, &dataTrackId);
354 if (ret != 0) {
355 return;
356 }
357
358 ret = WriteTrackSampleByFdMem(&dataSize, avMuxerDemoBuffer, &avMuxerDemoBufferSize);
359 if (ret != 0) {
360 break;
361 }
362
363 resultStr =
364 "inputFile is: " + to_string(inputFile) + ", avMuxerDemoBufferSize is " + to_string(avMuxerDemoBufferSize);
365 cout << resultStr << endl;
366
367 ret = read(inputFile, static_cast<void*>(avMuxerDemoBuffer), dataSize);
368 if (ret <= 0) {
369 cout << "read data error, ret is: " << ret << endl;
370 continue;
371 }
372
373 trackId = WriteTrackSampleByFdGetIndex(&dataSize, &dataTrackId, &info, &audioTrackIndex, &videoTrackIndex);
374 if (trackId >= 0) {
375 trackIndex = trackId;
376 std::shared_ptr<AVSharedMemoryBase> avMemBuffer =
377 std::make_shared<AVSharedMemoryBase>(info.size, AVSharedMemory::FLAGS_READ_ONLY, "sampleData");
378 (void)memcpy_s(avMemBuffer->GetBase(), avMemBuffer->GetSize(), avMuxerDemoBuffer, info.size);
379 int32_t result = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag);
380 if (result != AVCS_ERR_OK) {
381 cout << "InnerWriteSample error! ret is: " << result << endl;
382 break;
383 }
384 }
385 }
386 if (avMuxerDemoBuffer != nullptr) {
387 free(avMuxerDemoBuffer);
388 }
389 }
390
RunMuxer(string testcaseName,int threadId,OutputFormat format)391 void RunMuxer(string testcaseName, int threadId, OutputFormat format)
392 {
393 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
394 time_t startTime = time(nullptr);
395 ASSERT_NE(startTime, -1);
396 time_t curTime = startTime;
397
398 while (difftime(curTime, startTime) < RUN_TIME) {
399 cout << "thread id is: " << threadId << ", run time : " << difftime(curTime, startTime) << " seconds" << endl;
400 string fileName = testcaseName + "_" + to_string(threadId);
401
402 cout << "thread id is: " << threadId << ", cur file name is: " << fileName << endl;
403 int32_t fd = muxerDemo->InnergetFdByName(format, fileName);
404
405 int32_t inputFile;
406 int32_t audioTrackId;
407 int32_t videoTrackId;
408
409 cout << "thread id is: " << threadId << ", fd is: " << fd << endl;
410 muxerDemo->InnerCreate(fd, format);
411
412 int32_t ret;
413
414 if (format == OUTPUT_FORMAT_MPEG_4) {
415 cout << "thread id is: " << threadId << ", format is: " << format << endl;
416 inputFile = open("avDataMpegMpeg4.bin", O_RDONLY);
417 AddAudioTrackByFd(muxerDemo, inputFile, audioTrackId);
418 AddVideoTrackByFd(muxerDemo, inputFile, videoTrackId);
419 } else {
420 cout << "thread id is: " << threadId << ", format is: " << format << endl;
421 inputFile = open("avData_mpeg4_aac_2.bin", O_RDONLY);
422 AddAudioTrackAACByFd(muxerDemo, inputFile, audioTrackId);
423 videoTrackId = -1;
424 int extraSize = 0;
425 unsigned char buffer[100] = {0};
426 read(inputFile, static_cast<void*>(&extraSize), sizeof(extraSize));
427 if (extraSize <= BUFFER_SiZE && extraSize > 0) {
428 read(inputFile, buffer, extraSize);
429 }
430 }
431
432 cout << "thread id is: " << threadId << ", audio track id is: " << audioTrackId
433 << ", video track id is: " << videoTrackId << endl;
434
435 ret = muxerDemo->InnerStart();
436 cout << "thread id is: " << threadId << ", Start ret is:" << ret << endl;
437
438 WriteTrackSampleByFd(muxerDemo, audioTrackId, videoTrackId, inputFile);
439
440 ret = muxerDemo->InnerStop();
441 cout << "thread id is: " << threadId << ", Stop ret is:" << ret << endl;
442
443 ret = muxerDemo->InnerDestroy();
444 cout << "thread id is: " << threadId << ", Destroy ret is:" << ret << endl;
445
446 close(inputFile);
447 close(fd);
448 curTime = time(nullptr);
449 ASSERT_NE(curTime, -1);
450 }
451 g_testResult[threadId] = AVCS_ERR_OK;
452 delete muxerDemo;
453 }
454 } // namespace
455
456 /**
457 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_001
458 * @tc.name : Create(1000 times)
459 * @tc.desc : Stability test
460 */
461 HWTEST_F(InnerAVMuxerStablityTest, SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_001, TestSize.Level2)
462 {
463 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
464
465 OutputFormat format = OUTPUT_FORMAT_M4A;
466 int32_t fd = muxerDemo->InnergetFdByName(format, "SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_001");
467
468 g_inputFile = open("avData_mpeg4_aac_2.bin", O_RDONLY);
469 struct timeval start, end;
470 double totalTime = 0;
471 for (int i = 0; i < RUN_TIMES; i++) {
472 gettimeofday(&start, nullptr);
473 muxerDemo->InnerCreate(fd, format);
474 gettimeofday(&end, nullptr);
475 totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
476 cout << "run time is: " << i << endl;
477 int32_t ret = muxerDemo->InnerDestroy();
478 ASSERT_EQ(AVCS_ERR_OK, ret);
479 }
480 cout << "1000 times finish, run time is " << totalTime << endl;
481 close(fd);
482 delete muxerDemo;
483 }
484
485 /**
486 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_002
487 * @tc.name : SetRotation(1000 times)
488 * @tc.desc : Stability test
489 */
490 HWTEST_F(InnerAVMuxerStablityTest, SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_002, TestSize.Level2)
491 {
492 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
493
494 OutputFormat format = OUTPUT_FORMAT_M4A;
495 int32_t fd = muxerDemo->InnergetFdByName(format, "SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_002");
496
497 muxerDemo->InnerCreate(fd, format);
498 double totalTime = 0;
499 struct timeval start, end;
500
501 for (int i = 0; i < RUN_TIMES; i++) {
502 gettimeofday(&start, nullptr);
503 int32_t ret = SetRotation(muxerDemo);
504 gettimeofday(&end, nullptr);
505 ASSERT_EQ(AVCS_ERR_OK, ret);
506 totalTime += (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 1000000.0;
507 cout << "run time is: " << i << ", ret is:" << ret << endl;
508 }
509 cout << "1000 times finish, run time is " << totalTime << endl;
510 muxerDemo->InnerDestroy();
511
512 close(fd);
513 delete muxerDemo;
514 }
515
516 /**
517 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_003
518 * @tc.name : AddTrack(1000 times)
519 * @tc.desc : Stability test
520 */
521 HWTEST_F(InnerAVMuxerStablityTest, SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_003, TestSize.Level2)
522 {
523 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
524
525 OutputFormat format = OUTPUT_FORMAT_M4A;
526 int32_t fd = muxerDemo->InnergetFdByName(format, "SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_003");
527
528 muxerDemo->InnerCreate(fd, format);
529
530 double totalTime = 0;
531 struct timeval start, end;
532 for (int i = 0; i < RUN_TIMES; i++) {
533 int32_t trackId = -1;
534 gettimeofday(&start, nullptr);
535 AddTrack(muxerDemo, trackId);
536 gettimeofday(&end, nullptr);
537 ASSERT_EQ(-1, trackId);
538 cout << "run time is: " << i << ", track id is:" << trackId << endl;
539 }
540 cout << "1000 times finish, run time is " << totalTime << endl;
541 muxerDemo->InnerDestroy();
542
543 close(fd);
544 delete muxerDemo;
545 }
546
547 /**
548 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_004
549 * @tc.name : Start(1000 times)
550 * @tc.desc : Stability test
551 */
552 HWTEST_F(InnerAVMuxerStablityTest, SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_004, TestSize.Level2)
553 {
554 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
555
556 OutputFormat format = OUTPUT_FORMAT_M4A;
557 int32_t fd = muxerDemo->InnergetFdByName(format, "SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_004");
558
559 muxerDemo->InnerCreate(fd, format);
560 int32_t audioTrackId;
561 int32_t trackId = AddTrack(muxerDemo, audioTrackId);
562 ASSERT_EQ(0, trackId);
563
564 double totalTime = 0;
565 struct timeval start, end;
566 for (int i = 0; i < RUN_TIMES; i++) {
567 gettimeofday(&start, nullptr);
568 int32_t ret = muxerDemo->InnerStart();
569 gettimeofday(&end, nullptr);
570 ASSERT_EQ(AVCS_ERR_OK, ret);
571 cout << "run time is: " << i << ", ret is:" << ret << endl;
572 }
573 cout << "1000 times finish, run time is " << totalTime << endl;
574 muxerDemo->InnerDestroy();
575
576 close(fd);
577 delete muxerDemo;
578 }
579
580 /**
581 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_005
582 * @tc.name : WriteSample(1000 times)
583 * @tc.desc : Stability test
584 */
585 HWTEST_F(InnerAVMuxerStablityTest, SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_005, TestSize.Level2)
586 {
587 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
588
589 OutputFormat format = OUTPUT_FORMAT_M4A;
590 int32_t fd = muxerDemo->InnergetFdByName(format, "SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_005");
591
592 muxerDemo->InnerCreate(fd, format);
593
594 int32_t audioTrackId;
595 int32_t trackId = AddTrack(muxerDemo, audioTrackId);
596 ASSERT_EQ(0, trackId);
597
598 int32_t ret = muxerDemo->InnerStart();
599 ASSERT_EQ(AVCS_ERR_OK, ret);
600
601 double totalTime = 0;
602 struct timeval start, end;
603 for (int i = 0; i < RUN_TIMES; i++) {
604 gettimeofday(&start, nullptr);
605 ret = WriteSample(muxerDemo);
606 gettimeofday(&end, nullptr);
607 cout << "run time is: " << i << ", ret is:" << ret << endl;
608 }
609 cout << "1000 times finish, run time is " << totalTime << endl;
610 muxerDemo->InnerDestroy();
611
612 close(fd);
613 delete muxerDemo;
614 }
615
616 /**
617 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_006
618 * @tc.name : Stop(1000 times)
619 * @tc.desc : Stability test
620 */
621 HWTEST_F(InnerAVMuxerStablityTest, SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_006, TestSize.Level2)
622 {
623 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
624
625 OutputFormat format = OUTPUT_FORMAT_M4A;
626 int32_t fd = muxerDemo->InnergetFdByName(format, "SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_006");
627
628 muxerDemo->InnerCreate(fd, format);
629
630 int32_t audioTrackId;
631 int32_t trackId = AddTrack(muxerDemo, audioTrackId);
632 ASSERT_EQ(0, trackId);
633
634 int32_t ret = muxerDemo->InnerStart();
635 ASSERT_EQ(AVCS_ERR_OK, ret);
636
637 ret = WriteSample(muxerDemo);
638 ASSERT_EQ(AVCS_ERR_OK, ret);
639
640 double totalTime = 0;
641 struct timeval start, end;
642 for (int i = 0; i < RUN_TIMES; i++) {
643 gettimeofday(&start, nullptr);
644 ret = muxerDemo->InnerStop();
645 gettimeofday(&end, nullptr);
646 cout << "run time is: " << i << ", ret is:" << ret << endl;
647 }
648 cout << "1000 times finish, run time is " << totalTime << endl;
649 muxerDemo->InnerDestroy();
650
651 close(fd);
652 delete muxerDemo;
653 }
654
655 /**
656 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_007
657 * @tc.name : Destroy(1000 times)
658 * @tc.desc : Stability test
659 */
660 HWTEST_F(InnerAVMuxerStablityTest, SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_007, TestSize.Level2)
661 {
662 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
663
664 OutputFormat format = OUTPUT_FORMAT_M4A;
665 int32_t fd = muxerDemo->InnergetFdByName(format, "SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_007");
666
667 double totalTime = 0;
668 struct timeval start, end;
669 for (int i = 0; i < RUN_TIMES; i++) {
670 muxerDemo->InnerCreate(fd, format);
671
672 gettimeofday(&start, nullptr);
673 int32_t ret = muxerDemo->InnerDestroy();
674 gettimeofday(&end, nullptr);
675 ASSERT_EQ(AVCS_ERR_OK, ret);
676 cout << "run time is: " << i << ", ret is:" << ret << endl;
677 }
678 cout << "1000 times finish, run time is " << totalTime << endl;
679 close(fd);
680 delete muxerDemo;
681 }
682
683 /**
684 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_008
685 * @tc.name : m4a(long time)
686 * @tc.desc : Function test
687 */
688 HWTEST_F(InnerAVMuxerStablityTest, SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_008, TestSize.Level2)
689 {
690 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
691 time_t startTime = time(nullptr);
692 ASSERT_NE(startTime, -1);
693 time_t curTime = startTime;
694
695 while (difftime(curTime, startTime) < RUN_TIME) {
696 cout << "run time: " << difftime(curTime, startTime) << " seconds" << endl;
697 OutputFormat format = OUTPUT_FORMAT_M4A;
698 int32_t fd = muxerDemo->InnergetFdByName(format, "SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_008");
699
700 g_inputFile = open("avData_mpeg4_aac_2.bin", O_RDONLY);
701
702 muxerDemo->InnerCreate(fd, format);
703
704 int32_t audioTrackId;
705 AddAudioTrackAAC(muxerDemo, audioTrackId);
706 int32_t videoTrackId = -1;
707 RemoveHeader();
708
709 cout << "audio track id is: " << audioTrackId << ", video track id is: " << videoTrackId << endl;
710
711 int32_t ret;
712
713 ret = muxerDemo->InnerStart();
714 cout << "Start ret is:" << ret << endl;
715
716 WriteTrackSample(muxerDemo, audioTrackId, videoTrackId);
717
718 ret = muxerDemo->InnerStop();
719 cout << "Stop ret is:" << ret << endl;
720
721 ret = muxerDemo->InnerDestroy();
722 cout << "Destroy ret is:" << ret << endl;
723
724 close(g_inputFile);
725 close(fd);
726 curTime = time(nullptr);
727 ASSERT_NE(curTime, -1);
728 }
729 delete muxerDemo;
730 }
731
732 /**
733 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_009
734 * @tc.name : mp4(long time)
735 * @tc.desc : Function test
736 */
737 HWTEST_F(InnerAVMuxerStablityTest, SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_009, TestSize.Level2)
738 {
739 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
740 time_t startTime = time(nullptr);
741 ASSERT_NE(startTime, -1);
742 time_t curTime = startTime;
743
744 while (difftime(curTime, startTime) < RUN_TIME) {
745 cout << "run time: " << difftime(curTime, startTime) << " seconds" << endl;
746
747 OutputFormat format = OUTPUT_FORMAT_MPEG_4;
748 int32_t fd = muxerDemo->InnergetFdByName(format, "SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_009");
749
750 g_inputFile = open("avDataMpegMpeg4.bin", O_RDONLY);
751
752 muxerDemo->InnerCreate(fd, format);
753
754 int32_t audioTrackId;
755 AddAudioTrack(muxerDemo, audioTrackId);
756 int32_t videoTrackId;
757 AddVideoTrack(muxerDemo, videoTrackId);
758
759 cout << "audio track id is: " << audioTrackId << ", video track id is: " << videoTrackId << endl;
760
761 int32_t ret;
762
763 ret = muxerDemo->InnerStart();
764 cout << "Start ret is:" << ret << endl;
765
766 WriteTrackSample(muxerDemo, audioTrackId, videoTrackId);
767
768 ret = muxerDemo->InnerStop();
769 cout << "Stop ret is:" << ret << endl;
770
771 ret = muxerDemo->InnerDestroy();
772 cout << "Destroy ret is:" << ret << endl;
773
774 close(g_inputFile);
775 close(fd);
776 curTime = time(nullptr);
777 ASSERT_NE(curTime, -1);
778 }
779 delete muxerDemo;
780 }
781
782 /**
783 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_010
784 * @tc.name : m4a(thread long time)
785 * @tc.desc : Function test
786 */
787 HWTEST_F(InnerAVMuxerStablityTest, SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_010, TestSize.Level2)
788 {
789 vector<thread> threadVec;
790 OutputFormat format = OUTPUT_FORMAT_M4A;
791 for (int i = 0; i < 10; i++) {
792 threadVec.push_back(thread(RunMuxer, "SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_010", i, format));
793 }
794 for (uint32_t i = 0; i < threadVec.size(); i++) {
795 threadVec[i].join();
796 }
797 for (int32_t i = 0; i < 10; i++)
798 {
799 ASSERT_EQ(AV_ERR_OK, g_testResult[i]);
800 }
801 }
802
803 /**
804 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_011
805 * @tc.name : mp4(thread long time)
806 * @tc.desc : Function test
807 */
808 HWTEST_F(InnerAVMuxerStablityTest, SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_011, TestSize.Level2)
809 {
810 vector<thread> threadVec;
811 OutputFormat format = OUTPUT_FORMAT_MPEG_4;
812 for (int i = 0; i < 10; i++) {
813 threadVec.push_back(thread(RunMuxer, "SUB_MULTIMEDIA_MEDIA_MUXER_STABILITY_011", i, format));
814 }
815 for (uint32_t i = 0; i < threadVec.size(); i++) {
816 threadVec[i].join();
817 }
818 for (int32_t i = 0; i < 10; i++)
819 {
820 ASSERT_EQ(AV_ERR_OK, g_testResult[i]);
821 }
822 }