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 HDI_INIT_H_ 17 #define HDI_INIT_H_ 18 19 #include <gst/gst.h> 20 #include <memory> 21 #include <unordered_map> 22 #include <mutex> 23 #include "avcodec_info.h" 24 #include "codec_component_manager.h" 25 #include "hdf_remote_service.h" 26 #include "codec_internal.h" 27 #include "servmgr_hdi.h" 28 #include "i_gst_codec.h" 29 namespace OHOS { 30 namespace Media { 31 struct HdiInfo { 32 std::string name; 33 void *appData; 34 CodecCallbackType *callbacks; 35 std::weak_ptr<IGstCodec> codec; 36 }; 37 class HdiInit { 38 public: 39 static HdiInit &GetInstance(); 40 ~HdiInit(); 41 int32_t GetHandle(CodecComponentType **component, uint32_t &id, HdiInfo info); 42 int32_t FreeHandle(CodecComponentType *component, uint32_t id); 43 std::vector<CapabilityData> GetCapabilitys(); 44 void CodecComponentManagerReset(); 45 void CodecComponentManagerInit(); 46 47 struct HandleInfo { 48 uint32_t id; 49 std::weak_ptr<IGstCodec> codec; 50 }; 51 52 private: 53 HdiInit(); 54 using GetProfileLevelsFunc = std::map<int32_t, std::vector<int32_t>> (*)(CodecCompCapability &hdiCap); 55 static std::string GetCodecName(std::string hdiName); 56 static int32_t GetCodecType(CodecType hdiType); 57 static std::string GetCodecMime(AvCodecRole &role); 58 static std::vector<int32_t> GetCodecFormats(CodecVideoPortCap &port); 59 static std::vector<int32_t> GetOmxFormats(CodecVideoPortCap &port); 60 static std::vector<int32_t> GetBitrateMode(CodecVideoPortCap &port); 61 static std::map<ImgSize, Range> GetMeasuredFrameRate(CodecVideoPortCap &port); 62 static std::map<int32_t, std::vector<int32_t>> GetH264ProfileLevels(CodecCompCapability &hdiCap); 63 static std::map<int32_t, std::vector<int32_t>> GetH265ProfileLevels(CodecCompCapability &hdiCap); 64 static std::map<int32_t, std::vector<int32_t>> GetCodecProfileLevels(CodecCompCapability &hdiCap); 65 void AddHdiCap(CodecCompCapability &hdiCap); 66 void InitCaps(); 67 const static std::unordered_map<int32_t, GetProfileLevelsFunc> PROFILE_LEVEL_FUNC_MAP; 68 std::vector<CapabilityData> capabilitys_; 69 CodecComponentManager *mgr_ = nullptr; 70 std::mutex mutex_; 71 std::map<CodecComponentType *, HandleInfo> handleMap_; 72 }; 73 } 74 } 75 #endif /* HDI_INIT_H_ */ 76