• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 "avc_encoder_loader.h"
16 #include <dlfcn.h>
17 #include "avcodec_errors.h"
18 #include "avcodec_log.h"
19 #include "avc_encoder.h"
20 
21 namespace OHOS {
22 namespace MediaAVCodec {
23 namespace {
24 using AvcEncoder = Codec::AvcEncoder;
25 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_FRAMEWORK, "AvcEncoderLoader"};
26 const char *AVC_ENCODER_LIB_PATH = "libavc_encoder.z.so";
27 const char *AVC_ENCODER_CREATE_FUNC_NAME = "CreateAvcEncoderByName";
28 const char *AVC_ENCODER_GETCAPS_FUNC_NAME = "GetAvcEncoderCapabilityList";
29 } // namespace
30 
CreateByName(const std::string & name)31 std::shared_ptr<CodecBase> AvcEncoderLoader::CreateByName(const std::string &name)
32 {
33     AvcEncoderLoader &loader = GetInstance();
34 
35     std::lock_guard<std::mutex> lock(loader.mutex_);
36     CHECK_AND_RETURN_RET_LOG(loader.Init() == AVCS_ERR_OK, nullptr, "Create codec by name failed: init error");
37     return loader.Create(name);
38 }
39 
GetCapabilityList(std::vector<CapabilityData> & caps)40 int32_t AvcEncoderLoader::GetCapabilityList(std::vector<CapabilityData> &caps)
41 {
42     AvcEncoderLoader &loader = GetInstance();
43 
44     std::lock_guard<std::mutex> lock(loader.mutex_);
45     CHECK_AND_RETURN_RET_LOG(loader.Init() == AVCS_ERR_OK, AVCS_ERR_UNKNOWN, "Get capability failed: init error");
46     return loader.GetCaps(caps);
47 }
48 
AvcEncoderLoader()49 AvcEncoderLoader::AvcEncoderLoader() : VideoCodecLoader(AVC_ENCODER_LIB_PATH,
50     AVC_ENCODER_CREATE_FUNC_NAME, AVC_ENCODER_GETCAPS_FUNC_NAME) {}
51 
CloseLibrary()52 void AvcEncoderLoader::CloseLibrary()
53 {
54     if (avcEncoderCount_ != 0) {
55         return;
56     }
57     Close();
58 }
59 
GetInstance()60 AvcEncoderLoader &AvcEncoderLoader::GetInstance()
61 {
62     static AvcEncoderLoader loader;
63     return loader;
64 }
65 } // namespace MediaAVCodec
66 } // namespace OHOS