Skip to content

Commit f2c8187

Browse files
committed
samples: drivers: video: make capture sample failure more visible
Centralize exit of all helper functions and display a common message that indicates clearly that the sample is not blocking on any function but instead stopped running. Signed-off-by: Josuah Demangeon <me@josuah.net>
1 parent 6af39b3 commit f2c8187

File tree

1 file changed

+15
-11
lines changed
  • samples/drivers/video/capture/src

1 file changed

+15
-11
lines changed

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static inline int app_setup_display(const struct device *const display_dev, cons
5454
}
5555
break;
5656
default:
57+
LOG_ERR("Display pixel format not supported by this sample");
5758
return -ENOTSUP;
5859
}
5960
if (ret < 0) {
@@ -356,48 +357,47 @@ int main(void)
356357

357358
ret = app_query_video_info(video_dev, &caps, &fmt);
358359
if (ret < 0) {
359-
return 0;
360+
goto err;
360361
}
361362

362363
ret = app_setup_video_selection(video_dev, &fmt);
363364
if (ret < 0) {
364-
return 0;
365+
goto err;
365366
}
366367

367368
ret = app_setup_video_format(video_dev, &fmt);
368369
if (ret < 0) {
369-
return 0;
370+
goto err;
370371
}
371372

372373
ret = app_setup_video_frmival(video_dev, &fmt);
373374
if (ret < 0) {
374-
return 0;
375+
goto err;
375376
}
376377

377378
ret = app_setup_video_controls(video_dev);
378379
if (ret < 0) {
379-
return 0;
380+
goto err;
380381
}
381382

382383
#if DT_HAS_CHOSEN(zephyr_display)
383384
const struct device *const display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
384385

385386
ret = app_setup_display(display_dev, fmt.pixelformat);
386387
if (ret < 0) {
387-
LOG_ERR("Unable to set up display");
388-
return 0;
388+
goto err;
389389
}
390390
#endif
391391

392392
ret = app_setup_video_buffers(video_dev, &caps, &fmt);
393393
if (ret < 0) {
394-
return 0;
394+
goto err;
395395
}
396396

397397
ret = video_stream_start(video_dev, VIDEO_BUF_TYPE_OUTPUT);
398398
if (ret < 0) {
399399
LOG_ERR("Unable to start capture (interface)");
400-
return 0;
400+
goto err;
401401
}
402402

403403
LOG_INF("Capture started");
@@ -407,7 +407,7 @@ int main(void)
407407
ret = video_dequeue(video_dev, &vbuf, K_FOREVER);
408408
if (ret < 0) {
409409
LOG_ERR("Unable to dequeue video buf");
410-
return 0;
410+
goto err;
411411
}
412412

413413
LOG_INF("Got frame %u! size: %u; timestamp %u ms",
@@ -423,7 +423,11 @@ int main(void)
423423
ret = video_enqueue(video_dev, vbuf);
424424
if (ret < 0) {
425425
LOG_ERR("Unable to requeue video buf");
426-
return 0;
426+
goto err;
427427
}
428428
}
429+
430+
err:
431+
LOG_ERR("Aborting sample");
432+
return 0;
429433
}

0 commit comments

Comments
 (0)