mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-03-01 10:11:01 +00:00
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>
This commit is contained in:
parent
8a4c0866dc
commit
b6a6459a24
@ -115,23 +115,23 @@ 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;
|
AVIOContext *avio = NULL;
|
||||||
ret = av_file_map(lavfi->graph_filename,
|
ret = avio_open(&avio, lavfi->graph_filename, AVIO_FLAG_READ);
|
||||||
&file_buf, &file_bufsize, 0, avctx);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto end;
|
FAIL(ret);
|
||||||
|
av_bprint_init(&graph_file_pb, 0, AV_BPRINT_SIZE_UNLIMITED);
|
||||||
/* create a 0-terminated string based on the read file */
|
ret = avio_read_to_bprint(avio, &graph_file_pb, INT_MAX);
|
||||||
graph_buf = av_malloc(file_bufsize + 1);
|
avio_close(avio);
|
||||||
if (!graph_buf) {
|
av_bprint_chars(&graph_file_pb, '\0', 1);
|
||||||
av_file_unmap(file_buf, file_bufsize);
|
if (!ret && !av_bprint_is_complete(&graph_file_pb))
|
||||||
FAIL(AVERROR(ENOMEM));
|
ret = AVERROR(ENOMEM);
|
||||||
|
if (ret) {
|
||||||
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user