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 int32_t dataAccuracy; 32 std::vector<uint32_t> abilityId; 33 } DetailInfo; 34 35 typedef struct StreamRelatedInfo { 36 int32_t streamType; 37 uint32_t detailInfoCount; 38 std::vector<DetailInfo> detailInfo; 39 } StreamRelatedInfo; 40 41 typedef struct ModeInfo { 42 int32_t modeName; 43 uint32_t streamTypeCount; 44 std::vector<StreamRelatedInfo> streamInfo; 45 } ModeInfo; 46 47 typedef struct ExtendInfo { 48 uint32_t modeCount; 49 std::vector<ModeInfo> modeInfo; 50 } ExtendInfo; 51 52 constexpr static int32_t MODE_FINISH = -1; 53 constexpr static int32_t STREAM_FINISH = -1; 54 constexpr static int32_t ABILITY_FINISH = -1; 55 constexpr static int32_t ONE_STEP = 1; 56 constexpr static int32_t TWO_STEP = 2; 57 58 class CameraStreamInfoParse { 59 public: getModeInfo(int32_t * originInfo,uint32_t count,ExtendInfo & transferedInfo)60 void getModeInfo(int32_t* originInfo, uint32_t count, ExtendInfo& transferedInfo) 61 { 62 modeStartIndex_.push_back(0); 63 for (uint32_t i = TWO_STEP; i < count; i++) { 64 if (originInfo[i - TWO_STEP] == ABILITY_FINISH &&originInfo[i - ONE_STEP] == STREAM_FINISH 65 && originInfo[i] == MODE_FINISH) { // 判断mode的-1 结束符位置 66 modeEndIndex_.push_back(i); 67 if (i + ONE_STEP < count) { 68 modeStartIndex_.push_back(i + ONE_STEP); 69 } 70 transferedInfo.modeCount++; 71 } 72 } 73 modeCount_ = transferedInfo.modeCount; 74 transferedInfo.modeInfo.resize(transferedInfo.modeCount); 75 76 getStreamCount(originInfo, transferedInfo); 77 for (uint32_t i = 0; i < modeCount_; i++) { 78 transferedInfo.modeInfo[i].modeName = originInfo[modeStartIndex_[i]]; 79 streamTypeCount_.push(transferedInfo.modeInfo[i].streamTypeCount); 80 } 81 for (uint32_t i = 0; i < transferedInfo.modeCount; i++) { 82 getStreamInfo(originInfo, transferedInfo.modeInfo[i]); 83 } 84 for (uint32_t i = 0; i < transferedInfo.modeCount; i++) { 85 getDetailStreamInfo(originInfo, transferedInfo.modeInfo[i]); 86 } 87 } 88 private: getStreamCount(int32_t * originInfo,ExtendInfo & transferedInfo)89 void getStreamCount(int32_t* originInfo, ExtendInfo& transferedInfo) 90 { 91 for (uint32_t i = 0; i < modeCount_; i++) { 92 for (uint32_t j = modeStartIndex_[i]; j < modeEndIndex_[i]; j++) { 93 if (j == modeStartIndex_[i]) { 94 streamStartIndex_.push(modeStartIndex_[i] + ONE_STEP); 95 } 96 if (originInfo[j] == STREAM_FINISH && originInfo[j - ONE_STEP] == ABILITY_FINISH) { 97 streamEndIndex_.push(j); 98 transferedInfo.modeInfo[i].streamTypeCount++; 99 } 100 if ((originInfo[j] == STREAM_FINISH) && (originInfo[j - ONE_STEP] == ABILITY_FINISH) 101 && ((j + ONE_STEP) < modeEndIndex_[i])) { 102 streamStartIndex_.push(j + ONE_STEP); 103 } 104 } 105 } 106 modeStartIndex_.clear(); 107 modeEndIndex_.clear(); 108 return; 109 } 110 getStreamInfo(int32_t * originInfo,ModeInfo & modeInfo)111 void getStreamInfo(int32_t* originInfo, ModeInfo& modeInfo) 112 { 113 modeInfo.streamInfo.resize(modeInfo.streamTypeCount); 114 for (uint32_t j = 0; j < modeInfo.streamTypeCount; j++) { 115 modeInfo.streamInfo[j].streamType = originInfo[streamStartIndex_.front()]; 116 for (uint32_t k = streamStartIndex_.front(); k < streamEndIndex_.front(); k++) { 117 if (k == streamStartIndex_.front()) { 118 abilityStartIndex_.push(k + ONE_STEP); 119 } 120 if (originInfo[k] == ABILITY_FINISH) { 121 abilityEndIndex_.push(k); 122 modeInfo.streamInfo[j].detailInfoCount++; 123 } 124 if (originInfo[k] == ABILITY_FINISH && originInfo[k + ONE_STEP] != STREAM_FINISH) { 125 abilityStartIndex_.push(k + ONE_STEP); 126 } 127 } 128 deatiInfoCount_.push(modeInfo.streamInfo[j].detailInfoCount); 129 streamStartIndex_.pop(); 130 streamEndIndex_.pop(); 131 } 132 return; 133 } 134 getDetailStreamInfo(int32_t * originInfo,ModeInfo & modeInfo)135 void getDetailStreamInfo(int32_t* originInfo, ModeInfo& modeInfo) 136 { 137 for (uint32_t j = 0; j < streamTypeCount_.front(); j++) { 138 modeInfo.streamInfo[j].detailInfo.resize(deatiInfoCount_.front()); 139 getDetailAbilityInfo(originInfo, modeInfo.streamInfo[j]); 140 } 141 streamTypeCount_.pop(); 142 } 143 getDetailAbilityInfo(int32_t * originInfo,StreamRelatedInfo & streamInfo)144 void getDetailAbilityInfo(int32_t* originInfo, StreamRelatedInfo& streamInfo) 145 { 146 uint32_t allOffset = 6; 147 uint32_t formatOffset = 0; 148 uint32_t widthOffset = 1; 149 uint32_t heightOffset = 2; 150 uint32_t fixedFpsOffset = 3; 151 uint32_t minFpsOffset = 4; 152 uint32_t maxFpsOffset = 5; 153 for (uint32_t k = 0; k < deatiInfoCount_.front(); k++) { 154 for (uint32_t m = abilityStartIndex_.front(); m < abilityEndIndex_.front(); m++) { 155 streamInfo.detailInfo[k].format = 156 originInfo[m + formatOffset]; 157 streamInfo.detailInfo[k].width = 158 originInfo[m + widthOffset]; 159 streamInfo.detailInfo[k].height = 160 originInfo[m + heightOffset]; 161 streamInfo.detailInfo[k].fixedFps = 162 originInfo[m + fixedFpsOffset]; 163 streamInfo.detailInfo[k].minFps = 164 originInfo[m + minFpsOffset]; 165 streamInfo.detailInfo[k].maxFps = 166 originInfo[m + maxFpsOffset]; 167 for (uint32_t n = m + allOffset; n < abilityEndIndex_.front(); n++) { 168 streamInfo.detailInfo[k].abilityId.push_back(originInfo[n]); 169 } 170 m += abilityEndIndex_.front(); 171 } 172 abilityStartIndex_.pop(); 173 abilityEndIndex_.pop(); 174 } 175 deatiInfoCount_.pop(); 176 } 177 uint32_t modeCount_ = 0; 178 std::vector<uint32_t> modeStartIndex_ = {}; 179 std::vector<uint32_t> modeEndIndex_ = {}; 180 std::queue<uint32_t> streamStartIndex_; 181 std::queue<uint32_t> streamEndIndex_; 182 std::queue<uint32_t> streamTypeCount_; 183 std::queue<uint32_t> deatiInfoCount_; 184 std::queue<uint32_t> abilityEndIndex_; 185 std::queue<uint32_t> abilityStartIndex_; 186 }; 187 188 class CameraDepthInfoParse { 189 public: getModeInfo(int32_t * originInfo,uint32_t count,ExtendInfo & transferedInfo)190 void getModeInfo(int32_t* originInfo, uint32_t count, ExtendInfo& transferedInfo) 191 { 192 modeStartIndex_.push_back(0); 193 for (uint32_t i = TWO_STEP; i < count; i++) { 194 if (originInfo[i] == MODE_FINISH) { // 判断mode的-1 结束符位置 195 modeEndIndex_.push_back(i); 196 if (i + ONE_STEP < count) { 197 modeStartIndex_.push_back(i + ONE_STEP); 198 } 199 transferedInfo.modeCount++; 200 } 201 } 202 modeCount_ = transferedInfo.modeCount; 203 transferedInfo.modeInfo.resize(transferedInfo.modeCount); 204 getStreamCount(originInfo, transferedInfo); 205 for (uint32_t i = 0; i < modeCount_; i++) { 206 transferedInfo.modeInfo[i].modeName = originInfo[modeStartIndex_[i]]; 207 streamTypeCount_.push(transferedInfo.modeInfo[i].streamTypeCount); 208 } 209 for (uint32_t i = 0; i < transferedInfo.modeCount; i++) { 210 getStreamInfo(originInfo, transferedInfo.modeInfo[i]); 211 } 212 for (uint32_t i = 0; i < transferedInfo.modeCount; i++) { 213 getDetailStreamInfo(originInfo, transferedInfo.modeInfo[i]); 214 } 215 } 216 private: getStreamCount(int32_t * originInfo,ExtendInfo & transferedInfo)217 void getStreamCount(int32_t* originInfo, ExtendInfo& transferedInfo) 218 { 219 for (uint32_t i = 0; i < modeCount_; i++) { 220 for (uint32_t j = modeStartIndex_[i]; j < modeEndIndex_[i]; j++) { 221 if (j == modeStartIndex_[i]) { 222 streamStartIndex_.push(modeStartIndex_[i]); 223 } 224 if (originInfo[j + ONE_STEP] == STREAM_FINISH) { 225 streamEndIndex_.push(j + ONE_STEP); 226 transferedInfo.modeInfo[i].streamTypeCount++; 227 } 228 } 229 } 230 231 modeStartIndex_.clear(); 232 modeEndIndex_.clear(); 233 return; 234 } 235 getStreamInfo(int32_t * originInfo,ModeInfo & modeInfo)236 void getStreamInfo(int32_t* originInfo, ModeInfo& modeInfo) 237 { 238 modeInfo.streamInfo.resize(modeInfo.streamTypeCount); 239 for (uint32_t j = 0; j < modeInfo.streamTypeCount; j++) { 240 modeInfo.streamInfo[j].streamType = originInfo[streamStartIndex_.front()]; 241 for (uint32_t k = streamStartIndex_.front(); k < streamEndIndex_.front(); k++) { 242 if (k == streamStartIndex_.front()) { 243 abilityStartIndex_.push(k); 244 } 245 if (originInfo[k + ONE_STEP] == ABILITY_FINISH) { 246 abilityEndIndex_.push(k + ONE_STEP); 247 modeInfo.streamInfo[j].detailInfoCount++; 248 } 249 } 250 deatiInfoCount_.push(modeInfo.streamInfo[j].detailInfoCount); 251 streamStartIndex_.pop(); 252 streamEndIndex_.pop(); 253 } 254 return; 255 } 256 getDetailStreamInfo(int32_t * originInfo,ModeInfo & modeInfo)257 void getDetailStreamInfo(int32_t* originInfo, ModeInfo& modeInfo) 258 { 259 for (uint32_t j = 0; j < streamTypeCount_.front(); j++) { 260 modeInfo.streamInfo[j].detailInfo.resize(deatiInfoCount_.front()); 261 getDetailAbilityInfo(originInfo, modeInfo.streamInfo[j]); 262 } 263 streamTypeCount_.pop(); 264 } 265 getDetailAbilityInfo(int32_t * originInfo,StreamRelatedInfo & streamInfo)266 void getDetailAbilityInfo(int32_t* originInfo, StreamRelatedInfo& streamInfo) 267 { 268 uint32_t formatOffset = 1; 269 uint32_t dataAccuracyOffset = 2; 270 uint32_t widthOffset = 3; 271 uint32_t heightOffset = 4; 272 for (uint32_t k = 0; k < deatiInfoCount_.front(); k++) { 273 for (uint32_t m = abilityStartIndex_.front(); m < abilityEndIndex_.front(); m++) { 274 streamInfo.detailInfo[k].format = 275 originInfo[m + formatOffset]; 276 streamInfo.detailInfo[k].dataAccuracy = 277 originInfo[m + dataAccuracyOffset]; 278 streamInfo.detailInfo[k].width = 279 originInfo[m + widthOffset]; 280 streamInfo.detailInfo[k].height = 281 originInfo[m + heightOffset]; 282 m += abilityEndIndex_.front(); 283 } 284 abilityStartIndex_.pop(); 285 abilityEndIndex_.pop(); 286 } 287 deatiInfoCount_.pop(); 288 } 289 uint32_t modeCount_ = 0; 290 std::vector<uint32_t> modeStartIndex_ = {}; 291 std::vector<uint32_t> modeEndIndex_ = {}; 292 std::queue<uint32_t> streamStartIndex_; 293 std::queue<uint32_t> streamEndIndex_; 294 std::queue<uint32_t> streamTypeCount_; 295 std::queue<uint32_t> deatiInfoCount_; 296 std::queue<uint32_t> abilityEndIndex_; 297 std::queue<uint32_t> abilityStartIndex_; 298 }; 299 } // namespace CameraStandard 300 } // namespace OHOS 301 #endif // CAMERA_ERROR_CODE_H