]> git.sesse.net Git - vlc/blobdiff - modules/stream_filter/decomp.c
Fixed rar stream filter.
[vlc] / modules / stream_filter / decomp.c
index f89d16ddc4d58c22b2c193c3e084d4deac6ccc3f..b74bd1c9f0fc6f995067361824a57d480f88d919 100644 (file)
@@ -26,7 +26,9 @@
 #include <vlc_plugin.h>
 #include <vlc_stream.h>
 #include <vlc_network.h>
+#include <assert.h>
 #include <unistd.h>
+#include <errno.h>
 #ifndef _POSIX_SPAWN
 # define _POSIX_SPAWN (-1)
 #endif
@@ -120,9 +122,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)
@@ -143,6 +145,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)
 /**
@@ -155,11 +159,17 @@ static int Read (stream_t *stream, void *buf, unsigned int buflen)
     block_t *peeked;
     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)
     {   /* dequeue peeked data */
         length = (buflen > peeked->i_buffer) ? peeked->i_buffer : buflen;
-        memcpy (buf, peeked->p_buffer, length);
-        buf = ((char *)buf) + length;
+        if (buf != NULL)
+        {
+            memcpy (buf, peeked->p_buffer, length);
+            buf = ((char *)buf) + length;
+        }
         buflen -= length;
         peeked->p_buffer += length;
         peeked->i_buffer -= length;
@@ -174,6 +184,7 @@ static int Read (stream_t *stream, void *buf, unsigned int buflen)
             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)
@@ -233,9 +244,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;
     }