[Ffmpeg-cvslog] r7987 - in trunk: configure ffserver.c libavformat/os_support.c libavformat/os_support.h

mmu_man subversion
Thu Feb 15 08:44:11 CET 2007


Author: mmu_man
Date: Thu Feb 15 08:44:10 2007
New Revision: 7987

Modified:
   trunk/configure
   trunk/ffserver.c
   trunk/libavformat/os_support.c
   trunk/libavformat/os_support.h

Log:
poll() emulation for BeOS, and maybe MinGW.

Modified: trunk/configure
==============================================================================
--- trunk/configure	(original)
+++ trunk/configure	Thu Feb 15 08:44:10 2007
@@ -548,6 +548,7 @@
     sdl
     sdl_video_size
     soundcard_h
+    sys_poll_h
     sys_soundcard_h
     threads
     w32threads
@@ -1430,6 +1431,12 @@
 check_func localtime_r
 enabled zlib && check_lib zlib.h zlibVersion -lz || zlib="no"
 
+# ffserver uses poll(),
+# if it's not found we can emulate it using select().
+if enabled ffserver; then
+    check_header sys/poll.h
+fi
+
 # check for some common methods of building with pthread support
 # do this before the optional library checks as some of them require pthreads
 if enabled pthreads; then

Modified: trunk/ffserver.c
==============================================================================
--- trunk/ffserver.c	(original)
+++ trunk/ffserver.c	Thu Feb 15 08:44:10 2007
@@ -25,7 +25,9 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
+#ifdef HAVE_SYS_POLL_H
 #include <sys/poll.h>
+#endif
 #include <errno.h>
 #include <sys/time.h>
 #undef time //needed because HAVE_AV_CONFIG_H is defined on top

Modified: trunk/libavformat/os_support.c
==============================================================================
--- trunk/libavformat/os_support.c	(original)
+++ trunk/libavformat/os_support.c	Thu Feb 15 08:44:10 2007
@@ -35,6 +35,9 @@
 #include <sys/time.h>
 #endif
 #include <time.h>
+#ifndef HAVE_SYS_POLL_H
+#include <sys/select.h>
+#endif
 
 /**
  * gets the current time in micro seconds.
@@ -94,3 +97,66 @@
     return 1;
 }
 #endif /* !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK) */
+
+#ifndef HAVE_SYS_POLL_H
+int poll(struct pollfd *fds, nfds_t numfds, int timeout)
+{
+    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 < (nfds_t) n; 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;
+    };
+
+    return rc;
+}
+
+
+#endif /* HAVE_SYS_POLL_H */
+

Modified: trunk/libavformat/os_support.h
==============================================================================
--- trunk/libavformat/os_support.h	(original)
+++ trunk/libavformat/os_support.h	Thu Feb 15 08:44:10 2007
@@ -32,6 +32,7 @@
  * - floatf() (OS/2)
  * - strcasecmp() (OS/2)
  * - closesocket()
+ * - poll() (BeOS)
  */
 
 #if defined(__BEOS__) || defined(__INNOTEK_LIBC__)
@@ -78,4 +79,31 @@
 #define closesocket close
 #endif
 
+#ifndef HAVE_SYS_POLL_H
+typedef unsigned long nfds_t;
+
+struct pollfd {
+    int fd;
+    short events;  /* events to look for */
+    short revents; /* events that occured */
+};
+
+/* events & revents */
+#define POLLIN     0x0001  /* any readable data available */
+#define POLLOUT    0x0002  /* file descriptor is writeable */
+#define POLLRDNORM POLLIN
+#define POLLWRNORM POLLOUT
+#define POLLRDBAND 0x0008  /* priority readable data */
+#define POLLWRBAND 0x0010  /* priority data can be written */
+#define POLLPRI    0x0020  /* high priority readable data */
+
+/* revents only */
+#define POLLERR    0x0004  /* errors pending */
+#define POLLHUP    0x0080  /* disconnected */
+#define POLLNVAL   0x1000  /* invalid file descriptor */
+
+
+extern int poll(struct pollfd *fds, nfds_t numfds, int timeout);
+#endif /* HAVE_SYS_POLL_H */
+
 #endif /* _OS_SUPPORT_H */




More information about the ffmpeg-cvslog mailing list