• 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 "input/camera_manager_for_sys.h"
17 
18 #include "camera_log.h"
19 #include "camera_util.h"
20 #include "input/camera_manager.h"
21 #include "session/aperture_video_session.h"
22 #include "session/light_painting_session.h"
23 #include "session/quick_shot_photo_session.h"
24 #include "session/capture_session.h"
25 #include "session/fluorescence_photo_session.h"
26 #include "session/high_res_photo_session.h"
27 #include "session/macro_photo_session.h"
28 #include "session/macro_video_session.h"
29 #include "session/night_session.h"
30 #include "session/panorama_session.h"
31 #include "session/photo_session_for_sys.h"
32 #include "session/portrait_session.h"
33 #include "session/profession_session.h"
34 #include "session/secure_camera_session_for_sys.h"
35 #include "session/slow_motion_session.h"
36 #include "session/time_lapse_photo_session.h"
37 #include "session/video_session_for_sys.h"
38 
39 using namespace std;
40 namespace OHOS {
41 namespace CameraStandard {
42 sptr<CameraManagerForSys> CameraManagerForSys::g_cameraManagerForSys = nullptr;
43 std::mutex CameraManagerForSys::g_sysInstanceMutex;
44 
CameraManagerForSys()45 CameraManagerForSys::CameraManagerForSys()
46 {
47     MEDIA_INFO_LOG("CameraManagerForSys::CameraManagerForSys construct enter");
48 }
49 
~CameraManagerForSys()50 CameraManagerForSys::~CameraManagerForSys()
51 {
52     MEDIA_INFO_LOG("CameraManagerForSys::~CameraManagerForSys() called");
53 }
54 
GetInstance()55 sptr<CameraManagerForSys>& CameraManagerForSys::GetInstance()
56 {
57     std::lock_guard<std::mutex> lock(g_sysInstanceMutex);
58     if (CameraManagerForSys::g_cameraManagerForSys == nullptr) {
59         MEDIA_INFO_LOG("Initializing camera manager for first time!");
60         CameraManagerForSys::g_cameraManagerForSys = new CameraManagerForSys();
61     }
62     return CameraManagerForSys::g_cameraManagerForSys;
63 }
64 
CreateCaptureSessionForSysImpl(SceneMode mode,sptr<ICaptureSession> session)65 sptr<CaptureSessionForSys> CameraManagerForSys::CreateCaptureSessionForSysImpl(SceneMode mode,
66     sptr<ICaptureSession> session)
67 {
68     switch (mode) {
69         case SceneMode::VIDEO:
70             return new (std::nothrow) VideoSessionForSys(session);
71         case SceneMode::CAPTURE:
72             return new (std::nothrow) PhotoSessionForSys(session);
73         case SceneMode::PORTRAIT:
74             return new (std::nothrow) PortraitSession(session);
75         case SceneMode::PROFESSIONAL_VIDEO:
76         case SceneMode::PROFESSIONAL_PHOTO:
77             return new (std::nothrow) ProfessionSession(session, CameraManager::GetInstance()->GetCameraDeviceList());
78         case SceneMode::NIGHT:
79             return new (std::nothrow) NightSession(session);
80         case SceneMode::CAPTURE_MACRO:
81             return new (std::nothrow) MacroPhotoSession(session);
82         case SceneMode::VIDEO_MACRO:
83             return new (std::nothrow) MacroVideoSession(session);
84         case SceneMode::SLOW_MOTION:
85             return new (std::nothrow) SlowMotionSession(session);
86         case SceneMode::HIGH_RES_PHOTO:
87             return new (std::nothrow) HighResPhotoSession(session);
88         case SceneMode::SECURE:
89             return new (std::nothrow) SecureCameraSessionForSys(session);
90         case SceneMode::QUICK_SHOT_PHOTO:
91             return new (std::nothrow) QuickShotPhotoSession(session);
92         case SceneMode::APERTURE_VIDEO:
93             return new (std::nothrow) ApertureVideoSession(session);
94         case SceneMode::PANORAMA_PHOTO:
95             return new (std::nothrow) PanoramaSession(session);
96         case SceneMode::LIGHT_PAINTING:
97             return new (std::nothrow) LightPaintingSession(session);
98         case SceneMode::TIMELAPSE_PHOTO:
99             return new(std::nothrow) TimeLapsePhotoSession(session,
100                 CameraManager::GetInstance()->GetCameraDeviceList());
101         case SceneMode::FLUORESCENCE_PHOTO:
102             return new(std::nothrow) FluorescencePhotoSession(session);
103         default:
104             return new (std::nothrow) CaptureSessionForSys(session);
105     }
106 }
107 
CreateCaptureSessionForSys(SceneMode mode)108 sptr<CaptureSessionForSys> CameraManagerForSys::CreateCaptureSessionForSys(SceneMode mode)
109 {
110     sptr<CaptureSessionForSys> session = nullptr;
111     CreateCaptureSessionForSys(session, mode);
112     return session;
113 }
114 
CreateCaptureSessionForSys(sptr<CaptureSessionForSys> & pCaptureSession,SceneMode mode)115 int32_t CameraManagerForSys::CreateCaptureSessionForSys(sptr<CaptureSessionForSys>& pCaptureSession, SceneMode mode)
116 {
117     MEDIA_DEBUG_LOG("CameraManagerForSys::CreateCaptureSessionForSys is called");
118     CAMERA_SYNC_TRACE;
119     sptr<ICaptureSession> session = nullptr;
120     sptr<CaptureSessionForSys> captureSessionForSys = nullptr;
121     int32_t retCode = CameraErrorCode::SUCCESS;
122     retCode = CameraManager::GetInstance()->CreateCaptureSessionFromService(session, mode);
123     CHECK_RETURN_RET_ELOG(retCode != CameraErrorCode::SUCCESS, retCode,
124         "CreateCaptureSessionForSys failed to CreateCaptureSessionFromService with retCode is %{public}d", retCode);
125     captureSessionForSys = CreateCaptureSessionForSysImpl(mode, session);
126     CHECK_RETURN_RET_ELOG(captureSessionForSys == nullptr, CameraErrorCode::SERVICE_FATL_ERROR,
127         "CreateCaptureSessionForSys failed to new captureSessionForSys!");
128     captureSessionForSys->SetMode(mode);
129     pCaptureSession = captureSessionForSys;
130     return CameraErrorCode::SUCCESS;
131 }
132 
CreateDepthDataOutput(DepthProfile & depthProfile,sptr<IBufferProducer> & surface,sptr<DepthDataOutput> * pDepthDataOutput)133 int CameraManagerForSys::CreateDepthDataOutput(DepthProfile& depthProfile, sptr<IBufferProducer> &surface,
134     sptr<DepthDataOutput>* pDepthDataOutput)
135 {
136     CAMERA_SYNC_TRACE;
137     sptr<IStreamDepthData> streamDepthData = nullptr;
138     sptr<DepthDataOutput> depthDataOutput = nullptr;
139     int32_t retCode = CameraErrorCode::SUCCESS;
140     retCode = CameraManager::GetInstance()->GetStreamDepthDataFromService(depthProfile, surface, streamDepthData);
141     if (retCode == CameraErrorCode::SUCCESS) {
142         depthDataOutput = new(std::nothrow) DepthDataOutput(surface);
143         CHECK_RETURN_RET(depthDataOutput == nullptr, CameraErrorCode::SERVICE_FATL_ERROR);
144         depthDataOutput->SetStream(streamDepthData);
145     } else {
146         MEDIA_ERR_LOG("GetStreamDepthDataFromService failed! retCode = %{public}d", retCode);
147         return retCode;
148     }
149     depthDataOutput->SetDepthProfile(depthProfile);
150     *pDepthDataOutput = depthDataOutput;
151     return CameraErrorCode::SUCCESS;
152 }
153 
154 } // namespace CameraStandard
155 } // namespace OHOS
156