Home | History | Annotate | Download | only in common
      1 /* Copyright (c) 2012, 2014, 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 #ifndef MM_JPEG_INTERFACE_H_
     31 #define MM_JPEG_INTERFACE_H_
     32 #include "QOMX_JpegExtensions.h"
     33 #include "cam_intf.h"
     34 
     35 #define MM_JPEG_MAX_PLANES 3
     36 #define MM_JPEG_MAX_BUF CAM_MAX_NUM_BUFS_PER_STREAM
     37 #define QUANT_SIZE 64
     38 #define QTABLE_MAX 2
     39 
     40 typedef enum {
     41   MM_JPEG_FMT_YUV,
     42   MM_JPEG_FMT_BITSTREAM
     43 } mm_jpeg_format_t;
     44 
     45 typedef struct {
     46   cam_3a_params_t cam_3a_params;
     47   cam_sensor_params_t sensor_params;
     48 } mm_jpeg_exif_params_t;
     49 
     50 typedef struct {
     51   uint32_t sequence;          /* for jpeg bit streams, assembling is based on sequence. sequence starts from 0 */
     52   uint8_t *buf_vaddr;        /* ptr to buf */
     53   int fd;                    /* fd of buf */
     54   uint32_t buf_size;         /* total size of buf (header + image) */
     55   mm_jpeg_format_t format;   /* buffer format*/
     56   cam_frame_len_offset_t offset; /* offset of all the planes */
     57   int index; /* index used to identify the buffers */
     58 } mm_jpeg_buf_t;
     59 
     60 typedef struct {
     61   uint8_t *buf_vaddr;        /* ptr to buf */
     62   int fd;                    /* fd of buf */
     63   uint32_t buf_filled_len;   /* used for output image. filled by the client */
     64 } mm_jpeg_output_t;
     65 
     66 typedef enum {
     67   MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2,
     68   MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V2,
     69   MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V1,
     70   MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V1,
     71   MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V2,
     72   MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V2,
     73   MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V1,
     74   MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V1,
     75   MM_JPEG_COLOR_FORMAT_MONOCHROME,
     76   MM_JPEG_COLOR_FORMAT_BITSTREAM_H2V2,
     77   MM_JPEG_COLOR_FORMAT_BITSTREAM_H2V1,
     78   MM_JPEG_COLOR_FORMAT_BITSTREAM_H1V2,
     79   MM_JPEG_COLOR_FORMAT_BITSTREAM_H1V1,
     80   MM_JPEG_COLOR_FORMAT_MAX
     81 } mm_jpeg_color_format;
     82 
     83 typedef enum {
     84   JPEG_JOB_STATUS_DONE = 0,
     85   JPEG_JOB_STATUS_ERROR
     86 } jpeg_job_status_t;
     87 
     88 typedef void (*jpeg_encode_callback_t)(jpeg_job_status_t status,
     89   uint32_t client_hdl,
     90   uint32_t jobId,
     91   mm_jpeg_output_t *p_output,
     92   void *userData);
     93 
     94 typedef struct {
     95   /* src img dimension */
     96   cam_dimension_t src_dim;
     97 
     98   /* jpeg output dimension */
     99   cam_dimension_t dst_dim;
    100 
    101   /* crop information */
    102   cam_rect_t crop;
    103 } mm_jpeg_dim_t;
    104 
    105 typedef struct {
    106   /* num of buf in src img */
    107   uint32_t num_src_bufs;
    108 
    109   /* num of src tmb bufs */
    110   uint32_t num_tmb_bufs;
    111 
    112   /* num of buf in src img */
    113   uint32_t num_dst_bufs;
    114 
    115   int8_t encode_thumbnail;
    116 
    117   /* src img bufs */
    118   mm_jpeg_buf_t src_main_buf[MM_JPEG_MAX_BUF];
    119 
    120   /* this will be used only for bitstream */
    121   mm_jpeg_buf_t src_thumb_buf[MM_JPEG_MAX_BUF];
    122 
    123   /* this will be used only for bitstream */
    124   mm_jpeg_buf_t dest_buf[MM_JPEG_MAX_BUF];
    125 
    126   /* mainimage color format */
    127   mm_jpeg_color_format color_format;
    128 
    129   /* thumbnail color format */
    130   mm_jpeg_color_format thumb_color_format;
    131 
    132   /* jpeg quality: range 0~100 */
    133   uint32_t quality;
    134 
    135   /* jpeg thumbnail quality: range 0~100 */
    136   uint32_t thumb_quality;
    137 
    138   /* buf to exif entries, caller needs to
    139    * take care of the memory manage with insider ptr */
    140   QOMX_EXIF_INFO exif_info;
    141 
    142   /*Callback registered to be called after encode*/
    143   jpeg_encode_callback_t jpeg_cb;
    144 
    145   /*Appdata passed by the user*/
    146   void* userdata;
    147 
    148   /* thumbnail dimension */
    149   mm_jpeg_dim_t thumb_dim;
    150 
    151   /* rotation informaiton */
    152   int rotation;
    153 
    154   /* thumb rotation informaiton */
    155   int thumb_rotation;
    156 
    157   /* main image dimension */
    158   mm_jpeg_dim_t main_dim;
    159 
    160   /* enable encoder burst mode */
    161   int8_t burst_mode;
    162 
    163   /*jpeg orientation information*/
    164   int jpeg_orientation;
    165 
    166   /* get memory function ptr */
    167   int (*get_memory)( omx_jpeg_ouput_buf_t *p_out_buf);
    168 } mm_jpeg_encode_params_t;
    169 
    170 typedef struct {
    171   /* num of buf in src img */
    172   uint32_t num_src_bufs;
    173 
    174   /* num of buf in src img */
    175   uint32_t num_dst_bufs;
    176 
    177   /* src img bufs */
    178   mm_jpeg_buf_t src_main_buf[MM_JPEG_MAX_BUF];
    179 
    180   /* this will be used only for bitstream */
    181   mm_jpeg_buf_t dest_buf[MM_JPEG_MAX_BUF];
    182 
    183   /* color format */
    184   mm_jpeg_color_format color_format;
    185 
    186   jpeg_encode_callback_t jpeg_cb;
    187   void* userdata;
    188 
    189 } mm_jpeg_decode_params_t;
    190 
    191 typedef struct {
    192   /* active indices of the buffers for encoding */
    193   int32_t src_index;
    194   int32_t dst_index;
    195   uint32_t thumb_index;
    196   mm_jpeg_dim_t thumb_dim;
    197 
    198   /* rotation informaiton */
    199   int rotation;
    200 
    201   /* main image dimension */
    202   mm_jpeg_dim_t main_dim;
    203 
    204   /*session id*/
    205   uint32_t session_id;
    206 
    207   /*Metadata stream*/
    208   metadata_buffer_t *p_metadata;
    209 
    210   /*HAL version*/
    211   cam_hal_version_t hal_version;
    212 
    213   /* buf to exif entries, caller needs to
    214    * take care of the memory manage with insider ptr */
    215   QOMX_EXIF_INFO exif_info;
    216 
    217   /* 3a parameters */
    218   mm_jpeg_exif_params_t cam_exif_params;
    219 
    220   /* jpeg encoder QTable */
    221   uint8_t qtable_set[QTABLE_MAX];
    222   OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE qtable[QTABLE_MAX];
    223 } mm_jpeg_encode_job_t;
    224 
    225 typedef struct {
    226   /* active indices of the buffers for encoding */
    227   uint32_t src_index;
    228   uint32_t dst_index;
    229   uint32_t tmb_dst_index;
    230 
    231   /* rotation informaiton */
    232   int rotation;
    233 
    234   /* main image  */
    235   mm_jpeg_dim_t main_dim;
    236 
    237   /*session id*/
    238   uint32_t session_id;
    239 } mm_jpeg_decode_job_t;
    240 
    241 typedef enum {
    242   JPEG_JOB_TYPE_ENCODE,
    243   JPEG_JOB_TYPE_DECODE,
    244   JPEG_JOB_TYPE_MAX
    245 } mm_jpeg_job_type_t;
    246 
    247 typedef struct {
    248   mm_jpeg_job_type_t job_type;
    249   union {
    250     mm_jpeg_encode_job_t encode_job;
    251     mm_jpeg_decode_job_t decode_job;
    252   };
    253 } mm_jpeg_job_t;
    254 
    255 typedef struct {
    256   uint32_t w;
    257   uint32_t h;
    258 } mm_dimension;
    259 
    260 typedef struct {
    261   /* config a job -- async call */
    262   int (*start_job)(mm_jpeg_job_t* job, uint32_t* job_id);
    263 
    264   /* abort a job -- sync call */
    265   int (*abort_job)(uint32_t job_id);
    266 
    267   /* create a session */
    268   int (*create_session)(uint32_t client_hdl,
    269     mm_jpeg_encode_params_t *p_params, uint32_t *p_session_id);
    270 
    271   /* destroy session */
    272   int (*destroy_session)(uint32_t session_id);
    273 
    274   /* close a jpeg client -- sync call */
    275   int (*close) (uint32_t clientHdl);
    276 } mm_jpeg_ops_t;
    277 
    278 typedef struct {
    279   /* config a job -- async call */
    280   int (*start_job)(mm_jpeg_job_t* job, uint32_t* job_id);
    281 
    282   /* abort a job -- sync call */
    283   int (*abort_job)(uint32_t job_id);
    284 
    285   /* create a session */
    286   int (*create_session)(uint32_t client_hdl,
    287     mm_jpeg_decode_params_t *p_params, uint32_t *p_session_id);
    288 
    289   /* destroy session */
    290   int (*destroy_session)(uint32_t session_id);
    291 
    292   /* close a jpeg client -- sync call */
    293   int (*close) (uint32_t clientHdl);
    294 } mm_jpegdec_ops_t;
    295 
    296 /* open a jpeg client -- sync call
    297  * returns client_handle.
    298  * failed if client_handle=0
    299  * jpeg ops tbl will be filled in if open succeeds */
    300 uint32_t jpeg_open(mm_jpeg_ops_t *ops, mm_dimension picture_size);
    301 
    302 /* open a jpeg client -- sync call
    303  * returns client_handle.
    304  * failed if client_handle=0
    305  * jpeg ops tbl will be filled in if open succeeds */
    306 uint32_t jpegdec_open(mm_jpegdec_ops_t *ops);
    307 
    308 #endif /* MM_JPEG_INTERFACE_H_ */
    309