ref: 1d3a39e1c03d86d83b155218307eebb3811398f9
parent: bc9c3c01bc7fa51d6d816fb6174a85ce531ee804
author: robs <robs>
date: Wed Oct 1 03:49:09 EDT 2008
merge in magic branch
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -75,6 +75,7 @@
if (NOT HAVE_LAME_LAME_H)
optional(HAVE_LAME_LAME_H lame.h mp3lame lame_init mp3)
endif (NOT HAVE_LAME_LAME_H)
+optional(HAVE_MAGIC magic.h magic magic_open "")
optional(HAVE_PNG png.h png png_set_rows spectrogram)
optional(HAVE_SAMPLERATE_H samplerate.h samplerate src_simple rabbit)
optional(HAVE_SNDFILE sndfile.h sndfile sf_open sndfile)
--- a/ChangeLog
+++ b/ChangeLog
@@ -98,6 +98,7 @@
o Updates to internal effects chain API. (cbagwell)
o Retire old FFT routines (speeds up `noisered' effect). (robs)
o Allow effects to use getopt. (robs)
+ o Use libmagic for mp3. (robs)
sox-14.1.0 2008-7-29
--- a/configure.ac
+++ b/configure.ac
@@ -349,6 +349,26 @@
AM_CONDITIONAL(HAVE_FFMPEG, test x$using_ffmpeg = xyes)
AC_SUBST(FFMPEG_LIBS)
+dnl Check for magic libraries
+AC_ARG_WITH(magic,
+ AC_HELP_STRING([--without-magic],
+ [Don't try to use magic]))
+using_magic=no
+if test "$with_magic" != "no"; then
+ using_magic=yes
+ AC_CHECK_HEADER(magic.h,
+ [AC_CHECK_LIB(magic, magic_open, MAGIC_LIBS="-lmagic",using_magic=no)],
+ using_magic=no)
+ if test "$with_magic" = "yes" -a "$using_magic" = "no"; then
+ AC_MSG_FAILURE([cannot find magic])
+ fi
+fi
+if test "$using_magic" = yes; then
+ AC_DEFINE(HAVE_MAGIC, 1, [Define to 1 if you have magic.])
+fi
+AM_CONDITIONAL(HAVE_MAGIC, test x$using_magic = xyes)
+AC_SUBST(MAGIC_LIBS)
+
dnl Check for MAD libraries
AC_ARG_WITH(mad,
AC_HELP_STRING([--without-mad],
@@ -554,6 +574,7 @@
echo "Ogg Vorbis format................. $using_ogg"
echo "FLAC format....................... $using_flac"
echo "ffmpeg formats.................... $using_ffmpeg"
+echo "magic library..................... $using_magic"
echo "MAD MP3 reader.................... $using_mad"
echo "id3tag library.................... $using_id3tag"
echo "LAME MP3 writer................... $using_lame"
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -307,6 +307,10 @@
libsox_la_LIBADD += @FFMPEG_LIBS@
sox_LDADD += @FFMPEG_LIBS@
endif
+if HAVE_MAGIC
+ libsox_la_LIBADD += @MAGIC_LIBS@
+ sox_LDADD += @MAGIC_LIBS@
+endif
if HAVE_SNDFILE
libsox_la_SOURCES += sndfile.c caf.c mat4.c mat5.c paf.c fap.c w64.c xi.c pvf.c sd2.c
libsox_la_CFLAGS += @SNDFILE_CFLAGS@
--- a/src/formats.c
+++ b/src/formats.c
@@ -33,6 +33,10 @@
#include <io.h>
#endif
+#if HAVE_MAGIC
+ #include <magic.h>
+#endif
+
static char const * detect_magic(sox_format_t * ft, char const * ext)
{
char data[256];
@@ -399,6 +403,22 @@
if (ft->seekable) {
filetype = detect_magic(ft, find_file_extension(path));
lsx_rewind(ft);
+#if HAVE_MAGIC
+ if (!filetype) {
+ static magic_t magic;
+ if (!magic) {
+ magic = magic_open(MAGIC_MIME | MAGIC_SYMLINK);
+ if (magic)
+ magic_load(magic, NULL);
+ }
+ if (magic)
+ filetype = magic_file(magic, path);
+ if (filetype && (
+ !strcmp(filetype, "application/octet-stream") ||
+ !strncmp(filetype, "text/plain", 10) ))
+ filetype = NULL;
+ }
+#endif
}
if (filetype) {
sox_report("detected file format type `%s'", filetype);
--- a/src/mp3.c
+++ b/src/mp3.c
@@ -506,7 +506,7 @@
SOX_FORMAT_HANDLER(mp3)
{
- static char const * const names[] = {"mp3", "mp2", NULL};
+ static char const * const names[] = {"mp3", "mp2", "audio/mpeg", NULL};
static unsigned const write_encodings[] = {
SOX_ENCODING_GSM, 0, 0};
static sox_format_handler_t const handler = {SOX_LIB_VERSION_CODE,
--- a/src/sox.c
+++ b/src/sox.c
@@ -262,6 +262,8 @@
static char const * const no_yes[] = {"no", "yes"};
FILE * const output = sox_mode == sox_soxi? stdout : stderr;
char const * filetype = find_file_extension(ft->filename);
+ sox_bool show_type = sox_true;
+ size_t i;
if (sox_mode == sox_play && sox_globals.verbosity < 3) {
play_file_info(ft, f, full);
@@ -270,7 +272,10 @@
fprintf(output, "\n%s: '%s'",
ft->mode == 'r'? "Input File " : "Output File ", ft->filename);
- if (!filetype || strcasecmp(filetype, ft->filetype))
+ if (filetype) for (i = 0; ft->handler.names[i] && show_type; ++i)
+ if (!strcasecmp(filetype, ft->handler.names[i]))
+ show_type = sox_false;
+ if (show_type)
fprintf(output, " (%s)", ft->handler.names[0]);
fprintf(output, "\n");
@@ -1432,7 +1437,8 @@
sox_format_handler_t const * handler = sox_format_fns[i].fn();
if (!(handler->flags & SOX_FILE_DEVICE))
for (names = handler->names; *names; ++names)
- format_list[formats++] = *names;
+ if (!strchr(*names, '/'))
+ format_list[formats++] = *names;
}
qsort(format_list, formats, sizeof(*format_list), strcmp_p);
for (i = 0; i < formats; i++)
--- a/src/soxconfig.h.cmake
+++ b/src/soxconfig.h.cmake
@@ -18,6 +18,7 @@
#cmakedefine HAVE_MACHINE_SOUNDCARD_H 1
#cmakedefine HAVE_MAD_H 1
#cmakedefine HAVE_MP3 1
+#cmakedefine HAVE_MAGIC 1
#cmakedefine HAVE_OGG_VORBIS 1
#cmakedefine HAVE_POPEN 1
#cmakedefine HAVE_PNG 1