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_all[MAX_EXIF_TABLE_ENTRIES];  //all exif tags for JPEG encoder
    108 
    109   mm_jpeg_cirq_t cb_q;
    110   int32_t ebd_count;
    111   int32_t fbd_count;
    112 
    113   /* this flag represents whether the job is active */
    114   OMX_BOOL active;
    115 
    116   /* this flag indicates if the configration is complete */
    117   OMX_BOOL config;
    118 
    119   /* job history count to generate unique id */
    120   int job_hist;
    121 
    122   OMX_BOOL encoding;
    123 } mm_jpeg_job_session_t;
    124 
    125 typedef struct {
    126   mm_jpeg_encode_job_t encode_job;
    127   uint32_t job_id;
    128   uint32_t client_handle;
    129 } mm_jpeg_encode_job_info_t;
    130 
    131 typedef struct {
    132   mm_jpeg_cmd_type_t type;
    133   union {
    134     mm_jpeg_encode_job_info_t enc_info;
    135   };
    136 } mm_jpeg_job_q_node_t;
    137 
    138 typedef struct {
    139   uint8_t is_used;                /* flag: if is a valid client */
    140   uint32_t client_handle;         /* client handle */
    141   mm_jpeg_job_session_t session[MM_JPEG_MAX_SESSION];
    142   pthread_mutex_t lock;           /* job lock */
    143 } mm_jpeg_client_t;
    144 
    145 typedef struct {
    146   pthread_t pid;                  /* job cmd thread ID */
    147   cam_semaphore_t job_sem;        /* semaphore for job cmd thread */
    148   mm_jpeg_queue_t job_queue;      /* queue for job to do */
    149 } mm_jpeg_job_cmd_thread_t;
    150 
    151 #define MAX_JPEG_CLIENT_NUM 8
    152 typedef struct mm_jpeg_obj_t {
    153   /* ClientMgr */
    154   int num_clients;                                /* num of clients */
    155   mm_jpeg_client_t clnt_mgr[MAX_JPEG_CLIENT_NUM]; /* client manager */
    156 
    157   /* JobMkr */
    158   pthread_mutex_t job_lock;                       /* job lock */
    159   mm_jpeg_job_cmd_thread_t job_mgr;               /* job mgr thread including todo_q*/
    160   mm_jpeg_queue_t ongoing_job_q;                  /* queue for ongoing jobs */
    161 } mm_jpeg_obj;
    162 
    163 extern int32_t mm_jpeg_init(mm_jpeg_obj *my_obj);
    164 extern int32_t mm_jpeg_deinit(mm_jpeg_obj *my_obj);
    165 extern uint32_t mm_jpeg_new_client(mm_jpeg_obj *my_obj);
    166 extern int32_t mm_jpeg_start_job(mm_jpeg_obj *my_obj,
    167   mm_jpeg_job_t* job,
    168   uint32_t* jobId);
    169 extern int32_t mm_jpeg_abort_job(mm_jpeg_obj *my_obj,
    170   uint32_t jobId);
    171 extern int32_t mm_jpeg_close(mm_jpeg_obj *my_obj,
    172   uint32_t client_hdl);
    173 extern int32_t mm_jpeg_create_session(mm_jpeg_obj *my_obj,
    174   uint32_t client_hdl,
    175   mm_jpeg_encode_params_t *p_params,
    176   uint32_t* p_session_id);
    177 extern int32_t mm_jpeg_destroy_session_by_id(mm_jpeg_obj *my_obj,
    178   uint32_t session_id);
    179 
    180 /* utiltity fucntion declared in mm-camera-inteface2.c
    181  * and need be used by mm-camera and below*/
    182 uint32_t mm_jpeg_util_generate_handler(uint8_t index);
    183 uint8_t mm_jpeg_util_get_index_by_handler(uint32_t handler);
    184 
    185 /* basic queue functions */
    186 extern int32_t mm_jpeg_queue_init(mm_jpeg_queue_t* queue);
    187 extern int32_t mm_jpeg_queue_enq(mm_jpeg_queue_t* queue, void* node);
    188 extern void* mm_jpeg_queue_deq(mm_jpeg_queue_t* queue);
    189 extern int32_t mm_jpeg_queue_deinit(mm_jpeg_queue_t* queue);
    190 extern int32_t mm_jpeg_queue_flush(mm_jpeg_queue_t* queue);
    191 extern uint32_t mm_jpeg_queue_get_size(mm_jpeg_queue_t* queue);
    192 extern void* mm_jpeg_queue_peek(mm_jpeg_queue_t* queue);
    193 extern int32_t addExifEntry(QOMX_EXIF_INFO *p_exif_info, exif_tag_id_t tagid,
    194   exif_tag_type_t type, uint32_t count, void *data);
    195 extern int32_t releaseExifEntry(QOMX_EXIF_INFO *p_exif_info);
    196 
    197 #endif /* MM_JPEG_H_ */
    198 
    199 
    200