diff --git a/src/lib/crypto/MD5.cxx b/src/lib/crypto/MD5.cxx index 3e2cba445..720cea2f4 100644 --- a/src/lib/crypto/MD5.cxx +++ b/src/lib/crypto/MD5.cxx @@ -28,20 +28,38 @@ */ #include "MD5.hxx" +#include "util/HexFormat.hxx" +#include "config.h" + +#ifdef HAVE_LIBAVUTIL +extern "C" { +#include +} +#else #include "lib/gcrypt/MD5.hxx" #include "lib/gcrypt/Init.hxx" -#include "util/HexFormat.hxx" +#endif void GlobalInitMD5() noexcept { +#ifdef HAVE_LIBAVUTIL + /* no initialization necessary */ +#else Gcrypt::Init(); +#endif } std::array MD5(ConstBuffer input) noexcept { +#ifdef HAVE_LIBAVUTIL + std::array result; + av_md5_sum(&result.front(), (const uint8_t *)input.data, input.size); + return result; +#else return Gcrypt::MD5(input); +#endif } StringBuffer<33> diff --git a/src/lib/crypto/meson.build b/src/lib/crypto/meson.build index da543a2be..f3a99cb86 100644 --- a/src/lib/crypto/meson.build +++ b/src/lib/crypto/meson.build @@ -1,9 +1,10 @@ -if gcrypt_dep.found() +if libavutil_dep.found() or gcrypt_dep.found() crypto_md5 = static_library( 'crypto_md5', 'MD5.cxx', include_directories: inc, dependencies: [ + libavutil_dep, gcrypt_dep, ], ) diff --git a/src/lib/ffmpeg/meson.build b/src/lib/ffmpeg/meson.build index 3db5b1a8f..0a0217ccf 100644 --- a/src/lib/ffmpeg/meson.build +++ b/src/lib/ffmpeg/meson.build @@ -1,6 +1,7 @@ libavformat_dep = dependency('libavformat', version: '>= 57.40', required: get_option('ffmpeg')) libavcodec_dep = dependency('libavcodec', version: '>= 57.48', required: get_option('ffmpeg')) libavutil_dep = dependency('libavutil', version: '>= 55.27', required: get_option('ffmpeg')) +conf.set('HAVE_LIBAVUTIL', libavutil_dep.found()) enable_ffmpeg = libavformat_dep.found() and libavcodec_dep.found() and libavutil_dep.found() conf.set('ENABLE_FFMPEG', enable_ffmpeg) diff --git a/src/lib/gcrypt/meson.build b/src/lib/gcrypt/meson.build index 5840bfe4d..b7006b6db 100644 --- a/src/lib/gcrypt/meson.build +++ b/src/lib/gcrypt/meson.build @@ -1,3 +1,10 @@ +if libavutil_dep.found() + # if we have FFmpeg, we can use its MD5 implementation and we don't + # need libgcrypt + gcrypt_dep = dependency('', required: false) + subdir_done() +endif + # Since version 0.49.0 Meson has native libgcrypt dependency support, which has # the advantage over find_library() as it uses libgcrypt-config to query the # required linker flags.