Skip to content

Commit 70d4b18

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 need to the capture sample Signed-off-by: Phi Bang Nguyen <phibang.nguyen@nxp.com>
1 parent 20e1bcb commit 70d4b18

File tree

3 files changed

+76
-4
lines changed

3 files changed

+76
-4
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
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
CONFIG_VIDEO_BUFFER_POOL_SZ_MAX=3686800
1+
CONFIG_VIDEO_BUFFER_POOL_SZ_MAX=6530200
2+
CONFIG_VIDEO_FRAME_HEIGHT=1280
3+
CONFIG_VIDEO_FRAME_WIDTH=720
4+
5+
CONFIG_VIDEO_BUFFER_POOL_NUM_MAX=3

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

Lines changed: 70 additions & 2 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,6 +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+
struct video_buffer *vbuf_in = &(struct video_buffer){};
376+
vbuf_in->type = VIDEO_BUF_TYPE_INPUT;
377+
err = video_dequeue(transform_dev, &vbuf_in, K_FOREVER);
378+
if (err) {
379+
LOG_ERR("Unable to dequeue PxP video buf in");
380+
return 0;
381+
}
382+
383+
// buffers[2]->type = VIDEO_BUF_TYPE_OUTPUT; => rework buffer management
384+
struct video_buffer *vbuf_out = &(struct video_buffer){};
385+
vbuf_out->type = VIDEO_BUF_TYPE_OUTPUT;
386+
err = video_dequeue(transform_dev, &vbuf_out, K_FOREVER);
387+
if (err) {
388+
LOG_ERR("Unable to dequeue PxP video buf out");
389+
return 0;
390+
}
391+
324392
#if DT_HAS_CHOSEN(zephyr_display)
325393
video_display_frame(display_dev, vbuf, fmt);
326394
#endif

0 commit comments

Comments
 (0)