From b819667f36ef252b6ab184d5c28b2fe28f9452f4 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Tue, 9 Apr 2019 20:07:05 +0900 Subject: [PATCH] hls: Make crypto dependency optional when hls-crypto is auto crypto libraries are not required for hlssink and hlssink2. Also, hlsdemux with nonencrypted stream can work without crpyto. Make an error only when users set "hls-crpyto" with non-auto option explicitly, but no crpyto library was found. --- configure.ac | 7 +---- ext/hls/gsthlsdemux.c | 26 ++++++++++++++++- ext/hls/gsthlsdemux.h | 4 +-- ext/hls/meson.build | 80 +++++++++++++++++++++++++-------------------------- 4 files changed, 68 insertions(+), 49 deletions(-) diff --git a/configure.ac b/configure.ac index 5362248..a730e82 100644 --- a/configure.ac +++ b/configure.ac @@ -2234,19 +2234,15 @@ AG_GST_CHECK_FEATURE(HLS, [http live streaming plugin], hls, [ ], [ dnl Try to find a valid crypto library + HAVE_HLS="yes" PKG_CHECK_MODULES(NETTLE, nettle, [ AC_DEFINE(HAVE_NETTLE, 1, [Define if nettle is available]) - HAVE_HLS="yes" ],[ AM_PATH_LIBGCRYPT([1.2.0], [ AC_DEFINE(HAVE_LIBGCRYPT, 1, [Define if libgcrypt is available]) - HAVE_HLS="yes" ],[ PKG_CHECK_MODULES(OPENSSL, openssl, [ AC_DEFINE(HAVE_OPENSSL, 1, [Define if openssl is available]) - HAVE_HLS="yes" - ],[ - HAVE_HLS="no" ]) ]) ]) @@ -2727,4 +2723,3 @@ AC_OUTPUT AG_GST_OUTPUT_PLUGINS ORC_OUTPUT - diff --git a/ext/hls/gsthlsdemux.c b/ext/hls/gsthlsdemux.c index 864b65b..efd135e 100644 --- a/ext/hls/gsthlsdemux.c +++ b/ext/hls/gsthlsdemux.c @@ -1738,7 +1738,7 @@ gst_hls_demux_stream_decrypt_end (GstHLSDemuxStream * stream) /* NOP */ } -#else +#elif defined(HAVE_LIBGCRYPT) static gboolean gst_hls_demux_stream_decrypt_start (GstHLSDemuxStream * stream, const guint8 * key_data, const guint8 * iv_data) @@ -1786,6 +1786,30 @@ gst_hls_demux_stream_decrypt_end (GstHLSDemuxStream * stream) stream->aes_ctx = NULL; } } + +#else +/* NO crypto available */ +static gboolean +gst_hls_demux_stream_decrypt_start (GstHLSDemuxStream * stream, + const guint8 * key_data, const guint8 * iv_data) +{ + GST_ERROR ("No crypto available"); + return FALSE; +} + +static gboolean +decrypt_fragment (GstHLSDemuxStream * stream, gsize length, + const guint8 * encrypted_data, guint8 * decrypted_data) +{ + GST_ERROR ("Cannot decrypt fragment, no crypto available"); + return FALSE; +} + +static void +gst_hls_demux_stream_decrypt_end (GstHLSDemuxStream * stream) +{ + return; +} #endif static GstBuffer * diff --git a/ext/hls/gsthlsdemux.h b/ext/hls/gsthlsdemux.h index 0cab196..529cd19 100644 --- a/ext/hls/gsthlsdemux.h +++ b/ext/hls/gsthlsdemux.h @@ -34,7 +34,7 @@ #elif defined(HAVE_NETTLE) #include #include -#else +#elif defined(HAVE_LIBGCRYPT) #include #endif @@ -108,7 +108,7 @@ struct _GstHLSDemuxStream # endif #elif defined(HAVE_NETTLE) struct CBC_CTX (struct aes_ctx, AES_BLOCK_SIZE) aes_ctx; -#else +#elif defined(HAVE_LIBGCRYPT) gcry_cipher_hd_t aes_ctx; #endif diff --git a/ext/hls/meson.build b/ext/hls/meson.build index 69597ac..4229140 100644 --- a/ext/hls/meson.build +++ b/ext/hls/meson.build @@ -13,52 +13,52 @@ hls_cargs = ['-DGST_USE_UNSTABLE_API'] hls_crypto = get_option('hls-crypto') hls_option = get_option('hls') -have_hls_crypto = false -if not hls_option.disabled() - if ['auto', 'nettle'].contains(hls_crypto) - hls_crypto_dep = dependency('nettle', required : false) - if hls_crypto_dep.found() - have_hls_crypto = true - hls_cargs += ['-DHAVE_NETTLE'] - endif - endif +hls_crypto_dep = dependency('', required : false) + +if hls_option.disabled() + subdir_done() +endif - if not have_hls_crypto and ['auto', 'libgcrypt'].contains(hls_crypto) - hls_crypto_dep = cc.find_library('gcrypt', required : false) - if hls_crypto_dep.found() - have_hls_crypto = true - hls_cargs += ['-DHAVE_LIBGCRYPT'] - endif +if ['auto', 'nettle'].contains(hls_crypto) + hls_crypto_dep = dependency('nettle', required : false) + if hls_crypto_dep.found() + hls_cargs += ['-DHAVE_NETTLE'] endif +endif - if not have_hls_crypto and ['auto', 'openssl'].contains(hls_crypto) - hls_crypto_dep = dependency('openssl', required : false) - if hls_crypto_dep.found() - have_hls_crypto = true - hls_cargs += ['-DHAVE_OPENSSL'] - endif +if not hls_crypto_dep.found() and ['auto', 'libgcrypt'].contains(hls_crypto) + hls_crypto_dep = cc.find_library('gcrypt', required : false) + if hls_crypto_dep.found() + hls_cargs += ['-DHAVE_LIBGCRYPT'] endif +endif - if not have_hls_crypto and hls_option.enabled() - if hls_crypto == 'auto' - error('HLS plugin enabled, but found none of nettle, libgcrypt, or openssl') - else - error('HLS plugin enabled, but crypto library "@0@" not found'.format(hls_crypto)) - endif +if not hls_crypto_dep.found() and ['auto', 'openssl'].contains(hls_crypto) + hls_crypto_dep = dependency('openssl', required : false) + if hls_crypto_dep.found() + hls_cargs += ['-DHAVE_OPENSSL'] endif endif -if have_hls_crypto - gsthls = library('gsthls', - hls_sources, - c_args : gst_plugins_bad_args + hls_cargs, - link_args : noseh_link_args, - include_directories : [configinc], - dependencies : [gstpbutils_dep, gsttag_dep, gstvideo_dep, - gstadaptivedemux_dep, gsturidownloader_dep, - hls_crypto_dep, libm], - install : true, - install_dir : plugins_install_dir, - ) - pkgconfig.generate(gsthls, install_dir : plugins_pkgconfig_install_dir) +if not hls_crypto_dep.found() + if hls_crypto == 'auto' + message('Enable HLS plugin enable without crypto') + elif hls_option.enabled() + error('HLS plugin enabled with crypto, but crypto library "@0@" not found'.format(hls_crypto)) + else + subdir_done() + endif endif + +gsthls = library('gsthls', + hls_sources, + c_args : gst_plugins_bad_args + hls_cargs, + link_args : noseh_link_args, + include_directories : [configinc], + dependencies : [gstpbutils_dep, gsttag_dep, gstvideo_dep, + gstadaptivedemux_dep, gsturidownloader_dep, + hls_crypto_dep, libm], + install : true, + install_dir : plugins_install_dir, +) +pkgconfig.generate(gsthls, install_dir : plugins_pkgconfig_install_dir) -- 2.7.4