diff mbox series

[FFmpeg-devel] hwcontext_drm: make dependency on Linux kernel headers optional

Message ID MPpX9NI--3-2@lynne.ee
State New
Headers show
Series [FFmpeg-devel] hwcontext_drm: make dependency on Linux kernel headers optional
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Lynne Dec. 30, 2020, 9:23 p.m. UTC
This was introduced sometimes in between 4.4 and 4.15. And may not exist 
at all without an optional package. So to prevent a hard dependency
on needing the Linux kernel headers to compile, make this optional.

Patch attached.
Subject: [PATCH] hwcontext_drm: make dependency on Linux kernel headers
 optional

This was introduced sometimes in between 4.4 and 4.15. And may not exist
at all without an optional package. So to prevent a hard dependency
on needing the Linux kernel headers to compile, make this optional.
---
 configure                 |  2 ++
 libavutil/hwcontext_drm.c | 34 ++++++++++++++++++++++++----------
 2 files changed, 26 insertions(+), 10 deletions(-)

Comments

Lynne Dec. 30, 2020, 10:18 p.m. UTC | #1
Dec 30, 2020, 22:23 by dev@lynne.ee:

> This was introduced sometimes in between 4.4 and 4.15. And may not exist 
> at all without an optional package. So to prevent a hard dependency
> on needing the Linux kernel headers to compile, make this optional.
>
> Patch attached.
>

After some discussion on IRC pushed a slightly different version.
diff mbox series

Patch

diff --git a/configure b/configure
index 90914752f1..5e2559ef2a 100755
--- 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,7 @@  check_headers dxgidebug.h
 check_headers dxva.h
 check_headers dxva2api.h -D_WIN32_WINNT=0x0600
 check_headers io.h
+check_headers linux/dma-buf.h
 check_headers linux/perf_event.h
 check_headers libcrystalhd/libcrystalhd_if.h
 check_headers malloc.h
diff --git a/libavutil/hwcontext_drm.c b/libavutil/hwcontext_drm.c
index ceacf683a0..aadbd0dc72 100644
--- a/libavutil/hwcontext_drm.c
+++ b/libavutil/hwcontext_drm.c
@@ -19,8 +19,15 @@ 
 #include <fcntl.h>
 #include <sys/mman.h>
 #include <unistd.h>
+
+/* This was introduced sometimes in between 4.4 and 4.15. And may not exist
+ * at all without an optional package. So to prevent a hard dependency
+ * on needing the Linux kernel headers to compile, make this optional. */
+#include "config.h"
+#if HAVE_LINUX_DMA_BUF_H
 #include <linux/dma-buf.h>
 #include <sys/ioctl.h>
+#endif
 
 #include <drm.h>
 #include <xf86drm.h>
@@ -97,14 +104,15 @@  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);
+    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 };
+        int 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);
+#endif
         munmap(map->address[i], map->length[i]);
     }
 
@@ -115,7 +123,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 +136,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,6 +164,7 @@  static int drm_map_frame(AVHWFramesContext *hwfc,
         map->length[i]  = desc->objects[i].size;
         map->object[i] = desc->objects[i].fd;
 
+#if HAVE_LINUX_DMA_BUF_H
         err = ioctl(desc->objects[i].fd, DMA_BUF_IOCTL_SYNC, &sync_start);
         if (err) {
             err = AVERROR(errno);
@@ -159,6 +172,7 @@  static int drm_map_frame(AVHWFramesContext *hwfc,
                    "%d: %d.\n", desc->objects[i].fd, errno);
             goto fail;
         }
+#endif
     }
     map->nb_regions = i;