[vlc-commits] posix: add non-anonymous picture allocator

Rémi Denis-Courmont git at videolan.org
Sun Oct 28 11:18:21 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Oct 27 18:48:32 2018 +0300| [9fae25fb6e303a600e1f2c899e1b701085505a4b] | committer: Rémi Denis-Courmont

posix: add non-anonymous picture allocator

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9fae25fb6e303a600e1f2c899e1b701085505a4b
---

 src/Makefile.am     |  1 +
 src/posix/picture.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git a/src/Makefile.am b/src/Makefile.am
index b3022d2104..c64592a11b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -432,6 +432,7 @@ libvlccore_la_SOURCES += \
 	posix/dirs.c \
 	posix/error.c \
 	posix/netconf.c \
+	posix/picture.c \
 	posix/specific.c \
 	posix/thread.c
 if HAVE_LINUX
diff --git a/src/posix/picture.c b/src/posix/picture.c
new file mode 100644
index 0000000000..ea0a3c3ed2
--- /dev/null
+++ b/src/posix/picture.c
@@ -0,0 +1,55 @@
+/*****************************************************************************
+ * picture.c:
+ *****************************************************************************
+ * Copyright (C) 2018 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+
+#include <vlc_common.h>
+#include <vlc_fs.h>
+#include "misc/picture.h"
+
+void *picture_Allocate(int *restrict fdp, size_t size)
+{
+    int fd = vlc_memfd();
+
+    if (ftruncate(fd, size)) {
+error:
+        vlc_close(fd);
+        return NULL;
+    }
+
+    void *base = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+    if (base == MAP_FAILED)
+        goto error;
+
+    *fdp = fd;
+    return base;
+}
+
+void picture_Deallocate(int fd, void *base, size_t size)
+{
+    munmap(base, size);
+    vlc_close(fd);
+}



More information about the vlc-commits mailing list