Home | History | Annotate | Download | only in src
      1 /* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
      2  *
      3  * Redistribution and use in source and binary forms, with or without
      4  * modification, are permitted provided that the following conditions are
      5  * met:
      6  *     * Redistributions of source code must retain the above copyright
      7  *       notice, this list of conditions and the following disclaimer.
      8  *     * Redistributions in binary form must reproduce the above
      9  *       copyright notice, this list of conditions and the following
     10  *       disclaimer in the documentation and/or other materials provided
     11  *       with the distribution.
     12  *     * Neither the name of The Linux Foundation nor the names of its
     13  *       contributors may be used to endorse or promote products derived
     14  *       from this software without specific prior written permission.
     15  *
     16  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     23  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  *
     28  */
     29 
     30 // To remove
     31 #include <cutils/properties.h>
     32 
     33 // System dependencies
     34 #include <pthread.h>
     35 #include <errno.h>
     36 #include <fcntl.h>
     37 #include <stdlib.h>
     38 #include <linux/media.h>
     39 #include <media/msm_cam_sensor.h>
     40 #include <dlfcn.h>
     41 #include <unistd.h> // for close()
     42 
     43 #define IOCTL_H <SYSTEM_HEADER_PREFIX/ioctl.h>
     44 #include IOCTL_H
     45 
     46 // Camera dependencies
     47 #include "mm_camera_dbg.h"
     48 #include "mm_camera_interface.h"
     49 #include "mm_camera.h"
     50 
     51 static pthread_mutex_t g_intf_lock = PTHREAD_MUTEX_INITIALIZER;
     52 
     53 static mm_camera_ctrl_t g_cam_ctrl;
     54 
     55 static pthread_mutex_t g_handler_lock = PTHREAD_MUTEX_INITIALIZER;
     56 static uint16_t g_handler_history_count = 0; /* history count for handler */
     57 
     58 #define CAM_SENSOR_TYPE_MASK (1U<<24) // 24th (starting from 0) bit tells its a MAIN or AUX camera
     59 #define CAM_SENSOR_FORMAT_MASK (1U<<25) // 25th(starting from 0) bit tells its YUV sensor or not
     60 
     61 /*===========================================================================
     62  * FUNCTION   : mm_camera_util_generate_handler
     63  *
     64  * DESCRIPTION: utility function to generate handler for camera/channel/stream
     65  *
     66  * PARAMETERS :
     67  *   @index: index of the object to have handler
     68  *
     69  * RETURN     : uint32_t type of handle that uniquely identify the object
     70  *==========================================================================*/
     71 uint32_t mm_camera_util_generate_handler(uint8_t index)
     72 {
     73     uint32_t handler = 0;
     74     pthread_mutex_lock(&g_handler_lock);
     75     g_handler_history_count++;
     76     if (0 == g_handler_history_count) {
     77         g_handler_history_count++;
     78     }
     79     handler = g_handler_history_count;
     80     handler = (handler<<8) | index;
     81     pthread_mutex_unlock(&g_handler_lock);
     82     return handler;
     83 }
     84 
     85 /*===========================================================================
     86  * FUNCTION   : mm_camera_util_get_index_by_handler
     87  *
     88  * DESCRIPTION: utility function to get index from handle
     89  *
     90  * PARAMETERS :
     91  *   @handler: object handle
     92  *
     93  * RETURN     : uint8_t type of index derived from handle
     94  *==========================================================================*/
     95 uint8_t mm_camera_util_get_index_by_handler(uint32_t handler)
     96 {
     97     return (handler&0x000000ff);
     98 }
     99 
    100 /*===========================================================================
    101  * FUNCTION   : mm_camera_util_get_dev_name
    102  *
    103  * DESCRIPTION: utility function to get device name from camera handle
    104  *
    105  * PARAMETERS :
    106  *   @cam_handle: camera handle
    107  *
    108  * RETURN     : char ptr to the device name stored in global variable
    109  * NOTE       : caller should not free the char ptr
    110  *==========================================================================*/
    111 const char *mm_camera_util_get_dev_name(uint32_t cam_handle)
    112 {
    113     char *dev_name = NULL;
    114     uint8_t cam_idx = mm_camera_util_get_index_by_handler(cam_handle);
    115     if(cam_idx < MM_CAMERA_MAX_NUM_SENSORS) {
    116         dev_name = g_cam_ctrl.video_dev_name[cam_idx];
    117     }
    118     return dev_name;
    119 }
    120 
    121 /*===========================================================================
    122  * FUNCTION   : mm_camera_util_get_camera_by_handler
    123  *
    124  * DESCRIPTION: utility function to get camera object from camera handle
    125  *
    126  * PARAMETERS :
    127  *   @cam_handle: camera handle
    128  *
    129  * RETURN     : ptr to the camera object stored in global variable
    130  * NOTE       : caller should not free the camera object ptr
    131  *==========================================================================*/
    132 mm_camera_obj_t* mm_camera_util_get_camera_by_handler(uint32_t cam_handle)
    133 {
    134     mm_camera_obj_t *cam_obj = NULL;
    135     uint8_t cam_idx = mm_camera_util_get_index_by_handler(cam_handle);
    136 
    137     if (cam_idx < MM_CAMERA_MAX_NUM_SENSORS &&
    138         (NULL != g_cam_ctrl.cam_obj[cam_idx]) &&
    139         (cam_handle == g_cam_ctrl.cam_obj[cam_idx]->my_hdl)) {
    140         cam_obj = g_cam_ctrl.cam_obj[cam_idx];
    141     }
    142     return cam_obj;
    143 }
    144 
    145 /*===========================================================================
    146  * FUNCTION   : mm_camera_util_get_camera_by_session_id
    147  *
    148  * DESCRIPTION: utility function to get camera object from camera sessionID
    149  *
    150  * PARAMETERS :
    151  *   @session_id: sessionid for which cam obj mapped
    152  *
    153  * RETURN     : ptr to the camera object stored in global variable
    154  * NOTE       : caller should not free the camera object ptr
    155  *==========================================================================*/
    156 mm_camera_obj_t* mm_camera_util_get_camera_by_session_id(uint32_t session_id)
    157 {
    158    int cam_idx = 0;
    159    mm_camera_obj_t *cam_obj = NULL;
    160    for (cam_idx = 0; cam_idx < MM_CAMERA_MAX_NUM_SENSORS; cam_idx++) {
    161         if ((NULL != g_cam_ctrl.cam_obj[cam_idx]) &&
    162                 (session_id == (uint32_t)g_cam_ctrl.cam_obj[cam_idx]->sessionid)) {
    163             LOGD("session id:%d match idx:%d\n", session_id, cam_idx);
    164             cam_obj = g_cam_ctrl.cam_obj[cam_idx];
    165         }
    166     }
    167     return cam_obj;
    168 }
    169 
    170 /*===========================================================================
    171  * FUNCTION   : mm_camera_intf_query_capability
    172  *
    173  * DESCRIPTION: query camera capability
    174  *
    175  * PARAMETERS :
    176  *   @camera_handle: camera handle
    177  *
    178  * RETURN     : int32_t type of status
    179  *              0  -- success
    180  *              -1 -- failure
    181  *==========================================================================*/
    182 static int32_t mm_camera_intf_query_capability(uint32_t camera_handle)
    183 {
    184     int32_t rc = -1;
    185     mm_camera_obj_t * my_obj = NULL;
    186 
    187     LOGD("E: camera_handler = %d ", camera_handle);
    188 
    189     pthread_mutex_lock(&g_intf_lock);
    190     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    191 
    192     if(my_obj) {
    193         pthread_mutex_lock(&my_obj->cam_lock);
    194         pthread_mutex_unlock(&g_intf_lock);
    195         rc = mm_camera_query_capability(my_obj);
    196     } else {
    197         pthread_mutex_unlock(&g_intf_lock);
    198     }
    199     LOGD("X rc = %d", rc);
    200     return rc;
    201 }
    202 
    203 /*===========================================================================
    204  * FUNCTION   : mm_camera_intf_set_parms
    205  *
    206  * DESCRIPTION: set parameters per camera
    207  *
    208  * PARAMETERS :
    209  *   @camera_handle: camera handle
    210  *   @parms        : ptr to a param struct to be set to server
    211  *
    212  * RETURN     : int32_t type of status
    213  *              0  -- success
    214  *              -1 -- failure
    215  * NOTE       : Assume the parms struct buf is already mapped to server via
    216  *              domain socket. Corresponding fields of parameters to be set
    217  *              are already filled in by upper layer caller.
    218  *==========================================================================*/
    219 static int32_t mm_camera_intf_set_parms(uint32_t camera_handle,
    220                                         parm_buffer_t *parms)
    221 {
    222     int32_t rc = -1;
    223     mm_camera_obj_t * my_obj = NULL;
    224 
    225     pthread_mutex_lock(&g_intf_lock);
    226     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    227 
    228     if(my_obj) {
    229         pthread_mutex_lock(&my_obj->cam_lock);
    230         pthread_mutex_unlock(&g_intf_lock);
    231         rc = mm_camera_set_parms(my_obj, parms);
    232     } else {
    233         pthread_mutex_unlock(&g_intf_lock);
    234     }
    235     return rc;
    236 }
    237 
    238 /*===========================================================================
    239  * FUNCTION   : mm_camera_intf_get_parms
    240  *
    241  * DESCRIPTION: get parameters per camera
    242  *
    243  * PARAMETERS :
    244  *   @camera_handle: camera handle
    245  *   @parms        : ptr to a param struct to be get from server
    246  *
    247  * RETURN     : int32_t type of status
    248  *              0  -- success
    249  *              -1 -- failure
    250  * NOTE       : Assume the parms struct buf is already mapped to server via
    251  *              domain socket. Parameters to be get from server are already
    252  *              filled in by upper layer caller. After this call, corresponding
    253  *              fields of requested parameters will be filled in by server with
    254  *              detailed information.
    255  *==========================================================================*/
    256 static int32_t mm_camera_intf_get_parms(uint32_t camera_handle,
    257                                         parm_buffer_t *parms)
    258 {
    259     int32_t rc = -1;
    260     mm_camera_obj_t * my_obj = NULL;
    261 
    262     pthread_mutex_lock(&g_intf_lock);
    263     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    264 
    265     if(my_obj) {
    266         pthread_mutex_lock(&my_obj->cam_lock);
    267         pthread_mutex_unlock(&g_intf_lock);
    268         rc = mm_camera_get_parms(my_obj, parms);
    269     } else {
    270         pthread_mutex_unlock(&g_intf_lock);
    271     }
    272     return rc;
    273 }
    274 
    275 /*===========================================================================
    276  * FUNCTION   : mm_camera_intf_do_auto_focus
    277  *
    278  * DESCRIPTION: performing auto focus
    279  *
    280  * PARAMETERS :
    281  *   @camera_handle: camera handle
    282  *
    283  * RETURN     : int32_t type of status
    284  *              0  -- success
    285  *              -1 -- failure
    286  * NOTE       : if this call success, we will always assume there will
    287  *              be an auto_focus event following up.
    288  *==========================================================================*/
    289 static int32_t mm_camera_intf_do_auto_focus(uint32_t camera_handle)
    290 {
    291     int32_t rc = -1;
    292     mm_camera_obj_t * my_obj = NULL;
    293 
    294     pthread_mutex_lock(&g_intf_lock);
    295     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    296 
    297     if(my_obj) {
    298         pthread_mutex_lock(&my_obj->cam_lock);
    299         pthread_mutex_unlock(&g_intf_lock);
    300         rc = mm_camera_do_auto_focus(my_obj);
    301     } else {
    302         pthread_mutex_unlock(&g_intf_lock);
    303     }
    304     return rc;
    305 }
    306 
    307 /*===========================================================================
    308  * FUNCTION   : mm_camera_intf_cancel_auto_focus
    309  *
    310  * DESCRIPTION: cancel auto focus
    311  *
    312  * PARAMETERS :
    313  *   @camera_handle: camera handle
    314  *
    315  * RETURN     : int32_t type of status
    316  *              0  -- success
    317  *              -1 -- failure
    318  *==========================================================================*/
    319 static int32_t mm_camera_intf_cancel_auto_focus(uint32_t camera_handle)
    320 {
    321     int32_t rc = -1;
    322     mm_camera_obj_t * my_obj = NULL;
    323 
    324     pthread_mutex_lock(&g_intf_lock);
    325     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    326 
    327     if(my_obj) {
    328         pthread_mutex_lock(&my_obj->cam_lock);
    329         pthread_mutex_unlock(&g_intf_lock);
    330         rc = mm_camera_cancel_auto_focus(my_obj);
    331     } else {
    332         pthread_mutex_unlock(&g_intf_lock);
    333     }
    334     return rc;
    335 }
    336 
    337 /*===========================================================================
    338  * FUNCTION   : mm_camera_intf_prepare_snapshot
    339  *
    340  * DESCRIPTION: prepare hardware for snapshot
    341  *
    342  * PARAMETERS :
    343  *   @camera_handle: camera handle
    344  *   @do_af_flag   : flag indicating if AF is needed
    345  *
    346  * RETURN     : int32_t type of status
    347  *              0  -- success
    348  *              -1 -- failure
    349  *==========================================================================*/
    350 static int32_t mm_camera_intf_prepare_snapshot(uint32_t camera_handle,
    351                                                int32_t do_af_flag)
    352 {
    353     int32_t rc = -1;
    354     mm_camera_obj_t * my_obj = NULL;
    355 
    356     pthread_mutex_lock(&g_intf_lock);
    357     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    358 
    359     if(my_obj) {
    360         pthread_mutex_lock(&my_obj->cam_lock);
    361         pthread_mutex_unlock(&g_intf_lock);
    362         rc = mm_camera_prepare_snapshot(my_obj, do_af_flag);
    363     } else {
    364         pthread_mutex_unlock(&g_intf_lock);
    365     }
    366     return rc;
    367 }
    368 
    369 /*===========================================================================
    370  * FUNCTION   : mm_camera_intf_flush
    371  *
    372  * DESCRIPTION: flush the current camera state and buffers
    373  *
    374  * PARAMETERS :
    375  *   @camera_handle: camera handle
    376  *
    377  * RETURN     : int32_t type of status
    378  *              0  -- success
    379  *              -1 -- failure
    380  *==========================================================================*/
    381 static int32_t mm_camera_intf_flush(uint32_t camera_handle)
    382 {
    383     int32_t rc = -1;
    384     mm_camera_obj_t * my_obj = NULL;
    385 
    386     pthread_mutex_lock(&g_intf_lock);
    387     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    388 
    389     if(my_obj) {
    390         pthread_mutex_lock(&my_obj->cam_lock);
    391         pthread_mutex_unlock(&g_intf_lock);
    392         rc = mm_camera_flush(my_obj);
    393     } else {
    394         pthread_mutex_unlock(&g_intf_lock);
    395     }
    396     return rc;
    397 }
    398 
    399 /*===========================================================================
    400  * FUNCTION   : mm_camera_intf_close
    401  *
    402  * DESCRIPTION: close a camera by its handle
    403  *
    404  * PARAMETERS :
    405  *   @camera_handle: camera handle
    406  *
    407  * RETURN     : int32_t type of status
    408  *              0  -- success
    409  *              -1 -- failure
    410  *==========================================================================*/
    411 static int32_t mm_camera_intf_close(uint32_t camera_handle)
    412 {
    413     int32_t rc = -1;
    414     uint8_t cam_idx = camera_handle & 0x00ff;
    415     mm_camera_obj_t * my_obj = NULL;
    416 
    417     LOGD("E: camera_handler = %d ", camera_handle);
    418 
    419     pthread_mutex_lock(&g_intf_lock);
    420     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    421 
    422     if (my_obj){
    423         my_obj->ref_count--;
    424 
    425         if(my_obj->ref_count > 0) {
    426             /* still have reference to obj, return here */
    427             LOGD("ref_count=%d\n", my_obj->ref_count);
    428             pthread_mutex_unlock(&g_intf_lock);
    429             rc = 0;
    430         } else {
    431             /* need close camera here as no other reference
    432              * first empty g_cam_ctrl's referent to cam_obj */
    433             g_cam_ctrl.cam_obj[cam_idx] = NULL;
    434 
    435             pthread_mutex_lock(&my_obj->cam_lock);
    436             pthread_mutex_unlock(&g_intf_lock);
    437             rc = mm_camera_close(my_obj);
    438             pthread_mutex_destroy(&my_obj->cam_lock);
    439             free(my_obj);
    440         }
    441     } else {
    442         pthread_mutex_unlock(&g_intf_lock);
    443     }
    444 
    445     return rc;
    446 }
    447 
    448 /*===========================================================================
    449  * FUNCTION   : mm_camera_intf_add_channel
    450  *
    451  * DESCRIPTION: add a channel
    452  *
    453  * PARAMETERS :
    454  *   @camera_handle: camera handle
    455  *   @attr         : bundle attribute of the channel if needed
    456  *   @channel_cb   : callback function for bundle data notify
    457  *   @userdata     : user data ptr
    458  *
    459  * RETURN     : uint32_t type of channel handle
    460  *              0  -- invalid channel handle, meaning the op failed
    461  *              >0 -- successfully added a channel with a valid handle
    462  * NOTE       : if no bundle data notify is needed, meaning each stream in the
    463  *              channel will have its own stream data notify callback, then
    464  *              attr, channel_cb, and userdata can be NULL. In this case,
    465  *              no matching logic will be performed in channel for the bundling.
    466  *==========================================================================*/
    467 static uint32_t mm_camera_intf_add_channel(uint32_t camera_handle,
    468                                            mm_camera_channel_attr_t *attr,
    469                                            mm_camera_buf_notify_t channel_cb,
    470                                            void *userdata)
    471 {
    472     uint32_t ch_id = 0;
    473     mm_camera_obj_t * my_obj = NULL;
    474 
    475     LOGD("E camera_handler = %d", camera_handle);
    476     pthread_mutex_lock(&g_intf_lock);
    477     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    478 
    479     if(my_obj) {
    480         pthread_mutex_lock(&my_obj->cam_lock);
    481         pthread_mutex_unlock(&g_intf_lock);
    482         ch_id = mm_camera_add_channel(my_obj, attr, channel_cb, userdata);
    483     } else {
    484         pthread_mutex_unlock(&g_intf_lock);
    485     }
    486     LOGD("X ch_id = %d", ch_id);
    487     return ch_id;
    488 }
    489 
    490 /*===========================================================================
    491  * FUNCTION   : mm_camera_intf_del_channel
    492  *
    493  * DESCRIPTION: delete a channel by its handle
    494  *
    495  * PARAMETERS :
    496  *   @camera_handle: camera handle
    497  *   @ch_id        : channel handle
    498  *
    499  * RETURN     : int32_t type of status
    500  *              0  -- success
    501  *              -1 -- failure
    502  * NOTE       : all streams in the channel should be stopped already before
    503  *              this channel can be deleted.
    504  *==========================================================================*/
    505 static int32_t mm_camera_intf_del_channel(uint32_t camera_handle,
    506                                           uint32_t ch_id)
    507 {
    508     int32_t rc = -1;
    509     mm_camera_obj_t * my_obj = NULL;
    510 
    511     LOGD("E ch_id = %d", ch_id);
    512     pthread_mutex_lock(&g_intf_lock);
    513     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    514 
    515     if(my_obj) {
    516         pthread_mutex_lock(&my_obj->cam_lock);
    517         pthread_mutex_unlock(&g_intf_lock);
    518         rc = mm_camera_del_channel(my_obj, ch_id);
    519     } else {
    520         pthread_mutex_unlock(&g_intf_lock);
    521     }
    522     LOGD("X");
    523     return rc;
    524 }
    525 
    526 /*===========================================================================
    527  * FUNCTION   : mm_camera_intf_get_bundle_info
    528  *
    529  * DESCRIPTION: query bundle info of the channel
    530  *
    531  * PARAMETERS :
    532  *   @camera_handle: camera handle
    533  *   @ch_id        : channel handle
    534  *   @bundle_info  : bundle info to be filled in
    535  *
    536  * RETURN     : int32_t type of status
    537  *              0  -- success
    538  *              -1 -- failure
    539  * NOTE       : all streams in the channel should be stopped already before
    540  *              this channel can be deleted.
    541  *==========================================================================*/
    542 static int32_t mm_camera_intf_get_bundle_info(uint32_t camera_handle,
    543                                               uint32_t ch_id,
    544                                               cam_bundle_config_t *bundle_info)
    545 {
    546     int32_t rc = -1;
    547     mm_camera_obj_t * my_obj = NULL;
    548 
    549     LOGD("E ch_id = %d", ch_id);
    550     pthread_mutex_lock(&g_intf_lock);
    551     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    552 
    553     if(my_obj) {
    554         pthread_mutex_lock(&my_obj->cam_lock);
    555         pthread_mutex_unlock(&g_intf_lock);
    556         rc = mm_camera_get_bundle_info(my_obj, ch_id, bundle_info);
    557     } else {
    558         pthread_mutex_unlock(&g_intf_lock);
    559     }
    560     LOGD("X");
    561     return rc;
    562 }
    563 
    564 /*===========================================================================
    565  * FUNCTION   : mm_camera_intf_register_event_notify
    566  *
    567  * DESCRIPTION: register for event notify
    568  *
    569  * PARAMETERS :
    570  *   @camera_handle: camera handle
    571  *   @evt_cb       : callback for event notify
    572  *   @user_data    : user data ptr
    573  *
    574  * RETURN     : int32_t type of status
    575  *              0  -- success
    576  *              -1 -- failure
    577  *==========================================================================*/
    578 static int32_t mm_camera_intf_register_event_notify(uint32_t camera_handle,
    579                                                     mm_camera_event_notify_t evt_cb,
    580                                                     void * user_data)
    581 {
    582     int32_t rc = -1;
    583     mm_camera_obj_t * my_obj = NULL;
    584 
    585     LOGD("E ");
    586     pthread_mutex_lock(&g_intf_lock);
    587     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    588 
    589     if(my_obj) {
    590         pthread_mutex_lock(&my_obj->cam_lock);
    591         pthread_mutex_unlock(&g_intf_lock);
    592         rc = mm_camera_register_event_notify(my_obj, evt_cb, user_data);
    593     } else {
    594         pthread_mutex_unlock(&g_intf_lock);
    595     }
    596     LOGD("E rc = %d", rc);
    597     return rc;
    598 }
    599 
    600 /*===========================================================================
    601  * FUNCTION   : mm_camera_intf_qbuf
    602  *
    603  * DESCRIPTION: enqueue buffer back to kernel
    604  *
    605  * PARAMETERS :
    606  *   @camera_handle: camera handle
    607  *   @ch_id        : channel handle
    608  *   @buf          : buf ptr to be enqueued
    609  *
    610  * RETURN     : int32_t type of status
    611  *              0  -- success
    612  *              -1 -- failure
    613  *==========================================================================*/
    614 static int32_t mm_camera_intf_qbuf(uint32_t camera_handle,
    615                                     uint32_t ch_id,
    616                                     mm_camera_buf_def_t *buf)
    617 {
    618     int32_t rc = -1;
    619     mm_camera_obj_t * my_obj = NULL;
    620 
    621     pthread_mutex_lock(&g_intf_lock);
    622     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    623 
    624     if(my_obj) {
    625         pthread_mutex_lock(&my_obj->cam_lock);
    626         pthread_mutex_unlock(&g_intf_lock);
    627         rc = mm_camera_qbuf(my_obj, ch_id, buf);
    628     } else {
    629         pthread_mutex_unlock(&g_intf_lock);
    630     }
    631     LOGD("X evt_type = %d",rc);
    632     return rc;
    633 }
    634 
    635 /*===========================================================================
    636  * FUNCTION   : mm_camera_intf_qbuf
    637  *
    638  * DESCRIPTION: enqueue buffer back to kernel
    639  *
    640  * PARAMETERS :
    641  *   @camera_handle: camera handle
    642  *   @ch_id        : channel handle
    643  *   @buf          : buf ptr to be enqueued
    644  *
    645  * RETURN     : int32_t type of status
    646  *              0  -- success
    647  *              -1 -- failure
    648  *==========================================================================*/
    649 static int32_t mm_camera_intf_cancel_buf(uint32_t camera_handle, uint32_t ch_id, uint32_t stream_id,
    650                      uint32_t buf_idx)
    651 {
    652     int32_t rc = -1;
    653     mm_camera_obj_t * my_obj = NULL;
    654 
    655     pthread_mutex_lock(&g_intf_lock);
    656     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    657 
    658     if(my_obj) {
    659         pthread_mutex_lock(&my_obj->cam_lock);
    660         pthread_mutex_unlock(&g_intf_lock);
    661         rc = mm_camera_cancel_buf(my_obj, ch_id, stream_id, buf_idx);
    662     } else {
    663         pthread_mutex_unlock(&g_intf_lock);
    664     }
    665     LOGD("X evt_type = %d",rc);
    666     return rc;
    667 }
    668 
    669 
    670 /*===========================================================================
    671  * FUNCTION   : mm_camera_intf_get_queued_buf_count
    672  *
    673  * DESCRIPTION: returns the queued buffer count
    674  *
    675  * PARAMETERS :
    676  *   @camera_handle: camera handle
    677  *   @ch_id        : channel handle
    678  *   @stream_id : stream id
    679  *
    680  * RETURN     : int32_t - queued buffer count
    681  *
    682  *==========================================================================*/
    683 static int32_t mm_camera_intf_get_queued_buf_count(uint32_t camera_handle,
    684         uint32_t ch_id, uint32_t stream_id)
    685 {
    686     int32_t rc = -1;
    687     mm_camera_obj_t * my_obj = NULL;
    688 
    689     pthread_mutex_lock(&g_intf_lock);
    690     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    691 
    692     if(my_obj) {
    693         pthread_mutex_lock(&my_obj->cam_lock);
    694         pthread_mutex_unlock(&g_intf_lock);
    695         rc = mm_camera_get_queued_buf_count(my_obj, ch_id, stream_id);
    696     } else {
    697         pthread_mutex_unlock(&g_intf_lock);
    698     }
    699     LOGD("X queued buffer count = %d",rc);
    700     return rc;
    701 }
    702 
    703 /*===========================================================================
    704  * FUNCTION   : mm_camera_intf_link_stream
    705  *
    706  * DESCRIPTION: link a stream into a new channel
    707  *
    708  * PARAMETERS :
    709  *   @camera_handle: camera handle
    710  *   @ch_id        : channel handle
    711  *   @stream_id    : stream id
    712  *   @linked_ch_id : channel in which the stream will be linked
    713  *
    714  * RETURN     : int32_t type of stream handle
    715  *              0  -- invalid stream handle, meaning the op failed
    716  *              >0 -- successfully linked a stream with a valid handle
    717  *==========================================================================*/
    718 static int32_t mm_camera_intf_link_stream(uint32_t camera_handle,
    719         uint32_t ch_id,
    720         uint32_t stream_id,
    721         uint32_t linked_ch_id)
    722 {
    723     uint32_t id = 0;
    724     mm_camera_obj_t * my_obj = NULL;
    725 
    726     LOGD("E handle = %u ch_id = %u",
    727           camera_handle, ch_id);
    728 
    729     pthread_mutex_lock(&g_intf_lock);
    730     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    731 
    732     if(my_obj) {
    733         pthread_mutex_lock(&my_obj->cam_lock);
    734         pthread_mutex_unlock(&g_intf_lock);
    735         id = mm_camera_link_stream(my_obj, ch_id, stream_id, linked_ch_id);
    736     } else {
    737         pthread_mutex_unlock(&g_intf_lock);
    738     }
    739 
    740     LOGD("X stream_id = %u", stream_id);
    741     return (int32_t)id;
    742 }
    743 
    744 /*===========================================================================
    745  * FUNCTION   : mm_camera_intf_add_stream
    746  *
    747  * DESCRIPTION: add a stream into a channel
    748  *
    749  * PARAMETERS :
    750  *   @camera_handle: camera handle
    751  *   @ch_id        : channel handle
    752  *
    753  * RETURN     : uint32_t type of stream handle
    754  *              0  -- invalid stream handle, meaning the op failed
    755  *              >0 -- successfully added a stream with a valid handle
    756  *==========================================================================*/
    757 static uint32_t mm_camera_intf_add_stream(uint32_t camera_handle,
    758                                           uint32_t ch_id)
    759 {
    760     uint32_t stream_id = 0;
    761     mm_camera_obj_t * my_obj = NULL;
    762 
    763     LOGD("E handle = %d ch_id = %d",
    764           camera_handle, ch_id);
    765 
    766     pthread_mutex_lock(&g_intf_lock);
    767     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    768 
    769     if(my_obj) {
    770         pthread_mutex_lock(&my_obj->cam_lock);
    771         pthread_mutex_unlock(&g_intf_lock);
    772         stream_id = mm_camera_add_stream(my_obj, ch_id);
    773     } else {
    774         pthread_mutex_unlock(&g_intf_lock);
    775     }
    776     LOGD("X stream_id = %d", stream_id);
    777     return stream_id;
    778 }
    779 
    780 /*===========================================================================
    781  * FUNCTION   : mm_camera_intf_del_stream
    782  *
    783  * DESCRIPTION: delete a stream by its handle
    784  *
    785  * PARAMETERS :
    786  *   @camera_handle: camera handle
    787  *   @ch_id        : channel handle
    788  *   @stream_id    : stream handle
    789  *
    790  * RETURN     : int32_t type of status
    791  *              0  -- success
    792  *              -1 -- failure
    793  * NOTE       : stream should be stopped already before it can be deleted.
    794  *==========================================================================*/
    795 static int32_t mm_camera_intf_del_stream(uint32_t camera_handle,
    796                                          uint32_t ch_id,
    797                                          uint32_t stream_id)
    798 {
    799     int32_t rc = -1;
    800     mm_camera_obj_t * my_obj = NULL;
    801 
    802     LOGD("E handle = %d ch_id = %d stream_id = %d",
    803           camera_handle, ch_id, stream_id);
    804 
    805     pthread_mutex_lock(&g_intf_lock);
    806     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    807 
    808     if(my_obj) {
    809         pthread_mutex_lock(&my_obj->cam_lock);
    810         pthread_mutex_unlock(&g_intf_lock);
    811         rc = mm_camera_del_stream(my_obj, ch_id, stream_id);
    812     } else {
    813         pthread_mutex_unlock(&g_intf_lock);
    814     }
    815     LOGD("X rc = %d", rc);
    816     return rc;
    817 }
    818 
    819 /*===========================================================================
    820  * FUNCTION   : mm_camera_intf_config_stream
    821  *
    822  * DESCRIPTION: configure a stream
    823  *
    824  * PARAMETERS :
    825  *   @camera_handle: camera handle
    826  *   @ch_id        : channel handle
    827  *   @stream_id    : stream handle
    828  *   @config       : stream configuration
    829  *
    830  * RETURN     : int32_t type of status
    831  *              0  -- success
    832  *              -1 -- failure
    833  *==========================================================================*/
    834 static int32_t mm_camera_intf_config_stream(uint32_t camera_handle,
    835                                             uint32_t ch_id,
    836                                             uint32_t stream_id,
    837                                             mm_camera_stream_config_t *config)
    838 {
    839     int32_t rc = -1;
    840     mm_camera_obj_t * my_obj = NULL;
    841 
    842     LOGD("E handle = %d, ch_id = %d,stream_id = %d",
    843           camera_handle, ch_id, stream_id);
    844 
    845     pthread_mutex_lock(&g_intf_lock);
    846     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    847 
    848     LOGD("mm_camera_intf_config_stream stream_id = %d",stream_id);
    849 
    850     if(my_obj) {
    851         pthread_mutex_lock(&my_obj->cam_lock);
    852         pthread_mutex_unlock(&g_intf_lock);
    853         rc = mm_camera_config_stream(my_obj, ch_id, stream_id, config);
    854     } else {
    855         pthread_mutex_unlock(&g_intf_lock);
    856     }
    857     LOGD("X rc = %d", rc);
    858     return rc;
    859 }
    860 
    861 /*===========================================================================
    862  * FUNCTION   : mm_camera_intf_start_channel
    863  *
    864  * DESCRIPTION: start a channel, which will start all streams in the channel
    865  *
    866  * PARAMETERS :
    867  *   @camera_handle: camera handle
    868  *   @ch_id        : channel handle
    869  *
    870  * RETURN     : int32_t type of status
    871  *              0  -- success
    872  *              -1 -- failure
    873  *==========================================================================*/
    874 static int32_t mm_camera_intf_start_channel(uint32_t camera_handle,
    875                                             uint32_t ch_id)
    876 {
    877     int32_t rc = -1;
    878     mm_camera_obj_t * my_obj = NULL;
    879 
    880     pthread_mutex_lock(&g_intf_lock);
    881     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    882 
    883     if(my_obj) {
    884         pthread_mutex_lock(&my_obj->cam_lock);
    885         pthread_mutex_unlock(&g_intf_lock);
    886         rc = mm_camera_start_channel(my_obj, ch_id);
    887     } else {
    888         pthread_mutex_unlock(&g_intf_lock);
    889     }
    890     LOGD("X rc = %d", rc);
    891     return rc;
    892 }
    893 
    894 /*===========================================================================
    895  * FUNCTION   : mm_camera_intf_stop_channel
    896  *
    897  * DESCRIPTION: stop a channel, which will stop all streams in the channel
    898  *
    899  * PARAMETERS :
    900  *   @camera_handle: camera handle
    901  *   @ch_id        : channel handle
    902  *
    903  * RETURN     : int32_t type of status
    904  *              0  -- success
    905  *              -1 -- failure
    906  *==========================================================================*/
    907 static int32_t mm_camera_intf_stop_channel(uint32_t camera_handle,
    908                                            uint32_t ch_id)
    909 {
    910     int32_t rc = -1;
    911     mm_camera_obj_t * my_obj = NULL;
    912 
    913     pthread_mutex_lock(&g_intf_lock);
    914     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    915 
    916     if(my_obj) {
    917         pthread_mutex_lock(&my_obj->cam_lock);
    918         pthread_mutex_unlock(&g_intf_lock);
    919         rc = mm_camera_stop_channel(my_obj, ch_id);
    920     } else {
    921         pthread_mutex_unlock(&g_intf_lock);
    922     }
    923     LOGD("X rc = %d", rc);
    924     return rc;
    925 }
    926 
    927 /*===========================================================================
    928  * FUNCTION   : mm_camera_intf_request_super_buf
    929  *
    930  * DESCRIPTION: for burst mode in bundle, reuqest certain amount of matched
    931  *              frames from superbuf queue
    932  *
    933  * PARAMETERS :
    934  *   @camera_handle: camera handle
    935  *   @ch_id             : channel handle
    936  *   @buf                : request buffer info
    937  *
    938  * RETURN     : int32_t type of status
    939  *              0  -- success
    940  *              -1 -- failure
    941  *==========================================================================*/
    942 static int32_t mm_camera_intf_request_super_buf(uint32_t camera_handle,
    943         uint32_t ch_id, mm_camera_req_buf_t *buf)
    944 {
    945     int32_t rc = -1;
    946     LOGD("E camera_handler = %d,ch_id = %d",
    947           camera_handle, ch_id);
    948     mm_camera_obj_t * my_obj = NULL;
    949 
    950     pthread_mutex_lock(&g_intf_lock);
    951     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    952 
    953     if(my_obj && buf) {
    954         pthread_mutex_lock(&my_obj->cam_lock);
    955         pthread_mutex_unlock(&g_intf_lock);
    956         rc = mm_camera_request_super_buf (my_obj, ch_id, buf);
    957     } else {
    958         pthread_mutex_unlock(&g_intf_lock);
    959     }
    960     LOGD("X rc = %d", rc);
    961     return rc;
    962 }
    963 
    964 /*===========================================================================
    965  * FUNCTION   : mm_camera_intf_cancel_super_buf_request
    966  *
    967  * DESCRIPTION: for burst mode in bundle, cancel the reuqest for certain amount
    968  *              of matched frames from superbuf queue
    969  *
    970  * PARAMETERS :
    971  *   @camera_handle: camera handle
    972  *   @ch_id        : channel handle
    973  *
    974  * RETURN     : int32_t type of status
    975  *              0  -- success
    976  *              -1 -- failure
    977  *==========================================================================*/
    978 static int32_t mm_camera_intf_cancel_super_buf_request(uint32_t camera_handle,
    979                                                        uint32_t ch_id)
    980 {
    981     int32_t rc = -1;
    982     mm_camera_obj_t * my_obj = NULL;
    983 
    984     LOGD("E camera_handler = %d,ch_id = %d",
    985           camera_handle, ch_id);
    986     pthread_mutex_lock(&g_intf_lock);
    987     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
    988 
    989     if(my_obj) {
    990         pthread_mutex_lock(&my_obj->cam_lock);
    991         pthread_mutex_unlock(&g_intf_lock);
    992         rc = mm_camera_cancel_super_buf_request(my_obj, ch_id);
    993     } else {
    994         pthread_mutex_unlock(&g_intf_lock);
    995     }
    996     LOGD("X rc = %d", rc);
    997     return rc;
    998 }
    999 
   1000 /*===========================================================================
   1001  * FUNCTION   : mm_camera_intf_flush_super_buf_queue
   1002  *
   1003  * DESCRIPTION: flush out all frames in the superbuf queue
   1004  *
   1005  * PARAMETERS :
   1006  *   @camera_handle: camera handle
   1007  *   @ch_id        : channel handle
   1008  *   @frame_idx    : frame index
   1009  *
   1010  * RETURN     : int32_t type of status
   1011  *              0  -- success
   1012  *              -1 -- failure
   1013  *==========================================================================*/
   1014 static int32_t mm_camera_intf_flush_super_buf_queue(uint32_t camera_handle,
   1015                                                     uint32_t ch_id, uint32_t frame_idx)
   1016 {
   1017     int32_t rc = -1;
   1018     mm_camera_obj_t * my_obj = NULL;
   1019 
   1020     LOGD("E camera_handler = %d,ch_id = %d",
   1021           camera_handle, ch_id);
   1022     pthread_mutex_lock(&g_intf_lock);
   1023     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1024 
   1025     if(my_obj) {
   1026         pthread_mutex_lock(&my_obj->cam_lock);
   1027         pthread_mutex_unlock(&g_intf_lock);
   1028         rc = mm_camera_flush_super_buf_queue(my_obj, ch_id, frame_idx);
   1029     } else {
   1030         pthread_mutex_unlock(&g_intf_lock);
   1031     }
   1032     LOGD("X rc = %d", rc);
   1033     return rc;
   1034 }
   1035 
   1036 /*===========================================================================
   1037  * FUNCTION   : mm_camera_intf_start_zsl_snapshot
   1038  *
   1039  * DESCRIPTION: Starts zsl snapshot
   1040  *
   1041  * PARAMETERS :
   1042  *   @camera_handle: camera handle
   1043  *   @ch_id        : channel handle
   1044  *
   1045  * RETURN     : int32_t type of status
   1046  *              0  -- success
   1047  *              -1 -- failure
   1048  *==========================================================================*/
   1049 static int32_t mm_camera_intf_start_zsl_snapshot(uint32_t camera_handle,
   1050         uint32_t ch_id)
   1051 {
   1052     int32_t rc = -1;
   1053     mm_camera_obj_t * my_obj = NULL;
   1054 
   1055     LOGD("E camera_handler = %d,ch_id = %d",
   1056           camera_handle, ch_id);
   1057     pthread_mutex_lock(&g_intf_lock);
   1058     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1059 
   1060     if(my_obj) {
   1061         pthread_mutex_lock(&my_obj->cam_lock);
   1062         pthread_mutex_unlock(&g_intf_lock);
   1063         rc = mm_camera_start_zsl_snapshot_ch(my_obj, ch_id);
   1064     } else {
   1065         pthread_mutex_unlock(&g_intf_lock);
   1066     }
   1067     LOGD("X rc = %d", rc);
   1068     return rc;
   1069 }
   1070 
   1071 /*===========================================================================
   1072  * FUNCTION   : mm_camera_intf_stop_zsl_snapshot
   1073  *
   1074  * DESCRIPTION: Stops zsl snapshot
   1075  *
   1076  * PARAMETERS :
   1077  *   @camera_handle: camera handle
   1078  *   @ch_id        : channel handle
   1079  *
   1080  * RETURN     : int32_t type of status
   1081  *              0  -- success
   1082  *              -1 -- failure
   1083  *==========================================================================*/
   1084 static int32_t mm_camera_intf_stop_zsl_snapshot(uint32_t camera_handle,
   1085         uint32_t ch_id)
   1086 {
   1087     int32_t rc = -1;
   1088     mm_camera_obj_t * my_obj = NULL;
   1089 
   1090     LOGD("E camera_handler = %d,ch_id = %d",
   1091           camera_handle, ch_id);
   1092     pthread_mutex_lock(&g_intf_lock);
   1093     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1094 
   1095     if(my_obj) {
   1096         pthread_mutex_lock(&my_obj->cam_lock);
   1097         pthread_mutex_unlock(&g_intf_lock);
   1098         rc = mm_camera_stop_zsl_snapshot_ch(my_obj, ch_id);
   1099     } else {
   1100         pthread_mutex_unlock(&g_intf_lock);
   1101     }
   1102     LOGD("X rc = %d", rc);
   1103     return rc;
   1104 }
   1105 
   1106 /*===========================================================================
   1107  * FUNCTION   : mm_camera_intf_configure_notify_mode
   1108  *
   1109  * DESCRIPTION: Configures channel notification mode
   1110  *
   1111  * PARAMETERS :
   1112  *   @camera_handle: camera handle
   1113  *   @ch_id        : channel handle
   1114  *   @notify_mode  : notification mode
   1115  *
   1116  * RETURN     : int32_t type of status
   1117  *              0  -- success
   1118  *              -1 -- failure
   1119  *==========================================================================*/
   1120 static int32_t mm_camera_intf_configure_notify_mode(uint32_t camera_handle,
   1121                                                     uint32_t ch_id,
   1122                                                     mm_camera_super_buf_notify_mode_t notify_mode)
   1123 {
   1124     int32_t rc = -1;
   1125     mm_camera_obj_t * my_obj = NULL;
   1126 
   1127     LOGD("E camera_handler = %d,ch_id = %d",
   1128           camera_handle, ch_id);
   1129     pthread_mutex_lock(&g_intf_lock);
   1130     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1131 
   1132     if(my_obj) {
   1133         pthread_mutex_lock(&my_obj->cam_lock);
   1134         pthread_mutex_unlock(&g_intf_lock);
   1135         rc = mm_camera_config_channel_notify(my_obj, ch_id, notify_mode);
   1136     } else {
   1137         pthread_mutex_unlock(&g_intf_lock);
   1138     }
   1139     LOGD("X rc = %d", rc);
   1140     return rc;
   1141 }
   1142 
   1143 /*===========================================================================
   1144  * FUNCTION   : mm_camera_intf_map_buf
   1145  *
   1146  * DESCRIPTION: mapping camera buffer via domain socket to server
   1147  *
   1148  * PARAMETERS :
   1149  *   @camera_handle: camera handle
   1150  *   @buf_type     : type of buffer to be mapped. could be following values:
   1151  *                   CAM_MAPPING_BUF_TYPE_CAPABILITY
   1152  *                   CAM_MAPPING_BUF_TYPE_SETPARM_BUF
   1153  *                   CAM_MAPPING_BUF_TYPE_GETPARM_BUF
   1154  *   @fd           : file descriptor of the buffer
   1155  *   @size         : size of the buffer
   1156  *
   1157  * RETURN     : int32_t type of status
   1158  *              0  -- success
   1159  *              -1 -- failure
   1160  *==========================================================================*/
   1161 static int32_t mm_camera_intf_map_buf(uint32_t camera_handle,
   1162     uint8_t buf_type, int fd, size_t size, void *buffer)
   1163 {
   1164     int32_t rc = -1;
   1165     mm_camera_obj_t * my_obj = NULL;
   1166 
   1167     pthread_mutex_lock(&g_intf_lock);
   1168     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1169 
   1170     if(my_obj) {
   1171         pthread_mutex_lock(&my_obj->cam_lock);
   1172         pthread_mutex_unlock(&g_intf_lock);
   1173         rc = mm_camera_map_buf(my_obj, buf_type, fd, size, buffer);
   1174     } else {
   1175         pthread_mutex_unlock(&g_intf_lock);
   1176     }
   1177     return rc;
   1178 }
   1179 
   1180 /*===========================================================================
   1181  * FUNCTION   : mm_camera_intf_map_bufs
   1182  *
   1183  * DESCRIPTION: mapping camera buffer via domain socket to server
   1184  *
   1185  * PARAMETERS :
   1186  *   @camera_handle: camera handle
   1187  *   @buf_type     : type of buffer to be mapped. could be following values:
   1188  *                   CAM_MAPPING_BUF_TYPE_CAPABILITY
   1189  *                   CAM_MAPPING_BUF_TYPE_SETPARM_BUF
   1190  *                   CAM_MAPPING_BUF_TYPE_GETPARM_BUF
   1191  *
   1192  * RETURN     : int32_t type of status
   1193  *              0  -- success
   1194  *              -1 -- failure
   1195  *==========================================================================*/
   1196 static int32_t mm_camera_intf_map_bufs(uint32_t camera_handle,
   1197         const cam_buf_map_type_list *buf_map_list)
   1198 {
   1199     int32_t rc = -1;
   1200     mm_camera_obj_t * my_obj = NULL;
   1201 
   1202     pthread_mutex_lock(&g_intf_lock);
   1203     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1204 
   1205     if(my_obj) {
   1206         pthread_mutex_lock(&my_obj->cam_lock);
   1207         pthread_mutex_unlock(&g_intf_lock);
   1208         rc = mm_camera_map_bufs(my_obj, buf_map_list);
   1209     } else {
   1210         pthread_mutex_unlock(&g_intf_lock);
   1211     }
   1212     return rc;
   1213 }
   1214 
   1215 /*===========================================================================
   1216  * FUNCTION   : mm_camera_intf_unmap_buf
   1217  *
   1218  * DESCRIPTION: unmapping camera buffer via domain socket to server
   1219  *
   1220  * PARAMETERS :
   1221  *   @camera_handle: camera handle
   1222  *   @buf_type     : type of buffer to be unmapped. could be following values:
   1223  *                   CAM_MAPPING_BUF_TYPE_CAPABILITY
   1224  *                   CAM_MAPPING_BUF_TYPE_SETPARM_BUF
   1225  *                   CAM_MAPPING_BUF_TYPE_GETPARM_BUF
   1226  *
   1227  * RETURN     : int32_t type of status
   1228  *              0  -- success
   1229  *              -1 -- failure
   1230  *==========================================================================*/
   1231 static int32_t mm_camera_intf_unmap_buf(uint32_t camera_handle,
   1232                                         uint8_t buf_type)
   1233 {
   1234     int32_t rc = -1;
   1235     mm_camera_obj_t * my_obj = NULL;
   1236 
   1237     pthread_mutex_lock(&g_intf_lock);
   1238     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1239 
   1240     if(my_obj) {
   1241         pthread_mutex_lock(&my_obj->cam_lock);
   1242         pthread_mutex_unlock(&g_intf_lock);
   1243         rc = mm_camera_unmap_buf(my_obj, buf_type);
   1244     } else {
   1245         pthread_mutex_unlock(&g_intf_lock);
   1246     }
   1247     return rc;
   1248 }
   1249 
   1250 /*===========================================================================
   1251  * FUNCTION   : mm_camera_intf_set_stream_parms
   1252  *
   1253  * DESCRIPTION: set parameters per stream
   1254  *
   1255  * PARAMETERS :
   1256  *   @camera_handle: camera handle
   1257  *   @ch_id        : channel handle
   1258  *   @s_id         : stream handle
   1259  *   @parms        : ptr to a param struct to be set to server
   1260  *
   1261  * RETURN     : int32_t type of status
   1262  *              0  -- success
   1263  *              -1 -- failure
   1264  * NOTE       : Assume the parms struct buf is already mapped to server via
   1265  *              domain socket. Corresponding fields of parameters to be set
   1266  *              are already filled in by upper layer caller.
   1267  *==========================================================================*/
   1268 static int32_t mm_camera_intf_set_stream_parms(uint32_t camera_handle,
   1269                                                uint32_t ch_id,
   1270                                                uint32_t s_id,
   1271                                                cam_stream_parm_buffer_t *parms)
   1272 {
   1273     int32_t rc = -1;
   1274     mm_camera_obj_t * my_obj = NULL;
   1275 
   1276     pthread_mutex_lock(&g_intf_lock);
   1277     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1278 
   1279     LOGD("E camera_handle = %d,ch_id = %d,s_id = %d",
   1280           camera_handle, ch_id, s_id);
   1281 
   1282     if(my_obj) {
   1283         pthread_mutex_lock(&my_obj->cam_lock);
   1284         pthread_mutex_unlock(&g_intf_lock);
   1285         rc = mm_camera_set_stream_parms(my_obj, ch_id, s_id, parms);
   1286     }else{
   1287         pthread_mutex_unlock(&g_intf_lock);
   1288     }
   1289     LOGD("X rc = %d", rc);
   1290     return rc;
   1291 }
   1292 
   1293 /*===========================================================================
   1294  * FUNCTION   : mm_camera_intf_get_stream_parms
   1295  *
   1296  * DESCRIPTION: get parameters per stream
   1297  *
   1298  * PARAMETERS :
   1299  *   @camera_handle: camera handle
   1300  *   @ch_id        : channel handle
   1301  *   @s_id         : stream handle
   1302  *   @parms        : ptr to a param struct to be get from server
   1303  *
   1304  * RETURN     : int32_t type of status
   1305  *              0  -- success
   1306  *              -1 -- failure
   1307  * NOTE       : Assume the parms struct buf is already mapped to server via
   1308  *              domain socket. Parameters to be get from server are already
   1309  *              filled in by upper layer caller. After this call, corresponding
   1310  *              fields of requested parameters will be filled in by server with
   1311  *              detailed information.
   1312  *==========================================================================*/
   1313 static int32_t mm_camera_intf_get_stream_parms(uint32_t camera_handle,
   1314                                                uint32_t ch_id,
   1315                                                uint32_t s_id,
   1316                                                cam_stream_parm_buffer_t *parms)
   1317 {
   1318     int32_t rc = -1;
   1319     mm_camera_obj_t * my_obj = NULL;
   1320 
   1321     pthread_mutex_lock(&g_intf_lock);
   1322     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1323 
   1324     LOGD("E camera_handle = %d,ch_id = %d,s_id = %d",
   1325           camera_handle, ch_id, s_id);
   1326 
   1327     if(my_obj) {
   1328         pthread_mutex_lock(&my_obj->cam_lock);
   1329         pthread_mutex_unlock(&g_intf_lock);
   1330         rc = mm_camera_get_stream_parms(my_obj, ch_id, s_id, parms);
   1331     }else{
   1332         pthread_mutex_unlock(&g_intf_lock);
   1333     }
   1334 
   1335     LOGD("X rc = %d", rc);
   1336     return rc;
   1337 }
   1338 
   1339 /*===========================================================================
   1340  * FUNCTION   : mm_camera_intf_map_stream_buf
   1341  *
   1342  * DESCRIPTION: mapping stream buffer via domain socket to server
   1343  *
   1344  * PARAMETERS :
   1345  *   @camera_handle: camera handle
   1346  *   @ch_id        : channel handle
   1347  *   @s_id         : stream handle
   1348  *   @buf_type     : type of buffer to be mapped. could be following values:
   1349  *                   CAM_MAPPING_BUF_TYPE_STREAM_BUF
   1350  *                   CAM_MAPPING_BUF_TYPE_STREAM_INFO
   1351  *                   CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF
   1352  *   @buf_idx      : index of buffer within the stream buffers, only valid if
   1353  *                   buf_type is CAM_MAPPING_BUF_TYPE_STREAM_BUF or
   1354  *                   CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF
   1355  *   @plane_idx    : plane index. If all planes share the same fd,
   1356  *                   plane_idx = -1; otherwise, plean_idx is the
   1357  *                   index to plane (0..num_of_planes)
   1358  *   @fd           : file descriptor of the buffer
   1359  *   @size         : size of the buffer
   1360  *
   1361  * RETURN     : int32_t type of status
   1362  *              0  -- success
   1363  *              -1 -- failure
   1364  *==========================================================================*/
   1365 static int32_t mm_camera_intf_map_stream_buf(uint32_t camera_handle,
   1366         uint32_t ch_id, uint32_t stream_id, uint8_t buf_type,
   1367         uint32_t buf_idx, int32_t plane_idx, int fd,
   1368         size_t size, void *buffer)
   1369 {
   1370     int32_t rc = -1;
   1371     mm_camera_obj_t * my_obj = NULL;
   1372 
   1373     pthread_mutex_lock(&g_intf_lock);
   1374     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1375 
   1376     LOGD("E camera_handle = %d, ch_id = %d, s_id = %d, buf_idx = %d, plane_idx = %d",
   1377           camera_handle, ch_id, stream_id, buf_idx, plane_idx);
   1378 
   1379     if(my_obj) {
   1380         pthread_mutex_lock(&my_obj->cam_lock);
   1381         pthread_mutex_unlock(&g_intf_lock);
   1382         rc = mm_camera_map_stream_buf(my_obj, ch_id, stream_id,
   1383                                       buf_type, buf_idx, plane_idx,
   1384                                       fd, size, buffer);
   1385     }else{
   1386         pthread_mutex_unlock(&g_intf_lock);
   1387     }
   1388 
   1389     LOGD("X rc = %d", rc);
   1390     return rc;
   1391 }
   1392 
   1393 /*===========================================================================
   1394  * FUNCTION   : mm_camera_intf_map_stream_bufs
   1395  *
   1396  * DESCRIPTION: mapping stream buffers via domain socket to server
   1397  *
   1398  * PARAMETERS :
   1399  *   @camera_handle: camera handle
   1400  *   @ch_id        : channel handle
   1401  *   @buf_map_list : list of buffers to be mapped
   1402  *
   1403  * RETURN     : int32_t type of status
   1404  *              0  -- success
   1405  *              -1 -- failure
   1406  *==========================================================================*/
   1407 static int32_t mm_camera_intf_map_stream_bufs(uint32_t camera_handle,
   1408                                               uint32_t ch_id,
   1409                                               const cam_buf_map_type_list *buf_map_list)
   1410 {
   1411     int32_t rc = -1;
   1412     mm_camera_obj_t * my_obj = NULL;
   1413 
   1414     pthread_mutex_lock(&g_intf_lock);
   1415     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1416 
   1417     LOGD("E camera_handle = %d, ch_id = %d",
   1418           camera_handle, ch_id);
   1419 
   1420     if(my_obj) {
   1421         pthread_mutex_lock(&my_obj->cam_lock);
   1422         pthread_mutex_unlock(&g_intf_lock);
   1423         rc = mm_camera_map_stream_bufs(my_obj, ch_id, buf_map_list);
   1424     }else{
   1425         pthread_mutex_unlock(&g_intf_lock);
   1426     }
   1427 
   1428     LOGD("X rc = %d", rc);
   1429     return rc;
   1430 }
   1431 
   1432 /*===========================================================================
   1433  * FUNCTION   : mm_camera_intf_unmap_stream_buf
   1434  *
   1435  * DESCRIPTION: unmapping stream buffer via domain socket to server
   1436  *
   1437  * PARAMETERS :
   1438  *   @camera_handle: camera handle
   1439  *   @ch_id        : channel handle
   1440  *   @s_id         : stream handle
   1441  *   @buf_type     : type of buffer to be unmapped. could be following values:
   1442  *                   CAM_MAPPING_BUF_TYPE_STREAM_BUF
   1443  *                   CAM_MAPPING_BUF_TYPE_STREAM_INFO
   1444  *                   CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF
   1445  *   @buf_idx      : index of buffer within the stream buffers, only valid if
   1446  *                   buf_type is CAM_MAPPING_BUF_TYPE_STREAM_BUF or
   1447  *                   CAM_MAPPING_BUF_TYPE_OFFLINE_INPUT_BUF
   1448  *   @plane_idx    : plane index. If all planes share the same fd,
   1449  *                   plane_idx = -1; otherwise, plean_idx is the
   1450  *                   index to plane (0..num_of_planes)
   1451  *
   1452  * RETURN     : int32_t type of status
   1453  *              0  -- success
   1454  *              -1 -- failure
   1455  *==========================================================================*/
   1456 static int32_t mm_camera_intf_unmap_stream_buf(uint32_t camera_handle,
   1457                                                uint32_t ch_id,
   1458                                                uint32_t stream_id,
   1459                                                uint8_t buf_type,
   1460                                                uint32_t buf_idx,
   1461                                                int32_t plane_idx)
   1462 {
   1463     int32_t rc = -1;
   1464     mm_camera_obj_t * my_obj = NULL;
   1465 
   1466     pthread_mutex_lock(&g_intf_lock);
   1467     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1468 
   1469     LOGD("E camera_handle = %d, ch_id = %d, s_id = %d, buf_idx = %d, plane_idx = %d",
   1470           camera_handle, ch_id, stream_id, buf_idx, plane_idx);
   1471 
   1472     if(my_obj) {
   1473         pthread_mutex_lock(&my_obj->cam_lock);
   1474         pthread_mutex_unlock(&g_intf_lock);
   1475         rc = mm_camera_unmap_stream_buf(my_obj, ch_id, stream_id,
   1476                                         buf_type, buf_idx, plane_idx);
   1477     }else{
   1478         pthread_mutex_unlock(&g_intf_lock);
   1479     }
   1480 
   1481     LOGD("X rc = %d", rc);
   1482     return rc;
   1483 }
   1484 
   1485 /*===========================================================================
   1486  * FUNCTION   : mm_camera_intf_get_session_id
   1487  *
   1488  * DESCRIPTION: retrieve the session ID from the kernel for this HWI instance
   1489  *
   1490  * PARAMETERS :
   1491  *   @camera_handle: camera handle
   1492  *   @sessionid: session id to be retrieved from server
   1493  *
   1494  * RETURN     : int32_t type of status
   1495  *              0  -- success
   1496  *              -1 -- failure
   1497  * NOTE       : if this call succeeds, we will get a valid session id.
   1498  *==========================================================================*/
   1499 static int32_t mm_camera_intf_get_session_id(uint32_t camera_handle,
   1500                                                        uint32_t* sessionid)
   1501 {
   1502     int32_t rc = -1;
   1503     mm_camera_obj_t * my_obj = NULL;
   1504 
   1505     pthread_mutex_lock(&g_intf_lock);
   1506     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1507 
   1508     if(my_obj) {
   1509         pthread_mutex_lock(&my_obj->cam_lock);
   1510         pthread_mutex_unlock(&g_intf_lock);
   1511         *sessionid = my_obj->sessionid;
   1512         pthread_mutex_unlock(&my_obj->cam_lock);
   1513         rc = 0;
   1514     } else {
   1515         pthread_mutex_unlock(&g_intf_lock);
   1516     }
   1517     return rc;
   1518 }
   1519 
   1520 /*===========================================================================
   1521  * FUNCTION   : mm_camera_intf_sync_related_sensors
   1522  *
   1523  * DESCRIPTION: retrieve the session ID from the kernel for this HWI instance
   1524  *
   1525  * PARAMETERS :
   1526  *   @camera_handle: camera handle
   1527  *   @related_cam_info: pointer to the related cam info to be sent to the server
   1528  *
   1529  * RETURN     : int32_t type of status
   1530  *              0  -- success
   1531  *              -1 -- failure
   1532  * NOTE       : if this call succeeds, we will get linking established in back end
   1533  *==========================================================================*/
   1534 static int32_t mm_camera_intf_sync_related_sensors(uint32_t camera_handle,
   1535                               cam_sync_related_sensors_event_info_t* related_cam_info)
   1536 {
   1537     int32_t rc = -1;
   1538     mm_camera_obj_t * my_obj = NULL;
   1539 
   1540     pthread_mutex_lock(&g_intf_lock);
   1541     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1542 
   1543     if(my_obj) {
   1544         pthread_mutex_lock(&my_obj->cam_lock);
   1545         pthread_mutex_unlock(&g_intf_lock);
   1546         rc = mm_camera_sync_related_sensors(my_obj, related_cam_info);
   1547     } else {
   1548         pthread_mutex_unlock(&g_intf_lock);
   1549     }
   1550     return rc;
   1551 }
   1552 
   1553 /*===========================================================================
   1554  * FUNCTION   : get_sensor_info
   1555  *
   1556  * DESCRIPTION: get sensor info like facing(back/front) and mount angle
   1557  *
   1558  * PARAMETERS :
   1559  *
   1560  * RETURN     :
   1561  *==========================================================================*/
   1562 void get_sensor_info()
   1563 {
   1564     int rc = 0;
   1565     int dev_fd = -1;
   1566     struct media_device_info mdev_info;
   1567     int num_media_devices = 0;
   1568     size_t num_cameras = 0;
   1569 
   1570     LOGD("E");
   1571     while (1) {
   1572         char dev_name[32];
   1573         snprintf(dev_name, sizeof(dev_name), "/dev/media%d", num_media_devices);
   1574         dev_fd = open(dev_name, O_RDWR | O_NONBLOCK);
   1575         if (dev_fd < 0) {
   1576             LOGD("Done discovering media devices\n");
   1577             break;
   1578         }
   1579         num_media_devices++;
   1580         memset(&mdev_info, 0, sizeof(mdev_info));
   1581         rc = ioctl(dev_fd, MEDIA_IOC_DEVICE_INFO, &mdev_info);
   1582         if (rc < 0) {
   1583             LOGE("Error: ioctl media_dev failed: %s\n", strerror(errno));
   1584             close(dev_fd);
   1585             dev_fd = -1;
   1586             num_cameras = 0;
   1587             break;
   1588         }
   1589 
   1590         if(strncmp(mdev_info.model,  MSM_CONFIGURATION_NAME, sizeof(mdev_info.model)) != 0) {
   1591             close(dev_fd);
   1592             dev_fd = -1;
   1593             continue;
   1594         }
   1595 
   1596         unsigned int num_entities = 1;
   1597         while (1) {
   1598             struct media_entity_desc entity;
   1599             uint32_t temp;
   1600             uint32_t mount_angle;
   1601             uint32_t facing;
   1602             int32_t type = 0;
   1603             uint8_t is_yuv;
   1604 
   1605             memset(&entity, 0, sizeof(entity));
   1606             entity.id = num_entities++;
   1607             rc = ioctl(dev_fd, MEDIA_IOC_ENUM_ENTITIES, &entity);
   1608             if (rc < 0) {
   1609                 LOGD("Done enumerating media entities\n");
   1610                 rc = 0;
   1611                 break;
   1612             }
   1613             if(entity.type == MEDIA_ENT_T_V4L2_SUBDEV &&
   1614                 entity.group_id == MSM_CAMERA_SUBDEV_SENSOR) {
   1615                 temp = entity.flags >> 8;
   1616                 mount_angle = (temp & 0xFF) * 90;
   1617                 facing = (temp & 0xFF00) >> 8;
   1618                 type = ((entity.flags & CAM_SENSOR_TYPE_MASK) ?
   1619                         CAM_TYPE_AUX:CAM_TYPE_MAIN);
   1620                 is_yuv = ((entity.flags & CAM_SENSOR_FORMAT_MASK) ?
   1621                         CAM_SENSOR_YUV:CAM_SENSOR_RAW);
   1622                 LOGL("index = %u flag = %x mount_angle = %u "
   1623                         "facing = %u type: %u is_yuv = %u\n",
   1624                         (unsigned int)num_cameras, (unsigned int)temp,
   1625                         (unsigned int)mount_angle, (unsigned int)facing,
   1626                         (unsigned int)type, (uint8_t)is_yuv);
   1627                 g_cam_ctrl.info[num_cameras].facing = (int)facing;
   1628                 g_cam_ctrl.info[num_cameras].orientation = (int)mount_angle;
   1629                 g_cam_ctrl.cam_type[num_cameras] = type;
   1630                 g_cam_ctrl.is_yuv[num_cameras] = is_yuv;
   1631                 LOGD("dev_info[id=%zu,name='%s']\n",
   1632                          num_cameras, g_cam_ctrl.video_dev_name[num_cameras]);
   1633                 num_cameras++;
   1634                 continue;
   1635             }
   1636         }
   1637         close(dev_fd);
   1638         dev_fd = -1;
   1639     }
   1640 
   1641     LOGD("num_cameras=%d\n", g_cam_ctrl.num_cam);
   1642     return;
   1643 }
   1644 
   1645 /*===========================================================================
   1646  * FUNCTION   : sort_camera_info
   1647  *
   1648  * DESCRIPTION: sort camera info to keep back cameras idx is smaller than front cameras idx
   1649  *
   1650  * PARAMETERS : number of cameras
   1651  *
   1652  * RETURN     :
   1653  *==========================================================================*/
   1654 void sort_camera_info(int num_cam)
   1655 {
   1656     int idx = 0, i;
   1657     int8_t is_dual_cam = 0, is_aux_cam_exposed = 0;
   1658     char prop[PROPERTY_VALUE_MAX];
   1659     struct camera_info temp_info[MM_CAMERA_MAX_NUM_SENSORS];
   1660     cam_sync_type_t temp_type[MM_CAMERA_MAX_NUM_SENSORS];
   1661     cam_sync_mode_t temp_mode[MM_CAMERA_MAX_NUM_SENSORS];
   1662     uint8_t temp_is_yuv[MM_CAMERA_MAX_NUM_SENSORS];
   1663     char temp_dev_name[MM_CAMERA_MAX_NUM_SENSORS][MM_CAMERA_DEV_NAME_LEN];
   1664 
   1665     memset(temp_info, 0, sizeof(temp_info));
   1666     memset(temp_dev_name, 0, sizeof(temp_dev_name));
   1667     memset(temp_type, 0, sizeof(temp_type));
   1668     memset(temp_mode, 0, sizeof(temp_mode));
   1669     memset(temp_is_yuv, 0, sizeof(temp_is_yuv));
   1670 
   1671     // Signifies whether system has to enable dual camera mode
   1672     memset(prop, 0, sizeof(prop));
   1673     property_get("persist.camera.dual.camera", prop, "0");
   1674     is_dual_cam = atoi(prop);
   1675 
   1676     // Signifies whether AUX camera has to be exposed as physical camera
   1677     memset(prop, 0, sizeof(prop));
   1678     property_get("persist.camera.aux.camera", prop, "0");
   1679     is_aux_cam_exposed = atoi(prop);
   1680     LOGI("dualCamera:%d auxCamera %d",
   1681             is_dual_cam, is_aux_cam_exposed);
   1682 
   1683     /*
   1684     1. If dual camera is enabled, dont hide any camera here. Further logic to handle AUX
   1685        cameras is handled in setupLogicalCameras().
   1686     2. If dual camera is not enabled, hide Front camera if AUX camera property is set.
   1687         In such case, application will see only back MAIN and back AUX cameras.
   1688     3. TODO: Need to revisit this logic if front AUX is available.
   1689     */
   1690 
   1691     /* firstly save the main back cameras info*/
   1692     for (i = 0; i < num_cam; i++) {
   1693         if ((g_cam_ctrl.info[i].facing == CAMERA_FACING_BACK) &&
   1694             (g_cam_ctrl.cam_type[i] == CAM_TYPE_MAIN)) {
   1695             temp_info[idx] = g_cam_ctrl.info[i];
   1696             temp_type[idx] = g_cam_ctrl.cam_type[i];
   1697             temp_mode[idx] = g_cam_ctrl.cam_mode[i];
   1698             temp_is_yuv[idx] = g_cam_ctrl.is_yuv[i];
   1699             LOGD("Found Back Main Camera: i: %d idx: %d", i, idx);
   1700             memcpy(temp_dev_name[idx++],g_cam_ctrl.video_dev_name[i],
   1701                 MM_CAMERA_DEV_NAME_LEN);
   1702         }
   1703     }
   1704 
   1705     /* save the aux back cameras info*/
   1706     if (is_dual_cam || is_aux_cam_exposed) {
   1707         for (i = 0; i < num_cam; i++) {
   1708             if ((g_cam_ctrl.info[i].facing == CAMERA_FACING_BACK) &&
   1709                 (g_cam_ctrl.cam_type[i] == CAM_TYPE_AUX)) {
   1710                 temp_info[idx] = g_cam_ctrl.info[i];
   1711                 temp_type[idx] = g_cam_ctrl.cam_type[i];
   1712                 temp_mode[idx] = g_cam_ctrl.cam_mode[i];
   1713                 temp_is_yuv[idx] = g_cam_ctrl.is_yuv[i];
   1714                 LOGD("Found Back Aux Camera: i: %d idx: %d", i, idx);
   1715                 memcpy(temp_dev_name[idx++],g_cam_ctrl.video_dev_name[i],
   1716                     MM_CAMERA_DEV_NAME_LEN);
   1717             }
   1718         }
   1719     }
   1720 
   1721     if (is_dual_cam || !is_aux_cam_exposed) {
   1722         /* then save the front cameras info*/
   1723         for (i = 0; i < num_cam; i++) {
   1724             if ((g_cam_ctrl.info[i].facing == CAMERA_FACING_FRONT) &&
   1725                 (g_cam_ctrl.cam_type[i] == CAM_TYPE_MAIN)) {
   1726                 temp_info[idx] = g_cam_ctrl.info[i];
   1727                 temp_type[idx] = g_cam_ctrl.cam_type[i];
   1728                 temp_mode[idx] = g_cam_ctrl.cam_mode[i];
   1729                 temp_is_yuv[idx] = g_cam_ctrl.is_yuv[i];
   1730                 LOGD("Found Front Main Camera: i: %d idx: %d", i, idx);
   1731                 memcpy(temp_dev_name[idx++],g_cam_ctrl.video_dev_name[i],
   1732                     MM_CAMERA_DEV_NAME_LEN);
   1733             }
   1734         }
   1735     }
   1736 
   1737     //TODO: Need to revisit this logic if front AUX is available.
   1738     /* save the aux front cameras info*/
   1739     for (i = 0; i < num_cam; i++) {
   1740         if ((g_cam_ctrl.info[i].facing == CAMERA_FACING_FRONT) &&
   1741             (g_cam_ctrl.cam_type[i] == CAM_TYPE_AUX)) {
   1742             temp_info[idx] = g_cam_ctrl.info[i];
   1743             temp_type[idx] = g_cam_ctrl.cam_type[i];
   1744             temp_mode[idx] = g_cam_ctrl.cam_mode[i];
   1745             temp_is_yuv[idx] = g_cam_ctrl.is_yuv[i];
   1746             LOGD("Found Front Aux Camera: i: %d idx: %d", i, idx);
   1747             memcpy(temp_dev_name[idx++],g_cam_ctrl.video_dev_name[i],
   1748                 MM_CAMERA_DEV_NAME_LEN);
   1749         }
   1750     }
   1751 
   1752     if (idx <= num_cam) {
   1753         memcpy(g_cam_ctrl.info, temp_info, sizeof(temp_info));
   1754         memcpy(g_cam_ctrl.cam_type, temp_type, sizeof(temp_type));
   1755         memcpy(g_cam_ctrl.cam_mode, temp_mode, sizeof(temp_mode));
   1756         memcpy(g_cam_ctrl.is_yuv, temp_is_yuv, sizeof(temp_is_yuv));
   1757         memcpy(g_cam_ctrl.video_dev_name, temp_dev_name, sizeof(temp_dev_name));
   1758         //Set num cam based on the cameras exposed finally via dual/aux properties.
   1759         g_cam_ctrl.num_cam = idx;
   1760         for (i = 0; i < idx; i++) {
   1761             LOGI("Camera id: %d facing: %d, type: %d is_yuv: %d",
   1762                 i, g_cam_ctrl.info[i].facing, g_cam_ctrl.cam_type[i], g_cam_ctrl.is_yuv[i]);
   1763         }
   1764     }
   1765     LOGI("Number of cameras %d sorted %d", num_cam, idx);
   1766     return;
   1767 }
   1768 
   1769 /*===========================================================================
   1770  * FUNCTION   : get_num_of_cameras
   1771  *
   1772  * DESCRIPTION: get number of cameras
   1773  *
   1774  * PARAMETERS :
   1775  *
   1776  * RETURN     : number of cameras supported
   1777  *==========================================================================*/
   1778 uint8_t get_num_of_cameras()
   1779 {
   1780     int rc = 0;
   1781     int dev_fd = -1;
   1782     struct media_device_info mdev_info;
   1783     int num_media_devices = 0;
   1784     int8_t num_cameras = 0;
   1785     char subdev_name[32];
   1786     char prop[PROPERTY_VALUE_MAX];
   1787 #ifdef DAEMON_PRESENT
   1788     int32_t sd_fd = -1;
   1789     struct sensor_init_cfg_data cfg;
   1790 #endif
   1791 
   1792     LOGD("E");
   1793 
   1794     property_get("vold.decrypt", prop, "0");
   1795     int decrypt = atoi(prop);
   1796     if (decrypt == 1)
   1797      return 0;
   1798     pthread_mutex_lock(&g_intf_lock);
   1799 
   1800     memset (&g_cam_ctrl, 0, sizeof (g_cam_ctrl));
   1801 #ifndef DAEMON_PRESENT
   1802     if (mm_camera_load_shim_lib() < 0) {
   1803         LOGE ("Failed to module shim library");
   1804         return 0;
   1805     }
   1806 #endif /* DAEMON_PRESENT */
   1807 
   1808     while (1) {
   1809         uint32_t num_entities = 1U;
   1810         char dev_name[32];
   1811 
   1812         snprintf(dev_name, sizeof(dev_name), "/dev/media%d", num_media_devices);
   1813         dev_fd = open(dev_name, O_RDWR | O_NONBLOCK);
   1814         if (dev_fd < 0) {
   1815             LOGD("Done discovering media devices\n");
   1816             break;
   1817         }
   1818         num_media_devices++;
   1819         rc = ioctl(dev_fd, MEDIA_IOC_DEVICE_INFO, &mdev_info);
   1820         if (rc < 0) {
   1821             LOGE("Error: ioctl media_dev failed: %s\n", strerror(errno));
   1822             close(dev_fd);
   1823             dev_fd = -1;
   1824             break;
   1825         }
   1826 
   1827         if (strncmp(mdev_info.model, MSM_CONFIGURATION_NAME,
   1828           sizeof(mdev_info.model)) != 0) {
   1829             close(dev_fd);
   1830             dev_fd = -1;
   1831             continue;
   1832         }
   1833 
   1834         while (1) {
   1835             struct media_entity_desc entity;
   1836             memset(&entity, 0, sizeof(entity));
   1837             entity.id = num_entities++;
   1838             LOGD("entity id %d", entity.id);
   1839             rc = ioctl(dev_fd, MEDIA_IOC_ENUM_ENTITIES, &entity);
   1840             if (rc < 0) {
   1841                 LOGD("Done enumerating media entities");
   1842                 rc = 0;
   1843                 break;
   1844             }
   1845             LOGD("entity name %s type %d group id %d",
   1846                 entity.name, entity.type, entity.group_id);
   1847             if (entity.type == MEDIA_ENT_T_V4L2_SUBDEV &&
   1848                 entity.group_id == MSM_CAMERA_SUBDEV_SENSOR_INIT) {
   1849                 snprintf(subdev_name, sizeof(dev_name), "/dev/%s", entity.name);
   1850                 break;
   1851             }
   1852         }
   1853         close(dev_fd);
   1854         dev_fd = -1;
   1855     }
   1856 
   1857 #ifdef DAEMON_PRESENT
   1858     /* Open sensor_init subdev */
   1859     sd_fd = open(subdev_name, O_RDWR);
   1860     if (sd_fd < 0) {
   1861         LOGE("Open sensor_init subdev failed");
   1862         return FALSE;
   1863     }
   1864 
   1865     cfg.cfgtype = CFG_SINIT_PROBE_WAIT_DONE;
   1866     cfg.cfg.setting = NULL;
   1867     if (ioctl(sd_fd, VIDIOC_MSM_SENSOR_INIT_CFG, &cfg) < 0) {
   1868         LOGE("failed");
   1869     }
   1870     close(sd_fd);
   1871 #endif
   1872 
   1873 
   1874     num_media_devices = 0;
   1875     while (1) {
   1876         uint32_t num_entities = 1U;
   1877         char dev_name[32];
   1878 
   1879         snprintf(dev_name, sizeof(dev_name), "/dev/media%d", num_media_devices);
   1880         dev_fd = open(dev_name, O_RDWR | O_NONBLOCK);
   1881         if (dev_fd < 0) {
   1882             LOGD("Done discovering media devices: %s\n", strerror(errno));
   1883             break;
   1884         }
   1885         num_media_devices++;
   1886         memset(&mdev_info, 0, sizeof(mdev_info));
   1887         rc = ioctl(dev_fd, MEDIA_IOC_DEVICE_INFO, &mdev_info);
   1888         if (rc < 0) {
   1889             LOGE("Error: ioctl media_dev failed: %s\n", strerror(errno));
   1890             close(dev_fd);
   1891             dev_fd = -1;
   1892             num_cameras = 0;
   1893             break;
   1894         }
   1895 
   1896         if(strncmp(mdev_info.model, MSM_CAMERA_NAME, sizeof(mdev_info.model)) != 0) {
   1897             close(dev_fd);
   1898             dev_fd = -1;
   1899             continue;
   1900         }
   1901 
   1902         while (1) {
   1903             struct media_entity_desc entity;
   1904             memset(&entity, 0, sizeof(entity));
   1905             entity.id = num_entities++;
   1906             rc = ioctl(dev_fd, MEDIA_IOC_ENUM_ENTITIES, &entity);
   1907             if (rc < 0) {
   1908                 LOGD("Done enumerating media entities\n");
   1909                 rc = 0;
   1910                 break;
   1911             }
   1912             if(entity.type == MEDIA_ENT_T_DEVNODE_V4L && entity.group_id == QCAMERA_VNODE_GROUP_ID) {
   1913                 strlcpy(g_cam_ctrl.video_dev_name[num_cameras],
   1914                      entity.name, sizeof(entity.name));
   1915                 LOGI("dev_info[id=%d,name='%s']\n",
   1916                     (int)num_cameras, g_cam_ctrl.video_dev_name[num_cameras]);
   1917                 num_cameras++;
   1918                 break;
   1919             }
   1920         }
   1921         close(dev_fd);
   1922         dev_fd = -1;
   1923         if (num_cameras >= MM_CAMERA_MAX_NUM_SENSORS) {
   1924             LOGW("Maximum number of camera reached %d", num_cameras);
   1925             break;
   1926         }
   1927     }
   1928     g_cam_ctrl.num_cam = num_cameras;
   1929 
   1930     get_sensor_info();
   1931     sort_camera_info(g_cam_ctrl.num_cam);
   1932     /* unlock the mutex */
   1933     pthread_mutex_unlock(&g_intf_lock);
   1934     LOGI("num_cameras=%d\n", (int)g_cam_ctrl.num_cam);
   1935     return(uint8_t)g_cam_ctrl.num_cam;
   1936 }
   1937 
   1938 /*===========================================================================
   1939  * FUNCTION   : mm_camera_intf_process_advanced_capture
   1940  *
   1941  * DESCRIPTION: Configures channel advanced capture mode
   1942  *
   1943  * PARAMETERS :
   1944  *   @camera_handle: camera handle
   1945  *   @type : advanced capture type
   1946  *   @ch_id        : channel handle
   1947  *   @trigger  : 1 for start and 0 for cancel/stop
   1948  *   @value  : input capture configaration
   1949  *
   1950  * RETURN     : int32_t type of status
   1951  *              0  -- success
   1952  *              -1 -- failure
   1953  *==========================================================================*/
   1954 static int32_t mm_camera_intf_process_advanced_capture(uint32_t camera_handle,
   1955         uint32_t ch_id, mm_camera_advanced_capture_t type,
   1956         int8_t trigger, void *in_value)
   1957 {
   1958     int32_t rc = -1;
   1959     mm_camera_obj_t * my_obj = NULL;
   1960 
   1961     LOGD("E camera_handler = %d,ch_id = %d",
   1962           camera_handle, ch_id);
   1963     pthread_mutex_lock(&g_intf_lock);
   1964     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   1965 
   1966     if(my_obj) {
   1967         pthread_mutex_lock(&my_obj->cam_lock);
   1968         pthread_mutex_unlock(&g_intf_lock);
   1969         rc = mm_camera_channel_advanced_capture(my_obj, ch_id, type,
   1970                 (uint32_t)trigger, in_value);
   1971     } else {
   1972         pthread_mutex_unlock(&g_intf_lock);
   1973     }
   1974     LOGD("X ");
   1975     return rc;
   1976 }
   1977 
   1978 /*===========================================================================
   1979  * FUNCTION   : mm_camera_intf_register_stream_buf_cb
   1980  *
   1981  * DESCRIPTION: Register special callback for stream buffer
   1982  *
   1983  * PARAMETERS :
   1984  *   @camera_handle: camera handle
   1985  *   @ch_id        : channel handle
   1986  *   @stream_id    : stream handle
   1987  *   @buf_cb       : callback function
   1988  *   @buf_type     :SYNC/ASYNC
   1989  *   @userdata     : userdata pointer
   1990  *
   1991  * RETURN     : int32_t type of status
   1992  *              0  -- success
   1993  *              1 -- failure
   1994  *==========================================================================*/
   1995 static int32_t mm_camera_intf_register_stream_buf_cb(uint32_t camera_handle,
   1996         uint32_t ch_id, uint32_t stream_id, mm_camera_buf_notify_t buf_cb,
   1997         mm_camera_stream_cb_type cb_type, void *userdata)
   1998 {
   1999     int32_t rc = 0;
   2000     mm_camera_obj_t * my_obj = NULL;
   2001 
   2002     LOGD("E handle = %u ch_id = %u",
   2003           camera_handle, ch_id);
   2004 
   2005     pthread_mutex_lock(&g_intf_lock);
   2006     my_obj = mm_camera_util_get_camera_by_handler(camera_handle);
   2007 
   2008     if(my_obj) {
   2009         pthread_mutex_lock(&my_obj->cam_lock);
   2010         pthread_mutex_unlock(&g_intf_lock);
   2011         rc = mm_camera_reg_stream_buf_cb(my_obj, ch_id, stream_id,
   2012                 buf_cb, cb_type, userdata);
   2013     } else {
   2014         pthread_mutex_unlock(&g_intf_lock);
   2015     }
   2016     return (int32_t)rc;
   2017 }
   2018 
   2019 struct camera_info *get_cam_info(uint32_t camera_id, cam_sync_type_t *pCamType)
   2020 {
   2021     *pCamType = g_cam_ctrl.cam_type[camera_id];
   2022     return &g_cam_ctrl.info[camera_id];
   2023 }
   2024 
   2025 uint8_t is_yuv_sensor(uint32_t camera_id)
   2026 {
   2027     return g_cam_ctrl.is_yuv[camera_id];
   2028 }
   2029 
   2030 /* camera ops v-table */
   2031 static mm_camera_ops_t mm_camera_ops = {
   2032     .query_capability = mm_camera_intf_query_capability,
   2033     .register_event_notify = mm_camera_intf_register_event_notify,
   2034     .close_camera = mm_camera_intf_close,
   2035     .set_parms = mm_camera_intf_set_parms,
   2036     .get_parms = mm_camera_intf_get_parms,
   2037     .do_auto_focus = mm_camera_intf_do_auto_focus,
   2038     .cancel_auto_focus = mm_camera_intf_cancel_auto_focus,
   2039     .prepare_snapshot = mm_camera_intf_prepare_snapshot,
   2040     .start_zsl_snapshot = mm_camera_intf_start_zsl_snapshot,
   2041     .stop_zsl_snapshot = mm_camera_intf_stop_zsl_snapshot,
   2042     .map_buf = mm_camera_intf_map_buf,
   2043     .map_bufs = mm_camera_intf_map_bufs,
   2044     .unmap_buf = mm_camera_intf_unmap_buf,
   2045     .add_channel = mm_camera_intf_add_channel,
   2046     .delete_channel = mm_camera_intf_del_channel,
   2047     .get_bundle_info = mm_camera_intf_get_bundle_info,
   2048     .add_stream = mm_camera_intf_add_stream,
   2049     .link_stream = mm_camera_intf_link_stream,
   2050     .delete_stream = mm_camera_intf_del_stream,
   2051     .config_stream = mm_camera_intf_config_stream,
   2052     .qbuf = mm_camera_intf_qbuf,
   2053     .cancel_buffer = mm_camera_intf_cancel_buf,
   2054     .get_queued_buf_count = mm_camera_intf_get_queued_buf_count,
   2055     .map_stream_buf = mm_camera_intf_map_stream_buf,
   2056     .map_stream_bufs = mm_camera_intf_map_stream_bufs,
   2057     .unmap_stream_buf = mm_camera_intf_unmap_stream_buf,
   2058     .set_stream_parms = mm_camera_intf_set_stream_parms,
   2059     .get_stream_parms = mm_camera_intf_get_stream_parms,
   2060     .start_channel = mm_camera_intf_start_channel,
   2061     .stop_channel = mm_camera_intf_stop_channel,
   2062     .request_super_buf = mm_camera_intf_request_super_buf,
   2063     .cancel_super_buf_request = mm_camera_intf_cancel_super_buf_request,
   2064     .flush_super_buf_queue = mm_camera_intf_flush_super_buf_queue,
   2065     .configure_notify_mode = mm_camera_intf_configure_notify_mode,
   2066     .process_advanced_capture = mm_camera_intf_process_advanced_capture,
   2067     .get_session_id = mm_camera_intf_get_session_id,
   2068     .sync_related_sensors = mm_camera_intf_sync_related_sensors,
   2069     .flush = mm_camera_intf_flush,
   2070     .register_stream_buf_cb = mm_camera_intf_register_stream_buf_cb
   2071 };
   2072 
   2073 /*===========================================================================
   2074  * FUNCTION   : camera_open
   2075  *
   2076  * DESCRIPTION: open a camera by camera index
   2077  *
   2078  * PARAMETERS :
   2079  *   @camera_idx  : camera index. should within range of 0 to num_of_cameras
   2080  *   @camera_vtbl : ptr to a virtual table containing camera handle and operation table.
   2081  *
   2082  * RETURN     : int32_t type of status
   2083  *              0  -- success
   2084  *              non-zero error code -- failure
   2085  *==========================================================================*/
   2086 int32_t camera_open(uint8_t camera_idx, mm_camera_vtbl_t **camera_vtbl)
   2087 {
   2088     int32_t rc = 0;
   2089     mm_camera_obj_t *cam_obj = NULL;
   2090 
   2091 #ifdef QCAMERA_REDEFINE_LOG
   2092     mm_camera_set_dbg_log_properties();
   2093 #endif
   2094 
   2095     LOGD("E camera_idx = %d\n", camera_idx);
   2096     if (camera_idx >= g_cam_ctrl.num_cam) {
   2097         LOGE("Invalid camera_idx (%d)", camera_idx);
   2098         return -EINVAL;
   2099     }
   2100 
   2101     pthread_mutex_lock(&g_intf_lock);
   2102     /* opened already */
   2103     if(NULL != g_cam_ctrl.cam_obj[camera_idx]) {
   2104         /* Add reference */
   2105         g_cam_ctrl.cam_obj[camera_idx]->ref_count++;
   2106         pthread_mutex_unlock(&g_intf_lock);
   2107         LOGD("opened alreadyn");
   2108         *camera_vtbl = &g_cam_ctrl.cam_obj[camera_idx]->vtbl;
   2109         return rc;
   2110     }
   2111 
   2112     cam_obj = (mm_camera_obj_t *)malloc(sizeof(mm_camera_obj_t));
   2113     if(NULL == cam_obj) {
   2114         pthread_mutex_unlock(&g_intf_lock);
   2115         LOGE("no mem");
   2116         return -EINVAL;
   2117     }
   2118 
   2119     /* initialize camera obj */
   2120     memset(cam_obj, 0, sizeof(mm_camera_obj_t));
   2121     cam_obj->ctrl_fd = -1;
   2122     cam_obj->ds_fd = -1;
   2123     cam_obj->ref_count++;
   2124     cam_obj->my_hdl = mm_camera_util_generate_handler(camera_idx);
   2125     cam_obj->vtbl.camera_handle = cam_obj->my_hdl; /* set handler */
   2126     cam_obj->vtbl.ops = &mm_camera_ops;
   2127     pthread_mutex_init(&cam_obj->cam_lock, NULL);
   2128     /* unlock global interface lock, if not, in dual camera use case,
   2129       * current open will block operation of another opened camera obj*/
   2130     pthread_mutex_lock(&cam_obj->cam_lock);
   2131     pthread_mutex_unlock(&g_intf_lock);
   2132 
   2133     rc = mm_camera_open(cam_obj);
   2134 
   2135     pthread_mutex_lock(&g_intf_lock);
   2136     if (rc != 0) {
   2137         LOGE("mm_camera_open err = %d", rc);
   2138         pthread_mutex_destroy(&cam_obj->cam_lock);
   2139         g_cam_ctrl.cam_obj[camera_idx] = NULL;
   2140         free(cam_obj);
   2141         cam_obj = NULL;
   2142         pthread_mutex_unlock(&g_intf_lock);
   2143         *camera_vtbl = NULL;
   2144         return rc;
   2145     } else {
   2146         LOGD("Open succeded\n");
   2147         g_cam_ctrl.cam_obj[camera_idx] = cam_obj;
   2148         pthread_mutex_unlock(&g_intf_lock);
   2149         *camera_vtbl = &cam_obj->vtbl;
   2150         return 0;
   2151     }
   2152 }
   2153 
   2154 /*===========================================================================
   2155  * FUNCTION   : mm_camera_load_shim_lib
   2156  *
   2157  * DESCRIPTION: Load shim layer library
   2158  *
   2159  * PARAMETERS :
   2160  *
   2161  * RETURN     : status of load shim library
   2162  *==========================================================================*/
   2163 int32_t mm_camera_load_shim_lib()
   2164 {
   2165     const char* error = NULL;
   2166     void *qdaemon_lib = NULL;
   2167 
   2168     LOGD("E");
   2169     qdaemon_lib = dlopen(SHIMLAYER_LIB, RTLD_NOW);
   2170     if (!qdaemon_lib) {
   2171         error = dlerror();
   2172         LOGE("dlopen failed with error %s", error ? error : "");
   2173         return -1;
   2174     }
   2175 
   2176     *(void **)&mm_camera_shim_module_init =
   2177             dlsym(qdaemon_lib, "mct_shimlayer_process_module_init");
   2178     if (!mm_camera_shim_module_init) {
   2179         error = dlerror();
   2180         LOGE("dlsym failed with error code %s", error ? error: "");
   2181         dlclose(qdaemon_lib);
   2182         return -1;
   2183     }
   2184 
   2185     return mm_camera_shim_module_init(&g_cam_ctrl.cam_shim_ops);
   2186 }
   2187 
   2188 /*===========================================================================
   2189  * FUNCTION   : mm_camera_module_open_session
   2190  *
   2191  * DESCRIPTION: wrapper function to call shim layer API to open session.
   2192  *
   2193  * PARAMETERS :
   2194  *   @sessionid  : sessionID to open session
   2195  *   @evt_cb     : Event callback function
   2196  *
   2197  * RETURN     : int32_t type of status
   2198  *              0  -- success
   2199  *              non-zero error code -- failure
   2200  *==========================================================================*/
   2201 cam_status_t mm_camera_module_open_session(int sessionid,
   2202         mm_camera_shim_event_handler_func evt_cb)
   2203 {
   2204     cam_status_t rc = -1;
   2205     if(g_cam_ctrl.cam_shim_ops.mm_camera_shim_open_session) {
   2206         rc = g_cam_ctrl.cam_shim_ops.mm_camera_shim_open_session(
   2207                 sessionid, evt_cb);
   2208     }
   2209     return rc;
   2210 }
   2211 
   2212 /*===========================================================================
   2213  * FUNCTION   : mm_camera_module_close_session
   2214  *
   2215  * DESCRIPTION: wrapper function to call shim layer API to close session
   2216  *
   2217  * PARAMETERS :
   2218  *   @sessionid  : sessionID to open session
   2219  *
   2220  * RETURN     : int32_t type of status
   2221  *              0  -- success
   2222  *              non-zero error code -- failure
   2223  *==========================================================================*/
   2224 int32_t mm_camera_module_close_session(int session)
   2225 {
   2226     int32_t rc = -1;
   2227     if(g_cam_ctrl.cam_shim_ops.mm_camera_shim_close_session) {
   2228         rc = g_cam_ctrl.cam_shim_ops.mm_camera_shim_close_session(session);
   2229     }
   2230     return rc;
   2231 }
   2232 
   2233 /*===========================================================================
   2234  * FUNCTION   : mm_camera_module_open_session
   2235  *
   2236  * DESCRIPTION: wrapper function to call shim layer API
   2237  *
   2238  * PARAMETERS :
   2239  *   @sessionid  : sessionID to open session
   2240  *   @evt_cb     : Event callback function
   2241  *
   2242  * RETURN     : int32_t type of status
   2243  *              0  -- success
   2244  *              non-zero error code -- failure
   2245  *==========================================================================*/
   2246 int32_t mm_camera_module_send_cmd(cam_shim_packet_t *event)
   2247 {
   2248     int32_t rc = -1;
   2249     if(g_cam_ctrl.cam_shim_ops.mm_camera_shim_send_cmd) {
   2250         rc = g_cam_ctrl.cam_shim_ops.mm_camera_shim_send_cmd(event);
   2251     }
   2252     return rc;
   2253 }
   2254 
   2255 /*===========================================================================
   2256  * FUNCTION   : mm_camera_module_event_handler
   2257  *
   2258  * DESCRIPTION: call back function for shim layer
   2259  *
   2260  * PARAMETERS :
   2261  *
   2262  * RETURN     : status of call back function
   2263  *==========================================================================*/
   2264 int mm_camera_module_event_handler(uint32_t session_id, cam_event_t *event)
   2265 {
   2266     if (!event) {
   2267         LOGE("null event");
   2268         return FALSE;
   2269     }
   2270     mm_camera_event_t evt;
   2271 
   2272     LOGD("session_id:%d, cmd:0x%x", session_id, event->server_event_type);
   2273     memset(&evt, 0, sizeof(mm_camera_event_t));
   2274 
   2275     evt = *event;
   2276     mm_camera_obj_t *my_obj =
   2277          mm_camera_util_get_camera_by_session_id(session_id);
   2278     if (!my_obj) {
   2279         LOGE("my_obj:%p", my_obj);
   2280         return FALSE;
   2281     }
   2282     switch( evt.server_event_type) {
   2283        case CAM_EVENT_TYPE_DAEMON_PULL_REQ:
   2284        case CAM_EVENT_TYPE_CAC_DONE:
   2285        case CAM_EVENT_TYPE_DAEMON_DIED:
   2286        case CAM_EVENT_TYPE_INT_TAKE_JPEG:
   2287        case CAM_EVENT_TYPE_INT_TAKE_RAW:
   2288            mm_camera_enqueue_evt(my_obj, &evt);
   2289            break;
   2290        default:
   2291            LOGE("cmd:%x from shim layer is not handled", evt.server_event_type);
   2292            break;
   2293    }
   2294    return TRUE;
   2295 }
   2296 
   2297