[vlc-devel] commit: Decomp: vmsplice support ( Rémi Denis-Courmont )
git version control
git at videolan.org
Sat Oct 11 19:36:45 CEST 2008
vlc | branch: master | Rémi Denis-Courmont <rdenis at simphalempin.com> | Sat Oct 11 20:34:41 2008 +0300| [8ccbbab4fb76dc3a93f2ec7fbbb739ea984626f0] | committer: Rémi Denis-Courmont
Decomp: vmsplice support
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8ccbbab4fb76dc3a93f2ec7fbbb739ea984626f0
---
modules/demux/decomp.c | 38 ++++++++++++++++++++++++++++----------
1 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/modules/demux/decomp.c b/modules/demux/decomp.c
index d37b04e..4734e55 100644
--- a/modules/demux/decomp.c
+++ b/modules/demux/decomp.c
@@ -32,6 +32,10 @@
#include <spawn.h>
#include <sys/wait.h>
#include <sys/ioctl.h>
+#ifdef __linux__
+# include <sys/uio.h>
+# include <sys/mman.h>
+#endif
#include <assert.h>
@@ -71,11 +75,13 @@ static void cloexec (int fd)
extern char **environ;
-static void cleanup_fd (void *data)
+static const size_t bufsize = 65536;
+static void cleanup_mmap (void *addr)
{
- close ((intptr_t)data);
+ munmap (addr, bufsize);
}
+
static void *Thread (void *data)
{
demux_t *demux = data;
@@ -83,17 +89,19 @@ static void *Thread (void *data)
int fd = p_sys->write_fd;
bool error = false;
- vlc_cleanup_push (cleanup_fd, (void *)(intptr_t)fd);
-
do
{
+ ssize_t len;
+ int canc = vlc_savecancel ();
#ifdef __linux__
- /* TODO: mmap() + vmsplice() */
+ unsigned char *buf = mmap (NULL, bufsize, PROT_READ|PROT_WRITE,
+ MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+ vlc_cleanup_push (cleanup_mmap, buf);
+#else
+ unsigned char buf[bufsize];
#endif
- unsigned char buf[65536];
- int canc = vlc_savecancel ();
- ssize_t len = stream_Read (demux->s, buf, sizeof (buf));
+ len = stream_Read (demux->s, buf, bufsize);
vlc_restorecancel (canc);
if (len <= 0)
@@ -101,7 +109,13 @@ static void *Thread (void *data)
for (ssize_t i = 0, j = 0; i < len; i += j)
{
- j = write (fd, buf + i, len - i);
+ struct iovec iov[1] = { { buf + i, len - i, } };
+
+#ifdef __linux__
+ j = vmsplice (fd, iov, 1, SPLICE_F_GIFT);
+#else
+ j = writev (fd, iov, 1);
+#endif
if (j == -1)
{
msg_Err (demux, "cannot write data (%m)");
@@ -109,10 +123,13 @@ static void *Thread (void *data)
break;
}
}
+#ifdef __linux__
+ vlc_cleanup_run (); /* munmap (buf, bufsize) */
+#endif
}
while (!error);
- vlc_cleanup_run (); /* close(fd) */
+ msg_Dbg (demux, "compressed stream at EOF");
return NULL;
}
@@ -249,6 +266,7 @@ static void Close (vlc_object_t *obj)
stream_DemuxDelete (p_sys->out);
close (p_sys->read_fd);
vlc_join (p_sys->thread, NULL);
+ close (p_sys->write_fd);
msg_Dbg (obj, "waiting for PID %u", (unsigned)p_sys->pid);
while (waitpid (p_sys->pid, &status, 0) == -1);
More information about the vlc-devel
mailing list