Allow checking tag position

Only implemented for MP4 so far
This commit is contained in:
Martchus 2016-11-15 22:48:38 +01:00
parent f6d0f3a003
commit 6717062ca2
8 changed files with 39 additions and 11 deletions

View File

@ -159,8 +159,8 @@ set(META_APP_AUTHOR "Martchus")
set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}") set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
set(META_APP_DESCRIPTION "C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags") set(META_APP_DESCRIPTION "C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags")
set(META_VERSION_MAJOR 6) set(META_VERSION_MAJOR 6)
set(META_VERSION_MINOR 0) set(META_VERSION_MINOR 1)
set(META_VERSION_PATCH 1) set(META_VERSION_PATCH 0)
set(META_PUBLIC_SHARED_LIB_DEPENDS c++utilities) set(META_PUBLIC_SHARED_LIB_DEPENDS c++utilities)
set(META_PUBLIC_STATIC_LIB_DEPENDS c++utilities_static) set(META_PUBLIC_STATIC_LIB_DEPENDS c++utilities_static)
set(META_PRIVATE_COMPILE_DEFINITIONS LEGACY_API) set(META_PRIVATE_COMPILE_DEFINITIONS LEGACY_API)

View File

@ -315,6 +315,16 @@ bool AbstractContainer::removeTag(Tag *)
void AbstractContainer::removeAllTags() void AbstractContainer::removeAllTags()
{} {}
/*!
* \brief Determines the position of the tags inside the file.
* \returns Returns ElementPosition::BeforeData or ElementPosition::AfterData if the position could
* be determined; otherwise returns ElementPosition::Keep.
*/
ElementPosition AbstractContainer::determineTagPosition() const
{
return ElementPosition::Keep;
}
/*! /*!
* \brief Returns the track with the specified \a index. * \brief Returns the track with the specified \a index.
* *

View File

@ -13,10 +13,8 @@
#include <iostream> #include <iostream>
namespace IoUtilities { namespace IoUtilities {
class BinaryReader; class BinaryReader;
class BinaryWriter; class BinaryWriter;
} }
namespace Media { namespace Media {
@ -26,6 +24,13 @@ class AbstractTrack;
class AbstractChapter; class AbstractChapter;
class AbstractAttachment; class AbstractAttachment;
enum class ElementPosition
{
BeforeData, /**< the element is positioned before the actual data */
AfterData, /**< the element is positioned after the actual data */
Keep /**< the element is placed where it was before */
};
class TAG_PARSER_EXPORT AbstractContainer : public StatusProvider class TAG_PARSER_EXPORT AbstractContainer : public StatusProvider
{ {
public: public:
@ -55,6 +60,7 @@ public:
virtual std::size_t tagCount() const; virtual std::size_t tagCount() const;
virtual bool removeTag(Tag *tag); virtual bool removeTag(Tag *tag);
virtual void removeAllTags(); virtual void removeAllTags();
virtual ElementPosition determineTagPosition() const;
virtual AbstractTrack *track(std::size_t index); virtual AbstractTrack *track(std::size_t index);
virtual std::size_t trackCount() const; virtual std::size_t trackCount() const;

View File

@ -332,6 +332,11 @@ generateRandomId:
return attachment.get(); return attachment.get();
} }
ElementPosition MatroskaContainer::determineTagPosition() const
{
return ElementPosition::Keep; // TODO
}
void MatroskaContainer::internalParseHeader() void MatroskaContainer::internalParseHeader()
{ {
static const string context("parsing header of Matroska container"); static const string context("parsing header of Matroska container");

View File

@ -41,6 +41,7 @@ public:
MatroskaAttachment *createAttachment(); MatroskaAttachment *createAttachment();
MatroskaAttachment *attachment(std::size_t index); MatroskaAttachment *attachment(std::size_t index);
std::size_t attachmentCount() const; std::size_t attachmentCount() const;
ElementPosition determineTagPosition() const;
virtual bool supportsTitle() const; virtual bool supportsTitle() const;
virtual std::size_t segmentCount() const; virtual std::size_t segmentCount() const;

View File

@ -37,13 +37,6 @@ enum class TagUsage
Never /**< tags of the type are never used; a possibly existing tag of the type is removed */ Never /**< tags of the type are never used; a possibly existing tag of the type is removed */
}; };
enum class ElementPosition
{
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 */
};
/*! /*!
* \brief The ParsingStatus enum specifies whether a certain part of the file (tracks, tags, ...) has * \brief The ParsingStatus enum specifies whether a certain part of the file (tracks, tags, ...) has
* been parsed yet and if what the parsing result is. * been parsed yet and if what the parsing result is.

View File

@ -45,6 +45,18 @@ void Mp4Container::reset()
m_fragmented = false; m_fragmented = false;
} }
ElementPosition Mp4Container::determineTagPosition() const
{
if(m_firstElement) {
Mp4Atom *mediaDataAtom = m_firstElement->siblingById(Mp4AtomIds::MediaData);
Mp4Atom *userDataAtom = m_firstElement->subelementByPath({Mp4AtomIds::Movie, Mp4AtomIds::UserData});
if(mediaDataAtom && userDataAtom) {
return userDataAtom->startOffset() < mediaDataAtom->startOffset() ? ElementPosition::BeforeData : ElementPosition::AfterData;
}
}
return ElementPosition::Keep;
}
void Mp4Container::internalParseHeader() void Mp4Container::internalParseHeader()
{ {
//const string context("parsing header of MP4 container"); will be used when generating notifications //const string context("parsing header of MP4 container"); will be used when generating notifications

View File

@ -25,6 +25,7 @@ public:
bool supportsTrackModifications() const; bool supportsTrackModifications() const;
bool isFragmented() const; bool isFragmented() const;
void reset(); void reset();
ElementPosition determineTagPosition() const;
protected: protected:
void internalParseHeader(); void internalParseHeader();