• 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 
16 #include "dynamic_loader/camera_napi_ex_manager.h"
17 
18 #include "camera_log.h"
19 
20 namespace OHOS {
21 namespace CameraStandard {
22 std::shared_ptr<CameraNapiExProxy> CameraNapiExManager::cameraNapiExProxy_ = nullptr;
23 std::vector<CameraNapiExProxyUserType> CameraNapiExManager::userList_ = {};
24 std::mutex CameraNapiExManager::mutex_;
25 
GetCameraNapiExProxy(CameraNapiExProxyUserType type)26 std::shared_ptr<CameraNapiExProxy> CameraNapiExManager::GetCameraNapiExProxy(CameraNapiExProxyUserType type)
27 {
28     CAMERA_SYNC_TRACE;
29     MEDIA_DEBUG_LOG("CameraNapiExManager::GetCameraNapiExProxy is called");
30     std::lock_guard<std::mutex> lock(mutex_);
31     if (cameraNapiExProxy_ == nullptr) {
32         cameraNapiExProxy_ = CameraNapiExProxy::GetCameraNapiExProxy();
33         CHECK_RETURN_RET_ELOG(cameraNapiExProxy_ == nullptr, nullptr,
34             "get cameraNapiExProxy failed");
35     }
36     auto item = std::find(userList_.begin(), userList_.end(), type);
37     if (item == userList_.end()) {
38         userList_.push_back(type);
39     }
40     return cameraNapiExProxy_;
41 }
42 
FreeCameraNapiExProxy(CameraNapiExProxyUserType type)43 void CameraNapiExManager::FreeCameraNapiExProxy(CameraNapiExProxyUserType type)
44 {
45     MEDIA_DEBUG_LOG("CameraNapiExManager::FreeCameraNapiExProxy is called");
46     std::lock_guard<std::mutex> lock(mutex_);
47     auto item = std::find(userList_.begin(), userList_.end(), type);
48     if (item != userList_.end()) {
49         userList_.erase(item);
50     }
51     if (userList_.empty() && cameraNapiExProxy_ != nullptr) {
52         cameraNapiExProxy_ = nullptr;
53     }
54 }
55 } // namespace CameraStandard
56 } // namespace OHOS