blob: 6dc5f51bd61a213681d36abd3672380fa6b8dd00
1 | /* |
2 | * Copyright (C) 2011 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 "CameraProperties " |
19 | #include <utils/threads.h> |
20 | |
21 | #include "DebugUtils.h" |
22 | #include "CameraProperties.h" |
23 | |
24 | #define CAMERA_ROOT "CameraRoot" |
25 | #define CAMERA_INSTANCE "CameraInstance" |
26 | |
27 | namespace android { |
28 | |
29 | extern "C" void loadCaps(int camera_id, CameraProperties::Properties* params) |
30 | {} |
31 | |
32 | /********************************************************* |
33 | CameraProperties - public function implemetation |
34 | **********************************************************/ |
35 | |
36 | CameraProperties::CameraProperties() : mCamerasSupported(0) |
37 | { |
38 | LOG_FUNCTION_NAME; |
39 | |
40 | mCamerasSupported = 0; |
41 | mInitialized = 0; |
42 | |
43 | LOG_FUNCTION_NAME_EXIT; |
44 | } |
45 | |
46 | CameraProperties::~CameraProperties() |
47 | { |
48 | LOG_FUNCTION_NAME; |
49 | |
50 | LOG_FUNCTION_NAME_EXIT; |
51 | } |
52 | |
53 | // Initializes the CameraProperties class |
54 | status_t CameraProperties::initialize(int cameraid) |
55 | { |
56 | LOG_FUNCTION_NAME; |
57 | |
58 | status_t ret = NO_ERROR; |
59 | |
60 | Mutex::Autolock lock(mLock); |
61 | |
62 | CAMHAL_LOGDB("%s, mCamerasSupported=%d\n", |
63 | mInitialized?"initialized":"no initialize", mCamerasSupported); |
64 | |
65 | if( !mInitialized ){ |
66 | |
67 | int temp = CameraAdapter_CameraNum(); |
68 | for ( int i = 0; i < temp; i++) { |
69 | mInitialized |= (1 << cameraid); |
70 | mCamerasSupported ++; |
71 | mCameraProps[i].set(CameraProperties::CAMERA_SENSOR_INDEX, i); |
72 | loadCaps(i, &mCameraProps[i]); |
73 | mCameraProps[i].dump(); |
74 | } |
75 | |
76 | }else{ |
77 | |
78 | if(!strcmp( mCameraProps[cameraid].get(CameraProperties::RELOAD_WHEN_OPEN), "1")){ |
79 | CAMHAL_LOGDB("cameraid %d reload\n", cameraid); |
80 | loadCaps(cameraid, &mCameraProps[cameraid]); |
81 | }else{ |
82 | CAMHAL_LOGDA("device don't need reload\n"); |
83 | } |
84 | |
85 | } |
86 | |
87 | LOG_FUNCTION_NAME_EXIT; |
88 | return ret; |
89 | |
90 | } |
91 | |
92 | ///Loads all the Camera related properties |
93 | status_t CameraProperties::loadProperties() |
94 | { |
95 | LOG_FUNCTION_NAME; |
96 | |
97 | status_t ret = NO_ERROR; |
98 | CAMHAL_LOGDA("this func delete!!!\n"); |
99 | return ret; |
100 | } |
101 | |
102 | // Returns the number of Cameras found |
103 | int CameraProperties::camerasSupported() |
104 | { |
105 | LOG_FUNCTION_NAME; |
106 | return mCamerasSupported; |
107 | } |
108 | |
109 | // Returns the properties class for a specific Camera |
110 | // Each value is indexed by the CameraProperties::CameraPropertyIndex enum |
111 | int CameraProperties::getProperties(int cameraIndex, CameraProperties::Properties** properties) |
112 | { |
113 | LOG_FUNCTION_NAME; |
114 | |
115 | if((unsigned int)cameraIndex >= mCamerasSupported) |
116 | { |
117 | LOG_FUNCTION_NAME_EXIT; |
118 | return -EINVAL; |
119 | } |
120 | |
121 | *properties = mCameraProps+cameraIndex; |
122 | |
123 | LOG_FUNCTION_NAME_EXIT; |
124 | return 0; |
125 | } |
126 | |
127 | ////////////////////////////////////////////////////////////////////////// |
128 | ////////////////////////////////////////////////////////////////////////// |
129 | ////////CameraProperties::Properties function///////////////////////////// |
130 | ////////////////////////////////////////////////////////////////////////// |
131 | ////////////////////////////////////////////////////////////////////////// |
132 | |
133 | ssize_t CameraProperties::Properties::set(const char *prop, const char *value) |
134 | { |
135 | if(!prop) |
136 | return -EINVAL; |
137 | if(!value) |
138 | value = DEFAULT_VALUE; |
139 | |
140 | return mProperties->replaceValueFor(String8(prop), String8(value)); |
141 | } |
142 | |
143 | ssize_t CameraProperties::Properties::set(const char *prop, int value) |
144 | { |
145 | char s_val[30]; |
146 | |
147 | sprintf(s_val, "%d", value); |
148 | |
149 | return set(prop, s_val); |
150 | } |
151 | |
152 | const char* CameraProperties::Properties::get(const char * prop) |
153 | { |
154 | String8 value = mProperties->valueFor(String8(prop)); |
155 | return value.string(); |
156 | } |
157 | |
158 | void CameraProperties::Properties::dump() |
159 | { |
160 | for (size_t i = 0; i < mProperties->size(); i++) |
161 | { |
162 | CAMHAL_LOGVB("%s = %s\n", |
163 | mProperties->keyAt(i).string(), |
164 | mProperties->valueAt(i).string()); |
165 | } |
166 | } |
167 | |
168 | const char* CameraProperties::Properties::keyAt(unsigned int index) |
169 | { |
170 | if(index < mProperties->size()) |
171 | { |
172 | return mProperties->keyAt(index).string(); |
173 | } |
174 | return NULL; |
175 | } |
176 | |
177 | const char* CameraProperties::Properties::valueAt(unsigned int index) |
178 | { |
179 | if(index < mProperties->size()) |
180 | { |
181 | return mProperties->valueAt(index).string(); |
182 | } |
183 | return NULL; |
184 | } |
185 | |
186 | ////////////////////////////////////////////////////////////////////////// |
187 | ////////////////////////////////////////////////////////////////////////// |
188 | ///////////CameraProperties::const char initialized/////////////////////// |
189 | ////////////////////////////////////////////////////////////////////////// |
190 | ////////////////////////////////////////////////////////////////////////// |
191 | const char CameraProperties::PIXEL_FORMAT_RGB24[] = "rgb24"; |
192 | const char CameraProperties::RELOAD_WHEN_OPEN[]="prop-reload-key"; |
193 | const char CameraProperties::DEVICE_NAME[] = "device_name"; |
194 | |
195 | const char CameraProperties::DEFAULT_VALUE[] = ""; |
196 | const char CameraProperties::PARAMS_DELIMITER []= ","; |
197 | ////////////////////////////////////////////////////////////////////////// |
198 | ////////////////////////////////////////////////////////////////////////// |
199 | ///////////CameraProperties::const char initialize finished/////////////// |
200 | ////////////////////////////////////////////////////////////////////////// |
201 | ////////////////////////////////////////////////////////////////////////// |
202 | |
203 | }; |
204 |