public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafaël Carré" <funman@videolan.org>
To: linux-media@vger.kernel.org
Subject: [PATCH] dvb_dev_get_fd(): return fd of local devices
Date: Wed, 15 Nov 2017 11:47:11 +0100	[thread overview]
Message-ID: <20171115104711.5418-1-funman@videolan.org> (raw)

This makes it possible to poll a local device.
Getting the fd is preferrable to adding a dvb_dev_poll() function,
because we can poll several fds together in an event-based program.

This is not implemented for remote devices, as polling a remote fd
does not make sense.
We could instead return the socket to know when to expect messages
from the remote device, but the current implementation in
dvb-dev-remote.c already runs a thread to receive remote messages
as soon as possible.
---

Note, after reading README, I did not bump the library version.

Comments welcome

 lib/include/libdvbv5/dvb-dev.h | 12 ++++++++++++
 lib/libdvbv5/dvb-dev-local.c   |  6 ++++++
 lib/libdvbv5/dvb-dev-priv.h    |  1 +
 lib/libdvbv5/dvb-dev.c         | 11 +++++++++++
 4 files changed, 30 insertions(+)

diff --git a/lib/include/libdvbv5/dvb-dev.h b/lib/include/libdvbv5/dvb-dev.h
index 98bee5e7..55e0f065 100644
--- a/lib/include/libdvbv5/dvb-dev.h
+++ b/lib/include/libdvbv5/dvb-dev.h
@@ -289,6 +289,18 @@ struct dvb_open_descriptor *dvb_dev_open(struct dvb_device *dvb,
  */
 void dvb_dev_close(struct dvb_open_descriptor *open_dev);
 
+/**
+ * @brief returns fd from a local device
+ * This will not work for remote devices.
+ * @ingroup dvb_device
+ *
+ * @param open_dev	Points to the struct dvb_open_descriptor
+ *
+ * @return On success, returns the fd.
+ * Returns -1 on error.
+ */
+int dvb_dev_get_fd(struct dvb_open_descriptor *open_dev);
+
 /**
  * @brief read from a dvb demux or dvr file
  * @ingroup dvb_device
diff --git a/lib/libdvbv5/dvb-dev-local.c b/lib/libdvbv5/dvb-dev-local.c
index b50b61b4..eb2f0775 100644
--- a/lib/libdvbv5/dvb-dev-local.c
+++ b/lib/libdvbv5/dvb-dev-local.c
@@ -775,6 +775,11 @@ static void dvb_dev_local_free(struct dvb_device_priv *dvb)
 	free(priv);
 }
 
+static int dvb_local_get_fd(struct dvb_open_descriptor *open_dev)
+{
+    return open_dev->fd;
+}
+
 /* Initialize for local usage */
 void dvb_dev_local_init(struct dvb_device_priv *dvb)
 {
@@ -788,6 +793,7 @@ void dvb_dev_local_init(struct dvb_device_priv *dvb)
 	ops->stop_monitor = dvb_local_stop_monitor;
 	ops->open = dvb_local_open;
 	ops->close = dvb_local_close;
+	ops->get_fd = dvb_local_get_fd;
 
 	ops->dmx_stop = dvb_local_dmx_stop;
 	ops->set_bufsize = dvb_local_set_bufsize;
diff --git a/lib/libdvbv5/dvb-dev-priv.h b/lib/libdvbv5/dvb-dev-priv.h
index e05fcad2..2e69f766 100644
--- a/lib/libdvbv5/dvb-dev-priv.h
+++ b/lib/libdvbv5/dvb-dev-priv.h
@@ -72,6 +72,7 @@ struct dvb_dev_ops {
 	int (*fe_get_stats)(struct dvb_v5_fe_parms *p);
 
 	void (*free)(struct dvb_device_priv *dvb);
+	int (*get_fd)(struct dvb_open_descriptor *dvb);
 };
 
 struct dvb_device_priv {
diff --git a/lib/libdvbv5/dvb-dev.c b/lib/libdvbv5/dvb-dev.c
index 7e2da1fb..447c9fd5 100644
--- a/lib/libdvbv5/dvb-dev.c
+++ b/lib/libdvbv5/dvb-dev.c
@@ -218,6 +218,17 @@ struct dvb_open_descriptor *dvb_dev_open(struct dvb_device *d,
 	return ops->open(dvb, sysname, flags);
 }
 
+int dvb_dev_get_fd(struct dvb_open_descriptor *open_dev)
+{
+	struct dvb_device_priv *dvb = (void *)open_dev;
+	struct dvb_dev_ops *ops = &dvb->ops;
+
+	if (!ops->get_fd)
+		return -1;
+
+	return ops->get_fd(open_dev);
+}
+
 void dvb_dev_close(struct dvb_open_descriptor *open_dev)
 {
 	struct dvb_device_priv *dvb = open_dev->dvb;
-- 
2.14.1

             reply	other threads:[~2017-11-15 10:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-15 10:47 Rafaël Carré [this message]
2017-11-15 14:25 ` [PATCH v2] dvb_dev_get_fd(): return fd of local devices Rafaël Carré
2017-11-16 11:26   ` Mauro Carvalho Chehab
2017-11-16 11:38   ` Rafaël Carré
2017-11-16 11:25 ` [PATCH] " Mauro Carvalho Chehab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171115104711.5418-1-funman@videolan.org \
    --to=funman@videolan.org \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox