Skip to content

Commit 8435cdc

Browse files
committed
[WIP]samples: video: capture: Add support for m2m transformation
Some boards need additional processing from a m2m device to correctly displays the image, e.g. the LCD on RT1170 is in portrait orientation while the camera image is in landscape. This is to add such a transformation to the capture sample. Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
1 parent 3200798 commit 8435cdc

File tree

4 files changed

+74
-7
lines changed

4 files changed

+74
-7
lines changed

drivers/video/video_sw_generator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct video_sw_generator_data {
5252
.width_min = 64, \
5353
.width_max = 1920, \
5454
.height_min = 64, \
55-
.height_max = 1080, \
55+
.height_max = 1280, \
5656
.width_step = 1, \
5757
.height_step = 1, \
5858
}

include/zephyr/drivers/video.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ struct video_caps {
144144
* Represent a video frame.
145145
*/
146146
struct video_buffer {
147-
/** type of the buffer */
148-
enum video_buf_type type;
149147
/** pointer to driver specific data. */
150148
void *driver_data;
149+
/** type of the buffer */
150+
enum video_buf_type type;
151151
/** pointer to the start of the buffer. */
152152
uint8_t *buffer;
153153
/** index of the buffer, optionally set by the application */
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
CONFIG_VIDEO_BUFFER_POOL_SZ_MAX=3686800
1+
CONFIG_VIDEO_BUFFER_POOL_SZ_MAX=6530200
2+
CONFIG_VIDEO_BUFFER_POOL_NUM_MAX=3

samples/drivers/video/capture/src/main.c

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ int main(void)
120120

121121
LOG_INF("Video device: %s", video_dev->name);
122122

123+
/* Get PxP device */
124+
const struct device *const transform_dev = DEVICE_DT_GET(DT_NODELABEL(pxp));
125+
123126
/* Get capabilities */
124127
caps.type = type;
125128
if (video_get_caps(video_dev, &caps)) {
@@ -206,6 +209,25 @@ int main(void)
206209
return 0;
207210
}
208211

212+
/* Set format PxP */
213+
fmt.type = VIDEO_BUF_TYPE_INPUT;
214+
if (video_set_format(transform_dev, &fmt)) {
215+
LOG_ERR("Unable to set input format for PxP");
216+
return 0;
217+
}
218+
fmt.type = VIDEO_BUF_TYPE_OUTPUT;
219+
220+
struct video_format fmt_out = {.pixelformat = fmt.pixelformat,
221+
.width = fmt.height,
222+
.height = fmt.width,
223+
.type = VIDEO_BUF_TYPE_OUTPUT,};
224+
225+
if (video_set_format(transform_dev, &fmt_out)) {
226+
LOG_ERR("Unable to set output format for PxP");
227+
return 0;
228+
}
229+
230+
/* Get and enumerate frame interval */
209231
if (!video_get_frmival(video_dev, &frmival)) {
210232
LOG_INF("- Default frame rate : %f fps",
211233
1.0 * frmival.denominator / frmival.numerator);
@@ -257,6 +279,11 @@ int main(void)
257279
video_set_ctrl(video_dev, &ctrl);
258280
}
259281

282+
/* Rotate image 90 degree with PxP */
283+
ctrl.id = VIDEO_CID_ROTATE;
284+
ctrl.val = 90;
285+
video_set_ctrl(transform_dev, &ctrl);
286+
260287
#if DT_HAS_CHOSEN(zephyr_display)
261288
const struct device *const display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
262289

@@ -265,7 +292,7 @@ int main(void)
265292
return 0;
266293
}
267294

268-
err = display_setup(display_dev, fmt.pixelformat);
295+
err = display_setup(display_dev, fmt_out.pixelformat);
269296
if (err) {
270297
LOG_ERR("Unable to set up display");
271298
return err;
@@ -292,7 +319,10 @@ int main(void)
292319
return 0;
293320
}
294321
buffers[i]->type = type;
295-
video_enqueue(video_dev, buffers[i]);
322+
323+
if (i < 2) {
324+
video_enqueue(video_dev, buffers[i]);
325+
}
296326
}
297327

298328
/* Start video capture */
@@ -321,8 +351,44 @@ int main(void)
321351
}
322352
#endif
323353

354+
/* PxP m2m handling */
355+
vbuf->type = VIDEO_BUF_TYPE_INPUT;
356+
err = video_enqueue(transform_dev, vbuf);
357+
if (err) {
358+
LOG_ERR("Unable to enqueue PxP video buf in");
359+
return 0;
360+
}
361+
362+
buffers[2]->type = VIDEO_BUF_TYPE_OUTPUT;
363+
err = video_enqueue(transform_dev, buffers[2]);
364+
if (err) {
365+
LOG_ERR("Unable to enqueue PxP video buf out");
366+
return 0;
367+
}
368+
369+
/* same start for both input and output */
370+
if (video_stream_start(transform_dev, VIDEO_BUF_TYPE_INPUT)) {
371+
LOG_ERR("Unable to start PxP");
372+
return 0;
373+
}
374+
375+
err = video_dequeue(transform_dev, &vbuf, K_FOREVER);
376+
if (err) {
377+
LOG_ERR("Unable to dequeue PxP video buf in");
378+
return 0;
379+
}
380+
381+
// buffers[2]->type = VIDEO_BUF_TYPE_OUTPUT; => rework buffer management
382+
struct video_buffer *vbuf_out = &(struct video_buffer){};
383+
vbuf_out->type = VIDEO_BUF_TYPE_OUTPUT;
384+
err = video_dequeue(transform_dev, &vbuf_out, K_FOREVER);
385+
if (err) {
386+
LOG_ERR("Unable to dequeue PxP video buf out");
387+
return 0;
388+
}
389+
324390
#if DT_HAS_CHOSEN(zephyr_display)
325-
video_display_frame(display_dev, vbuf, fmt);
391+
video_display_frame(display_dev, vbuf_out, fmt_out);
326392
#endif
327393

328394
err = video_enqueue(video_dev, vbuf);

0 commit comments

Comments
 (0)