[vlc-devel] Android patches

Jean-Baptiste Kempf jb at videolan.org
Fri Jun 3 02:04:09 CEST 2011


On Thu, Jun 02, 2011 at 02:06:16PM +0200, Jean-Baptiste Kempf wrote :
> A few more patches from the vlc-android tree, since noone seems to care
> about merging them...

Going on, in the hope that this will make the project go on...

Android doesn't have a working poll, so here is some code.

Hoping this makes a little of sense
--- 

From: Dominique Martinet
---
 include/vlc_fixups.h |    2 +-
 src/network/poll.c   |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 1 deletions(-)

diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index 63fcb20..6040cd8 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -272,7 +272,7 @@ struct pollfd
 };
 
 # define poll(a, b, c) vlc_poll(a, b, c)
-#elif defined (HAVE_MAEMO)
+#elif defined (HAVE_MAEMO) || defined (__ANDROID__)
 # include <poll.h>
 # define poll(a, b, c) vlc_poll(a, b, c)
 int vlc_poll (struct pollfd *, unsigned, int);
diff --git a/src/network/poll.c b/src/network/poll.c
index c1ca900..c87ab1f 100644
--- a/src/network/poll.c
+++ b/src/network/poll.c
@@ -60,6 +60,77 @@ int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
     return ret;
 }
 
+#elif defined (__ANDROID__)
+
+#include <errno.h>
+
+int vlc_poll(struct pollfd *fds, nfds_t numfds, int timeout)
+{
+
+    /* On Android, an interruption (any signal) will cancel a call to poll,
+     * setting errno to EINTR. As a consequence, no need to do anything special
+     * to cancel poll().
+     * Since the cancellation mechanism should call pthread_exit() we just
+     * need to make sure this thread is not cancellable now.
+     */
+    int canc = vlc_savecancel ();
+
+    fd_set read_set;
+    fd_set write_set;
+    fd_set exception_set;
+    nfds_t i;
+    int n;
+    int rc;
+
+    FD_ZERO(&read_set);
+    FD_ZERO(&write_set);
+    FD_ZERO(&exception_set);
+    n = -1;
+    for (i = 0; i < numfds; i++)
+    {
+        if (fds[i].fd < 0)
+            continue;
+        if (fds[i].fd >= FD_SETSIZE) {
+            errno = EINVAL;
+            return -1;
+        }
+        if (fds[i].events & POLLIN)  FD_SET(fds[i].fd, &read_set);
+        if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &write_set);
+        if (fds[i].events & POLLERR) FD_SET(fds[i].fd, &exception_set);
+
+        if (fds[i].fd > n)
+            n = fds[i].fd;
+    };
+    if (n == -1)
+        /* Hey!? Nothing to poll, in fact!!! */
+        return 0;
+
+    if (timeout < 0)
+        rc = select(n+1, &read_set, &write_set, &exception_set, NULL);
+    else
+    {
+        struct timeval tv;
+
+        tv.tv_sec = timeout / 1000;
+        tv.tv_usec = 1000 * (timeout % 1000);
+        rc = select(n+1, &read_set, &write_set, &exception_set, &tv);
+    }
+    if (rc < 0)
+        return rc;
+    for (i = 0; i < numfds; i++)
+    {
+        fds[i].revents = 0;
+        if (FD_ISSET(fds[i].fd, &read_set))      fds[i].revents |= POLLIN;
+        if (FD_ISSET(fds[i].fd, &write_set))     fds[i].revents |= POLLOUT;
+        if (FD_ISSET(fds[i].fd, &exception_set)) fds[i].revents |= POLLERR;
+    }
+
+    vlc_restorecancel (canc);
+    vlc_testcancel ();
+
+    return rc;
+}
+
 #elif defined (HAVE_POLL)
 # include <vlc_network.h>
 
-- 
1.7.5.3





More information about the vlc-devel mailing list