Home | History | Annotate | Download | only in inc
      1 /* Copyright (c) 2012, 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 #ifndef ANDROID_HARDWARE_QCAMERA_USB_PRIV_H
     30 #define ANDROID_HARDWARE_QCAMERA_USB_PRIV_H
     31 
     32 namespace android {
     33 
     34 /* File name length in number of characters */
     35 #define FILENAME_LENGTH     (256)
     36 
     37 /* Number of display buffers (in addition to minimum number of undequed buffers */
     38 #define PRVW_DISP_BUF_CNT   2
     39 
     40 /* Number of V4L2 capture  buffers. */
     41 #define PRVW_CAP_BUF_CNT    4
     42 
     43 /* Maximum buffer size for JPEG output in number of bytes */
     44 #define MAX_JPEG_BUFFER_SIZE    (1024 * 1024)
     45 
     46 /* Preview loop commands */
     47 #define USB_CAM_PREVIEW_EXIT    (0x100)
     48 #define USB_CAM_PREVIEW_PAUSE   (0x101)
     49 #define USB_CAM_PREVIEW_TAKEPIC (0x200)
     50 
     51 /******************************************************************************
     52  * Macro function to input validate device handle
     53  *****************************************************************************/
     54 #define VALIDATE_DEVICE_HDL(camHal, device, ret_err_code)     {\
     55     if(device && device->priv){\
     56         camHal = (camera_hardware_t *)device->priv;\
     57     }else{\
     58         ALOGE("%s: Null device or device->priv", __func__);\
     59         return ret_err_code;\
     60     }\
     61 }\
     62 
     63 /******************************************************************************
     64  * Macro function to check return status of a function, log and exit the thread
     65  *****************************************************************************/
     66 #define ERROR_CHECK_EXIT_THREAD(rc, string)    {\
     67     if(rc < 0) {\
     68         ALOGE("%s: Error %s", __func__, string);\
     69         return (void *)-1;\
     70     }\
     71 }
     72 
     73 /******************************************************************************
     74  * Macro function to check return status of a function, log and exit
     75  *****************************************************************************/
     76 #define ERROR_CHECK_EXIT(rc, string)    {\
     77     if(rc < 0) {\
     78         ALOGE("%s: Error %s", __func__, string);\
     79         return -1;\
     80     }\
     81 }
     82 
     83 /******************************************************************************
     84 * Macro function to Print the parameter string 1000 characters at a time
     85 ******************************************************************************/
     86 #define PRINT_PARAM_STR(parms)    {\
     87         char temp[1001] = {0};\
     88         int n=0;\
     89         while(1) {\
     90             strlcpy(temp,parms+n,1000);\
     91             ALOGD("parms = %s", temp);\
     92             if (strlen(temp) < 1000) break;\
     93             n += 1000;\
     94         }\
     95     }\
     96 
     97 /******************************************************************************
     98  * Macro function to open camera
     99  *****************************************************************************/
    100 #define USB_CAM_OPEN(camHal)    {\
    101         camHal->fd = open(camHal->dev_name, O_RDWR | O_NONBLOCK, 0);\
    102         if(!camHal->fd)\
    103             ALOGE("%s: Error in open", __func__);\
    104         else\
    105             ALOGD("%s: Successfully opened", __func__);\
    106         }\
    107 
    108 /******************************************************************************
    109  * Macro function to close camera
    110  *****************************************************************************/
    111 #define USB_CAM_CLOSE(camHal) {\
    112         int rc;\
    113         if(camHal->fd){\
    114             rc = close(camHal->fd);\
    115             if(0 > rc){\
    116                 ALOGE("%s: close failed ", __func__);\
    117             }\
    118             else{\
    119                 camHal->fd = 0;\
    120                 ALOGD("%s: close successful", __func__);\
    121             }\
    122         }\
    123     }\
    124 
    125 struct bufObj {
    126     void    *data;
    127     int     len;
    128 };
    129 
    130 typedef struct {
    131     camera_device                       hw_dev;
    132     Mutex                               lock;
    133     int                                 previewEnabledFlag;
    134     int                                 prvwStoppedForPicture;
    135     int                                 msgEnabledFlag;
    136     volatile int                        prvwCmdPending;
    137     volatile int                        prvwCmd;
    138     pthread_t                           previewThread;
    139     pthread_t                           takePictureThread;
    140 
    141     camera_notify_callback              notify_cb;
    142     camera_data_callback                data_cb;
    143     camera_data_timestamp_callback      data_cb_timestamp;
    144     camera_request_memory               get_memory;
    145     void*                               cb_ctxt;
    146 
    147     /* capture related members */
    148     /* prevFormat is pixel format of preview buffers that are exported */
    149     int                                 prevFormat;
    150     int                                 prevFps;
    151     int                                 prevWidth;
    152     int                                 prevHeight;
    153     /* captureFormat is internal setting for USB camera buffers */
    154     int                                 captureFormat;
    155     char                                dev_name[FILENAME_LENGTH];
    156     int                                 fd;
    157     unsigned int                        n_buffers;
    158     struct v4l2_buffer                  curCaptureBuf;
    159     struct bufObj                       *buffers;
    160 
    161     /* Display related members */
    162     preview_stream_ops*                 window;
    163     QCameraHalMemory_t                  previewMem;
    164     /* dispFormat is preview display format.Same as preview buffer format*/
    165     int                                 dispFormat;
    166     int                                 dispWidth;
    167     int                                 dispHeight;
    168 
    169     /* MJPEG decoder related members */
    170     /* MJPEG decoder object */
    171     void*                               mjpegd;
    172 
    173     /* JPEG picture and thumbnail related members */
    174     int                                 pictFormat;
    175     int                                 pictWidth;
    176     int                                 pictHeight;
    177     int                                 pictJpegQlty;
    178     int                                 thumbnailWidth;
    179     int                                 thumbnailHeight;
    180     int                                 thumbnailJpegQlty;
    181     QCameraHalMemory_t                  pictMem;
    182     int                                 takePictInProgress;
    183     int                                 jpegEncInProgress;
    184     pthread_mutex_t                     jpegEncMutex;
    185     pthread_cond_t                      jpegEncCond;
    186 
    187     /* */
    188     QCameraParameters                   qCamParams;
    189     String8                             prevSizeValues;
    190     String8                             pictSizeValues;
    191     String8                             thumbnailSizeValues;
    192     String8                             vidSizeValues;
    193     String8                             pictFormatValues;
    194     String8                             prevFormatValues;
    195     String8                             prevFpsRangesValues;
    196 
    197 } camera_hardware_t;
    198 
    199 
    200 }; // namespace android
    201 
    202 #endif /* ANDROID_HARDWARE_QCAMERA_USB_PRIV_H */
    203