mirror of
https://github.com/taglib/taglib.git
synced 2025-05-27 21:20:26 -04:00
Untested implementation of RIFF chunk parsing.
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@808221 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
parent
40da982936
commit
efdcc7b01f
@ -24,21 +24,26 @@
|
||||
***************************************************************************/
|
||||
|
||||
#include "rifffile.h"
|
||||
#include <tbytevectorlist.h>
|
||||
|
||||
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<uint> 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);
|
||||
}
|
||||
}
|
||||
|
@ -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 &);
|
||||
|
Loading…
Reference in New Issue
Block a user