forked from rbraken/wetab-ICS-device-tree
/
CameraFactory.cpp
151 lines (122 loc) · 4.31 KB
/
CameraFactory.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Contains implementation of a class CameraFactory that manages cameras
* available
*/
#define LOG_NDEBUG 0
#define LOG_TAG "Camera_Factory"
#include <cutils/log.h>
#include <cutils/properties.h>
#include "CameraFactory.h"
extern camera_module_t HAL_MODULE_INFO_SYM;
/* A global instance of CameraFactory is statically instantiated and
* initialized when camera HAL is loaded.
*/
android::CameraFactory gCameraFactory;
namespace android {
CameraFactory::CameraFactory()
: mCamera(NULL)
{
LOGD("CameraFactory::CameraFactory");
}
CameraFactory::~CameraFactory()
{
LOGD("CameraFactory::~CameraFactory");
if (mCamera != NULL) {
delete mCamera;
mCamera = NULL;
}
}
/****************************************************************************
* Camera HAL API handlers.
*
* Each handler simply verifies existence of an appropriate Camera
* instance, and dispatches the call to that instance.
*
***************************************************************************/
int CameraFactory::cameraDeviceOpen(const hw_module_t* module,int camera_id, hw_device_t** device)
{
LOGD("CameraFactory::cameraDeviceOpen: id = %d", camera_id);
*device = NULL;
if (camera_id < 0 || camera_id >= getCameraNum()) {
LOGE("%s: Camera id %d is out of bounds (%d)",
__FUNCTION__, camera_id, getCameraNum());
return -EINVAL;
}
if (!mCamera)
mCamera = new CameraHardware(module);
return mCamera->connectCamera(device);
}
/* Returns the number of available cameras */
int CameraFactory::getCameraNum()
{
LOGD("CameraFactory::getCameraNum");
return 1; //RvdB
}
int CameraFactory::getCameraInfo(int camera_id, struct camera_info* info)
{
LOGD("CameraFactory::getCameraInfo: id = %d,info = %p", camera_id,info);
if (camera_id < 0 || camera_id >= getCameraNum()) {
LOGE("%s: Camera id %d is out of bounds (%d)",
__FUNCTION__, camera_id, getCameraNum());
return -EINVAL;
}
LOGD("CameraFactory::getCameraInfo: about to fetch info");
return CameraHardware::getCameraInfo(info);
}
/****************************************************************************
* Camera HAL API callbacks.
***************************************************************************/
int CameraFactory::device_open(const hw_module_t* module,
const char* name,
hw_device_t** device)
{
LOGD("CameraFactory::device_open: name = %s", name);
/*
* Simply verify the parameters, and dispatch the call inside the
* CameraFactory instance.
*/
if (module != &HAL_MODULE_INFO_SYM.common) {
LOGE("%s: Invalid module %p expected %p",
__FUNCTION__, module, &HAL_MODULE_INFO_SYM.common);
return -EINVAL;
}
if (name == NULL) {
LOGE("%s: NULL name is not expected here", __FUNCTION__);
return -EINVAL;
}
return gCameraFactory.cameraDeviceOpen(module,atoi(name), device);
}
int CameraFactory::get_number_of_cameras(void)
{
LOGD("CameraFactory::get_number_of_cameras");
return gCameraFactory.getCameraNum();
}
int CameraFactory::get_camera_info(int camera_id,
struct camera_info* info)
{
LOGD("CameraFactory::get_camera_info");
return gCameraFactory.getCameraInfo(camera_id, info);
}
/********************************************************************************
* Initializer for the static member structure.
*******************************************************************************/
/* Entry point for camera HAL API. */
struct hw_module_methods_t CameraFactory::mCameraModuleMethods = {
open: CameraFactory::device_open
};
}; /* namespace android */