• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 #include <string>
18 #include <vector>
19 #include <fcntl.h>
20 #include "avmuxer.h"
21 #include "avcodec_info.h"
22 #include "avmuxer_unit_test.h"
23 #ifdef AVMUXER_UNITTEST_CAPI
24 #include "native_avmuxer.h"
25 #include "native_avformat.h"
26 #endif
27 #include <policycoreutils.h>
28 
29 using namespace testing::ext;
30 using namespace OHOS::MediaAVCodec;
31 namespace {
32 constexpr int32_t TEST_CHANNEL_COUNT = 2;
33 constexpr int32_t TEST_SAMPLE_RATE = 2;
34 constexpr int32_t TEST_WIDTH = 720;
35 constexpr int32_t TEST_HEIGHT = 480;
36 constexpr int32_t TEST_ROTATION = 90;
37 constexpr int32_t INVALID_FORMAT = -99;
38 const std::string TEST_FILE_PATH = "/data/test/media/";
39 } // namespace
40 
SetUpTestCase()41 void AVMuxerUnitTest::SetUpTestCase() {}
42 
TearDownTestCase()43 void AVMuxerUnitTest::TearDownTestCase() {}
44 
SetUp()45 void AVMuxerUnitTest::SetUp()
46 {
47     avmuxer_ = std::make_shared<AVMuxerSample>();
48     Restorecon(TEST_FILE_PATH.c_str());
49 }
50 
TearDown()51 void AVMuxerUnitTest::TearDown()
52 {
53     if (fd_ >= 0) {
54         close(fd_);
55         fd_ = -1;
56     }
57 
58     if (avmuxer_ != nullptr) {
59         avmuxer_->Destroy();
60         avmuxer_ = nullptr;
61     }
62 }
63 
64 /**
65  * @tc.name: Muxer_Create_001
66  * @tc.desc: Muxer Create
67  * @tc.type: FUNC
68  */
69 HWTEST_F(AVMuxerUnitTest, Muxer_Create_001, TestSize.Level0)
70 {
71     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Create.mp4");
72     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
73     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
74     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
75     ASSERT_TRUE(isCreated);
76 }
77 
78 /**
79  * @tc.name: Muxer_Create_002
80  * @tc.desc: Muxer Create write only
81  * @tc.type: FUNC
82  */
83 HWTEST_F(AVMuxerUnitTest, Muxer_Create_002, TestSize.Level0)
84 {
85     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Create.mp4");
86     fd_ = open(outputFile.c_str(), O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
87     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
88     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
89     ASSERT_FALSE(isCreated);
90 }
91 
92 /**
93  * @tc.name: Muxer_Create_003
94  * @tc.desc: Muxer Create read only
95  * @tc.type: FUNC
96  */
97 HWTEST_F(AVMuxerUnitTest, Muxer_Create_003, TestSize.Level0)
98 {
99     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Create.mp4");
100     fd_ = open(outputFile.c_str(), O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR);
101     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
102     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
103     ASSERT_FALSE(isCreated);
104 }
105 
106 /**
107  * @tc.name: Muxer_Create_004
108  * @tc.desc: Muxer Create rand fd
109  * @tc.type: FUNC
110  */
111 HWTEST_F(AVMuxerUnitTest, Muxer_Create_004, TestSize.Level0)
112 {
113     constexpr int32_t invalidFd = 999999;
114     constexpr int32_t negativeFd = -999;
115     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
116     bool isCreated = avmuxer_->CreateMuxer(invalidFd, outputFormat);
117     ASSERT_FALSE(isCreated);
118 
119     avmuxer_->Destroy();
120     isCreated = avmuxer_->CreateMuxer(0xfffffff, outputFormat);
121     ASSERT_FALSE(isCreated);
122 
123     avmuxer_->Destroy();
124     isCreated = avmuxer_->CreateMuxer(-1, outputFormat);
125     ASSERT_FALSE(isCreated);
126 
127     avmuxer_->Destroy();
128     isCreated = avmuxer_->CreateMuxer(negativeFd, outputFormat);
129     ASSERT_FALSE(isCreated);
130 }
131 
132 /**
133  * @tc.name: Muxer_Create_005
134  * @tc.desc: Muxer Create different outputFormat
135  * @tc.type: FUNC
136  */
137 HWTEST_F(AVMuxerUnitTest, Muxer_Create_005, TestSize.Level0)
138 {
139     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Create.mp4");
140     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
141 
142     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
143     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
144     ASSERT_TRUE(isCreated);
145 
146     avmuxer_->Destroy();
147     outputFormat = OUTPUT_FORMAT_M4A;
148     isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
149     ASSERT_TRUE(isCreated);
150 
151     avmuxer_->Destroy();
152     outputFormat = OUTPUT_FORMAT_DEFAULT;
153     isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
154     ASSERT_TRUE(isCreated);
155 
156     avmuxer_->Destroy();
157     isCreated = avmuxer_->CreateMuxer(fd_, static_cast<OutputFormat>(INVALID_FORMAT));
158     ASSERT_FALSE(isCreated);
159 }
160 
161 /**
162  * @tc.name: Muxer_AddTrack_001
163  * @tc.desc: Muxer AddTrack add audio track
164  * @tc.type: FUNC
165  */
166 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_001, TestSize.Level0)
167 {
168     int32_t audioTrackId = -1;
169     int32_t ret = 0;
170     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_AddTrack.mp4");
171     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
172     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
173     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
174     ASSERT_TRUE(isCreated);
175 
176     std::shared_ptr<FormatMock> audioParams = FormatMockFactory::CreateFormat();
177     audioParams->PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_MPEG);
178     audioParams->PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, TEST_SAMPLE_RATE);
179     audioParams->PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, TEST_CHANNEL_COUNT);
180     ret = avmuxer_->AddTrack(audioTrackId, audioParams);
181     EXPECT_EQ(ret, AV_ERR_OK);
182     EXPECT_GE(audioTrackId, 0);
183 
184     audioParams = FormatMockFactory::CreateFormat();
185     audioParams->PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, TEST_SAMPLE_RATE);
186     audioParams->PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, TEST_CHANNEL_COUNT);
187     ret = avmuxer_->AddTrack(audioTrackId, audioParams);
188     EXPECT_NE(ret, AV_ERR_OK);
189 
190     audioParams = FormatMockFactory::CreateFormat();
191     audioParams->PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_MPEG);
192     audioParams->PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, TEST_CHANNEL_COUNT);
193     ret = avmuxer_->AddTrack(audioTrackId, audioParams);
194     EXPECT_NE(ret, AV_ERR_OK);
195 
196     audioParams = FormatMockFactory::CreateFormat();
197     audioParams->PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_MPEG);
198     audioParams->PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, TEST_SAMPLE_RATE);
199     ret = avmuxer_->AddTrack(audioTrackId, audioParams);
200     EXPECT_NE(ret, AV_ERR_OK);
201 }
202 
203 /**
204  * @tc.name: Muxer_AddTrack_002
205  * @tc.desc: Muxer AddTrack add video track
206  * @tc.type: FUNC
207  */
208 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_002, TestSize.Level0)
209 {
210     int32_t videoTrackId = -1;
211     int32_t ret = AV_ERR_INVALID_VAL;
212     std::string outputFile = TEST_FILE_PATH + std::string("avmuxer_AddTrack_002.mp4");
213     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
214     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
215     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
216     ASSERT_TRUE(isCreated);
217 
218     std::shared_ptr<FormatMock> videoParams = FormatMockFactory::CreateFormat();
219     videoParams->PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_MPEG4);
220     videoParams->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, TEST_WIDTH);
221     videoParams->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, TEST_HEIGHT);
222     ret = avmuxer_->AddTrack(videoTrackId, videoParams);
223     EXPECT_EQ(ret, AV_ERR_OK);
224     EXPECT_GE(videoTrackId, 0);
225 
226     videoParams = FormatMockFactory::CreateFormat();
227     videoParams->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, TEST_WIDTH);
228     videoParams->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, TEST_HEIGHT);
229     ret = avmuxer_->AddTrack(videoTrackId, videoParams);
230     EXPECT_NE(ret, AV_ERR_OK);
231 
232     videoParams = FormatMockFactory::CreateFormat();
233     videoParams->PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_MPEG4);
234     videoParams->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, TEST_HEIGHT);
235     ret = avmuxer_->AddTrack(videoTrackId, videoParams);
236     EXPECT_NE(ret, AV_ERR_OK);
237 
238     videoParams = FormatMockFactory::CreateFormat();
239     videoParams->PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_MPEG4);
240     videoParams->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, TEST_WIDTH);
241     ret = avmuxer_->AddTrack(videoTrackId, videoParams);
242     EXPECT_NE(ret, AV_ERR_OK);
243 }
244 
245 /**
246  * @tc.name: Muxer_AddTrack_003
247  * @tc.desc: Muxer AddTrack after Start()
248  * @tc.type: FUNC
249  */
250 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_003, TestSize.Level0)
251 {
252     int32_t audioTrackId = -1;
253     int32_t videoTrackId = -1;
254     int32_t ret = AV_ERR_INVALID_VAL;
255     std::string outputFile = TEST_FILE_PATH + std::string("avmuxer_AddTrack_003.mp4");
256     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
257     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
258     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
259     ASSERT_TRUE(isCreated);
260 
261     std::shared_ptr<FormatMock> videoParams =
262         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_MPEG4, TEST_WIDTH, TEST_HEIGHT);
263     videoParams->PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
264     ret = avmuxer_->AddTrack(videoTrackId, videoParams);
265     EXPECT_EQ(ret, AV_ERR_OK);
266     EXPECT_GE(videoTrackId, 0);
267 
268     ASSERT_EQ(avmuxer_->Start(), 0);
269     std::shared_ptr<FormatMock> audioParams =
270         FormatMockFactory::CreateAudioFormat(CodecMimeType::AUDIO_MPEG, TEST_SAMPLE_RATE, TEST_CHANNEL_COUNT);
271     ret = avmuxer_->AddTrack(audioTrackId, audioParams);
272     EXPECT_NE(ret, AV_ERR_OK);
273 }
274 
275 /**
276  * @tc.name: Muxer_AddTrack_004
277  * @tc.desc: Muxer AddTrack mimeType test
278  * @tc.type: FUNC
279  */
280 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_004, TestSize.Level0)
281 {
282     int32_t trackId = -1;
283     int32_t ret = 0;
284     const std::vector<std::string_view> testMp4MimeTypeList =
285     {
286         CodecMimeType::AUDIO_MPEG,
287         // CodecMimeType::AUDIO_FLAC,
288         // CodecMimeType::AUDIO_RAW,
289         CodecMimeType::AUDIO_AAC,
290         // CodecMimeType::AUDIO_VORBIS,
291         // CodecMimeType::AUDIO_OPUS,
292         // CodecMimeType::AUDIO_AMR_NB,
293         // CodecMimeType::AUDIO_AMR_WB,
294         CodecMimeType::VIDEO_AVC,
295         CodecMimeType::VIDEO_MPEG4,
296         CodecMimeType::IMAGE_JPG,
297         CodecMimeType::IMAGE_PNG,
298         CodecMimeType::IMAGE_BMP,
299     };
300 
301     const std::vector<std::string_view> testM4aMimeTypeList =
302     {
303         CodecMimeType::AUDIO_AAC,
304         CodecMimeType::VIDEO_AVC,
305         CodecMimeType::VIDEO_MPEG4,
306         CodecMimeType::IMAGE_JPG,
307         CodecMimeType::IMAGE_PNG,
308         CodecMimeType::IMAGE_BMP,
309     };
310 
311     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_AddTrack.mp4");
312     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
313     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
314 
315     std::shared_ptr<FormatMock> avParam = FormatMockFactory::CreateFormat();
316     avParam->PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, TEST_SAMPLE_RATE);
317     avParam->PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, TEST_CHANNEL_COUNT);
318     avParam->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, TEST_WIDTH);
319     avParam->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, TEST_HEIGHT);
320 
321     for (uint32_t i = 0; i < testMp4MimeTypeList.size(); ++i) {
322         bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
323         ASSERT_TRUE(isCreated);
324         avParam->PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, testMp4MimeTypeList[i]);
325         ret = avmuxer_->AddTrack(trackId, avParam);
326         EXPECT_EQ(ret, AV_ERR_OK) << "AddTrack failed: i:" << i << " mimeType:" << testMp4MimeTypeList[i];
327         EXPECT_EQ(trackId, 0) << "i:" << i << " TrackId:" << trackId << " mimeType:" << testMp4MimeTypeList[i];
328     }
329 
330     // need to change libohosffmpeg.z.so, muxer build config add ipod
331     avmuxer_->Destroy();
332     outputFormat = OUTPUT_FORMAT_M4A;
333     for (uint32_t i = 0; i < testM4aMimeTypeList.size(); ++i) {
334         bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
335         ASSERT_TRUE(isCreated);
336         avParam->PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, testM4aMimeTypeList[i]);
337         ret = avmuxer_->AddTrack(trackId, avParam);
338         EXPECT_EQ(ret, AV_ERR_OK) << "AddTrack failed: i:" << i << " mimeType:" << testM4aMimeTypeList[i];
339         EXPECT_EQ(trackId, 0) << "i:" << i << " TrackId:" << trackId << " mimeType:" << testM4aMimeTypeList[i];
340     }
341 }
342 
343 /**
344  * @tc.name: Muxer_AddTrack_005
345  * @tc.desc: Muxer AddTrack while create by unexpected outputFormat
346  * @tc.type: FUNC
347  */
348 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_005, TestSize.Level0)
349 {
350     int32_t trackId = -2;
351     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_AddTrack.mp4");
352     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
353     bool isCreated = avmuxer_->CreateMuxer(fd_, static_cast<OutputFormat>(INVALID_FORMAT));
354     ASSERT_FALSE(isCreated);
355 
356     std::shared_ptr<FormatMock> avParam = FormatMockFactory::CreateFormat();
357     avParam->PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_MPEG);
358     avParam->PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, TEST_SAMPLE_RATE);
359     avParam->PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, TEST_CHANNEL_COUNT);
360     avParam->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, TEST_WIDTH);
361     avParam->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, TEST_HEIGHT);
362 
363     int32_t ret = avmuxer_->AddTrack(trackId, avParam);
364     ASSERT_NE(ret, 0);
365 
366     avParam->PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_MPEG4);
367     ret = avmuxer_->AddTrack(trackId, avParam);
368     ASSERT_NE(ret, 0);
369 }
370 
371 /**
372  * @tc.name: Muxer_AddTrack_006
373  * @tc.desc: Muxer AddTrack while create by unexpected value
374  * @tc.type: FUNC
375  */
376 HWTEST_F(AVMuxerUnitTest, Muxer_AddTrack_006, TestSize.Level0)
377 {
378     int32_t trackId = -2;
379     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_AddTrack.mp4");
380     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
381     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
382     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
383     ASSERT_TRUE(isCreated);
384 
385     std::shared_ptr<FormatMock> audioParam = FormatMockFactory::CreateFormat();
386     audioParam->PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::AUDIO_MPEG);
387     audioParam->PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, TEST_SAMPLE_RATE);
388     audioParam->PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, -1);
389     int32_t ret = avmuxer_->AddTrack(trackId, audioParam);
390     ASSERT_NE(ret, 0);
391 
392     audioParam->PutIntValue(MediaDescriptionKey::MD_KEY_SAMPLE_RATE, -1);
393     audioParam->PutIntValue(MediaDescriptionKey::MD_KEY_CHANNEL_COUNT, TEST_CHANNEL_COUNT);
394     ret = avmuxer_->AddTrack(trackId, audioParam);
395     ASSERT_NE(ret, 0);
396 
397     // test add video track
398     std::shared_ptr<FormatMock> videoParam = FormatMockFactory::CreateFormat();
399     videoParam->PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_MPEG4);
400     videoParam->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, TEST_WIDTH);
401     videoParam->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, -1);
402     ret = avmuxer_->AddTrack(trackId, videoParam);
403     ASSERT_NE(ret, 0);
404 
405     videoParam->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, -1);
406     videoParam->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, TEST_HEIGHT);
407     ret = avmuxer_->AddTrack(trackId, videoParam);
408     ASSERT_NE(ret, 0);
409 
410     videoParam->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, TEST_WIDTH);
411     videoParam->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, 0xFFFF + 1);
412     ret = avmuxer_->AddTrack(trackId, videoParam);
413     ASSERT_NE(ret, 0);
414 
415     videoParam->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, 0xFFFF + 1);
416     videoParam->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, TEST_HEIGHT);
417     ret = avmuxer_->AddTrack(trackId, videoParam);
418     ASSERT_NE(ret, 0);
419 
420     videoParam->PutIntValue(MediaDescriptionKey::MD_KEY_WIDTH, 0xFFFF);
421     videoParam->PutIntValue(MediaDescriptionKey::MD_KEY_HEIGHT, 0xFFFF);
422     ret = avmuxer_->AddTrack(trackId, videoParam);
423     ASSERT_EQ(ret, 0);
424 }
425 
426 /**
427  * @tc.name: Muxer_Start_001
428  * @tc.desc: Muxer Start normal
429  * @tc.type: FUNC
430  */
431 HWTEST_F(AVMuxerUnitTest, Muxer_Start_001, TestSize.Level0)
432 {
433     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Start.mp4");
434     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
435     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
436     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
437     ASSERT_TRUE(isCreated);
438 
439     std::shared_ptr<FormatMock> videoParams =
440         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_MPEG4, TEST_WIDTH, TEST_HEIGHT);
441     videoParams->PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
442 
443     int32_t videoTrackId = -1;
444     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
445     ASSERT_EQ(ret, AV_ERR_OK);
446     ASSERT_GE(videoTrackId, 0);
447     EXPECT_EQ(avmuxer_->Start(), 0);
448 }
449 
450 /**
451  * @tc.name: Muxer_Start_002
452  * @tc.desc: Muxer Start twice
453  * @tc.type: FUNC
454  */
455 HWTEST_F(AVMuxerUnitTest, Muxer_Start_002, TestSize.Level0)
456 {
457     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Start.mp4");
458     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
459     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
460     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
461     ASSERT_TRUE(isCreated);
462 
463     std::shared_ptr<FormatMock> videoParams =
464         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_MPEG4, TEST_WIDTH, TEST_HEIGHT);
465     videoParams->PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
466 
467     int32_t videoTrackId = -1;
468     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
469     ASSERT_EQ(ret, AV_ERR_OK);
470     ASSERT_GE(videoTrackId, 0);
471     ASSERT_EQ(avmuxer_->Start(), 0);
472     EXPECT_NE(avmuxer_->Start(), 0);
473 }
474 
475 /**
476  * @tc.name: Muxer_Start_003
477  * @tc.desc: Muxer Start after Create()
478  * @tc.type: FUNC
479  */
480 HWTEST_F(AVMuxerUnitTest, Muxer_Start_003, TestSize.Level0)
481 {
482     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Start.mp4");
483     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
484     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
485     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
486     ASSERT_TRUE(isCreated);
487     EXPECT_NE(avmuxer_->Start(), 0);
488 }
489 
490 /**
491  * @tc.name: Muxer_Start_004
492  * @tc.desc: Muxer Start after Stop()
493  * @tc.type: FUNC
494  */
495 HWTEST_F(AVMuxerUnitTest, Muxer_Start_004, TestSize.Level0)
496 {
497     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Start.mp4");
498     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
499     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
500     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
501     ASSERT_TRUE(isCreated);
502 
503     std::shared_ptr<FormatMock> videoParams =
504         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_MPEG4, TEST_WIDTH, TEST_HEIGHT);
505     videoParams->PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
506 
507     int32_t videoTrackId = -1;
508     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
509     ASSERT_EQ(ret, AV_ERR_OK);
510     ASSERT_GE(videoTrackId, 0);
511     ASSERT_EQ(avmuxer_->Start(), 0);
512     ASSERT_EQ(avmuxer_->Stop(), 0);
513 
514     EXPECT_NE(avmuxer_->Start(), 0);
515 }
516 
517 /**
518  * @tc.name: Muxer_Start_005
519  * @tc.desc: Muxer Start while create by unexpected outputFormat
520  * @tc.type: FUNC
521  */
522 HWTEST_F(AVMuxerUnitTest, Muxer_Start_005, TestSize.Level0)
523 {
524     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Start.mp4");
525     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
526     bool isCreated = avmuxer_->CreateMuxer(fd_, static_cast<OutputFormat>(INVALID_FORMAT));
527     ASSERT_FALSE(isCreated);
528 
529     std::shared_ptr<FormatMock> videoParams =
530         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_MPEG4, TEST_WIDTH, TEST_HEIGHT);
531     videoParams->PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
532 
533     int32_t videoTrackId = -1;
534     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
535     ASSERT_NE(ret, AV_ERR_OK);
536     ASSERT_LT(videoTrackId, 0);
537     ASSERT_NE(avmuxer_->Start(), 0);
538 }
539 
540 /**
541  * @tc.name: Muxer_Stop_001
542  * @tc.desc: Muxer Stop() normal
543  * @tc.type: FUNC
544  */
545 HWTEST_F(AVMuxerUnitTest, Muxer_Stop_001, TestSize.Level0)
546 {
547     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Stop.mp4");
548     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
549     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
550     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
551     ASSERT_TRUE(isCreated);
552 
553     std::shared_ptr<FormatMock> videoParams =
554         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_MPEG4, TEST_WIDTH, TEST_HEIGHT);
555     videoParams->PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
556     int32_t videoTrackId = -1;
557     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
558     ASSERT_EQ(ret, AV_ERR_OK);
559     ASSERT_GE(videoTrackId, 0);
560     ASSERT_EQ(avmuxer_->Start(), 0);
561     EXPECT_EQ(avmuxer_->Stop(), 0);
562 }
563 
564 /**
565  * @tc.name: Muxer_Stop_002
566  * @tc.desc: Muxer Stop() after Create()
567  * @tc.type: FUNC
568  */
569 HWTEST_F(AVMuxerUnitTest, Muxer_Stop_002, TestSize.Level0)
570 {
571     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Stop.mp4");
572     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
573     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
574     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
575     ASSERT_TRUE(isCreated);
576     EXPECT_NE(avmuxer_->Stop(), 0);
577 }
578 
579 /**
580  * @tc.name: Muxer_Stop_003
581  * @tc.desc: Muxer Stop() after AddTrack()
582  * @tc.type: FUNC
583  */
584 HWTEST_F(AVMuxerUnitTest, Muxer_Stop_003, TestSize.Level0)
585 {
586     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Stop.mp4");
587     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
588     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
589     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
590     ASSERT_TRUE(isCreated);
591 
592     std::shared_ptr<FormatMock> videoParams =
593         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_MPEG4, TEST_WIDTH, TEST_HEIGHT);
594     videoParams->PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
595     int32_t videoTrackId = -1;
596     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
597     ASSERT_EQ(ret, AV_ERR_OK);
598     ASSERT_GE(videoTrackId, 0);
599     EXPECT_NE(avmuxer_->Stop(), 0);
600 }
601 
602 /**
603  * @tc.name: Muxer_Stop_004
604  * @tc.desc: Muxer Stop() multiple times
605  * @tc.type: FUNC
606  */
607 HWTEST_F(AVMuxerUnitTest, Muxer_Stop_004, TestSize.Level0)
608 {
609     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Stop.mp4");
610     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
611     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
612     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
613     ASSERT_TRUE(isCreated);
614 
615     std::shared_ptr<FormatMock> videoParams =
616         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_MPEG4, TEST_WIDTH, TEST_HEIGHT);
617     videoParams->PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
618     int32_t videoTrackId = -1;
619     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
620     ASSERT_EQ(ret, AV_ERR_OK);
621     ASSERT_GE(videoTrackId, 0);
622     ASSERT_EQ(avmuxer_->Start(), 0);
623     ASSERT_EQ(avmuxer_->Stop(), 0);
624 
625     ASSERT_NE(avmuxer_->Stop(), 0);
626     ASSERT_NE(avmuxer_->Stop(), 0);
627     ASSERT_NE(avmuxer_->Stop(), 0);
628 }
629 
630 /**
631  * @tc.name: Muxer_Stop_005
632  * @tc.desc: Muxer Stop() before Start
633  * @tc.type: FUNC
634  */
635 HWTEST_F(AVMuxerUnitTest, Muxer_Stop_005, TestSize.Level0)
636 {
637     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Stop.mp4");
638     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
639     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
640     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
641     ASSERT_TRUE(isCreated);
642 
643     std::shared_ptr<FormatMock> videoParams =
644         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_MPEG4, TEST_WIDTH, TEST_HEIGHT);
645     videoParams->PutStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, CodecMimeType::VIDEO_MPEG4);
646     videoParams->PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
647     int32_t videoTrackId = -1;
648     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
649     ASSERT_EQ(ret, AV_ERR_OK);
650     EXPECT_GE(videoTrackId, 0);
651     EXPECT_NE(avmuxer_->Stop(), 0);
652     EXPECT_EQ(avmuxer_->Start(), 0);
653     EXPECT_EQ(avmuxer_->Stop(), 0);
654 }
655 
656 /**
657  * @tc.name: Muxer_Stop_006
658  * @tc.desc: Muxer Stop() while create by unexpected outputFormat
659  * @tc.type: FUNC
660  */
661 HWTEST_F(AVMuxerUnitTest, Muxer_Stop_006, TestSize.Level0)
662 {
663     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Stop.mp4");
664     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
665     bool isCreated = avmuxer_->CreateMuxer(fd_, static_cast<OutputFormat>(INVALID_FORMAT));
666     ASSERT_FALSE(isCreated);
667 
668     std::shared_ptr<FormatMock> videoParams =
669         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_MPEG4, TEST_WIDTH, TEST_HEIGHT);
670     videoParams->PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
671     int32_t videoTrackId = -1;
672     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
673     ASSERT_NE(ret, AV_ERR_OK);
674     ASSERT_LT(videoTrackId, 0);
675     ASSERT_NE(avmuxer_->Start(), 0);
676     ASSERT_NE(avmuxer_->Stop(), 0);
677 }
678 
679 /**
680  * @tc.name: Muxer_writeSample_001
681  * @tc.desc: Muxer Write Sample normal
682  * @tc.type: FUNC
683  */
684 HWTEST_F(AVMuxerUnitTest, Muxer_writeSample_001, TestSize.Level0)
685 {
686     int32_t trackId = -1;
687     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_WriteSample.mp4");
688     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
689 
690     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
691     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
692     ASSERT_TRUE(isCreated);
693 
694     std::shared_ptr<FormatMock> vParam =
695         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
696 
697     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
698     ASSERT_EQ(ret, 0);
699     ASSERT_GE(trackId, 0);
700     ASSERT_EQ(avmuxer_->Start(), 0);
701 
702     AVCodecBufferAttrMock info;
703     info.pts = 0;
704     info.size = sizeof(buffer_);
705     ret = avmuxer_->WriteSample(trackId, buffer_, info);
706     ASSERT_EQ(ret, 0);
707 }
708 
709 /**
710  * @tc.name: Muxer_writeSample_002
711  * @tc.desc: Muxer Write Sample while create by unexpected outputFormat
712  * @tc.type: FUNC
713  */
714 HWTEST_F(AVMuxerUnitTest, Muxer_writeSample_002, TestSize.Level0)
715 {
716     int32_t trackId = -1;
717     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_writeSample.mp4");
718     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
719     bool isCreated = avmuxer_->CreateMuxer(fd_, static_cast<OutputFormat>(INVALID_FORMAT));
720     ASSERT_FALSE(isCreated);
721 
722     std::shared_ptr<FormatMock> vParam =
723         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
724 
725     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
726     ASSERT_NE(ret, 0);
727     ASSERT_LT(trackId, 0);
728     ASSERT_NE(avmuxer_->Start(), 0);
729 
730     AVCodecBufferAttrMock info;
731     info.pts = 0;
732     info.size = sizeof(buffer_);
733     ret = avmuxer_->WriteSample(trackId, buffer_, info);
734     ASSERT_NE(ret, 0);
735 }
736 
737 /**
738  * @tc.name: Muxer_writeSample_003
739  * @tc.desc: Muxer Write Sample without Start()
740  * @tc.type: FUNC
741  */
742 HWTEST_F(AVMuxerUnitTest, Muxer_writeSample_003, TestSize.Level0)
743 {
744     int32_t trackId = -1;
745     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_WriteSample.mp4");
746     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
747 
748     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
749     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
750     ASSERT_TRUE(isCreated);
751 
752     std::shared_ptr<FormatMock> vParam =
753         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
754 
755     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
756     ASSERT_EQ(ret, 0);
757     ASSERT_GE(trackId, 0);
758 
759     AVCodecBufferAttrMock info;
760     info.pts = 0;
761     info.size = sizeof(buffer_);
762     ret = avmuxer_->WriteSample(trackId, buffer_, info);
763     ASSERT_NE(ret, 0);
764 }
765 
766 /**
767  * @tc.name: Muxer_writeSample_004
768  * @tc.desc: Muxer Write Sample unexisting track
769  * @tc.type: FUNC
770  */
771 HWTEST_F(AVMuxerUnitTest, Muxer_writeSample_004, TestSize.Level0)
772 {
773     constexpr int32_t invalidTrackId = 99999;
774     int32_t trackId = -1;
775     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_WriteSample.mp4");
776     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
777 
778     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
779     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
780     ASSERT_TRUE(isCreated);
781 
782     std::shared_ptr<FormatMock> vParam =
783         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
784 
785     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
786     ASSERT_EQ(ret, 0);
787     ASSERT_GE(trackId, 0);
788     ASSERT_EQ(avmuxer_->Start(), 0);
789 
790     AVCodecBufferAttrMock info;
791     info.pts = 0;
792     info.size = sizeof(buffer_);
793     ret = avmuxer_->WriteSample(trackId + 1, buffer_, info);
794     ASSERT_NE(ret, 0);
795 
796     ret = avmuxer_->WriteSample(-1, buffer_, info);
797     ASSERT_NE(ret, 0);
798 
799     ret = avmuxer_->WriteSample(invalidTrackId, buffer_, info);
800     ASSERT_NE(ret, 0);
801 }
802 
803 /**
804  * @tc.name: Muxer_writeSample_005
805  * @tc.desc: Muxer Write Sample after Stop()
806  * @tc.type: FUNC
807  */
808 HWTEST_F(AVMuxerUnitTest, Muxer_writeSample_005, TestSize.Level0)
809 {
810     int32_t trackId = -1;
811     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_WriteSample.mp4");
812     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
813 
814     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
815     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
816     ASSERT_TRUE(isCreated);
817 
818     std::shared_ptr<FormatMock> vParam =
819         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
820 
821     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
822     ASSERT_EQ(ret, 0);
823     ASSERT_GE(trackId, 0);
824     ASSERT_EQ(avmuxer_->Start(), 0);
825     ASSERT_EQ(avmuxer_->Stop(), 0);
826 
827     AVCodecBufferAttrMock info;
828     info.pts = 0;
829     info.size = sizeof(buffer_);
830     ret = avmuxer_->WriteSample(trackId, buffer_, info);
831     ASSERT_NE(ret, 0);
832 }
833 
834 /**
835  * @tc.name: Muxer_SetRotation_001
836  * @tc.desc: Muxer SetRotation after Create
837  * @tc.type: FUNC
838  */
839 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_001, TestSize.Level0)
840 {
841     int32_t trackId = -1;
842     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
843     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
844 
845     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
846     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
847     ASSERT_TRUE(isCreated);
848 
849     std::shared_ptr<FormatMock> vParam =
850         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
851     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
852     ASSERT_EQ(ret, 0);
853     ASSERT_GE(trackId, 0);
854 
855     ret = avmuxer_->SetRotation(TEST_ROTATION);
856     EXPECT_EQ(ret, 0);
857 }
858 
859 
860 /**
861  * @tc.name: Muxer_SetRotation_002
862  * @tc.desc: Muxer SetRotation after Create
863  * @tc.type: FUNC
864  */
865 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_002, TestSize.Level0)
866 {
867     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
868     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
869 
870     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
871     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
872     ASSERT_TRUE(isCreated);
873 
874     int32_t ret = avmuxer_->SetRotation(TEST_ROTATION);
875     EXPECT_EQ(ret, 0);
876 }
877 
878 /**
879  * @tc.name: Muxer_SetRotation_003
880  * @tc.desc: Muxer SetRotation after Start
881  * @tc.type: FUNC
882  */
883 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_003, TestSize.Level0)
884 {
885     int32_t trackId = -1;
886     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
887     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
888 
889     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
890     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
891     ASSERT_TRUE(isCreated);
892 
893     std::shared_ptr<FormatMock> vParam =
894         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
895     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
896     ASSERT_EQ(ret, 0);
897     ASSERT_GE(trackId, 0);
898     ASSERT_EQ(avmuxer_->Start(), 0);
899 
900     ret = avmuxer_->SetRotation(TEST_ROTATION);
901     EXPECT_NE(ret, 0);
902 }
903 
904 /**
905  * @tc.name: Muxer_SetRotation_004
906  * @tc.desc: Muxer SetRotation after Stop
907  * @tc.type: FUNC
908  */
909 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_004, TestSize.Level0)
910 {
911     int32_t trackId = -1;
912     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
913     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
914 
915     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
916     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
917     ASSERT_TRUE(isCreated);
918 
919     std::shared_ptr<FormatMock> vParam =
920         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_AVC, TEST_WIDTH, TEST_HEIGHT);
921     int32_t ret = avmuxer_->AddTrack(trackId, vParam);
922     ASSERT_EQ(ret, 0);
923     ASSERT_GE(trackId, 0);
924     ASSERT_EQ(avmuxer_->Start(), 0);
925     ASSERT_EQ(avmuxer_->Stop(), 0);
926 
927     ret = avmuxer_->SetRotation(TEST_ROTATION);
928     EXPECT_NE(ret, 0);
929 }
930 
931 /**
932  * @tc.name: Muxer_SetRotation_005
933  * @tc.desc: Muxer SetRotation after WriteSample
934  * @tc.type: FUNC
935  */
936 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_005, TestSize.Level0)
937 {
938     int32_t trackId = -1;
939     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
940     OutputFormat outputFormat = 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(CodecMimeType::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     AVCodecBufferAttrMock info;
955     info.pts = 0;
956     info.size = sizeof(buffer_);
957     ret = avmuxer_->WriteSample(trackId, buffer_, info);
958     EXPECT_EQ(ret, 0);
959 
960     ret = avmuxer_->SetRotation(TEST_ROTATION);
961     EXPECT_NE(ret, 0);
962 }
963 
964 /**
965  * @tc.name: Muxer_SetRotation_006
966  * @tc.desc: Muxer SetRotation while Create failed!
967  * @tc.type: FUNC
968  */
969 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_006, TestSize.Level0)
970 {
971     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
972     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
973     bool isCreated = avmuxer_->CreateMuxer(fd_, static_cast<OutputFormat>(INVALID_FORMAT));
974     ASSERT_FALSE(isCreated);
975 
976     int32_t ret = avmuxer_->SetRotation(TEST_ROTATION);
977     ASSERT_NE(ret, 0);
978 }
979 
980 /**
981  * @tc.name: Muxer_SetRotation_007
982  * @tc.desc: Muxer SetRotation expected value
983  * @tc.type: FUNC
984  */
985 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_007, TestSize.Level0)
986 {
987     constexpr int32_t testRotation180 = 180;
988     constexpr int32_t testRotation270 = 270;
989     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
990     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
991 
992     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
993     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
994     ASSERT_TRUE(isCreated);
995 
996     int32_t ret = avmuxer_->SetRotation(0);
997     EXPECT_EQ(ret, 0);
998 
999     ret = avmuxer_->SetRotation(TEST_ROTATION);
1000     EXPECT_EQ(ret, 0);
1001 
1002     ret = avmuxer_->SetRotation(testRotation180);
1003     EXPECT_EQ(ret, 0);
1004 
1005     ret = avmuxer_->SetRotation(testRotation270);
1006     EXPECT_EQ(ret, 0);
1007 }
1008 
1009 /**
1010  * @tc.name: Muxer_SetRotation_008
1011  * @tc.desc: Muxer SetRotation unexpected value
1012  * @tc.type: FUNC
1013  */
1014 HWTEST_F(AVMuxerUnitTest, Muxer_SetRotation_008, TestSize.Level0)
1015 {
1016     constexpr int32_t testRotation360 = 360;
1017     constexpr int32_t testRotationNeg90 = -90;
1018     constexpr int32_t testRotationNeg180 = -180;
1019     constexpr int32_t testRotationNeg270 = -270;
1020     constexpr int32_t testRotationNeg360 = -360;
1021     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_SetRotation.mp4");
1022     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
1023 
1024     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1025     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1026     ASSERT_TRUE(isCreated);
1027 
1028     int32_t ret = avmuxer_->SetRotation(1);
1029     EXPECT_NE(ret, 0);
1030 
1031     ret = avmuxer_->SetRotation(TEST_ROTATION + 1);
1032     EXPECT_NE(ret, 0);
1033 
1034     ret = avmuxer_->SetRotation(testRotation360);
1035     EXPECT_NE(ret, 0);
1036 
1037     ret = avmuxer_->SetRotation(-1);
1038     EXPECT_NE(ret, 0);
1039 
1040     ret = avmuxer_->SetRotation(testRotationNeg90);
1041     EXPECT_NE(ret, 0);
1042 
1043     ret = avmuxer_->SetRotation(testRotationNeg180);
1044     EXPECT_NE(ret, 0);
1045 
1046     ret = avmuxer_->SetRotation(testRotationNeg270);
1047     EXPECT_NE(ret, 0);
1048 
1049     ret = avmuxer_->SetRotation(testRotationNeg360);
1050     EXPECT_NE(ret, 0);
1051 }
1052 
1053 #ifdef AVMUXER_UNITTEST_CAPI
1054 /**
1055  * @tc.name: Muxer_Destroy_001
1056  * @tc.desc: Muxer Destroy normal
1057  * @tc.type: FUNC
1058  */
1059 HWTEST_F(AVMuxerUnitTest, Muxer_Destroy_001, TestSize.Level0)
1060 {
1061     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Destro.mp4");
1062     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1063     OutputFormat outputFormat = OUTPUT_FORMAT_MPEG_4;
1064     bool isCreated = avmuxer_->CreateMuxer(fd_, outputFormat);
1065     ASSERT_TRUE(isCreated);
1066 
1067     std::shared_ptr<FormatMock> videoParams =
1068         FormatMockFactory::CreateVideoFormat(CodecMimeType::VIDEO_MPEG4, TEST_WIDTH, TEST_HEIGHT);
1069     videoParams->PutBuffer(MediaDescriptionKey::MD_KEY_CODEC_CONFIG, buffer_, sizeof(buffer_));
1070     int32_t videoTrackId = -1;
1071     int32_t ret = avmuxer_->AddTrack(videoTrackId, videoParams);
1072     ASSERT_EQ(ret, AV_ERR_OK);
1073     ASSERT_GE(videoTrackId, 0);
1074     ASSERT_EQ(avmuxer_->Start(), 0);
1075     ASSERT_EQ(avmuxer_->Stop(), 0);
1076     ASSERT_EQ(avmuxer_->Destroy(), 0);
1077 }
1078 
1079 /**
1080  * @tc.name: Muxer_Destroy_002
1081  * @tc.desc: Muxer Destroy normal
1082  * @tc.type: FUNC
1083  */
1084 HWTEST_F(AVMuxerUnitTest, Muxer_Destroy_002, TestSize.Level0)
1085 {
1086     std::string outputFile = TEST_FILE_PATH + std::string("Muxer_Destroy.mp4");
1087     fd_ = open(outputFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, S_IRUSR | S_IWUSR);
1088     OH_AVOutputFormat outputFormat = AV_OUTPUT_FORMAT_MPEG_4;
1089     OH_AVMuxer *muxer = OH_AVMuxer_Create(fd_, outputFormat);
1090     int32_t ret = OH_AVMuxer_Destroy(muxer);
1091     ASSERT_EQ(ret, 0);
1092     muxer = nullptr;
1093 }
1094 
1095 /**
1096  * @tc.name: Muxer_Destroy_003
1097  * @tc.desc: Muxer Destroy nullptr
1098  * @tc.type: FUNC
1099  */
1100 HWTEST_F(AVMuxerUnitTest, Muxer_Destroy_003, TestSize.Level0)
1101 {
1102     int32_t ret = OH_AVMuxer_Destroy(nullptr);
1103     ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
1104 }
1105 
1106 /**
1107  * @tc.name: Muxer_Destroy_004
1108  * @tc.desc: Muxer Destroy other class
1109  * @tc.type: FUNC
1110  */
1111 HWTEST_F(AVMuxerUnitTest, Muxer_Destroy_004, TestSize.Level0)
1112 {
1113     OH_AVFormat *format = OH_AVFormat_Create();
1114     int32_t ret = OH_AVMuxer_Destroy(reinterpret_cast<OH_AVMuxer*>(format));
1115     ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
1116     OH_AVFormat_Destroy(format);
1117 }
1118 #endif // AVMUXER_UNITTEST_CAPI