]> granicus.if.org Git - taglib/commitdiff
Untested implementation of RIFF chunk parsing.
authorScott Wheeler <wheeler@kde.org>
Fri, 16 May 2008 03:49:44 +0000 (03:49 +0000)
committerScott Wheeler <wheeler@kde.org>
Fri, 16 May 2008 03:49:44 +0000 (03:49 +0000)
git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@808221 283d02a7-25f6-0310-bc7c-ecb5cbfe19da

taglib/riff/rifffile.cpp
taglib/riff/rifffile.h

index 44a1a0ed43e07f1bd7c5ab9502977f74dd340349..3e9ad9d0a5fc1d73299cfa36d16194b070afff6a 100644 (file)
  ***************************************************************************/
 
 #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);
+  }
 }
index ad700df4d97622b43c9c477569dd747b0a32ba70..5949df1e1d1ddcc6258d19f228c690628b98e2d1 100644 (file)
@@ -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 &);