From 177c2c741b521469b75d180e380429bf29ce5fe4 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 7 Aug 2016 10:55:19 -0400 Subject: [PATCH 1/2] Fixes #1584. I've just copied the relevant functions from ffmpeg source. Please review carefully before merging. --- src/zm_ffmpeg.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++ src/zm_ffmpeg.h | 11 ++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index e7c9edbef..1874459f8 100644 --- a/src/zm_ffmpeg.cpp +++ b/src/zm_ffmpeg.cpp @@ -69,6 +69,55 @@ enum _AVPIXELFORMAT GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subp return pf; } +/* The following is copied directly from newer ffmpeg. */ +#if LIBAVUTIL_VERSION_CHECK(52, 6, 0, 6, 0) +#else +static int parse_key_value_pair(AVDictionary **pm, const char **buf, + const char *key_val_sep, const char *pairs_sep, + int flags) +{ + char *key = av_get_token(buf, key_val_sep); + char *val = NULL; + int ret; + + if (key && *key && strspn(*buf, key_val_sep)) { + (*buf)++; + val = av_get_token(buf, pairs_sep); + } + + if (key && *key && val && *val) + ret = av_dict_set(pm, key, val, flags); + else + ret = AVERROR(EINVAL); + + av_freep(&key); + av_freep(&val); + + return ret; +} +int av_dict_parse_string(AVDictionary **pm, const char *str, + const char *key_val_sep, const char *pairs_sep, + int flags) + { + int ret; + + if (!str) + return 0; + + /* ignore STRDUP flags */ + flags &= ~(AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL); + + while (*str) { + if ((ret = parse_key_value_pair(pm, &str, key_val_sep, pairs_sep, flags)) < 0) + return ret; + + if (*str) + str++; + } + + return 0; + } +#endif #endif // HAVE_LIBAVUTIL #if HAVE_LIBSWSCALE && HAVE_LIBAVUTIL @@ -240,4 +289,5 @@ int SWScale::ConvertDefaults(const uint8_t* in_buffer, const size_t in_buffer_si } #endif // HAVE_LIBSWSCALE && HAVE_LIBAVUTIL + #endif // HAVE_LIBAVCODEC || HAVE_LIBAVUTIL || HAVE_LIBSWSCALE diff --git a/src/zm_ffmpeg.h b/src/zm_ffmpeg.h index 894408437..d727da7a4 100644 --- a/src/zm_ffmpeg.h +++ b/src/zm_ffmpeg.h @@ -32,6 +32,7 @@ extern "C" { #include #include #include +#include /* LIBAVUTIL_VERSION_CHECK checks for the right version of libav and FFmpeg * The original source is vlc (in modules/codec/avcodec/avcommon_compat.h) @@ -274,7 +275,15 @@ protected: #undef av_err2str #define av_err2str(errnum) av_make_error_string(errnum).c_str() - #endif // __cplusplus + /* The following is copied directly from newer ffmpeg */ + #if LIBAVUTIL_VERSION_CHECK(52, 6, 0, 0, 0) + #else + int av_dict_parse_string(AVDictionary **pm, const char *str, + const char *key_val_sep, const char *pairs_sep, + int flags); + #endif + +#endif // __cplusplus #endif // ( HAVE_LIBAVUTIL_AVUTIL_H || HAVE_LIBAVCODEC_AVCODEC_H || HAVE_LIBAVFORMAT_AVFORMAT_H || HAVE_LIBAVDEVICE_AVDEVICE_H ) From 3f713df8264baf6a1c187e1a864ff323152b5e18 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 9 Aug 2016 13:14:10 -0400 Subject: [PATCH 2/2] bump libavutil version check as per @SteveGilvarry --- src/zm_ffmpeg.cpp | 2 +- src/zm_ffmpeg.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index 1874459f8..def7ef0c3 100644 --- a/src/zm_ffmpeg.cpp +++ b/src/zm_ffmpeg.cpp @@ -70,7 +70,7 @@ enum _AVPIXELFORMAT GetFFMPEGPixelFormat(unsigned int p_colours, unsigned p_subp return pf; } /* The following is copied directly from newer ffmpeg. */ -#if LIBAVUTIL_VERSION_CHECK(52, 6, 0, 6, 0) +#if LIBAVUTIL_VERSION_CHECK(52, 7, 0, 17, 100) #else static int parse_key_value_pair(AVDictionary **pm, const char **buf, const char *key_val_sep, const char *pairs_sep, diff --git a/src/zm_ffmpeg.h b/src/zm_ffmpeg.h index d727da7a4..f1486c2ee 100644 --- a/src/zm_ffmpeg.h +++ b/src/zm_ffmpeg.h @@ -276,7 +276,7 @@ protected: #define av_err2str(errnum) av_make_error_string(errnum).c_str() /* The following is copied directly from newer ffmpeg */ - #if LIBAVUTIL_VERSION_CHECK(52, 6, 0, 0, 0) + #if LIBAVUTIL_VERSION_CHECK(52, 7, 0, 17, 100) #else int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep,