summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2012-07-31 13:10:44 +0200
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2014-03-10 19:53:57 +0100
commitbc72e1332cfc81e166c83c90ad63b4b648f19867 (patch)
tree91285072d74f8addcd5a72e6960f37e61a7e95b4 /src/main.c
parent45033a900fb0d004b9790f7b9d57045ea7510cd3 (diff)
Split media_device creation and opening
Make the media_device refcounted to manage its life time. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Acked-by: Sakari Ailus <sakari.ailus@iki.fi>
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index 4a27c8c..8b48fde 100644
--- a/src/main.c
+++ b/src/main.c
@@ -329,15 +329,20 @@ int main(int argc, char **argv)
if (parse_cmdline(argc, argv))
return EXIT_FAILURE;
- /* Open the media device and enumerate entities, pads and links. */
+ media = media_device_new(media_opts.devname);
+ if (media == NULL) {
+ printf("Failed to create media device\n");
+ goto out;
+ }
+
if (media_opts.verbose)
- media = media_open_debug(
- media_opts.devname,
+ media_debug_set_handler(media,
(void (*)(void *, ...))fprintf, stdout);
- else
- media = media_open(media_opts.devname);
- if (media == NULL) {
- printf("Failed to open %s\n", media_opts.devname);
+
+ /* Enumerate entities, pads and links. */
+ ret = media_device_enumerate(media);
+ if (ret < 0) {
+ printf("Failed to enumerate %s (%d)\n", media_opts.devname, ret);
goto out;
}
@@ -446,7 +451,7 @@ int main(int argc, char **argv)
out:
if (media)
- media_close(media);
+ media_device_unref(media);
return ret ? EXIT_FAILURE : EXIT_SUCCESS;
}