[FFmpeg-cvslog] avdevice/lavfi: allow non-mmappable files for graph_file
Andrey Utkin
git at videolan.org
Mon Jul 7 21:40:16 CEST 2014
ffmpeg | branch: master | Andrey Utkin <andrey.krieger.utkin at gmail.com> | Thu Jul 3 14:37:09 2014 +0300| [2229a6dfe66fd73126082bdf83c388ee4ea2c879] | committer: Michael Niedermayer
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 at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2229a6dfe66fd73126082bdf83c388ee4ea2c879
---
libavdevice/lavfi.c | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index d1904dd..9be2d0e 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,22 @@ 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));
+ 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);
}
- 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 ((ret = av_bprint_finalize(&graph_file_pb, &lavfi->graph_str)))
+ FAIL(ret);
}
if (!lavfi->graph_str)
More information about the ffmpeg-cvslog
mailing list