1 /*
2  * Copyright (C) 2023 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 "avmuxer_unit_test.h"
17 #include <gtest/gtest.h>
18 #include <string>
19 #include <vector>
20 #include <fcntl.h>
21 #include "avmuxer.h"
22 #include "native_avbuffer.h"
23 #include "native_audio_channel_layout.h"
24 #ifdef AVMUXER_UNITTEST_CAPI
25 #include "native_avmuxer.h"
26 #include "native_avformat.h"
27 #endif
28 
29 using namespace testing::ext;
30 using namespace OHOS::MediaAVCodec;
31 using namespace OHOS::Media;
32 namespace {
33 constexpr int32_t TEST_CHANNEL_COUNT = 2;
34 constexpr int32_t TEST_SAMPLE_RATE = 2;
35 constexpr int32_t TEST_WIDTH = 720;
36 constexpr int32_t TEST_HEIGHT = 480;
37 constexpr int32_t TEST_ROTATION = 90;
38 constexpr int32_t INVALID_FORMAT = -99;
39 const std::string TEST_FILE_PATH = "/data/test/media/";
40 const std::string INPUT_FILE_PATH = "/data/test/media/h264_720_480.dat";
41 const std::string HEVC_LIB_PATH = std::string(AV_CODEC_PATH) + "/libav_codec_hevc_parser.z.so";
42 constexpr uint32_t AVCODEC_BUFFER_FLAGS_DISPOSABLE_EXT_TEST = 1 << 6;
43 const std::string TIMED_METADATA_TRACK_MIMETYPE = "meta/timed-metadata";
44 const std::string TIMED_METADATA_KEY = "com.openharmony.timed_metadata.test";
45 } // namespace
46 
SetUpTestCase()47 void AVMuxerUnitTest::SetUpTestCase() {}
48 
TearDownTestCase()49 void AVMuxerUnitTest::TearDownTestCase() {}
50 
SetUp()51 void AVMuxerUnitTest::SetUp()
52 {
53     avmuxer_ = std::make_shared<AVMuxerSample>();
54 }
55 
TearDown()56 void AVMuxerUnitTest::TearDown()
57 {
58     if (fd_ >= 0) {
59         close(fd_);
60         fd_ = -1;
61     }
62 
63     if (inputFile_ != nullptr) {
64         if (inputFile_->is_open()) {
65             inputFile_->close();
66         }
67     }
68 
69     if (avmuxer_ != nullptr) {
70         avmuxer_->Destroy();
71         avmuxer_ = nullptr;
72     }
73 }
74 
WriteSample(int32_t trackId,std::shared_ptr<std::ifstream> file,bool & eosFlag,uint32_t flag)75 int32_t AVMuxerUnitTest::WriteSample(int32_t trackId, std::shared_ptr<std::ifstream> file,
76                                      bool &eosFlag, uint32_t flag)
77 {
78     OH_AVCodecBufferAttr info;
79 
80     if (file->eof()) {
81         eosFlag = true;
82         return 0;
83     }
84     file->read(reinterpret_cast<char*>(&info.pts), sizeof(info.pts));
85 
86     if (file->eof()) {
87         eosFlag = true;
88         return 0;
89     }
90     file->read(reinterpret_cast<char*>(&info.flags), sizeof(info.flags));
91 
92     if (file->eof()) {
93         eosFlag = true;
94         return 0;
95     }
96     file->read(reinterpret_cast<char*>(&info.size), sizeof(info.size));
97 
98     if (file->eof()) {
99         eosFlag = true;
100         return 0;
101     }
102 
103     if (info.flags & AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
104         info.flags |= flag;
105     }
106 
107     OH_AVBuffer *buffer = OH_AVBuffer_Create(info.size);
108     file->read(reinterpret_cast<char*>(OH_AVBuffer_GetAddr(buffer)), info.size);
109     OH_AVBuffer_SetBufferAttr(buffer, &info);
110     int32_t ret = avmuxer_->WriteSampleBuffer(trackId, buffer);
111     OH_AVBuffer_Destroy(buffer);
112     return ret;
113 }
114 
WriteSample(sptr<AVBufferQueueProducer> bqProducer,std::shared_ptr<std::ifstream> file,bool & eosFlag)115 int32_t AVMuxerUnitTest::WriteSample(sptr<AVBufferQueueProducer> bqProducer,
116     std::shared_ptr<std::ifstream> file, bool &eosFlag)
117 {
118     if (file->eof()) {
119         eosFlag = true;
120         return 0;
121     }
122     int64_t pts = 0;
123     file->read(reinterpret_cast<char*>(&pts), sizeof(pts));
124     if (file->eof()) {
125         eosFlag = true;
126         return 0;
127     }
128     uint32_t flags = 0;
129     file->read(reinterpret_cast<char*>(&flags), sizeof(flags));
130     if (file->eof()) {
131         eosFlag = true;
132         return 0;
133     }
134     int32_t size = 0;
135     file->read(reinterpret_cast<char*>(&size), sizeof(size));
136     if (file->eof()) {
137         eosFlag = true;
138         return 0;
139     }
140     std::shared_ptr<AVBuffer> buffer = nullptr;
141     AVBufferConfig avBufferConfig;
142     avBufferConfig.size = size;
143     avBufferConfig.memoryType = MemoryType::VIRTUAL_MEMORY;
144     bqProducer->RequestBuffer(buffer, avBufferConfig, -1);
145     buffer->pts_ = pts;
146     buffer->flag_ = flags;
147     file->read(reinterpret_cast<char*>(buffer->memory_->GetAddr()), size);
148     buffer->memory_->SetSize(size);
149     Status ret = bqProducer->PushBuffer(buffer, true);
150     if (ret == Status::OK) {
151         return 0;
152     }
153     return -1;
154 }
155 
156 namespace {
157 /**
158  * @tc.name: Muxer_Create_001
159  * @tc.desc: Muxer Create
160  * @tc.type: FUNC
161  */
162 HWTEST_F(AVMuxerUnitTest, Muxer_Create_001, TestSize.Level0)
163 {
164     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Create.mp4");
165     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
166     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
167     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
168     ASSERT_TRUE(isCreated);
169 }
170 
171 /**
172  * @tc.name: Muxer_Create_002
173  * @tc.desc: Muxer Create write only
174  * @tc.type: FUNC
175  */
176 HWTEST_F(AVMuxerUnitTest, Muxer_Create_002, TestSize.Level0)
177 {
178     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Create.mp4");
179     fd_ = open(outputFile.c_str(), O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
180     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
181     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
182     ASSERT_TRUE(isCreated);
183 }
184 
185 /**
186  * @tc.name: Muxer_Create_003
187  * @tc.desc: Muxer Create read only
188  * @tc.type: FUNC
189  */
190 HWTEST_F(AVMuxerUnitTest, Muxer_Create_003, TestSize.Level0)
191 {
192     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Create.mp4");
193     fd_ = open(outputFile.c_str(), O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR);
194     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
195     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
196     ASSERT_FALSE(isCreated);
197 }
198 
199 /**
200  * @tc.name: Muxer_Create_004
201  * @tc.desc: Muxer Create rand fd
202  * @tc.type: FUNC
203  */
204 HWTEST_F(AVMuxerUnitTest, Muxer_Create_004, TestSize.Level0)
205 {
206     constexpr int32_t invalidFd = 999999;
207     constexpr int32_t negativeFd = -999;
208     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
209     bool isCreated = avmuxer_->CreateMuxer(invalidFd, outputFormat);
210     ASSERT_FALSE(isCreated);
211 
212     avmuxer_->Destroy();
213     isCreated = avmuxer_->CreateMuxer(0xfffffff, outputFormat);
214     ASSERT_FALSE(isCreated);
215 
216     avmuxer_->Destroy();
217     isCreated = avmuxer_->CreateMuxer(-1, outputFormat);
218     ASSERT_FALSE(isCreated);
219 
220     avmuxer_->Destroy();
221     isCreated = avmuxer_->CreateMuxer(negativeFd, outputFormat);
222     ASSERT_FALSE(isCreated);
223 }
224 
225 /**
226  * @tc.name: Muxer_Create_005
227  * @tc.desc: Muxer Create different outputFormat
228  * @tc.type: FUNC
229  */
230 HWTEST_F(AVMuxerUnitTest, Muxer_Create_005, TestSize.Level0)
231 {
232     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Create.mp4");
233     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
234 
235     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
236     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
237     ASSERT_TRUE(isCreated);
238 
239     avmuxer_->Destroy();
240     outputFormat = AV_OUTPUT_FORMAT_M4A;
241     isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
242     ASSERT_TRUE(isCreated);
243 
244     avmuxer_->Destroy();
245     outputFormat = AV_OUTPUT_FORMAT_AMR;
246     isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
247     ASSERT_TRUE(isCreated);
248 
249     avmuxer_->Destroy();
250     outputFormat = AV_OUTPUT_FORMAT_DEFAULT;
251     isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
252     ASSERT_TRUE(isCreated);
253 
254     avmuxer_->Destroy();
255     outputFormat = AV_OUTPUT_FORMAT_MP3;
256     isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
257     ASSERT_TRUE(isCreated);
258 
259     avmuxer_->Destroy();
260     isCreated = avmuxer_->CreateMuxer(fd_, static_cast<OH_AVOutputFormat>(INVALID_FORMAT));
261     ASSERT_FALSE(isCreated);
262 }
263 
264 /**
265  * @tc.name: Muxer_AddTrack_001
266  * @tc.desc: Muxer AddTrack add audio track
267  * @tc.type: FUNC
268  */
269 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_001, TestSize.Level0)
270 {
271     int32_t audioTrackId = -1;
272     int32_t ret = 0;
273     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_AddTrack.mp4");
274     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
275     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
276     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
277     ASSERT_TRUE(isCreated);
278 
279     std::shared_ptr<FormatMock> audioParams = FormatMockFactory::CreateFormat();
280     audioParams->PutStringValue(OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
281     audioParams->PutIntValue(OH_MD_KEY_AUD_SAMPLE_RATE, TEST_SAMPLE_RATE);
282     audioParams->PutIntValue(OH_MD_KEY_AUD_CHANNEL_COUNT, TEST_CHANNEL_COUNT);
283     ret = avmuxer_->AddTrack(audioTrackId, audioParams);
284     EXPECT_EQ(ret, AV_ERR_OK);
285     EXPECT_GE(audioTrackId, 0);
286 
287     audioParams = FormatMockFactory::CreateFormat();
288     audioParams->PutIntValue(OH_MD_KEY_AUD_SAMPLE_RATE, TEST_SAMPLE_RATE);
289     audioParams->PutIntValue(OH_MD_KEY_AUD_CHANNEL_COUNT, TEST_CHANNEL_COUNT);
290     ret = avmuxer_->AddTrack(audioTrackId, audioParams);
291     EXPECT_NE(ret, AV_ERR_OK);
292 
293     audioParams = FormatMockFactory::CreateFormat();
294     audioParams->PutStringValue(OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
295     audioParams->PutIntValue(OH_MD_KEY_AUD_CHANNEL_COUNT, TEST_CHANNEL_COUNT);
296     ret = avmuxer_->AddTrack(audioTrackId, audioParams);
297     EXPECT_NE(ret, AV_ERR_OK);
298 
299     audioParams = FormatMockFactory::CreateFormat();
300     audioParams->PutStringValue(OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
301     audioParams->PutIntValue(OH_MD_KEY_AUD_SAMPLE_RATE, TEST_SAMPLE_RATE);
302     ret = avmuxer_->AddTrack(audioTrackId, audioParams);
303     EXPECT_NE(ret, AV_ERR_OK);
304 }
305 
306 /**
307  * @tc.name: Muxer_AddTrack_002
308  * @tc.desc: Muxer AddTrack add video track
309  * @tc.type: FUNC
310  */
311 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_002, TestSize.Level0)
312 {
313     int32_t videoTrackId = -1;
314     int32_t ret = AV_ERR_INVALID_VAL;
315     std::string outputFile = TEST_FILE_PATH + std::string("avmuxer_AddTrack_002.mp4");
316     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
317     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
318     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
319     ASSERT_TRUE(isCreated);
320 
321     std::shared_ptr<FormatMock> videoParams = FormatMockFactory::CreateFormat();
322     videoParams->PutStringValue(OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_VIDEO_AVC);
323     videoParams->PutIntValue(OH_MD_KEY_WIDTH, TEST_WIDTH);
324     videoParams->PutIntValue(OH_MD_KEY_HEIGHT, TEST_HEIGHT);
325     ret = avmuxer_->AddTrack(videoTrackId, videoParams);
326     EXPECT_EQ(ret, AV_ERR_OK);
327     EXPECT_GE(videoTrackId, 0);
328 
329     videoParams = FormatMockFactory::CreateFormat();
330     videoParams->PutIntValue(OH_MD_KEY_WIDTH, TEST_WIDTH);
331     videoParams->PutIntValue(OH_MD_KEY_HEIGHT, TEST_HEIGHT);
332     ret = avmuxer_->AddTrack(videoTrackId, videoParams);
333     EXPECT_NE(ret, AV_ERR_OK);
334 
335     videoParams = FormatMockFactory::CreateFormat();
336     videoParams->PutStringValue(OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_VIDEO_AVC);
337     videoParams->PutIntValue(OH_MD_KEY_HEIGHT, TEST_HEIGHT);
338     ret = avmuxer_->AddTrack(videoTrackId, videoParams);
339     EXPECT_NE(ret, AV_ERR_OK);
340 
341     videoParams = FormatMockFactory::CreateFormat();
342     videoParams->PutStringValue(OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_VIDEO_AVC);
343     videoParams->PutIntValue(OH_MD_KEY_WIDTH, TEST_WIDTH);
344     ret = avmuxer_->AddTrack(videoTrackId, videoParams);
345     EXPECT_NE(ret, AV_ERR_OK);
346 }
347 
348 /**
349  * @tc.name: Muxer_AddTrack_003
350  * @tc.desc: Muxer AddTrack after Start()
351  * @tc.type: FUNC
352  */
353 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_003, TestSize.Level0)
354 {
355     int32_t audioTrackId = -1;
356     int32_t videoTrackId = -1;
357     int32_t ret = AV_ERR_INVALID_VAL;
358     std::string outputFile = TEST_FILE_PATH + std::string("avmuxer_AddTrack_003.mp4");
359     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
360     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
361     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
362     ASSERT_TRUE(isCreated);
363 
364     std::shared_ptr<FormatMock> videoParams =
365         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
366     videoParams->PutBuffer(OH_MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
367     ret = avmuxer_->AddTrack(videoTrackId, videoParams);
368     EXPECT_EQ(ret, AV_ERR_OK);
369     EXPECT_GE(videoTrackId, 0);
370 
371     ASSERT_EQ(avmuxer_->Start(), 0);
372     std::shared_ptr<FormatMock> audioParams =
373         FormatMockFactory::CreateAudioFormat(OH_AVCODEC_MIMETYPE_AUDIO_MPEG, TEST_SAMPLE_RATE, TEST_CHANNEL_COUNT);
374     ret = avmuxer_->AddTrack(audioTrackId, audioParams);
375     EXPECT_NE(ret, AV_ERR_OK);
376 }
377 
378 /**
379  * @tc.name: Muxer_AddTrack_004
380  * @tc.desc: Muxer AddTrack mimeType test
381  * @tc.type: FUNC
382  */
383 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_004, TestSize.Level0)
384 {
385     int32_t trackId = -1;
386     int32_t ret = 0;
387     const std::vector<std::string_view> testMp4MimeTypeList =
388     {
389         OH_AVCODEC_MIMETYPE_AUDIO_MPEG,
390         OH_AVCODEC_MIMETYPE_AUDIO_AAC,
391         OH_AVCODEC_MIMETYPE_VIDEO_AVC,
392         OH_AVCODEC_MIMETYPE_IMAGE_JPG,
393         OH_AVCODEC_MIMETYPE_IMAGE_PNG,
394         OH_AVCODEC_MIMETYPE_IMAGE_BMP,
395     };
396 
397     const std::vector<std::string_view> testM4aMimeTypeList =
398     {
399         OH_AVCODEC_MIMETYPE_AUDIO_AAC,
400         OH_AVCODEC_MIMETYPE_IMAGE_JPG,
401         OH_AVCODEC_MIMETYPE_IMAGE_PNG,
402         OH_AVCODEC_MIMETYPE_IMAGE_BMP,
403     };
404 
405     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_AddTrack.mp4");
406     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
407     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
408 
409     std::shared_ptr<FormatMock> avParam = FormatMockFactory::CreateFormat();
410     avParam->PutIntValue(OH_MD_KEY_AUD_SAMPLE_RATE, TEST_SAMPLE_RATE);
411     avParam->PutIntValue(OH_MD_KEY_AUD_CHANNEL_COUNT, TEST_CHANNEL_COUNT);
412     avParam->PutIntValue(OH_MD_KEY_WIDTH, TEST_WIDTH);
413     avParam->PutIntValue(OH_MD_KEY_HEIGHT, TEST_HEIGHT);
414 
415     for (uint32_t i = 0; i < testMp4MimeTypeList.size(); ++i) {
416         bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
417         ASSERT_TRUE(isCreated);
418         avParam->PutStringValue(OH_MD_KEY_CODEC_MIME, testMp4MimeTypeList[i]);
419         ret = avmuxer_->AddTrack(trackId, avParam);
420         EXPECT_EQ(ret, AV_ERR_OK) << "AddTrack failed: i:" << i << " mimeType:" << testMp4MimeTypeList[i];
421         EXPECT_EQ(trackId, 0) << "i:" << i << " TrackId:" << trackId << " mimeType:" << testMp4MimeTypeList[i];
422     }
423 
424     // need to change libohosffmpeg.z.so, muxer build config add ipod
425     avmuxer_->Destroy();
426     outputFormat = AV_OUTPUT_FORMAT_M4A;
427     avParam->PutIntValue(OH_MD_KEY_PROFILE, AAC_PROFILE_LC);
428     avParam->PutBuffer(OH_MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
429     for (uint32_t i = 0; i < testM4aMimeTypeList.size(); ++i) {
430         bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
431         ASSERT_TRUE(isCreated);
432         avParam->PutStringValue(OH_MD_KEY_CODEC_MIME, testM4aMimeTypeList[i]);
433         ret = avmuxer_->AddTrack(trackId, avParam);
434         EXPECT_EQ(ret, AV_ERR_OK) << "AddTrack failed: i:" << i << " mimeType:" << testM4aMimeTypeList[i];
435         EXPECT_EQ(trackId, 0) << "i:" << i << " TrackId:" << trackId << " mimeType:" << testM4aMimeTypeList[i];
436     }
437 }
438 
439 /**
440  * @tc.name: Muxer_AddTrack_0091
441  * @tc.desc: Muxer AddTrack while create by unexpected outputFormat
442  * @tc.type: FUNC
443  */
444 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_0091, TestSize.Level0)
445 {
446     int32_t audioTrackId = -1; // -1 track
447     int32_t ret = 0;
448     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_AddTrack.mp3");
449     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
450     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MP3;
451     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
452     ASSERT_TRUE(isCreated);
453 
454     std::shared_ptr<FormatMock> audioParams = FormatMockFactory::CreateFormat();
455     audioParams->PutStringValue(OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
456     audioParams->PutIntValue(OH_MD_KEY_AUD_SAMPLE_RATE, TEST_SAMPLE_RATE);
457     audioParams->PutIntValue(OH_MD_KEY_AUD_CHANNEL_COUNT, TEST_CHANNEL_COUNT);
458     ret = avmuxer_->AddTrack(audioTrackId, audioParams);
459     EXPECT_EQ(ret, AV_ERR_OK);
460     EXPECT_GE(audioTrackId, 0);
461 }
462 
463 /**
464  * @tc.name: Muxer_AddTrack_005
465  * @tc.desc: Muxer AddTrack while create by unexpected outputFormat
466  * @tc.type: FUNC
467  */
468 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_005, TestSize.Level0)
469 {
470     int32_t trackId = -2;
471     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_AddTrack.mp4");
472     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
473     bool isCreated = avmuxer_->CreateMuxer(fd_, static_cast<OH_AVOutputFormat>(INVALID_FORMAT));
474     ASSERT_FALSE(isCreated);
475 
476     std::shared_ptr<FormatMock> avParam = FormatMockFactory::CreateFormat();
477     avParam->PutStringValue(OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
478     avParam->PutIntValue(OH_MD_KEY_AUD_SAMPLE_RATE, TEST_SAMPLE_RATE);
479     avParam->PutIntValue(OH_MD_KEY_AUD_CHANNEL_COUNT, TEST_CHANNEL_COUNT);
480     avParam->PutIntValue(OH_MD_KEY_WIDTH, TEST_WIDTH);
481     avParam->PutIntValue(OH_MD_KEY_HEIGHT, TEST_HEIGHT);
482 
483     int32_t ret = avmuxer_->AddTrack(trackId, avParam);
484     ASSERT_NE(ret, 0);
485 
486     avParam->PutStringValue(OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_VIDEO_AVC);
487     ret = avmuxer_->AddTrack(trackId, avParam);
488     ASSERT_NE(ret, 0);
489 }
490 
491 /**
492  * @tc.name: Muxer_AddTrack_006
493  * @tc.desc: Muxer AddTrack while create by unexpected value
494  * @tc.type: FUNC
495  */
496 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_006, TestSize.Level0)
497 {
498     int32_t trackId = -2;
499     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_AddTrack.mp4");
500     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
501     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
502     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
503     ASSERT_TRUE(isCreated);
504 
505     std::shared_ptr<FormatMock> audioParam = FormatMockFactory::CreateFormat();
506     audioParam->PutStringValue(OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
507     audioParam->PutIntValue(OH_MD_KEY_AUD_SAMPLE_RATE, TEST_SAMPLE_RATE);
508     audioParam->PutIntValue(OH_MD_KEY_AUD_CHANNEL_COUNT, -1);
509     int32_t ret = avmuxer_->AddTrack(trackId, audioParam);
510     ASSERT_NE(ret, 0);
511 
512     audioParam->PutIntValue(OH_MD_KEY_AUD_SAMPLE_RATE, -1);
513     audioParam->PutIntValue(OH_MD_KEY_AUD_CHANNEL_COUNT, TEST_CHANNEL_COUNT);
514     ret = avmuxer_->AddTrack(trackId, audioParam);
515     ASSERT_NE(ret, 0);
516 
517     // test add video track
518     std::shared_ptr<FormatMock> videoParam = FormatMockFactory::CreateFormat();
519     videoParam->PutStringValue(OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_VIDEO_AVC);
520     videoParam->PutIntValue(OH_MD_KEY_WIDTH, TEST_WIDTH);
521     videoParam->PutIntValue(OH_MD_KEY_HEIGHT, -1);
522     ret = avmuxer_->AddTrack(trackId, videoParam);
523     ASSERT_NE(ret, 0);
524 
525     videoParam->PutIntValue(OH_MD_KEY_WIDTH, -1);
526     videoParam->PutIntValue(OH_MD_KEY_HEIGHT, TEST_HEIGHT);
527     ret = avmuxer_->AddTrack(trackId, videoParam);
528     ASSERT_NE(ret, 0);
529 
530     videoParam->PutIntValue(OH_MD_KEY_WIDTH, TEST_WIDTH);
531     videoParam->PutIntValue(OH_MD_KEY_HEIGHT, 0xFFFF + 1);
532     ret = avmuxer_->AddTrack(trackId, videoParam);
533     ASSERT_NE(ret, 0);
534 
535     videoParam->PutIntValue(OH_MD_KEY_WIDTH, 0xFFFF + 1);
536     videoParam->PutIntValue(OH_MD_KEY_HEIGHT, TEST_HEIGHT);
537     ret = avmuxer_->AddTrack(trackId, videoParam);
538     ASSERT_NE(ret, 0);
539 
540     videoParam->PutIntValue(OH_MD_KEY_WIDTH, 0xFFFF);
541     videoParam->PutIntValue(OH_MD_KEY_HEIGHT, 0xFFFF);
542     ret = avmuxer_->AddTrack(trackId, videoParam);
543     ASSERT_EQ(ret, 0);
544 }
545 
546 /**
547  * @tc.name: Muxer_AddTrack_007
548  * @tc.desc: Create amr-nb Muxer AddTrack
549  * @tc.type: FUNC
550  */
551 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_007, TestSize.Level0)
552 {
553     int32_t trackId = -2; // -2: Initialize to an invalid ID
554     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_AddTrack.amr");
555     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
556     bool isCreated = avmuxer_->CreateMuxer(fd_, static_cast<OH_AVOutputFormat>(AV_OUTPUT_FORMAT_AMR));
557     ASSERT_TRUE(isCreated);
558 
559     std::shared_ptr<FormatMock> avParam = FormatMockFactory::CreateFormat();
560     avParam->PutStringValue(OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_AMR_NB);
561     avParam->PutIntValue(OH_MD_KEY_AUD_SAMPLE_RATE, 8000); // 8000: 8khz sample rate
562     avParam->PutIntValue(OH_MD_KEY_AUD_CHANNEL_COUNT, 1); // 1: 1 audio channel,mono
563 
564     int32_t ret = avmuxer_->AddTrack(trackId, avParam);
565     ASSERT_EQ(ret, 0);
566 }
567 
568 /**
569  * @tc.name: Muxer_AddTrack_008
570  * @tc.desc: Create amr-wb Muxer AddTrack
571  * @tc.type: FUNC
572  */
573 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_008, TestSize.Level0)
574 {
575     int32_t trackId = -2; // -2: Initialize to an invalid ID
576     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_AddTrack.amr");
577     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
578     bool isCreated = avmuxer_->CreateMuxer(fd_, static_cast<OH_AVOutputFormat>(AV_OUTPUT_FORMAT_AMR));
579     ASSERT_TRUE(isCreated);
580 
581     std::shared_ptr<FormatMock> avParam = FormatMockFactory::CreateFormat();
582     avParam->PutStringValue(OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_AMR_WB);
583     avParam->PutIntValue(OH_MD_KEY_AUD_SAMPLE_RATE, 16000); // 16000: 16khz sample rate
584     avParam->PutIntValue(OH_MD_KEY_AUD_CHANNEL_COUNT, 1); // 1: 1 audio channel, mono
585 
586     int32_t ret = avmuxer_->AddTrack(trackId, avParam);
587     ASSERT_EQ(ret, 0);
588 }
589 
590 /**
591  * @tc.name: Muxer_Start_001
592  * @tc.desc: Muxer Start normal
593  * @tc.type: FUNC
594  */
595 HWTEST_F(AVMuxerUnitTest, Muxer_Start_001, TestSize.Level0)
596 {
597     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Start.mp4");
598     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
599     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
600     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
601     ASSERT_TRUE(isCreated);
602 
603     std::shared_ptr<FormatMock> videoParams =
604         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
605     videoParams->PutBuffer(OH_MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
606 
607     int32_t videoTrackId = -1;
608     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
609     ASSERT_EQ(ret, AV_ERR_OK);
610     ASSERT_GE(videoTrackId, 0);
611     EXPECT_EQ(avmuxer_->Start(), 0);
612 }
613 
614 /**
615  * @tc.name: Muxer_Start_002
616  * @tc.desc: Muxer Start twice
617  * @tc.type: FUNC
618  */
619 HWTEST_F(AVMuxerUnitTest, Muxer_Start_002, TestSize.Level0)
620 {
621     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Start.mp4");
622     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
623     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
624     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
625     ASSERT_TRUE(isCreated);
626 
627     std::shared_ptr<FormatMock> videoParams =
628         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
629     videoParams->PutBuffer(OH_MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
630 
631     int32_t videoTrackId = -1;
632     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
633     ASSERT_EQ(ret, AV_ERR_OK);
634     ASSERT_GE(videoTrackId, 0);
635     ASSERT_EQ(avmuxer_->Start(), 0);
636     EXPECT_NE(avmuxer_->Start(), 0);
637 }
638 
639 /**
640  * @tc.name: Muxer_Start_003
641  * @tc.desc: Muxer Start after Create()
642  * @tc.type: FUNC
643  */
644 HWTEST_F(AVMuxerUnitTest, Muxer_Start_003, TestSize.Level0)
645 {
646     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Start.mp4");
647     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
648     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
649     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
650     ASSERT_TRUE(isCreated);
651     EXPECT_NE(avmuxer_->Start(), 0);
652 }
653 
654 /**
655  * @tc.name: Muxer_Start_004
656  * @tc.desc: Muxer Start after Stop()
657  * @tc.type: FUNC
658  */
659 HWTEST_F(AVMuxerUnitTest, Muxer_Start_004, TestSize.Level0)
660 {
661     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Start.mp4");
662     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
663     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
664     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
665     ASSERT_TRUE(isCreated);
666 
667     std::shared_ptr<FormatMock> videoParams =
668         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
669     videoParams->PutBuffer(OH_MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
670 
671     int32_t videoTrackId = -1;
672     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
673     ASSERT_EQ(ret, AV_ERR_OK);
674     ASSERT_GE(videoTrackId, 0);
675     ASSERT_EQ(avmuxer_->Start(), 0);
676     ASSERT_EQ(avmuxer_->Stop(), 0);
677 
678     EXPECT_NE(avmuxer_->Start(), 0);
679 }
680 
681 /**
682  * @tc.name: Muxer_Start_005
683  * @tc.desc: Muxer Start while create by unexpected outputFormat
684  * @tc.type: FUNC
685  */
686 HWTEST_F(AVMuxerUnitTest, Muxer_Start_005, TestSize.Level0)
687 {
688     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Start.mp4");
689     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
690     bool isCreated = avmuxer_->CreateMuxer(fd_, static_cast<OH_AVOutputFormat>(INVALID_FORMAT));
691     ASSERT_FALSE(isCreated);
692 
693     std::shared_ptr<FormatMock> videoParams =
694         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
695     videoParams->PutBuffer(OH_MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
696 
697     int32_t videoTrackId = -1;
698     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
699     ASSERT_NE(ret, AV_ERR_OK);
700     ASSERT_LT(videoTrackId, 0);
701     ASSERT_NE(avmuxer_->Start(), 0);
702 }
703 
704 /**
705  * @tc.name: Muxer_Stop_001
706  * @tc.desc: Muxer Stop() normal
707  * @tc.type: FUNC
708  */
709 HWTEST_F(AVMuxerUnitTest, Muxer_Stop_001, TestSize.Level0)
710 {
711     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Stop.mp4");
712     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
713     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
714     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
715     ASSERT_TRUE(isCreated);
716 
717     std::shared_ptr<FormatMock> videoParams =
718         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
719     videoParams->PutBuffer(OH_MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
720     int32_t videoTrackId = -1;
721     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
722     ASSERT_EQ(ret, AV_ERR_OK);
723     ASSERT_GE(videoTrackId, 0);
724     ASSERT_EQ(avmuxer_->Start(), 0);
725     EXPECT_EQ(avmuxer_->Stop(), 0);
726 }
727 
728 /**
729  * @tc.name: Muxer_Stop_002
730  * @tc.desc: Muxer Stop() after Create()
731  * @tc.type: FUNC
732  */
733 HWTEST_F(AVMuxerUnitTest, Muxer_Stop_002, TestSize.Level0)
734 {
735     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Stop.mp4");
736     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
737     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
738     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
739     ASSERT_TRUE(isCreated);
740     EXPECT_NE(avmuxer_->Stop(), 0);
741 }
742 
743 /**
744  * @tc.name: Muxer_Stop_003
745  * @tc.desc: Muxer Stop() after AddTrack()
746  * @tc.type: FUNC
747  */
748 HWTEST_F(AVMuxerUnitTest, Muxer_Stop_003, TestSize.Level0)
749 {
750     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Stop.mp4");
751     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
752     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
753     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
754     ASSERT_TRUE(isCreated);
755 
756     std::shared_ptr<FormatMock> videoParams =
757         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
758     videoParams->PutBuffer(OH_MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
759     int32_t videoTrackId = -1;
760     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
761     ASSERT_EQ(ret, AV_ERR_OK);
762     ASSERT_GE(videoTrackId, 0);
763     EXPECT_NE(avmuxer_->Stop(), 0);
764 }
765 
766 /**
767  * @tc.name: Muxer_Stop_004
768  * @tc.desc: Muxer Stop() multiple times
769  * @tc.type: FUNC
770  */
771 HWTEST_F(AVMuxerUnitTest, Muxer_Stop_004, TestSize.Level0)
772 {
773     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Stop.mp4");
774     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
775     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
776     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
777     ASSERT_TRUE(isCreated);
778 
779     std::shared_ptr<FormatMock> videoParams =
780         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
781     videoParams->PutBuffer(OH_MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
782     int32_t videoTrackId = -1;
783     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
784     ASSERT_EQ(ret, AV_ERR_OK);
785     ASSERT_GE(videoTrackId, 0);
786     ASSERT_EQ(avmuxer_->Start(), 0);
787     ASSERT_EQ(avmuxer_->Stop(), 0);
788 
789     ASSERT_NE(avmuxer_->Stop(), 0);
790     ASSERT_NE(avmuxer_->Stop(), 0);
791     ASSERT_NE(avmuxer_->Stop(), 0);
792 }
793 
794 /**
795  * @tc.name: Muxer_Stop_005
796  * @tc.desc: Muxer Stop() before Start
797  * @tc.type: FUNC
798  */
799 HWTEST_F(AVMuxerUnitTest, Muxer_Stop_005, TestSize.Level0)
800 {
801     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Stop.mp4");
802     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
803     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
804     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
805     ASSERT_TRUE(isCreated);
806 
807     std::shared_ptr<FormatMock> videoParams =
808         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
809     videoParams->PutBuffer(OH_MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
810     int32_t videoTrackId = -1;
811     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
812     ASSERT_EQ(ret, AV_ERR_OK);
813     EXPECT_GE(videoTrackId, 0);
814     EXPECT_NE(avmuxer_->Stop(), 0);
815     EXPECT_EQ(avmuxer_->Start(), 0);
816     EXPECT_EQ(avmuxer_->Stop(), 0);
817 }
818 
819 /**
820  * @tc.name: Muxer_Stop_006
821  * @tc.desc: Muxer Stop() while create by unexpected outputFormat
822  * @tc.type: FUNC
823  */
824 HWTEST_F(AVMuxerUnitTest, Muxer_Stop_006, TestSize.Level0)
825 {
826     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Stop.mp4");
827     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
828     bool isCreated = avmuxer_->CreateMuxer(fd_, static_cast<OH_AVOutputFormat>(INVALID_FORMAT));
829     ASSERT_FALSE(isCreated);
830 
831     std::shared_ptr<FormatMock> videoParams =
832         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
833     videoParams->PutBuffer(OH_MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
834     int32_t videoTrackId = -1;
835     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
836     ASSERT_NE(ret, AV_ERR_OK);
837     ASSERT_LT(videoTrackId, 0);
838     ASSERT_NE(avmuxer_->Start(), 0);
839     ASSERT_NE(avmuxer_->Stop(), 0);
840 }
841 
842 /**
843  * @tc.name: Muxer_writeSample_001
844  * @tc.desc: Muxer Write Sample normal
845  * @tc.type: FUNC
846  */
847 HWTEST_F(AVMuxerUnitTest, Muxer_writeSample_001, TestSize.Level0)
848 {
849     int32_t trackId = -1;
850     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_WriteSample.mp4");
851     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
852 
853     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
854     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
855     ASSERT_TRUE(isCreated);
856 
857     std::shared_ptr<FormatMock> vParam =
858         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
859 
860     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
861     ASSERT_EQ(ret, 0);
862     ASSERT_GE(trackId, 0);
863     ASSERT_EQ(avmuxer_->Start(), 0);
864 
865     OH_AVCodecBufferAttr info;
866     info.pts = 0;
867     info.offset = 0;
868     info.size = sizeof(buffer_);
869     ret = avmuxer_->WriteSample(trackId, buffer_, info);
870     ASSERT_EQ(ret, 0);
871 }
872 
873 /**
874  * @tc.name: Muxer_writeSample_002
875  * @tc.desc: Muxer Write Sample while create by unexpected outputFormat
876  * @tc.type: FUNC
877  */
878 HWTEST_F(AVMuxerUnitTest, Muxer_writeSample_002, TestSize.Level0)
879 {
880     int32_t trackId = -1;
881     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_writeSample.mp4");
882     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
883     bool isCreated = avmuxer_->CreateMuxer(fd_, static_cast<OH_AVOutputFormat>(INVALID_FORMAT));
884     ASSERT_FALSE(isCreated);
885 
886     std::shared_ptr<FormatMock> vParam =
887         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
888 
889     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
890     ASSERT_NE(ret, 0);
891     ASSERT_LT(trackId, 0);
892     ASSERT_NE(avmuxer_->Start(), 0);
893 
894     OH_AVCodecBufferAttr info;
895     info.pts = 0;
896     info.size = sizeof(buffer_);
897     ret = avmuxer_->WriteSample(trackId, buffer_, info);
898     ASSERT_NE(ret, 0);
899 }
900 
901 /**
902  * @tc.name: Muxer_writeSample_003
903  * @tc.desc: Muxer Write Sample without Start()
904  * @tc.type: FUNC
905  */
906 HWTEST_F(AVMuxerUnitTest, Muxer_writeSample_003, TestSize.Level0)
907 {
908     int32_t trackId = -1;
909     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_WriteSample.mp4");
910     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
911 
912     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
913     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
914     ASSERT_TRUE(isCreated);
915 
916     std::shared_ptr<FormatMock> vParam =
917         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
918 
919     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
920     ASSERT_EQ(ret, 0);
921     ASSERT_GE(trackId, 0);
922 
923     OH_AVCodecBufferAttr info;
924     info.pts = 0;
925     info.size = sizeof(buffer_);
926     ret = avmuxer_->WriteSample(trackId, buffer_, info);
927     ASSERT_NE(ret, 0);
928 }
929 
930 /**
931  * @tc.name: Muxer_writeSample_004
932  * @tc.desc: Muxer Write Sample unexisting track
933  * @tc.type: FUNC
934  */
935 HWTEST_F(AVMuxerUnitTest, Muxer_writeSample_004, TestSize.Level0)
936 {
937     constexpr int32_t invalidTrackId = 99999;
938     int32_t trackId = -1;
939     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_WriteSample.mp4");
940     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
941 
942     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
943     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
944     ASSERT_TRUE(isCreated);
945 
946     std::shared_ptr<FormatMock> vParam =
947         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
948 
949     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
950     ASSERT_EQ(ret, 0);
951     ASSERT_GE(trackId, 0);
952     ASSERT_EQ(avmuxer_->Start(), 0);
953 
954     OH_AVCodecBufferAttr info;
955     info.pts = 0;
956     info.size = sizeof(buffer_);
957     ret = avmuxer_->WriteSample(trackId + 1, buffer_, info);
958     ASSERT_NE(ret, 0);
959 
960     ret = avmuxer_->WriteSample(-1, buffer_, info);
961     ASSERT_NE(ret, 0);
962 
963     ret = avmuxer_->WriteSample(invalidTrackId, buffer_, info);
964     ASSERT_NE(ret, 0);
965 }
966 
967 /**
968  * @tc.name: Muxer_writeSample_005
969  * @tc.desc: Muxer Write Sample after Stop()
970  * @tc.type: FUNC
971  */
972 HWTEST_F(AVMuxerUnitTest, Muxer_writeSample_005, TestSize.Level0)
973 {
974     int32_t trackId = -1;
975     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_WriteSample.mp4");
976     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
977 
978     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
979     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
980     ASSERT_TRUE(isCreated);
981 
982     std::shared_ptr<FormatMock> vParam =
983         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
984 
985     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
986     ASSERT_EQ(ret, 0);
987     ASSERT_GE(trackId, 0);
988     ASSERT_EQ(avmuxer_->Start(), 0);
989     ASSERT_EQ(avmuxer_->Stop(), 0);
990 
991     OH_AVCodecBufferAttr info;
992     info.pts = 0;
993     info.size = sizeof(buffer_);
994     ret = avmuxer_->WriteSample(trackId, buffer_, info);
995     ASSERT_NE(ret, 0);
996 }
997 
998 /**
999  * @tc.name: Muxer_SetRotation_001
1000  * @tc.desc: Muxer SetRotation after Create
1001  * @tc.type: FUNC
1002  */
1003 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_001, TestSize.Level0)
1004 {
1005     int32_t trackId = -1;
1006     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
1007     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1008 
1009     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1010     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1011     ASSERT_TRUE(isCreated);
1012 
1013     std::shared_ptr<FormatMock> vParam =
1014         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
1015     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
1016     ASSERT_EQ(ret, 0);
1017     ASSERT_GE(trackId, 0);
1018 
1019     ret = avmuxer_->SetRotation(TEST_ROTATION);
1020     EXPECT_EQ(ret, 0);
1021     EXPECT_EQ(avmuxer_->Start(), 0);
1022     EXPECT_EQ(avmuxer_->Stop(), 0);
1023 }
1024 
1025 
1026 /**
1027  * @tc.name: Muxer_SetRotation_002
1028  * @tc.desc: Muxer SetRotation after Create
1029  * @tc.type: FUNC
1030  */
1031 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_002, TestSize.Level0)
1032 {
1033     int32_t trackId = -1;
1034     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
1035     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1036 
1037     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1038     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1039     ASSERT_TRUE(isCreated);
1040 
1041     int32_t ret = avmuxer_->SetRotation(180); // 180 rotation
1042     EXPECT_EQ(ret, 0);
1043 
1044     std::shared_ptr<FormatMock> vParam =
1045     FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
1046     ret = avmuxer_->AddTrack(trackId, vParam);
1047     ASSERT_EQ(ret, 0);
1048     ASSERT_GE(trackId, 0);
1049 
1050     EXPECT_EQ(avmuxer_->Start(), 0);
1051     EXPECT_EQ(avmuxer_->Stop(), 0);
1052 }
1053 
1054 /**
1055  * @tc.name: Muxer_SetRotation_003
1056  * @tc.desc: Muxer SetRotation after Start
1057  * @tc.type: FUNC
1058  */
1059 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_003, TestSize.Level0)
1060 {
1061     int32_t trackId = -1;
1062     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
1063     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1064 
1065     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1066     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1067     ASSERT_TRUE(isCreated);
1068 
1069     std::shared_ptr<FormatMock> vParam =
1070         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
1071     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
1072     ASSERT_EQ(ret, 0);
1073     ASSERT_GE(trackId, 0);
1074     ASSERT_EQ(avmuxer_->Start(), 0);
1075 
1076     ret = avmuxer_->SetRotation(TEST_ROTATION);
1077     EXPECT_NE(ret, 0);
1078 }
1079 
1080 /**
1081  * @tc.name: Muxer_SetRotation_004
1082  * @tc.desc: Muxer SetRotation after Stop
1083  * @tc.type: FUNC
1084  */
1085 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_004, TestSize.Level0)
1086 {
1087     int32_t trackId = -1;
1088     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
1089     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1090 
1091     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1092     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1093     ASSERT_TRUE(isCreated);
1094 
1095     std::shared_ptr<FormatMock> vParam =
1096         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
1097     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
1098     ASSERT_EQ(ret, 0);
1099     ASSERT_GE(trackId, 0);
1100     ASSERT_EQ(avmuxer_->Start(), 0);
1101     ASSERT_EQ(avmuxer_->Stop(), 0);
1102 
1103     ret = avmuxer_->SetRotation(TEST_ROTATION);
1104     EXPECT_NE(ret, 0);
1105 }
1106 
1107 /**
1108  * @tc.name: Muxer_SetRotation_005
1109  * @tc.desc: Muxer SetRotation after WriteSample
1110  * @tc.type: FUNC
1111  */
1112 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_005, TestSize.Level0)
1113 {
1114     int32_t trackId = -1;
1115     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
1116     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1117 
1118     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1119     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1120     ASSERT_TRUE(isCreated);
1121 
1122     std::shared_ptr<FormatMock> vParam =
1123         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
1124 
1125     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
1126     ASSERT_EQ(ret, 0);
1127     ASSERT_GE(trackId, 0);
1128     ASSERT_EQ(avmuxer_->Start(), 0);
1129 
1130     OH_AVCodecBufferAttr info;
1131     info.pts = 0;
1132     info.size = sizeof(buffer_);
1133     ret = avmuxer_->WriteSample(trackId, buffer_, info);
1134     EXPECT_EQ(ret, 0);
1135 
1136     ret = avmuxer_->SetRotation(TEST_ROTATION);
1137     EXPECT_NE(ret, 0);
1138 }
1139 
1140 /**
1141  * @tc.name: Muxer_SetRotation_006
1142  * @tc.desc: Muxer SetRotation while Create failed!
1143  * @tc.type: FUNC
1144  */
1145 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_006, TestSize.Level0)
1146 {
1147     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
1148     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1149     bool isCreated = avmuxer_->CreateMuxer(fd_, static_cast<OH_AVOutputFormat>(INVALID_FORMAT));
1150     ASSERT_FALSE(isCreated);
1151 
1152     int32_t ret = avmuxer_->SetRotation(TEST_ROTATION);
1153     ASSERT_NE(ret, 0);
1154 }
1155 
1156 /**
1157  * @tc.name: Muxer_SetRotation_007
1158  * @tc.desc: Muxer SetRotation expected value
1159  * @tc.type: FUNC
1160  */
1161 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_007, TestSize.Level0)
1162 {
1163     int32_t trackId = -1;
1164     constexpr int32_t testRotation180 = 180;
1165     constexpr int32_t testRotation270 = 270;
1166     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
1167     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1168 
1169     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1170     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1171     ASSERT_TRUE(isCreated);
1172 
1173     int32_t ret = avmuxer_->SetRotation(0);
1174     EXPECT_EQ(ret, 0);
1175 
1176     ret = avmuxer_->SetRotation(TEST_ROTATION);
1177     EXPECT_EQ(ret, 0);
1178 
1179     ret = avmuxer_->SetRotation(testRotation180);
1180     EXPECT_EQ(ret, 0);
1181 
1182     ret = avmuxer_->SetRotation(testRotation270);
1183     EXPECT_EQ(ret, 0);
1184 
1185     std::shared_ptr<FormatMock> vParam =
1186         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
1187     ret = avmuxer_->AddTrack(trackId, vParam);
1188     ASSERT_EQ(ret, 0);
1189     ASSERT_GE(trackId, 0);
1190 
1191     EXPECT_EQ(avmuxer_->Start(), 0);
1192     EXPECT_EQ(avmuxer_->Stop(), 0);
1193 }
1194 
1195 /**
1196  * @tc.name: Muxer_SetRotation_008
1197  * @tc.desc: Muxer SetRotation unexpected value
1198  * @tc.type: FUNC
1199  */
1200 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_008, TestSize.Level0)
1201 {
1202     constexpr int32_t testRotation360 = 360;
1203     constexpr int32_t testRotationNeg90 = -90;
1204     constexpr int32_t testRotationNeg180 = -180;
1205     constexpr int32_t testRotationNeg270 = -270;
1206     constexpr int32_t testRotationNeg360 = -360;
1207     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
1208     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1209 
1210     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1211     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1212     ASSERT_TRUE(isCreated);
1213 
1214     int32_t ret = avmuxer_->SetRotation(1);
1215     EXPECT_NE(ret, 0);
1216 
1217     ret = avmuxer_->SetRotation(TEST_ROTATION + 1);
1218     EXPECT_NE(ret, 0);
1219 
1220     ret = avmuxer_->SetRotation(testRotation360);
1221     EXPECT_NE(ret, 0);
1222 
1223     ret = avmuxer_->SetRotation(-1);
1224     EXPECT_NE(ret, 0);
1225 
1226     ret = avmuxer_->SetRotation(testRotationNeg90);
1227     EXPECT_NE(ret, 0);
1228 
1229     ret = avmuxer_->SetRotation(testRotationNeg180);
1230     EXPECT_NE(ret, 0);
1231 
1232     ret = avmuxer_->SetRotation(testRotationNeg270);
1233     EXPECT_NE(ret, 0);
1234 
1235     ret = avmuxer_->SetRotation(testRotationNeg360);
1236     EXPECT_NE(ret, 0);
1237 }
1238 
1239 /**
1240  * @tc.name: Muxer_Hevc_AddTrack_001
1241  * @tc.desc: Muxer Hevc AddTrack while create by unexpected value
1242  * @tc.type: FUNC
1243  */
1244 HWTEST_F(AVMuxerUnitTest, Muxer_Hevc_AddTrack_001, TestSize.Level0)
1245 {
1246     if (access(HEVC_LIB_PATH.c_str(), F_OK) != 0) {
1247         std::cout << "the hevc of mimetype is not supported" << std::endl;
1248         return;
1249     }
1250 
1251     constexpr int32_t validVideoDelay = 1;
1252     constexpr int32_t invalidVideoDelay = -1;
1253     constexpr int32_t validFrameRate = 30;
1254     constexpr int32_t invalidFrameRate = -1;
1255 
1256     int32_t trackId = -1;
1257     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_H265.mp4");
1258     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1259     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1260     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1261     ASSERT_TRUE(isCreated);
1262 
1263     std::shared_ptr<FormatMock> videoParams =
1264         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_HEVC, TEST_WIDTH, TEST_HEIGHT);
1265 
1266     videoParams->PutIntValue("video_delay", validVideoDelay);
1267     int32_t ret = avmuxer_->AddTrack(trackId, videoParams);
1268     ASSERT_NE(ret, 0);
1269 
1270     videoParams->PutIntValue("video_delay", invalidVideoDelay);
1271     videoParams->PutDoubleValue(OH_MD_KEY_FRAME_RATE, validFrameRate);
1272     ret = avmuxer_->AddTrack(trackId, videoParams);
1273     ASSERT_NE(ret, 0);
1274 
1275     videoParams->PutIntValue("video_delay", validVideoDelay);
1276     videoParams->PutDoubleValue(OH_MD_KEY_FRAME_RATE, invalidFrameRate);
1277     ret = avmuxer_->AddTrack(trackId, videoParams);
1278     ASSERT_NE(ret, 0);
1279 
1280     videoParams->PutIntValue("video_delay", 0xFF);
1281     videoParams->PutDoubleValue(OH_MD_KEY_FRAME_RATE, validFrameRate);
1282     ret = avmuxer_->AddTrack(trackId, videoParams);
1283     ASSERT_NE(ret, 0);
1284 
1285     videoParams->PutIntValue("video_delay", validVideoDelay);
1286     videoParams->PutDoubleValue(OH_MD_KEY_FRAME_RATE, validFrameRate);
1287     ret = avmuxer_->AddTrack(trackId, videoParams);
1288     ASSERT_EQ(ret, 0);
1289     ASSERT_GE(trackId, 0);
1290 }
1291 
1292 /**
1293  * @tc.name: Muxer_Hevc_WriteSample_001
1294  * @tc.desc: Muxer Hevc Write Sample normal
1295  * @tc.type: FUNC
1296  */
1297 HWTEST_F(AVMuxerUnitTest, Muxer_Hevc_WriteSample_001, TestSize.Level0)
1298 {
1299     if (access(HEVC_LIB_PATH.c_str(), F_OK) != 0) {
1300         return;
1301     }
1302 
1303     constexpr int32_t invalidTrackId = 99999;
1304     int32_t trackId = -1;
1305     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_H265.mp4");
1306     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1307 
1308     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1309     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1310     ASSERT_TRUE(isCreated);
1311 
1312     std::shared_ptr<FormatMock> videoParams =
1313         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_HEVC, TEST_WIDTH, TEST_HEIGHT);
1314 
1315     int32_t ret = avmuxer_->AddTrack(trackId, videoParams);
1316     ASSERT_EQ(ret, 0);
1317     ASSERT_GE(trackId, 0);
1318     ASSERT_EQ(avmuxer_->Start(), 0);
1319 
1320     OH_AVCodecBufferAttr info;
1321     info.pts = 0;
1322     info.size = sizeof(buffer_);
1323     OH_AVBuffer *buffer = OH_AVBuffer_Create(info.size);
1324     ASSERT_EQ(memcpy_s(OH_AVBuffer_GetAddr(buffer), info.size, buffer_, sizeof(buffer_)), 0);
1325     OH_AVBuffer_SetBufferAttr(buffer, &info);
1326 
1327     ret = avmuxer_->WriteSampleBuffer(trackId + 1, buffer);
1328     ASSERT_NE(ret, 0);
1329 
1330     ret = avmuxer_->WriteSampleBuffer(-1, buffer);
1331     ASSERT_NE(ret, 0);
1332 
1333     ret = avmuxer_->WriteSampleBuffer(invalidTrackId, buffer);
1334     ASSERT_NE(ret, 0);
1335 
1336     ret = avmuxer_->WriteSampleBuffer(trackId, buffer);
1337     ASSERT_EQ(ret, 0);
1338 
1339     OH_AVBuffer_Destroy(buffer);
1340 }
1341 
1342 /**
1343  * @tc.name: Muxer_Hevc_WriteSample_002
1344  * @tc.desc: Muxer Hevc Write Sample flags AVCODEC_BUFFER_FLAGS_CODEC_DATA
1345  * @tc.type: FUNC
1346  */
1347 HWTEST_F(AVMuxerUnitTest, Muxer_Hevc_WriteSample_002, TestSize.Level0)
1348 {
1349     if (access(HEVC_LIB_PATH.c_str(), F_OK) != 0) {
1350         return;
1351     }
1352 
1353     int32_t trackId = -1;
1354     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_H265.mp4");
1355     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1356 
1357     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1358     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1359     ASSERT_TRUE(isCreated);
1360 
1361     std::shared_ptr<FormatMock> videoParams =
1362         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_HEVC, TEST_WIDTH, TEST_HEIGHT);
1363 
1364     int32_t ret = avmuxer_->AddTrack(trackId, videoParams);
1365     ASSERT_EQ(ret, 0);
1366     ASSERT_GE(trackId, 0);
1367     ASSERT_EQ(avmuxer_->Start(), 0);
1368 
1369     OH_AVCodecBufferAttr info;
1370     info.pts = 0;
1371     info.size = sizeof(annexBuffer_);
1372     OH_AVBuffer *buffer = OH_AVBuffer_Create(info.size);
1373     ASSERT_EQ(memcpy_s(OH_AVBuffer_GetAddr(buffer), info.size, annexBuffer_, sizeof(annexBuffer_)), 0);
1374 
1375     info.flags = AVCODEC_BUFFER_FLAGS_CODEC_DATA;
1376     OH_AVBuffer_SetBufferAttr(buffer, &info);
1377     ret = avmuxer_->WriteSampleBuffer(trackId, buffer);
1378     ASSERT_EQ(ret, 0);
1379 
1380     info.flags = AVCODEC_BUFFER_FLAGS_SYNC_FRAME;
1381     OH_AVBuffer_SetBufferAttr(buffer, &info);
1382     ret = avmuxer_->WriteSampleBuffer(trackId, buffer);
1383     ASSERT_EQ(ret, 0);
1384 
1385     OH_AVBuffer_Destroy(buffer);
1386 }
1387 
1388 /**
1389  * @tc.name: Muxer_Hevc_WriteSample_003
1390  * @tc.desc: Muxer Hevc Write Sample flags AVCODEC_BUFFER_FLAGS_CODEC_DATA | AVCODEC_BUFFER_FLAGS_SYNC_FRAME
1391  * @tc.type: FUNC
1392  */
1393 HWTEST_F(AVMuxerUnitTest, Muxer_Hevc_WriteSample_003, TestSize.Level0)
1394 {
1395     if (access(HEVC_LIB_PATH.c_str(), F_OK) != 0) {
1396         return;
1397     }
1398 
1399     int32_t trackId = -1;
1400     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_H265.mp4");
1401     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1402 
1403     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1404     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1405     ASSERT_TRUE(isCreated);
1406 
1407     std::shared_ptr<FormatMock> videoParams =
1408         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_HEVC, TEST_WIDTH, TEST_HEIGHT);
1409 
1410     int32_t ret = avmuxer_->AddTrack(trackId, videoParams);
1411     ASSERT_EQ(ret, 0);
1412     ASSERT_GE(trackId, 0);
1413     ASSERT_EQ(avmuxer_->Start(), 0);
1414 
1415     OH_AVCodecBufferAttr info;
1416     info.pts = 0;
1417     info.size = sizeof(annexBuffer_);
1418     OH_AVBuffer *buffer = OH_AVBuffer_Create(info.size);
1419     ASSERT_EQ(memcpy_s(OH_AVBuffer_GetAddr(buffer), info.size, annexBuffer_, sizeof(annexBuffer_)), 0);
1420 
1421     info.flags = AVCODEC_BUFFER_FLAGS_CODEC_DATA | AVCODEC_BUFFER_FLAGS_SYNC_FRAME;
1422     OH_AVBuffer_SetBufferAttr(buffer, &info);
1423     ret = avmuxer_->WriteSampleBuffer(trackId, buffer);
1424     ASSERT_EQ(ret, 0);
1425 
1426     info.flags = AVCODEC_BUFFER_FLAGS_NONE;
1427     OH_AVBuffer_SetBufferAttr(buffer, &info);
1428     ret = avmuxer_->WriteSampleBuffer(trackId, buffer);
1429     ASSERT_EQ(ret, 0);
1430 
1431     OH_AVBuffer_Destroy(buffer);
1432 }
1433 
1434 /**
1435  * @tc.name: Muxer_Hevc_WriteSample_004
1436  * @tc.desc: Muxer Hevc Write Sample flags AVCODEC_BUFFER_FLAGS_SYNC_FRAME
1437  * @tc.type: FUNC
1438  */
1439 HWTEST_F(AVMuxerUnitTest, Muxer_Hevc_WriteSample_004, TestSize.Level0)
1440 {
1441     if (access(HEVC_LIB_PATH.c_str(), F_OK) != 0) {
1442         return;
1443     }
1444 
1445     int32_t trackId = -1;
1446     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_H265.mp4");
1447     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1448 
1449     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1450     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1451     ASSERT_TRUE(isCreated);
1452 
1453     std::shared_ptr<FormatMock> videoParams =
1454         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_HEVC, TEST_WIDTH, TEST_HEIGHT);
1455 
1456     int32_t ret = avmuxer_->AddTrack(trackId, videoParams);
1457     ASSERT_EQ(ret, 0);
1458     ASSERT_GE(trackId, 0);
1459     ASSERT_EQ(avmuxer_->Start(), 0);
1460 
1461     OH_AVCodecBufferAttr info;
1462     info.pts = 0;
1463     info.size = sizeof(annexBuffer_);
1464     OH_AVBuffer *buffer = OH_AVBuffer_Create(info.size);
1465     ASSERT_EQ(memcpy_s(OH_AVBuffer_GetAddr(buffer), info.size, annexBuffer_, sizeof(annexBuffer_)), 0);
1466 
1467     info.flags = AVCODEC_BUFFER_FLAGS_SYNC_FRAME;
1468     OH_AVBuffer_SetBufferAttr(buffer, &info);
1469     ret = avmuxer_->WriteSampleBuffer(trackId, buffer);
1470     ASSERT_EQ(ret, 0);
1471 
1472     info.flags = AVCODEC_BUFFER_FLAGS_NONE;
1473     OH_AVBuffer_SetBufferAttr(buffer, &info);
1474     ret = avmuxer_->WriteSampleBuffer(trackId, buffer);
1475     ASSERT_EQ(ret, 0);
1476 
1477     OH_AVBuffer_Destroy(buffer);
1478 }
1479 
1480 /**
1481  * @tc.name: Muxer_SetFlag_001
1482  * @tc.desc: Muxer Write Sample flags AVCODEC_BUFFER_FLAGS_DISPOSABLE
1483  * @tc.type: FUNC
1484  */
1485 HWTEST_F(AVMuxerUnitTest, Muxer_SetFlag_001, TestSize.Level0)
1486 {
1487     int32_t trackId = -1;
1488     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Disposable_flag.mp4");
1489     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1490 
1491     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1492     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1493     ASSERT_TRUE(isCreated);
1494 
1495     std::shared_ptr<FormatMock> videoParams =
1496         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
1497 
1498     int32_t ret = avmuxer_->AddTrack(trackId, videoParams);
1499     ASSERT_EQ(ret, 0);
1500     ASSERT_GE(trackId, 0);
1501     ASSERT_EQ(avmuxer_->Start(), 0);
1502 
1503     inputFile_ = std::make_shared<std::ifstream>(INPUT_FILE_PATH, std::ios::binary);
1504 
1505     int32_t extSize = 0;
1506     inputFile_->read(reinterpret_cast<char*>(&extSize), sizeof(extSize));
1507     if (extSize > 0) {
1508         std::vector<uint8_t> buffer(extSize);
1509         inputFile_->read(reinterpret_cast<char*>(buffer.data()), extSize);
1510     }
1511 
1512     bool eosFlag = false;
1513     uint32_t flag = AVCODEC_BUFFER_FLAGS_DISPOSABLE;
1514     ret = WriteSample(trackId, inputFile_, eosFlag, flag);
1515     while (!eosFlag && (ret == 0)) {
1516         ret = WriteSample(trackId, inputFile_, eosFlag, flag);
1517     }
1518     ASSERT_EQ(ret, 0);
1519 }
1520 
1521 /**
1522  * @tc.name: Muxer_SetFlag_001
1523  * @tc.desc: Muxer Write Sample flags AVCODEC_BUFFER_FLAGS_DISPOSABLE_EXT
1524  * @tc.type: FUNC
1525  */
1526 HWTEST_F(AVMuxerUnitTest, Muxer_SetFlag_002, TestSize.Level0)
1527 {
1528     int32_t trackId = -1;
1529     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_DisposableExt_flag.mp4");
1530     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1531 
1532     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1533     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1534     ASSERT_TRUE(isCreated);
1535 
1536     std::shared_ptr<FormatMock> videoParams =
1537         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
1538 
1539     int32_t ret = avmuxer_->AddTrack(trackId, videoParams);
1540     ASSERT_EQ(ret, 0);
1541     ASSERT_GE(trackId, 0);
1542     ASSERT_EQ(avmuxer_->Start(), 0);
1543 
1544     inputFile_ = std::make_shared<std::ifstream>(INPUT_FILE_PATH, std::ios::binary);
1545 
1546     int32_t extSize = 0;
1547     inputFile_->read(reinterpret_cast<char*>(&extSize), sizeof(extSize));
1548     if (extSize > 0) {
1549         std::vector<uint8_t> buffer(extSize);
1550         inputFile_->read(reinterpret_cast<char*>(buffer.data()), extSize);
1551     }
1552 
1553     bool eosFlag = false;
1554     uint32_t flag = AVCODEC_BUFFER_FLAGS_DISPOSABLE_EXT_TEST;
1555     ret = WriteSample(trackId, inputFile_, eosFlag, flag);
1556     while (!eosFlag && (ret == 0)) {
1557         ret = WriteSample(trackId, inputFile_, eosFlag, flag);
1558     }
1559     ASSERT_EQ(ret, 0);
1560 }
1561 
1562 /**
1563  * @tc.name: Muxer_SetFlag_001
1564  * @tc.desc: Muxer Write Sample flags AVCODEC_BUFFER_FLAGS_DISPOSABLE & AVCODEC_BUFFER_FLAGS_DISPOSABLE_EXT
1565  * @tc.type: FUNC
1566  */
1567 HWTEST_F(AVMuxerUnitTest, Muxer_SetFlag_003, TestSize.Level0)
1568 {
1569     int32_t trackId = -1;
1570     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Disposable_DisposableExt_flag.mp4");
1571     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1572 
1573     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1574     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1575     ASSERT_TRUE(isCreated);
1576 
1577     ASSERT_EQ(avmuxer_->SetRotation(180), 0); // 180 rotation
1578 
1579     std::shared_ptr<FormatMock> videoParams =
1580         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
1581 
1582     int32_t ret = avmuxer_->AddTrack(trackId, videoParams);
1583     ASSERT_EQ(ret, 0);
1584     ASSERT_GE(trackId, 0);
1585     ASSERT_EQ(avmuxer_->Start(), 0);
1586 
1587     inputFile_ = std::make_shared<std::ifstream>(INPUT_FILE_PATH, std::ios::binary);
1588 
1589     int32_t extSize = 0;
1590     inputFile_->read(reinterpret_cast<char*>(&extSize), sizeof(extSize));
1591     if (extSize > 0) {
1592         std::vector<uint8_t> buffer(extSize);
1593         inputFile_->read(reinterpret_cast<char*>(buffer.data()), extSize);
1594     }
1595 
1596     bool eosFlag = false;
1597     uint32_t flag = AVCODEC_BUFFER_FLAGS_DISPOSABLE;
1598     flag |= AVCODEC_BUFFER_FLAGS_DISPOSABLE_EXT_TEST;
1599     ret = WriteSample(trackId, inputFile_, eosFlag, flag);
1600     while (!eosFlag && (ret == 0)) {
1601         ret = WriteSample(trackId, inputFile_, eosFlag, flag);
1602     }
1603     ASSERT_EQ(ret, 0);
1604     ASSERT_EQ(avmuxer_->Stop(), 0);
1605 }
1606 
1607 /**
1608  * @tc.name: Muxer_WAV_001
1609  * @tc.desc: Muxer mux the wav by g711mu
1610  * @tc.type: FUNC
1611  */
1612 HWTEST_F(AVMuxerUnitTest, Muxer_WAV_001, TestSize.Level0)
1613 {
1614     int32_t trackId = -1;
1615     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_G711MU_44100_2.wav");
1616     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_WAV;
1617 
1618     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1619     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1620     ASSERT_TRUE(isCreated);
1621 
1622     std::shared_ptr<FormatMock> audioParams = FormatMockFactory::CreateFormat();
1623     audioParams->PutStringValue(OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
1624     audioParams->PutIntValue(OH_MD_KEY_AUD_SAMPLE_RATE, 44100); // 44100 sample rate
1625     audioParams->PutIntValue(OH_MD_KEY_AUD_CHANNEL_COUNT, 2); // 2 channels
1626     audioParams->PutIntValue(OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_U8);
1627     audioParams->PutLongValue(OH_MD_KEY_BITRATE, 705600); // 705600 bit rate
1628     audioParams->PutIntValue("audio_samples_per_frame", 2048); // 2048 frame size
1629     int32_t ret = avmuxer_->AddTrack(trackId, audioParams);
1630     ASSERT_EQ(ret, 0);
1631     ASSERT_GE(trackId, 0);
1632     ASSERT_EQ(avmuxer_->Start(), 0);
1633 
1634     inputFile_ = std::make_shared<std::ifstream>("/data/test/media/g711mu_44100_2.dat", std::ios::binary);
1635 
1636     int32_t extSize = 0;
1637     inputFile_->read(reinterpret_cast<char*>(&extSize), sizeof(extSize));
1638     if (extSize > 0) {
1639         std::vector<uint8_t> buffer(extSize);
1640         inputFile_->read(reinterpret_cast<char*>(buffer.data()), extSize);
1641     }
1642 
1643     bool eosFlag = false;
1644     uint32_t flag = AVCODEC_BUFFER_FLAGS_SYNC_FRAME;
1645     ret = WriteSample(trackId, inputFile_, eosFlag, flag);
1646     while (!eosFlag && (ret == 0)) {
1647         ret = WriteSample(trackId, inputFile_, eosFlag, flag);
1648     }
1649     ASSERT_EQ(ret, 0);
1650     ASSERT_EQ(avmuxer_->Stop(), 0);
1651 }
1652 
1653 /**
1654  * @tc.name: Muxer_WAV_002
1655  * @tc.desc: Muxer mux the wav by pcm
1656  * @tc.type: FUNC
1657  */
1658 HWTEST_F(AVMuxerUnitTest, Muxer_WAV_002, TestSize.Level0)
1659 {
1660     int32_t trackId = -1;
1661     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_PCM_44100_2_S16LE.wav");
1662     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_WAV;
1663 
1664     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1665     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1666     ASSERT_TRUE(isCreated);
1667 
1668     std::shared_ptr<FormatMock> audioParams = FormatMockFactory::CreateFormat();
1669     audioParams->PutStringValue(OH_MD_KEY_CODEC_MIME, "audio/raw");
1670     audioParams->PutIntValue(OH_MD_KEY_AUD_SAMPLE_RATE, 44100); // 44100 sample rate
1671     audioParams->PutIntValue(OH_MD_KEY_AUD_CHANNEL_COUNT, 2); // 2 channels
1672     audioParams->PutIntValue(OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16LE);
1673     audioParams->PutLongValue(OH_MD_KEY_BITRATE, 1411200); // 1411200 bit rate
1674     audioParams->PutIntValue("audio_samples_per_frame", 1024); // 1024 frame size
1675     audioParams->PutLongValue(OH_MD_KEY_CHANNEL_LAYOUT, CH_LAYOUT_STEREO);
1676     int32_t ret = avmuxer_->AddTrack(trackId, audioParams);
1677     ASSERT_EQ(ret, 0);
1678     ASSERT_GE(trackId, 0);
1679     ASSERT_EQ(avmuxer_->Start(), 0);
1680 
1681     inputFile_ = std::make_shared<std::ifstream>("/data/test/media/pcm_44100_2_s16le.dat", std::ios::binary);
1682 
1683     int32_t extSize = 0;
1684     inputFile_->read(reinterpret_cast<char*>(&extSize), sizeof(extSize));
1685     if (extSize > 0) {
1686         std::vector<uint8_t> buffer(extSize);
1687         inputFile_->read(reinterpret_cast<char*>(buffer.data()), extSize);
1688     }
1689 
1690     bool eosFlag = false;
1691     uint32_t flag = AVCODEC_BUFFER_FLAGS_SYNC_FRAME;
1692     ret = WriteSample(trackId, inputFile_, eosFlag, flag);
1693     while (!eosFlag && (ret == 0)) {
1694         ret = WriteSample(trackId, inputFile_, eosFlag, flag);
1695     }
1696     ASSERT_EQ(ret, 0);
1697     ASSERT_EQ(avmuxer_->Stop(), 0);
1698 }
1699 
1700 /**
1701  * @tc.name: Muxer_WAV_003
1702  * @tc.desc: Muxer mux the wav by pcm, test OH_MD_KEY_AUDIO_SAMPLE_FORMAT
1703  * @tc.type: FUNC
1704  */
1705 HWTEST_F(AVMuxerUnitTest, Muxer_WAV_003, TestSize.Level0)
1706 {
1707     int32_t trackId = -1;
1708     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_PCM_44100_2_XXX.wav");
1709     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_WAV;
1710 
1711     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1712     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1713     ASSERT_TRUE(isCreated);
1714 
1715     std::shared_ptr<FormatMock> audioParams = FormatMockFactory::CreateFormat();
1716     audioParams->PutStringValue(OH_MD_KEY_CODEC_MIME, "audio/raw");
1717     audioParams->PutIntValue(OH_MD_KEY_AUD_SAMPLE_RATE, 44100); // 44100 sample rate
1718     audioParams->PutIntValue(OH_MD_KEY_AUD_CHANNEL_COUNT, 2); // 2 channels
1719     audioParams->PutIntValue(OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_U8P);
1720     audioParams->PutLongValue(OH_MD_KEY_BITRATE, 705600); // 705600 bit rate
1721     audioParams->PutIntValue("audio_samples_per_frame", 1024); // 1024 frame size
1722     audioParams->PutLongValue(OH_MD_KEY_CHANNEL_LAYOUT, CH_LAYOUT_STEREO);
1723     ASSERT_NE(avmuxer_->AddTrack(trackId, audioParams), 0);
1724     audioParams->PutIntValue(OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16P);
1725     ASSERT_NE(avmuxer_->AddTrack(trackId, audioParams), 0);
1726     audioParams->PutIntValue(OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S24P);
1727     ASSERT_NE(avmuxer_->AddTrack(trackId, audioParams), 0);
1728     audioParams->PutIntValue(OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S32P);
1729     ASSERT_NE(avmuxer_->AddTrack(trackId, audioParams), 0);
1730     audioParams->PutIntValue(OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_F32P);
1731     ASSERT_NE(avmuxer_->AddTrack(trackId, audioParams), 0);
1732 }
1733 
1734 /**
1735  * @tc.name: Muxer_WAV_004
1736  * @tc.desc: Muxer mux the wav by pcm, test OH_MD_KEY_CHANNEL_LAYOUT
1737  * @tc.type: FUNC
1738  */
1739 HWTEST_F(AVMuxerUnitTest, Muxer_WAV_004, TestSize.Level0)
1740 {
1741     int32_t trackId = -1;
1742     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_PCM_44100_2_XXX.wav");
1743     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_WAV;
1744 
1745     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1746     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1747     ASSERT_TRUE(isCreated);
1748 
1749     std::shared_ptr<FormatMock> audioParams = FormatMockFactory::CreateFormat();
1750     audioParams->PutStringValue(OH_MD_KEY_CODEC_MIME, "audio/raw");
1751     audioParams->PutIntValue(OH_MD_KEY_AUD_SAMPLE_RATE, 44100); // 44100 sample rate
1752     audioParams->PutIntValue(OH_MD_KEY_AUD_CHANNEL_COUNT, 2); // 2 channels
1753     audioParams->PutIntValue(OH_MD_KEY_AUDIO_SAMPLE_FORMAT, SAMPLE_S16LE);
1754     audioParams->PutLongValue(OH_MD_KEY_BITRATE, 1411200); // 1411200 bit rate
1755     audioParams->PutIntValue("audio_samples_per_frame", 1024); // 1024 frame size
1756     audioParams->PutLongValue(OH_MD_KEY_CHANNEL_LAYOUT, CH_LAYOUT_2POINT0POINT2);
1757     ASSERT_NE(avmuxer_->AddTrack(trackId, audioParams), 0);
1758     audioParams->PutLongValue(OH_MD_KEY_CHANNEL_LAYOUT, CH_LAYOUT_AMB_ORDER1_ACN_N3D);
1759     ASSERT_NE(avmuxer_->AddTrack(trackId, audioParams), 0);
1760     audioParams->PutLongValue(OH_MD_KEY_CHANNEL_LAYOUT, CH_LAYOUT_AMB_ORDER1_FUMA);
1761     ASSERT_NE(avmuxer_->AddTrack(trackId, audioParams), 0);
1762 }
1763 #ifdef AVMUXER_UNITTEST_CAPI
1764 /**
1765  * @tc.name: Muxer_Destroy_001
1766  * @tc.desc: Muxer Destroy normal
1767  * @tc.type: FUNC
1768  */
1769 HWTEST_F(AVMuxerUnitTest, Muxer_Destroy_001, TestSize.Level0)
1770 {
1771     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Destroy.mp4");
1772     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1773     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1774     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1775     ASSERT_TRUE(isCreated);
1776 
1777     std::shared_ptr<FormatMock> videoParams =
1778         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
1779     videoParams->PutBuffer(OH_MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
1780     int32_t videoTrackId = -1;
1781     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
1782     ASSERT_EQ(ret, AV_ERR_OK);
1783     ASSERT_GE(videoTrackId, 0);
1784     ASSERT_EQ(avmuxer_->Start(), 0);
1785     ASSERT_EQ(avmuxer_->Stop(), 0);
1786     ASSERT_EQ(avmuxer_->Destroy(), 0);
1787 }
1788 
1789 /**
1790  * @tc.name: Muxer_Destroy_002
1791  * @tc.desc: Muxer Destroy normal
1792  * @tc.type: FUNC
1793  */
1794 HWTEST_F(AVMuxerUnitTest, Muxer_Destroy_002, TestSize.Level0)
1795 {
1796     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Destroy.mp4");
1797     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1798     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1799     OH_AVMuxer *muxer = OH_AVMuxer_Create(fd_, outputFormat);
1800     int32_t ret = OH_AVMuxer_Destroy(muxer);
1801     ASSERT_EQ(ret, 0);
1802     muxer = nullptr;
1803 }
1804 
1805 /**
1806  * @tc.name: Muxer_Destroy_003
1807  * @tc.desc: Muxer Destroy nullptr
1808  * @tc.type: FUNC
1809  */
1810 HWTEST_F(AVMuxerUnitTest, Muxer_Destroy_003, TestSize.Level0)
1811 {
1812     int32_t ret = OH_AVMuxer_Destroy(nullptr);
1813     ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
1814 }
1815 
1816 /**
1817  * @tc.name: Muxer_Destroy_004
1818  * @tc.desc: Muxer Destroy other class
1819  * @tc.type: FUNC
1820  */
1821 HWTEST_F(AVMuxerUnitTest, Muxer_Destroy_004, TestSize.Level0)
1822 {
1823     OH_AVFormat *format = OH_AVFormat_Create();
1824     int32_t ret = OH_AVMuxer_Destroy(reinterpret_cast<OH_AVMuxer*>(format));
1825     ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
1826     OH_AVFormat_Destroy(format);
1827 }
1828 #endif // AVMUXER_UNITTEST_CAPI
1829 
1830 #ifdef AVMUXER_UNITTEST_INNER_API
1831 /**
1832  * @tc.name: Muxer_SetParameter_001
1833  * @tc.desc: Muxer SetParameter after Create
1834  * @tc.type: FUNC
1835  */
1836 HWTEST_F(AVMuxerUnitTest, Muxer_SetParameter_001, TestSize.Level0)
1837 {
1838     int32_t trackId = -1;
1839     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetParameter.mp4");
1840     Plugins::OutputFormat outputFormat = Plugins::OutputFormat::MPEG_4;
1841 
1842     int32_t fd = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1843     std::shared_ptr<AVMuxer> avmuxer = AVMuxerFactory::CreateAVMuxer(fd, outputFormat);
1844     ASSERT_NE(avmuxer, nullptr);
1845 
1846     std::shared_ptr<Meta> videoParams = std::make_shared<Meta>();
1847     videoParams->Set<Tag::MIME_TYPE>(Plugins::MimeType::VIDEO_AVC);
1848     videoParams->Set<Tag::VIDEO_WIDTH>(TEST_WIDTH);
1849     videoParams->Set<Tag::VIDEO_HEIGHT>(TEST_HEIGHT);
1850 
1851     int32_t ret = avmuxer->AddTrack(trackId, videoParams);
1852     ASSERT_EQ(ret, 0);
1853     ASSERT_GE(trackId, 0);
1854 
1855     std::shared_ptr<Meta> param = std::make_shared<Meta>();
1856     param->Set<Tag::VIDEO_ROTATION>(Plugins::VideoRotation::VIDEO_ROTATION_0);
1857     param->Set<Tag::MEDIA_CREATION_TIME>("2023-12-19T03:16:00.000Z");
1858     param->Set<Tag::MEDIA_LATITUDE>(22.67f); // 22.67f test latitude
1859     param->Set<Tag::MEDIA_LONGITUDE>(114.06f); // 114.06f test longitude
1860     param->Set<Tag::MEDIA_TITLE>("ohos muxer");
1861     param->Set<Tag::MEDIA_ARTIST>("ohos muxer");
1862     param->Set<Tag::MEDIA_COMPOSER>("ohos muxer");
1863     param->Set<Tag::MEDIA_DATE>("2023-12-19");
1864     param->Set<Tag::MEDIA_ALBUM>("ohos muxer");
1865     param->Set<Tag::MEDIA_ALBUM_ARTIST>("ohos muxer");
1866     param->Set<Tag::MEDIA_COPYRIGHT>("ohos muxer");
1867     param->Set<Tag::MEDIA_GENRE>("{marketing-name:\"HW P60\"}");
1868     ret = avmuxer->SetParameter(param);
1869     EXPECT_EQ(ret, 0);
1870 
1871     close(fd);
1872 }
1873 
1874 /**
1875  * @tc.name: Muxer_SetParameter_002
1876  * @tc.desc: Muxer SetParameter after Create
1877  * @tc.type: FUNC
1878  */
1879 HWTEST_F(AVMuxerUnitTest, Muxer_SetParameter_002, TestSize.Level0)
1880 {
1881     int32_t trackId = -1;
1882     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetParameter.mp4");
1883     Plugins::OutputFormat outputFormat = Plugins::OutputFormat::MPEG_4;
1884 
1885     int32_t fd = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1886     std::shared_ptr<AVMuxer> avmuxer = AVMuxerFactory::CreateAVMuxer(fd, outputFormat);
1887     ASSERT_NE(avmuxer, nullptr);
1888 
1889     std::shared_ptr<Meta> videoParams = std::make_shared<Meta>();
1890     videoParams->Set<Tag::MIME_TYPE>(Plugins::MimeType::VIDEO_AVC);
1891     videoParams->Set<Tag::VIDEO_WIDTH>(TEST_WIDTH);
1892     videoParams->Set<Tag::VIDEO_HEIGHT>(TEST_HEIGHT);
1893 
1894     int32_t ret = avmuxer->AddTrack(trackId, videoParams);
1895     ASSERT_EQ(ret, 0);
1896     ASSERT_GE(trackId, 0);
1897 
1898     std::shared_ptr<Meta> param = std::make_shared<Meta>();
1899     param->Set<Tag::MEDIA_LONGITUDE>(114.06f); // 114.06f test longitude
1900     ret = avmuxer->SetParameter(param);
1901     EXPECT_NE(ret, 0);
1902 
1903     param->Set<Tag::MEDIA_LATITUDE>(-90.0f); // -90.0f test latitude
1904     ret = avmuxer->SetParameter(param);
1905     EXPECT_EQ(ret, 0);
1906 
1907     param->Set<Tag::MEDIA_LATITUDE>(90.0f); // 90.0f test latitude
1908     ret = avmuxer->SetParameter(param);
1909     EXPECT_EQ(ret, 0);
1910 
1911     param->Set<Tag::MEDIA_LATITUDE>(-90.1f); // -90.1f test latitude
1912     ret = avmuxer->SetParameter(param);
1913     EXPECT_NE(ret, 0);
1914 
1915     param->Set<Tag::MEDIA_LATITUDE>(90.1f); // 90.1f test latitude
1916     ret = avmuxer->SetParameter(param);
1917     EXPECT_NE(ret, 0);
1918 
1919     close(fd);
1920 }
1921 
1922 /**
1923  * @tc.name: Muxer_SetParameter_003
1924  * @tc.desc: Muxer SetParameter after Create
1925  * @tc.type: FUNC
1926  */
1927 HWTEST_F(AVMuxerUnitTest, Muxer_SetParameter_003, TestSize.Level0)
1928 {
1929     int32_t trackId = -1;
1930     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetParameter.mp4");
1931     Plugins::OutputFormat outputFormat = Plugins::OutputFormat::MPEG_4;
1932 
1933     int32_t fd = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1934     std::shared_ptr<AVMuxer> avmuxer = AVMuxerFactory::CreateAVMuxer(fd, outputFormat);
1935     ASSERT_NE(avmuxer, nullptr);
1936 
1937     std::shared_ptr<Meta> videoParams = std::make_shared<Meta>();
1938     videoParams->Set<Tag::MIME_TYPE>(Plugins::MimeType::VIDEO_AVC);
1939     videoParams->Set<Tag::VIDEO_WIDTH>(TEST_WIDTH);
1940     videoParams->Set<Tag::VIDEO_HEIGHT>(TEST_HEIGHT);
1941 
1942     int32_t ret = avmuxer->AddTrack(trackId, videoParams);
1943     ASSERT_EQ(ret, 0);
1944     ASSERT_GE(trackId, 0);
1945 
1946     std::shared_ptr<Meta> param = std::make_shared<Meta>();
1947     param->Set<Tag::MEDIA_LATITUDE>(22.67f); // 22.67f test latitude
1948     ret = avmuxer->SetParameter(param);
1949     EXPECT_NE(ret, 0);
1950 
1951     param->Set<Tag::MEDIA_LONGITUDE>(-180.0f); // -180.0f test longitude
1952     ret = avmuxer->SetParameter(param);
1953     EXPECT_EQ(ret, 0);
1954 
1955     param->Set<Tag::MEDIA_LONGITUDE>(180.0f); // 180.0f test longitude
1956     ret = avmuxer->SetParameter(param);
1957     EXPECT_EQ(ret, 0);
1958 
1959     param->Set<Tag::MEDIA_LONGITUDE>(-180.1f); // -180.1f test longitude
1960     ret = avmuxer->SetParameter(param);
1961     EXPECT_NE(ret, 0);
1962 
1963     param->Set<Tag::MEDIA_LONGITUDE>(180.1f); // 180.1f test longitude
1964     ret = avmuxer->SetParameter(param);
1965     EXPECT_NE(ret, 0);
1966 
1967     close(fd);
1968 }
1969 
1970 /**
1971  * @tc.name: Muxer_SetUserMeta_001
1972  * @tc.desc: Muxer SetUserMeta after Create
1973  * @tc.type: FUNC
1974  */
1975 HWTEST_F(AVMuxerUnitTest, Muxer_SetUserMeta_001, TestSize.Level0)
1976 {
1977     int32_t trackId = -1;
1978     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetUserMeta.mp4");
1979     Plugins::OutputFormat outputFormat = Plugins::OutputFormat::MPEG_4;
1980 
1981     int32_t fd = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1982     std::shared_ptr<AVMuxer> avmuxer = AVMuxerFactory::CreateAVMuxer(fd, outputFormat);
1983     ASSERT_NE(avmuxer, nullptr);
1984 
1985     std::shared_ptr<Meta> videoParams = std::make_shared<Meta>();
1986     videoParams->Set<Tag::MIME_TYPE>(Plugins::MimeType::VIDEO_AVC);
1987     videoParams->Set<Tag::VIDEO_WIDTH>(TEST_WIDTH);
1988     videoParams->Set<Tag::VIDEO_HEIGHT>(TEST_HEIGHT);
1989 
1990     int32_t ret = avmuxer->AddTrack(trackId, videoParams);
1991     ASSERT_EQ(ret, 0);
1992     ASSERT_GE(trackId, 0);
1993 
1994     std::shared_ptr<Meta> param = std::make_shared<Meta>();
1995     param->Set<Tag::VIDEO_ROTATION>(Plugins::VideoRotation::VIDEO_ROTATION_0);
1996     param->Set<Tag::MEDIA_CREATION_TIME>("2023-12-19T03:16:00.000Z");
1997     param->Set<Tag::MEDIA_LATITUDE>(22.67f); // 22.67f test latitude
1998     param->Set<Tag::MEDIA_LONGITUDE>(114.06f); // 114.06f test longitude
1999     param->Set<Tag::MEDIA_TITLE>("ohos muxer");
2000     param->Set<Tag::MEDIA_ARTIST>("ohos muxer");
2001     param->Set<Tag::MEDIA_COMPOSER>("ohos muxer");
2002     param->Set<Tag::MEDIA_DATE>("2023-12-19");
2003     param->Set<Tag::MEDIA_ALBUM>("ohos muxer");
2004     param->Set<Tag::MEDIA_ALBUM_ARTIST>("ohos muxer");
2005     param->Set<Tag::MEDIA_COPYRIGHT>("ohos muxer");
2006     param->Set<Tag::MEDIA_GENRE>("{marketing-name:\"HW P60\"}");
2007     param->SetData("fast_start", static_cast<int32_t>(1)); // 1 moov 前置
2008     ret = avmuxer->SetParameter(param);
2009     EXPECT_EQ(ret, 0);
2010 
2011     std::shared_ptr<Meta> userMeta = std::make_shared<Meta>();
2012     userMeta->SetData("com.openharmony.version", 5); // 5 test version
2013     userMeta->SetData("com.openharmony.model", "LNA-AL00");
2014     userMeta->SetData("com.openharmony.manufacturer", "HW");
2015     userMeta->SetData("com.openharmony.marketing_name", "HW P60");
2016     userMeta->SetData("com.openharmony.capture.fps", 30.00f); // 30.00f test capture fps
2017     userMeta->SetData("model", "LNA-AL00");
2018     userMeta->SetData("com.openharmony.flag", true);
2019     ret = avmuxer->SetUserMeta(userMeta);
2020     EXPECT_EQ(ret, 0);
2021 
2022     close(fd);
2023 }
2024 
2025 /**
2026  * @tc.name: Muxer_SetFlag_004
2027  * @tc.desc: Muxer Write Sample for timed metadata track
2028  * @tc.type: FUNC
2029  */
2030 HWTEST_F(AVMuxerUnitTest, Muxer_SetFlag_004, TestSize.Level0)
2031 {
2032     int32_t vidTrackId = -1;
2033     int32_t metaTrackId = -1;
2034     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Timedmetadata_track.mp4");
2035     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
2036 
2037     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
2038     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
2039     ASSERT_TRUE(isCreated);
2040 
2041     std::shared_ptr<FormatMock> videoParams =
2042         FormatMockFactory::CreateVideoFormat(OH_AVCODEC_MIMETYPE_VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
2043 
2044     ASSERT_EQ(avmuxer_->AddTrack(vidTrackId, videoParams), 0);
2045     ASSERT_GE(vidTrackId, 0);
2046 
2047     std::shared_ptr<FormatMock> metadataParams = FormatMockFactory::CreateTimedMetadataFormat(
2048         TIMED_METADATA_TRACK_MIMETYPE.c_str(), TIMED_METADATA_KEY, vidTrackId);
2049     ASSERT_NE(metadataParams, nullptr);
2050 
2051     ASSERT_EQ(avmuxer_->AddTrack(metaTrackId, metadataParams), 0);
2052     ASSERT_GE(metaTrackId, 1);
2053 
2054     int32_t ret = avmuxer_->SetTimedMetadata();
2055     EXPECT_EQ(ret, 0);
2056 
2057     ASSERT_EQ(avmuxer_->Start(), 0);
2058 
2059     inputFile_ = std::make_shared<std::ifstream>(INPUT_FILE_PATH, std::ios::binary);
2060 
2061     int32_t extSize = 0;
2062     inputFile_->read(reinterpret_cast<char*>(&extSize), sizeof(extSize));
2063     if (extSize > 0) {
2064         std::vector<uint8_t> buffer(extSize);
2065         inputFile_->read(reinterpret_cast<char*>(buffer.data()), extSize);
2066     }
2067 
2068     bool eosFlag = false;
2069     uint32_t flag = AVCODEC_BUFFER_FLAGS_DISPOSABLE_EXT_TEST;
2070     ret = WriteSample(vidTrackId, inputFile_, eosFlag, flag);
2071     while (!eosFlag && (ret == 0)) {
2072         ret = WriteSample(vidTrackId, inputFile_, eosFlag, flag);
2073     }
2074     ASSERT_EQ(ret, 0);
2075 
2076     auto inputFileMeta = std::make_shared<std::ifstream>(INPUT_FILE_PATH, std::ios::binary);
2077     extSize = 0;
2078     inputFileMeta->read(reinterpret_cast<char*>(&extSize), sizeof(extSize));
2079     if (extSize > 0) {
2080         std::vector<uint8_t> buffer(extSize);
2081         inputFileMeta->read(reinterpret_cast<char*>(buffer.data()), extSize);
2082     }
2083     eosFlag = false;
2084     flag = AVCODEC_BUFFER_FLAGS_DISPOSABLE_EXT_TEST;
2085     ret = WriteSample(metaTrackId, inputFileMeta, eosFlag, flag);
2086     while (!eosFlag && (ret == 0)) {
2087         ret = WriteSample(metaTrackId, inputFileMeta, eosFlag, flag);
2088     }
2089     ASSERT_EQ(ret, 0);
2090     ASSERT_EQ(avmuxer_->Stop(), 0);
2091 }
2092 
2093 /**
2094  * @tc.name: Muxer_MP4_001
2095  * @tc.desc: Muxer mux mp4 by h264
2096  * @tc.type: FUNC
2097  */
2098 HWTEST_F(AVMuxerUnitTest, Muxer_MP4_001, TestSize.Level0)
2099 {
2100     int32_t trackId = -1;
2101     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_AVC.mp4");
2102     Plugins::OutputFormat outputFormat = Plugins::OutputFormat::MPEG_4;
2103     int32_t fd = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
2104     std::shared_ptr<AVMuxer> avmuxer = AVMuxerFactory::CreateAVMuxer(fd, outputFormat);
2105     ASSERT_NE(avmuxer, nullptr);
2106 
2107     std::shared_ptr<Meta> videoParams = std::make_shared<Meta>();
2108     videoParams->Set<Tag::MIME_TYPE>(Plugins::MimeType::VIDEO_AVC);
2109     videoParams->Set<Tag::VIDEO_WIDTH>(TEST_WIDTH);
2110     videoParams->Set<Tag::VIDEO_HEIGHT>(TEST_HEIGHT);
2111     videoParams->Set<Tag::VIDEO_FRAME_RATE>(60.0); // 60.0 fps
2112     videoParams->Set<Tag::VIDEO_DELAY>(0);
2113     ASSERT_EQ(avmuxer->AddTrack(trackId, videoParams), 0);
2114     ASSERT_GE(trackId, 0);
2115 
2116     std::shared_ptr<Meta> param = std::make_shared<Meta>();
2117     param->Set<Tag::VIDEO_ROTATION>(Plugins::VideoRotation::VIDEO_ROTATION_90);
2118     param->Set<Tag::MEDIA_CREATION_TIME>("2023-12-19T03:16:00.000Z");
2119     param->Set<Tag::MEDIA_LATITUDE>(22.67f); // 22.67f test latitude
2120     param->Set<Tag::MEDIA_LONGITUDE>(114.06f); // 114.06f test longitude
2121     param->SetData("fast_start", static_cast<int32_t>(1)); // 1 moov 前置
2122     EXPECT_EQ(avmuxer->SetParameter(param), 0);
2123     OHOS::sptr<AVBufferQueueProducer> bqProducer= avmuxer->GetInputBufferQueue(trackId);
2124     ASSERT_NE(bqProducer, nullptr);
2125 
2126     ASSERT_EQ(avmuxer->Start(), 0);
2127     std::shared_ptr<Meta> userMeta = std::make_shared<Meta>();
2128     userMeta->SetData("com.openharmony.version", 5); // 5 test version
2129     userMeta->SetData("com.openharmony.model", "LNA-AL00");
2130     userMeta->SetData("com.openharmony.capture.fps", 30.00f); // 30.00f test capture fps
2131     EXPECT_EQ(avmuxer->SetUserMeta(userMeta), 0);
2132 
2133     inputFile_ = std::make_shared<std::ifstream>(INPUT_FILE_PATH, std::ios::binary);
2134     int32_t extSize = 0;
2135     inputFile_->read(reinterpret_cast<char*>(&extSize), sizeof(extSize));
2136     if (extSize > 0) {
2137         std::vector<uint8_t> buffer(extSize);
2138         inputFile_->read(reinterpret_cast<char*>(buffer.data()), extSize);
2139     }
2140     bool eosFlag = false;
2141     int32_t ret = 0;
2142     do {
2143         ret = WriteSample(bqProducer, inputFile_, eosFlag);
2144     } while (!eosFlag && (ret == 0));
2145     ASSERT_EQ(ret, 0);
2146     ASSERT_EQ(avmuxer->Stop(), 0);
2147     close(fd);
2148 }
2149 #endif
2150 } // namespace