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