diff --git a/taglib/riff/rifffile.cpp b/taglib/riff/rifffile.cpp index 44a1a0ed..3e9ad9d0 100644 --- a/taglib/riff/rifffile.cpp +++ b/taglib/riff/rifffile.cpp @@ -24,21 +24,26 @@ ***************************************************************************/ #include "rifffile.h" +#include using namespace TagLib; class RIFF::File::FilePrivate { public: - FilePrivate() + FilePrivate() : + endianness(BigEndian), + size(0) { } + Endianness endianness; + ByteVector type; + uint size; + ByteVector format; - ~FilePrivate() - { - - } + ByteVectorList chunkNames; + List chunkSizes; }; //////////////////////////////////////////////////////////////////////////////// @@ -54,19 +59,64 @@ RIFF::File::~File() // protected members //////////////////////////////////////////////////////////////////////////////// -RIFF::File::File(FileName file) : TagLib::File(file) +RIFF::File::File(FileName file, Endianness endianness) : TagLib::File(file) { d = new FilePrivate; + d->endianness = endianness; if(isOpen()) read(); } +uint RIFF::File::chunkCount() const +{ + return d->chunkNames.size(); +} + +ByteVector RIFF::File::chunkName(uint i) const +{ + if(i >= chunkCount()) + return ByteVector::null; + + return d->chunkNames[i]; +} + +ByteVector RIFF::File::chunkData(uint i) +{ + if(i >= chunkCount()) + return ByteVector::null; + + // Offset for the first subchunk's data + + long begin = 12 + 8; + + for(uint it = 0; it < i; it++) + begin += 8 + d->chunkSizes[it]; + + seek(begin); + + return readBlock(d->chunkSizes[i]); +} + //////////////////////////////////////////////////////////////////////////////// // private members //////////////////////////////////////////////////////////////////////////////// void RIFF::File::read() { + bool bigEndian = (d->endianness == BigEndian); + d->type = readBlock(4); + d->size = readBlock(4).toUInt(bigEndian); + d->format = readBlock(4); + + while(tell() < length()) { + ByteVector chunkName = readBlock(4); + uint chunkSize = readBlock(4).toUInt(bigEndian); + + d->chunkNames.append(chunkName); + d->chunkSizes.append(chunkSize); + + seek(chunkSize, Current); + } } diff --git a/taglib/riff/rifffile.h b/taglib/riff/rifffile.h index ad700df4..5949df1e 100644 --- a/taglib/riff/rifffile.h +++ b/taglib/riff/rifffile.h @@ -52,7 +52,14 @@ namespace TagLib { virtual ~File(); protected: - File(FileName file); + + enum Endianness { BigEndian, LittleEndian }; + + File(FileName file, Endianness endianness); + + uint chunkCount() const; + ByteVector chunkName(uint i) const; + ByteVector chunkData(uint i); private: File(const File &);