From e99910dd74cf21dc2bc8efc10c1c816d7b45002d Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Thu, 3 Dec 2015 10:06:04 +0900 Subject: [PATCH] Revert some ABI breaking changes. --- taglib/ape/apetag.cpp | 26 ++++++++++++++++++-------- taglib/ape/apetag.h | 2 +- taglib/mpeg/id3v1/id3v1tag.cpp | 18 +++++++++++++----- taglib/mpeg/id3v1/id3v1tag.h | 2 +- taglib/mpeg/id3v2/id3v2tag.cpp | 34 +++++++++++++++++----------------- taglib/mpeg/id3v2/id3v2tag.h | 2 +- 6 files changed, 51 insertions(+), 33 deletions(-) diff --git a/taglib/ape/apetag.cpp b/taglib/ape/apetag.cpp index 16e56c1f..4b020413 100644 --- a/taglib/ape/apetag.cpp +++ b/taglib/ape/apetag.cpp @@ -46,6 +46,13 @@ using namespace APE; class APE::Tag::TagPrivate { public: + TagPrivate() : + file(0), + footerLocation(0) {} + + File *file; + long footerLocation; + Footer footer; ItemListMap itemListMap; }; @@ -64,7 +71,10 @@ APE::Tag::Tag(TagLib::File *file, long footerLocation) : TagLib::Tag(), d(new TagPrivate()) { - read(file, footerLocation); + d->file = file; + d->footerLocation = footerLocation; + + read(); } APE::Tag::~Tag() @@ -325,19 +335,19 @@ bool APE::Tag::isEmpty() const // protected methods //////////////////////////////////////////////////////////////////////////////// -void APE::Tag::read(TagLib::File *file, long footerLocation) +void APE::Tag::read() { - if(file && file->isValid()) { + if(d->file && d->file->isValid()) { - file->seek(footerLocation); - d->footer.setData(file->readBlock(Footer::size())); + d->file->seek(d->footerLocation); + d->footer.setData(d->file->readBlock(Footer::size())); if(d->footer.tagSize() <= Footer::size() || - d->footer.tagSize() > static_cast(file->length())) + d->footer.tagSize() > static_cast(d->file->length())) return; - file->seek(footerLocation + Footer::size() - d->footer.tagSize()); - parse(file->readBlock(d->footer.tagSize() - Footer::size())); + d->file->seek(d->footerLocation + Footer::size() - d->footer.tagSize()); + parse(d->file->readBlock(d->footer.tagSize() - Footer::size())); } } diff --git a/taglib/ape/apetag.h b/taglib/ape/apetag.h index b76419ee..f4d4fba6 100644 --- a/taglib/ape/apetag.h +++ b/taglib/ape/apetag.h @@ -188,7 +188,7 @@ namespace TagLib { /*! * Reads from the file specified in the constructor. */ - void read(TagLib::File *file, long footerLocation); + void read(); /*! * Parses the body of the tag in \a data. diff --git a/taglib/mpeg/id3v1/id3v1tag.cpp b/taglib/mpeg/id3v1/id3v1tag.cpp index 9b724159..ca930411 100644 --- a/taglib/mpeg/id3v1/id3v1tag.cpp +++ b/taglib/mpeg/id3v1/id3v1tag.cpp @@ -42,9 +42,14 @@ class ID3v1::Tag::TagPrivate { public: TagPrivate() : + file(0), + tagOffset(0), track(0), genre(255) {} + File *file; + long tagOffset; + String title; String artist; String album; @@ -89,7 +94,10 @@ ID3v1::Tag::Tag(File *file, long tagOffset) : TagLib::Tag(), d(new TagPrivate()) { - read(file, tagOffset); + d->file = file; + d->tagOffset = tagOffset; + + read(); } ID3v1::Tag::~Tag() @@ -211,12 +219,12 @@ void ID3v1::Tag::setStringHandler(const StringHandler *handler) // protected methods //////////////////////////////////////////////////////////////////////////////// -void ID3v1::Tag::read(File *file, long tagOffset) +void ID3v1::Tag::read() { - if(file && file->isValid()) { - file->seek(tagOffset); + if(d->file && d->file->isValid()) { + d->file->seek(d->tagOffset); // read the tag -- always 128 bytes - const ByteVector data = file->readBlock(128); + const ByteVector data = d->file->readBlock(128); // some initial sanity checking if(data.size() == 128 && data.startsWith("TAG")) diff --git a/taglib/mpeg/id3v1/id3v1tag.h b/taglib/mpeg/id3v1/id3v1tag.h index 9cff408f..b61f06af 100644 --- a/taglib/mpeg/id3v1/id3v1tag.h +++ b/taglib/mpeg/id3v1/id3v1tag.h @@ -183,7 +183,7 @@ namespace TagLib { /*! * Reads from the file specified in the constructor. */ - void read(File *file, long tagOffset); + void read(); /*! * Pareses the body of the tag in \a data. */ diff --git a/taglib/mpeg/id3v2/id3v2tag.cpp b/taglib/mpeg/id3v2/id3v2tag.cpp index b826ecaa..0f0b1a18 100644 --- a/taglib/mpeg/id3v2/id3v2tag.cpp +++ b/taglib/mpeg/id3v2/id3v2tag.cpp @@ -64,7 +64,8 @@ class ID3v2::Tag::TagPrivate { public: TagPrivate() : - fileLength(0), + file(0), + tagOffset(0), extendedHeader(0), footer(0) { @@ -77,9 +78,11 @@ public: delete footer; } - long fileLength; const FrameFactory *factory; + File *file; + long tagOffset; + Header header; ExtendedHeader *extendedHeader; Footer *footer; @@ -121,8 +124,10 @@ ID3v2::Tag::Tag(File *file, long tagOffset, const FrameFactory *factory) : d(new TagPrivate()) { d->factory = factory; + d->file = file; + d->tagOffset = tagOffset; - read(file, tagOffset); + read(); } ID3v2::Tag::~Tag() @@ -620,7 +625,7 @@ ByteVector ID3v2::Tag::render(int version) const else { // Padding won't increase beyond 1% of the file size or 1MB. - long threshold = d->fileLength / 100; + long threshold = d->file ? d->file->length() / 100 : 0; threshold = std::max(threshold, MinPaddingSize); threshold = std::min(threshold, MaxPaddingSize); @@ -634,9 +639,6 @@ ByteVector ID3v2::Tag::render(int version) const d->header.setMajorVersion(version); d->header.setTagSize(tagData.size() - Header::size()); - if(d->fileLength > 0) - d->fileLength += (d->header.tagSize() - originalSize); - // TODO: This should eventually include d->footer->render(). const ByteVector headerData = d->header.render(); std::copy(headerData.begin(), headerData.end(), tagData.begin()); @@ -661,24 +663,22 @@ void ID3v2::Tag::setLatin1StringHandler(const Latin1StringHandler *handler) // protected members //////////////////////////////////////////////////////////////////////////////// -void ID3v2::Tag::read(TagLib::File *file, long offset) +void ID3v2::Tag::read() { - if(!file) + if(!d->file) return; - if(!file->isOpen()) + if(!d->file->isOpen()) return; - d->fileLength = file->length(); - - file->seek(offset); - d->header.setData(file->readBlock(Header::size())); + d->file->seek(d->tagOffset); + d->header.setData(d->file->readBlock(Header::size())); // If the tag size is 0, then this is an invalid tag (tags must contain at // least one frame) if(d->header.tagSize() != 0) - parse(file->readBlock(d->header.tagSize())); + parse(d->file->readBlock(d->header.tagSize())); // Look for duplicate ID3v2 tags and treat them as an extra blank of this one. // It leads to overwriting them with zero when saving the tag. @@ -690,9 +690,9 @@ void ID3v2::Tag::read(TagLib::File *file, long offset) while(true) { - file->seek(offset + d->header.completeTagSize() + extraSize); + d->file->seek(d->tagOffset + d->header.completeTagSize() + extraSize); - const ByteVector data = file->readBlock(Header::size()); + const ByteVector data = d->file->readBlock(Header::size()); if(data.size() < Header::size() || !data.startsWith(Header::fileIdentifier())) break; diff --git a/taglib/mpeg/id3v2/id3v2tag.h b/taglib/mpeg/id3v2/id3v2tag.h index dcd55a0c..4367181f 100644 --- a/taglib/mpeg/id3v2/id3v2tag.h +++ b/taglib/mpeg/id3v2/id3v2tag.h @@ -382,7 +382,7 @@ namespace TagLib { * the Header, the body of the tag (which contains the ExtendedHeader and * frames) and Footer. */ - void read(TagLib::File *file, long offset); + void read(); /*! * This is called by read to parse the body of the tag. It determines if an