[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdesupport/taglib
From:       Lukáš Lalinský <lalinsky () gmail ! com>
Date:       2010-04-02 11:53:29
Message-ID: 20100402115329.3BA2FAC88C () svn ! kde ! org
[Download RAW message or body]

SVN commit 1110205 by lalinsky:

Save ASF attributes larger than 64k to the metadata library object

 M  +26 -0     taglib/asf/asfattribute.cpp  
 M  +3 -0      taglib/asf/asfattribute.h  
 M  +3 -2      taglib/asf/asffile.cpp  
 M  +19 -0     tests/test_asf.cpp  


--- trunk/kdesupport/taglib/taglib/asf/asfattribute.cpp #1110204:1110205
@@ -30,6 +30,7 @@
 #ifdef WITH_ASF
 
 #include <taglib.h>
+#include <tdebug.h>
 #include "asfattribute.h"
 #include "asffile.h"
 
@@ -197,6 +198,10 @@
     name = f.readString(nameLength);
   }
 
+  if(kind != 2 && size > 65535) {
+    debug("ASF::Attribute::parse() -- Value larger than 64kB");
+  }
+
   switch(d->type) {
   case WordType:
     d->shortValue = f.readWORD();
@@ -232,6 +237,27 @@
   return name;
 }
 
+int
+ASF::Attribute::dataSize() const
+{
+  switch (d->type) {
+  case WordType:
+    return 2;
+  case BoolType:
+    return 4;
+  case DWordType:
+    return 4;
+  case QWordType:
+    return 5;
+  case UnicodeType:
+    return d->stringValue.size() * 2 + 2;
+  case BytesType:
+  case GuidType:
+    return d->byteVectorValue.size();
+  }
+  return 0;
+}
+
 ByteVector
 ASF::Attribute::render(const String &name, int kind) const
 {
--- trunk/kdesupport/taglib/taglib/asf/asfattribute.h #1110204:1110205
@@ -165,6 +165,9 @@
       String parse(ASF::File &file, int kind = 0);
 #endif
 
+      //! Returns the size of the stored data
+      int dataSize() const;
+
     private:
       friend class File;
 
--- trunk/kdesupport/taglib/taglib/asf/asffile.cpp #1110204:1110205
@@ -480,11 +480,12 @@
     bool inMetadataObject = false;
     for(unsigned int j = 0; j < attributes.size(); j++) {
       const Attribute &attribute = attributes[j];
-      if(!inExtendedContentDescriptionObject && attribute.language() == 0 && \
attribute.stream() == 0) { +      bool largeValue = attribute.dataSize() > 65535;
+      if(!inExtendedContentDescriptionObject && !largeValue && attribute.language() \
                == 0 && attribute.stream() == 0) {
         d->extendedContentDescriptionObject->attributeData.append(attribute.render(name));
  inExtendedContentDescriptionObject = true;
       }
-      else if(!inMetadataObject && attribute.language() == 0 && attribute.stream() \
!= 0) { +      else if(!inMetadataObject && !largeValue && attribute.language() == 0 \
                && attribute.stream() != 0) {
         d->metadataObject->attributeData.append(attribute.render(name, 1));
         inMetadataObject = true;
       }
--- trunk/kdesupport/taglib/tests/test_asf.cpp #1110204:1110205
@@ -19,6 +19,7 @@
   CPPUNIT_TEST(testSaveStream);
   CPPUNIT_TEST(testSaveLanguage);
   CPPUNIT_TEST(testDWordTrackNumber);
+  CPPUNIT_TEST(testSaveLargeValue);
   CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -122,6 +123,24 @@
     delete f;
   }
 
+  void testSaveLargeValue()
+  {
+    ScopedFileCopy copy("silence-1", ".wma");
+    string newname = copy.fileName();
+
+    ASF::File *f = new ASF::File(newname.c_str());
+    ASF::AttributeList values;
+    ASF::Attribute attr(ByteVector(70000, 'x'));
+    values.append(attr);
+    f->tag()->attributeListMap()["WM/Blob"] = values;
+    f->save();
+    delete f;
+
+    f = new ASF::File(newname.c_str());
+    CPPUNIT_ASSERT_EQUAL(ByteVector(70000, 'x'), \
f->tag()->attributeListMap()["WM/Blob"][0].toByteVector()); +    delete f;
+  }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestASF);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic