1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef CAMERA_STREAM_INFO_PARSE_H 16 #define CAMERA_STREAM_INFO_PARSE_H 17 18 #include <queue> 19 #include <vector> 20 #include <iostream> 21 namespace OHOS { 22 namespace CameraStandard { 23 using namespace std; 24 typedef struct DetailInfo { 25 int32_t format; 26 int32_t width; 27 int32_t height; 28 int32_t fixedFps; 29 int32_t minFps; 30 int32_t maxFps; 31 std::vector<uint32_t> abilityId; 32 } DetailInfo; 33 34 typedef struct StreamRelatedInfo { 35 int32_t streamType; 36 uint32_t detailInfoCount; 37 std::vector<DetailInfo> detailInfo; 38 } StreamRelatedInfo; 39 40 typedef struct ModeInfo { 41 int32_t modeName; 42 uint32_t streamTypeCount; 43 std::vector<StreamRelatedInfo> streamInfo; 44 } ModeInfo; 45 46 typedef struct ExtendInfo { 47 uint32_t modeCount; 48 std::vector<ModeInfo> modeInfo; 49 } ExtendInfo; 50 51 constexpr static int32_t MODE_FINISH = -1; 52 constexpr static int32_t STREAM_FINISH = -1; 53 constexpr static int32_t ABILITY_FINISH = -1; 54 constexpr static int32_t ONE_STEP = 1; 55 constexpr static int32_t TWO_STEP = 2; 56 57 class CameraStreamInfoParse { 58 public: getModeInfo(int32_t * originInfo,uint32_t count,ExtendInfo & transferedInfo)59 void getModeInfo(int32_t* originInfo, uint32_t count, ExtendInfo& transferedInfo) 60 { 61 modeStartIndex_.push_back(0); 62 for (uint32_t i = TWO_STEP; i < count; i++) { 63 if (originInfo[i - TWO_STEP] == ABILITY_FINISH &&originInfo[i - ONE_STEP] == STREAM_FINISH 64 && originInfo[i] == MODE_FINISH) { // 判断mode的-1 结束符位置 65 modeEndIndex_.push_back(i); 66 if (i + ONE_STEP < count) { 67 modeStartIndex_.push_back(i + ONE_STEP); 68 } 69 transferedInfo.modeCount++; 70 } 71 } 72 modeCount_ = transferedInfo.modeCount; 73 transferedInfo.modeInfo.resize(transferedInfo.modeCount); 74 75 getStreamCount(originInfo, transferedInfo); 76 for (uint32_t i = 0; i < modeCount_; i++) { 77 transferedInfo.modeInfo[i].modeName = originInfo[modeStartIndex_[i]]; 78 streamTypeCount_.push(transferedInfo.modeInfo[i].streamTypeCount); 79 } 80 for (uint32_t i = 0; i < transferedInfo.modeCount; i++) { 81 getStreamInfo(originInfo, transferedInfo.modeInfo[i]); 82 } 83 for (uint32_t i = 0; i < transferedInfo.modeCount; i++) { 84 getDetailStreamInfo(originInfo, transferedInfo.modeInfo[i]); 85 } 86 } 87 private: getStreamCount(int32_t * originInfo,ExtendInfo & transferedInfo)88 void getStreamCount(int32_t* originInfo, ExtendInfo& transferedInfo) 89 { 90 for (uint32_t i = 0; i < modeCount_; i++) { 91 for (uint32_t j = modeStartIndex_[i]; j < modeEndIndex_[i]; j++) { 92 if (j == modeStartIndex_[i]) { 93 streamStartIndex_.push(modeStartIndex_[i] + ONE_STEP); 94 } 95 if (originInfo[j] == STREAM_FINISH && originInfo[j - ONE_STEP] == ABILITY_FINISH) { 96 streamEndIndex_.push(j); 97 transferedInfo.modeInfo[i].streamTypeCount++; 98 } 99 if ((originInfo[j] == STREAM_FINISH) && (originInfo[j - ONE_STEP] == ABILITY_FINISH) 100 && ((j + ONE_STEP) < modeEndIndex_[i])) { 101 streamStartIndex_.push(j + ONE_STEP); 102 } 103 } 104 } 105 modeStartIndex_.clear(); 106 modeEndIndex_.clear(); 107 return; 108 } 109 getStreamInfo(int32_t * originInfo,ModeInfo & modeInfo)110 void getStreamInfo(int32_t* originInfo, ModeInfo& modeInfo) 111 { 112 modeInfo.streamInfo.resize(modeInfo.streamTypeCount); 113 for (uint32_t j = 0; j < modeInfo.streamTypeCount; j++) { 114 modeInfo.streamInfo[j].streamType = originInfo[streamStartIndex_.front()]; 115 for (uint32_t k = streamStartIndex_.front(); k < streamEndIndex_.front(); k++) { 116 if (k == streamStartIndex_.front()) { 117 abilityStartIndex_.push(k + ONE_STEP); 118 } 119 if (originInfo[k] == ABILITY_FINISH) { 120 abilityEndIndex_.push(k); 121 modeInfo.streamInfo[j].detailInfoCount++; 122 } 123 if (originInfo[k] == ABILITY_FINISH && originInfo[k + ONE_STEP] != STREAM_FINISH) { 124 abilityStartIndex_.push(k + ONE_STEP); 125 } 126 } 127 deatiInfoCount_.push(modeInfo.streamInfo[j].detailInfoCount); 128 streamStartIndex_.pop(); 129 streamEndIndex_.pop(); 130 } 131 return; 132 } 133 getDetailStreamInfo(int32_t * originInfo,ModeInfo & modeInfo)134 void getDetailStreamInfo(int32_t* originInfo, ModeInfo& modeInfo) 135 { 136 for (uint32_t j = 0; j < streamTypeCount_.front(); j++) { 137 modeInfo.streamInfo[j].detailInfo.resize(deatiInfoCount_.front()); 138 getDetailAbilityInfo(originInfo, modeInfo.streamInfo[j]); 139 } 140 streamTypeCount_.pop(); 141 } 142 getDetailAbilityInfo(int32_t * originInfo,StreamRelatedInfo & streamInfo)143 void getDetailAbilityInfo(int32_t* originInfo, StreamRelatedInfo& streamInfo) 144 { 145 uint32_t allOffset = 6; 146 uint32_t formatOffset = 0; 147 uint32_t widthOffset = 1; 148 uint32_t heightOffset = 2; 149 uint32_t fixedFpsOffset = 3; 150 uint32_t minFpsOffset = 4; 151 uint32_t maxFpsOffset = 5; 152 for (uint32_t k = 0; k < deatiInfoCount_.front(); k++) { 153 for (uint32_t m = abilityStartIndex_.front(); m < abilityEndIndex_.front(); m++) { 154 streamInfo.detailInfo[k].format = 155 originInfo[m + formatOffset]; 156 streamInfo.detailInfo[k].width = 157 originInfo[m + widthOffset]; 158 streamInfo.detailInfo[k].height = 159 originInfo[m + heightOffset]; 160 streamInfo.detailInfo[k].fixedFps = 161 originInfo[m + fixedFpsOffset]; 162 streamInfo.detailInfo[k].minFps = 163 originInfo[m + minFpsOffset]; 164 streamInfo.detailInfo[k].maxFps = 165 originInfo[m + maxFpsOffset]; 166 for (uint32_t n = m + allOffset; n < abilityEndIndex_.front(); n++) { 167 streamInfo.detailInfo[k].abilityId.push_back(originInfo[n]); 168 } 169 m += abilityEndIndex_.front(); 170 } 171 abilityStartIndex_.pop(); 172 abilityEndIndex_.pop(); 173 } 174 deatiInfoCount_.pop(); 175 } 176 uint32_t modeCount_ = 0; 177 std::vector<uint32_t> modeStartIndex_ = {}; 178 std::vector<uint32_t> modeEndIndex_ = {}; 179 std::queue<uint32_t> streamStartIndex_; 180 std::queue<uint32_t> streamEndIndex_; 181 std::queue<uint32_t> streamTypeCount_; 182 std::queue<uint32_t> deatiInfoCount_; 183 std::queue<uint32_t> abilityEndIndex_; 184 std::queue<uint32_t> abilityStartIndex_; 185 }; 186 } // namespace CameraStandard 187 } // namespace OHOS 188 #endif // CAMERA_ERROR_CODE_H