1 /*
2  * Copyright (C) 2023 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 #include "hcodec_loader.h"
16 #include <dlfcn.h>
17 #include "avcodec_errors.h"
18 #include "avcodec_log.h"
19 
20 namespace OHOS {
21 namespace MediaAVCodec {
22 namespace {
23 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_FRAMEWORK, "HCodecLoader"};
24 const char *HCODEC_LIB_PATH = "libhcodec.z.so";
25 const char *HCODEC_CREATE_FUNC_NAME = "CreateHCodecByName";
26 const char *HCODEC_GETCAPS_FUNC_NAME = "GetHCodecCapabilityList";
27 } // namespace
CreateByName(const std::string & name)28 std::shared_ptr<CodecBase> HCodecLoader::CreateByName(const std::string &name)
29 {
30     HCodecLoader &loader = GetInstance();
31     CHECK_AND_RETURN_RET_LOG(loader.Init() == AVCS_ERR_OK, nullptr, "Create codec by name failed: init error");
32     return loader.Create(name);
33 }
34 
GetCapabilityList(std::vector<CapabilityData> & caps)35 int32_t HCodecLoader::GetCapabilityList(std::vector<CapabilityData> &caps)
36 {
37     HCodecLoader &loader = GetInstance();
38     CHECK_AND_RETURN_RET_LOG(loader.Init() == AVCS_ERR_OK, AVCS_ERR_UNKNOWN, "Get capability failed: init error");
39     return loader.GetCaps(caps);
40 }
41 
HCodecLoader()42 HCodecLoader::HCodecLoader() : VideoCodecLoader(HCODEC_LIB_PATH, HCODEC_CREATE_FUNC_NAME, HCODEC_GETCAPS_FUNC_NAME) {}
43 
GetInstance()44 HCodecLoader &HCodecLoader::GetInstance()
45 {
46     static HCodecLoader loader;
47     return loader;
48 }
49 } // namespace MediaAVCodec
50 } // namespace OHOS