From cbb54d5aebe6fa7b7077ba29e729149d40d5fb72 Mon Sep 17 00:00:00 2001 From: Martchus Date: Tue, 20 Mar 2018 21:41:05 +0100 Subject: [PATCH] Allow custom writing application --- matroska/matroskacontainer.cpp | 21 ++++++++++++++------- mediafileinfo.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/matroska/matroskacontainer.cpp b/matroska/matroskacontainer.cpp index 8a90f98..5f0f679 100644 --- a/matroska/matroskacontainer.cpp +++ b/matroska/matroskacontainer.cpp @@ -33,10 +33,6 @@ using namespace ChronoUtilities; namespace TagParser { -constexpr const char appInfo[] = APP_NAME " v" APP_VERSION; -constexpr uint64 appInfoElementDataSize = sizeof(appInfo) - 1; -constexpr uint64 appInfoElementTotalSize = 2 + 1 + appInfoElementDataSize; - /*! * \class Media::MatroskaContainer * \brief Implementation of GenericContainer. @@ -931,6 +927,16 @@ void MatroskaContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFee ebmlHeaderDataSize += EbmlElement::calculateSizeDenotationLength(m_doctype.size()); const uint64 ebmlHeaderSize = 4 + EbmlElement::calculateSizeDenotationLength(ebmlHeaderDataSize) + ebmlHeaderDataSize; + // calculate size of "WritingLib"-element + constexpr const char muxingAppName[] = APP_NAME " v" APP_VERSION; + constexpr uint64 muxingAppElementDataSize = sizeof(muxingAppName) - 1; + constexpr uint64 muxingAppElementTotalSize = 2 + 1 + muxingAppElementDataSize; + + // calculate size of "WritingApp"-element + const uint64 writingAppElementDataSize + = fileInfo().writingApplication().empty() ? muxingAppElementDataSize : fileInfo().writingApplication().size() - 1; + const uint64 writingAppElementTotalSize = 2 + 1 + writingAppElementDataSize; + try { // calculate size of "Tags"-element for (auto &tag : tags()) { @@ -1103,7 +1109,7 @@ void MatroskaContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFee } else { // add size of "SegmentInfo"-element // -> size of "MuxingApp"- and "WritingApp"-element - segment.infoDataSize = 2 * appInfoElementTotalSize; + segment.infoDataSize = muxingAppElementTotalSize + writingAppElementTotalSize; // -> add size of "Title"-element if (segmentIndex < m_titles.size()) { const auto &title = m_titles[segmentIndex]; @@ -1617,8 +1623,9 @@ void MatroskaContainer::internalMakeFile(Diagnostics &diag, AbortableProgressFee } } // -> write "MuxingApp"- and "WritingApp"-element - EbmlElement::makeSimpleElement(outputStream, MatroskaIds::MuxingApp, appInfo, appInfoElementDataSize); - EbmlElement::makeSimpleElement(outputStream, MatroskaIds::WrittingApp, appInfo, appInfoElementDataSize); + EbmlElement::makeSimpleElement(outputStream, MatroskaIds::MuxingApp, muxingAppName, muxingAppElementDataSize); + EbmlElement::makeSimpleElement(outputStream, MatroskaIds::WrittingApp, + fileInfo().writingApplication().empty() ? muxingAppName : fileInfo().writingApplication().data(), writingAppElementDataSize); } // write "Tracks"-element diff --git a/mediafileinfo.h b/mediafileinfo.h index 37f2bfc..58d2715 100644 --- a/mediafileinfo.h +++ b/mediafileinfo.h @@ -122,6 +122,9 @@ public: // methods to get, set object behaviour const std::string &saveFilePath() const; void setSaveFilePath(const std::string &saveFilePath); + const std::string writingApplication() const; + void setWritingApplication(const std::string &writingApplication); + void setWritingApplication(const char *writingApplication); bool isForcingFullParse() const; void setForceFullParse(bool forceFullParse); bool isForcingRewrite() const; @@ -174,6 +177,7 @@ private: // fields specifying object behaviour std::string m_saveFilePath; + std::string m_writingApplication; size_t m_minPadding; size_t m_maxPadding; size_t m_preferredPadding; @@ -363,6 +367,34 @@ inline void MediaFileInfo::setSaveFilePath(const std::string &saveFilePath) m_saveFilePath = saveFilePath; } +/*! + * \brief Sets the writing application as container-level meta-data. + * \remarks This is not read from the file when parsing and only used when saving changes. + * \sa setWritingApplication() for more details + */ +inline const std::string MediaFileInfo::writingApplication() const +{ + return m_writingApplication; +} + +/*! + * \brief Sets the writing application as container-level meta-data. Put the name of your application here. + * \remarks Might not be used (depends on the format). + */ +inline void MediaFileInfo::setWritingApplication(const std::string &writingApplication) +{ + m_writingApplication = writingApplication; +} + +/*! + * \brief Sets the writing application as container-level meta-data. Put the name of your application here. + * \remarks Might not be used (depends on the format). + */ +inline void MediaFileInfo::setWritingApplication(const char *writingApplication) +{ + m_writingApplication = writingApplication; +} + /*! * \brief Returns the container for the current file. *