shithub: sox

Download patch

ref: 581b885091127f14506e3ced5b8c8d1488195524
parent: a45ef1d2e89d59bd27456b3a01eb4d7f88e4d35d
author: robs <robs>
date: Wed May 13 14:35:37 EDT 2009

further step towards dl mp3

--- a/src/mp3.c
+++ b/src/mp3.c
@@ -1,3 +1,8 @@
+#if 0
+#define DL_MAD
+#define DL_LAME
+#endif
+
 /* MP3 support for SoX
  *
  * Uses libmad for MP3 decoding
@@ -35,11 +40,6 @@
 #endif
 #endif
 
-#if 0
-#define DL_MAD
-#define DL_LAME
-#endif
-
 #define INPUT_BUFFER_SIZE       (sox_globals.bufsiz)
 
 /* Private data */
@@ -228,7 +228,8 @@
     } \
     p->x = ltptr.fn;
   union {void (* fn)(); lt_ptr ptr;} ltptr;
-  p->mad_lth = lt_dlopenext("libmad");
+  if (!lt_dlinit())
+    p->mad_lth = lt_dlopenext("libmad");
   if (!p->mad_lth) {
     lsx_fail("could not find " DL_LIB_NAME ")");
     return SOX_EOF;
@@ -436,7 +437,8 @@
 
   free(p->InputBuffer);
 #if defined HAVE_LIBLTDL && defined DL_MAD
-  lt_dlclose(p->mad_lth);
+  if (!lt_dlclose(p->mad_lth))
+    lt_dlexit();
 #endif
   return SOX_SUCCESS;
 }
@@ -468,8 +470,9 @@
       return SOX_EOF; \
     } \
     p->x = ltptr.fn;
-  union {void (* fn)(); lt_ptr ptr;} ltptr;
-  p->lame_lth = lt_dlopenext("libmp3lame");
+  union {int (* fn)(); lt_ptr ptr;} ltptr;
+  if (!lt_dlinit())
+    p->lame_lth = lt_dlopenext("libmp3lame");
   if (!p->lame_lth) {
     lsx_fail("could not find " DL_LIB_NAME ")");
     return SOX_EOF;
@@ -629,8 +632,9 @@
     lsx_fail_errno(ft, SOX_EOF, "File write failed");
 
   p->lame_close(p->gfp);
-#if defined HAVE_LIBLTDL && defined DL_MAD
-  lt_dlclose(p->lame_lth);
+#if defined HAVE_LIBLTDL && defined DL_LAME
+  if (!lt_dlclose(p->lame_lth))
+    lt_dlexit();
 #endif
   return SOX_SUCCESS;
 }