]> git.sesse.net Git - ffmpeg/commitdiff
hwcontext_drm: make dependency on Linux kernel headers optional
authorLynne <dev@lynne.ee>
Wed, 30 Dec 2020 21:19:16 +0000 (22:19 +0100)
committerLynne <dev@lynne.ee>
Wed, 30 Dec 2020 22:14:46 +0000 (23:14 +0100)
This was introduced in version 4.6. And may not exist all without an
optional package. So to prevent a hard dependency on needing the Linux
kernel headers to compile, make this optional.

Also ignore the status of the ioctl, since it may fail on older kernels
which don't support it. It's okay to ignore as its not fatal and any
serious errors will be caught later by the mmap call.

configure
libavutil/hwcontext_drm.c

index 90914752f1622d9cc7867a4243253cff2f381268..df42f37d083c6f3877ca7b2d3322af9eedf61b7e 100755 (executable)
--- a/configure
+++ b/configure
@@ -2125,6 +2125,7 @@ HEADERS_LIST="
     ES2_gl_h
     gsm_h
     io_h
+    linux_dma_buf_h
     linux_perf_event_h
     machine_ioctl_bt848_h
     machine_ioctl_meteor_h
@@ -6151,6 +6152,9 @@ check_headers dxgidebug.h
 check_headers dxva.h
 check_headers dxva2api.h -D_WIN32_WINNT=0x0600
 check_headers io.h
+enabled libdrm &&
+    check_headers linux/dma-buf.h
+
 check_headers linux/perf_event.h
 check_headers libcrystalhd/libcrystalhd_if.h
 check_headers malloc.h
index ceacf683a08b3b3cdf6e33a886b395da7e4aaa95..7a9fdbd263d48c5817c15ad34fee6775a5e27838 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config.h"
+
 #include <fcntl.h>
 #include <sys/mman.h>
 #include <unistd.h>
+
+/* This was introduced in version 4.6. And may not exist all without an
+ * optional package. So to prevent a hard dependency on needing the Linux
+ * kernel headers to compile, make this optional. */
+#if HAVE_LINUX_DMA_BUF_H
 #include <linux/dma-buf.h>
 #include <sys/ioctl.h>
+#endif
 
 #include <drm.h>
 #include <xf86drm.h>
@@ -97,14 +105,12 @@ static void drm_unmap_frame(AVHWFramesContext *hwfc,
                             HWMapDescriptor *hwmap)
 {
     DRMMapping *map = hwmap->priv;
-    struct dma_buf_sync sync = { .flags = DMA_BUF_SYNC_END | map->sync_flags };
-    int i, ret;
-
-    for (i = 0; i < map->nb_regions; i++) {
-        ret = ioctl(map->object[i], DMA_BUF_IOCTL_SYNC, &sync);
-        if (ret)
-            av_log(hwfc, AV_LOG_ERROR, "Failed to issue ioctl sync to DRM object "
-                   "%d: %d.\n", map->object[i], errno);
+
+    for (int i = 0; i < map->nb_regions; i++) {
+#if HAVE_LINUX_DMA_BUF_H
+        struct dma_buf_sync sync = { .flags = DMA_BUF_SYNC_END | map->sync_flags };
+        ioctl(map->object[i], DMA_BUF_IOCTL_SYNC, &sync);
+#endif
         munmap(map->address[i], map->length[i]);
     }
 
@@ -115,7 +121,9 @@ static int drm_map_frame(AVHWFramesContext *hwfc,
                          AVFrame *dst, const AVFrame *src, int flags)
 {
     const AVDRMFrameDescriptor *desc = (AVDRMFrameDescriptor*)src->data[0];
+#if HAVE_LINUX_DMA_BUF_H
     struct dma_buf_sync sync_start = { 0 };
+#endif
     DRMMapping *map;
     int err, i, p, plane;
     int mmap_prot;
@@ -126,16 +134,18 @@ static int drm_map_frame(AVHWFramesContext *hwfc,
         return AVERROR(ENOMEM);
 
     mmap_prot = 0;
-    if (flags & AV_HWFRAME_MAP_READ) {
+    if (flags & AV_HWFRAME_MAP_READ)
         mmap_prot |= PROT_READ;
-        map->sync_flags |= DMA_BUF_SYNC_READ;
-    }
-    if (flags & AV_HWFRAME_MAP_WRITE) {
+    if (flags & AV_HWFRAME_MAP_WRITE)
         mmap_prot |= PROT_WRITE;
-        map->sync_flags |= DMA_BUF_SYNC_WRITE;
-    }
 
+#if HAVE_LINUX_DMA_BUF_H
+    if (flags & AV_HWFRAME_MAP_READ)
+        map->sync_flags |= DMA_BUF_SYNC_READ;
+    if (flags & AV_HWFRAME_MAP_WRITE)
+        map->sync_flags |= DMA_BUF_SYNC_WRITE;
     sync_start.flags = DMA_BUF_SYNC_START | map->sync_flags;
+#endif
 
     av_assert0(desc->nb_objects <= AV_DRM_MAX_PLANES);
     for (i = 0; i < desc->nb_objects; i++) {
@@ -152,13 +162,11 @@ static int drm_map_frame(AVHWFramesContext *hwfc,
         map->length[i]  = desc->objects[i].size;
         map->object[i] = desc->objects[i].fd;
 
-        err = ioctl(desc->objects[i].fd, DMA_BUF_IOCTL_SYNC, &sync_start);
-        if (err) {
-            err = AVERROR(errno);
-            av_log(hwfc, AV_LOG_ERROR, "Failed to issue ioctl sync to DRM object "
-                   "%d: %d.\n", desc->objects[i].fd, errno);
-            goto fail;
-        }
+#if HAVE_LINUX_DMA_BUF_H
+        /* We're not checking for errors here because the kernel may not
+         * support the ioctl, in which case its okay to carry on */
+        ioctl(desc->objects[i].fd, DMA_BUF_IOCTL_SYNC, &sync_start);
+#endif
     }
     map->nb_regions = i;