Skip to content

Commit 11ad07b

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 11ad07b

File tree

13 files changed

+24
-49
lines changed

13 files changed

+24
-49
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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,6 @@ 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
}
@@ -269,6 +266,7 @@ static int video_esp32_get_fmt(const struct device *dev, struct video_format *fm
269266
}
270267

271268
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
269+
fmt->size = fmt->pitch * fmt->height;
272270

273271
return 0;
274272
}
@@ -285,6 +283,7 @@ static int video_esp32_set_fmt(const struct device *dev, struct video_format *fm
285283
}
286284

287285
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
286+
fmt->size = fmt->pitch * fmt->height;
288287

289288
data->video_format = *fmt;
290289

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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ static int video_stm32_dcmi_set_fmt(const struct device *dev, struct video_forma
195195
}
196196

197197
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
198+
fmt->size = fmt->pitch * fmt->height;
198199

199200
data->fmt = *fmt;
200201

@@ -214,6 +215,7 @@ static int video_stm32_dcmi_get_fmt(const struct device *dev, struct video_forma
214215
}
215216

216217
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
218+
fmt->size = fmt->pitch * fmt->height;
217219

218220
data->fmt = *fmt;
219221

@@ -309,9 +311,6 @@ static int video_stm32_dcmi_get_caps(const struct device *dev, struct video_caps
309311
/* 2 buffers are needed for DCMI_MODE_CONTINUOUS */
310312
caps->min_vbuf_count = 2;
311313

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

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)