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