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

git-svn-id: svn://anonsvn.kde.org/home/kde/trunk/kdesupport/taglib@1110205 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
This commit is contained in:
Lukáš Lalinský
2010-04-02 11:53:28 +00:00
parent 4202ce3ec9
commit 2ef8fc5118
4 changed files with 51 additions and 2 deletions

View File

@ -30,6 +30,7 @@
#ifdef WITH_ASF
#include <taglib.h>
#include <tdebug.h>
#include "asfattribute.h"
#include "asffile.h"
@ -197,6 +198,10 @@ ASF::Attribute::parse(ASF::File &f, int kind)
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 @@ ASF::Attribute::parse(ASF::File &f, int kind)
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
{

View File

@ -165,6 +165,9 @@ namespace TagLib
String parse(ASF::File &file, int kind = 0);
#endif
//! Returns the size of the stored data
int dataSize() const;
private:
friend class File;

View File

@ -480,11 +480,12 @@ bool ASF::File::save()
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;
}