1 #ifndef _BFLB_MJPEG_H
2 #define _BFLB_MJPEG_H
3 
4 #include "bflb_core.h"
5 
6 /** @addtogroup LHAL
7   * @{
8   */
9 
10 /** @addtogroup MJPEG
11   * @{
12   */
13 
14 /** @defgroup MJPEG_FORMAT mjpeg format definition
15   * @{
16   */
17 #define MJPEG_FORMAT_YUV422_YUYV   0
18 #define MJPEG_FORMAT_YUV422_YVYU   1
19 #define MJPEG_FORMAT_YUV422_UYVY   2
20 #define MJPEG_FORMAT_YUV422_VYUY   3
21 #define MJPEG_FORMAT_YUV422SP_NV16 4
22 #define MJPEG_FORMAT_YUV422SP_NV61 5
23 #define MJPEG_FORMAT_YUV420SP_NV12 6
24 #define MJPEG_FORMAT_YUV420SP_NV21 7
25 #define MJPEG_FORMAT_GRAY          8
26 /**
27   * @}
28   */
29 
30 /** @defgroup MJPEG_INTSTS mjpeg interrupt status definition
31   * @{
32   */
33 #define MJPEG_INTSTS_ONE_FRAME     (1 << 4)
34 /**
35   * @}
36   */
37 
38 /** @defgroup MJPEG_INTCLR mjpeg interrupt clear definition
39   * @{
40   */
41 #define MJPEG_INTCLR_ONE_FRAME     (1 << 8)
42 /**
43   * @}
44   */
45 
46 /** @defgroup MJPEG_CMD mjpeg feature control cmd definition
47   * @{
48   */
49 #define MJPEG_CMD_SET_INPUTADDR0   0x00
50 #define MJPEG_CMD_SET_INPUTADDR1   0x01
51 /**
52   * @}
53   */
54 
55 #define MJPEG_MAX_FRAME_COUNT      4
56 
57 /**
58  * @brief MJPEG configuration structure
59  *
60  * @param format            MJPEG format, use @ref MJPEG_FORMAT
61  * @param resolution_x      MJPEG width, must be a multiple of 8 or a multiple of 16
62  * @param resolution_y      MJPEG higth, must be a multiple of 8 or a multiple of 16
63  * @param input_bufaddr0    MJPEG input buffer address 0 for yy , must be align 16
64  * @param input_bufaddr1    MJPEG input buffer address 0 for yy , must be align 16
65  * @param output_bufaddr    MJPEG output buffer address , must be align 16
66  * @param output_bufsize    MJPEG output buffer size, must be larger than resolution_x*resolution_y*2*MJPEG_MAX_FRAME_COUNT
67  */
68 struct bflb_mjpeg_config_s {
69     uint8_t format;
70     uint8_t quality;
71     uint16_t rows;
72     uint16_t resolution_x;
73     uint16_t resolution_y;
74     uint32_t input_bufaddr0;
75     uint32_t input_bufaddr1;
76     uint32_t output_bufaddr;
77     uint32_t output_bufsize;
78     uint16_t *input_yy_table;
79     uint16_t *input_uv_table;
80 };
81 
82 #ifdef __cplusplus
83 extern "C" {
84 #endif
85 
86 /**
87  * @brief Initialize mjpeg.
88  *
89  * @param [in] dev device handle
90  * @param [in] config pointer to save mjpeg config
91  */
92 void bflb_mjpeg_init(struct bflb_device_s *dev, const struct bflb_mjpeg_config_s *config);
93 
94 /**
95  * @brief Start mjpeg compression with camera.
96  *
97  * @param [in] dev device handle
98  */
99 void bflb_mjpeg_start(struct bflb_device_s *dev);
100 
101 /**
102  * @brief Stop mjpeg compression with camera.
103  *
104  * @param [in] dev device handle
105  */
106 void bflb_mjpeg_stop(struct bflb_device_s *dev);
107 
108 /**
109  * @brief Start mjpeg compression without camera.
110  *
111  * @param [in] dev device handle
112  * @param [in] frame_count frame count to compress
113  */
114 void bflb_mjpeg_sw_run(struct bflb_device_s *dev, uint8_t frame_count);
115 
116 /**
117  * @brief Start mjpeg kick mode compression without camera.
118  *
119  * @param [in] dev device handle
120  * @param [in] kick_count kick block horizontal count to compress
121  */
122 void bflb_mjpeg_kick_run(struct bflb_device_s *dev, uint16_t kick_count);
123 
124 /**
125  * @brief Stop mjpeg kick mode compression without camera.
126  *
127  * @param [in] dev device handle
128  */
129 void bflb_mjpeg_kick_stop(struct bflb_device_s *dev);
130 
131 /**
132  * @brief kick one times compression without camera.
133  *
134  * @param [in] dev device handle
135  */
136 void bflb_mjpeg_kick(struct bflb_device_s *dev);
137 /**
138  * @brief Enable or disable mjpeg one frame compression completion interrupt.
139  *
140  * @param [in] dev device handle
141  * @param [in] mask true means disable, false means enable
142  */
143 void bflb_mjpeg_tcint_mask(struct bflb_device_s *dev, bool mask);
144 
145 /**
146  * @brief Enable or disable mjpeg error interrupt.
147  *
148  * @param [in] dev device handle
149  * @param [in] mask true means disable, false means enable
150  */
151 void bflb_mjpeg_errint_mask(struct bflb_device_s *dev, bool mask);
152 
153 /**
154  * @brief Get mjpeg interrupt status.
155  *
156  * @param [in] dev device handle
157  * @return interrupt status
158  */
159 uint32_t bflb_mjpeg_get_intstatus(struct bflb_device_s *dev);
160 
161 /**
162  * @brief Clear mjpeg interrupt status.
163  *
164  * @param [in] dev device handle
165  * @param [in] int_clear clear value
166  */
167 void bflb_mjpeg_int_clear(struct bflb_device_s *dev, uint32_t int_clear);
168 
169 /**
170  * @brief Get number of frame count that has compressed.
171  *
172  * @param [in] dev device handle
173  * @return compressed frame count
174  */
175 uint8_t bflb_mjpeg_get_frame_count(struct bflb_device_s *dev);
176 
177 /**
178  * @brief Drop one frame that has compressed.
179  *
180  * @param [in] dev device handle
181  */
182 void bflb_mjpeg_pop_one_frame(struct bflb_device_s *dev);
183 
184 /**
185  * @brief Get one frame information.
186  *
187  * @param [in] dev device handle
188  * @param [in] pic pointer to save frame address.
189  * @return frame length
190  */
191 uint32_t bflb_mjpeg_get_frame_info(struct bflb_device_s *dev, uint8_t **pic);
192 
193 /**
194  * @brief Calculate jpeg quantize table.
195  *
196  * @param [in] quality image quality
197  * @param [in] input_table pointer to save input table
198  * @param [in] output_table pointer to save output table
199  */
200 void bflb_mjpeg_calculate_quantize_table(uint8_t quality, uint16_t *input_table, uint16_t *output_table);
201 
202 /**
203  * @brief Fill quantize table into mjpeg register.
204  *
205  * @param [in] dev device handle
206  * @param [in] input_yy yy quantize table
207  * @param [in] input_uv uv quantize table
208  */
209 void bflb_mjpeg_fill_quantize_table(struct bflb_device_s *dev, uint16_t *input_yy, uint16_t *input_uv);
210 
211 /**
212  * @brief Fill jpeg header into mjpeg register and enable hardware auto adding jpeg tail.
213  *
214  * @param [in] dev device handle
215  * @param [in] header pointer to jpeg header
216  * @param [in] header_len jpeg header length
217  */
218 void bflb_mjpeg_fill_jpeg_header_tail(struct bflb_device_s *dev, uint8_t *header, uint32_t header_len);
219 
220 /**
221  * @brief Set mjpeg input when uses camera with yuv402sp.
222  *
223  * @param [in] dev device handle
224  * @param [in] yy camera id for yy
225  * @param [in] uv camera id for uv
226  */
227 void bflb_mjpeg_set_yuv420sp_cam_input(struct bflb_device_s *dev, uint8_t yy, uint8_t uv);
228 
229 /**
230  * @brief Control mjpeg feature.
231  *
232  * @param [in] dev device handle
233  * @param [in] cmd feature command
234  * @param [in] arg user data
235  * @return A negated errno value on failure.
236  */
237 int bflb_mjpeg_feature_control(struct bflb_device_s *dev, int cmd, size_t arg);
238 
239 /**
240  * @brief Control mjpeg feature.
241  *
242  * @param [in] dev device handle
243  * @param [in] input_buf0 input buffer 0
244  * @param [in] input_buf1 input buffer 1
245  * @param [in] output_buff output buffer
246  * @param [in] output_buff_size size of output buffer
247  * @return A negated errno value on failure.
248  */
249 void bflb_mjpeg_update_input_output_buff(struct bflb_device_s *dev, void *input_buf0, void *input_buf1, void *output_buff, size_t output_buff_size);
250 
251 #ifdef __cplusplus
252 }
253 #endif
254 
255 /**
256   * @}
257   */
258 
259 /**
260   * @}
261   */
262 
263 #endif