MSVC does not allow passing file pointers between libs This API can thus not work with MSVC and as it was very recently added and its it was in no release its removial should not cause any problems
Found-by: Hendrik Leppkes <h.lepp...@gmail.com> Signed-off-by: Michael Niedermayer <michae...@gmx.at> --- libavdevice/lavfi.c | 39 ++++++++++++++++----------------------- libavutil/bprint.c | 24 ------------------------ libavutil/bprint.h | 7 ------- 3 files changed, 16 insertions(+), 54 deletions(-) diff --git a/libavdevice/lavfi.c b/libavdevice/lavfi.c index 4fc09d8..d1904dd 100644 --- a/libavdevice/lavfi.c +++ b/libavdevice/lavfi.c @@ -26,7 +26,6 @@ /* #define DEBUG */ #include <float.h> /* DBL_MIN, DBL_MAX */ -#include <fcntl.h> /* O_RDONLY */ #include "libavutil/bprint.h" #include "libavutil/channel_layout.h" @@ -42,13 +41,6 @@ #include "libavformat/internal.h" #include "avdevice.h" -#if HAVE_UNISTD_H -#include <unistd.h> /* close() */ -#endif -#if HAVE_IO_H -#include <io.h> -#endif - typedef struct { AVClass *class; ///< class for private options char *graph_str; @@ -123,22 +115,23 @@ av_cold static int lavfi_read_header(AVFormatContext *avctx) } if (lavfi->graph_filename) { - 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); + 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)); } - if ((ret = av_bprint_finalize(&graph_file_pb, &lavfi->graph_str))) - 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 (!lavfi->graph_str) diff --git a/libavutil/bprint.c b/libavutil/bprint.c index 325ff17..0a0d078 100644 --- a/libavutil/bprint.c +++ b/libavutil/bprint.c @@ -30,14 +30,6 @@ #include "error.h" #include "mem.h" -#if HAVE_IO_H -#include <io.h> -#endif -#if HAVE_UNISTD_H -#include <unistd.h> -#endif - - #define av_bprint_room(buf) ((buf)->size - FFMIN((buf)->len, (buf)->size)) #define av_bprint_is_allocated(buf) ((buf)->str != (buf)->reserved_internal_buffer) @@ -312,22 +304,6 @@ void av_bprint_escape(AVBPrint *dstbuf, const char *src, const char *special_cha } } -int av_bprint_fd_contents(AVBPrint *pb, int fd) -{ - int ret; - char buf[1024]; - while (1) { - ret = read(fd, buf, sizeof(buf)); - if (!ret) - return 0; - else if (ret < 0) - return AVERROR(errno); - av_bprint_append_data(pb, buf, ret); - if (!av_bprint_is_complete(pb)) - return AVERROR(ENOMEM); - } -} - #ifdef TEST #undef printf diff --git a/libavutil/bprint.h b/libavutil/bprint.h index 1b23b9f..839ec1e 100644 --- a/libavutil/bprint.h +++ b/libavutil/bprint.h @@ -213,11 +213,4 @@ int av_bprint_finalize(AVBPrint *buf, char **ret_str); void av_bprint_escape(AVBPrint *dstbuf, const char *src, const char *special_chars, enum AVEscapeMode mode, int flags); -/** - * Read contents of fd into print buffer up to EOF. - * - * @return 0 for success, error code otherwise - */ -int av_bprint_fd_contents(AVBPrint *pb, int fd); - #endif /* AVUTIL_BPRINT_H */ -- 1.7.9.5 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel