Skip to content

Commit e5ba362

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 40d6dc7 commit e5ba362

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) {
@@ -357,48 +358,47 @@ int main(void)
357358

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

363364
ret = app_setup_video_selection(video_dev, &fmt);
364365
if (ret < 0) {
365-
return 0;
366+
goto err;
366367
}
367368

368369
ret = app_setup_video_format(video_dev, &fmt);
369370
if (ret < 0) {
370-
return 0;
371+
goto err;
371372
}
372373

373374
ret = app_setup_video_frmival(video_dev, &fmt);
374375
if (ret < 0) {
375-
return 0;
376+
goto err;
376377
}
377378

378379
ret = app_setup_video_controls(video_dev);
379380
if (ret < 0) {
380-
return 0;
381+
goto err;
381382
}
382383

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

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

393393
ret = app_setup_video_buffers(video_dev, &caps, &fmt);
394394
if (ret < 0) {
395-
return 0;
395+
goto err;
396396
}
397397

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

404404
LOG_INF("Capture started");
@@ -408,7 +408,7 @@ int main(void)
408408
ret = video_dequeue(video_dev, &vbuf, K_FOREVER);
409409
if (ret < 0) {
410410
LOG_ERR("Unable to dequeue video buf");
411-
return 0;
411+
goto err;
412412
}
413413

414414
LOG_INF("Got frame %u! size: %u; timestamp %u ms",
@@ -424,7 +424,11 @@ int main(void)
424424
ret = video_enqueue(video_dev, vbuf);
425425
if (ret < 0) {
426426
LOG_ERR("Unable to requeue video buf");
427-
return 0;
427+
goto err;
428428
}
429429
}
430+
431+
err:
432+
LOG_ERR("Aborting sample");
433+
return 0;
430434
}

0 commit comments

Comments
 (0)