[FFmpeg-devel] [PATCH 2/2] lavfi indev: use av_fd_dump() instead of av_file_map() for graph_file
Andrey Utkin
andrey.krieger.utkin at gmail.com
Tue Jun 24 15:27:28 CEST 2014
---
libavdevice/lavfi.c | 31 ++++++++++++++-----------------
1 file changed, 14 insertions(+), 17 deletions(-)
diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index d1904dd..4179aaf 100644
--- a/libavdevice/lavfi.c
+++ b/libavdevice/lavfi.c
@@ -26,6 +26,8 @@
/* #define DEBUG */
#include <float.h> /* DBL_MIN, DBL_MAX */
+#include <fcntl.h> /* O_RDONLY */
+#include <unistd.h> /* close() */
#include "libavutil/bprint.h"
#include "libavutil/channel_layout.h"
@@ -115,23 +117,18 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx)
}
if (lavfi->graph_filename) {
- 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));
- }
- memcpy(graph_buf, file_buf, file_bufsize);
- graph_buf[file_bufsize] = 0;
- av_file_unmap(file_buf, file_bufsize);
- lavfi->graph_str = graph_buf;
+ size_t file_length;
+ int fd = avpriv_open(lavfi->graph_filename, O_RDONLY);
+ if (fd == -1)
+ FAIL(AVERROR(EINVAL));
+ file_length = 0;
+ lavfi->graph_str = NULL;
+ ret = av_fd_dump(fd, (uint8_t**)&lavfi->graph_str, &file_length,
+ 1, 1024);
+ close(fd);
+ if (ret)
+ FAIL(ret);
+ lavfi->graph_str[file_length] = '\0';
}
if (!lavfi->graph_str)
--
1.8.3.2
More information about the ffmpeg-devel
mailing list