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 
38 typedef enum {
39   MM_JPEG_FMT_YUV,
40   MM_JPEG_FMT_BITSTREAM
41 } mm_jpeg_format_t;
42 
43 typedef struct {
44   cam_3a_params_t cam_3a_params;
45   cam_sensor_params_t sensor_params;
46 } mm_jpeg_exif_params_t;
47 typedef struct {
48   uint32_t sequence;          /* for jpeg bit streams, assembling is based on sequence. sequence starts from 0 */
49   uint8_t *buf_vaddr;        /* ptr to buf */
50   int fd;                    /* fd of buf */
51   uint32_t buf_size;         /* total size of buf (header + image) */
52   mm_jpeg_format_t format;   /* buffer format*/
53   cam_frame_len_offset_t offset; /* offset of all the planes */
54   int index; /* index used to identify the buffers */
55 } mm_jpeg_buf_t;
56 
57 typedef struct {
58   uint8_t *buf_vaddr;        /* ptr to buf */
59   int fd;                    /* fd of buf */
60   uint32_t buf_filled_len;   /* used for output image. filled by the client */
61 } mm_jpeg_output_t;
62 
63 typedef enum {
64   MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V2,
65   MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V2,
66   MM_JPEG_COLOR_FORMAT_YCRCBLP_H2V1,
67   MM_JPEG_COLOR_FORMAT_YCBCRLP_H2V1,
68   MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V2,
69   MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V2,
70   MM_JPEG_COLOR_FORMAT_YCRCBLP_H1V1,
71   MM_JPEG_COLOR_FORMAT_YCBCRLP_H1V1,
72   MM_JPEG_COLOR_FORMAT_BITSTREAM_H2V2,
73   MM_JPEG_COLOR_FORMAT_BITSTREAM_H2V1,
74   MM_JPEG_COLOR_FORMAT_BITSTREAM_H1V2,
75   MM_JPEG_COLOR_FORMAT_BITSTREAM_H1V1,
76   MM_JPEG_COLOR_FORMAT_MAX
77 } mm_jpeg_color_format;
78 
79 typedef enum {
80   JPEG_JOB_STATUS_DONE = 0,
81   JPEG_JOB_STATUS_ERROR
82 } jpeg_job_status_t;
83 
84 typedef void (*jpeg_encode_callback_t)(jpeg_job_status_t status,
85   uint32_t client_hdl,
86   uint32_t jobId,
87   mm_jpeg_output_t *p_output,
88   void *userData);
89 
90 typedef struct {
91   /* src img dimension */
92   cam_dimension_t src_dim;
93 
94   /* jpeg output dimension */
95   cam_dimension_t dst_dim;
96 
97   /* crop information */
98   cam_rect_t crop;
99 } mm_jpeg_dim_t;
100 
101 typedef struct {
102   /* num of buf in src img */
103   uint32_t num_src_bufs;
104 
105   /* num of src tmb bufs */
106   uint32_t num_tmb_bufs;
107 
108   /* num of buf in src img */
109   uint32_t num_dst_bufs;
110 
111   int8_t encode_thumbnail;
112 
113   /* src img bufs */
114   mm_jpeg_buf_t src_main_buf[MM_JPEG_MAX_BUF];
115 
116   /* this will be used only for bitstream */
117   mm_jpeg_buf_t src_thumb_buf[MM_JPEG_MAX_BUF];
118 
119   /* this will be used only for bitstream */
120   mm_jpeg_buf_t dest_buf[MM_JPEG_MAX_BUF];
121 
122   /* color format */
123   mm_jpeg_color_format color_format;
124 
125   /* jpeg quality: range 0~100 */
126   uint32_t quality;
127 
128   /* jpeg thumbnail quality: range 0~100 */
129   uint32_t thumb_quality;
130 
131   /* buf to exif entries, caller needs to
132    * take care of the memory manage with insider ptr */
133   QOMX_EXIF_INFO exif_info;
134 
135   jpeg_encode_callback_t jpeg_cb;
136   void* userdata;
137 
138 } mm_jpeg_encode_params_t;
139 
140 typedef struct {
141   /* active indices of the buffers for encoding */
142   uint32_t src_index;
143   uint32_t dst_index;
144   uint32_t thumb_index;
145   mm_jpeg_dim_t thumb_dim;
146 
147   /* rotation informaiton */
148   int rotation;
149 
150   /* main image dimension */
151   mm_jpeg_dim_t main_dim;
152 
153   /*session id*/
154   uint32_t session_id;
155 
156   /*Metadata from HAl version 1 */
157   cam_metadata_info_t *p_metadata_v1;
158 
159   /*Metadata stream from HAL version 3*/
160   metadata_buffer_t *p_metadata_v3;
161 
162   /* buf to exif entries, caller needs to
163    * take care of the memory manage with insider ptr */
164   QOMX_EXIF_INFO exif_info;
165   /* 3a parameters */
166   mm_jpeg_exif_params_t cam_exif_params;
167 } mm_jpeg_encode_job_t;
168 
169 typedef enum {
170   JPEG_JOB_TYPE_ENCODE,
171   JPEG_JOB_TYPE_MAX
172 } mm_jpeg_job_type_t;
173 
174 typedef struct {
175   mm_jpeg_job_type_t job_type;
176   union {
177     mm_jpeg_encode_job_t encode_job;
178   };
179 } mm_jpeg_job_t;
180 
181 typedef struct {
182   /* config a job -- async call */
183   int (*start_job)(mm_jpeg_job_t* job, uint32_t* job_id);
184 
185   /* abort a job -- sync call */
186   int (*abort_job)(uint32_t job_id);
187 
188   /* create a session */
189   int (*create_session)(uint32_t client_hdl,
190     mm_jpeg_encode_params_t *p_params, uint32_t *p_session_id);
191 
192   /* destroy session */
193   int (*destroy_session)(uint32_t session_id);
194 
195   /* close a jpeg client -- sync call */
196   int (*close) (uint32_t clientHdl);
197 } mm_jpeg_ops_t;
198 
199 /* open a jpeg client -- sync call
200  * returns client_handle.
201  * failed if client_handle=0
202  * jpeg ops tbl will be filled in if open succeeds */
203 uint32_t jpeg_open(mm_jpeg_ops_t *ops);
204 
205 #endif /* MM_JPEG_INTERFACE_H_ */
206