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 "gtest/gtest.h"
21 #include "AVMuxerDemo.h"
22 #include "fcntl.h"
23 #include "avcodec_info.h"
24 #include "avcodec_errors.h"
25
26 using namespace std;
27 using namespace testing::ext;
28 using namespace OHOS;
29 using namespace OHOS::MediaAVCodec;
30 constexpr uint32_t SAMPLE_RATE_352 = 352;
31 constexpr uint32_t SAMPLE_RATE_288 = 288;
32 constexpr uint32_t CHANNEL_COUNT = 2;
33 constexpr uint32_t SAMPLE_RATE_44100 = 44100;
34 constexpr uint32_t EXTRA_SIZE_NUM = 100;
35
36 namespace {
37 class InnerAVMuxerFunctionTest : 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 InnerAVMuxerFunctionTest::SetUpTestCase() {}
TearDownTestCase()46 void InnerAVMuxerFunctionTest::TearDownTestCase() {}
SetUp()47 void InnerAVMuxerFunctionTest::SetUp() {}
TearDown()48 void InnerAVMuxerFunctionTest::TearDown() {}
49
50 static int g_inputFile = -1;
51 static const int DATA_AUDIO_ID = 0;
52 static const int DATA_VIDEO_ID = 1;
53 int32_t g_testResult[10] = { -1 };
54
addAudioTrack(AVMuxerDemo * muxerDemo,int32_t & trackIndex)55 int32_t addAudioTrack(AVMuxerDemo *muxerDemo, int32_t &trackIndex)
56 {
57 MediaDescription audioParams;
58
59 int extraSize = 0;
60 unsigned char buffer[100] = {0};
61
62 read(g_inputFile, static_cast<void*>(&extraSize), sizeof(extraSize));
63 if (extraSize <= EXTRA_SIZE_NUM && extraSize > 0) {
64 read(g_inputFile, buffer, extraSize);
65 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, static_cast<uint8_t*>buffer, extraSize);
66 }
67 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_MPEG);
68 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
69 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
70
71 int32_t ret = muxerDemo->InnerAddTrack(trackIndex, audioParams);
72
73 return ret;
74 }
75
addAudioTrackAAC(AVMuxerDemo * muxerDemo,int32_t & trackIndex)76 int32_t addAudioTrackAAC(AVMuxerDemo *muxerDemo, int32_t &trackIndex)
77 {
78 MediaDescription audioParams;
79
80 int extraSize = 0;
81 unsigned char buffer[100] = {0};
82
83 read(g_inputFile, static_cast<void*>(&extraSize), sizeof(extraSize));
84 if (extraSize <= EXTRA_SIZE_NUM && extraSize > 0) {
85 read(g_inputFile, buffer, extraSize);
86 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, static_cast<uint8_t*>buffer, extraSize);
87 }
88 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_AAC);
89 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
90 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
91
92 int32_t ret = muxerDemo->InnerAddTrack(trackIndex, audioParams);
93
94 return ret;
95 }
96
addVideoTrack(AVMuxerDemo * muxerDemo,int32_t & trackIndex)97 int32_t addVideoTrack(AVMuxerDemo *muxerDemo, int32_t &trackIndex)
98 {
99 MediaDescription videoParams;
100
101 int extraSize = 0;
102 unsigned char buffer[100] = {0};
103
104 read(g_inputFile, static_cast<void*>(&extraSize), sizeof(extraSize));
105 if (extraSize <= EXTRA_SIZE_NUM && extraSize > 0) {
106 read(g_inputFile, buffer, extraSize);
107 videoParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, static_cast<uint8_t*>buffer, extraSize);
108 }
109 videoParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_MPEG4);
110 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, SAMPLE_RATE_352);
111 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, SAMPLE_RATE_288);
112
113 int32_t ret = muxerDemo->InnerAddTrack(trackIndex, videoParams);
114
115 return ret;
116 }
117
addCoverTrack(AVMuxerDemo * muxerDemo,string coverType,int32_t trackIndex)118 int32_t addCoverTrack(AVMuxerDemo *muxerDemo, string coverType, int32_t trackIndex)
119 {
120 MediaDescription coverFormat;
121
122 if (coverType == "jpg") {
123 coverFormat.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::IMAGE_JPG);
124 } else if (coverType == "png") {
125 coverFormat.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::IMAGE_PNG);
126 } else {
127 coverFormat.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::IMAGE_BMP);
128 }
129 coverFormat.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, SAMPLE_RATE_352);
130 coverFormat.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, SAMPLE_RATE_288);
131
132 int32_t ret = muxerDemo->InnerAddTrack(trackIndex, coverFormat);
133 return ret;
134 }
135
removeHeader()136 void removeHeader()
137 {
138 int extraSize = 0;
139 unsigned char buffer[100] = {0};
140 read(g_inputFile, static_cast<void*>&extraSize, sizeof(extraSize));
141 if (extraSize <= EXTRA_SIZE_NUM && extraSize > 0) {
142 read(g_inputFile, buffer, extraSize);
143 }
144 }
145
WriteTrackSample(AVMuxerDemo * muxerDemo,int audioTrackIndex,int videoTrackIndex)146 void WriteTrackSample(AVMuxerDemo *muxerDemo, int audioTrackIndex, int videoTrackIndex)
147 {
148 int dataTrackId = 0;
149 int dataSize = 0;
150 int ret = 0;
151 int trackId = 0;
152 AVCodecBufferInfo info;
153 uint32_t trackIndex;
154 AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_NONE;
155 uint8_t data[1024 * 1024] = {0};
156 while (1) {
157 ret = read(g_inputFile, static_cast<void*>(&dataTrackId), sizeof(dataTrackId));
158 if (ret <= 0) {
159 return;
160 }
161 ret = read(g_inputFile, static_cast<void*>(&info.presentationTimeUs), sizeof(info.presentationTimeUs));
162 if (ret <= 0) {
163 return;
164 }
165 ret = read(g_inputFile, static_cast<void*>(&dataSize), sizeof(dataSize));
166 if (ret <= 0) {
167 return;
168 }
169 ret = read(g_inputFile, static_cast<void*>data, dataSize);
170 if (ret <= 0) {
171 return;
172 }
173
174 info.size = dataSize;
175 if (dataTrackId == DATA_AUDIO_ID) {
176 trackId = audioTrackIndex;
177 } else if (dataTrackId == DATA_VIDEO_ID) {
178 trackId = videoTrackIndex;
179 } else {
180 cout << "error dataTrackId : " << trackId << endl;
181 }
182 if (trackId >= 0) {
183 trackIndex = trackId;
184 std::shared_ptr<AVSharedMemoryBase> avMemBuffer =
185 std::make_shared<AVSharedMemoryBase>(info.size, AVSharedMemory::FLAGS_READ_ONLY, "sampleData");
186
187 avMemBuffer->Init();
188 (void)memcpy_s(avMemBuffer->GetBase(), avMemBuffer->GetSize(), data, info.size);
189 int32_t result = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag);
190 if (result != AVCS_ERR_OK) {
191 return;
192 }
193 }
194 }
195 }
196
WriteTrackSampleShort(AVMuxerDemo * muxerDemo,int audioTrackIndex,int videoTrackIndex,int audioWriteTime)197 void WriteTrackSampleShort(AVMuxerDemo *muxerDemo, int audioTrackIndex, int videoTrackIndex, int audioWriteTime)
198 {
199 int dataTrackId = 0, dataSize = 0, ret = 0, trackId = 0;
200 int curTime = 0;
201 AVCodecBufferInfo info;
202 uint32_t trackIndex;
203 AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_NONE;
204 uint8_t data[1024 * 1024] = {0};
205 while (1) {
206 ret = read(g_inputFile, static_cast<void*>(&dataTrackId), sizeof(dataTrackId));
207 if (ret <= 0) {
208 return;
209 }
210 ret = read(g_inputFile, static_cast<void*>(&info.presentationTimeUs), sizeof(info.presentationTimeUs));
211 if (ret <= 0) {
212 return;
213 }
214 ret = read(g_inputFile, static_cast<void*>(&dataSize), sizeof(dataSize));
215 if (ret <= 0) {
216 return;
217 }
218 ret = read(g_inputFile, static_cast<void*>data, dataSize);
219 if (ret <= 0) {
220 return;
221 }
222
223 info.size = dataSize;
224 if (dataTrackId == DATA_AUDIO_ID) {
225 trackId = audioTrackIndex;
226 } else if (dataTrackId == DATA_VIDEO_ID) {
227 trackId = videoTrackIndex;
228 } else {
229 printf("error dataTrackId : %d", trackId);
230 }
231 if (trackId >= 0) {
232 if (trackId == audioTrackIndex && curTime > audioWriteTime) {
233 continue;
234 } else if (trackId == audioTrackIndex) {
235 curTime++;
236 }
237 trackIndex = trackId;
238 std::shared_ptr<AVSharedMemoryBase> avMemBuffer =
239 std::make_shared<AVSharedMemoryBase>(info.size, AVSharedMemory::FLAGS_READ_ONLY, "sampleData");
240 avMemBuffer->Init();
241 (void)memcpy_s(avMemBuffer->GetBase(), avMemBuffer->GetSize(), data, info.size);
242 int32_t result = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag);
243 if (result != AVCS_ERR_OK) {
244 return;
245 }
246 }
247 }
248 }
249
addAudioTrackByFd(AVMuxerDemo * muxerDemo,int32_t inputFile,int32_t & trackIndex)250 int32_t addAudioTrackByFd(AVMuxerDemo *muxerDemo, int32_t inputFile, int32_t &trackIndex)
251 {
252 MediaDescription audioParams;
253
254 int extraSize = 0;
255 unsigned char buffer[100] = {0};
256
257 read(inputFile, static_cast<void*>&extraSize, sizeof(extraSize));
258 if (extraSize <= EXTRA_SIZE_NUM && extraSize > 0) {
259 read(inputFile, buffer, extraSize);
260 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, static_cast<uint8_t*>buffer, extraSize);
261 }
262 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_MPEG);
263 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
264 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
265
266 int32_t ret = muxerDemo->InnerAddTrack(trackIndex, audioParams);
267
268 return ret;
269 }
270
addAudioTrackAACByFd(AVMuxerDemo * muxerDemo,int32_t inputFile,int32_t & trackIndex)271 int32_t addAudioTrackAACByFd(AVMuxerDemo *muxerDemo, int32_t inputFile, int32_t &trackIndex)
272 {
273 MediaDescription audioParams;
274
275 int extraSize = 0;
276 unsigned char buffer[100] = {0};
277
278 read(inputFile, static_cast<void*>&extraSize, sizeof(extraSize));
279 if (extraSize <= EXTRA_SIZE_NUM && extraSize > 0) {
280 read(inputFile, buffer, extraSize);
281 audioParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, static_cast<uint8_t*>buffer, extraSize);
282 }
283 audioParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_AAC);
284 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, CHANNEL_COUNT);
285 audioParams.PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, SAMPLE_RATE_44100);
286
287 int32_t ret = muxerDemo->InnerAddTrack(trackIndex, audioParams);
288
289 return ret;
290 }
291
addVideoTrackByFd(AVMuxerDemo * muxerDemo,int32_t inputFile,int32_t & trackIndex)292 int32_t addVideoTrackByFd(AVMuxerDemo *muxerDemo, int32_t inputFile, int32_t &trackIndex)
293 {
294 MediaDescription videoParams;
295
296 int extraSize = 0;
297 unsigned char buffer[100] = {0};
298
299 read(inputFile, static_cast<void*>&extraSize, sizeof(extraSize));
300 if (extraSize <= EXTRA_SIZE_NUM && extraSize > 0) {
301 read(inputFile, buffer, extraSize);
302 videoParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, static_cast<uint8_t*>buffer, extraSize);
303 }
304 videoParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_MPEG4);
305 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, SAMPLE_RATE_352);
306 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, SAMPLE_RATE_288);
307
308 int32_t ret = muxerDemo->InnerAddTrack(trackIndex, videoParams);
309
310 return ret;
311 }
addVideoTrackH264ByFd(AVMuxerDemo * muxerDemo,int32_t inputFile,int32_t & trackIndex)312 int32_t addVideoTrackH264ByFd(AVMuxerDemo *muxerDemo, int32_t inputFile, int32_t &trackIndex)
313 {
314 MediaDescription videoParams;
315
316 int extraSize = 0;
317 unsigned char buffer[100] = {0};
318
319 read(inputFile, static_cast<void*>&extraSize, sizeof(extraSize));
320 if (extraSize <= EXTRA_SIZE_NUM && extraSize > 0) {
321 read(inputFile, buffer, extraSize);
322 videoParams.PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, (uint8_t *)buffer, extraSize);
323 }
324 videoParams.PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_AVC);
325 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, SAMPLE_RATE_352);
326 videoParams.PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, SAMPLE_RATE_288);
327
328 int32_t ret = muxerDemo->InnerAddTrack(trackIndex, videoParams);
329
330 return ret;
331 }
332
WriteTrackSampleByFdRead(int * inputFile,AVCodecBufferInfo * info,int * dataSize,int * dataTrackId)333 int WriteTrackSampleByFdRead(int *inputFile, AVCodecBufferInfo *info, int *dataSize, int *dataTrackId)
334 {
335 int ret = read(*inputFile, static_cast<void*>dataTrackId, sizeof(*dataTrackId));
336 if (ret <= 0) {
337 cout << "read dataTrackId error, ret is: " << ret << endl;
338 return -1;
339 }
340 ret = read(*inputFile, static_cast<void*>(&info->presentationTimeUs), sizeof(info->presentationTimeUs));
341 if (ret <= 0) {
342 cout << "read info.presentationTimeUs error, ret is: " << ret << endl;
343 return -1;
344 }
345 ret = read(*inputFile, static_cast<void*>dataSize, sizeof(*dataSize));
346 if (ret <= 0) {
347 cout << "read dataSize error, ret is: " << ret << endl;
348 return -1;
349 }
350 return 0;
351 }
352
WriteTrackSampleByFdMem(int * dataSize,unsigned char * avMuxerDemoBuffer,int * avMuxerDemoBufferSize)353 int WriteTrackSampleByFdMem(int *dataSize, unsigned char *avMuxerDemoBuffer, int *avMuxerDemoBufferSize)
354 {
355 if (avMuxerDemoBuffer != nullptr && *dataSize > *avMuxerDemoBufferSize) {
356 free(avMuxerDemoBuffer);
357 *avMuxerDemoBufferSize = 0;
358 avMuxerDemoBuffer = nullptr;
359 }
360 if (avMuxerDemoBuffer == nullptr) {
361 avMuxerDemoBuffer = (unsigned char *)malloc(*dataSize);
362 *avMuxerDemoBufferSize = *dataSize;
363 if (avMuxerDemoBuffer == nullptr) {
364 printf("error malloc memory!\n");
365 return -1;
366 }
367 }
368 return 0;
369 }
WriteTrackSampleByFdGetIndex(int * dataSize,int * dataTrackId,AVCodecBufferInfo * info,int * audioTrackIndex,int * videoTrackIndex)370 int WriteTrackSampleByFdGetIndex(int *dataSize, int *dataTrackId, AVCodecBufferInfo *info, int *audioTrackIndex,
371 int *videoTrackIndex)
372 {
373 int trackId = 0;
374 info->size = *dataSize;
375 if (*dataTrackId == DATA_AUDIO_ID) {
376 trackId = *audioTrackIndex;
377 } else if (*dataTrackId == DATA_VIDEO_ID) {
378 trackId = *videoTrackIndex;
379 } else {
380 cout << "error dataTrackId : " << *dataTrackId << endl;
381 }
382
383 return trackId;
384 }
385
WriteTrackSampleByFd(AVMuxerDemo * muxerDemo,int audioTrackIndex,int videoTrackIndex,int32_t inputFile)386 void WriteTrackSampleByFd(AVMuxerDemo *muxerDemo, int audioTrackIndex, int videoTrackIndex, int32_t inputFile)
387 {
388 int dataTrackId = 0;
389 int dataSize = 0;
390 int ret = 0;
391 int trackId = 0;
392 AVCodecBufferInfo info;
393 uint32_t trackIndex;
394 AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_NONE;
395 unsigned char *avMuxerDemoBuffer = nullptr;
396 int avMuxerDemoBufferSize = 0;
397 string resultStr = "";
398 while (1) {
399 ret = WriteTrackSampleByFdRead(&inputFile, &info, &dataSize, &dataTrackId);
400 if (ret != 0) {
401 return;
402 }
403
404 ret = WriteTrackSampleByFdMem(&dataSize, avMuxerDemoBuffer, &avMuxerDemoBufferSize);
405 if (ret != 0) {
406 break;
407 }
408
409 resultStr =
410 "inputFile is: " + to_string(inputFile) + ", avMuxerDemoBufferSize is " + to_string(avMuxerDemoBufferSize);
411 cout << resultStr << endl;
412
413 ret = read(inputFile, static_cast<void*>avMuxerDemoBuffer, dataSize);
414 if (ret <= 0) {
415 cout << "read data error, ret is: " << ret << endl;
416 continue;
417 }
418 trackId = WriteTrackSampleByFdGetIndex(&dataSize, &dataTrackId, &info, &audioTrackIndex, &videoTrackIndex);
419 if (trackId >= 0) {
420 trackIndex = trackId;
421 std::shared_ptr<AVSharedMemoryBase> avMemBuffer =
422 std::make_shared<AVSharedMemoryBase>(info.size, AVSharedMemory::FLAGS_READ_ONLY, "sampleData");
423 avMemBuffer->Init();
424 (void)memcpy_s(avMemBuffer->GetBase(), avMemBuffer->GetSize(), avMuxerDemoBuffer, info.size);
425 int32_t result = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag);
426 if (result != 0) {
427 cout << " WriteSampleBuffer error! ret is: " << result << endl;
428 break;
429 }
430 }
431 }
432 if (avMuxerDemoBuffer != nullptr) {
433 free(avMuxerDemoBuffer);
434 }
435 }
436
RunMuxer(string testcaseName,int threadId,OutputFormat format)437 void RunMuxer(string testcaseName, int threadId, OutputFormat format)
438 {
439 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
440 string fileName = testcaseName + "_" + to_string(threadId);
441
442 cout << "thread id is: " << threadId << ", cur file name is: " << fileName << endl;
443 int32_t fd = muxerDemo->InnergetFdByName(format, fileName);
444
445 int32_t inputFile;
446 int32_t audioTrackId;
447 int32_t videoTrackId;
448
449 cout << "thread id is: " << threadId << ", fd is: " << fd << endl;
450 muxerDemo->InnerCreate(fd, format);
451 int32_t ret;
452
453 if (format == OUTPUT_FORMAT_MPEG_4) {
454 cout << "thread id is: " << threadId << ", format is: " << format << endl;
455 inputFile = open("avDataMpegMpeg4.bin", O_RDONLY);
456 addAudioTrackByFd(muxerDemo, inputFile, audioTrackId);
457 addVideoTrackByFd(muxerDemo, inputFile, videoTrackId);
458 } else {
459 cout << "thread id is: " << threadId << ", format is: " << format << endl;
460 inputFile = open("avData_mpeg4_aac_2.bin", O_RDONLY);
461 addAudioTrackAACByFd(muxerDemo, inputFile, audioTrackId);
462 videoTrackId = -1;
463 int extraSize = 0;
464 unsigned char buffer[100] = {0};
465 read(inputFile, static_cast<void*>&extraSize, sizeof(extraSize));
466 if (extraSize <= EXTRA_SIZE_NUM && extraSize > 0) {
467 read(inputFile, buffer, extraSize);
468 }
469 }
470
471 cout << "thread id is: " << threadId << ", audio track id is: " << audioTrackId
472 << ", video track id is: " << videoTrackId << endl;
473
474 ret = muxerDemo->InnerStart();
475 cout << "thread id is: " << threadId << ", Start ret is:" << ret << endl;
476
477 WriteTrackSampleByFd(muxerDemo, audioTrackId, videoTrackId, inputFile);
478
479 ret = muxerDemo->InnerStop();
480 cout << "thread id is: " << threadId << ", Stop ret is:" << ret << endl;
481
482 ret = muxerDemo->InnerDestroy();
483 cout << "thread id is: " << threadId << ", Destroy ret is:" << ret << endl;
484
485 g_testResult[threadId] = AVCS_ERR_OK;
486 close(inputFile);
487 close(fd);
488 delete muxerDemo;
489 }
490
WriteSingleTrackSampleRead(int * fp,AVCodecBufferInfo * info,int * dataSize,int * flags)491 int WriteSingleTrackSampleRead(int *fp, AVCodecBufferInfo *info, int *dataSize, int *flags)
492 {
493 int ret = read(*fp, static_cast<void*>(&info->presentationTimeUs), sizeof(info->presentationTimeUs));
494 if (ret <= 0) {
495 return -1;
496 }
497
498 ret = read(*fp, static_cast<void*>flags, sizeof(*flags));
499 if (ret <= 0) {
500 return -1;
501 }
502
503 ret = read(*fp, static_cast<void*>dataSize, sizeof(*dataSize));
504 if (ret <= 0 || *dataSize < 0) {
505 return -1;
506 }
507 return 0;
508 }
509
WriteSingleTrackSampleMem(int * dataSize,unsigned char * avMuxerDemoBuffer,int * avMuxerDemoBufferSize)510 int WriteSingleTrackSampleMem(int *dataSize, unsigned char *avMuxerDemoBuffer, int *avMuxerDemoBufferSize)
511 {
512 if (avMuxerDemoBuffer != nullptr && *dataSize > *avMuxerDemoBufferSize) {
513 free(avMuxerDemoBuffer);
514 *avMuxerDemoBufferSize = 0;
515 avMuxerDemoBuffer = nullptr;
516 }
517 if (avMuxerDemoBuffer == nullptr) {
518 avMuxerDemoBuffer = (unsigned char *)malloc(*dataSize);
519 *avMuxerDemoBufferSize = *dataSize;
520 if (avMuxerDemoBuffer == nullptr) {
521 printf("error malloc memory! %d\n", *dataSize);
522 return -1;
523 }
524 }
525 return 0;
526 }
527
WriteSingleTrackSample(AVMuxerDemo * muxerDemo,int trackId,int fd)528 void WriteSingleTrackSample(AVMuxerDemo *muxerDemo, int trackId, int fd)
529 {
530 int ret = 0;
531 int dataSize = 0;
532 int flags = 0;
533 unsigned char *avMuxerDemoBuffer = nullptr;
534 int avMuxerDemoBufferSize = 0;
535 AVCodecBufferInfo info;
536 uint32_t trackIndex;
537 AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_NONE;
538 memset_s(&info, sizeof(info), 0, sizeof(info));
539 while (1) {
540 ret = WriteSingleTrackSampleRead(&fd, &info, &dataSize, &flags);
541 if (ret != 0) {
542 break;
543 }
544 ret = WriteSingleTrackSampleMem(&dataSize, avMuxerDemoBuffer, &avMuxerDemoBufferSize);
545 if (ret != 0) {
546 break;
547 }
548 ret = read(fd, static_cast<void*>avMuxerDemoBuffer, dataSize);
549 if (ret <= 0) {
550 break;
551 }
552 info.size = dataSize;
553
554 if (flag != 0) {
555 flag = AVCODEC_BUFFER_FLAG_SYNC_FRAME;
556 }
557 trackIndex = trackId;
558 std::shared_ptr<AVSharedMemoryBase> avMemBuffer =
559 std::make_shared<AVSharedMemoryBase>(info.size, AVSharedMemory::FLAGS_READ_ONLY, "sampleData");
560 avMemBuffer->Init();
561 auto memRet = memcpy_s(avMemBuffer->GetBase(), avMemBuffer->GetSize(), avMuxerDemoBuffer, info.size);
562 if (memRet != EOK) {
563 printf("WriteSingleTrackSample memcpy_s failed, memRet:%d\n", memRet);
564 break;
565 }
566 int32_t result = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag);
567 if (result != 0) {
568 cout << "WriteSingleTrackSample error! ret is: " << result << endl;
569 break;
570 }
571 }
572
573 if (avMuxerDemoBuffer != nullptr) {
574 free(avMuxerDemoBuffer);
575 }
576 }
577
WriteTrackCover(AVMuxerDemo * muxerDemo,int coverTrackIndex,int fdInput)578 void WriteTrackCover(AVMuxerDemo *muxerDemo, int coverTrackIndex, int fdInput)
579 {
580 printf("WriteTrackCover\n");
581 AVCodecBufferInfo info;
582 uint32_t trackIndex;
583 AVCodecBufferFlag flag = AVCODEC_BUFFER_FLAG_NONE;
584 memset_s(&info, sizeof(info), 0, sizeof(info));
585 struct stat fileStat;
586 fstat(fdInput, &fileStat);
587 info.size = fileStat.st_size;
588 unsigned char *avMuxerDemoBuffer = (unsigned char *)malloc(info.size);
589 if (avMuxerDemoBuffer == nullptr) {
590 printf("malloc memory error! size: %d \n", info.size);
591 return;
592 }
593
594 int ret = read(fdInput, avMuxerDemoBuffer, info.size);
595 if (ret <= 0) {
596 free(avMuxerDemoBuffer);
597 return;
598 }
599 trackIndex = coverTrackIndex;
600 std::shared_ptr<AVSharedMemoryBase> avMemBuffer =
601 std::make_shared<AVSharedMemoryBase>(info.size, AVSharedMemory::FLAGS_READ_ONLY, "sampleData");
602 avMemBuffer->Init();
603 auto memRet = memcpy_s(avMemBuffer->GetBase(), avMemBuffer->GetSize(), avMuxerDemoBuffer, info.size);
604 if (memRet != EOK) {
605 printf("WriteTrackCover memcpy_s failed, memRet:%d\n", memRet);
606 return;
607 }
608 int32_t result = muxerDemo->InnerWriteSample(trackIndex, avMemBuffer, info, flag);
609 if (result != 0) {
610 free(avMuxerDemoBuffer);
611 cout << "WriteTrackCover error! ret is: " << result << endl;
612 return;
613 }
614 free(avMuxerDemoBuffer);
615 }
616 } // namespace
617
618 /**
619 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_001
620 * @tc.name : audio
621 * @tc.desc : Function test
622 */
623 HWTEST_F(InnerAVMuxerFunctionTest, SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_001, TestSize.Level2)
624 {
625 OutputFormat formatList[] = {OUTPUT_FORMAT_M4A, OUTPUT_FORMAT_MPEG_4};
626 for (int i = 0; i < 2; i++) {
627 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
628
629 OutputFormat format = formatList[i];
630 int32_t fd = muxerDemo->InnergetFdByName(format, "FUNCTION_001_INNER_" + to_string(i));
631
632 int32_t audioFileFd = open("aac_44100_2.bin", O_RDONLY);
633
634 muxerDemo->InnerCreate(fd, format);
635
636 int32_t audioTrackId;
637 addAudioTrackAAC(muxerDemo, audioTrackId);
638
639 int32_t videoTrackId = -1;
640 removeHeader();
641
642 cout << "audio track id is: " << audioTrackId << ", video track id is: " << videoTrackId << endl;
643
644 int32_t ret;
645
646 ret = muxerDemo->InnerStart();
647 ASSERT_EQ(AVCS_ERR_OK, ret);
648 audioTrackId = 0;
649
650 if (audioTrackId >= 0) {
651 WriteSingleTrackSample(muxerDemo, audioTrackId, audioFileFd);
652 }
653
654 ret = muxerDemo->InnerStop();
655 ASSERT_EQ(AVCS_ERR_OK, ret);
656
657 ret = muxerDemo->InnerDestroy();
658 ASSERT_EQ(AVCS_ERR_OK, ret);
659
660 close(audioFileFd);
661 close(fd);
662 delete muxerDemo;
663 }
664 }
665
666 /**
667 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_002
668 * @tc.name : video
669 * @tc.desc : Function test
670 */
671 HWTEST_F(InnerAVMuxerFunctionTest, SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_002, TestSize.Level2)
672 {
673 OutputFormat formatList[] = {OUTPUT_FORMAT_M4A, OUTPUT_FORMAT_MPEG_4};
674 for (int i = 0; i < 2; i++) {
675 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
676
677 OutputFormat format = formatList[i];
678 int32_t fd = muxerDemo->InnergetFdByName(format, "FUNCTION_002_INNER_" + to_string(i));
679
680 int32_t videoFileFd = open("h264_640_360.bin", O_RDONLY);
681
682 muxerDemo->InnerCreate(fd, format);
683
684 int32_t audioTrackId = -1;
685 removeHeader();
686 int32_t videoTrackId;
687 addVideoTrack(muxerDemo, videoTrackId);
688
689 cout << "audio track id is: " << audioTrackId << ", video track id is: " << videoTrackId << endl;
690
691 int32_t ret;
692
693 ret = muxerDemo->InnerStart();
694 ASSERT_EQ(AVCS_ERR_OK, ret);
695
696 if (videoTrackId >= 0) {
697 WriteSingleTrackSample(muxerDemo, videoTrackId, videoFileFd);
698 }
699
700 ret = muxerDemo->InnerStop();
701 ASSERT_EQ(AVCS_ERR_OK, ret);
702
703 ret = muxerDemo->InnerDestroy();
704 ASSERT_EQ(AVCS_ERR_OK, ret);
705
706 close(videoFileFd);
707 close(fd);
708 delete muxerDemo;
709 }
710 }
711
712 /**
713 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_003
714 * @tc.name : audio and video
715 * @tc.desc : Function test
716 */
717 HWTEST_F(InnerAVMuxerFunctionTest, SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_003, TestSize.Level2)
718 {
719 OutputFormat formatList[] = {OUTPUT_FORMAT_M4A, OUTPUT_FORMAT_MPEG_4};
720 for (int i = 0; i < 2; i++) {
721 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
722
723 OutputFormat format = formatList[i];
724 int32_t fd = muxerDemo->InnergetFdByName(format, "FUNCTION_003_INNER_" + to_string(i));
725
726 int32_t audioFileFd = open("aac_44100_2.bin", O_RDONLY);
727 int32_t videoFileFd = open("mpeg4_720_480.bin", O_RDONLY);
728
729 muxerDemo->InnerCreate(fd, format);
730
731 int32_t audioTrackId;
732 addAudioTrackAACByFd(muxerDemo, audioFileFd, audioTrackId);
733 int32_t videoTrackId;
734 addVideoTrackByFd(muxerDemo, videoFileFd, videoTrackId);
735
736 cout << "audio track id is: " << audioTrackId << ", video track id is: " << videoTrackId << endl;
737
738 int32_t ret;
739
740 ret = muxerDemo->InnerStart();
741 ASSERT_EQ(AVCS_ERR_OK, ret);
742
743 if (audioTrackId >= 0) {
744 WriteSingleTrackSample(muxerDemo, audioTrackId, audioFileFd);
745 }
746 if (videoTrackId >= 0) {
747 WriteSingleTrackSample(muxerDemo, videoTrackId, videoFileFd);
748 }
749
750 ret = muxerDemo->InnerStop();
751 ASSERT_EQ(AVCS_ERR_OK, ret);
752
753 ret = muxerDemo->InnerDestroy();
754 ASSERT_EQ(AVCS_ERR_OK, ret);
755 close(audioFileFd);
756 close(videoFileFd);
757 close(fd);
758 delete muxerDemo;
759 }
760 }
761
762 /**
763 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_004
764 * @tc.name : mp4(SetRotation)
765 * @tc.desc : Function test
766 */
767 HWTEST_F(InnerAVMuxerFunctionTest, SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_004, TestSize.Level2)
768 {
769 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
770
771 OutputFormat format = OUTPUT_FORMAT_MPEG_4;
772 int32_t fd = muxerDemo->InnergetFdByName(format, "FUNCTION_004_INNER");
773
774 g_inputFile = open("avDataMpegMpeg4.bin", O_RDONLY);
775
776 muxerDemo->InnerCreate(fd, format);
777
778 int32_t audioTrackId;
779 addAudioTrack(muxerDemo, audioTrackId);
780 int32_t videoTrackId;
781 addVideoTrack(muxerDemo, videoTrackId);
782
783 cout << "audio track id is: " << audioTrackId << ", video track id is: " << videoTrackId << endl;
784
785 int32_t ret;
786 ret = muxerDemo->InnerSetRotation(90);
787 ASSERT_EQ(AVCS_ERR_OK, ret);
788
789 ret = muxerDemo->InnerStart();
790 ASSERT_EQ(AVCS_ERR_OK, ret);
791
792 WriteTrackSample(muxerDemo, audioTrackId, videoTrackId);
793
794 ret = muxerDemo->InnerStop();
795 ASSERT_EQ(AVCS_ERR_OK, ret);
796
797 ret = muxerDemo->InnerDestroy();
798 ASSERT_EQ(AVCS_ERR_OK, ret);
799
800 close(g_inputFile);
801 close(fd);
802 delete muxerDemo;
803 }
804
805 /**
806 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_005
807 * @tc.name : mp4(video audio length not equal)
808 * @tc.desc : Function test
809 */
810 HWTEST_F(InnerAVMuxerFunctionTest, SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_005, TestSize.Level2)
811 {
812 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
813
814 OutputFormat format = OUTPUT_FORMAT_MPEG_4;
815 int32_t fd = muxerDemo->InnergetFdByName(format, "FUNCTION_005_INNER");
816
817 g_inputFile = open("avDataMpegMpeg4.bin", O_RDONLY);
818
819 muxerDemo->InnerCreate(fd, format);
820 int32_t ret;
821
822 int32_t audioTrackId;
823 addAudioTrack(muxerDemo, audioTrackId);
824 int32_t videoTrackId;
825 addVideoTrack(muxerDemo, videoTrackId);
826
827 cout << "audio track id is: " << audioTrackId << ", video track id is: " << videoTrackId << endl;
828
829 ret = muxerDemo->InnerStart();
830 ASSERT_EQ(AVCS_ERR_OK, ret);
831
832 WriteTrackSampleShort(muxerDemo, audioTrackId, videoTrackId, 100);
833
834 ret = muxerDemo->InnerStop();
835 ASSERT_EQ(AVCS_ERR_OK, ret);
836
837 ret = muxerDemo->InnerDestroy();
838 ASSERT_EQ(AVCS_ERR_OK, ret);
839
840 close(g_inputFile);
841 close(fd);
842 delete muxerDemo;
843 }
844
845 /**
846 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_006
847 * @tc.name : m4a(thread)
848 * @tc.desc : Function test
849 */
850 HWTEST_F(InnerAVMuxerFunctionTest, SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_006, TestSize.Level2)
851 {
852 vector<thread> threadVec;
853 OutputFormat format = OUTPUT_FORMAT_M4A;
854 for (int i = 0; i < 16; i++) {
855 threadVec.push_back(thread(RunMuxer, "FUNCTION_006_INNER", i, format));
856 }
857 for (uint32_t i = 0; i < threadVec.size(); i++) {
858 threadVec[i].join();
859 }
860 for (int32_t i = 0; i < 10; i++)
861 {
862 ASSERT_EQ(AVCS_ERR_OK, g_testResult[i]);
863 }
864 }
865
866 /**
867 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_007
868 * @tc.name : mp4(thread)
869 * @tc.desc : Function test
870 */
871 HWTEST_F(InnerAVMuxerFunctionTest, SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_007, TestSize.Level2)
872 {
873 vector<thread> threadVec;
874 OutputFormat format = OUTPUT_FORMAT_MPEG_4;
875 for (int i = 0; i < 16; i++) {
876 threadVec.push_back(thread(RunMuxer, "FUNCTION_007_INNER", i, format));
877 }
878 for (uint32_t i = 0; i < threadVec.size(); i++) {
879 threadVec[i].join();
880 }
881 for (int32_t i = 0; i < 10; i++)
882 {
883 ASSERT_EQ(AVCS_ERR_OK, g_testResult[i]);
884 }
885 }
886
887 /**
888 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_008
889 * @tc.name : m4a(multi audio track)
890 * @tc.desc : Function test
891 */
892 HWTEST_F(InnerAVMuxerFunctionTest, SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_008, TestSize.Level2)
893 {
894 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
895
896 OutputFormat format = OUTPUT_FORMAT_M4A;
897 int32_t fd = muxerDemo->InnergetFdByName(format, "FUNCTION_008_INNER");
898
899 int32_t audioFileFd1 = open("aac_44100_2.bin", O_RDONLY);
900 int32_t audioFileFd2 = open("aac_44100_2.bin", O_RDONLY);
901
902 muxerDemo->InnerCreate(fd, format);
903
904 int32_t audioTrackId1;
905 int32_t audioTrackId2;
906 addAudioTrackAACByFd(muxerDemo, audioFileFd1, audioTrackId1);
907 addAudioTrackAACByFd(muxerDemo, audioFileFd2, audioTrackId2);
908 removeHeader();
909
910 cout << "audiotrack id1 is: " << audioTrackId1 << ", audioTrackId2 is: " << audioTrackId2 << endl;
911
912 int32_t ret;
913
914 ret = muxerDemo->InnerStart();
915 ASSERT_EQ(AVCS_ERR_OK, ret);
916
917 if (audioTrackId1 >= 0) {
918 WriteSingleTrackSample(muxerDemo, audioTrackId1, audioFileFd1);
919 }
920 if (audioTrackId2 >= 0) {
921 WriteSingleTrackSample(muxerDemo, audioTrackId2, audioFileFd2);
922 }
923
924 ret = muxerDemo->InnerStop();
925 ASSERT_EQ(AVCS_ERR_OK, ret);
926
927 ret = muxerDemo->InnerDestroy();
928 ASSERT_EQ(AVCS_ERR_OK, ret);
929
930 close(audioFileFd1);
931 close(audioFileFd2);
932 close(fd);
933 delete muxerDemo;
934 }
935
936 /**
937 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_009
938 * @tc.name : mp4(multi video track)
939 * @tc.desc : Function test
940 */
941 HWTEST_F(InnerAVMuxerFunctionTest, SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_009, TestSize.Level2)
942 {
943 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
944
945 OutputFormat format = OUTPUT_FORMAT_MPEG_4;
946 int32_t fd = muxerDemo->InnergetFdByName(format, "FUNCTION_009_INNER");
947
948 int32_t videoFileFd1 = open("h264_640_360.bin", O_RDONLY);
949 int32_t videoFileFd2 = open("h264_640_360.bin", O_RDONLY);
950
951 muxerDemo->InnerCreate(fd, format);
952
953 int32_t videoTrackId1;
954 int32_t videoTrackId2;
955 addVideoTrackH264ByFd(muxerDemo, videoFileFd1, videoTrackId1);
956 addVideoTrackH264ByFd(muxerDemo, videoFileFd2, videoTrackId2);
957
958 int32_t ret;
959
960 ret = muxerDemo->InnerStart();
961 ASSERT_EQ(AVCS_ERR_OK, ret);
962
963 if (videoTrackId1 >= 0) {
964 WriteSingleTrackSample(muxerDemo, videoTrackId1, videoFileFd1);
965 }
966 if (videoTrackId2 >= 0) {
967 WriteSingleTrackSample(muxerDemo, videoTrackId2, videoFileFd2);
968 }
969
970 ret = muxerDemo->InnerStop();
971 ASSERT_EQ(AVCS_ERR_OK, ret);
972
973 ret = muxerDemo->InnerDestroy();
974 ASSERT_EQ(AVCS_ERR_OK, ret);
975
976 close(videoFileFd1);
977 close(videoFileFd2);
978 close(fd);
979 delete muxerDemo;
980 }
981
982 /**
983 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_010
984 * @tc.name : m4a(auido video with cover)
985 * @tc.desc : Function test
986 */
987 HWTEST_F(InnerAVMuxerFunctionTest, SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_010, TestSize.Level2)
988 {
989 string coverTypeList[] = {"bmp", "jpg", "png"};
990 for (int i = 0; i < 3; i++) {
991 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
992 string outputFile = "SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_010_INNER_" + coverTypeList[i];
993 string coverFile = "greatwall." + coverTypeList[i];
994
995 OutputFormat format = OUTPUT_FORMAT_M4A;
996 int32_t fd = muxerDemo->InnergetFdByName(format, outputFile);
997
998 int32_t audioFileFd = open("aac_44100_2.bin", O_RDONLY);
999 int32_t videoFileFd = open("h264_640_360.bin", O_RDONLY);
1000 int32_t coverFileFd = open(coverFile.c_str(), O_RDONLY);
1001
1002 muxerDemo->InnerCreate(fd, format);
1003
1004 int32_t audioTrackId;
1005 int32_t videoTrackId;
1006 int32_t coverTrackId = 1;
1007
1008 addAudioTrackAACByFd(muxerDemo, audioFileFd, audioTrackId);
1009 addVideoTrackH264ByFd(muxerDemo, videoFileFd, videoTrackId);
1010 addCoverTrack(muxerDemo, coverTypeList[i], coverTrackId);
1011
1012 cout << "audio track id is: " << audioTrackId << ", video track id is: " << videoTrackId
1013 << ", cover track id is: " << coverTrackId << endl;
1014
1015 int32_t ret;
1016
1017 ret = muxerDemo->InnerStart();
1018 ASSERT_EQ(AVCS_ERR_OK, ret);
1019
1020 WriteTrackCover(muxerDemo, coverTrackId, coverFileFd);
1021 WriteSingleTrackSample(muxerDemo, audioTrackId, audioFileFd);
1022 WriteSingleTrackSample(muxerDemo, videoTrackId, videoFileFd);
1023
1024 ret = muxerDemo->InnerStop();
1025 ASSERT_EQ(AVCS_ERR_OK, ret);
1026
1027 ret = muxerDemo->InnerDestroy();
1028 ASSERT_EQ(AVCS_ERR_OK, ret);
1029
1030 close(audioFileFd);
1031 close(videoFileFd);
1032 close(coverFileFd);
1033 close(fd);
1034 delete muxerDemo;
1035 }
1036 }
1037
1038 /**
1039 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_011
1040 * @tc.name : mp4(auido video with cover)
1041 * @tc.desc : Function test
1042 */
1043 HWTEST_F(InnerAVMuxerFunctionTest, SUB_MULTIMEDIA_MEDIA_MUXER_FUNCTION_011, TestSize.Level2)
1044 {
1045 string coverTypeList[] = {"bmp", "jpg", "png"};
1046 for (int i = 0; i < 3; i++) {
1047 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
1048 string outputFile = "FUNCTION_011_INNER_" + coverTypeList[i];
1049 string coverFile = "greatwall." + coverTypeList[i];
1050
1051 OutputFormat format = OUTPUT_FORMAT_MPEG_4;
1052 int32_t fd = muxerDemo->InnergetFdByName(format, outputFile);
1053
1054 int32_t audioFileFd = open("aac_44100_2.bin", O_RDONLY);
1055 int32_t videoFileFd = open("mpeg4_720_480.bin", O_RDONLY);
1056 int32_t coverFileFd = open(coverFile.c_str(), O_RDONLY);
1057
1058 muxerDemo->InnerCreate(fd, format);
1059
1060 int32_t audioTrackId;
1061 int32_t videoTrackId;
1062 int32_t coverTrackId = 1;
1063
1064 addAudioTrackAACByFd(muxerDemo, audioFileFd, audioTrackId);
1065 addVideoTrackByFd(muxerDemo, videoFileFd, videoTrackId);
1066 addCoverTrack(muxerDemo, coverTypeList[i], coverTrackId);
1067
1068 cout << "audio track id is: " << audioTrackId << ", video track id is: " << videoTrackId
1069 << ", cover track id is: " << coverTrackId << endl;
1070
1071 int32_t ret;
1072
1073 ret = muxerDemo->InnerStart();
1074 ASSERT_EQ(AVCS_ERR_OK, ret);
1075
1076 WriteTrackCover(muxerDemo, coverTrackId, coverFileFd);
1077 WriteSingleTrackSample(muxerDemo, audioTrackId, audioFileFd);
1078 WriteSingleTrackSample(muxerDemo, videoTrackId, videoFileFd);
1079
1080 ret = muxerDemo->InnerStop();
1081 ASSERT_EQ(AVCS_ERR_OK, ret);
1082
1083 ret = muxerDemo->InnerDestroy();
1084 ASSERT_EQ(AVCS_ERR_OK, ret);
1085
1086 close(audioFileFd);
1087 close(videoFileFd);
1088 close(coverFileFd);
1089 close(fd);
1090 delete muxerDemo;
1091 }
1092 }
1093