Add DRM compile flags master
authorDavid Huang <d-huang@ti.com>
Thu, 12 Sep 2019 20:10:34 +0000 (15:10 -0500)
committerDavid Huang <d-huang@ti.com>
Fri, 13 Sep 2019 18:05:28 +0000 (13:05 -0500)
Signed-off-by: David Huang <d-huang@ti.com>
Makefile.am
main.c

index 3c91449a7ccd343f810e8d718e27cacba40de936..a764bd70f16827d882ddc97083ce8026e4abe3e6 100644 (file)
@@ -17,7 +17,7 @@
 bin_PROGRAMS = tidec_decode
 
 LDADD_COMMON = @DRM_LIBS@
-AM_CFLAGS = @DRM_CFLAGS@ @WARN_CFLAGS@ -I$(top_srcdir)/util
+AM_CFLAGS = @DRM_CFLAGS@ @WARN_CFLAGS@ -I$(top_srcdir)/util -DDRMMODE -DDRM
 LDFLAGS = -lm -lavcodec -lavutil -lavformat -lswresample -lbz2 -lz -llzma -ltheoraenc -ltheoradec -logg
 
 tidec_decode_SOURCES = main.c demux.c
diff --git a/main.c b/main.c
index f5d1583f5303d4856aadf200f18b55d07a82cb5b..dd4d3ad3ca5dadc3368156a43eeaf47a39982a95 100644 (file)
--- a/main.c
+++ b/main.c
@@ -16,6 +16,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <assert.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <linux/videodev2.h>
 #include <linux/v4l2-controls.h>
 
-#include <drm.h>
-#include <xf86drm.h>
+#ifdef DRMMODE
 #include <xf86drmMode.h>
-#include <drm_fourcc.h>
+#else
+#ifdef DRM
+#include <drm.h>
+#endif /* DRM */
+#endif /* DRMMODE */
 
 #include "demux.h"
 
@@ -746,7 +750,9 @@ static int mainloop(int fd, int rdfd, int wrfd,
 static void uninit_device(int fd, struct buffer outbufs[],
                struct buffer capbufs[], int *n_outbufs, int *n_capbufs, int usedrmbuff)
 {
+#ifdef DRM
        struct drm_mode_destroy_dumb gem_destroy;
+#endif
        int i, ret = 0;
        struct v4l2_event_subscription sub;
 
@@ -773,6 +779,7 @@ static void uninit_device(int fd, struct buffer outbufs[],
                        }
                }
        } else {
+#ifdef DRM
                /* Using drm bufffers for capture */
                for (i = 0; i < *n_capbufs; i++) {
                        debug_printf("[fd%d] munmap capbuf %d mapped=0x%p length=%d\n", fd, i, capbufs[i].mapped, capbufs[i].length);
@@ -788,6 +795,7 @@ static void uninit_device(int fd, struct buffer outbufs[],
                        if (ret)
                                printf("    DRM_IOCTL_MODE_DESTROY_DUMB failed\n");
                }
+#endif
        }
 
        memset(&sub, 0, sizeof(sub));
@@ -801,6 +809,7 @@ static void uninit_device(int fd, struct buffer outbufs[],
        }
 }
 
+#ifdef DRM
 static int create_drm_buffer(struct buffer *b,
        unsigned int width, unsigned int height)
 {
@@ -859,6 +868,7 @@ fail_gem:
 
        return ret;
 }
+#endif
 
 int stream_framelevel_parsing(struct stream_context *str, char *input_file, int max_frames)
 {
@@ -1244,6 +1254,7 @@ static int init_device(int fd, int rdfd,
                }
                }
        } else {
+#ifdef DRM
                debug_printf("[fd%d] Setup decoding CAPTURE with VIDIOC_REQBUFS\n", fd);
                debug_printf("[fd%d] buffer(y) size %u buffer(uv) size %u\n",
                                fd, fmt.fmt.pix_mp.plane_fmt[0].sizeimage,
@@ -1278,6 +1289,10 @@ static int init_device(int fd, int rdfd,
                        debug_printf("[fd%d] Create_DRM_BUFFERS drm_y_buffer[%d].dbuf_fd 0x%x, length %d offset %d\n",
                                        fd, i, capbufs[i].dbuf_fd, capbufs[i].length, capbufs[i].offset);
                }
+#else
+               printf("Cannot allocate DRM buffers\n");
+               return -1;
+#endif
        }
        return ret;
 }
@@ -1434,11 +1449,13 @@ int main(int argc, char **argv)
        char input_file[256];
        char output_file_base[120];
        char output_file[128];
-       const char *dir_path = "/dev/dri/";
        char drm_file_name[20];
+#ifdef DRMMODE
+       const char *dir_path = "/dev/dri/";
        DIR *d;
        struct dirent *dir;
        drmModeResPtr res;
+#endif
        int max_frames = -1;
        int enable_prof = 0;
        int sleep_time = 0;
@@ -1549,12 +1566,18 @@ int main(int argc, char **argv)
                printf("\nUsing v4l2 for capture buffers\n");
        } else {
                if (strlen(drm_file_name) > 0) {
+#ifdef DRM
                        drmfd1 = open(drm_file_name, O_CLOEXEC);
                        if (drmfd1 < 0) {
                                printf("Failed to open drm device\n");
                                return EXIT_FAILURE;
                        }
+#else
+                       printf("DRM not supported with current build arguments\n");
+                       return EXIT_FAILURE;
+#endif
                } else {
+#ifdef DRMMODE
                        d = opendir(dir_path);
                        if (!d) {
                                printf("Failed to open drm device directory\n");
@@ -1584,6 +1607,10 @@ int main(int argc, char **argv)
                                        drmfd1 = -1;
                                }
                        }
+#else
+                       printf("Can't search DRM directory\n");
+                       return EXIT_FAILURE;
+#endif
                }
                if (drmfd1 < 0) {
                        printf("Failed to open drm device\n");