Improve handling of binary Matroska tag fields

This commit is contained in:
Martchus 2016-07-22 01:37:25 +02:00
parent b8eb6bf8d7
commit 1182cbeb85
2 changed files with 23 additions and 10 deletions

View File

@ -138,7 +138,7 @@ MatroskaTagFieldMaker MatroskaTagField::prepareMaking()
}
try {
return MatroskaTagFieldMaker(*this);
} catch(ConversionException &) {
} catch(const ConversionException &) {
addNotification(NotificationType::Critical, "The assigned tag value can not be converted to be written appropriately.", context);
throw InvalidDataException();
}
@ -167,9 +167,15 @@ void MatroskaTagField::make(ostream &stream)
* \sa See MatroskaTagField::prepareMaking() for more information.
*/
MatroskaTagFieldMaker::MatroskaTagFieldMaker(MatroskaTagField &field) :
m_field(field)
m_field(field),
m_isBinary(false)
{
m_stringValue = m_field.value().toString();
try {
m_stringValue = m_field.value().toString();
} catch(const ConversionException &) {
m_field.addNotification(NotificationType::Warning, "The assigned tag value can not be converted to a string and is treated as binary value (which is likely not what you want since official Matroska specifiecation doesn't list any binary fields).", "making Matroska \"SimpleTag\" element.");
m_isBinary = true;
}
size_t languageSize = m_field.value().language().size();
if(!languageSize) {
languageSize = 3; // if there's no language set, the 3 byte long value "und" is used
@ -225,12 +231,18 @@ void MatroskaTagFieldMaker::make(ostream &stream) const
writer.writeUInt16BE(MatroskaIds::TagDefault);
stream.put(0x80 | 1);
stream.put(m_field.isDefault() ? 1 : 0);
// write header of "TagString" element
writer.writeUInt16BE(MatroskaIds::TagString);
sizeDenotationLen = EbmlElement::makeSizeDenotation(m_stringValue.size(), buff);
stream.write(buff, sizeDenotationLen);
stream.write(m_stringValue.c_str(), m_stringValue.size());
// "TagBinary" element currently not supported!
// write header of "TagString"/"TagBinary" element
if(m_isBinary) {
writer.writeUInt16BE(MatroskaIds::TagBinary);
sizeDenotationLen = EbmlElement::makeSizeDenotation(m_field.value().dataSize(), buff);
stream.write(buff, sizeDenotationLen);
stream.write(m_field.value().dataPointer(), m_field.value().dataSize());
} else {
writer.writeUInt16BE(MatroskaIds::TagString);
sizeDenotationLen = EbmlElement::makeSizeDenotation(m_stringValue.size(), buff);
stream.write(buff, sizeDenotationLen);
stream.write(m_stringValue.data(), m_stringValue.size());
}
// make nested tags
for(const auto &maker : m_nestedMaker) {
maker.make(stream);

View File

@ -54,7 +54,8 @@ public:
private:
MatroskaTagFieldMaker(MatroskaTagField &field);
const MatroskaTagField &m_field;
MatroskaTagField &m_field;
bool m_isBinary;
std::string m_stringValue;
uint64 m_simpleTagSize;
uint64 m_totalSize;