Home | History | Annotate | Download | only in src
      1 /*
      2 Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
      3 
      4 Redistribution and use in source and binary forms, with or without
      5 modification, are permitted provided that the following conditions are
      6 met:
      7     * Redistributions of source code must retain the above copyright
      8       notice, this list of conditions and the following disclaimer.
      9     * Redistributions in binary form must reproduce the above
     10       copyright notice, this list of conditions and the following
     11       disclaimer in the documentation and/or other materials provided
     12       with the distribution.
     13     * Neither the name of The Linux Foundation nor the names of its
     14       contributors may be used to endorse or promote products derived
     15       from this software without specific prior written permission.
     16 
     17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     20 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28 */
     29 
     30 #include <pthread.h>
     31 #include <fcntl.h>
     32 #include <stdio.h>
     33 #include <stdbool.h>
     34 #include <string.h>
     35 #include <unistd.h>
     36 #include <termios.h>
     37 #include <assert.h>
     38 #include <stdlib.h>
     39 #include <ctype.h>
     40 #include <signal.h>
     41 #include <errno.h>
     42 #include <sys/mman.h>
     43 #include <sys/time.h>
     44 #include <sys/ioctl.h>
     45 #include <linux/fb.h>
     46 #ifdef _ANDROID_
     47 #include <cutils/log.h>
     48 #endif
     49 #include <dlfcn.h>
     50 
     51 #include "mm_camera_dbg.h"
     52 #include "mm_qcamera_main_menu.h"
     53 #include "mm_qcamera_display_dimensions.h"
     54 #include "mm_qcamera_app.h"
     55 
     56 #define CAMERA_OPENED 0
     57 
     58 #define VIDEO_BUFFER_SIZE       (PREVIEW_WIDTH * PREVIEW_HEIGHT * 3/2)
     59 #define THUMBNAIL_BUFFER_SIZE   (THUMBNAIL_WIDTH * THUMBNAIL_HEIGHT * 3/2)
     60 #define SNAPSHOT_BUFFER_SIZE    (PICTURE_WIDTH * PICTURE_HEIGHT * 3/2)
     61 /*===========================================================================
     62  * Macro
     63  *===========================================================================*/
     64 #define PREVIEW_FRAMES_NUM    4
     65 #define VIDEO_FRAMES_NUM      4
     66 #define THUMBNAIL_FRAMES_NUM  1
     67 #define SNAPSHOT_FRAMES_NUM   1
     68 #define MAX_NUM_FORMAT        32
     69 /*===========================================================================
     70  * Defines
     71  *===========================================================================*/
     72 
     73 const CAMERA_MAIN_MENU_TBL_T camera_main_menu_tbl[] = {
     74   {STOP_CAMERA,                   "Stop preview/video and exit camera."},
     75   {PREVIEW_VIDEO_RESOLUTION,      "Preview/Video Resolution: SQCIF/QCIF/"
     76                               "QVGA/CIF/VGA/WVGA... Default WVGA."},
     77   {TAKE_YUV_SNAPSHOT,       "Take a snapshot"},
     78   {TAKE_RAW_SNAPSHOT,       "Take a raw snapshot"},
     79   {TAKE_ZSL_SNAPSHOT,       "Take a ZSL snapshot"},
     80   {START_RECORDING,       "Start RECORDING"},
     81   {START_RDI, "Start RDI stream"},
     82   {STOP_RDI, "Stop RDI stream"},
     83   {SWITCH_CAMERA,       "Switch Camera"},
     84 #if 0
     85   {SET_WHITE_BALANCE,          "Set white balance mode: Auto/Off/Daylight/Incandescent/Fluorescent. Default Auto."},
     86   {SET_EXP_METERING,          "Set exposure metering mode: FrameAverage/CenterWeighted/SpotMetering. Default CenterWeighted"},
     87   {GET_CTRL_VALUE,              "Get control value menu"},
     88   {TOGGLE_AFR,                 "Toggle auto frame rate. Default fixed frame rate"},
     89   {SET_ISO,                 "ISO changes."},
     90   {BRIGHTNESS_GOTO_SUBMENU,                               "Brightness changes."},
     91   {CONTRAST_GOTO_SUBMENU,                                 "Contrast changes."},
     92   {EV_GOTO_SUBMENU,                                       "EV changes."},
     93   {SATURATION_GOTO_SUBMENU,                               "Saturation changes."},
     94   {SET_ZOOM,          "Set Digital Zoom."},
     95   {SET_SHARPNESS,          "Set Sharpness."},
     96 #endif
     97 };
     98 
     99 const PREVIEW_DIMENSION_TBL_T preview_video_dimension_tbl[] = {
    100    { SQCIF, SQCIF_WIDTH, SQCIF_HEIGHT, "SQCIF",  "Preview/Video Resolution: SQCIF <128x96>"},
    101    {  QCIF,  QCIF_WIDTH,  QCIF_HEIGHT,  "QCIF",  "Preview/Video Resolution: QCIF <176x144>"},
    102    {  QVGA,  QVGA_WIDTH,  QVGA_HEIGHT,  "QVGA",  "Preview/Video Resolution: QVGA <320x240>"},
    103    {   CIF,   CIF_WIDTH,   CIF_HEIGHT,   "CIF",  "Preview/Video Resolution: CIF <352x288>"},
    104    {   VGA,   VGA_WIDTH,   VGA_HEIGHT,   "VGA",  "Preview/Video Resolution: VGA <640x480>"},
    105    {  WVGA,  WVGA_WIDTH,  WVGA_HEIGHT,  "WVGA",  "Preview/Video Resolution: WVGA <800x480>"},
    106    {  SVGA,  SVGA_WIDTH,  SVGA_HEIGHT,  "SVGA",  "Preview/Video Resolution: SVGA <800x600>"},
    107    {   XGA,   XGA_WIDTH,   XGA_HEIGHT,    "XGA", "Preview/Video Resolution: XGA <1024x768>"},
    108    { HD720, HD720_WIDTH, HD720_HEIGHT,  "HD720", "Preview/Video Resolution: HD720 <1280x720>"},
    109 };
    110 
    111 const CAMERA_BRIGHTNESS_TBL_T brightness_change_tbl[] = {
    112   {INC_BRIGHTNESS, "Increase Brightness by one step."},
    113   {DEC_BRIGHTNESS, "Decrease Brightness by one step."},
    114 };
    115 
    116 const CAMERA_CONTRST_TBL_T contrast_change_tbl[] = {
    117   {INC_CONTRAST, "Increase Contrast by one step."},
    118   {DEC_CONTRAST, "Decrease Contrast by one step."},
    119 };
    120 
    121 const CAMERA_EV_TBL_T camera_EV_tbl[] = {
    122   {INCREASE_EV, "Increase EV by one step."},
    123   {DECREASE_EV, "Decrease EV by one step."},
    124 };
    125 
    126 const CAMERA_SATURATION_TBL_T camera_saturation_tbl[] = {
    127   {INC_SATURATION, "Increase Satuation by one step."},
    128   {DEC_SATURATION, "Decrease Satuation by one step."},
    129 };
    130 
    131 const CAMERA_SHARPNESS_TBL_T camera_sharpness_tbl[] = {
    132   {INC_SHARPNESS, "Increase Sharpness."},
    133   {DEC_SHARPNESS, "Decrease Sharpness."},
    134 };
    135 
    136 const WHITE_BALANCE_TBL_T white_balance_tbl[] = {
    137   { 	MM_CAMERA_WHITE_BALANCE_AUTO,         "White Balance - Auto"},
    138   { 	MM_CAMERA_WHITE_BALANCE_OFF,          "White Balance - Off"},
    139   {   MM_CAMERA_WHITE_BALANCE_DAYLIGHT,     "White Balance - Daylight"},
    140   {   MM_CAMERA_WHITE_BALANCE_INCANDESCENT, "White Balance - Incandescent"},
    141   {   MM_CAMERA_WHITE_BALANCE_FLUORESCENT,  "White Balance - Fluorescent"},
    142 };
    143 
    144 const CAMERA_TBL_T cam_tbl[] = {
    145   { 	1,          "Back Camera"},
    146   { 	2,         "Front Camera"},
    147 };
    148 
    149 const RECORD_TBL_T record_tbl[] = {
    150   { 	LIVE_SNAPSHOT_MENU,          "Take Live snapshot"},
    151   { 	STOP_RECORDING_MENU,         "Stop Recording"},
    152 };
    153 
    154 const GET_CTRL_TBL_T get_ctrl_tbl[] = {
    155   {     WHITE_BALANCE_STATE,           "Get white balance state (auto/off)"},
    156   {     WHITE_BALANCE_TEMPERATURE,      "Get white balance temperature"},
    157   {     BRIGHTNESS_CTRL,      "Get brightness value"},
    158   {     EV,      "Get exposure value"},
    159   {     CONTRAST_CTRL,      "Get contrast value"},
    160   {     SATURATION_CTRL,      "Get saturation value"},
    161   {     SHARPNESS_CTRL,      "Get sharpness value"},
    162 };
    163 
    164 const EXP_METERING_TBL_T exp_metering_tbl[] = {
    165   {   EXP_METERING_FRAME_AVERAGE,      "Exposure Metering - Frame Average"},
    166   {   EXP_METERING_CENTER_WEIGHTED,    "Exposure Metering - Center Weighted"},
    167   {   EXP_METERING_SPOT_METERING,      "Exposure Metering - Spot Metering"},
    168 };
    169 
    170 const ISO_TBL_T iso_tbl[] = {
    171   {   ISO_AUTO, "ISO: Auto"},
    172   {   ISO_DEBLUR, "ISO: Deblur"},
    173   {   ISO_100, "ISO: 100"},
    174   {   ISO_200, "ISO: 200"},
    175   {   ISO_400, "ISO: 400"},
    176   {   ISO_800, "ISO: 800"},
    177   {   ISO_1600, "ISO: 1600"},
    178 };
    179 
    180 const ZOOM_TBL_T zoom_tbl[] = {
    181   {   ZOOM_IN, "Zoom In one step"},
    182   {   ZOOM_OUT, "Zoom Out one step"},
    183 };
    184 
    185 
    186 struct v4l2_fmtdesc enumfmtdesc[MAX_NUM_FORMAT];
    187 struct v4l2_format current_fmt;
    188 
    189 /*===========================================================================
    190  * Forward declarations
    191  *===========================================================================*/
    192 static int set_fps(int fps);
    193 static int start_snapshot (void);
    194 static int stop_snapshot (void);
    195 /*===========================================================================
    196  * Static global variables
    197  *===========================================================================*/
    198 USER_INPUT_DISPLAY_T input_display;
    199 static int camframe_status = 0;
    200 
    201 #ifdef _ANDROID_
    202 char *sdcard_path = "/data";
    203 #else
    204 char *sdcard_path = ".";
    205 #endif
    206 
    207 //void *libqcamera = NULL;
    208 //void (**LINK_jpegfragment_callback)(uint8_t * buff_ptr , uint32_t buff_size);
    209 //void (**LINK_jpeg_callback)(void);
    210 
    211 int num_supported_fmts = 0;
    212 int memoryType = V4L2_MEMORY_MMAP; /* default */
    213 int preview_video_resolution_flag = 0;
    214 int effect = CAMERA_EFFECT_OFF;
    215 int brightness = CAMERA_DEF_BRIGHTNESS;
    216 int contrast = CAMERA_DEF_CONTRAST;
    217 int saturation = CAMERA_DEF_SATURATION;
    218 int sharpness = CAMERA_DEF_SHARPNESS;
    219 int32_t ev_num = 0;
    220 uint8_t ezTune = false;
    221 int pmemThumbnailfd = 0;
    222 int pmemSnapshotfd = 0;
    223 int pmemRawSnapshotfd = 0;
    224 int fdSnapshot = 0;
    225 int fdThumbnail = 0;
    226 char snapshotBuf[256] = { 0};
    227 char thumbnailBuf[256] = { 0};
    228 uint32_t snapshot_buff_size = 0;
    229 uint32_t raw_snapshot_buffer_size = 0;
    230 static int thumbnailCntr = 0, snapshotCntr = 0;
    231 unsigned char *thumbnail_buf = NULL, *main_img_buf = NULL, *raw_img_buf = NULL;
    232 int32_t *sharpness_AF = NULL;
    233 struct crop_info cropInfo;
    234 common_crop_t cropInfo_s;
    235 
    236 interface_ctrl_t intrfcCtrl;
    237 config3a_wb_t autoWB = CAMERA_WB_AUTO;
    238 isp3a_af_mode_t af_mode = AF_MODE_AUTO;
    239 cam_af_focusrect_t afFocusRect = AUTO;
    240 
    241 cam_af_ctrl_t af_ctrl;
    242 camera_iso_mode_type iso = CAMERA_ISO_AUTO;
    243 camera_antibanding_type antibanding = CAMERA_ANTIBANDING_OFF;
    244 camera_auto_exposure_mode_type aec_mode = CAMERA_AEC_CENTER_WEIGHTED;
    245 led_mode_t led_mode = LED_MODE_OFF;
    246 motion_iso_t motion_iso = MOTION_ISO_OFF;
    247 int32_t hue = CAMERA_DEF_HUE;
    248 fps_mode_t fps_mode = FPS_MODE_AUTO;
    249 
    250 struct v4l2_cropcap cropcap;
    251 struct v4l2_queryctrl zoom_queryctrl;
    252 struct v4l2_queryctrl sharpness_queryctrl;
    253 int zoom_level;
    254 
    255 Camera_Resolution Resolution;
    256 //int32_t g_camParmInfo_current_value = 0;
    257 //extern unsigned long preview_frames_buf;
    258 //extern void test_app_mmcamera_videoframe_callback(struct msm_frame *frame); // video_cam.c
    259 
    260 /* To flush free video buffers queue */
    261 //void (*LINK_cam_frame_flush_free_video)(void);
    262 static int submain();
    263 
    264 //struct v4l2_frame_buffer frames[PREVIEW_FRAMES_NUM];
    265 //struct v4l2_frame_buffer video_frames[VIDEO_FRAMES_NUM];
    266 
    267 //pthread_t frame_thread;
    268 
    269 void test_app_camframe_timeout_callback(void)
    270 {
    271   camframe_status = -1;
    272 }
    273 
    274 /*===========================================================================
    275  * FUNCTION    - keypress_to_event -
    276  *
    277  * DESCRIPTION:
    278  *==========================================================================*/
    279 int keypress_to_event(char keypress)
    280 {
    281   char out_buf = INVALID_KEY_PRESS;
    282   if ((keypress >= 'A' && keypress <= 'Z') ||
    283     (keypress >= 'a' && keypress <= 'z')) {
    284     out_buf = tolower(keypress);
    285     out_buf = out_buf - 'a' + 1;
    286   } else if (keypress >= '1' && keypress <= '9') {
    287     out_buf = keypress;
    288     out_buf = keypress - '1' + BASE_OFFSET_NUM;
    289   }
    290   return out_buf;
    291 }
    292 
    293 int next_menu(menu_id_change_t current_menu_id, char keypress, camera_action_t * action_id_ptr, int * action_param)
    294 {
    295   char output_to_event;
    296   menu_id_change_t next_menu_id = MENU_ID_INVALID;
    297   * action_id_ptr = ACTION_NO_ACTION;
    298 
    299   output_to_event = keypress_to_event(keypress);
    300   CDBG("current_menu_id=%d\n",current_menu_id);
    301   CDBG("output_to_event=%d\n",output_to_event);
    302   switch(current_menu_id) {
    303     case MENU_ID_MAIN:
    304       switch(output_to_event) {
    305         case STOP_CAMERA:
    306           * action_id_ptr = ACTION_STOP_CAMERA;
    307           CDBG("STOP_CAMERA\n");
    308           break;
    309 
    310         case PREVIEW_VIDEO_RESOLUTION:
    311           next_menu_id = MENU_ID_PREVIEWVIDEORESOLUTIONCHANGE;
    312           CDBG("next_menu_id = MENU_ID_PREVIEWVIDEORESOLUTIONCHANGE = %d\n", next_menu_id);
    313           break;
    314 #if 0
    315         case SET_WHITE_BALANCE:
    316           next_menu_id = MENU_ID_WHITEBALANCECHANGE;
    317           CDBG("next_menu_id = MENU_ID_WHITEBALANCECHANGE = %d\n", next_menu_id);
    318           break;
    319 
    320         case SET_EXP_METERING:
    321           next_menu_id = MENU_ID_EXPMETERINGCHANGE;
    322           CDBG("next_menu_id = MENU_ID_EXPMETERINGCHANGE = %d\n", next_menu_id);
    323           break;
    324 
    325         case GET_CTRL_VALUE:
    326           next_menu_id = MENU_ID_GET_CTRL_VALUE;
    327           CDBG("next_menu_id = MENU_ID_GET_CTRL_VALUE = %d\n", next_menu_id);
    328           break;
    329 
    330         case BRIGHTNESS_GOTO_SUBMENU:
    331           next_menu_id = MENU_ID_BRIGHTNESSCHANGE;
    332           CDBG("next_menu_id = MENU_ID_BRIGHTNESSCHANGE = %d\n", next_menu_id);
    333           break;
    334 
    335         case CONTRAST_GOTO_SUBMENU:
    336           next_menu_id = MENU_ID_CONTRASTCHANGE;
    337           break;
    338 
    339         case EV_GOTO_SUBMENU:
    340           next_menu_id = MENU_ID_EVCHANGE;
    341           break;
    342 
    343         case SATURATION_GOTO_SUBMENU:
    344           next_menu_id = MENU_ID_SATURATIONCHANGE;
    345           break;
    346 
    347         case TOGGLE_AFR:
    348           * action_id_ptr = ACTION_TOGGLE_AFR;
    349           CDBG("next_menu_id = MENU_ID_TOGGLEAFR = %d\n", next_menu_id);
    350           break;
    351 
    352         case SET_ISO:
    353           next_menu_id = MENU_ID_ISOCHANGE;
    354           CDBG("next_menu_id = MENU_ID_ISOCHANGE = %d\n", next_menu_id);
    355           break;
    356 
    357         case SET_ZOOM:
    358           next_menu_id = MENU_ID_ZOOMCHANGE;
    359           CDBG("next_menu_id = MENU_ID_ZOOMCHANGE = %d\n", next_menu_id);
    360           break;
    361 
    362         case SET_SHARPNESS:
    363           next_menu_id = MENU_ID_SHARPNESSCHANGE;
    364           CDBG("next_menu_id = MENU_ID_SHARPNESSCHANGE = %d\n", next_menu_id);
    365           break;
    366 #endif
    367         case TAKE_YUV_SNAPSHOT:
    368           * action_id_ptr = ACTION_TAKE_YUV_SNAPSHOT;
    369           CDBG("Taking YUV snapshot\n");
    370           break;
    371 
    372         case TAKE_RAW_SNAPSHOT:
    373           * action_id_ptr = ACTION_TAKE_RAW_SNAPSHOT;
    374           CDBG("Taking RAW snapshot\n");
    375           break;
    376         case START_RECORDING:
    377           *action_id_ptr = ACTION_START_RECORDING;
    378           next_menu_id = MENU_ID_RECORD;
    379           CDBG("Start recording\n");
    380           break;
    381         /*case STOP_RECORDING:
    382           * action_id_ptr = ACTION_STOP_RECORDING;
    383           CDBG("Stop recording\n");
    384           break;*/
    385         case SWITCH_CAMERA:
    386           next_menu_id = MENU_ID_SWITCHCAMERA;
    387           CDBG("SWitch Camera\n");
    388           break;
    389         case TAKE_ZSL_SNAPSHOT:
    390           * action_id_ptr = ACTION_TAKE_ZSL_SNAPSHOT;
    391           CDBG("Taking ZSL snapshot\n");
    392           break;
    393         case START_RDI:
    394           * action_id_ptr = ACTION_START_RDI;
    395           break;
    396         case STOP_RDI:
    397           * action_id_ptr = ACTION_STOP_RDI;
    398           break;
    399         default:
    400           next_menu_id = MENU_ID_MAIN;
    401           CDBG("next_menu_id = MENU_ID_MAIN = %d\n", next_menu_id);
    402           break;
    403       }
    404       break;
    405 
    406     case MENU_ID_PREVIEWVIDEORESOLUTIONCHANGE:
    407       printf("MENU_ID_PREVIEWVIDEORESOLUTIONCHANGE\n");
    408       * action_id_ptr = ACTION_PREVIEW_VIDEO_RESOLUTION;
    409       if (output_to_event > RESOLUTION_PREVIEW_VIDEO_MAX ||
    410         output_to_event < RESOLUTION_MIN) {
    411           next_menu_id = current_menu_id;
    412       }
    413       else {
    414         next_menu_id = MENU_ID_MAIN;
    415         * action_param = output_to_event;
    416       }
    417       break;
    418 
    419     case MENU_ID_WHITEBALANCECHANGE:
    420       printf("MENU_ID_WHITEBALANCECHANGE\n");
    421       * action_id_ptr = ACTION_SET_WHITE_BALANCE;
    422       if (output_to_event > 0 &&
    423         output_to_event <= sizeof(white_balance_tbl)/sizeof(white_balance_tbl[0])) {
    424           next_menu_id = MENU_ID_MAIN;
    425           * action_param = output_to_event;
    426       }
    427       else {
    428         next_menu_id = current_menu_id;
    429       }
    430       break;
    431 
    432     case MENU_ID_EXPMETERINGCHANGE:
    433       printf("MENU_ID_EXPMETERINGCHANGE\n");
    434       * action_id_ptr = ACTION_SET_EXP_METERING;
    435       if (output_to_event > 0 &&
    436         output_to_event <= sizeof(exp_metering_tbl)/sizeof(exp_metering_tbl[0])) {
    437           next_menu_id = MENU_ID_MAIN;
    438           * action_param = output_to_event;
    439       }
    440       else {
    441         next_menu_id = current_menu_id;
    442       }
    443       break;
    444 
    445     case MENU_ID_GET_CTRL_VALUE:
    446       printf("MENU_ID_GET_CTRL_VALUE\n");
    447       * action_id_ptr = ACTION_GET_CTRL_VALUE;
    448       if (output_to_event > 0 &&
    449         output_to_event <= sizeof(get_ctrl_tbl)/sizeof(get_ctrl_tbl[0])) {
    450           next_menu_id = MENU_ID_MAIN;
    451           * action_param = output_to_event;
    452       }
    453       else {
    454         next_menu_id = current_menu_id;
    455       }
    456       break;
    457 
    458     case MENU_ID_BRIGHTNESSCHANGE:
    459       switch (output_to_event) {
    460         case INC_BRIGHTNESS:
    461           * action_id_ptr = ACTION_BRIGHTNESS_INCREASE;
    462           next_menu_id = MENU_ID_MAIN;
    463           break;
    464 
    465         case DEC_BRIGHTNESS:
    466           * action_id_ptr = ACTION_BRIGHTNESS_DECREASE;
    467           next_menu_id = MENU_ID_MAIN;
    468           break;
    469 
    470         default:
    471           next_menu_id = MENU_ID_BRIGHTNESSCHANGE;
    472           break;
    473       }
    474       break;
    475 
    476     case MENU_ID_CONTRASTCHANGE:
    477       switch (output_to_event) {
    478         case INC_CONTRAST:
    479           * action_id_ptr = ACTION_CONTRAST_INCREASE;
    480           next_menu_id = MENU_ID_MAIN;
    481           break;
    482 
    483         case DEC_CONTRAST:
    484           * action_id_ptr = ACTION_CONTRAST_DECREASE;
    485           next_menu_id = MENU_ID_MAIN;
    486           break;
    487 
    488         default:
    489           next_menu_id = MENU_ID_CONTRASTCHANGE;
    490           break;
    491       }
    492       break;
    493 
    494     case MENU_ID_EVCHANGE:
    495       switch (output_to_event) {
    496         case INCREASE_EV:
    497           * action_id_ptr = ACTION_EV_INCREASE;
    498           next_menu_id = MENU_ID_MAIN;
    499           break;
    500 
    501         case DECREASE_EV:
    502           * action_id_ptr = ACTION_EV_DECREASE;
    503           next_menu_id = MENU_ID_MAIN;
    504           break;
    505 
    506         default:
    507           next_menu_id = MENU_ID_EVCHANGE;
    508           break;
    509       }
    510       break;
    511 
    512     case MENU_ID_SATURATIONCHANGE:
    513       switch (output_to_event) {
    514         case INC_SATURATION:
    515           * action_id_ptr = ACTION_SATURATION_INCREASE;
    516           next_menu_id = MENU_ID_MAIN;
    517           break;
    518 
    519         case DEC_SATURATION:
    520           * action_id_ptr = ACTION_SATURATION_DECREASE;
    521           next_menu_id = MENU_ID_MAIN;
    522           break;
    523 
    524         default:
    525           next_menu_id = MENU_ID_EVCHANGE;
    526           break;
    527       }
    528       break;
    529 
    530     case MENU_ID_ISOCHANGE:
    531       printf("MENU_ID_ISOCHANGE\n");
    532       * action_id_ptr = ACTION_SET_ISO;
    533       if (output_to_event > 0 &&
    534         output_to_event <= sizeof(iso_tbl)/sizeof(iso_tbl[0])) {
    535           next_menu_id = MENU_ID_MAIN;
    536           * action_param = output_to_event;
    537       } else {
    538         next_menu_id = current_menu_id;
    539       }
    540       break;
    541 
    542     case MENU_ID_ZOOMCHANGE:
    543       * action_id_ptr = ACTION_SET_ZOOM;
    544       if (output_to_event > 0 &&
    545         output_to_event <= sizeof(zoom_tbl)/sizeof(zoom_tbl[0])) {
    546           next_menu_id = MENU_ID_MAIN;
    547           * action_param = output_to_event;
    548       } else {
    549         next_menu_id = current_menu_id;
    550       }
    551       break;
    552 
    553     case MENU_ID_SHARPNESSCHANGE:
    554       switch (output_to_event) {
    555         case INC_SHARPNESS:
    556           * action_id_ptr = ACTION_SHARPNESS_INCREASE;
    557           next_menu_id = MENU_ID_MAIN;
    558           break;
    559         case DEC_SHARPNESS:
    560           * action_id_ptr = ACTION_SHARPNESS_DECREASE;
    561           next_menu_id = MENU_ID_MAIN;
    562           break;
    563         default:
    564           next_menu_id = MENU_ID_SHARPNESSCHANGE;
    565           break;
    566       }
    567       break;
    568     case MENU_ID_SWITCHCAMERA:
    569       * action_id_ptr = ACTION_SWITCH_CAMERA;
    570       if (output_to_event >= 0 &&
    571         output_to_event <= sizeof(cam_tbl)/sizeof(cam_tbl[0])) {
    572           next_menu_id = MENU_ID_MAIN;
    573           * action_param = output_to_event;
    574       } else {
    575         next_menu_id = current_menu_id;
    576       }
    577       break;
    578    case MENU_ID_RECORD:
    579       switch (output_to_event) {
    580         case LIVE_SNAPSHOT_MENU:
    581           * action_id_ptr = ACTION_TAKE_LIVE_SNAPSHOT;
    582           next_menu_id = MENU_ID_RECORD;
    583           break;
    584 
    585         default:
    586         case STOP_RECORDING_MENU:
    587           * action_id_ptr = ACTION_STOP_RECORDING;
    588           next_menu_id = MENU_ID_MAIN;
    589           break;
    590       }
    591    default:
    592       CDBG("menu id is wrong: %d\n", current_menu_id);
    593       break;
    594   }
    595 
    596   return next_menu_id;
    597 }
    598 
    599 /*===========================================================================
    600  * FUNCTION    - print_menu_preview_video -
    601  *
    602  * DESCRIPTION:
    603  * ===========================================================================*/
    604 static void print_menu_preview_video(void) {
    605   unsigned int i;
    606 
    607   printf("\n");
    608   printf("===========================================\n");
    609   printf("      Camera is in preview/video mode now        \n");
    610   printf("===========================================\n\n");
    611 
    612   char menuNum = 'A';
    613   for (i = 0; i < sizeof(camera_main_menu_tbl)/sizeof(camera_main_menu_tbl[0]); i++) {
    614     if (i == BASE_OFFSET) {
    615       menuNum = '1';
    616     }
    617 
    618     printf("%c.  %s\n", menuNum, camera_main_menu_tbl[i].menu_name);
    619     menuNum++;
    620   }
    621 
    622   printf("\nPlease enter your choice: ");
    623 
    624   return;
    625 }
    626 
    627 static void camera_preview_video_resolution_change_tbl(void) {
    628     unsigned int i;
    629 
    630     printf("\n");
    631     printf("==========================================================\n");
    632     printf("      Camera is in preview/video resolution mode       \n");
    633     printf("==========================================================\n\n");
    634 
    635     char previewVideomenuNum = 'A';
    636     for (i = 0; i < sizeof(preview_video_dimension_tbl) /
    637       sizeof(preview_video_dimension_tbl[0]); i++) {
    638         printf("%c.  %s\n", previewVideomenuNum,
    639           preview_video_dimension_tbl[i].str_name);
    640         previewVideomenuNum++;
    641     }
    642 
    643     printf("\nPlease enter your choice for Preview/Video Resolution: ");
    644     return;
    645 }
    646 
    647 static void camera_preview_video_wb_change_tbl(void) {
    648   unsigned int i;
    649   printf("\n");
    650   printf("==========================================================\n");
    651   printf("      Camera is in white balance change mode       \n");
    652   printf("==========================================================\n\n");
    653 
    654   char submenuNum = 'A';
    655   for (i = 0 ; i < sizeof(white_balance_tbl) /
    656                    sizeof(white_balance_tbl[0]); i++) {
    657         //printf("%c.  %s\n", submenuNum, white_balance_tbl[i].wb_name);
    658         submenuNum++;
    659   }
    660   printf("\nPlease enter your choice for White Balance modes: ");
    661   return;
    662 }
    663 
    664 static void camera_preview_video_get_ctrl_value_tbl(void) {
    665   unsigned int i;
    666   printf("\n");
    667   printf("==========================================================\n");
    668   printf("      Camera is in get control value mode       \n");
    669   printf("==========================================================\n\n");
    670 
    671   char submenuNum = 'A';
    672   for (i = 0 ; i < sizeof(get_ctrl_tbl) /
    673                    sizeof(get_ctrl_tbl[0]); i++) {
    674         printf("%c.  %s\n", submenuNum, get_ctrl_tbl[i].get_ctrl_name);
    675         submenuNum++;
    676   }
    677   printf("\nPlease enter your choice for control value you want to get: ");
    678   return;
    679 }
    680 
    681 static void camera_preview_video_exp_metering_change_tbl(void) {
    682   unsigned int i;
    683   printf("\n");
    684   printf("==========================================================\n");
    685   printf("      Camera is in exposure metering change mode       \n");
    686   printf("==========================================================\n\n");
    687 
    688   char submenuNum = 'A';
    689   for (i = 0 ; i < sizeof(exp_metering_tbl) /
    690                    sizeof(exp_metering_tbl[0]); i++) {
    691         printf("%c.  %s\n", submenuNum, exp_metering_tbl[i].exp_metering_name);
    692         submenuNum++;
    693   }
    694   printf("\nPlease enter your choice for exposure metering modes: ");
    695   return;
    696 }
    697 
    698 static void camera_contrast_change_tbl(void) {
    699     unsigned int i;
    700 
    701     printf("\n");
    702     printf("==========================================================\n");
    703     printf("      Camera is in change contrast resolution mode       \n");
    704     printf("==========================================================\n\n");
    705 
    706     char contrastmenuNum = 'A';
    707     for (i = 0; i < sizeof(contrast_change_tbl) /
    708                     sizeof(contrast_change_tbl[0]); i++) {
    709         printf("%c.  %s\n", contrastmenuNum,
    710                             contrast_change_tbl[i].contrast_name);
    711         contrastmenuNum++;
    712     }
    713 
    714     printf("\nPlease enter your choice for contrast Change: ");
    715     return;
    716 }
    717 
    718 static void camera_EV_change_tbl(void) {
    719   unsigned int i;
    720 
    721   printf("\n");
    722   printf("===========================================\n");
    723   printf("      Camera is in EV change mode now       \n");
    724   printf("===========================================\n\n");
    725 
    726   char submenuNum = 'A';
    727   for (i = 0; i < sizeof(camera_EV_tbl)/sizeof(camera_EV_tbl[0]); i++) {
    728     printf("%c.  %s\n", submenuNum, camera_EV_tbl[i].EV_name);
    729     submenuNum++;
    730   }
    731 
    732   printf("\nPlease enter your choice for EV changes: ");
    733   return;
    734 }
    735 
    736 static void camera_preview_video_zoom_change_tbl(void) {
    737   unsigned int i;
    738   struct v4l2_control ctrl;
    739 
    740   memset(&ctrl, 0, sizeof(ctrl));
    741   ctrl.id = V4L2_CID_ZOOM_ABSOLUTE;
    742 #if 0 /* TBD */
    743   if (ioctl(camfd, VIDIOC_G_CTRL, &ctrl) >= 0) {
    744     zoom_level = ctrl.value;
    745     printf("\n");
    746     printf("==========================================================\n");
    747     printf("      Camera is in zoom change mode: %d,  [%d..%d]        \n",
    748         ctrl.value, zoom_queryctrl.minimum, zoom_queryctrl.maximum);
    749     printf("==========================================================\n\n");
    750 
    751     char submenuNum = 'A';
    752     for (i = 0 ; i < sizeof(zoom_tbl) /
    753                    sizeof(zoom_tbl[0]); i++) {
    754         printf("%c.  %s\n", submenuNum, zoom_tbl[i].zoom_direction_name);
    755         submenuNum++;
    756     }
    757     printf("\nPlease enter your choice for zoom change direction: ");
    758   } else {
    759     printf("\nVIDIOC_G_CTRL error: %d\n", errno);
    760   }
    761 #endif /* TBD */
    762   return;
    763 }
    764 
    765 static void camera_brightness_change_tbl(void) {
    766     unsigned int i;
    767 
    768     printf("\n");
    769     printf("==========================================================\n");
    770     printf("      Camera is in change brightness mode       \n");
    771     printf("==========================================================\n\n");
    772 
    773     char brightnessmenuNum = 'A';
    774     for (i = 0; i < sizeof(brightness_change_tbl) /
    775                     sizeof(brightness_change_tbl[0]); i++) {
    776         printf("%c.  %s\n", brightnessmenuNum,
    777                             brightness_change_tbl[i].brightness_name);
    778         brightnessmenuNum++;
    779     }
    780 
    781     printf("\nPlease enter your choice for Brightness Change: ");
    782     return;
    783 }
    784 
    785 static void camera_saturation_change_tbl(void) {
    786     unsigned int i;
    787 
    788     printf("\n");
    789     printf("==========================================================\n");
    790     printf("      Camera is in change saturation mode       \n");
    791     printf("==========================================================\n\n");
    792 
    793     char saturationmenuNum = 'A';
    794     for (i = 0; i < sizeof(camera_saturation_tbl) /
    795                     sizeof(camera_saturation_tbl[0]); i++) {
    796         printf("%c.  %s\n", saturationmenuNum,
    797                             camera_saturation_tbl[i].saturation_name);
    798         saturationmenuNum++;
    799     }
    800 
    801     printf("\nPlease enter your choice for Saturation Change: ");
    802     return;
    803 }
    804 
    805 char * set_preview_video_dimension_tbl(Camera_Resolution cs_id, uint16_t * width, uint16_t * height)
    806 {
    807   unsigned int i;
    808   char * ptr = NULL;
    809   for (i = 0; i < sizeof(preview_video_dimension_tbl) /
    810     sizeof(preview_video_dimension_tbl[0]); i++) {
    811       if (cs_id == preview_video_dimension_tbl[i].cs_id) {
    812         *width = preview_video_dimension_tbl[i].width;
    813         *height = preview_video_dimension_tbl[i].height;
    814         ptr = preview_video_dimension_tbl[i].name;
    815         break;
    816       }
    817   }
    818   return ptr;
    819 }
    820 
    821 static void camera_preview_video_iso_change_tbl(void) {
    822   unsigned int i;
    823   printf("\n");
    824   printf("==========================================================\n");
    825   printf("      Camera is in ISO change mode       \n");
    826   printf("==========================================================\n\n");
    827 
    828   char submenuNum = 'A';
    829   for (i = 0 ; i < sizeof(iso_tbl) /
    830                    sizeof(iso_tbl[0]); i++) {
    831         printf("%c.  %s\n", submenuNum, iso_tbl[i].iso_modes_name);
    832         submenuNum++;
    833   }
    834   printf("\nPlease enter your choice for iso modes: ");
    835   return;
    836 }
    837 
    838 static void camera_preview_video_sharpness_change_tbl(void) {
    839   unsigned int i;
    840   printf("\n");
    841   printf("==========================================================\n");
    842   printf("      Camera is in sharpness change mode       \n");
    843   printf("==========================================================\n\n");
    844 
    845   char submenuNum = 'A';
    846   for (i = 0 ; i < sizeof(camera_sharpness_tbl) /
    847                    sizeof(camera_sharpness_tbl[0]); i++) {
    848         printf("%c.  %s\n", submenuNum, camera_sharpness_tbl[i].sharpness_name);
    849         submenuNum++;
    850   }
    851   printf("\nPlease enter your choice for sharpness modes: ");
    852   return;
    853 }
    854 
    855 static void camera_record_tbl(void) {
    856   unsigned int i;
    857   printf("\n");
    858   printf("==========================================================\n");
    859   printf("      Camera is in record mode       \n");
    860   printf("==========================================================\n\n");
    861 
    862   char submenuNum = 'A';
    863   for (i = 0 ; i < sizeof(record_tbl) /
    864                    sizeof(record_tbl[0]); i++) {
    865         printf("%c.  %s\n", submenuNum, record_tbl[i].act_name);
    866         submenuNum++;
    867   }
    868   printf("\nPlease enter your choice:  ");
    869   return;
    870 }
    871 
    872 static void camera_switch_tbl(void) {
    873   unsigned int i;
    874   printf("\n");
    875   printf("==========================================================\n");
    876   printf("      Camera is in switch camera mode       \n");
    877   printf("==========================================================\n\n");
    878 
    879   char submenuNum = 'A';
    880   for (i = 0 ; i < sizeof(cam_tbl) /
    881                    sizeof(cam_tbl[0]); i++) {
    882         printf("%c.  %s\n", submenuNum, cam_tbl[i].cam_name);
    883         submenuNum++;
    884   }
    885   printf("\nPlease enter your choice for camera modes: ");
    886   return;
    887 }
    888 /*===========================================================================
    889  * FUNCTION     - increase_contrast -
    890  *
    891  * DESCRIPTION:
    892  * ===========================================================================*/
    893 int increase_contrast (void) {
    894   ++contrast;
    895   if (contrast > CAMERA_MAX_CONTRAST) {
    896     contrast = CAMERA_MAX_CONTRAST;
    897     printf("Reached max CONTRAST. \n");
    898   } else
    899     printf("Increase CONTRAST to %d\n", contrast);
    900 
    901   /*intrfcCtrl.setContrast(camfd, contrast);*/
    902 
    903   struct v4l2_queryctrl queryctrl;
    904   struct v4l2_control control;
    905 
    906   memset (&queryctrl, 0, sizeof (queryctrl));
    907   queryctrl.id = V4L2_CID_CONTRAST;
    908 #if 0 /* TBD */
    909   if (-1 == ioctl (camfd, VIDIOC_QUERYCTRL, &queryctrl)) {
    910     if (errno != EINVAL) {
    911       perror ("VIDIOC_QUERYCTRL");
    912       exit (EXIT_FAILURE);
    913     } else {
    914       printf ("V4L2_CID_contrast is not supported\n");
    915     }
    916   } else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
    917     printf ("V4L2_CID_contrast is not supported\n");
    918   } else {
    919     memset (&control, 0, sizeof (control));
    920     control.id = V4L2_CID_CONTRAST;
    921     /* Decreasing the contrast */
    922     control.value = contrast;
    923 
    924  //   if (-1 == ioctl (camfd, VIDIOC_S_CTRL, &control)) {
    925  //     perror ("VIDIOC_S_CTRL");
    926  //     return -1;
    927  //   }
    928   }
    929 #endif /* TBD */
    930   return 0;
    931 }
    932 
    933 /*===========================================================================
    934  * FUNCTION     - decrease_contrast -
    935  *
    936  * DESCRIPTION:
    937  * ===========================================================================*/
    938 int decrease_contrast (void) {
    939   --contrast;
    940   if (contrast < CAMERA_MIN_CONTRAST) {
    941     contrast = CAMERA_MIN_CONTRAST;
    942     printf("Reached min CONTRAST. \n");
    943   } else
    944     printf("Decrease CONTRAST to %d\n", contrast);
    945 
    946   /*intrfcCtrl.setContrast(camfd, contrast);*/
    947   struct v4l2_queryctrl queryctrl;
    948   struct v4l2_control control;
    949 
    950   memset (&queryctrl, 0, sizeof (queryctrl));
    951   queryctrl.id = V4L2_CID_CONTRAST;
    952 #if 0 /* TBD */
    953   if (-1 == ioctl (camfd, VIDIOC_QUERYCTRL, &queryctrl)) {
    954     if (errno != EINVAL) {
    955       perror ("VIDIOC_QUERYCTRL");
    956       exit (EXIT_FAILURE);
    957     } else {
    958       printf ("V4L2_CID_contrast is not supported\n");
    959     }
    960   } else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
    961     printf ("V4L2_CID_contrast is not supported\n");
    962   } else {
    963     memset (&control, 0, sizeof (control));
    964     control.id = V4L2_CID_CONTRAST;
    965     /* Decreasing the contrast */
    966     control.value = contrast;
    967 
    968   //  if (-1 == ioctl (camfd, VIDIOC_S_CTRL, &control)) {
    969   //    perror ("VIDIOC_S_CTRL");
    970   //    return -1;
    971   //  }
    972   }
    973 #endif /* TBD */
    974   return 0;
    975 }
    976 
    977 /*===========================================================================
    978  * FUNCTION     - decrease_brightness -
    979  *
    980  * DESCRIPTION:
    981  * ===========================================================================*/
    982 int decrease_brightness (void) {
    983   brightness -= CAMERA_BRIGHTNESS_STEP;
    984   if (brightness < CAMERA_MIN_BRIGHTNESS) {
    985     brightness = CAMERA_MIN_BRIGHTNESS;
    986     printf("Reached min BRIGHTNESS. \n");
    987   } else
    988     printf("Decrease BRIGHTNESS to %d\n", brightness);
    989 
    990   struct v4l2_queryctrl queryctrl;
    991   struct v4l2_control control;
    992 
    993   memset (&queryctrl, 0, sizeof (queryctrl));
    994   queryctrl.id = V4L2_CID_BRIGHTNESS;
    995 #if 0 /* TBD */
    996   if (-1 == ioctl (camfd, VIDIOC_QUERYCTRL, &queryctrl)) {
    997     if (errno != EINVAL) {
    998       perror ("VIDIOC_QUERYCTRL");
    999       exit (EXIT_FAILURE);
   1000     } else {
   1001       printf ("V4L2_CID_BRIGHTNESS is not supported\n");
   1002     }
   1003   } else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
   1004     printf ("V4L2_CID_BRIGHTNESS is not supported\n");
   1005   } else {
   1006     memset (&control, 0, sizeof (control));
   1007     control.id = V4L2_CID_BRIGHTNESS;
   1008     /* Decreasing the Brightness */
   1009     control.value = brightness;
   1010 
   1011     if (-1 == ioctl (camfd, VIDIOC_S_CTRL, &control)) {
   1012       perror ("VIDIOC_S_CTRL");
   1013       return -1;
   1014     }
   1015   }
   1016 #endif /* TBD */
   1017   return 0;
   1018 }
   1019 
   1020 /*===========================================================================
   1021  * FUNCTION     - increase_brightness -
   1022  *
   1023  * DESCRIPTION:
   1024  * ===========================================================================*/
   1025 int increase_brightness (void) {
   1026   brightness += CAMERA_BRIGHTNESS_STEP;
   1027   if (brightness > CAMERA_MAX_BRIGHTNESS) {
   1028     brightness = CAMERA_MAX_BRIGHTNESS;
   1029     printf("Reached max BRIGHTNESS. \n");
   1030   } else
   1031     printf("Increase BRIGHTNESS to %d\n", brightness);
   1032 
   1033   struct v4l2_queryctrl queryctrl;
   1034   struct v4l2_control control;
   1035 
   1036   memset (&queryctrl, 0, sizeof (queryctrl));
   1037   queryctrl.id = V4L2_CID_BRIGHTNESS;
   1038 #if 0 /* TBD */
   1039   if (-1 == ioctl (camfd, VIDIOC_QUERYCTRL, &queryctrl)) {
   1040     if (errno != EINVAL) {
   1041       perror ("VIDIOC_QUERYCTRL");
   1042       exit (EXIT_FAILURE);
   1043     } else {
   1044       printf ("V4L2_CID_BRIGHTNESS is not supported\n");
   1045     }
   1046   } else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
   1047     printf ("V4L2_CID_BRIGHTNESS is not supported\n");
   1048   } else {
   1049     memset (&control, 0, sizeof (control));
   1050     control.id = V4L2_CID_BRIGHTNESS;
   1051     /* Increasing the Brightness */
   1052     control.value = brightness;
   1053 
   1054     if (-1 == ioctl (camfd, VIDIOC_S_CTRL, &control)) {
   1055       perror ("VIDIOC_S_CTRL");
   1056       return -1;
   1057     }
   1058   }
   1059 #endif /* TBD */
   1060   return 0;
   1061 }
   1062 
   1063 /*===========================================================================
   1064  * FUNCTION     - increase_EV -
   1065  *
   1066  * DESCRIPTION:
   1067  * ===========================================================================*/
   1068 int increase_EV (void) {
   1069   int32_t ev = 0;
   1070   if (++ev_num <= 12) {
   1071      ev = (ev_num << 16) | 6;
   1072     printf("Increase EV to %d\n", ev_num);
   1073   } else {
   1074     printf("Reached max EV. \n");
   1075     ev = ev_num;
   1076   }
   1077 
   1078   struct v4l2_queryctrl queryctrl;
   1079   struct v4l2_control control;
   1080 
   1081   memset (&queryctrl, 0, sizeof (queryctrl));
   1082   queryctrl.id = V4L2_CID_EXPOSURE;
   1083 #if 0 /* TBD */
   1084   if (-1 == ioctl (camfd, VIDIOC_QUERYCTRL, &queryctrl)) {
   1085     if (errno != EINVAL) {
   1086       perror ("VIDIOC_QUERYCTRL");
   1087       exit (EXIT_FAILURE);
   1088     } else {
   1089       printf ("V4L2_CID_EXPOSURE is not supported\n");
   1090     }
   1091   } else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
   1092     printf ("V4L2_CID_EXPOSURE is not supported\n");
   1093   } else {
   1094     memset (&control, 0, sizeof (control));
   1095     control.id = V4L2_CID_EXPOSURE;
   1096     /* Increasing the EV*/
   1097     control.value = ev;
   1098 
   1099     if (-1 == ioctl (camfd, VIDIOC_S_CTRL, &control)) {
   1100       perror ("VIDIOC_S_CTRL");
   1101       return -1;
   1102     }
   1103   }
   1104 #endif /* TBD */
   1105   return 0;
   1106 }
   1107 
   1108 /*===========================================================================
   1109  * FUNCTION     - decrease_EV -
   1110  *
   1111  * DESCRIPTION:
   1112  * ===========================================================================*/
   1113 int decrease_EV (void) {
   1114   int32_t ev = 0;
   1115   if (--ev_num > -12) {
   1116     ev = (ev_num << 16) | 6;
   1117     printf("Decrease EV to %d\n", ev_num);
   1118   } else {
   1119     printf("Reached min EV. \n");
   1120     ev = ev_num;
   1121   }
   1122 
   1123   struct v4l2_queryctrl queryctrl;
   1124   struct v4l2_control control;
   1125 
   1126   memset (&queryctrl, 0, sizeof (queryctrl));
   1127   queryctrl.id = V4L2_CID_EXPOSURE;
   1128 #if 0 /* TBD */
   1129   if (-1 == ioctl (camfd, VIDIOC_QUERYCTRL, &queryctrl)) {
   1130     if (errno != EINVAL) {
   1131       perror ("VIDIOC_QUERYCTRL");
   1132       exit (EXIT_FAILURE);
   1133     } else {
   1134       printf ("V4L2_CID_EXPOSURE is not supported\n");
   1135     }
   1136   } else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
   1137     printf ("V4L2_CID_EXPOSURE is not supported\n");
   1138   } else {
   1139     memset (&control, 0, sizeof (control));
   1140     control.id = V4L2_CID_EXPOSURE;
   1141     /* Increasing the EV*/
   1142     control.value = ev;
   1143 
   1144     if (-1 == ioctl (camfd, VIDIOC_S_CTRL, &control)) {
   1145       perror ("VIDIOC_S_CTRL");
   1146       return -1;
   1147     }
   1148   }
   1149 #endif /* TBD */
   1150   return 0;
   1151 }
   1152 
   1153 /*===========================================================================
   1154  * FUNCTION     - increase_contrast -
   1155  *
   1156  * DESCRIPTION:
   1157  * ===========================================================================*/
   1158 int increase_saturation (void) {
   1159   ++saturation;
   1160   if (saturation > CAMERA_MAX_SATURATION) {
   1161     saturation = CAMERA_MAX_SATURATION;
   1162     printf("Reached max saturation. \n");
   1163   } else
   1164     printf("Increase saturation to %d\n", saturation);
   1165 
   1166   /*intrfcCtrl.setContrast(camfd, contrast);*/
   1167 
   1168   struct v4l2_queryctrl queryctrl;
   1169   struct v4l2_control control;
   1170 
   1171   memset (&queryctrl, 0, sizeof (queryctrl));
   1172   queryctrl.id = V4L2_CID_SATURATION;
   1173 #if 0 /* TBD */
   1174   if (-1 == ioctl (camfd, VIDIOC_QUERYCTRL, &queryctrl)) {
   1175     if (errno != EINVAL) {
   1176       perror ("VIDIOC_QUERYCTRL");
   1177       exit (EXIT_FAILURE);
   1178     } else {
   1179       printf ("V4L2_CID_saturation is not supported\n");
   1180     }
   1181   } else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
   1182     printf ("V4L2_CID_saturation is not supported\n");
   1183   } else {
   1184     memset (&control, 0, sizeof (control));
   1185     control.id = V4L2_CID_SATURATION;
   1186     /* Decreasing the contrast */
   1187     control.value = saturation;
   1188 
   1189     if (-1 == ioctl (camfd, VIDIOC_S_CTRL, &control)) {
   1190       perror ("VIDIOC_S_CTRL");
   1191       return -1;
   1192     }
   1193   }
   1194 #endif /* TBD */
   1195   return 0;
   1196 }
   1197 
   1198 /*===========================================================================
   1199  * FUNCTION     - decrease_saturation -
   1200  *
   1201  * DESCRIPTION:
   1202  * ===========================================================================*/
   1203 int decrease_saturation (void) {
   1204   --saturation;
   1205   if (saturation < CAMERA_MIN_SATURATION) {
   1206     saturation = CAMERA_MIN_SATURATION;
   1207     printf("Reached min saturation. \n");
   1208   } else
   1209     printf("Decrease saturation to %d\n", saturation);
   1210 
   1211   /*intrfcCtrl.setContrast(camfd, contrast);*/
   1212   struct v4l2_queryctrl queryctrl;
   1213   struct v4l2_control control;
   1214 
   1215   memset (&queryctrl, 0, sizeof (queryctrl));
   1216   queryctrl.id = V4L2_CID_SATURATION;
   1217 #if 0 /* TBD */
   1218   if (-1 == ioctl (camfd, VIDIOC_QUERYCTRL, &queryctrl)) {
   1219     if (errno != EINVAL) {
   1220       perror ("VIDIOC_QUERYCTRL");
   1221       exit (EXIT_FAILURE);
   1222     } else {
   1223       printf ("V4L2_CID_saturation is not supported\n");
   1224     }
   1225   } else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
   1226     printf ("V4L2_CID_saturation is not supported\n");
   1227   } else {
   1228     memset (&control, 0, sizeof (control));
   1229     control.id = V4L2_CID_SATURATION;
   1230     /* Decreasing the contrast */
   1231     control.value = saturation;
   1232 
   1233     if (-1 == ioctl (camfd, VIDIOC_S_CTRL, &control)) {
   1234       perror ("VIDIOC_S_CTRL");
   1235       return -1;
   1236     }
   1237   }
   1238 #endif /* TBD */
   1239   return 0;
   1240 }
   1241 
   1242 int takePicture_yuv(int cam_id)
   1243 {
   1244   int rc = 0;
   1245   CDBG("%s:BEGIN\n", __func__);
   1246   if(0 != (rc = mm_app_take_picture(cam_id))) {
   1247     CDBG_ERROR("%s: mm_app_take_picture() err=%d\n", __func__, rc);
   1248   }
   1249   return rc;
   1250 }
   1251 
   1252 int takePicture_zsl(int cam_id)
   1253 {
   1254   int rc = 0;
   1255   CDBG("%s:BEGIN\n", __func__);
   1256   if(0 != (rc = mm_app_take_zsl(cam_id))) {
   1257     CDBG_ERROR("%s: mm_app_take_picture() err=%d\n", __func__, rc);
   1258   }
   1259   return rc;
   1260 }
   1261 
   1262 int takePicture_live(int cam_id)
   1263 {
   1264   int rc = 0;
   1265   CDBG("%s:BEGIN\n", __func__);
   1266   if(0 != (rc = mm_app_take_live_snapshot(cam_id))) {
   1267     CDBG_ERROR("%s: mm_app_take_picture() err=%d\n", __func__, rc);
   1268   }
   1269   return rc;
   1270 }
   1271 
   1272 int takePicture_raw(int cam_id)
   1273 {
   1274   int rc = 0;
   1275   CDBG("%s:BEGIN\n", __func__);
   1276   if(0 != (rc = mm_app_take_raw_picture(cam_id))) {
   1277     CDBG("%s: mm_app_take_raw_picture() err=%d\n", __func__, rc);
   1278   }
   1279   return rc;
   1280 }
   1281 int system_dimension_set(int cam_id)
   1282 {
   1283   static cam_ctrl_dimension_t dim;
   1284   int rc = 0;
   1285 
   1286   if (preview_video_resolution_flag == 0) {
   1287     mm_app_set_dim_def(&dim);
   1288   } else {
   1289     dim.video_width = input_display.user_input_display_width;
   1290     dim.video_width = CEILING32(dim.video_width);
   1291     dim.video_height = input_display.user_input_display_height;
   1292     dim.orig_video_width = dim.video_width;
   1293     dim.orig_video_height = dim.video_height;
   1294     dim.display_width = dim.video_width;
   1295     dim.display_height = dim.video_height;
   1296   }
   1297   rc = mm_app_set_dim(cam_id, &dim);
   1298   return rc;
   1299 }
   1300 
   1301 /*int run_test_harness()
   1302 {
   1303     int good_test_cnt = 0;
   1304 
   1305     rc = run_test_1();
   1306     if(rc < 0)
   1307         CDBG_EROR("%s: run_test_1 err = %d", __func__, rc);
   1308     rc = run_test_2();
   1309 }*/
   1310 /*===========================================================================
   1311  * FUNCTION    - main -
   1312  *
   1313  * DESCRIPTION:
   1314  *==========================================================================*/
   1315 int main(int argc, char **argv)
   1316 {
   1317   int keep_on_going = 1;
   1318   int c, rc = 0, tmp_fd;
   1319   int run_tc = 0;
   1320   int run_dual_tc = 0;
   1321   struct v4l2_capability v4l2_cap;
   1322 
   1323   /* get v4l2 params - memory type etc */
   1324   while ((c = getopt(argc, argv, "tdh")) != -1) {
   1325     //printf("usage: %s [-m] [-u] [-o]\n", argv[1]);
   1326     switch (c) {
   1327 #if 0
   1328       case 'm':
   1329         memoryType = V4L2_MEMORY_MMAP;
   1330         break;
   1331 
   1332       case 'o':
   1333         /*use_overlay_fb_display_driver();*/
   1334         break;
   1335       case 'u':
   1336         memoryType = V4L2_MEMORY_USERPTR;
   1337         break;
   1338 #endif
   1339       case 't':
   1340         run_tc = 1;
   1341         break;
   1342       case 'd':
   1343         run_dual_tc = 1;
   1344         break;
   1345       case 'h':
   1346       default:
   1347         printf("usage: %s [-m] [-u] [-o]\n", argv[0]);
   1348         printf("-m:   V4L2_MEMORY_MMAP.      \n");
   1349         printf("-o:   use overlay fb display driver\n");
   1350         printf("-u:   V4L2_MEMORY_USERPTR\n");
   1351         exit(0);
   1352     }
   1353   }
   1354 
   1355   CDBG("\nCamera Test Application\n");
   1356 
   1357   struct timeval tdBeforePreviewVideo, tdStopCamera;
   1358   struct timezone tz;
   1359 
   1360   //return run_test_harness();
   1361   if((rc = mm_app_load_hal())) {
   1362     CDBG_ERROR("%s:mm_app_init err=%d\n", __func__, rc);
   1363     exit(-1);
   1364   }
   1365     /* we must init mm_app first */
   1366   if(mm_app_init() != MM_CAMERA_OK) {
   1367     CDBG_ERROR("%s:mm_app_init err=%d\n", __func__, rc);
   1368     exit(-1);
   1369   }
   1370 
   1371   if(run_tc) {
   1372     printf("\tRunning unit test engine only\n");
   1373     rc = mm_app_unit_test();
   1374     printf("\tUnit test engine. EXIT(%d)!!!\n", rc);
   1375     exit(rc);
   1376   }
   1377 
   1378   if(run_dual_tc) {
   1379     printf("\tRunning Dual camera test engine only\n");
   1380     rc = mm_app_dual_test();
   1381     printf("\t Dual camera engine. EXIT(%d)!!!\n", rc);
   1382     exit(rc);
   1383   }
   1384 
   1385   gettimeofday(&tdBeforePreviewVideo, &tz);
   1386 
   1387   CDBG("Profiling: Start Camera timestamp = %ld ms\n",
   1388     (tdBeforePreviewVideo.tv_sec * 1000) + (tdBeforePreviewVideo.tv_usec/1000));
   1389 
   1390   /* launch the primary camera in default mode */
   1391   if( mm_app_open(CAMERA_OPENED)) {
   1392     CDBG_ERROR("%s:mm_app_open() err=%d\n",__func__, rc);
   1393     exit(-2);
   1394   }
   1395 
   1396   /* main loop doing the work*/
   1397   do {
   1398     keep_on_going = submain();
   1399   } while ( keep_on_going );
   1400 
   1401   /* Clean up and exit. */
   1402   CDBG("Exiting the app\n");
   1403 
   1404 error_ionfd_open:
   1405   mm_app_close(CAMERA_OPENED);
   1406 
   1407   gettimeofday(&tdStopCamera, &tz);
   1408   CDBG("Exiting application\n");
   1409   CDBG("Profiling: Stop camera end timestamp = %ld ms\n",
   1410       (tdStopCamera.tv_sec * 1000) + (tdStopCamera.tv_usec/1000));
   1411 
   1412   return 0;
   1413 }
   1414 
   1415 
   1416 /*===========================================================================
   1417  * FUNCTION     - submain -
   1418  *
   1419  * DESCRIPTION:
   1420  * ===========================================================================*/
   1421 static int submain()
   1422 {
   1423   int rc = 0;
   1424   int back_mainflag = 0;
   1425   char tc_buf[3];
   1426   int stop_preview = 1;
   1427   menu_id_change_t current_menu_id = MENU_ID_MAIN, next_menu_id;
   1428   camera_action_t action_id;
   1429   int action_param;
   1430   int i;
   1431   int cam_id;
   1432 
   1433   CDBG("%s:E", __func__);
   1434   struct timeval tdStopCamera;
   1435   struct timezone tz;
   1436 
   1437   cam_id = my_cam_app.cam_open;
   1438 
   1439   rc = system_dimension_set(cam_id);
   1440   CDBG("Start Preview");
   1441   if( 0 != (rc = startPreview(cam_id))) {
   1442     CDBG("%s: startPreview() err=%d\n", __func__, rc);
   1443     return 0;
   1444   }
   1445 
   1446   do {
   1447     print_current_menu (current_menu_id);
   1448     fgets(tc_buf, 3, stdin);
   1449 
   1450     next_menu_id = next_menu(current_menu_id, tc_buf[0], &action_id, &action_param);
   1451 
   1452     if (next_menu_id != MENU_ID_INVALID) {
   1453       current_menu_id = next_menu_id;
   1454     }
   1455     if (action_id == ACTION_NO_ACTION) {
   1456       continue;
   1457     }
   1458     if(camframe_status == -1) {
   1459       printf("Preview/Video ERROR condition reported Closing Camera APP\n");
   1460       break;
   1461     }
   1462 
   1463     switch(action_id) {
   1464       case ACTION_STOP_CAMERA:
   1465         CDBG("ACTION_STOP_CAMERA \n");
   1466         stopPreview(cam_id);
   1467         break;
   1468 
   1469       case ACTION_PREVIEW_VIDEO_RESOLUTION:
   1470         back_mainflag = 1;
   1471         CDBG("Selection for the preview/video resolution change\n");
   1472         switchRes(cam_id);
   1473         preview_video_resolution (action_param);
   1474         break;
   1475       case ACTION_SET_WHITE_BALANCE:
   1476         CDBG("Selection for the White Balance changes\n");
   1477         set_whitebalance(action_param);
   1478         break;
   1479 
   1480       case ACTION_SET_EXP_METERING:
   1481         CDBG("Selection for the Exposure Metering changes\n");
   1482         set_exp_metering(action_param);
   1483         break;
   1484 
   1485       case ACTION_GET_CTRL_VALUE:
   1486         CDBG("Selection for getting control value\n");
   1487         get_ctrl_value(action_param);
   1488         break;
   1489 
   1490       case ACTION_BRIGHTNESS_INCREASE:
   1491         printf("Increase brightness\n");
   1492         increase_brightness();
   1493         break;
   1494 
   1495       case ACTION_BRIGHTNESS_DECREASE:
   1496         printf("Decrease brightness\n");
   1497         decrease_brightness();
   1498         break;
   1499 
   1500       case ACTION_CONTRAST_INCREASE:
   1501         CDBG("Selection for the contrast increase\n");
   1502         increase_contrast ();
   1503         break;
   1504 
   1505       case ACTION_CONTRAST_DECREASE:
   1506         CDBG("Selection for the contrast decrease\n");
   1507         decrease_contrast ();
   1508         break;
   1509 
   1510       case ACTION_EV_INCREASE:
   1511         CDBG("Selection for the EV increase\n");
   1512         increase_EV ();
   1513         break;
   1514 
   1515       case ACTION_EV_DECREASE:
   1516         CDBG("Selection for the EV decrease\n");
   1517         decrease_EV ();
   1518         break;
   1519 
   1520       case ACTION_SATURATION_INCREASE:
   1521         CDBG("Selection for the EV increase\n");
   1522         increase_saturation ();
   1523         break;
   1524 
   1525       case ACTION_SATURATION_DECREASE:
   1526         CDBG("Selection for the EV decrease\n");
   1527         decrease_saturation ();
   1528         break;
   1529 
   1530       case ACTION_TOGGLE_AFR:
   1531         CDBG("Select for auto frame rate toggling\n");
   1532         toggle_afr();
   1533         break;
   1534 
   1535       case ACTION_SET_ISO:
   1536         CDBG("Select for ISO changes\n");
   1537         set_iso(action_param);
   1538         break;
   1539 
   1540       case ACTION_SET_ZOOM:
   1541         CDBG("Selection for the zoom direction changes\n");
   1542         set_zoom(action_param);
   1543         break;
   1544 
   1545       case ACTION_SHARPNESS_INCREASE:
   1546         CDBG("Selection for sharpness increase\n");
   1547         increase_sharpness();
   1548         break;
   1549 
   1550       case ACTION_SHARPNESS_DECREASE:
   1551         CDBG("Selection for sharpness decrease\n");
   1552         decrease_sharpness();
   1553         break;
   1554 
   1555       case ACTION_TAKE_YUV_SNAPSHOT:
   1556         CDBG("Take YUV snapshot\n");
   1557         if (takePicture_yuv(cam_id) < 0)
   1558           goto ERROR;
   1559         break;
   1560       case ACTION_TAKE_RAW_SNAPSHOT:
   1561         CDBG("Take YUV snapshot\n");
   1562         if (takePicture_raw(cam_id) < 0)
   1563           goto ERROR;
   1564         break;
   1565       case ACTION_START_RECORDING:
   1566         CDBG("Start recording action\n");
   1567         if (startRecording(cam_id) < 0)
   1568           goto ERROR;
   1569         break;
   1570       case ACTION_STOP_RECORDING:
   1571         CDBG("Stop recording action\n");
   1572         if (stopRecording(cam_id) < 0)
   1573           goto ERROR;
   1574         break;
   1575       case ACTION_NO_ACTION:
   1576         printf("Go back to main menu");
   1577         break;
   1578       case ACTION_SWITCH_CAMERA:
   1579         CDBG("Toggle Camera action\n");
   1580         back_mainflag = 1;
   1581         if (switchCamera(action_param - 1) < 0)
   1582           goto ERROR;
   1583         break;
   1584 
   1585       case ACTION_TAKE_ZSL_SNAPSHOT:
   1586         CDBG("Take ZSL snapshot\n");
   1587         if (takePicture_zsl(cam_id) < 0)
   1588         {
   1589           CDBG("Error");
   1590           goto ERROR;
   1591         }
   1592         break;
   1593       case ACTION_START_RDI:
   1594 		CDBG("Start RDI Stream\n");
   1595 		startRdi(cam_id);
   1596 		break;
   1597 	  case ACTION_STOP_RDI:
   1598 		CDBG("Stop RDI Stream\n");
   1599 		stopRdi(cam_id);
   1600 		break;
   1601       case ACTION_TAKE_LIVE_SNAPSHOT:
   1602         CDBG("Take Live snapshot\n");
   1603         if (takePicture_live(cam_id) < 0)
   1604         {
   1605           CDBG("Error");
   1606           goto ERROR;
   1607         }
   1608         break;
   1609 
   1610       default:
   1611         printf("\n\n!!!!!WRONG INPUT: %d!!!!\n", action_id);
   1612         break;
   1613     }
   1614 
   1615     usleep(1000 * 1000);
   1616     CDBG("action_id = %d\n", action_id);
   1617     camframe_status = 0;
   1618 
   1619   } while ((action_id != ACTION_STOP_CAMERA) &&
   1620       (action_id != ACTION_PREVIEW_VIDEO_RESOLUTION) && (action_id !=ACTION_SWITCH_CAMERA));
   1621   action_id = ACTION_NO_ACTION;
   1622 
   1623   //system_destroy();
   1624 
   1625 
   1626   return back_mainflag;
   1627 
   1628 ERROR:
   1629   back_mainflag = 0;
   1630   return back_mainflag;
   1631 }
   1632 
   1633 
   1634 /*===========================================================================
   1635  * FUNCTION     - preview_resolution -
   1636  *
   1637  * DESCRIPTION:
   1638  * ===========================================================================*/
   1639 int preview_video_resolution (int preview_video_action_param) {
   1640   char * resolution_name;
   1641   CDBG("Selecting the action for preview/video resolution = %d \n", preview_video_action_param);
   1642   resolution_name = set_preview_video_dimension_tbl(preview_video_action_param,
   1643                       & input_display.user_input_display_width,
   1644                       & input_display.user_input_display_height);
   1645 
   1646   CDBG("Selected preview/video resolution is %s\n", resolution_name);
   1647 
   1648   if (resolution_name == NULL) {
   1649     CDBG("main:%d set_preview_dimension failed!\n", __LINE__);
   1650     goto ERROR;
   1651   }
   1652 
   1653   CDBG("Selected Preview Resolution: display_width = %d, display_height = %d\n",
   1654     input_display.user_input_display_width, input_display.user_input_display_height);
   1655 
   1656   preview_video_resolution_flag = 1;
   1657   return 0;
   1658 
   1659 ERROR:
   1660   return -1;
   1661 }
   1662 
   1663 /*===========================================================================
   1664  * FUNCTION     - set_whitebalance -
   1665  *
   1666  * DESCRIPTION:
   1667  * ===========================================================================*/
   1668 int set_whitebalance (int wb_action_param) {
   1669 
   1670 	int rc = 0;
   1671 	struct v4l2_control ctrl;
   1672 
   1673   if (wb_action_param == MM_CAMERA_WHITE_BALANCE_AUTO) {
   1674 		ctrl.id = V4L2_CID_AUTO_WHITE_BALANCE;
   1675 		ctrl.value = true;
   1676 	//	rc = ioctl(camfd, VIDIOC_S_CTRL, &ctrl);
   1677 
   1678 	} else if ( wb_action_param == MM_CAMERA_WHITE_BALANCE_OFF) {
   1679 		ctrl.id = V4L2_CID_AUTO_WHITE_BALANCE;
   1680 		ctrl.value = false;
   1681 	//	rc = ioctl(camfd, VIDIOC_S_CTRL, &ctrl);
   1682 
   1683   } else {
   1684 		int temperature = 6500;
   1685 
   1686 		switch (wb_action_param) {
   1687 			case MM_CAMERA_WHITE_BALANCE_DAYLIGHT:
   1688 				temperature = 6500;
   1689 				break;
   1690 			case MM_CAMERA_WHITE_BALANCE_INCANDESCENT:
   1691 				temperature = 2800;
   1692 				break;
   1693 			case MM_CAMERA_WHITE_BALANCE_FLUORESCENT:
   1694 				temperature = 4200;
   1695 				break;
   1696 			default:
   1697 				temperature = 4200;
   1698 				break;
   1699 		}
   1700 
   1701 		ctrl.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE;
   1702 		ctrl.value = temperature;
   1703 	//	rc = ioctl(camfd, VIDIOC_S_CTRL, &ctrl);
   1704 	}
   1705 
   1706 DONE:
   1707 	return rc;
   1708 }
   1709 
   1710 
   1711 /*===========================================================================
   1712  * FUNCTION     - set_exp_metering -
   1713  *
   1714  * DESCRIPTION:
   1715  * ===========================================================================*/
   1716 int set_exp_metering (int exp_metering_action_param) {
   1717 
   1718 	int rc = 0;
   1719 	struct v4l2_control ctrl;
   1720 
   1721   ctrl.id = MSM_V4L2_PID_EXP_METERING;
   1722   ctrl.value = exp_metering_action_param;
   1723  // rc = ioctl(camfd, VIDIOC_S_CTRL, &ctrl);
   1724 
   1725   return rc;
   1726 }
   1727 
   1728 int get_ctrl_value (int ctrl_value_mode_param){
   1729 
   1730     int rc = 0;
   1731     struct v4l2_control ctrl;
   1732 
   1733     if (ctrl_value_mode_param == WHITE_BALANCE_STATE) {
   1734         printf("You chose WHITE_BALANCE_STATE\n");
   1735         ctrl.id = V4L2_CID_AUTO_WHITE_BALANCE;
   1736     }
   1737     else if (ctrl_value_mode_param == WHITE_BALANCE_TEMPERATURE) {
   1738         printf("You chose WHITE_BALANCE_TEMPERATURE\n");
   1739         ctrl.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE;
   1740     }
   1741     else if (ctrl_value_mode_param == BRIGHTNESS_CTRL) {
   1742         printf("You chose brightness value\n");
   1743         ctrl.id = V4L2_CID_BRIGHTNESS;
   1744     }
   1745     else if (ctrl_value_mode_param == EV) {
   1746         printf("You chose exposure value\n");
   1747         ctrl.id = V4L2_CID_EXPOSURE;
   1748     }
   1749     else if (ctrl_value_mode_param == CONTRAST_CTRL) {
   1750         printf("You chose contrast value\n");
   1751         ctrl.id = V4L2_CID_CONTRAST;
   1752     }
   1753     else if (ctrl_value_mode_param == SATURATION_CTRL) {
   1754         printf("You chose saturation value\n");
   1755         ctrl.id = V4L2_CID_SATURATION;
   1756     } else if (ctrl_value_mode_param == SHARPNESS_CTRL) {
   1757         printf("You chose sharpness value\n");
   1758         ctrl.id = V4L2_CID_SHARPNESS;
   1759     }
   1760 
   1761   //  rc = ioctl(camfd, VIDIOC_G_CTRL, &ctrl);
   1762 
   1763     return rc;
   1764 }
   1765 
   1766 /*===========================================================================
   1767  * FUNCTION     - toggle_afr -
   1768  *
   1769  * DESCRIPTION:
   1770  * ===========================================================================*/
   1771 int toggle_afr () {
   1772   int rc = 0;
   1773   struct v4l2_control ctrl;
   1774 
   1775   memset(&ctrl, 0, sizeof(ctrl));
   1776   ctrl.id = V4L2_CID_EXPOSURE_AUTO;
   1777 //  rc = ioctl(camfd, VIDIOC_G_CTRL, &ctrl);
   1778   if (rc == -1) {
   1779     CDBG("%s: VIDIOC_G_CTRL V4L2_CID_EXPOSURE_AUTO failed: %s\n",
   1780         __func__, strerror(errno));
   1781     return rc;
   1782   }
   1783 
   1784   /* V4L2_CID_EXPOSURE_AUTO needs to be AUTO or SHUTTER_PRIORITY */
   1785   if (ctrl.value != V4L2_EXPOSURE_AUTO &&
   1786     ctrl.value != V4L2_EXPOSURE_SHUTTER_PRIORITY) {
   1787     CDBG("%s: V4L2_CID_EXPOSURE_AUTO needs to be AUTO/SHUTTER_PRIORITY\n",
   1788         __func__);
   1789     return -1;
   1790   }
   1791 
   1792   /* Get V4L2_CID_EXPOSURE_AUTO_PRIORITY */
   1793   memset(&ctrl, 0, sizeof(ctrl));
   1794   ctrl.id = V4L2_CID_EXPOSURE_AUTO_PRIORITY;
   1795  // rc = ioctl(camfd, VIDIOC_G_CTRL, &ctrl);
   1796   if (rc == -1) {
   1797     CDBG("%s: VIDIOC_G_CTRL V4L2_CID_EXPOSURE_AUTO_PRIORITY failed: %s\n",
   1798         __func__, strerror(errno));
   1799     return rc;
   1800   }
   1801 
   1802   ctrl.value = !ctrl.value;
   1803   printf("V4L2_CID_EXPOSURE_AUTO_PRIORITY changed to %d\n", ctrl.value);
   1804  // rc = ioctl(camfd, VIDIOC_S_CTRL, &ctrl);
   1805   if (rc == -1) {
   1806     CDBG("%s: VIDIOC_S_CTRL V4L2_CID_EXPOSURE_AUTO_PRIORITY failed: %s\n",
   1807       __func__, strerror(errno));
   1808   }
   1809   return rc;
   1810 }
   1811 
   1812 int set_zoom (int zoom_action_param) {
   1813     int rc = 0;
   1814     struct v4l2_control ctrl;
   1815 
   1816     if (zoom_action_param == ZOOM_IN) {
   1817         zoom_level += zoom_queryctrl.step;
   1818         if (zoom_level > zoom_queryctrl.maximum)
   1819             zoom_level = zoom_queryctrl.maximum;
   1820     } else if (zoom_action_param == ZOOM_OUT) {
   1821         zoom_level -= zoom_queryctrl.step;
   1822         if (zoom_level < zoom_queryctrl.minimum)
   1823             zoom_level = zoom_queryctrl.minimum;
   1824     } else {
   1825         CDBG("%s: Invalid zoom_action_param value\n", __func__);
   1826         return -EINVAL;
   1827     }
   1828     ctrl.id = V4L2_CID_ZOOM_ABSOLUTE;
   1829     ctrl.value = zoom_level;
   1830   //  rc = ioctl(camfd, VIDIOC_S_CTRL, &ctrl);
   1831 
   1832     return rc;
   1833 }
   1834 
   1835 /*===========================================================================
   1836  * FUNCTION     - set_iso -
   1837  *
   1838  * DESCRIPTION:
   1839  * ===========================================================================*/
   1840 int set_iso (int iso_action_param) {
   1841     int rc = 0;
   1842     struct v4l2_control ctrl;
   1843 
   1844     ctrl.id = MSM_V4L2_PID_ISO;
   1845     ctrl.value = iso_action_param - 1;
   1846   //  rc = ioctl(camfd, VIDIOC_S_CTRL, &ctrl);
   1847 
   1848     return rc;
   1849 }
   1850 
   1851 /*===========================================================================
   1852  * FUNCTION     - increase_sharpness -
   1853  *
   1854  * DESCRIPTION:
   1855  * ===========================================================================*/
   1856 int increase_sharpness () {
   1857     int rc = 0;
   1858     struct v4l2_control ctrl;
   1859 
   1860     sharpness += sharpness_queryctrl.step;
   1861     if (sharpness > sharpness_queryctrl.maximum)
   1862         sharpness = sharpness_queryctrl.maximum;
   1863 
   1864     ctrl.id = V4L2_CID_SHARPNESS;
   1865     ctrl.value = sharpness;
   1866  //   rc = ioctl(camfd, VIDIOC_S_CTRL, &ctrl);
   1867 
   1868     return rc;
   1869 }
   1870 
   1871 /*===========================================================================
   1872  * FUNCTION     - decrease_sharpness -
   1873  *
   1874  * DESCRIPTION:
   1875  * ===========================================================================*/
   1876 int decrease_sharpness () {
   1877     int rc = 0;
   1878     struct v4l2_control ctrl;
   1879 
   1880     sharpness -= sharpness_queryctrl.step;
   1881     if (sharpness < sharpness_queryctrl.minimum)
   1882         sharpness = sharpness_queryctrl.minimum;
   1883 
   1884     ctrl.id = V4L2_CID_SHARPNESS;
   1885     ctrl.value = sharpness;
   1886   //  rc = ioctl(camfd, VIDIOC_S_CTRL, &ctrl);
   1887 
   1888     return rc;
   1889 }
   1890 
   1891 /*===========================================================================
   1892  * FUNCTION     - print_current_menu -
   1893  *
   1894  * DESCRIPTION:
   1895  * ===========================================================================*/
   1896 int print_current_menu (menu_id_change_t current_menu_id) {
   1897   if (current_menu_id == MENU_ID_MAIN) {
   1898     print_menu_preview_video ();
   1899   } else if (current_menu_id == MENU_ID_PREVIEWVIDEORESOLUTIONCHANGE) {
   1900     camera_preview_video_resolution_change_tbl ();
   1901   }else if (current_menu_id == MENU_ID_WHITEBALANCECHANGE) {
   1902     camera_preview_video_wb_change_tbl();
   1903   } else if (current_menu_id == MENU_ID_EXPMETERINGCHANGE) {
   1904     camera_preview_video_exp_metering_change_tbl();
   1905   } else if (current_menu_id == MENU_ID_GET_CTRL_VALUE) {
   1906     camera_preview_video_get_ctrl_value_tbl();
   1907   } else if (current_menu_id == MENU_ID_ISOCHANGE) {
   1908     camera_preview_video_iso_change_tbl();
   1909   } else if (current_menu_id == MENU_ID_BRIGHTNESSCHANGE) {
   1910     camera_brightness_change_tbl ();
   1911   } else if (current_menu_id == MENU_ID_CONTRASTCHANGE) {
   1912     camera_contrast_change_tbl ();
   1913   } else if (current_menu_id == MENU_ID_EVCHANGE) {
   1914     camera_EV_change_tbl ();
   1915   } else if (current_menu_id == MENU_ID_SATURATIONCHANGE) {
   1916     camera_saturation_change_tbl ();
   1917   } else if (current_menu_id == MENU_ID_ZOOMCHANGE) {
   1918     camera_preview_video_zoom_change_tbl();
   1919   } else if (current_menu_id == MENU_ID_SHARPNESSCHANGE) {
   1920     camera_preview_video_sharpness_change_tbl();
   1921   }else if (current_menu_id == MENU_ID_SWITCHCAMERA) {
   1922     camera_switch_tbl();
   1923   }else if (current_menu_id == MENU_ID_RECORD) {
   1924     camera_record_tbl();
   1925   }
   1926 
   1927   return 0;
   1928 }
   1929 
   1930