diff --git a/mediafileinfo.cpp b/mediafileinfo.cpp index 0fae5c8..cfa608f 100644 --- a/mediafileinfo.cpp +++ b/mediafileinfo.cpp @@ -74,11 +74,14 @@ MediaFileInfo::MediaFileInfo() : m_chaptersParsingStatus(ParsingStatus::NotParsedYet), m_attachmentsParsingStatus(ParsingStatus::NotParsedYet), m_forceFullParse(MEDIAINFO_CPP_FORCE_FULL_PARSE), + m_forceRewrite(true), m_minPadding(0), m_maxPadding(0), m_preferredPadding(0), - m_tagPosition(TagPosition::BeforeData), - m_forceTagPosition(true) + m_tagPosition(ElementPosition::BeforeData), + m_forceTagPosition(true), + m_indexPosition(ElementPosition::BeforeData), + m_forceIndexPosition(true) {} /*! @@ -97,11 +100,14 @@ MediaFileInfo::MediaFileInfo(const string &path) : m_chaptersParsingStatus(ParsingStatus::NotParsedYet), m_attachmentsParsingStatus(ParsingStatus::NotParsedYet), m_forceFullParse(MEDIAINFO_CPP_FORCE_FULL_PARSE), + m_forceRewrite(true), m_minPadding(0), m_maxPadding(0), m_preferredPadding(0), - m_tagPosition(TagPosition::BeforeData), - m_forceTagPosition(true) + m_tagPosition(ElementPosition::BeforeData), + m_forceTagPosition(true), + m_indexPosition(ElementPosition::BeforeData), + m_forceIndexPosition(true) {} /*! @@ -142,7 +148,7 @@ void MediaFileInfo::parseContainerFormat() open(); // ensure the file is open m_containerFormat = ContainerFormat::Unknown; // file size - m_paddingSize = 0x0u; + m_paddingSize = 0; m_containerOffset = 0; // read signatrue char buff[16]; diff --git a/mediafileinfo.h b/mediafileinfo.h index f7d87f3..b291cd8 100644 --- a/mediafileinfo.h +++ b/mediafileinfo.h @@ -40,10 +40,11 @@ enum class TagUsage Never /**< tags of the type are never used; a possibly existing tag of the type is removed */ }; -enum class TagPosition +enum class ElementPosition { - BeforeData, - AfterData + BeforeData, /**< the element is positioned before the actual data */ + AfterData, /**< the element is positioned after the actual data */ + Keep /**< the element is placed at its previous position */ }; /*! @@ -141,16 +142,22 @@ public: // methods to get, set object behaviour bool isForcingFullParse() const; void setForceFullParse(bool forceFullParse); + bool isForcingRewrite() const; + void setForceRewrite(bool forceRewrite); size_t minPadding() const; void setMinPadding(size_t minPadding); size_t maxPadding() const; void setMaxPadding(size_t maxPadding); size_t preferredPadding() const; void setPreferredPadding(size_t preferredPadding); - TagPosition tagPosition() const; - void setTagPosition(TagPosition tagPosition); + ElementPosition tagPosition() const; + void setTagPosition(ElementPosition tagPosition); bool forceTagPosition() const; void setForceTagPosition(bool forceTagPosition); + ElementPosition indexPosition() const; + void setIndexPosition(ElementPosition indexPosition); + bool forceIndexPosition() const; + void setForceIndexPosition(bool forceTagPosition); protected: virtual void invalidated(); @@ -180,11 +187,14 @@ private: ParsingStatus m_attachmentsParsingStatus; // fields specifying object behaviour bool m_forceFullParse; + bool m_forceRewrite; size_t m_minPadding; size_t m_maxPadding; size_t m_preferredPadding; - TagPosition m_tagPosition; + ElementPosition m_tagPosition; bool m_forceTagPosition; + ElementPosition m_indexPosition; + bool m_forceIndexPosition; }; /*! @@ -383,6 +393,22 @@ inline void MediaFileInfo::setForceFullParse(bool forceFullParse) m_forceFullParse = forceFullParse; } +/*! + * \brief Returns whether forcing rewriting (when applying changes) is enabled. + */ +inline bool MediaFileInfo::isForcingRewrite() const +{ + return m_forceRewrite; +} + +/*! + * \brief Sets whether forcing rewriting (when applying changes) is enabled. + */ +inline void MediaFileInfo::setForceRewrite(bool forceRewrite) +{ + m_forceRewrite = forceRewrite; +} + /*! * \brief Returns the minimum padding to be written before the data blocks when applying changes. * @@ -458,7 +484,7 @@ inline void MediaFileInfo::setPreferredPadding(size_t preferredPadding) * \brief Returns the position (in the output file) where the tag information is written when applying changes. * \sa setTagPosition() */ -inline TagPosition MediaFileInfo::tagPosition() const +inline ElementPosition MediaFileInfo::tagPosition() const { return m_tagPosition; } @@ -471,8 +497,9 @@ inline TagPosition MediaFileInfo::tagPosition() const * might not be used if forceTagPosition() is false. * - However if the specified position is not supported by the container/tag format or by the implementation * for the format it is ignored (even if forceTagPosition() is true). + * - Default value is ElementPosition::BeforeData */ -inline void MediaFileInfo::setTagPosition(TagPosition tagPosition) +inline void MediaFileInfo::setTagPosition(ElementPosition tagPosition) { m_tagPosition = tagPosition; } @@ -497,6 +524,46 @@ inline void MediaFileInfo::setForceTagPosition(bool forceTagPosition) m_forceTagPosition = forceTagPosition; } +/*! + * \brief Returns the position (in the output file) where the index is written when applying changes. + * \sa setIndexPosition() + * + */ +inline ElementPosition MediaFileInfo::indexPosition() const +{ + return m_indexPosition; +} + +/*! + * \brief Sets the position (in the output file) where the index is written when applying changes. + * \remarks Same rules as for tagPosition() apply. If conflicting with tagPosition(), tagPosition() has priority. + * + */ +inline void MediaFileInfo::setIndexPosition(ElementPosition indexPosition) +{ + m_indexPosition = indexPosition; +} + +/*! + * \brief Returns whether indexPosition() is forced. + * \sa setForceIndexPosition() + * \sa indexPosition(), setIndexPosition() + */ +inline bool MediaFileInfo::forceIndexPosition() const +{ + return m_forceIndexPosition; +} + +/*! + * \brief Sets whether indexPosition() is forced. + * \sa forceIndexPosition() + * \sa indexPosition(), setIndexPosition() + */ +inline void MediaFileInfo::setForceIndexPosition(bool forceIndexPosition) +{ + m_forceIndexPosition = forceIndexPosition; +} + } #endif // MEDIAINFO_H diff --git a/mp4/mp4container.cpp b/mp4/mp4container.cpp index 2336f7c..62c2a15 100644 --- a/mp4/mp4container.cpp +++ b/mp4/mp4container.cpp @@ -246,7 +246,7 @@ void Mp4Container::internalMakeFile() vector newMdatOffsets; // used when simply copying mdat auto trackCount = tracks().size(); for(byte pass = 0; pass != 2; ++pass) { - if(fileInfo().tagPosition() == (pass ? TagPosition::AfterData : TagPosition::BeforeData)) { + if(fileInfo().tagPosition() == (pass ? ElementPosition::AfterData : ElementPosition::BeforeData)) { // write "moov"-atom (contains track and tag information) ostream::pos_type newMoovOffset = outputStream.tellp(); Mp4Atom *udtaAtom = nullptr;