1 /* 2 * Copyright (C) 2023-2025 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 #ifndef AVSOURCE_UNIT_TEST_H 17 #define AVSOURCE_UNIT_TEST_H 18 19 #include "gtest/gtest.h" 20 #include "avsource_mock.h" 21 22 namespace OHOS { 23 namespace MediaAVCodec { 24 class AVSourceUnitTest : public testing::Test { 25 public: 26 // SetUpTestCase: Called before all test cases 27 static void SetUpTestCase(void); 28 // TearDownTestCase: Called after all test case 29 static void TearDownTestCase(void); 30 // SetUp: Called before each test cases 31 void SetUp(void); 32 // TearDown: Called after each test cases 33 void TearDown(void); 34 int64_t GetFileSize(const std::string &fileName); 35 int32_t OpenFile(const std::string &fileName); 36 void ResetFormatValue(); 37 38 void InitResource(const std::string &path, bool local); 39 void CheckHevcInfo(const std::string resName); 40 41 protected: 42 std::shared_ptr<AVSourceMock> source_ = nullptr; 43 std::shared_ptr<FormatMock> format_ = nullptr; 44 int32_t fd_ = -1; 45 int64_t size_ = 0; 46 uint32_t trackIndex_ = 0; 47 int32_t streamsCount_ = 0; 48 int32_t vTrackIdx_ = 0; 49 int32_t aTrackIdx_ = 0; 50 uint8_t *addr_ = nullptr; 51 size_t buffSize_ = 0; 52 bool initStatus_ = false; 53 54 struct FormatValue { 55 // source format 56 std::string title = ""; 57 std::string artist = ""; 58 std::string album = ""; 59 std::string albumArtist = ""; 60 std::string date = ""; 61 std::string comment = ""; 62 std::string genre = ""; 63 std::string copyright = ""; 64 std::string description = ""; 65 std::string language = ""; 66 std::string lyrics = ""; 67 int64_t duration = 0; 68 int32_t trackCount = 0; 69 std::string author = ""; 70 std::string composer = ""; 71 int32_t hasVideo = -1; 72 int32_t hasAudio = -1; 73 int32_t hasTimedMeta = -1; 74 int32_t hasSubtitle = -1; 75 int32_t hasAuxl = -1; 76 int32_t fileType = 0; 77 // track format 78 std::string codecMime = ""; 79 int32_t trackType = 0; 80 int32_t width = 0; 81 int32_t height = 0; 82 int32_t aacIsAdts = -1; 83 int32_t sampleRate = 0; 84 int32_t channelCount = 0; 85 int64_t bitRate = 0; 86 int32_t audioSampleFormat = 0; 87 double frameRate = 0; 88 int32_t rotationAngle = 0; 89 int32_t orientationType = 0; 90 int64_t channelLayout = 0; 91 int32_t hdrType = 0; 92 int32_t codecProfile = 0; 93 int32_t codecLevel = 0; 94 int32_t colorPrimaries = 0; 95 int32_t transferCharacteristics = 0; 96 int32_t rangeFlag = 0; 97 int32_t matrixCoefficients = 0; 98 int32_t chromaLocation = 0; 99 std::string timedMetadataKey = ""; 100 int32_t srcTrackID = -1; 101 // hevc format 102 int32_t profile = 0; 103 int32_t level = 0; 104 int32_t colorPri = 0; 105 int32_t colorTrans = 0; 106 int32_t colorMatrix = 0; 107 int32_t colorRange = 0; 108 int32_t chromaLoc = 0; 109 int32_t isHdrVivid = 0; 110 // ape format 111 int32_t audioMaxInputSize = 0; 112 113 int32_t samplePerFrame = 0; 114 }; 115 FormatValue formatVal_; 116 117 bool checkPass_ = false; 118 void CheckAuxlHevc(); 119 void CheckAuxlAvc(); 120 void CheckAuxlAac(); 121 }; 122 } // namespace MediaAVCodec 123 } // namespace OHOS 124 #endif // AVSOURCE_UNIT_TEST_H 125