1 /* 2 * Copyright (c) 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 16 #ifndef OHOS_JSON_UTILS_H 17 #define OHOS_JSON_UTILS_H 18 19 #include <algorithm> 20 #include <iterator> 21 #include "cJSON.h" 22 #include <string> 23 #include <vector> 24 25 #include "avsession_info.h" 26 #include "avsession_errors.h" 27 28 namespace OHOS::AVSession { 29 class JsonUtils { 30 public: 31 static int32_t GetJsonCapability(const std::vector<std::vector<int32_t>>& capability, std::string& jsonCapability); 32 static int32_t GetVectorCapability(const std::string& jsonCapability, 33 std::vector<std::vector<int32_t>>& vectorCapability); 34 static int32_t GetAllCapability(const std::string& sessionInfo, std::string& jsonCapability); 35 36 static int32_t SetSessionBasicInfo(std::string& sessionInfo, const AVSessionBasicInfo& basicInfo); 37 static int32_t GetSessionBasicInfo(const std::string& sessionInfo, AVSessionBasicInfo& basicInfo); 38 39 static int32_t SetSessionDescriptors(std::string& sessionInfo, const std::vector<AVSessionDescriptor>& descriptors); 40 static int32_t GetSessionDescriptors(const std::string& sessionInfo, std::vector<AVSessionDescriptor>& descriptors); 41 42 static int32_t SetSessionDescriptor(std::string& sessionInfo, const AVSessionDescriptor& descriptor); 43 static int32_t GetSessionDescriptor(const std::string& sessionInfo, AVSessionDescriptor& descriptor); 44 45 private: 46 static int32_t JsonToVector(cJSON* object, std::vector<int32_t>& out); 47 static int32_t ConvertSessionType(const std::string& typeString); 48 static std::string ConvertSessionType(int32_t type); 49 static bool IsString(cJSON* jsonObj, const std::string& key); 50 static bool IsInt32(cJSON* jsonObj, const std::string& key); 51 static bool IsBool(cJSON* jsonObj, const std::string& key); 52 static int32_t SetSessionCompatibility(cJSON* jsonObj, const AVSessionBasicInfo& basicInfo); 53 static int32_t SetSessionData(cJSON* jsonObj, const AVSessionBasicInfo& basicInfo); 54 static int32_t SetSessionCapabilitySet(cJSON* jsonObj, const AVSessionBasicInfo& basicInfo); 55 static int32_t GetSessionCompatibility(cJSON* jsonObj, AVSessionBasicInfo& basicInfo); 56 static int32_t GetSessionData(cJSON* jsonObj, AVSessionBasicInfo& basicInfo); 57 static int32_t GetSessionCapabilitySet(cJSON* jsonObj, AVSessionBasicInfo& basicInfo); 58 static int32_t SetSessionDescriptorByCJSON(cJSON* sessionDescriptorItem, 59 const AVSessionDescriptor& descriptor); 60 static int32_t GetSessionDescriptorByCJSON(cJSON* sessionDescriptorItem, 61 AVSessionDescriptor& descriptor); 62 static int32_t SetIntVectorToCJSON(cJSON* jsonObject, std::string key, const std::vector<int32_t>& array); 63 }; 64 } // namespace OHOS::AVSession 65 #endif // OHOS_JSON_UTILS_H 66