Skip to content

Commit 122e85a

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 aa8b23d commit 122e85a

File tree

16 files changed

+43
-97
lines changed

16 files changed

+43
-97
lines changed

drivers/video/video_emul_rx.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ static int emul_rx_set_fmt(const struct device *const dev, struct video_format *
6767
}
6868

6969
/* Cache the format selected locally to use it for getting the size of the buffer */
70-
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
70+
ret = video_estimate_fmt_size(fmt);
71+
if (ret < 0) {
72+
return ret;
73+
}
74+
7175
data->fmt = *fmt;
7276

7377
return 0;

drivers/video/video_esp32_dvp.c

Lines changed: 8 additions & 5 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
}
@@ -268,7 +265,10 @@ static int video_esp32_get_fmt(const struct device *dev, struct video_format *fm
268265
return ret;
269266
}
270267

271-
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
268+
ret = video_estimate_fmt_size(fmt);
269+
if (ret < 0) {
270+
return ret;
271+
}
272272

273273
return 0;
274274
}
@@ -284,7 +284,10 @@ static int video_esp32_set_fmt(const struct device *dev, struct video_format *fm
284284
return ret;
285285
}
286286

287-
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
287+
ret = video_estimate_fmt_size(fmt);
288+
if (ret < 0) {
289+
return ret;
290+
}
288291

289292
data->video_format = *fmt;
290293

drivers/video/video_mcux_csi.c

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

128-
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
128+
video_estimate_fmt_size(fmt);
129129
}
130130
#endif
131131

@@ -168,6 +168,7 @@ static int video_mcux_csi_set_fmt(const struct device *dev, struct video_format
168168
}
169169

170170
fmt->pitch = data->csi_config.linePitch_Bytes;
171+
fmt->size = fmt->pitch * fmt->height;
171172

172173
return 0;
173174
}
@@ -323,8 +324,6 @@ static int video_mcux_csi_get_caps(const struct device *dev, struct video_caps *
323324

324325
/* NXP MCUX CSI request at least 2 buffer before starting */
325326
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;
328327

329328
/* no source dev */
330329
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: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ static int video_renesas_ra_ceu_get_format(const struct device *dev, struct vide
117117
return ret;
118118
}
119119

120-
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
121-
122-
return 0;
120+
return video_estimate_fmt_size(fmt);
123121
}
124122

125123
static int video_renesas_ra_ceu_set_format(const struct device *dev, struct video_format *fmt)
@@ -169,7 +167,10 @@ static int video_renesas_ra_ceu_set_format(const struct device *dev, struct vide
169167
return -EIO;
170168
}
171169

172-
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
170+
ret = video_estimate_fmt_size(fmt);
171+
if (ret < 0) {
172+
return ret;
173+
}
173174

174175
memcpy(&data->fmt, fmt, sizeof(struct video_format));
175176

@@ -181,8 +182,6 @@ static int video_renesas_ra_ceu_get_caps(const struct device *dev, struct video_
181182
const struct video_renesas_ra_ceu_config *config = dev->config;
182183

183184
caps->min_vbuf_count = 1;
184-
caps->min_line_count = LINE_COUNT_HEIGHT;
185-
caps->max_line_count = LINE_COUNT_HEIGHT;
186185

187186
return video_get_caps(config->source_dev, caps);
188187
}

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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ static int video_stm32_dcmi_set_fmt(const struct device *dev, struct video_forma
194194
return ret;
195195
}
196196

197-
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
197+
ret = video_estimate_fmt_size(fmt);
198+
if (ret < 0) {
199+
return ret;
200+
}
198201

199202
data->fmt = *fmt;
200203

@@ -213,7 +216,10 @@ static int video_stm32_dcmi_get_fmt(const struct device *dev, struct video_forma
213216
return ret;
214217
}
215218

216-
fmt->pitch = fmt->width * video_bits_per_pixel(fmt->pixelformat) / BITS_PER_BYTE;
219+
ret = video_estimate_fmt_size(fmt);
220+
if (ret < 0) {
221+
return ret;
222+
}
217223

218224
data->fmt = *fmt;
219225

@@ -309,9 +315,6 @@ static int video_stm32_dcmi_get_caps(const struct device *dev, struct video_caps
309315
/* 2 buffers are needed for DCMI_MODE_CONTINUOUS */
310316
caps->min_vbuf_count = 2;
311317

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

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_stm32_venc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,6 @@ static int stm32_venc_get_caps(const struct device *dev, struct video_caps *caps
806806
}
807807

808808
/* VENC produces full frames */
809-
caps->min_line_count = caps->max_line_count = LINE_COUNT_HEIGHT;
810809
caps->min_vbuf_count = 1;
811810

812811
return 0;

0 commit comments

Comments
 (0)