From 3f267b1795d68e660af9ec1678909a6102102d7d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 5 Sep 2013 18:22:02 +0200 Subject: Tag, ...: move to libtag.a --- Makefile.am | 40 ++- src/AllCommands.cxx | 2 +- src/CrossFade.cxx | 1 - src/DatabaseCommands.cxx | 2 +- src/DatabaseHelpers.cxx | 2 +- src/DatabaseHelpers.hxx | 2 +- src/DatabasePlugin.hxx | 2 +- src/DatabasePrint.cxx | 2 +- src/DatabaseSave.cxx | 4 +- src/DecoderAPI.hxx | 2 +- src/DecoderInternal.cxx | 2 +- src/DecoderThread.cxx | 2 +- src/DespotifyUtils.cxx | 2 +- src/EncoderAPI.hxx | 2 +- src/IcyMetaDataParser.cxx | 2 +- src/IcyMetaDataServer.cxx | 2 +- src/IcyMetaDataServer.hxx | 2 +- src/Main.cxx | 2 +- src/MusicChunk.cxx | 2 +- src/OutputAPI.hxx | 2 +- src/PlayerThread.cxx | 2 +- src/PlaylistSong.cxx | 2 +- src/Song.cxx | 2 +- src/SongFilter.cxx | 2 +- src/SongSave.cxx | 2 +- src/SongSort.cxx | 2 +- src/SongUpdate.cxx | 4 +- src/Tag.cxx | 509 ----------------------------- src/Tag.hxx | 223 ------------- src/TagHandler.cxx | 62 ---- src/TagHandler.hxx | 101 ------ src/TagInternal.hxx | 27 -- src/TagNames.c | 44 --- src/TagPool.cxx | 155 --------- src/TagPool.hxx | 39 --- src/TagPrint.cxx | 4 +- src/TagSave.cxx | 3 +- src/TagType.h | 56 ---- src/UpdateContainer.cxx | 4 +- src/cue/CueParser.cxx | 2 +- src/db/ProxyDatabasePlugin.cxx | 2 +- src/decoder/AdPlugDecoderPlugin.cxx | 2 +- src/decoder/AudiofileDecoderPlugin.cxx | 2 +- src/decoder/DsdLib.cxx | 2 +- src/decoder/DsdiffDecoderPlugin.cxx | 2 +- src/decoder/DsfDecoderPlugin.cxx | 2 +- src/decoder/FaadDecoderPlugin.cxx | 2 +- src/decoder/FfmpegDecoderPlugin.cxx | 2 +- src/decoder/FfmpegMetaData.cxx | 2 +- src/decoder/FlacMetadata.cxx | 4 +- src/decoder/GmeDecoderPlugin.cxx | 2 +- src/decoder/MadDecoderPlugin.cxx | 2 +- src/decoder/MikmodDecoderPlugin.cxx | 2 +- src/decoder/ModplugDecoderPlugin.cxx | 2 +- src/decoder/MpcdecDecoderPlugin.cxx | 2 +- src/decoder/Mpg123DecoderPlugin.cxx | 2 +- src/decoder/OpusDecoderPlugin.cxx | 2 +- src/decoder/OpusTags.cxx | 2 +- src/decoder/SndfileDecoderPlugin.cxx | 2 +- src/decoder/VorbisComments.cxx | 4 +- src/decoder/VorbisDecoderPlugin.cxx | 2 +- src/decoder/WavpackDecoderPlugin.cxx | 2 +- src/decoder/WildmidiDecoderPlugin.cxx | 2 +- src/decoder/sidplay_decoder_plugin.cxx | 5 +- src/encoder/VorbisEncoderPlugin.cxx | 2 +- src/input/CurlInputPlugin.cxx | 2 +- src/input/DespotifyInputPlugin.cxx | 2 +- src/input/RewindInputPlugin.cxx | 2 +- src/playlist/AsxPlaylistPlugin.cxx | 2 +- src/playlist/CuePlaylistPlugin.cxx | 2 +- src/playlist/DespotifyPlaylistPlugin.cxx | 2 +- src/playlist/EmbeddedCuePlaylistPlugin.cxx | 4 +- src/playlist/ExtM3uPlaylistPlugin.cxx | 2 +- src/playlist/PlsPlaylistPlugin.cxx | 2 +- src/playlist/RssPlaylistPlugin.cxx | 2 +- src/playlist/SoundCloudPlaylistPlugin.cxx | 2 +- src/playlist/XspfPlaylistPlugin.cxx | 2 +- src/tag/Tag.cxx | 509 +++++++++++++++++++++++++++++ src/tag/Tag.hxx | 223 +++++++++++++ src/tag/TagHandler.cxx | 62 ++++ src/tag/TagHandler.hxx | 101 ++++++ src/tag/TagInternal.hxx | 27 ++ src/tag/TagNames.c | 44 +++ src/tag/TagPool.cxx | 155 +++++++++ src/tag/TagPool.hxx | 39 +++ src/tag/TagType.h | 56 ++++ test/DumpDatabase.cxx | 2 +- test/dump_rva2.cxx | 2 +- test/read_tags.cxx | 2 +- test/run_input.cxx | 2 +- test/test_vorbis_encoder.cxx | 2 +- test/visit_archive.cxx | 2 +- 92 files changed, 1314 insertions(+), 1321 deletions(-) delete mode 100644 src/Tag.cxx delete mode 100644 src/Tag.hxx delete mode 100644 src/TagHandler.cxx delete mode 100644 src/TagHandler.hxx delete mode 100644 src/TagInternal.hxx delete mode 100644 src/TagNames.c delete mode 100644 src/TagPool.cxx delete mode 100644 src/TagPool.hxx delete mode 100644 src/TagType.h create mode 100644 src/tag/Tag.cxx create mode 100644 src/tag/Tag.hxx create mode 100644 src/tag/TagHandler.cxx create mode 100644 src/tag/TagHandler.hxx create mode 100644 src/tag/TagInternal.hxx create mode 100644 src/tag/TagNames.c create mode 100644 src/tag/TagPool.cxx create mode 100644 src/tag/TagPool.hxx create mode 100644 src/tag/TagType.h diff --git a/Makefile.am b/Makefile.am index b39848c59..6139113d7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -201,14 +201,8 @@ src_mpd_SOURCES = \ src/SongSort.cxx src/SongSort.hxx \ src/StateFile.cxx src/StateFile.hxx \ src/Stats.cxx \ - src/TagType.h \ - src/Tag.cxx src/Tag.hxx \ - src/TagInternal.hxx \ - src/TagNames.c \ - src/TagPool.cxx src/TagPool.hxx \ src/TagPrint.cxx src/TagPrint.hxx \ src/TagSave.cxx src/TagSave.hxx \ - src/TagHandler.cxx src/TagHandler.hxx \ src/TagFile.cxx src/TagFile.hxx \ src/TextFile.cxx src/TextFile.hxx \ src/TextInputStream.cxx \ @@ -428,7 +422,13 @@ TAG_LIBS = \ $(ID3TAG_LIBS) libtag_a_SOURCES =\ - src/tag/TagTable.cxx src/TagTable.hxx \ + src/tag/TagType.h \ + src/tag/Tag.cxx src/tag/Tag.hxx \ + src/tag/TagHandler.cxx src/tag/TagHandler.hxx \ + src/tag/TagInternal.hxx \ + src/tag/TagNames.c \ + src/tag/TagPool.cxx src/tag/TagPool.hxx \ + src/tag/TagTable.cxx src/tag/TagTable.hxx \ src/tag/ApeLoader.cxx src/tag/ApeLoader.hxx \ src/tag/ApeReplayGain.cxx src/tag/ApeReplayGain.hxx \ src/tag/ApeTag.cxx src/tag/ApeTag.hxx @@ -1074,6 +1074,7 @@ test_run_resolver_SOURCES = test/run_resolver.cxx test_DumpDatabase_LDADD = \ $(DB_LIBS) \ + $(TAG_LIBS) \ libconf.a \ libutil.a \ libsystem.a \ @@ -1087,13 +1088,14 @@ test_DumpDatabase_SOURCES = test/DumpDatabase.cxx \ src/PlaylistVector.cxx src/PlaylistDatabase.cxx \ src/DatabaseLock.cxx src/DatabaseSave.cxx \ src/Song.cxx src/SongSave.cxx src/SongSort.cxx \ - src/Tag.cxx src/TagNames.c src/TagPool.cxx src/TagSave.cxx \ + src/TagSave.cxx \ src/SongFilter.cxx \ src/TextFile.cxx test_run_input_LDADD = \ $(INPUT_LIBS) \ $(ARCHIVE_LIBS) \ + $(TAG_LIBS) \ libconf.a \ libutil.a \ libevent.a \ @@ -1103,13 +1105,14 @@ test_run_input_LDADD = \ test_run_input_SOURCES = test/run_input.cxx \ test/stdbin.h \ src/IOThread.cxx \ - src/Tag.cxx src/TagNames.c src/TagPool.cxx src/TagSave.cxx + src/TagSave.cxx if ENABLE_ARCHIVE test_visit_archive_LDADD = \ $(INPUT_LIBS) \ $(ARCHIVE_LIBS) \ + $(TAG_LIBS) \ libconf.a \ libutil.a \ libevent.a \ @@ -1118,8 +1121,7 @@ test_visit_archive_LDADD = \ $(GLIB_LIBS) test_visit_archive_SOURCES = test/visit_archive.cxx \ src/IOThread.cxx \ - src/InputStream.cxx \ - src/Tag.cxx src/TagNames.c src/TagPool.cxx + src/InputStream.cxx if ENABLE_DESPOTIFY test_visit_archive_SOURCES += src/DespotifyUtils.cxx @@ -1130,6 +1132,7 @@ endif test_dump_text_file_LDADD = \ $(INPUT_LIBS) \ $(ARCHIVE_LIBS) \ + $(TAG_LIBS) \ libconf.a \ libevent.a \ libfs.a \ @@ -1139,7 +1142,6 @@ test_dump_text_file_LDADD = \ test_dump_text_file_SOURCES = test/dump_text_file.cxx \ test/stdbin.h \ src/IOThread.cxx \ - src/Tag.cxx src/TagNames.c src/TagPool.cxx \ src/TextInputStream.cxx test_dump_playlist_LDADD = \ @@ -1159,8 +1161,8 @@ test_dump_playlist_LDADD = \ test_dump_playlist_SOURCES = test/dump_playlist.cxx \ $(DECODER_SRC) \ src/IOThread.cxx \ - src/Song.cxx src/Tag.cxx src/TagNames.c src/TagPool.cxx src/TagSave.cxx \ - src/TagHandler.cxx src/TagFile.cxx \ + src/Song.cxx src/TagSave.cxx \ + src/TagFile.cxx \ src/CheckAudioFormat.cxx \ src/TextInputStream.cxx \ src/cue/CueParser.cxx src/cue/CueParser.hxx @@ -1186,7 +1188,6 @@ test_run_decoder_LDADD = \ test_run_decoder_SOURCES = test/run_decoder.cxx \ test/stdbin.h \ src/IOThread.cxx \ - src/Tag.cxx src/TagNames.c src/TagPool.cxx src/TagHandler.cxx \ src/ReplayGainInfo.cxx \ src/AudioFormat.cxx src/CheckAudioFormat.cxx \ $(ARCHIVE_SRC) \ @@ -1208,7 +1209,6 @@ test_read_tags_LDADD = \ $(GLIB_LIBS) test_read_tags_SOURCES = test/read_tags.cxx \ src/IOThread.cxx \ - src/Tag.cxx src/TagNames.c src/TagPool.cxx src/TagHandler.cxx \ src/ReplayGainInfo.cxx \ src/CheckAudioFormat.cxx \ $(DECODER_SRC) @@ -1218,8 +1218,7 @@ test_dump_rva2_LDADD = \ $(TAG_LIBS) \ libutil.a \ $(GLIB_LIBS) -test_dump_rva2_SOURCES = test/dump_rva2.cxx \ - src/TagHandler.cxx +test_dump_rva2_SOURCES = test/dump_rva2.cxx endif test_run_filter_LDADD = \ @@ -1251,7 +1250,6 @@ if ENABLE_ENCODER noinst_PROGRAMS += test/run_encoder test_run_encoder_SOURCES = test/run_encoder.cxx \ test/stdbin.h \ - src/Tag.cxx src/TagNames.c src/TagPool.cxx \ src/CheckAudioFormat.cxx \ src/AudioFormat.cxx \ src/AudioParser.cxx @@ -1270,7 +1268,6 @@ if ENABLE_VORBIS_ENCODER noinst_PROGRAMS += test/test_vorbis_encoder test_test_vorbis_encoder_SOURCES = test/test_vorbis_encoder.cxx \ test/stdbin.h \ - src/Tag.cxx src/TagNames.c src/TagPool.cxx \ src/CheckAudioFormat.cxx \ src/AudioFormat.cxx \ src/AudioParser.cxx \ @@ -1280,6 +1277,7 @@ test_test_vorbis_encoder_CPPFLAGS = $(AM_CPPFLAGS) \ test_test_vorbis_encoder_LDADD = $(MPD_LIBS) \ $(ENCODER_LIBS) \ $(PCM_LIBS) \ + $(TAG_LIBS) \ libconf.a \ libsystem.a \ libfs.a \ @@ -1320,6 +1318,7 @@ test_run_output_LDADD = $(MPD_LIBS) \ $(ENCODER_LIBS) \ libmixer_plugins.a \ $(FILTER_LIBS) \ + $(TAG_LIBS) \ libconf.a \ libevent.a \ libfs.a \ @@ -1334,7 +1333,6 @@ test_run_output_SOURCES = test/run_output.cxx \ src/AudioFormat.cxx \ src/AudioParser.cxx \ src/Timer.cxx \ - src/Tag.cxx src/TagNames.c src/TagPool.cxx \ src/Page.cxx \ src/OutputError.cxx \ src/OutputInit.cxx src/OutputFinish.cxx src/OutputList.cxx \ diff --git a/src/AllCommands.cxx b/src/AllCommands.cxx index acd7d263e..e02e6df15 100644 --- a/src/AllCommands.cxx +++ b/src/AllCommands.cxx @@ -28,7 +28,7 @@ #include "MessageCommands.hxx" #include "OtherCommands.hxx" #include "Permission.hxx" -#include "Tag.hxx" +#include "tag/TagType.h" #include "protocol/Result.hxx" #include "Client.hxx" #include "util/Tokenizer.hxx" diff --git a/src/CrossFade.cxx b/src/CrossFade.cxx index 03b4b7918..db335651a 100644 --- a/src/CrossFade.cxx +++ b/src/CrossFade.cxx @@ -21,7 +21,6 @@ #include "CrossFade.hxx" #include "MusicChunk.hxx" #include "AudioFormat.hxx" -#include "Tag.hxx" #include diff --git a/src/DatabaseCommands.cxx b/src/DatabaseCommands.cxx index abed30564..cc9e0937b 100644 --- a/src/DatabaseCommands.cxx +++ b/src/DatabaseCommands.cxx @@ -25,7 +25,7 @@ #include "DatabaseSelection.hxx" #include "CommandError.hxx" #include "ClientInternal.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "util/UriUtil.hxx" #include "util/Error.hxx" #include "SongFilter.hxx" diff --git a/src/DatabaseHelpers.cxx b/src/DatabaseHelpers.cxx index f2086e5d2..f250e447a 100644 --- a/src/DatabaseHelpers.cxx +++ b/src/DatabaseHelpers.cxx @@ -20,7 +20,7 @@ #include "DatabaseHelpers.hxx" #include "DatabasePlugin.hxx" #include "Song.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include #include diff --git a/src/DatabaseHelpers.hxx b/src/DatabaseHelpers.hxx index 479cc37c1..e666278f2 100644 --- a/src/DatabaseHelpers.hxx +++ b/src/DatabaseHelpers.hxx @@ -21,7 +21,7 @@ #define MPD_MEMORY_DATABASE_PLUGIN_HXX #include "DatabaseVisitor.hxx" -#include "TagType.h" +#include "tag/TagType.h" #include "gcc.h" class Error; diff --git a/src/DatabasePlugin.hxx b/src/DatabasePlugin.hxx index c17bff63c..9bcbf49fd 100644 --- a/src/DatabasePlugin.hxx +++ b/src/DatabasePlugin.hxx @@ -27,7 +27,7 @@ #define MPD_DATABASE_PLUGIN_HXX #include "DatabaseVisitor.hxx" -#include "TagType.h" +#include "tag/TagType.h" #include "gcc.h" struct config_param; diff --git a/src/DatabasePrint.cxx b/src/DatabasePrint.cxx index cc7bee9e2..c50c7686e 100644 --- a/src/DatabasePrint.cxx +++ b/src/DatabasePrint.cxx @@ -26,7 +26,7 @@ #include "TimePrint.hxx" #include "Directory.hxx" #include "Client.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "Song.hxx" #include "DatabaseGlue.hxx" #include "DatabasePlugin.hxx" diff --git a/src/DatabaseSave.cxx b/src/DatabaseSave.cxx index 4213fb9a0..100c9220e 100644 --- a/src/DatabaseSave.cxx +++ b/src/DatabaseSave.cxx @@ -25,8 +25,8 @@ #include "DirectorySave.hxx" #include "Song.hxx" #include "TextFile.hxx" -#include "TagInternal.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" +#include "tag/TagInternal.hxx" #include "fs/Path.hxx" #include "util/Error.hxx" diff --git a/src/DecoderAPI.hxx b/src/DecoderAPI.hxx index d514ef7cc..ff7cdc27b 100644 --- a/src/DecoderAPI.hxx +++ b/src/DecoderAPI.hxx @@ -31,7 +31,7 @@ #include "DecoderCommand.hxx" #include "DecoderPlugin.hxx" #include "replay_gain_info.h" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "AudioFormat.hxx" #include "ConfigData.hxx" diff --git a/src/DecoderInternal.cxx b/src/DecoderInternal.cxx index 6c703e227..c16124c3e 100644 --- a/src/DecoderInternal.cxx +++ b/src/DecoderInternal.cxx @@ -23,7 +23,7 @@ #include "MusicPipe.hxx" #include "MusicBuffer.hxx" #include "MusicChunk.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include diff --git a/src/DecoderThread.cxx b/src/DecoderThread.cxx index e18b19409..a789cc30f 100644 --- a/src/DecoderThread.cxx +++ b/src/DecoderThread.cxx @@ -28,7 +28,7 @@ #include "Mapper.hxx" #include "fs/Path.hxx" #include "DecoderAPI.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "InputStream.hxx" #include "DecoderList.hxx" #include "util/UriUtil.hxx" diff --git a/src/DespotifyUtils.cxx b/src/DespotifyUtils.cxx index 863036464..3747ddbd9 100644 --- a/src/DespotifyUtils.cxx +++ b/src/DespotifyUtils.cxx @@ -18,7 +18,7 @@ */ #include "DespotifyUtils.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "ConfigGlobal.hxx" #include "ConfigOption.hxx" diff --git a/src/EncoderAPI.hxx b/src/EncoderAPI.hxx index b401192e2..b3397f25c 100644 --- a/src/EncoderAPI.hxx +++ b/src/EncoderAPI.hxx @@ -27,7 +27,7 @@ #include "EncoderPlugin.hxx" #include "AudioFormat.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "ConfigData.hxx" #endif diff --git a/src/IcyMetaDataParser.cxx b/src/IcyMetaDataParser.cxx index 6e1e18a51..d00833be1 100644 --- a/src/IcyMetaDataParser.cxx +++ b/src/IcyMetaDataParser.cxx @@ -19,7 +19,7 @@ #include "config.h" #include "IcyMetaDataParser.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include diff --git a/src/IcyMetaDataServer.cxx b/src/IcyMetaDataServer.cxx index d0ae0b77a..10d4ec94f 100644 --- a/src/IcyMetaDataServer.cxx +++ b/src/IcyMetaDataServer.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "IcyMetaDataServer.hxx" #include "Page.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include diff --git a/src/IcyMetaDataServer.hxx b/src/IcyMetaDataServer.hxx index ee685adcf..a37239cd7 100644 --- a/src/IcyMetaDataServer.hxx +++ b/src/IcyMetaDataServer.hxx @@ -20,7 +20,7 @@ #ifndef MPD_ICY_META_DATA_SERVER_HXX #define MPD_ICY_META_DATA_SERVER_HXX -#include "TagType.h" +#include "tag/TagType.h" struct Tag; class Page; diff --git a/src/Main.cxx b/src/Main.cxx index 73cae630f..511e136aa 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -38,7 +38,7 @@ #include "Partition.hxx" #include "Volume.hxx" #include "OutputAll.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "replay_gain_config.h" #include "Idle.hxx" #include "SignalHandlers.hxx" diff --git a/src/MusicChunk.cxx b/src/MusicChunk.cxx index fb9019988..9ffe4f509 100644 --- a/src/MusicChunk.cxx +++ b/src/MusicChunk.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "MusicChunk.hxx" #include "AudioFormat.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include diff --git a/src/OutputAPI.hxx b/src/OutputAPI.hxx index cc7a0832d..73cbaf183 100644 --- a/src/OutputAPI.hxx +++ b/src/OutputAPI.hxx @@ -23,7 +23,7 @@ #include "OutputPlugin.hxx" #include "OutputInternal.hxx" #include "AudioFormat.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "ConfigData.hxx" #endif diff --git a/src/PlayerThread.cxx b/src/PlayerThread.cxx index 7d8c2b563..83d9f55bd 100644 --- a/src/PlayerThread.cxx +++ b/src/PlayerThread.cxx @@ -30,7 +30,7 @@ #include "CrossFade.hxx" #include "PlayerControl.hxx" #include "OutputAll.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "Idle.hxx" #include "GlobalEvents.hxx" diff --git a/src/PlaylistSong.cxx b/src/PlaylistSong.cxx index f4c5b7478..1bec30da9 100644 --- a/src/PlaylistSong.cxx +++ b/src/PlaylistSong.cxx @@ -23,7 +23,7 @@ #include "DatabasePlugin.hxx" #include "DatabaseGlue.hxx" #include "ls.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "fs/Path.hxx" #include "util/UriUtil.hxx" #include "util/Error.hxx" diff --git a/src/Song.cxx b/src/Song.cxx index 023d52071..5ee4c5545 100644 --- a/src/Song.cxx +++ b/src/Song.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "Song.hxx" #include "Directory.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include diff --git a/src/SongFilter.cxx b/src/SongFilter.cxx index c928c793d..bab81b327 100644 --- a/src/SongFilter.cxx +++ b/src/SongFilter.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "SongFilter.hxx" #include "Song.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include diff --git a/src/SongSave.cxx b/src/SongSave.cxx index 7b89eccf4..d46eea6af 100644 --- a/src/SongSave.cxx +++ b/src/SongSave.cxx @@ -23,7 +23,7 @@ #include "TagSave.hxx" #include "Directory.hxx" #include "TextFile.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "util/StringUtil.hxx" #include "util/Error.hxx" #include "util/Domain.hxx" diff --git a/src/SongSort.cxx b/src/SongSort.cxx index 23ecc5ce5..f1eba0439 100644 --- a/src/SongSort.cxx +++ b/src/SongSort.cxx @@ -21,7 +21,7 @@ #include "SongSort.hxx" #include "Song.hxx" #include "util/list.h" -#include "Tag.hxx" +#include "tag/Tag.hxx" extern "C" { #include "util/list_sort.h" diff --git a/src/SongUpdate.cxx b/src/SongUpdate.cxx index f0dafc3a5..8e9768d55 100644 --- a/src/SongUpdate.cxx +++ b/src/SongUpdate.cxx @@ -25,11 +25,11 @@ #include "Mapper.hxx" #include "fs/Path.hxx" #include "fs/FileSystem.hxx" -#include "Tag.hxx" #include "InputStream.hxx" #include "DecoderPlugin.hxx" #include "DecoderList.hxx" -#include "TagHandler.hxx" +#include "tag/Tag.hxx" +#include "tag/TagHandler.hxx" #include "tag/TagId3.hxx" #include "tag/ApeTag.hxx" diff --git a/src/Tag.cxx b/src/Tag.cxx deleted file mode 100644 index c960da537..000000000 --- a/src/Tag.cxx +++ /dev/null @@ -1,509 +0,0 @@ -/* - * Copyright (C) 2003-2013 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" -#include "Tag.hxx" -#include "TagInternal.hxx" -#include "TagPool.hxx" -#include "ConfigGlobal.hxx" -#include "ConfigOption.hxx" -#include "Song.hxx" -#include "system/FatalError.hxx" - -#include -#include -#include -#include -#include - -/** - * Maximum number of items managed in the bulk list; if it is - * exceeded, we switch back to "normal" reallocation. - */ -#define BULK_MAX 64 - -static struct { -#ifndef NDEBUG - bool busy; -#endif - TagItem *items[BULK_MAX]; -} bulk; - -bool ignore_tag_items[TAG_NUM_OF_ITEM_TYPES]; - -enum tag_type -tag_name_parse(const char *name) -{ - assert(name != nullptr); - - for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) { - assert(tag_item_names[i] != nullptr); - - if (strcmp(name, tag_item_names[i]) == 0) - return (enum tag_type)i; - } - - return TAG_NUM_OF_ITEM_TYPES; -} - -enum tag_type -tag_name_parse_i(const char *name) -{ - assert(name != nullptr); - - for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) { - assert(tag_item_names[i] != nullptr); - - if (g_ascii_strcasecmp(name, tag_item_names[i]) == 0) - return (enum tag_type)i; - } - - return TAG_NUM_OF_ITEM_TYPES; -} - -static size_t -items_size(const Tag &tag) -{ - return tag.num_items * sizeof(TagItem *); -} - -void tag_lib_init(void) -{ - const char *value; - int quit = 0; - char *temp; - char *s; - char *c; - enum tag_type type; - - /* parse the "metadata_to_use" config parameter below */ - - /* ignore comments by default */ - ignore_tag_items[TAG_COMMENT] = true; - - value = config_get_string(CONF_METADATA_TO_USE, nullptr); - if (value == nullptr) - return; - - memset(ignore_tag_items, true, TAG_NUM_OF_ITEM_TYPES); - - if (0 == g_ascii_strcasecmp(value, "none")) - return; - - temp = c = s = g_strdup(value); - while (!quit) { - if (*s == ',' || *s == '\0') { - if (*s == '\0') - quit = 1; - *s = '\0'; - - c = g_strstrip(c); - if (*c == 0) - continue; - - type = tag_name_parse_i(c); - if (type == TAG_NUM_OF_ITEM_TYPES) - FormatFatalError("error parsing metadata item \"%s\"", - c); - - ignore_tag_items[type] = false; - - s++; - c = s; - } - s++; - } - - g_free(temp); -} - -void -Tag::Clear() -{ - time = -1; - has_playlist = false; - - tag_pool_lock.lock(); - for (unsigned i = 0; i < num_items; ++i) - tag_pool_put_item(items[i]); - tag_pool_lock.unlock(); - - if (items == bulk.items) { -#ifndef NDEBUG - assert(bulk.busy); - bulk.busy = false; -#endif - } else - g_free(items); - - items = nullptr; - num_items = 0; -} - -void -Tag::DeleteItem(unsigned idx) -{ - assert(idx < num_items); - --num_items; - - tag_pool_lock.lock(); - tag_pool_put_item(items[idx]); - tag_pool_lock.unlock(); - - if (num_items - idx > 0) { - memmove(items + idx, items + idx + 1, - (num_items - idx) * sizeof(items[0])); - } - - if (num_items > 0) { - items = (TagItem **) - g_realloc(items, items_size(*this)); - } else { - g_free(items); - items = nullptr; - } -} - -void -Tag::ClearItemsByType(tag_type type) -{ - for (unsigned i = 0; i < num_items; i++) { - if (items[i]->type == type) { - DeleteItem(i); - /* decrement since when just deleted this node */ - i--; - } - } -} - -Tag::~Tag() -{ - tag_pool_lock.lock(); - for (int i = num_items; --i >= 0; ) - tag_pool_put_item(items[i]); - tag_pool_lock.unlock(); - - if (items == bulk.items) { -#ifndef NDEBUG - assert(bulk.busy); - bulk.busy = false; -#endif - } else - g_free(items); -} - -Tag::Tag(const Tag &other) - :time(other.time), has_playlist(other.has_playlist), - items(nullptr), - num_items(other.num_items) -{ - if (num_items > 0) { - items = (TagItem **)g_malloc(items_size(other)); - - tag_pool_lock.lock(); - for (unsigned i = 0; i < num_items; i++) - items[i] = tag_pool_dup_item(other.items[i]); - tag_pool_lock.unlock(); - } -} - -Tag * -Tag::Merge(const Tag &base, const Tag &add) -{ - unsigned n; - - /* allocate new tag object */ - - Tag *ret = new Tag(); - ret->time = add.time > 0 ? add.time : base.time; - ret->num_items = base.num_items + add.num_items; - ret->items = ret->num_items > 0 - ? (TagItem **)g_malloc(items_size(*ret)) - : nullptr; - - tag_pool_lock.lock(); - - /* copy all items from "add" */ - - for (unsigned i = 0; i < add.num_items; ++i) - ret->items[i] = tag_pool_dup_item(add.items[i]); - - n = add.num_items; - - /* copy additional items from "base" */ - - for (unsigned i = 0; i < base.num_items; ++i) - if (!add.HasType(base.items[i]->type)) - ret->items[n++] = tag_pool_dup_item(base.items[i]); - - tag_pool_lock.unlock(); - - assert(n <= ret->num_items); - - if (n < ret->num_items) { - /* some tags were not copied - shrink ret->items */ - assert(n > 0); - - ret->num_items = n; - ret->items = (TagItem **) - g_realloc(ret->items, items_size(*ret)); - } - - return ret; -} - -Tag * -Tag::MergeReplace(Tag *base, Tag *add) -{ - if (add == nullptr) - return base; - - if (base == nullptr) - return add; - - Tag *tag = Merge(*base, *add); - delete base; - delete add; - - return tag; -} - -const char * -Tag::GetValue(tag_type type) const -{ - assert(type < TAG_NUM_OF_ITEM_TYPES); - - for (unsigned i = 0; i < num_items; i++) - if (items[i]->type == type) - return items[i]->value; - - return nullptr; -} - -bool -Tag::HasType(tag_type type) const -{ - return GetValue(type) != nullptr; -} - -bool -Tag::Equals(const Tag &other) const -{ - if (time != other.time) - return false; - - if (num_items != other.num_items) - return false; - - for (unsigned i = 0; i < num_items; i++) { - if (items[i]->type != other.items[i]->type) - return false; - if (strcmp(items[i]->value, other.items[i]->value)) { - return false; - } - } - - return true; -} - -/** - * Replace invalid sequences with the question mark. - */ -static char * -patch_utf8(const char *src, size_t length, const gchar *end) -{ - /* duplicate the string, and replace invalid bytes in that - buffer */ - char *dest = g_strdup(src); - - do { - dest[end - src] = '?'; - } while (!g_utf8_validate(end + 1, (src + length) - (end + 1), &end)); - - return dest; -} - -static char * -fix_utf8(const char *str, size_t length) -{ - const gchar *end; - char *temp; - gsize written; - - assert(str != nullptr); - - /* check if the string is already valid UTF-8 */ - if (g_utf8_validate(str, length, &end)) - return nullptr; - - /* no, it's not - try to import it from ISO-Latin-1 */ - temp = g_convert(str, length, "utf-8", "iso-8859-1", - nullptr, &written, nullptr); - if (temp != nullptr) - /* success! */ - return temp; - - /* no, still broken - there's no medication, just patch - invalid sequences */ - return patch_utf8(str, length, end); -} - -void -Tag::BeginAdd() -{ - assert(!bulk.busy); - assert(items == nullptr); - assert(num_items == 0); - -#ifndef NDEBUG - bulk.busy = true; -#endif - items = bulk.items; -} - -void -Tag::EndAdd() -{ - if (items == bulk.items) { - assert(num_items <= BULK_MAX); - - if (num_items > 0) { - /* copy the tag items from the bulk list over - to a new list (which fits exactly) */ - items = (TagItem **) - g_malloc(items_size(*this)); - memcpy(items, bulk.items, items_size(*this)); - } else - items = nullptr; - } - -#ifndef NDEBUG - bulk.busy = false; -#endif -} - -static bool -char_is_non_printable(unsigned char ch) -{ - return ch < 0x20; -} - -static const char * -find_non_printable(const char *p, size_t length) -{ - for (size_t i = 0; i < length; ++i) - if (char_is_non_printable(p[i])) - return p + i; - - return nullptr; -} - -/** - * Clears all non-printable characters, convert them to space. - * Returns nullptr if nothing needs to be cleared. - */ -static char * -clear_non_printable(const char *p, size_t length) -{ - const char *first = find_non_printable(p, length); - char *dest; - - if (first == nullptr) - return nullptr; - - dest = g_strndup(p, length); - - for (size_t i = first - p; i < length; ++i) - if (char_is_non_printable(dest[i])) - dest[i] = ' '; - - return dest; -} - -static char * -fix_tag_value(const char *p, size_t length) -{ - char *utf8, *cleared; - - utf8 = fix_utf8(p, length); - if (utf8 != nullptr) { - p = utf8; - length = strlen(p); - } - - cleared = clear_non_printable(p, length); - if (cleared == nullptr) - cleared = utf8; - else - g_free(utf8); - - return cleared; -} - -void -Tag::AddItemInternal(tag_type type, const char *value, size_t len) -{ - unsigned int i = num_items; - char *p; - - p = fix_tag_value(value, len); - if (p != nullptr) { - value = p; - len = strlen(value); - } - - num_items++; - - if (items != bulk.items) - /* bulk mode disabled */ - items = (TagItem **) - g_realloc(items, items_size(*this)); - else if (num_items >= BULK_MAX) { - /* bulk list already full - switch back to non-bulk */ - assert(bulk.busy); - - items = (TagItem **)g_malloc(items_size(*this)); - memcpy(items, bulk.items, - items_size(*this) - sizeof(TagItem *)); - } - - tag_pool_lock.lock(); - items[i] = tag_pool_get_item(type, value, len); - tag_pool_lock.unlock(); - - g_free(p); -} - -void -Tag::AddItem(tag_type type, const char *value, size_t len) -{ - if (ignore_tag_items[type]) - return; - - if (value == nullptr || len == 0) - return; - - AddItemInternal(type, value, len); -} - -void -Tag::AddItem(tag_type type, const char *value) -{ - AddItem(type, value, strlen(value)); -} diff --git a/src/Tag.hxx b/src/Tag.hxx deleted file mode 100644 index 2c5f599e2..000000000 --- a/src/Tag.hxx +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (C) 2003-2013 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPD_TAG_HXX -#define MPD_TAG_HXX - -#include "TagType.h" -#include "gcc.h" - -#include - -#include - -/** - * One tag value. It is a mapping of #tag_type to am arbitrary string - * value. Each tag can have multiple items of one tag type (although - * few clients support that). - */ -struct TagItem { - /** the type of this item */ - enum tag_type type; - - /** - * the value of this tag; this is a variable length string - */ - char value[sizeof(long)]; -} gcc_packed; - -/** - * The meta information about a song file. It is a MPD specific - * subset of tags (e.g. from ID3, vorbis comments, ...). - */ -struct Tag { - /** - * The duration of the song (in seconds). A value of zero - * means that the length is unknown. If the duration is - * really between zero and one second, you should round up to - * 1. - */ - int time; - - /** - * Does this file have an embedded playlist (e.g. embedded CUE - * sheet)? - */ - bool has_playlist; - - /** an array of tag items */ - TagItem **items; - - /** the total number of tag items in the #items array */ - unsigned num_items; - - /** - * Create an empty tag. - */ - Tag():time(-1), has_playlist(false), - items(nullptr), num_items(0) {} - - Tag(const Tag &other); - - Tag(Tag &&other) - :time(other.time), has_playlist(other.has_playlist), - items(other.items), num_items(other.num_items) { - other.items = nullptr; - other.num_items = 0; - } - - /** - * Free the tag object and all its items. - */ - ~Tag(); - - Tag &operator=(const Tag &other) = delete; - - Tag &operator=(Tag &&other) { - time = other.time; - has_playlist = other.has_playlist; - std::swap(items, other.items); - std::swap(num_items, other.num_items); - return *this; - } - - /** - * Returns true if the tag contains no items. This ignores the "time" - * attribute. - */ - bool IsEmpty() const { - return num_items == 0; - } - - /** - * Returns true if the tag contains any information. - */ - bool IsDefined() const { - return !IsEmpty() || time >= 0; - } - - /** - * Clear everything, as if this was a new Tag object. - */ - void Clear(); - - void DeleteItem(unsigned i); - - /** - * Clear all tag items with the specified type. - */ - void ClearItemsByType(tag_type type); - - /** - * Gives an optional hint to the tag library that we will now - * add several tag items; this is used by the library to - * optimize memory allocation. Only one tag may be in this - * state, and this tag must not have any items yet. You must - * call tag_end_add() when you are done. - */ - void BeginAdd(); - - /** - * Finishes the operation started with tag_begin_add(). - */ - void EndAdd(); - - /** - * Appends a new tag item. - * - * @param type the type of the new tag item - * @param value the value of the tag item (not null-terminated) - * @param len the length of #value - */ - void AddItem(tag_type type, const char *value, size_t len); - - /** - * Appends a new tag item. - * - * @param tag the #tag object - * @param type the type of the new tag item - * @param value the value of the tag item (null-terminated) - */ - void AddItem(tag_type type, const char *value); - - /** - * Merges the data from two tags. If both tags share data for the - * same tag_type, only data from "add" is used. - * - * @return a newly allocated tag - */ - gcc_malloc - static Tag *Merge(const Tag &base, const Tag &add); - - /** - * Merges the data from two tags. Any of the two may be NULL. Both - * are freed by this function. - * - * @return a newly allocated tag - */ - gcc_malloc - static Tag *MergeReplace(Tag *base, Tag *add); - - /** - * Returns the first value of the specified tag type, or NULL if none - * is present in this tag object. - */ - gcc_pure - const char *GetValue(tag_type type) const; - - /** - * Checks whether the tag contains one or more items with - * the specified type. - */ - bool HasType(tag_type type) const; - - /** - * Compares two tags, including the duration and all tag items. The - * order of the tag items matters. - */ - gcc_pure - bool Equals(const Tag &other) const; - -private: - void AddItemInternal(tag_type type, const char *value, size_t len); -}; - -/** - * Parse the string, and convert it into a #tag_type. Returns - * #TAG_NUM_OF_ITEM_TYPES if the string could not be recognized. - */ -enum tag_type -tag_name_parse(const char *name); - -/** - * Parse the string, and convert it into a #tag_type. Returns - * #TAG_NUM_OF_ITEM_TYPES if the string could not be recognized. - * - * Case does not matter. - */ -enum tag_type -tag_name_parse_i(const char *name); - -/** - * Initializes the tag library. - */ -void -tag_lib_init(); - -#endif diff --git a/src/TagHandler.cxx b/src/TagHandler.cxx deleted file mode 100644 index 055fae49a..000000000 --- a/src/TagHandler.cxx +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2003-2013 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" -#include "TagHandler.hxx" -#include "Tag.hxx" - -#include - -static void -add_tag_duration(unsigned seconds, void *ctx) -{ - Tag *tag = (Tag *)ctx; - - tag->time = seconds; -} - -static void -add_tag_tag(enum tag_type type, const char *value, void *ctx) -{ - Tag *tag = (Tag *)ctx; - - tag->AddItem(type, value); -} - -const struct tag_handler add_tag_handler = { - add_tag_duration, - add_tag_tag, - nullptr, -}; - -static void -full_tag_pair(const char *name, gcc_unused const char *value, void *ctx) -{ - Tag *tag = (Tag *)ctx; - - if (g_ascii_strcasecmp(name, "cuesheet") == 0) - tag->has_playlist = true; -} - -const struct tag_handler full_tag_handler = { - add_tag_duration, - add_tag_tag, - full_tag_pair, -}; - diff --git a/src/TagHandler.hxx b/src/TagHandler.hxx deleted file mode 100644 index 3303dd27e..000000000 --- a/src/TagHandler.hxx +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2003-2013 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPD_TAG_HANDLER_HXX -#define MPD_TAG_HANDLER_HXX - -#include "check.h" -#include "TagType.h" - -#include - -/** - * A callback table for receiving metadata of a song. - */ -struct tag_handler { - /** - * Declare the duration of a song, in seconds. Do not call - * this when the duration could not be determined, because - * there is no magic value for "unknown duration". - */ - void (*duration)(unsigned seconds, void *ctx); - - /** - * A tag has been read. - * - * @param the value of the tag; the pointer will become - * invalid after returning - */ - void (*tag)(enum tag_type type, const char *value, void *ctx); - - /** - * A name-value pair has been read. It is the codec specific - * representation of tags. - */ - void (*pair)(const char *key, const char *value, void *ctx); -}; - -static inline void -tag_handler_invoke_duration(const struct tag_handler *handler, void *ctx, - unsigned seconds) -{ - assert(handler != nullptr); - - if (handler->duration != nullptr) - handler->duration(seconds, ctx); -} - -static inline void -tag_handler_invoke_tag(const struct tag_handler *handler, void *ctx, - enum tag_type type, const char *value) -{ - assert(handler != nullptr); - assert((unsigned)type < TAG_NUM_OF_ITEM_TYPES); - assert(value != nullptr); - - if (handler->tag != nullptr) - handler->tag(type, value, ctx); -} - -static inline void -tag_handler_invoke_pair(const struct tag_handler *handler, void *ctx, - const char *name, const char *value) -{ - assert(handler != nullptr); - assert(name != nullptr); - assert(value != nullptr); - - if (handler->pair != nullptr) - handler->pair(name, value, ctx); -} - -/** - * This #tag_handler implementation adds tag values to a #tag object - * (casted from the context pointer). - */ -extern const struct tag_handler add_tag_handler; - -/** - * This #tag_handler implementation adds tag values to a #tag object - * (casted from the context pointer), and supports the has_playlist - * attribute. - */ -extern const struct tag_handler full_tag_handler; - -#endif diff --git a/src/TagInternal.hxx b/src/TagInternal.hxx deleted file mode 100644 index 8172d1319..000000000 --- a/src/TagInternal.hxx +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2003-2013 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPD_TAG_INTERNAL_HXX -#define MPD_TAG_INTERNAL_HXX - -#include "TagType.h" - -extern bool ignore_tag_items[TAG_NUM_OF_ITEM_TYPES]; - -#endif diff --git a/src/TagNames.c b/src/TagNames.c deleted file mode 100644 index 2e318f913..000000000 --- a/src/TagNames.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2003-2013 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" -#include "TagType.h" - -const char *tag_item_names[TAG_NUM_OF_ITEM_TYPES] = { - [TAG_ARTIST] = "Artist", - [TAG_ARTIST_SORT] = "ArtistSort", - [TAG_ALBUM] = "Album", - [TAG_ALBUM_ARTIST] = "AlbumArtist", - [TAG_ALBUM_ARTIST_SORT] = "AlbumArtistSort", - [TAG_TITLE] = "Title", - [TAG_TRACK] = "Track", - [TAG_NAME] = "Name", - [TAG_GENRE] = "Genre", - [TAG_DATE] = "Date", - [TAG_COMPOSER] = "Composer", - [TAG_PERFORMER] = "Performer", - [TAG_COMMENT] = "Comment", - [TAG_DISC] = "Disc", - - /* MusicBrainz tags from http://musicbrainz.org/doc/MusicBrainzTag */ - [TAG_MUSICBRAINZ_ARTISTID] = "MUSICBRAINZ_ARTISTID", - [TAG_MUSICBRAINZ_ALBUMID] = "MUSICBRAINZ_ALBUMID", - [TAG_MUSICBRAINZ_ALBUMARTISTID] = "MUSICBRAINZ_ALBUMARTISTID", - [TAG_MUSICBRAINZ_TRACKID] = "MUSICBRAINZ_TRACKID", -}; diff --git a/src/TagPool.cxx b/src/TagPool.cxx deleted file mode 100644 index 5a0b33c47..000000000 --- a/src/TagPool.cxx +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2003-2013 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" -#include "TagPool.hxx" -#include "Tag.hxx" - -#include - -#include -#include - -Mutex tag_pool_lock; - -#define NUM_SLOTS 4096 - -struct slot { - struct slot *next; - unsigned char ref; - TagItem item; -} mpd_packed; - -static struct slot *slots[NUM_SLOTS]; - -static inline unsigned -calc_hash_n(enum tag_type type, const char *p, size_t length) -{ - unsigned hash = 5381; - - assert(p != nullptr); - - while (length-- > 0) - hash = (hash << 5) + hash + *p++; - - return hash ^ type; -} - -static inline unsigned -calc_hash(enum tag_type type, const char *p) -{ - unsigned hash = 5381; - - assert(p != nullptr); - - while (*p != 0) - hash = (hash << 5) + hash + *p++; - - return hash ^ type; -} - -static inline struct slot * -tag_item_to_slot(TagItem *item) -{ - return (struct slot*)(((char*)item) - offsetof(struct slot, item)); -} - -static struct slot *slot_alloc(struct slot *next, - enum tag_type type, - const char *value, int length) -{ - struct slot *slot; - - slot = (struct slot *) - g_malloc(sizeof(*slot) - sizeof(slot->item.value) + length + 1); - slot->next = next; - slot->ref = 1; - slot->item.type = type; - memcpy(slot->item.value, value, length); - slot->item.value[length] = 0; - return slot; -} - -TagItem * -tag_pool_get_item(enum tag_type type, const char *value, size_t length) -{ - struct slot **slot_p, *slot; - - slot_p = &slots[calc_hash_n(type, value, length) % NUM_SLOTS]; - for (slot = *slot_p; slot != nullptr; slot = slot->next) { - if (slot->item.type == type && - length == strlen(slot->item.value) && - memcmp(value, slot->item.value, length) == 0 && - slot->ref < 0xff) { - assert(slot->ref > 0); - ++slot->ref; - return &slot->item; - } - } - - slot = slot_alloc(*slot_p, type, value, length); - *slot_p = slot; - return &slot->item; -} - -TagItem * -tag_pool_dup_item(TagItem *item) -{ - struct slot *slot = tag_item_to_slot(item); - - assert(slot->ref > 0); - - if (slot->ref < 0xff) { - ++slot->ref; - return item; - } else { - /* the reference counter overflows above 0xff; - duplicate the item, and start with 1 */ - size_t length = strlen(item->value); - struct slot **slot_p = - &slots[calc_hash_n(item->type, item->value, - length) % NUM_SLOTS]; - slot = slot_alloc(*slot_p, item->type, - item->value, strlen(item->value)); - *slot_p = slot; - return &slot->item; - } -} - -void -tag_pool_put_item(TagItem *item) -{ - struct slot **slot_p, *slot; - - slot = tag_item_to_slot(item); - assert(slot->ref > 0); - --slot->ref; - - if (slot->ref > 0) - return; - - for (slot_p = &slots[calc_hash(item->type, item->value) % NUM_SLOTS]; - *slot_p != slot; - slot_p = &(*slot_p)->next) { - assert(*slot_p != nullptr); - } - - *slot_p = slot->next; - g_free(slot); -} diff --git a/src/TagPool.hxx b/src/TagPool.hxx deleted file mode 100644 index a6b28b355..000000000 --- a/src/TagPool.hxx +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2003-2013 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPD_TAG_POOL_HXX -#define MPD_TAG_POOL_HXX - -#include "TagType.h" -#include "thread/Mutex.hxx" - -extern Mutex tag_pool_lock; - -struct TagItem; - -TagItem * -tag_pool_get_item(enum tag_type type, const char *value, size_t length); - -TagItem * -tag_pool_dup_item(TagItem *item); - -void -tag_pool_put_item(TagItem *item); - -#endif diff --git a/src/TagPrint.cxx b/src/TagPrint.cxx index 18490792c..3285d63db 100644 --- a/src/TagPrint.cxx +++ b/src/TagPrint.cxx @@ -19,8 +19,8 @@ #include "config.h" #include "TagPrint.hxx" -#include "Tag.hxx" -#include "TagInternal.hxx" +#include "tag/Tag.hxx" +#include "tag/TagInternal.hxx" #include "Song.hxx" #include "Client.hxx" diff --git a/src/TagSave.cxx b/src/TagSave.cxx index 4a9b98a90..b20d986c2 100644 --- a/src/TagSave.cxx +++ b/src/TagSave.cxx @@ -19,8 +19,7 @@ #include "config.h" #include "TagSave.hxx" -#include "Tag.hxx" -#include "TagInternal.hxx" +#include "tag/Tag.hxx" #include "Song.hxx" void diff --git a/src/TagType.h b/src/TagType.h deleted file mode 100644 index 7a1d351a5..000000000 --- a/src/TagType.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2003-2013 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPD_TAG_TYPE_H -#define MPD_TAG_TYPE_H - -/** - * Codes for the type of a tag item. - */ -enum tag_type { - TAG_ARTIST, - TAG_ARTIST_SORT, - TAG_ALBUM, - TAG_ALBUM_ARTIST, - TAG_ALBUM_ARTIST_SORT, - TAG_TITLE, - TAG_TRACK, - TAG_NAME, - TAG_GENRE, - TAG_DATE, - TAG_COMPOSER, - TAG_PERFORMER, - TAG_COMMENT, - TAG_DISC, - - TAG_MUSICBRAINZ_ARTISTID, - TAG_MUSICBRAINZ_ALBUMID, - TAG_MUSICBRAINZ_ALBUMARTISTID, - TAG_MUSICBRAINZ_TRACKID, - - TAG_NUM_OF_ITEM_TYPES -}; - -/** - * An array of strings, which map the #tag_type to its machine - * readable name (specific to the MPD protocol). - */ -extern const char *tag_item_names[]; - -#endif diff --git a/src/UpdateContainer.cxx b/src/UpdateContainer.cxx index 44c961a2b..a24f38830 100644 --- a/src/UpdateContainer.cxx +++ b/src/UpdateContainer.cxx @@ -27,8 +27,8 @@ #include "DecoderPlugin.hxx" #include "Mapper.hxx" #include "fs/Path.hxx" -#include "TagHandler.hxx" -#include "Tag.hxx" +#include "tag/TagHandler.hxx" +#include "tag/Tag.hxx" #include diff --git a/src/cue/CueParser.cxx b/src/cue/CueParser.cxx index e2ae6f2dd..584a77a81 100644 --- a/src/cue/CueParser.cxx +++ b/src/cue/CueParser.cxx @@ -21,7 +21,7 @@ #include "CueParser.hxx" #include "util/StringUtil.hxx" #include "Song.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include diff --git a/src/db/ProxyDatabasePlugin.cxx b/src/db/ProxyDatabasePlugin.cxx index fc8ea1535..6cf7af13f 100644 --- a/src/db/ProxyDatabasePlugin.cxx +++ b/src/db/ProxyDatabasePlugin.cxx @@ -27,7 +27,7 @@ #include "Song.hxx" #include "gcc.h" #include "ConfigData.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "util/Error.hxx" #include "util/Domain.hxx" diff --git a/src/decoder/AdPlugDecoderPlugin.cxx b/src/decoder/AdPlugDecoderPlugin.cxx index f3b986fc8..51a3f7ea7 100644 --- a/src/decoder/AdPlugDecoderPlugin.cxx +++ b/src/decoder/AdPlugDecoderPlugin.cxx @@ -19,7 +19,7 @@ #include "config.h" #include "AdPlugDecoderPlugin.h" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "DecoderAPI.hxx" #include "CheckAudioFormat.hxx" #include "util/Error.hxx" diff --git a/src/decoder/AudiofileDecoderPlugin.cxx b/src/decoder/AudiofileDecoderPlugin.cxx index d19249932..6b638bb3f 100644 --- a/src/decoder/AudiofileDecoderPlugin.cxx +++ b/src/decoder/AudiofileDecoderPlugin.cxx @@ -22,7 +22,7 @@ #include "DecoderAPI.hxx" #include "InputStream.hxx" #include "CheckAudioFormat.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "util/Error.hxx" #include diff --git a/src/decoder/DsdLib.cxx b/src/decoder/DsdLib.cxx index b093d5d66..7135c9903 100644 --- a/src/decoder/DsdLib.cxx +++ b/src/decoder/DsdLib.cxx @@ -28,7 +28,7 @@ #include "DecoderAPI.hxx" #include "InputStream.hxx" #include "util/bit_reverse.h" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "tag/TagId3.hxx" #include "util/Error.hxx" diff --git a/src/decoder/DsdiffDecoderPlugin.cxx b/src/decoder/DsdiffDecoderPlugin.cxx index 71226b8fb..49b0c601d 100644 --- a/src/decoder/DsdiffDecoderPlugin.cxx +++ b/src/decoder/DsdiffDecoderPlugin.cxx @@ -33,7 +33,7 @@ #include "CheckAudioFormat.hxx" #include "util/bit_reverse.h" #include "util/Error.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "DsdLib.hxx" #include diff --git a/src/decoder/DsfDecoderPlugin.cxx b/src/decoder/DsfDecoderPlugin.cxx index 5f2422e77..275f34929 100644 --- a/src/decoder/DsfDecoderPlugin.cxx +++ b/src/decoder/DsfDecoderPlugin.cxx @@ -35,7 +35,7 @@ #include "util/bit_reverse.h" #include "util/Error.hxx" #include "DsdLib.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include #include /* for SEEK_SET, SEEK_CUR */ diff --git a/src/decoder/FaadDecoderPlugin.cxx b/src/decoder/FaadDecoderPlugin.cxx index 7540413f5..c8acfb521 100644 --- a/src/decoder/FaadDecoderPlugin.cxx +++ b/src/decoder/FaadDecoderPlugin.cxx @@ -23,7 +23,7 @@ #include "DecoderBuffer.hxx" #include "InputStream.hxx" #include "CheckAudioFormat.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "util/Error.hxx" #include "util/Domain.hxx" diff --git a/src/decoder/FfmpegDecoderPlugin.cxx b/src/decoder/FfmpegDecoderPlugin.cxx index b9297ae2a..a0ac5b8fb 100644 --- a/src/decoder/FfmpegDecoderPlugin.cxx +++ b/src/decoder/FfmpegDecoderPlugin.cxx @@ -24,7 +24,7 @@ #include "FfmpegDecoderPlugin.hxx" #include "DecoderAPI.hxx" #include "FfmpegMetaData.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "InputStream.hxx" #include "CheckAudioFormat.hxx" #include "util/Error.hxx" diff --git a/src/decoder/FfmpegMetaData.cxx b/src/decoder/FfmpegMetaData.cxx index 132eefdaf..f4b7386ef 100644 --- a/src/decoder/FfmpegMetaData.cxx +++ b/src/decoder/FfmpegMetaData.cxx @@ -23,7 +23,7 @@ #include "config.h" #include "FfmpegMetaData.hxx" #include "tag/TagTable.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "ffmpeg" diff --git a/src/decoder/FlacMetadata.cxx b/src/decoder/FlacMetadata.cxx index f3b5ba81c..a27fec5d2 100644 --- a/src/decoder/FlacMetadata.cxx +++ b/src/decoder/FlacMetadata.cxx @@ -20,8 +20,8 @@ #include "config.h" #include "FlacMetadata.hxx" #include "XiphTags.hxx" -#include "Tag.hxx" -#include "TagHandler.hxx" +#include "tag/Tag.hxx" +#include "tag/TagHandler.hxx" #include "tag/TagTable.hxx" #include "replay_gain_info.h" diff --git a/src/decoder/GmeDecoderPlugin.cxx b/src/decoder/GmeDecoderPlugin.cxx index 006161c78..cc31c6bab 100644 --- a/src/decoder/GmeDecoderPlugin.cxx +++ b/src/decoder/GmeDecoderPlugin.cxx @@ -21,7 +21,7 @@ #include "GmeDecoderPlugin.hxx" #include "DecoderAPI.hxx" #include "CheckAudioFormat.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "util/UriUtil.hxx" #include "util/Error.hxx" diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx index 88a451412..dc2d0b806 100644 --- a/src/decoder/MadDecoderPlugin.cxx +++ b/src/decoder/MadDecoderPlugin.cxx @@ -24,7 +24,7 @@ #include "ConfigGlobal.hxx" #include "tag/TagId3.hxx" #include "tag/TagRva2.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "CheckAudioFormat.hxx" #include "util/Error.hxx" diff --git a/src/decoder/MikmodDecoderPlugin.cxx b/src/decoder/MikmodDecoderPlugin.cxx index 0de876f06..f98b22a6d 100644 --- a/src/decoder/MikmodDecoderPlugin.cxx +++ b/src/decoder/MikmodDecoderPlugin.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "MikmodDecoderPlugin.hxx" #include "DecoderAPI.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "system/FatalError.hxx" #include diff --git a/src/decoder/ModplugDecoderPlugin.cxx b/src/decoder/ModplugDecoderPlugin.cxx index 0305b582d..b5c02507a 100644 --- a/src/decoder/ModplugDecoderPlugin.cxx +++ b/src/decoder/ModplugDecoderPlugin.cxx @@ -21,7 +21,7 @@ #include "ModplugDecoderPlugin.hxx" #include "DecoderAPI.hxx" #include "InputStream.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include #include diff --git a/src/decoder/MpcdecDecoderPlugin.cxx b/src/decoder/MpcdecDecoderPlugin.cxx index 87d868f19..d9c7a17d1 100644 --- a/src/decoder/MpcdecDecoderPlugin.cxx +++ b/src/decoder/MpcdecDecoderPlugin.cxx @@ -22,7 +22,7 @@ #include "DecoderAPI.hxx" #include "InputStream.hxx" #include "CheckAudioFormat.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "util/Error.hxx" #include diff --git a/src/decoder/Mpg123DecoderPlugin.cxx b/src/decoder/Mpg123DecoderPlugin.cxx index c30455121..a44fc1241 100644 --- a/src/decoder/Mpg123DecoderPlugin.cxx +++ b/src/decoder/Mpg123DecoderPlugin.cxx @@ -21,7 +21,7 @@ #include "Mpg123DecoderPlugin.hxx" #include "DecoderAPI.hxx" #include "CheckAudioFormat.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "util/Error.hxx" #include diff --git a/src/decoder/OpusDecoderPlugin.cxx b/src/decoder/OpusDecoderPlugin.cxx index 2d378ef6c..9d852102b 100644 --- a/src/decoder/OpusDecoderPlugin.cxx +++ b/src/decoder/OpusDecoderPlugin.cxx @@ -27,7 +27,7 @@ #include "DecoderAPI.hxx" #include "OggCodec.hxx" #include "CheckAudioFormat.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "InputStream.hxx" #include "util/Error.hxx" diff --git a/src/decoder/OpusTags.cxx b/src/decoder/OpusTags.cxx index a63dc1c24..f09d79c3b 100644 --- a/src/decoder/OpusTags.cxx +++ b/src/decoder/OpusTags.cxx @@ -21,7 +21,7 @@ #include "OpusTags.hxx" #include "OpusReader.hxx" #include "XiphTags.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include #include diff --git a/src/decoder/SndfileDecoderPlugin.cxx b/src/decoder/SndfileDecoderPlugin.cxx index f61e7c2c2..252e88df5 100644 --- a/src/decoder/SndfileDecoderPlugin.cxx +++ b/src/decoder/SndfileDecoderPlugin.cxx @@ -22,7 +22,7 @@ #include "DecoderAPI.hxx" #include "InputStream.hxx" #include "CheckAudioFormat.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "util/Error.hxx" #include diff --git a/src/decoder/VorbisComments.cxx b/src/decoder/VorbisComments.cxx index eb64897d1..48c603ea4 100644 --- a/src/decoder/VorbisComments.cxx +++ b/src/decoder/VorbisComments.cxx @@ -20,9 +20,9 @@ #include "config.h" #include "VorbisComments.hxx" #include "XiphTags.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "tag/TagTable.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "replay_gain_info.h" #include diff --git a/src/decoder/VorbisDecoderPlugin.cxx b/src/decoder/VorbisDecoderPlugin.cxx index d6b0f5eb0..2b175912d 100644 --- a/src/decoder/VorbisDecoderPlugin.cxx +++ b/src/decoder/VorbisDecoderPlugin.cxx @@ -26,7 +26,7 @@ #include "util/Error.hxx" #include "util/UriUtil.hxx" #include "CheckAudioFormat.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #ifndef HAVE_TREMOR #define OV_EXCLUDE_STATIC_CALLBACKS diff --git a/src/decoder/WavpackDecoderPlugin.cxx b/src/decoder/WavpackDecoderPlugin.cxx index f37bd3f12..d0122ad87 100644 --- a/src/decoder/WavpackDecoderPlugin.cxx +++ b/src/decoder/WavpackDecoderPlugin.cxx @@ -22,7 +22,7 @@ #include "DecoderAPI.hxx" #include "InputStream.hxx" #include "CheckAudioFormat.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "tag/ApeTag.hxx" #include "util/Error.hxx" diff --git a/src/decoder/WildmidiDecoderPlugin.cxx b/src/decoder/WildmidiDecoderPlugin.cxx index 738073d52..daa0e0cc9 100644 --- a/src/decoder/WildmidiDecoderPlugin.cxx +++ b/src/decoder/WildmidiDecoderPlugin.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "WildmidiDecoderPlugin.hxx" #include "DecoderAPI.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "util/Error.hxx" #include "fs/Path.hxx" #include "fs/FileSystem.hxx" diff --git a/src/decoder/sidplay_decoder_plugin.cxx b/src/decoder/sidplay_decoder_plugin.cxx index 4e26efecb..19969c00a 100644 --- a/src/decoder/sidplay_decoder_plugin.cxx +++ b/src/decoder/sidplay_decoder_plugin.cxx @@ -19,10 +19,7 @@ #include "config.h" #include "../DecoderAPI.hxx" - -extern "C" { -#include "TagHandler.hxx" -} +#include "tag/TagHandler.hxx" #include #include diff --git a/src/encoder/VorbisEncoderPlugin.cxx b/src/encoder/VorbisEncoderPlugin.cxx index 27a368766..65a4d47e2 100644 --- a/src/encoder/VorbisEncoderPlugin.cxx +++ b/src/encoder/VorbisEncoderPlugin.cxx @@ -21,7 +21,7 @@ #include "VorbisEncoderPlugin.hxx" #include "OggStream.hxx" #include "EncoderAPI.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "AudioFormat.hxx" #include "ConfigError.hxx" #include "util/Error.hxx" diff --git a/src/input/CurlInputPlugin.cxx b/src/input/CurlInputPlugin.cxx index cd4733973..fb0401fd8 100644 --- a/src/input/CurlInputPlugin.cxx +++ b/src/input/CurlInputPlugin.cxx @@ -24,7 +24,7 @@ #include "InputPlugin.hxx" #include "ConfigGlobal.hxx" #include "ConfigData.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "IcyMetaDataParser.hxx" #include "event/MultiSocketMonitor.hxx" #include "event/Call.hxx" diff --git a/src/input/DespotifyInputPlugin.cxx b/src/input/DespotifyInputPlugin.cxx index f2b87dbcc..4e441da3c 100644 --- a/src/input/DespotifyInputPlugin.cxx +++ b/src/input/DespotifyInputPlugin.cxx @@ -23,7 +23,7 @@ #include "InputInternal.hxx" #include "InputStream.hxx" #include "InputPlugin.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" extern "C" { #include diff --git a/src/input/RewindInputPlugin.cxx b/src/input/RewindInputPlugin.cxx index bd4f01261..4bf5421db 100644 --- a/src/input/RewindInputPlugin.cxx +++ b/src/input/RewindInputPlugin.cxx @@ -22,7 +22,7 @@ #include "InputInternal.hxx" #include "InputStream.hxx" #include "InputPlugin.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include #include diff --git a/src/playlist/AsxPlaylistPlugin.cxx b/src/playlist/AsxPlaylistPlugin.cxx index 6920ec268..19fa5a0fb 100644 --- a/src/playlist/AsxPlaylistPlugin.cxx +++ b/src/playlist/AsxPlaylistPlugin.cxx @@ -23,7 +23,7 @@ #include "MemorySongEnumerator.hxx" #include "InputStream.hxx" #include "Song.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "util/Error.hxx" #include diff --git a/src/playlist/CuePlaylistPlugin.cxx b/src/playlist/CuePlaylistPlugin.cxx index 1c1433a6a..0ec5c3068 100644 --- a/src/playlist/CuePlaylistPlugin.cxx +++ b/src/playlist/CuePlaylistPlugin.cxx @@ -21,7 +21,7 @@ #include "CuePlaylistPlugin.hxx" #include "PlaylistPlugin.hxx" #include "SongEnumerator.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "Song.hxx" #include "cue/CueParser.hxx" #include "TextInputStream.hxx" diff --git a/src/playlist/DespotifyPlaylistPlugin.cxx b/src/playlist/DespotifyPlaylistPlugin.cxx index 3e6527ea7..b0394a5da 100644 --- a/src/playlist/DespotifyPlaylistPlugin.cxx +++ b/src/playlist/DespotifyPlaylistPlugin.cxx @@ -22,7 +22,7 @@ #include "DespotifyUtils.hxx" #include "PlaylistPlugin.hxx" #include "MemorySongEnumerator.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "Song.hxx" extern "C" { diff --git a/src/playlist/EmbeddedCuePlaylistPlugin.cxx b/src/playlist/EmbeddedCuePlaylistPlugin.cxx index 8c5309ac1..6b497d50c 100644 --- a/src/playlist/EmbeddedCuePlaylistPlugin.cxx +++ b/src/playlist/EmbeddedCuePlaylistPlugin.cxx @@ -27,8 +27,8 @@ #include "EmbeddedCuePlaylistPlugin.hxx" #include "PlaylistPlugin.hxx" #include "SongEnumerator.hxx" -#include "Tag.hxx" -#include "TagHandler.hxx" +#include "tag/Tag.hxx" +#include "tag/TagHandler.hxx" #include "tag/TagId3.hxx" #include "tag/ApeTag.hxx" #include "Song.hxx" diff --git a/src/playlist/ExtM3uPlaylistPlugin.cxx b/src/playlist/ExtM3uPlaylistPlugin.cxx index ff3fcbd7e..177e8857d 100644 --- a/src/playlist/ExtM3uPlaylistPlugin.cxx +++ b/src/playlist/ExtM3uPlaylistPlugin.cxx @@ -22,7 +22,7 @@ #include "PlaylistPlugin.hxx" #include "SongEnumerator.hxx" #include "Song.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "util/StringUtil.hxx" #include "TextInputStream.hxx" diff --git a/src/playlist/PlsPlaylistPlugin.cxx b/src/playlist/PlsPlaylistPlugin.cxx index 946fe9c55..721f9adab 100644 --- a/src/playlist/PlsPlaylistPlugin.cxx +++ b/src/playlist/PlsPlaylistPlugin.cxx @@ -23,7 +23,7 @@ #include "MemorySongEnumerator.hxx" #include "InputStream.hxx" #include "Song.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "util/Error.hxx" #include diff --git a/src/playlist/RssPlaylistPlugin.cxx b/src/playlist/RssPlaylistPlugin.cxx index 97c0d806b..cd42606d6 100644 --- a/src/playlist/RssPlaylistPlugin.cxx +++ b/src/playlist/RssPlaylistPlugin.cxx @@ -23,7 +23,7 @@ #include "MemorySongEnumerator.hxx" #include "InputStream.hxx" #include "Song.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "util/Error.hxx" #include diff --git a/src/playlist/SoundCloudPlaylistPlugin.cxx b/src/playlist/SoundCloudPlaylistPlugin.cxx index f822382fc..e6dbf5cf9 100644 --- a/src/playlist/SoundCloudPlaylistPlugin.cxx +++ b/src/playlist/SoundCloudPlaylistPlugin.cxx @@ -24,7 +24,7 @@ #include "ConfigData.hxx" #include "InputStream.hxx" #include "Song.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "util/Error.hxx" #include diff --git a/src/playlist/XspfPlaylistPlugin.cxx b/src/playlist/XspfPlaylistPlugin.cxx index 002a03f8a..797fd7f3a 100644 --- a/src/playlist/XspfPlaylistPlugin.cxx +++ b/src/playlist/XspfPlaylistPlugin.cxx @@ -22,7 +22,7 @@ #include "PlaylistPlugin.hxx" #include "MemorySongEnumerator.hxx" #include "InputStream.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "util/Error.hxx" #include diff --git a/src/tag/Tag.cxx b/src/tag/Tag.cxx new file mode 100644 index 000000000..c960da537 --- /dev/null +++ b/src/tag/Tag.cxx @@ -0,0 +1,509 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include "Tag.hxx" +#include "TagInternal.hxx" +#include "TagPool.hxx" +#include "ConfigGlobal.hxx" +#include "ConfigOption.hxx" +#include "Song.hxx" +#include "system/FatalError.hxx" + +#include +#include +#include +#include +#include + +/** + * Maximum number of items managed in the bulk list; if it is + * exceeded, we switch back to "normal" reallocation. + */ +#define BULK_MAX 64 + +static struct { +#ifndef NDEBUG + bool busy; +#endif + TagItem *items[BULK_MAX]; +} bulk; + +bool ignore_tag_items[TAG_NUM_OF_ITEM_TYPES]; + +enum tag_type +tag_name_parse(const char *name) +{ + assert(name != nullptr); + + for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) { + assert(tag_item_names[i] != nullptr); + + if (strcmp(name, tag_item_names[i]) == 0) + return (enum tag_type)i; + } + + return TAG_NUM_OF_ITEM_TYPES; +} + +enum tag_type +tag_name_parse_i(const char *name) +{ + assert(name != nullptr); + + for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i) { + assert(tag_item_names[i] != nullptr); + + if (g_ascii_strcasecmp(name, tag_item_names[i]) == 0) + return (enum tag_type)i; + } + + return TAG_NUM_OF_ITEM_TYPES; +} + +static size_t +items_size(const Tag &tag) +{ + return tag.num_items * sizeof(TagItem *); +} + +void tag_lib_init(void) +{ + const char *value; + int quit = 0; + char *temp; + char *s; + char *c; + enum tag_type type; + + /* parse the "metadata_to_use" config parameter below */ + + /* ignore comments by default */ + ignore_tag_items[TAG_COMMENT] = true; + + value = config_get_string(CONF_METADATA_TO_USE, nullptr); + if (value == nullptr) + return; + + memset(ignore_tag_items, true, TAG_NUM_OF_ITEM_TYPES); + + if (0 == g_ascii_strcasecmp(value, "none")) + return; + + temp = c = s = g_strdup(value); + while (!quit) { + if (*s == ',' || *s == '\0') { + if (*s == '\0') + quit = 1; + *s = '\0'; + + c = g_strstrip(c); + if (*c == 0) + continue; + + type = tag_name_parse_i(c); + if (type == TAG_NUM_OF_ITEM_TYPES) + FormatFatalError("error parsing metadata item \"%s\"", + c); + + ignore_tag_items[type] = false; + + s++; + c = s; + } + s++; + } + + g_free(temp); +} + +void +Tag::Clear() +{ + time = -1; + has_playlist = false; + + tag_pool_lock.lock(); + for (unsigned i = 0; i < num_items; ++i) + tag_pool_put_item(items[i]); + tag_pool_lock.unlock(); + + if (items == bulk.items) { +#ifndef NDEBUG + assert(bulk.busy); + bulk.busy = false; +#endif + } else + g_free(items); + + items = nullptr; + num_items = 0; +} + +void +Tag::DeleteItem(unsigned idx) +{ + assert(idx < num_items); + --num_items; + + tag_pool_lock.lock(); + tag_pool_put_item(items[idx]); + tag_pool_lock.unlock(); + + if (num_items - idx > 0) { + memmove(items + idx, items + idx + 1, + (num_items - idx) * sizeof(items[0])); + } + + if (num_items > 0) { + items = (TagItem **) + g_realloc(items, items_size(*this)); + } else { + g_free(items); + items = nullptr; + } +} + +void +Tag::ClearItemsByType(tag_type type) +{ + for (unsigned i = 0; i < num_items; i++) { + if (items[i]->type == type) { + DeleteItem(i); + /* decrement since when just deleted this node */ + i--; + } + } +} + +Tag::~Tag() +{ + tag_pool_lock.lock(); + for (int i = num_items; --i >= 0; ) + tag_pool_put_item(items[i]); + tag_pool_lock.unlock(); + + if (items == bulk.items) { +#ifndef NDEBUG + assert(bulk.busy); + bulk.busy = false; +#endif + } else + g_free(items); +} + +Tag::Tag(const Tag &other) + :time(other.time), has_playlist(other.has_playlist), + items(nullptr), + num_items(other.num_items) +{ + if (num_items > 0) { + items = (TagItem **)g_malloc(items_size(other)); + + tag_pool_lock.lock(); + for (unsigned i = 0; i < num_items; i++) + items[i] = tag_pool_dup_item(other.items[i]); + tag_pool_lock.unlock(); + } +} + +Tag * +Tag::Merge(const Tag &base, const Tag &add) +{ + unsigned n; + + /* allocate new tag object */ + + Tag *ret = new Tag(); + ret->time = add.time > 0 ? add.time : base.time; + ret->num_items = base.num_items + add.num_items; + ret->items = ret->num_items > 0 + ? (TagItem **)g_malloc(items_size(*ret)) + : nullptr; + + tag_pool_lock.lock(); + + /* copy all items from "add" */ + + for (unsigned i = 0; i < add.num_items; ++i) + ret->items[i] = tag_pool_dup_item(add.items[i]); + + n = add.num_items; + + /* copy additional items from "base" */ + + for (unsigned i = 0; i < base.num_items; ++i) + if (!add.HasType(base.items[i]->type)) + ret->items[n++] = tag_pool_dup_item(base.items[i]); + + tag_pool_lock.unlock(); + + assert(n <= ret->num_items); + + if (n < ret->num_items) { + /* some tags were not copied - shrink ret->items */ + assert(n > 0); + + ret->num_items = n; + ret->items = (TagItem **) + g_realloc(ret->items, items_size(*ret)); + } + + return ret; +} + +Tag * +Tag::MergeReplace(Tag *base, Tag *add) +{ + if (add == nullptr) + return base; + + if (base == nullptr) + return add; + + Tag *tag = Merge(*base, *add); + delete base; + delete add; + + return tag; +} + +const char * +Tag::GetValue(tag_type type) const +{ + assert(type < TAG_NUM_OF_ITEM_TYPES); + + for (unsigned i = 0; i < num_items; i++) + if (items[i]->type == type) + return items[i]->value; + + return nullptr; +} + +bool +Tag::HasType(tag_type type) const +{ + return GetValue(type) != nullptr; +} + +bool +Tag::Equals(const Tag &other) const +{ + if (time != other.time) + return false; + + if (num_items != other.num_items) + return false; + + for (unsigned i = 0; i < num_items; i++) { + if (items[i]->type != other.items[i]->type) + return false; + if (strcmp(items[i]->value, other.items[i]->value)) { + return false; + } + } + + return true; +} + +/** + * Replace invalid sequences with the question mark. + */ +static char * +patch_utf8(const char *src, size_t length, const gchar *end) +{ + /* duplicate the string, and replace invalid bytes in that + buffer */ + char *dest = g_strdup(src); + + do { + dest[end - src] = '?'; + } while (!g_utf8_validate(end + 1, (src + length) - (end + 1), &end)); + + return dest; +} + +static char * +fix_utf8(const char *str, size_t length) +{ + const gchar *end; + char *temp; + gsize written; + + assert(str != nullptr); + + /* check if the string is already valid UTF-8 */ + if (g_utf8_validate(str, length, &end)) + return nullptr; + + /* no, it's not - try to import it from ISO-Latin-1 */ + temp = g_convert(str, length, "utf-8", "iso-8859-1", + nullptr, &written, nullptr); + if (temp != nullptr) + /* success! */ + return temp; + + /* no, still broken - there's no medication, just patch + invalid sequences */ + return patch_utf8(str, length, end); +} + +void +Tag::BeginAdd() +{ + assert(!bulk.busy); + assert(items == nullptr); + assert(num_items == 0); + +#ifndef NDEBUG + bulk.busy = true; +#endif + items = bulk.items; +} + +void +Tag::EndAdd() +{ + if (items == bulk.items) { + assert(num_items <= BULK_MAX); + + if (num_items > 0) { + /* copy the tag items from the bulk list over + to a new list (which fits exactly) */ + items = (TagItem **) + g_malloc(items_size(*this)); + memcpy(items, bulk.items, items_size(*this)); + } else + items = nullptr; + } + +#ifndef NDEBUG + bulk.busy = false; +#endif +} + +static bool +char_is_non_printable(unsigned char ch) +{ + return ch < 0x20; +} + +static const char * +find_non_printable(const char *p, size_t length) +{ + for (size_t i = 0; i < length; ++i) + if (char_is_non_printable(p[i])) + return p + i; + + return nullptr; +} + +/** + * Clears all non-printable characters, convert them to space. + * Returns nullptr if nothing needs to be cleared. + */ +static char * +clear_non_printable(const char *p, size_t length) +{ + const char *first = find_non_printable(p, length); + char *dest; + + if (first == nullptr) + return nullptr; + + dest = g_strndup(p, length); + + for (size_t i = first - p; i < length; ++i) + if (char_is_non_printable(dest[i])) + dest[i] = ' '; + + return dest; +} + +static char * +fix_tag_value(const char *p, size_t length) +{ + char *utf8, *cleared; + + utf8 = fix_utf8(p, length); + if (utf8 != nullptr) { + p = utf8; + length = strlen(p); + } + + cleared = clear_non_printable(p, length); + if (cleared == nullptr) + cleared = utf8; + else + g_free(utf8); + + return cleared; +} + +void +Tag::AddItemInternal(tag_type type, const char *value, size_t len) +{ + unsigned int i = num_items; + char *p; + + p = fix_tag_value(value, len); + if (p != nullptr) { + value = p; + len = strlen(value); + } + + num_items++; + + if (items != bulk.items) + /* bulk mode disabled */ + items = (TagItem **) + g_realloc(items, items_size(*this)); + else if (num_items >= BULK_MAX) { + /* bulk list already full - switch back to non-bulk */ + assert(bulk.busy); + + items = (TagItem **)g_malloc(items_size(*this)); + memcpy(items, bulk.items, + items_size(*this) - sizeof(TagItem *)); + } + + tag_pool_lock.lock(); + items[i] = tag_pool_get_item(type, value, len); + tag_pool_lock.unlock(); + + g_free(p); +} + +void +Tag::AddItem(tag_type type, const char *value, size_t len) +{ + if (ignore_tag_items[type]) + return; + + if (value == nullptr || len == 0) + return; + + AddItemInternal(type, value, len); +} + +void +Tag::AddItem(tag_type type, const char *value) +{ + AddItem(type, value, strlen(value)); +} diff --git a/src/tag/Tag.hxx b/src/tag/Tag.hxx new file mode 100644 index 000000000..2c5f599e2 --- /dev/null +++ b/src/tag/Tag.hxx @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_TAG_HXX +#define MPD_TAG_HXX + +#include "TagType.h" +#include "gcc.h" + +#include + +#include + +/** + * One tag value. It is a mapping of #tag_type to am arbitrary string + * value. Each tag can have multiple items of one tag type (although + * few clients support that). + */ +struct TagItem { + /** the type of this item */ + enum tag_type type; + + /** + * the value of this tag; this is a variable length string + */ + char value[sizeof(long)]; +} gcc_packed; + +/** + * The meta information about a song file. It is a MPD specific + * subset of tags (e.g. from ID3, vorbis comments, ...). + */ +struct Tag { + /** + * The duration of the song (in seconds). A value of zero + * means that the length is unknown. If the duration is + * really between zero and one second, you should round up to + * 1. + */ + int time; + + /** + * Does this file have an embedded playlist (e.g. embedded CUE + * sheet)? + */ + bool has_playlist; + + /** an array of tag items */ + TagItem **items; + + /** the total number of tag items in the #items array */ + unsigned num_items; + + /** + * Create an empty tag. + */ + Tag():time(-1), has_playlist(false), + items(nullptr), num_items(0) {} + + Tag(const Tag &other); + + Tag(Tag &&other) + :time(other.time), has_playlist(other.has_playlist), + items(other.items), num_items(other.num_items) { + other.items = nullptr; + other.num_items = 0; + } + + /** + * Free the tag object and all its items. + */ + ~Tag(); + + Tag &operator=(const Tag &other) = delete; + + Tag &operator=(Tag &&other) { + time = other.time; + has_playlist = other.has_playlist; + std::swap(items, other.items); + std::swap(num_items, other.num_items); + return *this; + } + + /** + * Returns true if the tag contains no items. This ignores the "time" + * attribute. + */ + bool IsEmpty() const { + return num_items == 0; + } + + /** + * Returns true if the tag contains any information. + */ + bool IsDefined() const { + return !IsEmpty() || time >= 0; + } + + /** + * Clear everything, as if this was a new Tag object. + */ + void Clear(); + + void DeleteItem(unsigned i); + + /** + * Clear all tag items with the specified type. + */ + void ClearItemsByType(tag_type type); + + /** + * Gives an optional hint to the tag library that we will now + * add several tag items; this is used by the library to + * optimize memory allocation. Only one tag may be in this + * state, and this tag must not have any items yet. You must + * call tag_end_add() when you are done. + */ + void BeginAdd(); + + /** + * Finishes the operation started with tag_begin_add(). + */ + void EndAdd(); + + /** + * Appends a new tag item. + * + * @param type the type of the new tag item + * @param value the value of the tag item (not null-terminated) + * @param len the length of #value + */ + void AddItem(tag_type type, const char *value, size_t len); + + /** + * Appends a new tag item. + * + * @param tag the #tag object + * @param type the type of the new tag item + * @param value the value of the tag item (null-terminated) + */ + void AddItem(tag_type type, const char *value); + + /** + * Merges the data from two tags. If both tags share data for the + * same tag_type, only data from "add" is used. + * + * @return a newly allocated tag + */ + gcc_malloc + static Tag *Merge(const Tag &base, const Tag &add); + + /** + * Merges the data from two tags. Any of the two may be NULL. Both + * are freed by this function. + * + * @return a newly allocated tag + */ + gcc_malloc + static Tag *MergeReplace(Tag *base, Tag *add); + + /** + * Returns the first value of the specified tag type, or NULL if none + * is present in this tag object. + */ + gcc_pure + const char *GetValue(tag_type type) const; + + /** + * Checks whether the tag contains one or more items with + * the specified type. + */ + bool HasType(tag_type type) const; + + /** + * Compares two tags, including the duration and all tag items. The + * order of the tag items matters. + */ + gcc_pure + bool Equals(const Tag &other) const; + +private: + void AddItemInternal(tag_type type, const char *value, size_t len); +}; + +/** + * Parse the string, and convert it into a #tag_type. Returns + * #TAG_NUM_OF_ITEM_TYPES if the string could not be recognized. + */ +enum tag_type +tag_name_parse(const char *name); + +/** + * Parse the string, and convert it into a #tag_type. Returns + * #TAG_NUM_OF_ITEM_TYPES if the string could not be recognized. + * + * Case does not matter. + */ +enum tag_type +tag_name_parse_i(const char *name); + +/** + * Initializes the tag library. + */ +void +tag_lib_init(); + +#endif diff --git a/src/tag/TagHandler.cxx b/src/tag/TagHandler.cxx new file mode 100644 index 000000000..055fae49a --- /dev/null +++ b/src/tag/TagHandler.cxx @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include "TagHandler.hxx" +#include "Tag.hxx" + +#include + +static void +add_tag_duration(unsigned seconds, void *ctx) +{ + Tag *tag = (Tag *)ctx; + + tag->time = seconds; +} + +static void +add_tag_tag(enum tag_type type, const char *value, void *ctx) +{ + Tag *tag = (Tag *)ctx; + + tag->AddItem(type, value); +} + +const struct tag_handler add_tag_handler = { + add_tag_duration, + add_tag_tag, + nullptr, +}; + +static void +full_tag_pair(const char *name, gcc_unused const char *value, void *ctx) +{ + Tag *tag = (Tag *)ctx; + + if (g_ascii_strcasecmp(name, "cuesheet") == 0) + tag->has_playlist = true; +} + +const struct tag_handler full_tag_handler = { + add_tag_duration, + add_tag_tag, + full_tag_pair, +}; + diff --git a/src/tag/TagHandler.hxx b/src/tag/TagHandler.hxx new file mode 100644 index 000000000..3303dd27e --- /dev/null +++ b/src/tag/TagHandler.hxx @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_TAG_HANDLER_HXX +#define MPD_TAG_HANDLER_HXX + +#include "check.h" +#include "TagType.h" + +#include + +/** + * A callback table for receiving metadata of a song. + */ +struct tag_handler { + /** + * Declare the duration of a song, in seconds. Do not call + * this when the duration could not be determined, because + * there is no magic value for "unknown duration". + */ + void (*duration)(unsigned seconds, void *ctx); + + /** + * A tag has been read. + * + * @param the value of the tag; the pointer will become + * invalid after returning + */ + void (*tag)(enum tag_type type, const char *value, void *ctx); + + /** + * A name-value pair has been read. It is the codec specific + * representation of tags. + */ + void (*pair)(const char *key, const char *value, void *ctx); +}; + +static inline void +tag_handler_invoke_duration(const struct tag_handler *handler, void *ctx, + unsigned seconds) +{ + assert(handler != nullptr); + + if (handler->duration != nullptr) + handler->duration(seconds, ctx); +} + +static inline void +tag_handler_invoke_tag(const struct tag_handler *handler, void *ctx, + enum tag_type type, const char *value) +{ + assert(handler != nullptr); + assert((unsigned)type < TAG_NUM_OF_ITEM_TYPES); + assert(value != nullptr); + + if (handler->tag != nullptr) + handler->tag(type, value, ctx); +} + +static inline void +tag_handler_invoke_pair(const struct tag_handler *handler, void *ctx, + const char *name, const char *value) +{ + assert(handler != nullptr); + assert(name != nullptr); + assert(value != nullptr); + + if (handler->pair != nullptr) + handler->pair(name, value, ctx); +} + +/** + * This #tag_handler implementation adds tag values to a #tag object + * (casted from the context pointer). + */ +extern const struct tag_handler add_tag_handler; + +/** + * This #tag_handler implementation adds tag values to a #tag object + * (casted from the context pointer), and supports the has_playlist + * attribute. + */ +extern const struct tag_handler full_tag_handler; + +#endif diff --git a/src/tag/TagInternal.hxx b/src/tag/TagInternal.hxx new file mode 100644 index 000000000..8172d1319 --- /dev/null +++ b/src/tag/TagInternal.hxx @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_TAG_INTERNAL_HXX +#define MPD_TAG_INTERNAL_HXX + +#include "TagType.h" + +extern bool ignore_tag_items[TAG_NUM_OF_ITEM_TYPES]; + +#endif diff --git a/src/tag/TagNames.c b/src/tag/TagNames.c new file mode 100644 index 000000000..2e318f913 --- /dev/null +++ b/src/tag/TagNames.c @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include "TagType.h" + +const char *tag_item_names[TAG_NUM_OF_ITEM_TYPES] = { + [TAG_ARTIST] = "Artist", + [TAG_ARTIST_SORT] = "ArtistSort", + [TAG_ALBUM] = "Album", + [TAG_ALBUM_ARTIST] = "AlbumArtist", + [TAG_ALBUM_ARTIST_SORT] = "AlbumArtistSort", + [TAG_TITLE] = "Title", + [TAG_TRACK] = "Track", + [TAG_NAME] = "Name", + [TAG_GENRE] = "Genre", + [TAG_DATE] = "Date", + [TAG_COMPOSER] = "Composer", + [TAG_PERFORMER] = "Performer", + [TAG_COMMENT] = "Comment", + [TAG_DISC] = "Disc", + + /* MusicBrainz tags from http://musicbrainz.org/doc/MusicBrainzTag */ + [TAG_MUSICBRAINZ_ARTISTID] = "MUSICBRAINZ_ARTISTID", + [TAG_MUSICBRAINZ_ALBUMID] = "MUSICBRAINZ_ALBUMID", + [TAG_MUSICBRAINZ_ALBUMARTISTID] = "MUSICBRAINZ_ALBUMARTISTID", + [TAG_MUSICBRAINZ_TRACKID] = "MUSICBRAINZ_TRACKID", +}; diff --git a/src/tag/TagPool.cxx b/src/tag/TagPool.cxx new file mode 100644 index 000000000..5a0b33c47 --- /dev/null +++ b/src/tag/TagPool.cxx @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include "TagPool.hxx" +#include "Tag.hxx" + +#include + +#include +#include + +Mutex tag_pool_lock; + +#define NUM_SLOTS 4096 + +struct slot { + struct slot *next; + unsigned char ref; + TagItem item; +} mpd_packed; + +static struct slot *slots[NUM_SLOTS]; + +static inline unsigned +calc_hash_n(enum tag_type type, const char *p, size_t length) +{ + unsigned hash = 5381; + + assert(p != nullptr); + + while (length-- > 0) + hash = (hash << 5) + hash + *p++; + + return hash ^ type; +} + +static inline unsigned +calc_hash(enum tag_type type, const char *p) +{ + unsigned hash = 5381; + + assert(p != nullptr); + + while (*p != 0) + hash = (hash << 5) + hash + *p++; + + return hash ^ type; +} + +static inline struct slot * +tag_item_to_slot(TagItem *item) +{ + return (struct slot*)(((char*)item) - offsetof(struct slot, item)); +} + +static struct slot *slot_alloc(struct slot *next, + enum tag_type type, + const char *value, int length) +{ + struct slot *slot; + + slot = (struct slot *) + g_malloc(sizeof(*slot) - sizeof(slot->item.value) + length + 1); + slot->next = next; + slot->ref = 1; + slot->item.type = type; + memcpy(slot->item.value, value, length); + slot->item.value[length] = 0; + return slot; +} + +TagItem * +tag_pool_get_item(enum tag_type type, const char *value, size_t length) +{ + struct slot **slot_p, *slot; + + slot_p = &slots[calc_hash_n(type, value, length) % NUM_SLOTS]; + for (slot = *slot_p; slot != nullptr; slot = slot->next) { + if (slot->item.type == type && + length == strlen(slot->item.value) && + memcmp(value, slot->item.value, length) == 0 && + slot->ref < 0xff) { + assert(slot->ref > 0); + ++slot->ref; + return &slot->item; + } + } + + slot = slot_alloc(*slot_p, type, value, length); + *slot_p = slot; + return &slot->item; +} + +TagItem * +tag_pool_dup_item(TagItem *item) +{ + struct slot *slot = tag_item_to_slot(item); + + assert(slot->ref > 0); + + if (slot->ref < 0xff) { + ++slot->ref; + return item; + } else { + /* the reference counter overflows above 0xff; + duplicate the item, and start with 1 */ + size_t length = strlen(item->value); + struct slot **slot_p = + &slots[calc_hash_n(item->type, item->value, + length) % NUM_SLOTS]; + slot = slot_alloc(*slot_p, item->type, + item->value, strlen(item->value)); + *slot_p = slot; + return &slot->item; + } +} + +void +tag_pool_put_item(TagItem *item) +{ + struct slot **slot_p, *slot; + + slot = tag_item_to_slot(item); + assert(slot->ref > 0); + --slot->ref; + + if (slot->ref > 0) + return; + + for (slot_p = &slots[calc_hash(item->type, item->value) % NUM_SLOTS]; + *slot_p != slot; + slot_p = &(*slot_p)->next) { + assert(*slot_p != nullptr); + } + + *slot_p = slot->next; + g_free(slot); +} diff --git a/src/tag/TagPool.hxx b/src/tag/TagPool.hxx new file mode 100644 index 000000000..a6b28b355 --- /dev/null +++ b/src/tag/TagPool.hxx @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_TAG_POOL_HXX +#define MPD_TAG_POOL_HXX + +#include "TagType.h" +#include "thread/Mutex.hxx" + +extern Mutex tag_pool_lock; + +struct TagItem; + +TagItem * +tag_pool_get_item(enum tag_type type, const char *value, size_t length); + +TagItem * +tag_pool_dup_item(TagItem *item); + +void +tag_pool_put_item(TagItem *item); + +#endif diff --git a/src/tag/TagType.h b/src/tag/TagType.h new file mode 100644 index 000000000..7a1d351a5 --- /dev/null +++ b/src/tag/TagType.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_TAG_TYPE_H +#define MPD_TAG_TYPE_H + +/** + * Codes for the type of a tag item. + */ +enum tag_type { + TAG_ARTIST, + TAG_ARTIST_SORT, + TAG_ALBUM, + TAG_ALBUM_ARTIST, + TAG_ALBUM_ARTIST_SORT, + TAG_TITLE, + TAG_TRACK, + TAG_NAME, + TAG_GENRE, + TAG_DATE, + TAG_COMPOSER, + TAG_PERFORMER, + TAG_COMMENT, + TAG_DISC, + + TAG_MUSICBRAINZ_ARTISTID, + TAG_MUSICBRAINZ_ALBUMID, + TAG_MUSICBRAINZ_ALBUMARTISTID, + TAG_MUSICBRAINZ_TRACKID, + + TAG_NUM_OF_ITEM_TYPES +}; + +/** + * An array of strings, which map the #tag_type to its machine + * readable name (specific to the MPD protocol). + */ +extern const char *tag_item_names[]; + +#endif diff --git a/test/DumpDatabase.cxx b/test/DumpDatabase.cxx index 03ea37ee6..3544826f2 100644 --- a/test/DumpDatabase.cxx +++ b/test/DumpDatabase.cxx @@ -26,7 +26,7 @@ #include "PlaylistVector.hxx" #include "ConfigGlobal.hxx" #include "ConfigData.hxx" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "fs/Path.hxx" #include "util/Error.hxx" diff --git a/test/dump_rva2.cxx b/test/dump_rva2.cxx index 711786869..068faf252 100644 --- a/test/dump_rva2.cxx +++ b/test/dump_rva2.cxx @@ -18,11 +18,11 @@ */ #include "config.h" +#include "tag/Tag.hxx" #include "tag/TagId3.hxx" #include "tag/TagRva2.hxx" #include "replay_gain_info.h" #include "ConfigGlobal.hxx" -#include "Tag.hxx" #include "util/Error.hxx" #include diff --git a/test/read_tags.cxx b/test/read_tags.cxx index dc7a6df65..de100134b 100644 --- a/test/read_tags.cxx +++ b/test/read_tags.cxx @@ -24,7 +24,7 @@ #include "InputInit.hxx" #include "InputStream.hxx" #include "AudioFormat.hxx" -#include "TagHandler.hxx" +#include "tag/TagHandler.hxx" #include "tag/TagId3.hxx" #include "tag/ApeTag.hxx" #include "util/Error.hxx" diff --git a/test/run_input.cxx b/test/run_input.cxx index 9f44276f3..79b57536a 100644 --- a/test/run_input.cxx +++ b/test/run_input.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "TagSave.hxx" #include "stdbin.h" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "ConfigGlobal.hxx" #include "InputStream.hxx" #include "InputInit.hxx" diff --git a/test/test_vorbis_encoder.cxx b/test/test_vorbis_encoder.cxx index 676237ccb..1d95f6deb 100644 --- a/test/test_vorbis_encoder.cxx +++ b/test/test_vorbis_encoder.cxx @@ -23,7 +23,7 @@ #include "AudioFormat.hxx" #include "ConfigData.hxx" #include "stdbin.h" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "util/Error.hxx" #include diff --git a/test/visit_archive.cxx b/test/visit_archive.cxx index 68dfd1988..6e66c4696 100644 --- a/test/visit_archive.cxx +++ b/test/visit_archive.cxx @@ -19,7 +19,7 @@ #include "config.h" #include "stdbin.h" -#include "Tag.hxx" +#include "tag/Tag.hxx" #include "ConfigGlobal.hxx" #include "IOThread.hxx" #include "InputInit.hxx" -- cgit v1.2.3