diff options
-rw-r--r-- | configure.ac | 22 | ||||
-rw-r--r-- | doc/mpd.conf.5 | 4 | ||||
-rw-r--r-- | doc/mpdconf.example | 6 | ||||
-rw-r--r-- | m4/lame.m4 | 111 | ||||
-rw-r--r-- | src/conf.c | 18 | ||||
-rw-r--r-- | src/conf.h | 5 | ||||
-rw-r--r-- | src/decoder/ffmpeg_decoder_plugin.c | 13 | ||||
-rw-r--r-- | src/inotify_update.c | 41 | ||||
-rw-r--r-- | src/inotify_update.h | 4 | ||||
-rw-r--r-- | src/main.c | 3 |
10 files changed, 98 insertions, 129 deletions
diff --git a/configure.ac b/configure.ac index 8ae21793a..ff64bee06 100644 --- a/configure.ac +++ b/configure.ac @@ -195,6 +195,12 @@ AC_ARG_ENABLE(un, [disable support for clients connecting via unix domain sockets (default: enable)]),, [enable_un=yes]) +case "$host_os" in +mingw* | windows*) + enable_un=no + ;; +esac + if test x$enable_un = xyes; then AC_DEFINE(HAVE_UN, 1, [Define if unix domain socket support is enabled]) STRUCT_UCRED @@ -1139,12 +1145,20 @@ MPD_AUTO_PKG(vorbis_encoder, VORBISENC, [vorbisenc], [Ogg Vorbis encoder], [libvorbisenc not found]) if test x$enable_lame_encoder != xno; then - AM_PATH_LAME([found_lame_encoder=yes], [found_lame_encoder=no]) - MPD_AUTO_RESULT(lame_encoder, [LAME encoder plugin], - [LAME not found]) + AC_CHECK_HEADERS(lame/lame.h,, + [AC_CHECK_HEADERS(lame.h,, using_lame=no)]) + AC_CHECK_LIB(mp3lame, lame_init,, using_lame=no) + if test x$using_lame != xno; then + AC_DEFINE(HAVE_LAME, 1, [Define to 1 if you have lame 3.98 or greater.]) + LAME_LIBS="-lmp3lame -lm" + enable_lame_encoder=yes + fi + + if test "$enable_lame_encoder" = "yes" -a "$using_lame" = "no"; then + AC_MSG_ERROR([LAME libraries and development support files not found.]) + fi fi -AC_SUBST(LAME_CFLAGS) AC_SUBST(LAME_LIBS) MPD_AUTO_PKG(twolame_encoder, TWOLAME, [twolame], diff --git a/doc/mpd.conf.5 b/doc/mpd.conf.5 index 48b276d55..e0a30449e 100644 --- a/doc/mpd.conf.5 +++ b/doc/mpd.conf.5 @@ -253,6 +253,10 @@ comments. This specifies the wheter to support automatic update of music database when files are changed in music_directory. The default is to disable autoupdate of database. +.TP +.B auto_update_depth <N> +Limit the depth of the directories being watched, 0 means only watch +the music directory itself. There is no limit by default. .SH REQUIRED AUDIO OUTPUT PARAMETERS .TP .B type <type> diff --git a/doc/mpdconf.example b/doc/mpdconf.example index 1a0547094..3b69e9bb3 100644 --- a/doc/mpdconf.example +++ b/doc/mpdconf.example @@ -118,6 +118,12 @@ # music_directory are changed. # #auto_update "yes" +# +# Limit the depth of the directories being watched, 0 means only watch +# the music directory itself. There is no limit by default. +# +#auto_update_depth "3" +# ############################################################################### diff --git a/m4/lame.m4 b/m4/lame.m4 deleted file mode 100644 index 0723f7dba..000000000 --- a/m4/lame.m4 +++ /dev/null @@ -1,111 +0,0 @@ -dnl borrowed from oddsock.org -dnl AM_PATH_LAME([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]) -dnl Test for liblame, and define LAME_CFLAGS and LAME_LIBS -dnl -AC_DEFUN([AM_PATH_LAME], -[dnl -dnl Get the cflags and libraries -dnl -AC_ARG_WITH(lame, - AS_HELP_STRING([--with-lame=PFX], - [prefix where liblame is installed (optional)]),, - lame_prefix="") -AC_ARG_WITH(lame-libraries, - AS_HELP_STRING([--with-lame-libraries=DIR], - [directory where liblame library is installed (optional)]),, - lame_libraries="") -AC_ARG_WITH(lame-includes, - AS_HELP_STRING([--with-lame-includes=DIR], - [directory where liblame header files are installed (optional)]),, - lame_includes="") - -if test "x$lame_prefix" != "xno" ; then - - if test "x$lame_libraries" != "x" ; then - LAME_LIBS="-L$lame_libraries" - elif test "x$lame_prefix" != "x" ; then - LAME_LIBS="-L$lame_prefix/lib" - elif test "x$prefix" != "xNONE" ; then - LAME_LIBS="-L$prefix/lib" - fi - - LAME_LIBS="$LAME_LIBS -lmp3lame -lm" - - if test "x$lame_includes" != "x" ; then - LAME_CFLAGS="-I$lame_includes" - elif test "x$lame_prefix" != "x" ; then - LAME_CFLAGS="-I$lame_prefix/include" - elif test "x$prefix" != "xNONE"; then - LAME_CFLAGS="-I$prefix/include" - fi - - AC_MSG_CHECKING(for liblame) - no_lame="" - - - ac_save_CFLAGS="$CFLAGS" - ac_save_LIBS="$LIBS" - CFLAGS="$CFLAGS $LAME_CFLAGS" - LIBS="$LIBS $LAME_LIBS" -dnl -dnl Now check if the installed liblame is sufficiently new. -dnl - rm -f conf.lametest - AC_TRY_RUN([ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <lame/lame.h> - -int main () -{ - system("touch conf.lametest"); - return 0; -} - -],, no_lame=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) - CFLAGS="$ac_save_CFLAGS" - LIBS="$ac_save_LIBS" - fi - - if test "x$no_lame" = "x" ; then - AC_MSG_RESULT(yes) - ifelse([$1], , :, [$1]) - else - AC_MSG_RESULT(no) - if test -f conf.lametest ; then - : - else - echo "*** Could not run liblame test program, checking why..." - CFLAGS="$CFLAGS $LAME_CFLAGS" - LIBS="$LIBS $LAME_LIBS" - AC_TRY_LINK([ -#include <stdio.h> -#include <lame/lame.h> -], [ return 0; ], - [ echo "*** The test program compiled, but did not run. This usually means" - echo "*** that the run-time linker is not finding liblame or finding the wrong" - echo "*** version of liblame. If it is not finding liblame, you'll need to set your" - echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" - echo "*** to the installed location Also, make sure you have run ldconfig if that" - echo "*** is required on your system" - echo "***" - echo "*** If you have an old version installed, it is best to remove it, although" - echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"], - [ echo "*** The test program failed to compile or link. See the file config.log for the" - echo "*** exact error that occured. This usually means liblame was incorrectly installed" - echo "*** or that you have moved liblame since it was installed." ]) - CFLAGS="$ac_save_CFLAGS" - LIBS="$ac_save_LIBS" - fi - LAME_CFLAGS="" - LAME_LIBS="" - ifelse([$2], , :, [$2]) - fi - AC_DEFINE(HAVE_LAME, 1, [Define if you have liblame.]) - use_lame="1" - AC_SUBST(LAME_CFLAGS) - AC_SUBST(LAME_LIBS) - rm -f conf.lametest -]) - diff --git a/src/conf.c b/src/conf.c index cf78bb29c..ab7be10a7 100644 --- a/src/conf.c +++ b/src/conf.c @@ -94,6 +94,7 @@ static struct config_entry config_entries[] = { { .name = CONF_GAPLESS_MP3_PLAYBACK, false, false }, { .name = CONF_PLAYLIST_PLUGIN, true, true }, { .name = CONF_AUTO_UPDATE, false, false }, + { .name = CONF_AUTO_UPDATE_DEPTH, false, false }, { .name = "filter", true, true }, }; @@ -504,6 +505,23 @@ config_get_path(const char *name) } unsigned +config_get_unsigned(const char *name, unsigned default_value) +{ + const struct config_param *param = config_get_param(name); + long value; + char *endptr; + + if (param == NULL) + return default_value; + + value = strtol(param->value, &endptr, 0); + if (*endptr != 0 || value < 0) + g_error("Not a valid non-negative number in line %i", param->line); + + return (unsigned)value; +} + +unsigned config_get_positive(const char *name, unsigned default_value) { const struct config_param *param = config_get_param(name); diff --git a/src/conf.h b/src/conf.h index 7ffa6e44a..d79a673cc 100644 --- a/src/conf.h +++ b/src/conf.h @@ -70,6 +70,7 @@ #define CONF_GAPLESS_MP3_PLAYBACK "gapless_mp3_playback" #define CONF_PLAYLIST_PLUGIN "playlist_plugin" #define CONF_AUTO_UPDATE "auto_update" +#define CONF_AUTO_UPDATE_DEPTH "auto_update_depth" #define DEFAULT_PLAYLIST_MAX_LENGTH (1024*16) #define DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS false @@ -164,6 +165,10 @@ config_get_path(const char *name); G_GNUC_PURE unsigned +config_get_unsigned(const char *name, unsigned default_value); + +G_GNUC_PURE +unsigned config_get_positive(const char *name, unsigned default_value); G_GNUC_PURE diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c index d4d6224d2..4f956f555 100644 --- a/src/decoder/ffmpeg_decoder_plugin.c +++ b/src/decoder/ffmpeg_decoder_plugin.c @@ -67,11 +67,16 @@ static void mpd_ffmpeg_log_callback(G_GNUC_UNUSED void *ptr, int level, const char *fmt, va_list vl) { - const AVClass *cls = *(const AVClass *const*)ptr; - char *domain = g_strconcat(G_LOG_DOMAIN, "/", cls->item_name(ptr), NULL); + const AVClass * cls = NULL; - g_logv(domain, level_ffmpeg_to_glib(level), fmt, vl); - g_free(domain); + if (ptr != NULL) + cls = *(const AVClass *const*)ptr; + + if (cls != NULL) { + char *domain = g_strconcat(G_LOG_DOMAIN, "/", cls->item_name(ptr), NULL); + g_logv(domain, level_ffmpeg_to_glib(level), fmt, vl); + g_free(domain); + } } #endif /* !OLD_FFMPEG_INCLUDES */ diff --git a/src/inotify_update.c b/src/inotify_update.c index 00600dfb1..218440110 100644 --- a/src/inotify_update.c +++ b/src/inotify_update.c @@ -56,6 +56,7 @@ struct watch_directory { static struct mpd_inotify_source *inotify_source; +static unsigned inotify_max_depth; static struct watch_directory inotify_root; static GTree *inotify_directories; @@ -140,15 +141,21 @@ static bool skip_path(const char *path) static void recursive_watch_subdirectories(struct watch_directory *directory, - const char *path_fs) + const char *path_fs, unsigned depth) { GError *error = NULL; DIR *dir; struct dirent *ent; assert(directory != NULL); + assert(depth <= inotify_max_depth); assert(path_fs != NULL); + ++depth; + + if (depth > inotify_max_depth) + return; + dir = opendir(path_fs); if (dir == NULL) { g_warning("Failed to open directory %s: %s", @@ -209,13 +216,26 @@ recursive_watch_subdirectories(struct watch_directory *directory, tree_add_watch_directory(child); - recursive_watch_subdirectories(child, child_path_fs); + recursive_watch_subdirectories(child, child_path_fs, depth); g_free(child_path_fs); } closedir(dir); } +G_GNUC_PURE +static unsigned +watch_directory_depth(const struct watch_directory *d) +{ + assert(d != NULL); + + unsigned depth = 0; + while ((d = d->parent) != NULL) + ++depth; + + return depth; +} + static void mpd_inotify_callback(int wd, unsigned mask, G_GNUC_UNUSED const char *name, G_GNUC_UNUSED void *ctx) @@ -250,12 +270,17 @@ mpd_inotify_callback(int wd, unsigned mask, } else path_fs = root; - recursive_watch_subdirectories(directory, path_fs); + recursive_watch_subdirectories(directory, path_fs, + watch_directory_depth(directory)); g_free(path_fs); } - if ((mask & (IN_CLOSE_WRITE|IN_MOVE|IN_DELETE)) != 0) { - /* a file was changed, or a direectory was + if ((mask & (IN_CLOSE_WRITE|IN_MOVE|IN_DELETE)) != 0 || + /* at the maximum depth, we watch out for newly created + directories */ + (watch_directory_depth(directory) == inotify_max_depth && + (mask & (IN_CREATE|IN_ISDIR)) == (IN_CREATE|IN_ISDIR))) { + /* a file was changed, or a directory was moved/deleted: queue a database update */ char *uri_utf8 = uri_fs != NULL ? fs_charset_to_utf8(uri_fs) @@ -271,7 +296,7 @@ mpd_inotify_callback(int wd, unsigned mask, } void -mpd_inotify_init(void) +mpd_inotify_init(unsigned max_depth) { struct directory *root; char *path; @@ -300,6 +325,8 @@ mpd_inotify_init(void) return; } + inotify_max_depth = max_depth; + inotify_root.name = path; inotify_root.descriptor = mpd_inotify_source_add(inotify_source, path, IN_MASK, &error); @@ -315,7 +342,7 @@ mpd_inotify_init(void) inotify_directories = g_tree_new(compare); tree_add_watch_directory(&inotify_root); - recursive_watch_subdirectories(&inotify_root, path); + recursive_watch_subdirectories(&inotify_root, path, 0); mpd_inotify_queue_init(); diff --git a/src/inotify_update.h b/src/inotify_update.h index ee6fbcfd8..92b4e0cc6 100644 --- a/src/inotify_update.h +++ b/src/inotify_update.h @@ -25,7 +25,7 @@ #ifdef HAVE_INOTIFY_INIT void -mpd_inotify_init(void); +mpd_inotify_init(unsigned max_depth); void mpd_inotify_finish(void); @@ -33,7 +33,7 @@ mpd_inotify_finish(void); #else /* !HAVE_INOTIFY_INIT */ static inline void -mpd_inotify_init(void) +mpd_inotify_init(G_GNUC_UNUSED unsigned max_depth) { } diff --git a/src/main.c b/src/main.c index 80102968e..c93a3f615 100644 --- a/src/main.c +++ b/src/main.c @@ -379,7 +379,8 @@ int main(int argc, char *argv[]) success = config_get_bool(CONF_AUTO_UPDATE, false); #ifdef ENABLE_INOTIFY if (success && mapper_has_music_directory()) - mpd_inotify_init(); + mpd_inotify_init(config_get_unsigned(CONF_AUTO_UPDATE_DEPTH, + G_MAXUINT)); #else if (success) g_warning("inotify: auto_update was disabled. enable during compilation phase"); |