Igor Murashkin | 98e2472 | 2013-06-19 19:51:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | // #define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "CameraDeviceFactory" |
| 19 | #include <utils/Log.h> |
| 20 | |
Igor Murashkin | 98e2472 | 2013-06-19 19:51:04 -0700 | [diff] [blame] | 21 | #include "CameraService.h" |
| 22 | #include "CameraDeviceFactory.h" |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 23 | #include "common/CameraDeviceBase.h" |
| 24 | #include "device2/Camera2Device.h" |
| 25 | #include "device3/Camera3Device.h" |
Igor Murashkin | 98e2472 | 2013-06-19 19:51:04 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | wp<CameraService> CameraDeviceFactory::sService; |
| 30 | |
| 31 | sp<CameraDeviceBase> CameraDeviceFactory::createDevice(int cameraId) { |
| 32 | |
| 33 | sp<CameraService> svc = sService.promote(); |
| 34 | if (svc == 0) { |
| 35 | ALOGE("%s: No service registered", __FUNCTION__); |
| 36 | return NULL; |
| 37 | } |
| 38 | |
| 39 | int deviceVersion = svc->getDeviceVersion(cameraId, /*facing*/NULL); |
| 40 | |
| 41 | sp<CameraDeviceBase> device; |
| 42 | |
| 43 | switch (deviceVersion) { |
| 44 | case CAMERA_DEVICE_API_VERSION_2_0: |
| 45 | case CAMERA_DEVICE_API_VERSION_2_1: |
| 46 | device = new Camera2Device(cameraId); |
| 47 | break; |
| 48 | case CAMERA_DEVICE_API_VERSION_3_0: |
Zhijun He | 95dd5ba | 2014-03-26 18:18:00 -0700 | [diff] [blame] | 49 | case CAMERA_DEVICE_API_VERSION_3_1: |
| 50 | case CAMERA_DEVICE_API_VERSION_3_2: |
Ruben Brunk | cc77671 | 2015-02-17 20:18:47 -0800 | [diff] [blame^] | 51 | case CAMERA_DEVICE_API_VERSION_3_3: |
Igor Murashkin | 98e2472 | 2013-06-19 19:51:04 -0700 | [diff] [blame] | 52 | device = new Camera3Device(cameraId); |
| 53 | break; |
| 54 | default: |
| 55 | ALOGE("%s: Camera %d: Unknown HAL device version %d", |
| 56 | __FUNCTION__, cameraId, deviceVersion); |
| 57 | device = NULL; |
| 58 | break; |
| 59 | } |
| 60 | |
| 61 | ALOGV_IF(device != 0, "Created a new camera device for version %d", |
| 62 | deviceVersion); |
| 63 | |
| 64 | return device; |
| 65 | } |
| 66 | |
| 67 | void CameraDeviceFactory::registerService(wp<CameraService> service) { |
| 68 | ALOGV("%s: Registered service %p", __FUNCTION__, |
| 69 | service.promote().get()); |
| 70 | |
| 71 | sService = service; |
| 72 | } |
| 73 | |
| 74 | }; // namespace android |