]> git.sesse.net Git - vlc/blobdiff - modules/stream_filter/decomp.c
macosx: merge the nib fle containing Eric Dudiak's interface rework
[vlc] / modules / stream_filter / decomp.c
index da86731ecea2bd1091e0d0fe5bc8bb13e002def3..5171ea703d8e1e326044d601e58a6815c1cc0344 100644 (file)
 #include <vlc_plugin.h>
 #include <vlc_stream.h>
 #include <vlc_network.h>
+#include <assert.h>
 #include <unistd.h>
 #ifndef _POSIX_SPAWN
 # define _POSIX_SPAWN (-1)
 #endif
 #include <fcntl.h>
-#include <spawn.h>
+#if (_POSIX_SPAWN >= 0)
+# include <spawn.h>
+#endif
 #include <sys/wait.h>
 #include <sys/ioctl.h>
 #if defined (__linux__) && defined (HAVE_VMSPLICE)
@@ -118,9 +121,9 @@ static void *Thread (void *data)
                 struct iovec iov = { buf + i, (len - i) & ~page_mask, };
                 j = vmsplice (fd, &iov, 1, SPLICE_F_GIFT);
             }
-#else
-            j = write (fd, buf + i, len - i);
+            if (j == -1 && errno == ENOSYS) /* vmsplice() not supported */
 #endif
+            j = write (fd, buf + i, len - i);
             if (j <= 0)
             {
                 if (j == 0)
@@ -141,6 +144,8 @@ static void *Thread (void *data)
 }
 
 
+static int Peek (stream_t *, const uint8_t **, unsigned int);
+
 #define MIN_BLOCK (1 << 10)
 #define MAX_BLOCK (1 << 20)
 /**
@@ -151,26 +156,38 @@ static int Read (stream_t *stream, void *buf, unsigned int buflen)
 {
     stream_sys_t *p_sys = stream->p_sys;
     block_t *peeked;
-    size_t bonus = 0;
     ssize_t length;
 
+    if (buf == NULL) /* caller skips data, get big enough peek buffer */
+        buflen = Peek (stream, &(const uint8_t *){ NULL }, buflen);
+
     if ((peeked = p_sys->peeked) != NULL)
-    {
-        bonus = (buflen > peeked->i_buffer) ? peeked->i_buffer : buflen;
-        memcpy (buf, peeked->p_buffer, bonus);
-        peeked->p_buffer += bonus;
-        peeked->i_buffer -= bonus;
+    {   /* dequeue peeked data */
+        length = (buflen > peeked->i_buffer) ? peeked->i_buffer : buflen;
+        if (buf != NULL)
+        {
+            memcpy (buf, peeked->p_buffer, length);
+            buf = ((char *)buf) + length;
+        }
+        buflen -= length;
+        peeked->p_buffer += length;
+        peeked->i_buffer -= length;
         if (peeked->i_buffer == 0)
         {
             block_Release (peeked);
             p_sys->peeked = NULL;
         }
+        p_sys->offset += length;
+
+        if (buflen > 0)
+            length += Read (stream, ((char *)buf) + length, buflen - length);
+        return length;
     }
+    assert ((buf != NULL) || (buflen == 0));
 
     length = net_Read (stream, p_sys->read_fd, NULL, buf, buflen, false);
     if (length < 0)
         return 0;
-    length += bonus;
     p_sys->offset += length;
     return length;
 }
@@ -226,9 +243,6 @@ static int Control (stream_t *stream, int query, va_list args)
         case STREAM_GET_SIZE:
             *(va_arg (args, int64_t *)) = 0;
             break;
-        case STREAM_GET_MTU:
-            *(va_arg (args, int *)) = 0;
-            break;
         default:
             return VLC_EGENERIC;
     }