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
21 #include "CameraService.h"
22 #include "CameraDeviceFactory.h"
23 #include "common/CameraDeviceBase.h"
24 #include "device2/Camera2Device.h"
25 #include "device3/Camera3Device.h"
26
27 namespace android {
28
29 wp<CameraService> CameraDeviceFactory::sService;
30
createDevice(int cameraId)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:
49 case CAMERA_DEVICE_API_VERSION_3_1:
50 case CAMERA_DEVICE_API_VERSION_3_2:
51 device = new Camera3Device(cameraId);
52 break;
53 default:
54 ALOGE("%s: Camera %d: Unknown HAL device version %d",
55 __FUNCTION__, cameraId, deviceVersion);
56 device = NULL;
57 break;
58 }
59
60 ALOGV_IF(device != 0, "Created a new camera device for version %d",
61 deviceVersion);
62
63 return device;
64 }
65
registerService(wp<CameraService> service)66 void CameraDeviceFactory::registerService(wp<CameraService> service) {
67 ALOGV("%s: Registered service %p", __FUNCTION__,
68 service.promote().get());
69
70 sService = service;
71 }
72
73 }; // namespace android
74