• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /* Copyright (c) 2012, The Linux Foundation. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above
10  *       copyright notice, this list of conditions and the following
11  *       disclaimer in the documentation and/or other materials provided
12  *       with the distribution.
13  *     * Neither the name of The Linux Foundation nor the names of its
14  *       contributors may be used to endorse or promote products derived
15  *       from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef MM_JPEG_H_
31 #define MM_JPEG_H_
32 
33 #include "mm_jpeg_interface.h"
34 #include "cam_list.h"
35 #include "OMX_Types.h"
36 #include "OMX_Index.h"
37 #include "OMX_Core.h"
38 #include "OMX_Component.h"
39 #include "omx_jpeg_ext.h"
40 #include <semaphore.h>
41 
42 typedef struct {
43     struct cam_list list;
44     void* data;
45 } mm_jpeg_q_node_t;
46 
47 typedef struct {
48     mm_jpeg_q_node_t head; /* dummy head */
49     uint32_t size;
50     pthread_mutex_t lock;
51 } mm_jpeg_queue_t;
52 
53 typedef enum
54 {
55     MM_JPEG_CMD_TYPE_JOB,          /* job cmd */
56     MM_JPEG_CMD_TYPE_EXIT,         /* EXIT cmd for exiting jobMgr thread */
57     MM_JPEG_CMD_TYPE_MAX
58 } mm_jpeg_cmd_type_t;
59 
60 typedef struct {
61     OMX_BUFFERHEADERTYPE* buf_header;
62     uint32_t portIdx;
63 } mm_jpeg_omx_buf_info;
64 
65 typedef struct {
66     uint8_t num_bufs;
67     mm_jpeg_omx_buf_info bufs[MAX_SRC_BUF_NUM];
68 } mm_jpeg_omx_src_buf;
69 
70 typedef struct {
71     uint32_t client_hdl;           /* client handler */
72     uint32_t jobId;                /* job ID */
73     mm_jpeg_job job;               /* job description */
74     pthread_t cb_pid;              /* cb thread heandler*/
75 
76     void* jpeg_obj;                /* ptr to mm_jpeg_obj */
77     jpeg_job_status_t job_status;  /* job status */
78     uint8_t thumbnail_dropped;     /* flag indicating if thumbnail is dropped */
79     int32_t jpeg_size;             /* the size of jpeg output after job is done */
80 
81     mm_jpeg_omx_src_buf src_bufs[JPEG_SRC_IMAGE_TYPE_MAX];
82     mm_jpeg_omx_buf_info sink_buf;
83 } mm_jpeg_job_entry;
84 
85 typedef struct {
86     mm_jpeg_cmd_type_t type;
87     union {
88         mm_jpeg_job_entry  entry;
89     };
90 } mm_jpeg_job_q_node_t;
91 
92 typedef struct {
93     uint8_t is_used;                /* flag: if is a valid client */
94     uint32_t client_handle;         /* client handle */
95 } mm_jpeg_client_t;
96 
97 typedef struct {
98     pthread_t pid;                  /* job cmd thread ID */
99     sem_t job_sem;                  /* semaphore for job cmd thread */
100     mm_jpeg_queue_t job_queue;      /* queue for job to do */
101 } mm_jpeg_job_cmd_thread_t;
102 
103 typedef enum {
104     MM_JPEG_EVENT_MASK_JPEG_DONE    = 0x00000001, /* jpeg job is done */
105     MM_JPEG_EVENT_MASK_JPEG_ABORT   = 0x00000002, /* jpeg job is aborted */
106     MM_JPEG_EVENT_MASK_JPEG_ERROR   = 0x00000004, /* jpeg job has error */
107     MM_JPEG_EVENT_MASK_CMD_COMPLETE = 0x00000100  /* omx cmd complete evt */
108 } mm_jpeg_event_mask_t;
109 
110 typedef struct {
111     uint32_t evt;
112     int omx_value1;  /* only valid when evt_mask == MM_JPEG_EVENT_MASK_CMD_COMPLETE */
113     int omx_value2;  /* only valid when evt_mask == MM_JPEG_EVENT_MASK_CMD_COMPLETE */
114 } mm_jpeg_evt_t;
115 
116 #define MAX_JPEG_CLIENT_NUM 8
117 typedef struct mm_jpeg_obj_t {
118     /* ClientMgr */
119     int num_clients;                                /* num of clients */
120     mm_jpeg_client_t clnt_mgr[MAX_JPEG_CLIENT_NUM]; /* client manager */
121 
122     /* JobMkr */
123     pthread_mutex_t job_lock;                       /* job lock */
124     mm_jpeg_job_cmd_thread_t job_mgr;               /* job mgr thread including todo_q*/
125     mm_jpeg_queue_t ongoing_job_q;                  /* queue for ongoing jobs */
126 
127     /* Notifier */
128     mm_jpeg_queue_t cb_q;                           /* queue for CB threads */
129 
130     /* OMX related */
131     OMX_HANDLETYPE omx_handle;                      /* handle to omx engine */
132     OMX_CALLBACKTYPE omx_callbacks;                 /* callbacks to omx engine */
133 
134     pthread_mutex_t omx_evt_lock;
135     pthread_cond_t omx_evt_cond;
136     mm_jpeg_evt_t omx_evt_rcvd;
137 } mm_jpeg_obj;
138 
139 extern int32_t mm_jpeg_init(mm_jpeg_obj *my_obj);
140 extern int32_t mm_jpeg_deinit(mm_jpeg_obj *my_obj);
141 extern uint32_t mm_jpeg_new_client(mm_jpeg_obj *my_obj);
142 extern int32_t mm_jpeg_start_job(mm_jpeg_obj *my_obj,
143                                  uint32_t client_hdl,
144                                  mm_jpeg_job* job,
145                                  uint32_t* jobId);
146 extern int32_t mm_jpeg_abort_job(mm_jpeg_obj *my_obj,
147                                  uint32_t client_hdl,
148                                  uint32_t jobId);
149 extern int32_t mm_jpeg_close(mm_jpeg_obj *my_obj,
150                              uint32_t client_hdl);
151 
152 /* utiltity fucntion declared in mm-camera-inteface2.c
153  * and need be used by mm-camera and below*/
154 uint32_t mm_jpeg_util_generate_handler(uint8_t index);
155 uint8_t mm_jpeg_util_get_index_by_handler(uint32_t handler);
156 
157 /* basic queue functions */
158 extern int32_t mm_jpeg_queue_init(mm_jpeg_queue_t* queue);
159 extern int32_t mm_jpeg_queue_enq(mm_jpeg_queue_t* queue, void* node);
160 extern void* mm_jpeg_queue_peek(mm_jpeg_queue_t* queue);
161 extern void* mm_jpeg_queue_deq(mm_jpeg_queue_t* queue);
162 extern int32_t mm_jpeg_queue_deinit(mm_jpeg_queue_t* queue);
163 extern int32_t mm_jpeg_queue_flush(mm_jpeg_queue_t* queue);
164 extern uint32_t mm_jpeg_queue_get_size(mm_jpeg_queue_t* queue);
165 
166 #endif /* MM_JPEG_H_ */
167 
168 
169