avdevice/lavfi: allow non-mmappable files for graph_file

Use av_bprint_fd_contents() instead of av_file_map()

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Andrey Utkin 2014-07-03 14:37:09 +03:00 committed by Michael Niedermayer
parent fcd1f6bc9d
commit 2229a6dfe6
1 changed files with 17 additions and 16 deletions

View File

@ -26,6 +26,8 @@
/* #define DEBUG */ /* #define DEBUG */
#include <float.h> /* DBL_MIN, DBL_MAX */ #include <float.h> /* DBL_MIN, DBL_MAX */
#include <fcntl.h> /* O_RDONLY */
#include <unistd.h> /* close() */
#include "libavutil/bprint.h" #include "libavutil/bprint.h"
#include "libavutil/channel_layout.h" #include "libavutil/channel_layout.h"
@ -115,23 +117,22 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx)
} }
if (lavfi->graph_filename) { if (lavfi->graph_filename) {
uint8_t *file_buf, *graph_buf; AVBPrint graph_file_pb;
size_t file_bufsize; int fd = avpriv_open(lavfi->graph_filename, O_RDONLY);
ret = av_file_map(lavfi->graph_filename, if (fd == -1)
&file_buf, &file_bufsize, 0, avctx); FAIL(AVERROR(EINVAL));
if (ret < 0) av_bprint_init(&graph_file_pb, 0, AV_BPRINT_SIZE_UNLIMITED);
goto end; ret = av_bprint_fd_contents(&graph_file_pb, fd);
av_bprint_chars(&graph_file_pb, '\0', 1);
/* create a 0-terminated string based on the read file */ close(fd);
graph_buf = av_malloc(file_bufsize + 1); if (!ret && !av_bprint_is_complete(&graph_file_pb))
if (!graph_buf) { ret = AVERROR(ENOMEM);
av_file_unmap(file_buf, file_bufsize); if (ret) {
FAIL(AVERROR(ENOMEM)); av_bprint_finalize(&graph_file_pb, NULL);
FAIL(ret);
} }
memcpy(graph_buf, file_buf, file_bufsize); if ((ret = av_bprint_finalize(&graph_file_pb, &lavfi->graph_str)))
graph_buf[file_bufsize] = 0; FAIL(ret);
av_file_unmap(file_buf, file_bufsize);
lavfi->graph_str = graph_buf;
} }
if (!lavfi->graph_str) if (!lavfi->graph_str)