diff options
author | Martijn Kaijser <martijn@xbmc.org> | 2017-01-26 14:46:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-26 14:46:16 +0100 |
commit | 0ec98b9fa5d3e8cb5eb4f9f83e193c9d0905b60c (patch) | |
tree | defef4ff6c24195acddebe677615ac30d8736322 | |
parent | 2785739e53dc1274faf4bc2b4c1fb2a1b467a994 (diff) | |
parent | a76c914e26bc926cb34827732962ca1837085e4c (diff) |
Merge pull request #11548 from Rechi/taglibPatchKrypton
[depends] patch taglib: Efficient lookup for an ID3v2 tag in MPEG fil…
-rw-r--r-- | tools/depends/target/taglib/ID3v2Lookup.patch | 72 | ||||
-rw-r--r-- | tools/depends/target/taglib/Makefile | 3 |
2 files changed, 74 insertions, 1 deletions
diff --git a/tools/depends/target/taglib/ID3v2Lookup.patch b/tools/depends/target/taglib/ID3v2Lookup.patch new file mode 100644 index 0000000000..b31cf6a089 --- /dev/null +++ b/tools/depends/target/taglib/ID3v2Lookup.patch @@ -0,0 +1,72 @@ +From d2e0e5522308ce4c905c205c7bf5972ea71cd6e5 Mon Sep 17 00:00:00 2001 +From: Tsuda Kageyu <tsuda.kageyu@gmail.com> +Date: Fri, 20 Jan 2017 21:14:38 +0900 +Subject: [PATCH] Efficient lookup for an ID3v2 tag in MPEG files with garbage. + +This looks for an ID3v2 tag until reaching the first valid MPEG frame in O(n) time. +--- + taglib/mpeg/mpegfile.cpp | 45 +++++++++++++++++++++++++++++---------------- + 1 file changed, 29 insertions(+), 16 deletions(-) + +diff --git a/taglib/mpeg/mpegfile.cpp b/taglib/mpeg/mpegfile.cpp +index af7253f..c634eeb 100644 +--- a/taglib/mpeg/mpegfile.cpp ++++ b/taglib/mpeg/mpegfile.cpp +@@ -488,28 +488,41 @@ long MPEG::File::findID3v2() + const ByteVector headerID = ID3v2::Header::fileIdentifier(); + + seek(0); ++ if(readBlock(headerID.size()) == headerID) ++ return 0; + +- const ByteVector data = readBlock(headerID.size()); +- if(data.size() < headerID.size()) ++ Header firstHeader(this, 0, true); ++ if(firstHeader.isValid()) + return -1; + +- if(data == headerID) +- return 0; ++ // Look for an ID3v2 tag until reaching the first valid MPEG frame. + +- if(firstSyncByte(data[0]) && secondSynchByte(data[1])) +- return -1; ++ char frameSyncBytes[2] = {}; ++ char tagHeaderBytes[4] = {}; ++ long position = 0; + +- // Look for the entire file, if neither an MEPG frame or ID3v2 tag was found +- // at the beginning of the file. +- // We don't care about the inefficiency of the code, since this is a seldom case. ++ while(true) { ++ seek(position); ++ const ByteVector buffer = readBlock(bufferSize()); ++ if(buffer.isEmpty()) ++ return -1; + +- const long tagOffset = find(headerID); +- if(tagOffset < 0) +- return -1; ++ for(unsigned int i = 0; i < buffer.size(); ++i) { ++ frameSyncBytes[0] = frameSyncBytes[1]; ++ frameSyncBytes[1] = buffer[i]; ++ if(firstSyncByte(frameSyncBytes[0]) && secondSynchByte(frameSyncBytes[1])) { ++ Header header(this, position + i - 1, true); ++ if(header.isValid()) ++ return -1; ++ } + +- const long frameOffset = firstFrameOffset(); +- if(frameOffset < tagOffset) +- return -1; ++ tagHeaderBytes[0] = tagHeaderBytes[1]; ++ tagHeaderBytes[1] = tagHeaderBytes[2]; ++ tagHeaderBytes[2] = buffer[i]; ++ if(headerID == tagHeaderBytes) ++ return position + i - 2; ++ } + +- return tagOffset; ++ position += bufferSize(); ++ } + } diff --git a/tools/depends/target/taglib/Makefile b/tools/depends/target/taglib/Makefile index bc619c045b..069de1a65c 100644 --- a/tools/depends/target/taglib/Makefile +++ b/tools/depends/target/taglib/Makefile @@ -1,5 +1,5 @@ include ../../Makefile.include -DEPS= ../../Makefile.include Makefile +DEPS= ../../Makefile.include Makefile ID3v2Lookup.patch LIBNAME=taglib VERSION=1.11 @@ -16,6 +16,7 @@ $(PLATFORM): $(TARBALLS_LOCATION)/$(ARCHIVE) $(DEPS) rm -rf $(PLATFORM); mkdir -p $(PLATFORM) cd $(PLATFORM); $(ARCHIVE_TOOL) $(ARCHIVE_TOOL_FLAGS) $(TARBALLS_LOCATION)/$(ARCHIVE) cd $(PLATFORM); rm -rf build; mkdir -p build + cd $(PLATFORM); patch -p1 -i ../ID3v2Lookup.patch cd $(PLATFORM)/build; $(CMAKE) -DCMAKE_LIBRARY_PATH=$(TOOLCHAIN)/lib/$(HOST) -DBUILD_SHARED_LIBS=OFF .. $(LIBDYLIB): $(PLATFORM) |