aboutsummaryrefslogtreecommitdiffstats
path: root/libavdevice
diff options
context:
space:
mode:
authorAndrey Utkin <andrey.krieger.utkin@gmail.com>2014-07-23 16:12:39 +0300
committerMichael Niedermayer <michaelni@gmx.at>2014-07-23 18:42:41 +0200
commitb6a6459a24c6279502abeae064c28c1187fd0b0f (patch)
tree9b6eb3d92cfa8b8b44e6dee8523afc3dd8b3f0de /libavdevice
parent8a4c0866dc7d718b5ee3f0af60d4317cd133d83f (diff)
downloadffmpeg-b6a6459a24c6279502abeae064c28c1187fd0b0f.tar.gz
lavd/lavfi: work with non-mappable files for graph_file option
Example of non-mappable file is /dev/stdin. Previously passing it as graph_file value returned error. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavdevice')
-rw-r--r--libavdevice/lavfi.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c
index d1904dd70b..f1c88ac610 100644
--- a/libavdevice/lavfi.c
+++ b/libavdevice/lavfi.c
@@ -115,23 +115,23 @@ 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);
+ AVBPrint graph_file_pb;
+ AVIOContext *avio = NULL;
+ ret = avio_open(&avio, lavfi->graph_filename, AVIO_FLAG_READ);
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));
+ FAIL(ret);
+ av_bprint_init(&graph_file_pb, 0, AV_BPRINT_SIZE_UNLIMITED);
+ ret = avio_read_to_bprint(avio, &graph_file_pb, INT_MAX);
+ avio_close(avio);
+ av_bprint_chars(&graph_file_pb, '\0', 1);
+ 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)