hardware/libcamera
Révision | bbbfb37e9ab96a03d91d439a9a5aeae7251ee1e6 (tree) |
---|---|
l'heure | 2013-07-07 01:23:53 |
Auteur | Alberto Panizzo <alberto@amar...> |
Commiter | Alberto Panizzo |
Allow to set camera orientation (not facing) from cfg file
Signed-off-by: Alberto Panizzo <alberto@amarulasolutions.com>
@@ -43,6 +43,7 @@ CameraFactory::CameraFactory() | ||
43 | 43 | ALOGD("CameraFactory::CameraFactory"); |
44 | 44 | mCamera = NULL; |
45 | 45 | mCameraDevices = NULL; |
46 | + mCameraFacing = NULL; | |
46 | 47 | mCameraOrientation = NULL; |
47 | 48 | parseConfig(CONFIG_FILE); |
48 | 49 | } |
@@ -99,7 +100,8 @@ int CameraFactory::getCameraInfo(int camera_id, struct camera_info* info) | ||
99 | 100 | return -EINVAL; |
100 | 101 | } |
101 | 102 | |
102 | - return CameraHardware::getCameraInfo(info, mCameraOrientation[camera_id]); | |
103 | + return CameraHardware::getCameraInfo(info, mCameraFacing[camera_id], | |
104 | + mCameraOrientation[camera_id]); | |
103 | 105 | } |
104 | 106 | |
105 | 107 | // Parse a simple configuration file |
@@ -112,6 +114,7 @@ void CameraFactory::parseConfig(const char* configFile) | ||
112 | 114 | char line[128]; |
113 | 115 | char arg1[128]; |
114 | 116 | char arg2[128]; |
117 | + int arg3; | |
115 | 118 | |
116 | 119 | while (fgets(line, sizeof line, config) != NULL) { |
117 | 120 | int lineStart = strspn(line, " \t\n\v" ); |
@@ -119,12 +122,14 @@ void CameraFactory::parseConfig(const char* configFile) | ||
119 | 122 | if (line[lineStart] == '#') |
120 | 123 | continue; |
121 | 124 | |
122 | - sscanf(line, "%s %s", arg1, arg2); | |
125 | + sscanf(line, "%s %s %d", arg1, arg2, &arg3); | |
126 | + if (arg3 != 0 && arg3 != 90 && arg3 != 180 && arg3 != 270) | |
127 | + arg3 = 0; | |
123 | 128 | |
124 | 129 | if (strcmp(arg1, "front")) { |
125 | - newCameraConfig(CAMERA_FACING_FRONT, arg2); | |
130 | + newCameraConfig(CAMERA_FACING_FRONT, arg2, arg3); | |
126 | 131 | } else if (strcmp(arg1, "back")) { |
127 | - newCameraConfig(CAMERA_FACING_BACK, arg2); | |
132 | + newCameraConfig(CAMERA_FACING_BACK, arg2, arg3); | |
128 | 133 | } else { |
129 | 134 | ALOGD("CameraFactory::parseConfig: Unrecognized config line '%s'", line); |
130 | 135 | } |
@@ -133,17 +138,17 @@ void CameraFactory::parseConfig(const char* configFile) | ||
133 | 138 | ALOGD("%s not found, using camera configuration defaults", CONFIG_FILE); |
134 | 139 | if (access(DEFAULT_DEVICE_BACK, F_OK) != -1){ |
135 | 140 | ALOGD("Found device %s", DEFAULT_DEVICE_BACK); |
136 | - newCameraConfig(CAMERA_FACING_BACK, DEFAULT_DEVICE_BACK); | |
141 | + newCameraConfig(CAMERA_FACING_BACK, DEFAULT_DEVICE_BACK, 0); | |
137 | 142 | } |
138 | 143 | if (access(DEFAULT_DEVICE_FRONT, F_OK) != -1){ |
139 | 144 | ALOGD("Found device %s", DEFAULT_DEVICE_FRONT); |
140 | - newCameraConfig(CAMERA_FACING_FRONT, DEFAULT_DEVICE_FRONT); | |
145 | + newCameraConfig(CAMERA_FACING_FRONT, DEFAULT_DEVICE_FRONT, 0); | |
141 | 146 | } |
142 | 147 | } |
143 | 148 | } |
144 | 149 | |
145 | 150 | // Although realloc could be a costly operation, we only execute this function usually 2 times |
146 | -void CameraFactory::newCameraConfig(int facing, const char* location) | |
151 | +void CameraFactory::newCameraConfig(int facing, const char* location, int orientation) | |
147 | 152 | { |
148 | 153 | // Keep track of cameras |
149 | 154 | mCameraNum++; |
@@ -151,13 +156,17 @@ void CameraFactory::newCameraConfig(int facing, const char* location) | ||
151 | 156 | // Grow the information arrays |
152 | 157 | mCamera = (CameraHardware**) realloc(mCamera, mCameraNum * sizeof(CameraHardware*)); |
153 | 158 | mCameraDevices = (char**) realloc(mCameraDevices, mCameraNum * sizeof(char*)); |
159 | + mCameraFacing = (int*) realloc(mCameraFacing, mCameraNum * sizeof(int)); | |
154 | 160 | mCameraOrientation = (int*) realloc(mCameraOrientation, mCameraNum * sizeof(int)); |
155 | 161 | |
156 | 162 | // Store the values for each camera_id |
157 | 163 | mCamera[mCameraNum - 1] = NULL; |
158 | 164 | mCameraDevices[mCameraNum - 1] = strdup(location); |
159 | - mCameraOrientation[mCameraNum - 1] = facing; | |
160 | - ALOGD("CameraFactory::newCameraConfig: %d -> %s", mCameraOrientation[mCameraNum - 1], mCameraDevices[mCameraNum - 1]); | |
165 | + mCameraFacing[mCameraNum - 1] = facing; | |
166 | + mCameraOrientation[mCameraNum - 1] = orientation; | |
167 | + ALOGD("CameraFactory::newCameraConfig: %d -> %s (%d)", | |
168 | + mCameraFacing[mCameraNum - 1], mCameraDevices[mCameraNum - 1], | |
169 | + mCameraOrientation[mCameraNum - 1]); | |
161 | 170 | } |
162 | 171 | |
163 | 172 | /**************************************************************************** |
@@ -95,13 +95,14 @@ private: | ||
95 | 95 | hw_device_t** device); |
96 | 96 | |
97 | 97 | void parseConfig(const char* configFile); |
98 | - void newCameraConfig(int facing, const char* location); | |
98 | + void newCameraConfig(int facing, const char* location, int orientation); | |
99 | 99 | |
100 | 100 | private: |
101 | 101 | |
102 | 102 | /* Camera hardware */ |
103 | 103 | CameraHardware** mCamera; |
104 | 104 | char** mCameraDevices; |
105 | + int* mCameraFacing; | |
105 | 106 | int* mCameraOrientation; |
106 | 107 | int mCameraNum; |
107 | 108 |
@@ -321,12 +321,13 @@ status_t CameraHardware::closeCamera() | ||
321 | 321 | return NO_ERROR; |
322 | 322 | } |
323 | 323 | |
324 | -status_t CameraHardware::getCameraInfo(struct camera_info* info, int facing) | |
324 | +status_t CameraHardware::getCameraInfo(struct camera_info* info, int facing, | |
325 | + int orientation) | |
325 | 326 | { |
326 | 327 | ALOGD("CameraHardware::getCameraInfo"); |
327 | 328 | |
328 | 329 | info->facing = facing; |
329 | - info->orientation = 0; | |
330 | + info->orientation = orientation; | |
330 | 331 | |
331 | 332 | return NO_ERROR; |
332 | 333 | } |
@@ -212,7 +212,8 @@ public: | ||
212 | 212 | * NOTE: When this method is called the object is locked. |
213 | 213 | * Note that failures in this method are reported as negave EXXX statuses. |
214 | 214 | */ |
215 | - static status_t getCameraInfo(struct camera_info* info, int facing); | |
215 | + static status_t getCameraInfo(struct camera_info* info, int facing, | |
216 | + int orientation); | |
216 | 217 | |
217 | 218 | private: |
218 | 219 |