Skip to content

Commit 982a8e4

Browse files
committed
drivers: video: Set format size
Receiver drivers now need to set the format's size to expose it to the application. Application should base on the format size to allocate buffers. The caps' min/max_line_count (which are needed only for HWs that cannot support the whole image frame) can hence be dropped. Signed-off-by: Phi Bang Nguyen <[email protected]>
1 parent ed74d08 commit 982a8e4

File tree

15 files changed

+49
-83
lines changed

15 files changed

+49
-83
lines changed

drivers/video/video_emul_rx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ static int emul_rx_set_fmt(const struct device *const dev, struct video_format *
6868

6969
/* Cache the format selected locally to use it for getting the size of the buffer */
7070
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
71+
fmt->size = fmt->pitch * fmt->height;
72+
7173
data->fmt = *fmt;
7274

7375
return 0;

drivers/video/video_esp32_dvp.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,22 @@ static int video_esp32_get_caps(const struct device *dev, struct video_caps *cap
248248
/* Two buffers are needed to perform transfers */
249249
caps->min_vbuf_count = 2;
250250

251-
/* ESP32 produces full frames */
252-
caps->min_line_count = caps->max_line_count = LINE_COUNT_HEIGHT;
253-
254251
/* Forward the message to the source device */
255252
return video_get_caps(config->source_dev, caps);
256253
}
257254

255+
static void video_esp32_compute_fmt(struct video_format *fmt)
256+
{
257+
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
258+
if (fmt->pitch != 0) {
259+
/* Uncompressed format */
260+
fmt->size = fmt->pitch * fmt->height;
261+
} else {
262+
/* Rough estimate for Jpeg compressed format in the worst case (quality = 100) */
263+
fmt->size = fmt->width * fmt->height * 2;
264+
}
265+
}
266+
258267
static int video_esp32_get_fmt(const struct device *dev, struct video_format *fmt)
259268
{
260269
const struct video_esp32_config *cfg = dev->config;
@@ -268,7 +277,7 @@ static int video_esp32_get_fmt(const struct device *dev, struct video_format *fm
268277
return ret;
269278
}
270279

271-
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
280+
video_esp32_compute_fmt(fmt);
272281

273282
return 0;
274283
}
@@ -284,7 +293,7 @@ static int video_esp32_set_fmt(const struct device *dev, struct video_format *fm
284293
return ret;
285294
}
286295

287-
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
296+
video_esp32_compute_fmt(fmt);
288297

289298
data->video_format = *fmt;
290299

drivers/video/video_mcux_csi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ static inline void video_pix_fmt_convert(struct video_format *fmt, bool isGetFmt
126126
}
127127

128128
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
129+
fmt->size = fmt->pitch * fmt->height;
129130
}
130131
#endif
131132

@@ -168,6 +169,7 @@ static int video_mcux_csi_set_fmt(const struct device *dev, struct video_format
168169
}
169170

170171
fmt->pitch = data->csi_config.linePitch_Bytes;
172+
fmt->size = fmt->pitch * fmt->height;
171173

172174
return 0;
173175
}
@@ -323,8 +325,6 @@ static int video_mcux_csi_get_caps(const struct device *dev, struct video_caps *
323325

324326
/* NXP MCUX CSI request at least 2 buffer before starting */
325327
caps->min_vbuf_count = 2;
326-
/* CSI only operates on buffers of full frame size */
327-
caps->min_line_count = caps->max_line_count = LINE_COUNT_HEIGHT;
328328

329329
/* no source dev */
330330
return err;

drivers/video/video_mcux_smartdma.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ static int nxp_video_sdma_set_format(const struct device *dev, struct video_form
239239
}
240240

241241
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
242+
fmt->size = fmt->pitch * SDMA_LINE_COUNT;
242243

243244
return 0;
244245
}
@@ -271,6 +272,7 @@ static int nxp_video_sdma_get_format(const struct device *dev, struct video_form
271272
}
272273

273274
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
275+
fmt->size = fmt->pitch * SDMA_LINE_COUNT;
274276

275277
return 0;
276278
}
@@ -279,8 +281,6 @@ static int nxp_video_sdma_get_caps(const struct device *dev, struct video_caps *
279281
{
280282
/* SmartDMA needs at least two buffers allocated before starting */
281283
caps->min_vbuf_count = 2;
282-
/* Firmware reads 30 lines per queued vbuf */
283-
caps->min_line_count = caps->max_line_count = SDMA_LINE_COUNT;
284284
caps->format_caps = fmts;
285285
return 0;
286286
}

drivers/video/video_renesas_ra_ceu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ static int video_renesas_ra_ceu_get_format(const struct device *dev, struct vide
118118
}
119119

120120
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
121+
fmt->size = fmt->pitch * fmt->height;
121122

122123
return 0;
123124
}
@@ -170,6 +171,7 @@ static int video_renesas_ra_ceu_set_format(const struct device *dev, struct vide
170171
}
171172

172173
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
174+
fmt->size = fmt->pitch * fmt->height;
173175

174176
memcpy(&data->fmt, fmt, sizeof(struct video_format));
175177

@@ -181,8 +183,6 @@ static int video_renesas_ra_ceu_get_caps(const struct device *dev, struct video_
181183
const struct video_renesas_ra_ceu_config *config = dev->config;
182184

183185
caps->min_vbuf_count = 1;
184-
caps->min_line_count = LINE_COUNT_HEIGHT;
185-
caps->max_line_count = LINE_COUNT_HEIGHT;
186186

187187
return video_get_caps(config->source_dev, caps);
188188
}

drivers/video/video_shell.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,6 @@ static int video_shell_print_caps(const struct shell *sh, const struct device *d
499499
int ret;
500500

501501
shell_print(sh, "min vbuf count: %u", caps->min_vbuf_count);
502-
shell_print(sh, "min line count: %u", caps->min_line_count);
503-
shell_print(sh, "max line count: %u", caps->max_line_count);
504502

505503
for (size_t i = 0; caps->format_caps[i].pixelformat != 0; i++) {
506504
ret = video_shell_print_format_cap(sh, dev, caps->type, &caps->format_caps[i], i);

drivers/video/video_st_mipid02.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,6 @@ static int mipid02_get_caps(const struct device *dev, struct video_caps *caps)
253253

254254
caps->format_caps = drv_data->caps;
255255
caps->min_vbuf_count = 1;
256-
caps->min_line_count = LINE_COUNT_HEIGHT;
257-
caps->max_line_count = LINE_COUNT_HEIGHT;
258256

259257
return 0;
260258
}

drivers/video/video_stm32_dcmi.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,18 @@ static int stm32_dcmi_enable_clock(const struct device *dev)
183183
return clock_control_on(dcmi_clock, (clock_control_subsys_t)&config->pclken);
184184
}
185185

186+
static void video_stm32_dcmi_compute_fmt(struct video_format *fmt)
187+
{
188+
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
189+
if (fmt->pitch != 0) {
190+
/* Uncompressed format */
191+
fmt->size = fmt->pitch * fmt->height;
192+
} else {
193+
/* Rough estimate for Jpeg compressed format in the worst case (quality = 100) */
194+
fmt->size = fmt->width * fmt->height * 2;
195+
}
196+
}
197+
186198
static int video_stm32_dcmi_set_fmt(const struct device *dev, struct video_format *fmt)
187199
{
188200
const struct video_stm32_dcmi_config *config = dev->config;
@@ -194,7 +206,7 @@ static int video_stm32_dcmi_set_fmt(const struct device *dev, struct video_forma
194206
return ret;
195207
}
196208

197-
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
209+
video_stm32_dcmi_compute_fmt(fmt);
198210

199211
data->fmt = *fmt;
200212

@@ -213,7 +225,7 @@ static int video_stm32_dcmi_get_fmt(const struct device *dev, struct video_forma
213225
return ret;
214226
}
215227

216-
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
228+
video_stm32_dcmi_compute_fmt(fmt);
217229

218230
data->fmt = *fmt;
219231

@@ -309,9 +321,6 @@ static int video_stm32_dcmi_get_caps(const struct device *dev, struct video_caps
309321
/* 2 buffers are needed for DCMI_MODE_CONTINUOUS */
310322
caps->min_vbuf_count = 2;
311323

312-
/* DCMI produces full frames */
313-
caps->min_line_count = caps->max_line_count = LINE_COUNT_HEIGHT;
314-
315324
/* Forward the message to the sensor device */
316325
return video_get_caps(config->sensor_dev, caps);
317326
}

drivers/video/video_stm32_dcmipp.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@ static inline void stm32_dcmipp_compute_fmt_pitch(uint32_t pipe_id, struct video
545545
fmt->pitch = ROUND_UP(fmt->pitch, 16);
546546
}
547547
#endif
548+
549+
/* Update the corresponding fmt->size */
550+
fmt->size = fmt->pitch * fmt->height;
548551
}
549552

550553
static int stm32_dcmipp_set_fmt(const struct device *dev, struct video_format *fmt)
@@ -1370,8 +1373,6 @@ static int stm32_dcmipp_get_caps(const struct device *dev, struct video_caps *ca
13701373
ret = video_get_caps(config->source_dev, caps);
13711374

13721375
caps->min_vbuf_count = 1;
1373-
caps->min_line_count = LINE_COUNT_HEIGHT;
1374-
caps->max_line_count = LINE_COUNT_HEIGHT;
13751376

13761377
return ret;
13771378
}

drivers/video/video_sw_generator.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ static int video_sw_generator_set_fmt(const struct device *dev, struct video_for
8282
}
8383

8484
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
85+
fmt->size = fmt->pitch * fmt->height;
8586

8687
data->fmt = *fmt;
8788
return 0;
@@ -93,6 +94,9 @@ static int video_sw_generator_get_fmt(const struct device *dev, struct video_for
9394

9495
*fmt = data->fmt;
9596

97+
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
98+
fmt->size = fmt->pitch * fmt->height;
99+
96100
return 0;
97101
}
98102

@@ -365,9 +369,6 @@ static int video_sw_generator_get_caps(const struct device *dev, struct video_ca
365369
caps->format_caps = fmts;
366370
caps->min_vbuf_count = 1;
367371

368-
/* SW generator produces full frames */
369-
caps->min_line_count = caps->max_line_count = LINE_COUNT_HEIGHT;
370-
371372
return 0;
372373
}
373374

@@ -477,6 +478,7 @@ static int video_sw_generator_init(const struct device *dev)
477478
.fmt.height = 160, \
478479
.fmt.pitch = 320 * 2, \
479480
.fmt.pixelformat = VIDEO_PIX_FMT_RGB565, \
481+
.fmt.size = 320 * 2 * 160, \
480482
.frame_rate = DEFAULT_FRAME_RATE, \
481483
}; \
482484
\

0 commit comments

Comments
 (0)