[PATCH] avutil & avdevice: remove av_bprint_fd_contents()
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.leppkes@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@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
On 7/13/2014 3:01 PM, Michael Niedermayer wrote:
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.leppkes@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavdevice/lavfi.c | 39 ++++++++++++++++----------------------- libavutil/bprint.c | 24 ------------------------ libavutil/bprint.h | 7 ------- 3 files changed, 16 insertions(+), 54 deletions(-)
Could something like an AVIO-style read callback work? - Derek
On Sun, Jul 13, 2014 at 04:54:00PM +0100, Derek Buitenhuis wrote:
On 7/13/2014 3:01 PM, Michael Niedermayer wrote:
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.leppkes@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavdevice/lavfi.c | 39 ++++++++++++++++----------------------- libavutil/bprint.c | 24 ------------------------ libavutil/bprint.h | 7 ------- 3 files changed, 16 insertions(+), 54 deletions(-)
Could something like an AVIO-style read callback work?
probably yes but id like to remove thi file descriptor based API before the relase so noone has to hit the same msvc issue [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Many that live deserve death. And some that die deserve life. Can you give it to them? Then do not be too eager to deal out death in judgement. For even the very wise cannot see all ends. -- Gandalf
On 7/13/2014 5:21 PM, Michael Niedermayer wrote:
but id like to remove thi file descriptor based API before the relase so noone has to hit the same msvc issue
I am OK with it, but others may want to comment, particularly its author. - Derek
On Sun, Jul 13, 2014 at 04:01:05PM +0200, Michael Niedermayer wrote:
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.leppkes@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at> --- libavdevice/lavfi.c | 39 ++++++++++++++++----------------------- libavutil/bprint.c | 24 ------------------------ libavutil/bprint.h | 7 ------- 3 files changed, 16 insertions(+), 54 deletions(-)
an alternative suggestion or after this patch would be to switch to passing a filename string instead of a int fd and treat "" as stdin andrey, whats your oppinion about that ? also if you like the suggestion, do you have time to make that change ? Thanks [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I do not agree with what you have to say, but I'll defend to the death your right to say it. -- Voltaire
Le sextidi 26 messidor, an CCXXII, Michael Niedermayer a écrit :
an alternative suggestion or after this patch would be to switch to passing a filename string instead of a int fd and treat "" as stdin
"-" for stdin is more standard. Otherwise, it would be completely consistent with the av_file_map() function it intends to replace. But the name must be updated at the same time as the API. Regards, -- Nicolas George
On Sun, Jul 13, 2014 at 04:01:05PM +0200, Michael Niedermayer wrote:
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.leppkes@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Applied so i dont need to keep it in the back of my head that i need to apply this before the release if no other solution has been commited [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB I have often repented speaking, but never of holding my tongue. -- Xenocrates
participants (3)
-
Derek Buitenhuis -
Michael Niedermayer -
Nicolas George