From 09fcb374423a5f613f3def92b9db5e5f82a9cb79 Mon Sep 17 00:00:00 2001 From: Martchus Date: Mon, 27 Jul 2015 23:10:35 +0200 Subject: [PATCH] small adjustments --- fieldbasedtag.h | 10 +++++----- id3/id3v2tag.cpp | 29 +++++++++++++++++---------- id3/id3v2tag.h | 2 +- matroska/ebmlelement.cpp | 6 ++---- mp4/mp4atom.cpp | 2 +- mp4/mp4track.cpp | 5 +++-- tag.h | 5 +++-- tagvalue.cpp | 43 +++++++++++++++++++++------------------- 8 files changed, 57 insertions(+), 45 deletions(-) diff --git a/fieldbasedtag.h b/fieldbasedtag.h index e8ec7a3..c74dfb1 100644 --- a/fieldbasedtag.h +++ b/fieldbasedtag.h @@ -29,7 +29,7 @@ public: FieldMapBasedTag(); virtual ~FieldMapBasedTag(); - virtual const TagValue &value(KnownField value) const; + virtual const TagValue &value(KnownField field) const; virtual const TagValue &value(const typename FieldType::identifierType &id) const; virtual std::list values(const typename FieldType::identifierType &id) const; virtual bool setValue(KnownField field, const TagValue &value); @@ -82,9 +82,9 @@ FieldMapBasedTag::~FieldMapBasedTag() {} template -inline const TagValue &FieldMapBasedTag::value(KnownField value) const +inline const TagValue &FieldMapBasedTag::value(KnownField field) const { - return this->value(fieldId(value)); + return value(fieldId(field)); } /*! @@ -163,7 +163,7 @@ inline void FieldMapBasedTag::removeAllFields() * * This method provides direct access to the fields of the tag. It might * be usefull when the convenience methods value(), setValue(), hasField(), ... - * to not offer the required functionality. + * do not offer the required functionality. */ template inline const std::multimap &FieldMapBasedTag::fields() const @@ -176,7 +176,7 @@ inline const std::multimap inline std::multimap &FieldMapBasedTag::fields() diff --git a/id3/id3v2tag.cpp b/id3/id3v2tag.cpp index 5871641..d6daf81 100644 --- a/id3/id3v2tag.cpp +++ b/id3/id3v2tag.cpp @@ -331,28 +331,37 @@ void Id3v2Tag::setVersion(byte majorVersion, byte revisionVersion) /*! * \brief Returns true if \a lhs goes before \a rhs; otherwise returns false. */ -bool FrameComparer::operator ()(const uint32 &lhs, const uint32 &rhs) const +bool FrameComparer::operator()(const uint32 &lhs, const uint32 &rhs) const { - if(lhs == rhs) + if(lhs == rhs) { return false; - if(lhs == Id3v2FrameIds::lUniqueFileId || lhs == Id3v2FrameIds::sUniqueFileId) + } + if(lhs == Id3v2FrameIds::lUniqueFileId || lhs == Id3v2FrameIds::sUniqueFileId) { return true; - if(rhs == Id3v2FrameIds::lUniqueFileId || rhs == Id3v2FrameIds::sUniqueFileId) + } + if(rhs == Id3v2FrameIds::lUniqueFileId || rhs == Id3v2FrameIds::sUniqueFileId) { return false; - if(lhs == Id3v2FrameIds::lTitle || lhs == Id3v2FrameIds::sTitle) + } + if(lhs == Id3v2FrameIds::lTitle || lhs == Id3v2FrameIds::sTitle) { return true; - if(rhs == Id3v2FrameIds::lTitle || rhs == Id3v2FrameIds::sTitle) + } + if(rhs == Id3v2FrameIds::lTitle || rhs == Id3v2FrameIds::sTitle) { return false; + } bool lhstextfield = Id3v2FrameIds::isTextfield(lhs); bool rhstextfield = Id3v2FrameIds::isTextfield(rhs); - if(lhstextfield && !rhstextfield) + if(lhstextfield && !rhstextfield) { return true; - if(!lhstextfield && rhstextfield) + } + if(!lhstextfield && rhstextfield) { return false; - if(lhs == Id3v2FrameIds::lCover || lhs == Id3v2FrameIds::sCover) + } + if(lhs == Id3v2FrameIds::lCover || lhs == Id3v2FrameIds::sCover) { return false; - if(rhs == Id3v2FrameIds::lCover || rhs == Id3v2FrameIds::sCover) + } + if(rhs == Id3v2FrameIds::lCover || rhs == Id3v2FrameIds::sCover) { return true; + } return lhs < rhs; } diff --git a/id3/id3v2tag.h b/id3/id3v2tag.h index 8b81474..fe66bde 100644 --- a/id3/id3v2tag.h +++ b/id3/id3v2tag.h @@ -12,7 +12,7 @@ namespace Media struct LIB_EXPORT FrameComparer { - bool operator() (const uint32& lhs, const uint32& rhs) const; + bool operator()(const uint32& lhs, const uint32& rhs) const; }; class LIB_EXPORT Id3v2Tag : public FieldMapBasedTag diff --git a/matroska/ebmlelement.cpp b/matroska/ebmlelement.cpp index 1b6cc0c..716f45b 100644 --- a/matroska/ebmlelement.cpp +++ b/matroska/ebmlelement.cpp @@ -70,9 +70,7 @@ void EbmlElement::internalParse() } stream().seekg(startOffset()); // read ID - char buf[GenericFileElement::maximumIdLengthSupported() > GenericFileElement::maximumSizeLengthSupported() - ? GenericFileElement::maximumIdLengthSupported() - : GenericFileElement::maximumSizeLengthSupported()] = {0}; + char buf[maximumIdLengthSupported() > maximumSizeLengthSupported() ? maximumIdLengthSupported() : maximumSizeLengthSupported()] = {0}; byte beg, mask = 0x80; beg = stream().peek(); m_idLength = 1; @@ -107,7 +105,7 @@ void EbmlElement::internalParse() throw InvalidDataException(); } // read size into buffer - memset(buf, 0, sizeof(buf)); + *reinterpret_cast(buf) = 0; // reset buffer reader().read(buf + (GenericFileElement::maximumSizeLengthSupported() - m_sizeLength), m_sizeLength); *(buf + (GenericFileElement::maximumSizeLengthSupported() - m_sizeLength)) ^= mask; // xor the first byte in buffer which has been read from the file with mask m_dataSize = ConversionUtilities::BE::toUInt64(buf); diff --git a/mp4/mp4atom.cpp b/mp4/mp4atom.cpp index d9e6622..4778c5b 100644 --- a/mp4/mp4atom.cpp +++ b/mp4/mp4atom.cpp @@ -77,7 +77,7 @@ void Mp4Atom::internalParse() } m_id = reader().readUInt32BE(); m_idLength = 4; - if(dataSize() == 1) { // mp4 atom denotes 64 bit size + if(dataSize() == 1) { // atom denotes 64-bit size m_dataSize = reader().readUInt64BE(); m_sizeLength = 12; // 4 bytes indicate long size denotation + 8 bytes for actual size denotation if(dataSize() < 16 && m_dataSize != 1) { diff --git a/mp4/mp4track.cpp b/mp4/mp4track.cpp index 40dc6a7..0b11199 100644 --- a/mp4/mp4track.cpp +++ b/mp4/mp4track.cpp @@ -555,7 +555,7 @@ std::unique_ptr Mp4Track::parseMpeg4ElementaryStreamI esInfo->videoSpecificConfig = parseVideoSpecificConfig(decCfgDescChild); break; default: - ; // TODO: covering more object types + ; // TODO: cover more object types } break; } @@ -591,7 +591,6 @@ unique_ptr Mp4Track::parseAudioSpecificConfig(Mpeg4Des auto buff = make_unique(decSpecInfoDesc->dataSize()); m_istream->read(buff.get(), decSpecInfoDesc->dataSize()); BitReader bitReader(buff.get(), decSpecInfoDesc->dataSize()); - cout << "buff: " << reinterpret_cast(buff.get()) << ", " << decSpecInfoDesc->dataSize() << endl; auto audioCfg = make_unique(); try { // read audio object type @@ -798,6 +797,8 @@ std::unique_ptr Mp4Track::parseVideoSpecificConfig(Mpe * - the ID of the atom holding these offsets is not "stco" or "co64" * * \throws Throws std::ios_base::failure when an IO error occurs. + * + * \remarks This method needs to be fixed. */ void Mp4Track::updateChunkOffsets(const vector &oldMdatOffsets, const vector &newMdatOffsets) { diff --git a/tag.h b/tag.h index 180e12e..d2efded 100644 --- a/tag.h +++ b/tag.h @@ -69,7 +69,8 @@ enum class KnownField : unsigned int Cover, /**< cover */ Composer, /**< composer */ Rating, /**< rating */ - Description /**< description */ + Description, /**< description */ + Vendor /**< vendor */ }; /*! @@ -80,7 +81,7 @@ constexpr KnownField firstKnownField = KnownField::Title; /*! * \brief The last valid entry in the Media::KnownField enum. */ -constexpr KnownField lastKnownField = KnownField::Description; +constexpr KnownField lastKnownField = KnownField::Vendor; /*! * \brief The number of valid entries in the Media::KnownField enum. diff --git a/tagvalue.cpp b/tagvalue.cpp index 9470390..30001a7 100644 --- a/tagvalue.cpp +++ b/tagvalue.cpp @@ -202,16 +202,15 @@ int32 TagValue::toInteger() const return ConversionUtilities::stringToNumber(string(m_ptr.get(), m_size)); case TagDataType::Integer: case TagDataType::StandardGenreIndex: - if(m_size == sizeof(int)) { - char *test = m_ptr.get(); - int res = *reinterpret_cast(test); + if(m_size == sizeof(int32)) { + auto res = *reinterpret_cast(m_ptr.get()); return res; } else { - throw ConversionException("The assigned data is of unappropriate size."); + throw ConversionException("Can not convert assigned data to integer because the data size is not appropriate."); } break; default: - throw ConversionException("It is not possible to convert assigned data to a number because of its incompatible type."); + throw ConversionException("Can not convert binary data/picture/time span/date time to integer."); } } return 0; @@ -268,15 +267,16 @@ PositionInSet TagValue::toPositionIntSet() const return PositionInSet(string(m_ptr.get(), m_size)); case TagDataType::Integer: case TagDataType::PositionInSet: - if(m_size == sizeof(int32)) { + switch(m_size) { + case sizeof(int32): return PositionInSet(*(reinterpret_cast(m_ptr.get()))); - } else if(m_size == 2 * sizeof(int32)) { + case 2 * sizeof(int32): return PositionInSet(*(reinterpret_cast(m_ptr.get())), *(reinterpret_cast(m_ptr.get() + sizeof(int32)))); - } else { - throw ConversionException("The assigned data is of unappropriate size."); + default: + throw ConversionException("The size of the assigned data is not appropriate."); } default: - throw ConversionException("It is not possible to convert assigned data to a number because of its incompatible type."); + throw ConversionException("Can not convert binary data/genre index/picture to \"position in set\"."); } } return PositionInSet(); @@ -295,15 +295,16 @@ TimeSpan TagValue::toTimeSpan() const return TimeSpan::fromSeconds(ConversionUtilities::stringToNumber(string(m_ptr.get(), m_size))); case TagDataType::Integer: case TagDataType::TimeSpan: - if(m_size == sizeof(int32)) { + switch(m_size) { + case sizeof(int32): return TimeSpan(*(reinterpret_cast(m_ptr.get()))); - } else if(m_size == sizeof(int64)) { + case sizeof(int64): return TimeSpan(*(reinterpret_cast(m_ptr.get()))); - } else { - throw ConversionException("The assigned data is of unappropriate size."); + default: + throw ConversionException("The size of the assigned data is not appropriate."); } default: - throw ConversionException("No conversion from assigned data to time span known."); + throw ConversionException("Can not convert binary data/genre index/position in set/picture to time span."); } } return TimeSpan(); @@ -330,7 +331,7 @@ DateTime TagValue::toDateTime() const throw ConversionException("The assigned data is of unappropriate size."); } default: - throw ConversionException("No conversion from assigned data to date known."); + throw ConversionException("Can not convert binary data/genre index/position in set/picture to date time."); } } return DateTime(); @@ -351,14 +352,14 @@ string TagValue::toString() const /*! * \brief Converts the value of the current TagValue object to its equivalent * std::string representation. - * \throws Throws ConversionException an failure. + * \throws Throws ConversionException on failure. */ void TagValue::toString(string &result) const { if(!isEmpty()) { switch(m_type) { case TagDataType::Text: - result = string(m_ptr.get(), m_size); + result.assign(m_ptr.get(), m_size); return; case TagDataType::Integer: result = ConversionUtilities::numberToString(toInteger()); @@ -368,15 +369,17 @@ void TagValue::toString(string &result) const return; case TagDataType::StandardGenreIndex: if(const char *genreName = Id3Genres::stringFromIndex(toInteger())) { - result = string(genreName); + result.assign(genreName); return; + } else { + throw ConversionException("No string representation for the assigned standard genre index available."); } break; case TagDataType::TimeSpan: result = toTimeSpan().toString(); return; default: - throw ConversionException("It is not possible to convert assigned data to a number because of its incompatible type."); + throw ConversionException("Can not convert binary data/picture to string."); } } result.clear();