• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 #include "mode/mode_manager.h"
17 
18 
19 #include "camera_util.h"
20 #include "ipc_skeleton.h"
21 #include "iservice_registry.h"
22 #include "camera_log.h"
23 #include "system_ability_definition.h"
24 #include "camera_error_code.h"
25 #include "icamera_util.h"
26 #include "device_manager_impl.h"
27 
28 using namespace std;
29 namespace OHOS {
30 namespace CameraStandard {
31 sptr<ModeManager> ModeManager::modeManager_;
32 
ModeManager()33 ModeManager::ModeManager()
34 {
35     Init();
36 }
37 
~ModeManager()38 ModeManager::~ModeManager()
39 {
40     serviceProxy_ = nullptr;
41     ModeManager::modeManager_ = nullptr;
42 }
43 
GetInstance()44 sptr<ModeManager> &ModeManager::GetInstance()
45 {
46     if (ModeManager::modeManager_ == nullptr) {
47         MEDIA_INFO_LOG("Initializing mode manager for first time!");
48         ModeManager::modeManager_ = new(std::nothrow) ModeManager();
49         if (ModeManager::modeManager_ == nullptr) {
50             MEDIA_ERR_LOG("Failed to new ModeManager");
51         }
52     }
53     return ModeManager::modeManager_;
54 }
55 
Init()56 void ModeManager::Init()
57 {
58     CAMERA_SYNC_TRACE;
59     sptr<IRemoteObject> object = nullptr;
60     MEDIA_DEBUG_LOG("ModeManager:init srart");
61     auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
62     if (samgr == nullptr) {
63         MEDIA_ERR_LOG("ModeManager get System ability manager failed");
64         return;
65     }
66     MEDIA_DEBUG_LOG("ModeManager:GetSystemAbility srart");
67     object = samgr->GetSystemAbility(CAMERA_SERVICE_ID);
68     if (object == nullptr) {
69         MEDIA_ERR_LOG("object is null");
70         return;
71     }
72     serviceProxy_ = iface_cast<ICameraService>(object);
73     if (serviceProxy_ == nullptr) {
74         MEDIA_ERR_LOG("serviceProxy_ is null");
75         return;
76     }
77     return;
78 }
79 
CreateCaptureSession(CameraMode mode)80 sptr<CaptureSession> ModeManager::CreateCaptureSession(CameraMode mode)
81 {
82     CAMERA_SYNC_TRACE;
83     sptr<ICaptureSession> session = nullptr;
84     sptr<CaptureSession> captureSession = nullptr;
85 
86     int32_t retCode = CAMERA_OK;
87     if (serviceProxy_ == nullptr) {
88         MEDIA_ERR_LOG("serviceProxy_ is null");
89         return nullptr;
90     }
91     MEDIA_ERR_LOG("ModeManager CreateCaptureSession E");
92     retCode = serviceProxy_->CreateCaptureSession(session);
93     MEDIA_ERR_LOG("ModeManager CreateCaptureSession X, %{public}d", retCode);
94     if (retCode == CAMERA_OK && session != nullptr) {
95         switch (mode) {
96             case CameraMode::PORTRAIT:
97                 captureSession = new(std::nothrow) PortraitSession(session);
98                 break;
99             default:
100                 captureSession = new(std::nothrow) CaptureSession(session);
101                 break;
102         }
103     } else {
104         MEDIA_ERR_LOG("Failed to get capture session object from hcamera service!, %{public}d", retCode);
105         return nullptr;
106     }
107     return captureSession;
108 }
109 
GetSupportedModes(sptr<CameraDevice> & camera)110 std::vector<CameraMode> ModeManager::GetSupportedModes(sptr<CameraDevice>& camera)
111 {
112     vector<CameraMode> objectModes = {};
113     return objectModes;
114 }
115 
GetSupportedOutputCapability(sptr<CameraDevice> & camera,CameraMode modeName)116 sptr<CameraOutputCapability> ModeManager::GetSupportedOutputCapability(sptr<CameraDevice>& camera,
117     CameraMode modeName)
118 {
119     sptr<CameraOutputCapability> cameraOutputCapability = nullptr;
120     return cameraOutputCapability;
121 }
122 } // namespace CameraStandard
123 } // namespace OHOS
124