198e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin/* 298e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin * Copyright (C) 2013 The Android Open Source Project 398e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin * 498e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin * Licensed under the Apache License, Version 2.0 (the "License"); 598e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin * you may not use this file except in compliance with the License. 698e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin * You may obtain a copy of the License at 798e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin * 898e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin * http://www.apache.org/licenses/LICENSE-2.0 998e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin * 1098e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin * Unless required by applicable law or agreed to in writing, software 1198e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin * distributed under the License is distributed on an "AS IS" BASIS, 1298e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1398e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin * See the License for the specific language governing permissions and 1498e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin * limitations under the License. 1598e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin */ 1698e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin 1798e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin// #define LOG_NDEBUG 0 1898e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin#define LOG_TAG "CameraDeviceFactory" 1998e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin#include <utils/Log.h> 2098e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin 2198e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin#include "CameraService.h" 2298e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin#include "CameraDeviceFactory.h" 237b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include "common/CameraDeviceBase.h" 247b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include "device2/Camera2Device.h" 257b82efe7a376c882f8f938e1c41b8311a8cdda4aEino-Ville Talvala#include "device3/Camera3Device.h" 2698e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin 2798e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkinnamespace android { 2898e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin 2998e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkinwp<CameraService> CameraDeviceFactory::sService; 3098e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin 3198e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkinsp<CameraDeviceBase> CameraDeviceFactory::createDevice(int cameraId) { 3298e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin 3398e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin sp<CameraService> svc = sService.promote(); 3498e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin if (svc == 0) { 3598e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin ALOGE("%s: No service registered", __FUNCTION__); 3698e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin return NULL; 3798e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin } 3898e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin 3998e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin int deviceVersion = svc->getDeviceVersion(cameraId, /*facing*/NULL); 4098e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin 4198e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin sp<CameraDeviceBase> device; 4298e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin 4398e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin switch (deviceVersion) { 4498e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin case CAMERA_DEVICE_API_VERSION_2_0: 4598e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin case CAMERA_DEVICE_API_VERSION_2_1: 4698e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin device = new Camera2Device(cameraId); 4798e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin break; 4898e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin case CAMERA_DEVICE_API_VERSION_3_0: 4995dd5ba5bf83716f2eed5fe72366c4212464d710Zhijun He case CAMERA_DEVICE_API_VERSION_3_1: 5095dd5ba5bf83716f2eed5fe72366c4212464d710Zhijun He case CAMERA_DEVICE_API_VERSION_3_2: 51cc776718c0be7c31fe5ab4fc1446d377be60369fRuben Brunk case CAMERA_DEVICE_API_VERSION_3_3: 5298e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin device = new Camera3Device(cameraId); 5398e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin break; 5498e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin default: 5598e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin ALOGE("%s: Camera %d: Unknown HAL device version %d", 5698e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin __FUNCTION__, cameraId, deviceVersion); 5798e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin device = NULL; 5898e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin break; 5998e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin } 6098e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin 6198e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin ALOGV_IF(device != 0, "Created a new camera device for version %d", 6298e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin deviceVersion); 6398e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin 6498e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin return device; 6598e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin} 6698e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin 6798e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkinvoid CameraDeviceFactory::registerService(wp<CameraService> service) { 6898e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin ALOGV("%s: Registered service %p", __FUNCTION__, 6998e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin service.promote().get()); 7098e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin 7198e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin sService = service; 7298e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin} 7398e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin 7498e24724fb77445d4d015a5fec4ecbd5b49abc9bIgor Murashkin}; // namespace android 75