]> git.sesse.net Git - ffmpeg/blobdiff - libavdevice/lavfi.c
Merge commit 'eba2233b58c2c4b468c58287d6537b2f1188a8cd'
[ffmpeg] / libavdevice / lavfi.c
index 4fc09d86c889b120e283621927c16e8147d9980b..d1904dd70b31b4060a3036287fe49e9516b6bdba 100644 (file)
@@ -26,7 +26,6 @@
 /* #define DEBUG */
 
 #include <float.h>              /* DBL_MIN, DBL_MAX */
-#include <fcntl.h>              /* O_RDONLY */
 
 #include "libavutil/bprint.h"
 #include "libavutil/channel_layout.h"
 #include "libavformat/internal.h"
 #include "avdevice.h"
 
-#if HAVE_UNISTD_H
-#include <unistd.h>             /* close() */
-#endif
-#if HAVE_IO_H
-#include <io.h>
-#endif
-
 typedef struct {
     AVClass *class;          ///< class for private options
     char          *graph_str;
@@ -123,22 +115,23 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx)
     }
 
     if (lavfi->graph_filename) {
-        AVBPrint graph_file_pb;
-        int fd = avpriv_open(lavfi->graph_filename, O_RDONLY);
-        if (fd == -1)
-            FAIL(AVERROR(EINVAL));
-        av_bprint_init(&graph_file_pb, 0, AV_BPRINT_SIZE_UNLIMITED);
-        ret = av_bprint_fd_contents(&graph_file_pb, fd);
-        av_bprint_chars(&graph_file_pb, '\0', 1);
-        close(fd);
-        if (!ret && !av_bprint_is_complete(&graph_file_pb))
-            ret = AVERROR(ENOMEM);
-        if (ret) {
-            av_bprint_finalize(&graph_file_pb, NULL);
-            FAIL(ret);
+        uint8_t *file_buf, *graph_buf;
+        size_t file_bufsize;
+        ret = av_file_map(lavfi->graph_filename,
+                          &file_buf, &file_bufsize, 0, avctx);
+        if (ret < 0)
+            goto end;
+
+        /* create a 0-terminated string based on the read file */
+        graph_buf = av_malloc(file_bufsize + 1);
+        if (!graph_buf) {
+            av_file_unmap(file_buf, file_bufsize);
+            FAIL(AVERROR(ENOMEM));
         }
-        if ((ret = av_bprint_finalize(&graph_file_pb, &lavfi->graph_str)))
-            FAIL(ret);
+        memcpy(graph_buf, file_buf, file_bufsize);
+        graph_buf[file_bufsize] = 0;
+        av_file_unmap(file_buf, file_bufsize);
+        lavfi->graph_str = graph_buf;
     }
 
     if (!lavfi->graph_str)