hls: Make crypto dependency optional when hls-crypto is auto
authorSeungha Yang <seungha.yang@navercorp.com>
Tue, 9 Apr 2019 11:07:05 +0000 (20:07 +0900)
committerXavier Claessens <xavier.claessens@collabora.com>
Mon, 9 Sep 2019 13:15:34 +0000 (09:15 -0400)
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
ext/hls/gsthlsdemux.c
ext/hls/gsthlsdemux.h
ext/hls/meson.build

index 5362248..a730e82 100644 (file)
@@ -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
-
index 864b65b..efd135e 100644 (file)
@@ -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 *
index 0cab196..529cd19 100644 (file)
@@ -34,7 +34,7 @@
 #elif defined(HAVE_NETTLE)
 #include <nettle/aes.h>
 #include <nettle/cbc.h>
-#else
+#elif defined(HAVE_LIBGCRYPT)
 #include <gcrypt.h>
 #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
 
index 69597ac..4229140 100644 (file)
@@ -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)