Home | History | Annotate | Download | only in inc
      1 /* Copyright (c) 2012-2013, 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_H_
     31 #define MM_JPEG_H_
     32 
     33 #include <cam_semaphore.h>
     34 #include "mm_jpeg_interface.h"
     35 #include "cam_list.h"
     36 #include "OMX_Types.h"
     37 #include "OMX_Index.h"
     38 #include "OMX_Core.h"
     39 #include "OMX_Component.h"
     40 #include "QOMX_JpegExtensions.h"
     41 
     42 #define MM_JPEG_MAX_THREADS 30
     43 #define MM_JPEG_CIRQ_SIZE 30
     44 #define MM_JPEG_MAX_SESSION 10
     45 #define MAX_EXIF_TABLE_ENTRIES 50
     46 
     47 typedef struct {
     48   struct cam_list list;
     49   void* data;
     50 } mm_jpeg_q_node_t;
     51 
     52 typedef struct {
     53   mm_jpeg_q_node_t head; /* dummy head */
     54   uint32_t size;
     55   pthread_mutex_t lock;
     56 } mm_jpeg_queue_t;
     57 
     58 typedef enum {
     59   MM_JPEG_CMD_TYPE_JOB,          /* job cmd */
     60   MM_JPEG_CMD_TYPE_EXIT,         /* EXIT cmd for exiting jobMgr thread */
     61   MM_JPEG_CMD_TYPE_MAX
     62 } mm_jpeg_cmd_type_t;
     63 
     64 typedef struct {
     65   union {
     66     int i_data[MM_JPEG_CIRQ_SIZE];
     67     void *p_data[MM_JPEG_CIRQ_SIZE];
     68   };
     69   int front;
     70   int rear;
     71   int count;
     72   pthread_mutex_t lock;
     73 } mm_jpeg_cirq_t;
     74 
     75 typedef struct {
     76   uint32_t client_hdl;           /* client handler */
     77   uint32_t jobId;                /* job ID */
     78   uint32_t sessionId;            /* session ID */
     79   mm_jpeg_encode_params_t params; /* encode params */
     80   mm_jpeg_encode_job_t encode_job;             /* job description */
     81   pthread_t encode_pid;          /* encode thread handler*/
     82 
     83   void *jpeg_obj;                /* ptr to mm_jpeg_obj */
     84   jpeg_job_status_t job_status;  /* job status */
     85 
     86   int state_change_pending;      /* flag to indicate if state change is pending */
     87   OMX_ERRORTYPE error_flag;      /* variable to indicate error during encoding */
     88   OMX_BOOL abort_flag;      /* variable to indicate abort during encoding */
     89 
     90   /* OMX related */
     91   OMX_HANDLETYPE omx_handle;                      /* handle to omx engine */
     92   OMX_CALLBACKTYPE omx_callbacks;                 /* callbacks to omx engine */
     93 
     94   /* buffer headers */
     95   OMX_BUFFERHEADERTYPE *p_in_omx_buf[MM_JPEG_MAX_BUF];
     96   OMX_BUFFERHEADERTYPE *p_in_omx_thumb_buf[MM_JPEG_MAX_BUF];
     97   OMX_BUFFERHEADERTYPE *p_out_omx_buf[MM_JPEG_MAX_BUF];
     98 
     99   OMX_PARAM_PORTDEFINITIONTYPE inputPort;
    100   OMX_PARAM_PORTDEFINITIONTYPE outputPort;
    101   OMX_PARAM_PORTDEFINITIONTYPE inputTmbPort;
    102 
    103   /* event locks */
    104   pthread_mutex_t lock;
    105   pthread_cond_t cond;
    106 
    107   QEXIF_INFO_DATA exif_info_local[MAX_EXIF_TABLE_ENTRIES];  //all exif tags for JPEG encoder
    108   int exif_count_local;
    109 
    110   mm_jpeg_cirq_t cb_q;
    111   int32_t ebd_count;
    112   int32_t fbd_count;
    113 
    114   /* this flag represents whether the job is active */
    115   OMX_BOOL active;
    116 
    117   /* this flag indicates if the configration is complete */
    118   OMX_BOOL config;
    119 
    120   /* job history count to generate unique id */
    121   int job_hist;
    122 
    123   OMX_BOOL encoding;
    124 } mm_jpeg_job_session_t;
    125 
    126 typedef struct {
    127   mm_jpeg_encode_job_t encode_job;
    128   uint32_t job_id;
    129   uint32_t client_handle;
    130 } mm_jpeg_encode_job_info_t;
    131 
    132 typedef struct {
    133   mm_jpeg_cmd_type_t type;
    134   union {
    135     mm_jpeg_encode_job_info_t enc_info;
    136   };
    137 } mm_jpeg_job_q_node_t;
    138 
    139 typedef struct {
    140   uint8_t is_used;                /* flag: if is a valid client */
    141   uint32_t client_handle;         /* client handle */
    142   mm_jpeg_job_session_t session[MM_JPEG_MAX_SESSION];
    143   pthread_mutex_t lock;           /* job lock */
    144 } mm_jpeg_client_t;
    145 
    146 typedef struct {
    147   pthread_t pid;                  /* job cmd thread ID */
    148   cam_semaphore_t job_sem;        /* semaphore for job cmd thread */
    149   mm_jpeg_queue_t job_queue;      /* queue for job to do */
    150 } mm_jpeg_job_cmd_thread_t;
    151 
    152 #define MAX_JPEG_CLIENT_NUM 8
    153 typedef struct mm_jpeg_obj_t {
    154   /* ClientMgr */
    155   int num_clients;                                /* num of clients */
    156   mm_jpeg_client_t clnt_mgr[MAX_JPEG_CLIENT_NUM]; /* client manager */
    157 
    158   /* JobMkr */
    159   pthread_mutex_t job_lock;                       /* job lock */
    160   mm_jpeg_job_cmd_thread_t job_mgr;               /* job mgr thread including todo_q*/
    161   mm_jpeg_queue_t ongoing_job_q;                  /* queue for ongoing jobs */
    162 } mm_jpeg_obj;
    163 
    164 extern int32_t mm_jpeg_init(mm_jpeg_obj *my_obj);
    165 extern int32_t mm_jpeg_deinit(mm_jpeg_obj *my_obj);
    166 extern uint32_t mm_jpeg_new_client(mm_jpeg_obj *my_obj);
    167 extern int32_t mm_jpeg_start_job(mm_jpeg_obj *my_obj,
    168   mm_jpeg_job_t* job,
    169   uint32_t* jobId);
    170 extern int32_t mm_jpeg_abort_job(mm_jpeg_obj *my_obj,
    171   uint32_t jobId);
    172 extern int32_t mm_jpeg_close(mm_jpeg_obj *my_obj,
    173   uint32_t client_hdl);
    174 extern int32_t mm_jpeg_create_session(mm_jpeg_obj *my_obj,
    175   uint32_t client_hdl,
    176   mm_jpeg_encode_params_t *p_params,
    177   uint32_t* p_session_id);
    178 extern int32_t mm_jpeg_destroy_session_by_id(mm_jpeg_obj *my_obj,
    179   uint32_t session_id);
    180 extern int32_t mm_jpeg_destroy_job(mm_jpeg_job_session_t *p_session);
    181 
    182 /* utiltity fucntion declared in mm-camera-inteface2.c
    183  * and need be used by mm-camera and below*/
    184 uint32_t mm_jpeg_util_generate_handler(uint8_t index);
    185 uint8_t mm_jpeg_util_get_index_by_handler(uint32_t handler);
    186 
    187 /* basic queue functions */
    188 extern int32_t mm_jpeg_queue_init(mm_jpeg_queue_t* queue);
    189 extern int32_t mm_jpeg_queue_enq(mm_jpeg_queue_t* queue, void* node);
    190 extern void* mm_jpeg_queue_deq(mm_jpeg_queue_t* queue);
    191 extern int32_t mm_jpeg_queue_deinit(mm_jpeg_queue_t* queue);
    192 extern int32_t mm_jpeg_queue_flush(mm_jpeg_queue_t* queue);
    193 extern uint32_t mm_jpeg_queue_get_size(mm_jpeg_queue_t* queue);
    194 extern void* mm_jpeg_queue_peek(mm_jpeg_queue_t* queue);
    195 extern int32_t addExifEntry(QOMX_EXIF_INFO *p_exif_info, exif_tag_id_t tagid,
    196   exif_tag_type_t type, uint32_t count, void *data);
    197 extern int32_t releaseExifEntry(QEXIF_INFO_DATA *p_exif_data);
    198 extern int process_meta_data_v1(cam_metadata_info_t *p_meta,
    199   QOMX_EXIF_INFO *exif_info, mm_jpeg_exif_params_t *p_cam_exif_params);
    200 extern int process_meta_data_v3(metadata_buffer_t *p_meta,
    201   QOMX_EXIF_INFO *exif_info, mm_jpeg_exif_params_t *p_cam3a_params);
    202 
    203 #endif /* MM_JPEG_H_ */
    204 
    205 
    206