1/*
2 * Copyright (C) Texas Instruments - http://www.ti.com/
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/**
18* @file CameraProperties.cpp
19*
20* This file maps the CameraHardwareInterface to the Camera interfaces on OMAP4 (mainly OMX).
21*
22*/
23
24#include "CameraProperties.h"
25
26namespace Ti {
27namespace Camera {
28
29const char CameraProperties::INVALID[]="prop-invalid-key";
30const char CameraProperties::CAMERA_NAME[]="prop-camera-name";
31const char CameraProperties::CAMERA_SENSOR_INDEX[]="prop-sensor-index";
32const char CameraProperties::CAMERA_SENSOR_ID[] = "prop-sensor-id";
33const char CameraProperties::ORIENTATION_INDEX[]="prop-orientation";
34const char CameraProperties::FACING_INDEX[]="prop-facing";
35const char CameraProperties::SUPPORTED_PREVIEW_SIZES[] = "prop-preview-size-values";
36const char CameraProperties::SUPPORTED_PREVIEW_SUBSAMPLED_SIZES[] = "prop-preview-subsampled-size-values";
37const char CameraProperties::SUPPORTED_PREVIEW_TOPBOTTOM_SIZES[] = "prop-preview-topbottom-size-values";
38const char CameraProperties::SUPPORTED_PREVIEW_SIDEBYSIDE_SIZES[] = "prop-preview-sidebyside-size-values";
39const char CameraProperties::SUPPORTED_PREVIEW_FORMATS[] = "prop-preview-format-values";
40const char CameraProperties::SUPPORTED_PREVIEW_FRAME_RATES[] = "prop-preview-frame-rate-values";
41const char CameraProperties::SUPPORTED_PREVIEW_FRAME_RATES_EXT[] = "prop-preview-frame-rate-ext-values";
42const char CameraProperties::SUPPORTED_PICTURE_SIZES[] = "prop-picture-size-values";
43const char CameraProperties::SUPPORTED_PICTURE_SUBSAMPLED_SIZES[] = "prop-picture-subsampled-size-values";
44const char CameraProperties::SUPPORTED_PICTURE_TOPBOTTOM_SIZES[] = "prop-picture-topbottom-size-values";
45const char CameraProperties::SUPPORTED_PICTURE_SIDEBYSIDE_SIZES[] = "prop-picture-sidebyside-size-values";
46const char CameraProperties::SUPPORTED_PICTURE_FORMATS[] = "prop-picture-format-values";
47const char CameraProperties::SUPPORTED_THUMBNAIL_SIZES[] = "prop-jpeg-thumbnail-size-values";
48const char CameraProperties::SUPPORTED_WHITE_BALANCE[] = "prop-whitebalance-values";
49const char CameraProperties::SUPPORTED_EFFECTS[] = "prop-effect-values";
50const char CameraProperties::SUPPORTED_ANTIBANDING[] = "prop-antibanding-values";
51const char CameraProperties::SUPPORTED_EXPOSURE_MODES[] = "prop-exposure-mode-values";
52const char CameraProperties::SUPPORTED_MANUAL_EXPOSURE_MIN[] = "prop-manual-exposure-min";
53const char CameraProperties::SUPPORTED_MANUAL_EXPOSURE_MAX[] = "prop-manual-exposure-max";
54const char CameraProperties::SUPPORTED_MANUAL_EXPOSURE_STEP[] = "prop-manual-exposure-step";
55const char CameraProperties::SUPPORTED_MANUAL_GAIN_ISO_MIN[] = "prop-manual-gain-iso-min";
56const char CameraProperties::SUPPORTED_MANUAL_GAIN_ISO_MAX[] = "prop-manual-gain-iso-max";
57const char CameraProperties::SUPPORTED_MANUAL_GAIN_ISO_STEP[] = "prop-manual-gain-iso-step";
58const char CameraProperties::SUPPORTED_EV_MAX[] = "prop-ev-compensation-max";
59const char CameraProperties::SUPPORTED_EV_MIN[] = "prop-ev-compensation-min";
60const char CameraProperties::SUPPORTED_EV_STEP[] = "prop-ev-compensation-step";
61const char CameraProperties::SUPPORTED_ISO_VALUES[] = "prop-iso-mode-values";
62const char CameraProperties::SUPPORTED_SCENE_MODES[] = "prop-scene-mode-values";
63const char CameraProperties::SUPPORTED_FLASH_MODES[] = "prop-flash-mode-values";
64const char CameraProperties::SUPPORTED_FOCUS_MODES[] = "prop-focus-mode-values";
65const char CameraProperties::REQUIRED_PREVIEW_BUFS[] = "prop-required-preview-bufs";
66const char CameraProperties::REQUIRED_IMAGE_BUFS[] = "prop-required-image-bufs";
67const char CameraProperties::SUPPORTED_ZOOM_RATIOS[] = "prop-zoom-ratios";
68const char CameraProperties::SUPPORTED_ZOOM_STAGES[] = "prop-zoom-stages";
69const char CameraProperties::SUPPORTED_IPP_MODES[] = "prop-ipp-values";
70const char CameraProperties::SMOOTH_ZOOM_SUPPORTED[] = "prop-smooth-zoom-supported";
71const char CameraProperties::ZOOM_SUPPORTED[] = "prop-zoom-supported";
72const char CameraProperties::PREVIEW_SIZE[] = "prop-preview-size-default";
73const char CameraProperties::PREVIEW_FORMAT[] = "prop-preview-format-default";
74const char CameraProperties::PREVIEW_FRAME_RATE[] = "prop-preview-frame-rate-default";
75const char CameraProperties::ZOOM[] = "prop-zoom-default";
76const char CameraProperties::PICTURE_SIZE[] = "prop-picture-size-default";
77const char CameraProperties::PICTURE_FORMAT[] = "prop-picture-format-default";
78const char CameraProperties::JPEG_THUMBNAIL_SIZE[] = "prop-jpeg-thumbnail-size-default";
79const char CameraProperties::WHITEBALANCE[] = "prop-whitebalance-default";
80const char CameraProperties::EFFECT[] = "prop-effect-default";
81const char CameraProperties::ANTIBANDING[] = "prop-antibanding-default";
82const char CameraProperties::EXPOSURE_MODE[] = "prop-exposure-mode-default";
83const char CameraProperties::EV_COMPENSATION[] = "prop-ev-compensation-default";
84const char CameraProperties::ISO_MODE[] = "prop-iso-mode-default";
85const char CameraProperties::FOCUS_MODE[] = "prop-focus-mode-default";
86const char CameraProperties::SCENE_MODE[] = "prop-scene-mode-default";
87const char CameraProperties::FLASH_MODE[] = "prop-flash-mode-default";
88const char CameraProperties::JPEG_QUALITY[] = "prop-jpeg-quality-default";
89const char CameraProperties::CONTRAST[] = "prop-contrast-default";
90const char CameraProperties::BRIGHTNESS[] = "prop-brightness-default";
91const char CameraProperties::SATURATION[] = "prop-saturation-default";
92const char CameraProperties::SHARPNESS[] = "prop-sharpness-default";
93const char CameraProperties::IPP[] = "prop-ipp-default";
94const char CameraProperties::GBCE[] = "prop-gbce-default";
95const char CameraProperties::SUPPORTED_GBCE[] = "prop-gbce-supported";
96const char CameraProperties::GLBCE[] = "prop-glbce-default";
97const char CameraProperties::SUPPORTED_GLBCE[] = "prop-glbce-supported";
98const char CameraProperties::S3D_PRV_FRAME_LAYOUT[] = "prop-s3d-prv-frame-layout";
99const char CameraProperties::S3D_PRV_FRAME_LAYOUT_VALUES[] = "prop-s3d-prv-frame-layout-values";
100const char CameraProperties::S3D_CAP_FRAME_LAYOUT[] = "prop-s3d-cap-frame-layout";
101const char CameraProperties::S3D_CAP_FRAME_LAYOUT_VALUES[] = "prop-s3d-cap-frame-layout-values";
102const char CameraProperties::AUTOCONVERGENCE_MODE[] = "prop-auto-convergence-mode";
103const char CameraProperties::AUTOCONVERGENCE_MODE_VALUES[] = "prop-auto-convergence-mode-values";
104const char CameraProperties::MANUAL_CONVERGENCE[] = "prop-manual-convergence";
105const char CameraProperties::SUPPORTED_MANUAL_CONVERGENCE_MIN[] = "prop-supported-manual-convergence-min";
106const char CameraProperties::SUPPORTED_MANUAL_CONVERGENCE_MAX[] = "prop-supported-manual-convergence-max";
107const char CameraProperties::SUPPORTED_MANUAL_CONVERGENCE_STEP[] = "prop-supported-manual-convergence-step";
108const char CameraProperties::VSTAB[] = "prop-vstab-default";
109const char CameraProperties::VSTAB_SUPPORTED[] = "prop-vstab-supported";
110const char CameraProperties::VNF[] = "prop-vnf-default";
111const char CameraProperties::VNF_SUPPORTED[] = "prop-vnf-supported";
112const char CameraProperties::REVISION[] = "prop-revision";
113const char CameraProperties::FOCAL_LENGTH[] = "prop-focal-length";
114const char CameraProperties::HOR_ANGLE[] = "prop-horizontal-angle";
115const char CameraProperties::VER_ANGLE[] = "prop-vertical-angle";
116const char CameraProperties::FRAMERATE_RANGE[] = "prop-framerate-range-default";
117const char CameraProperties::FRAMERATE_RANGE_SUPPORTED[]="prop-framerate-range-values";
118const char CameraProperties::FRAMERATE_RANGE_EXT_SUPPORTED[]="prop-framerate-range-ext-values";
119const char CameraProperties::SENSOR_ORIENTATION[]= "sensor-orientation";
120const char CameraProperties::SENSOR_ORIENTATION_VALUES[]= "sensor-orientation-values";
121const char CameraProperties::EXIF_MAKE[] = "prop-exif-make";
122const char CameraProperties::EXIF_MODEL[] = "prop-exif-model";
123const char CameraProperties::JPEG_THUMBNAIL_QUALITY[] = "prop-jpeg-thumbnail-quality-default";
124const char CameraProperties::MAX_FOCUS_AREAS[] = "prop-max-focus-areas";
125const char CameraProperties::MAX_FD_HW_FACES[] = "prop-max-fd-hw-faces";
126const char CameraProperties::MAX_FD_SW_FACES[] = "prop-max-fd-sw-faces";
127const char CameraProperties::AUTO_EXPOSURE_LOCK[] = "prop-auto-exposure-lock";
128const char CameraProperties::AUTO_EXPOSURE_LOCK_SUPPORTED[] = "prop-auto-exposure-lock-supported";
129const char CameraProperties::AUTO_WHITEBALANCE_LOCK[] = "prop-auto-whitebalance-lock";
130const char CameraProperties::AUTO_WHITEBALANCE_LOCK_SUPPORTED[] = "prop-auto-whitebalance-lock-supported";
131const char CameraProperties::MAX_NUM_METERING_AREAS[] = "prop-max-num-metering-areas";
132const char CameraProperties::METERING_AREAS[] = "prop-metering-areas";
133const char CameraProperties::VIDEO_SNAPSHOT_SUPPORTED[] = "prop-video-snapshot-supported";
134const char CameraProperties::VIDEO_SIZE[] = "video-size";
135const char CameraProperties::SUPPORTED_VIDEO_SIZES[] = "video-size-values";
136const char CameraProperties::MECHANICAL_MISALIGNMENT_CORRECTION_SUPPORTED[] = "prop-mechanical-misalignment-correction-supported";
137const char CameraProperties::MECHANICAL_MISALIGNMENT_CORRECTION[] = "prop-mechanical-misalignment-correction";
138const char CameraProperties::CAP_MODE_VALUES[] = "prop-mode-values";
139const char CameraProperties::RAW_WIDTH[] = "prop-raw-width-values";
140const char CameraProperties::RAW_HEIGHT[] = "prop-raw-height-values";
141const char CameraProperties::MAX_PICTURE_WIDTH[] = "prop-max-picture-width";
142const char CameraProperties::MAX_PICTURE_HEIGHT[] = "prop-max-picture-height";
143
144const char CameraProperties::DEFAULT_VALUE[] = "";
145
146const char CameraProperties::PARAMS_DELIMITER []= ",";
147
148// Returns the properties class for a specific Camera
149// Each value is indexed by the CameraProperties::CameraPropertyIndex enum
150int CameraProperties::getProperties(int cameraIndex, CameraProperties::Properties** properties)
151{
152    LOG_FUNCTION_NAME;
153
154    if(cameraIndex >= mCamerasSupported)
155    {
156        LOG_FUNCTION_NAME_EXIT;
157        return -EINVAL;
158    }
159
160    *properties = mCameraProps+cameraIndex;
161
162    LOG_FUNCTION_NAME_EXIT;
163    return 0;
164}
165
166void CameraProperties::Properties::set(const char * const prop, const char * const value) {
167    CAMHAL_ASSERT(prop);
168
169    if ( !value ) {
170        mProperties[mCurrentMode].removeItem(android::String8(prop));
171    } else {
172        mProperties[mCurrentMode].replaceValueFor(android::String8(prop), android::String8(value));
173    }
174}
175
176void CameraProperties::Properties::set(const char * const prop, const int value) {
177    char s_val[30];
178    sprintf(s_val, "%d", value);
179    set(prop, s_val);
180}
181
182const char* CameraProperties::Properties::get(const char * prop) const {
183    return mProperties[mCurrentMode].valueFor(android::String8(prop)).string();
184}
185
186int CameraProperties::Properties::getInt(const char * prop) const {
187    android::String8 value = mProperties[mCurrentMode].valueFor(android::String8(prop));
188    if (value.isEmpty()) {
189        return -1;
190    }
191    return strtol(value, 0, 0);
192}
193
194void CameraProperties::Properties::setSensorIndex(int idx) {
195    OperatingMode originalMode = getMode();
196    for ( int i = 0 ; i < MODE_MAX ; i++ ) {
197        setMode(static_cast<OperatingMode>(i));
198        set(CAMERA_SENSOR_INDEX, idx);
199    }
200    setMode(originalMode);
201}
202
203void CameraProperties::Properties::setMode(OperatingMode mode) {
204    CAMHAL_ASSERT(mode >= 0 && mode < MODE_MAX);
205    mCurrentMode = mode;
206}
207
208OperatingMode CameraProperties::Properties::getMode() const {
209    return mCurrentMode;
210}
211
212void CameraProperties::Properties::dump() {
213    CAMHAL_LOGD("================================");
214    CAMHAL_LOGD("Dumping properties for camera: %d", getInt("prop-sensor-index"));
215
216    for (size_t i = 0; i < mProperties[mCurrentMode].size(); i++) {
217        CAMHAL_LOGD("%s = %s",
218                mProperties[mCurrentMode].keyAt(i).string(),
219                mProperties[mCurrentMode].valueAt(i).string());
220    }
221
222    CAMHAL_LOGD("--------------------------------");
223}
224
225const char* CameraProperties::Properties::keyAt(const unsigned int index) const {
226    if (index < mProperties[mCurrentMode].size()) {
227        return mProperties[mCurrentMode].keyAt(index).string();
228    }
229    return NULL;
230}
231
232const char* CameraProperties::Properties::valueAt(const unsigned int index) const {
233    if (index < mProperties[mCurrentMode].size()) {
234        return mProperties[mCurrentMode].valueAt(index).string();
235    }
236    return NULL;
237}
238
239} // namespace Camera
240} // namespace Ti
241