• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "camera_device_impl.h"
17 #include "ipipeline_core.h"
18 #include "idevice_manager.h"
19 
20 namespace OHOS::Camera {
CreateCameraDevice(const std::string & cameraId)21 std::shared_ptr<CameraDevice> CameraDevice::CreateCameraDevice(const std::string &cameraId)
22 {
23     // create pipelineCore
24     std::shared_ptr<IPipelineCore> pipelineCore = IPipelineCore::Create();
25     if (pipelineCore == nullptr) {
26         CAMERA_LOGW("create pipeline core failed. [cameraId = %{public}s]", cameraId.c_str());
27         return nullptr;
28     }
29 
30     RetCode rc = pipelineCore->Init();
31     if (rc != RC_OK) {
32         CAMERA_LOGW("pipeline core init failed. [cameraId = %{public}s]", cameraId.c_str());
33         return nullptr;
34     }
35 
36     std::shared_ptr<CameraDeviceImpl> device = std::make_shared<CameraDeviceImpl>(cameraId, pipelineCore);
37     if (device == nullptr) {
38         CAMERA_LOGW("create camera device failed. [cameraId = %{public}s]", cameraId.c_str());
39         return nullptr;
40     }
41     CAMERA_LOGD("create camera device success. [cameraId = %{public}s]", cameraId.c_str());
42 
43     // set deviceManager metadata & dev status callback
44     std::shared_ptr<IDeviceManager> deviceManager = IDeviceManager::GetInstance();
45     if (deviceManager != nullptr) {
46         deviceManager->SetMetaDataCallBack([device](const std::shared_ptr<CameraStandard::CameraMetadata> &metadata) {
47             std::static_pointer_cast<CameraDevice>(device)->OnMetadataChanged(metadata);
48         });
49         deviceManager->SetDevStatusCallBack([device]() {
50             std::static_pointer_cast<CameraDevice>(device)->OnDevStatusErr();
51         });
52     }
53 
54     return device;
55 }
56 } // end namespace OHOS::Camera
57 
58