Replace boolean fields in MediaFileInfo with flag enums
This commit is contained in:
parent
0e29c98b9f
commit
32cd02217b
|
@ -85,7 +85,8 @@ MediaFileInfo::MediaFileInfo(std::string &&path)
|
||||||
, m_containerParsingStatus(ParsingStatus::NotParsedYet)
|
, m_containerParsingStatus(ParsingStatus::NotParsedYet)
|
||||||
, m_containerFormat(ContainerFormat::Unknown)
|
, m_containerFormat(ContainerFormat::Unknown)
|
||||||
, m_containerOffset(0)
|
, m_containerOffset(0)
|
||||||
, m_actualExistingId3v1Tag(false)
|
, m_paddingSize(0)
|
||||||
|
, m_fileStructureFlags(MediaFileStructureFlags::None)
|
||||||
, m_tracksParsingStatus(ParsingStatus::NotParsedYet)
|
, m_tracksParsingStatus(ParsingStatus::NotParsedYet)
|
||||||
, m_tagsParsingStatus(ParsingStatus::NotParsedYet)
|
, m_tagsParsingStatus(ParsingStatus::NotParsedYet)
|
||||||
, m_chaptersParsingStatus(ParsingStatus::NotParsedYet)
|
, m_chaptersParsingStatus(ParsingStatus::NotParsedYet)
|
||||||
|
@ -95,10 +96,8 @@ MediaFileInfo::MediaFileInfo(std::string &&path)
|
||||||
, m_preferredPadding(0)
|
, m_preferredPadding(0)
|
||||||
, m_tagPosition(ElementPosition::BeforeData)
|
, m_tagPosition(ElementPosition::BeforeData)
|
||||||
, m_indexPosition(ElementPosition::BeforeData)
|
, m_indexPosition(ElementPosition::BeforeData)
|
||||||
, m_forceFullParse(MEDIAINFO_CPP_FORCE_FULL_PARSE)
|
, m_fileHandlingFlags((MEDIAINFO_CPP_FORCE_FULL_PARSE ? MediaFileHandlingFlags::ForceFullParse : MediaFileHandlingFlags::None)
|
||||||
, m_forceRewrite(true)
|
| MediaFileHandlingFlags::ForceRewrite | MediaFileHandlingFlags::ForceTagPosition | MediaFileHandlingFlags::ForceIndexPosition)
|
||||||
, m_forceTagPosition(true)
|
|
||||||
, m_forceIndexPosition(true)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +237,7 @@ startParsingSignature:
|
||||||
} else if (container->documentType() == "webm") {
|
} else if (container->documentType() == "webm") {
|
||||||
m_containerFormat = ContainerFormat::Webm;
|
m_containerFormat = ContainerFormat::Webm;
|
||||||
}
|
}
|
||||||
if (m_forceFullParse) {
|
if (isForcingFullParse()) {
|
||||||
// validating the element structure of Matroska files takes too long when
|
// validating the element structure of Matroska files takes too long when
|
||||||
// parsing big files so do this only when explicitely desired
|
// parsing big files so do this only when explicitely desired
|
||||||
container->validateElementStructure(diag, progress, &m_paddingSize);
|
container->validateElementStructure(diag, progress, &m_paddingSize);
|
||||||
|
@ -255,7 +254,7 @@ startParsingSignature:
|
||||||
case ContainerFormat::Ogg:
|
case ContainerFormat::Ogg:
|
||||||
// Ogg is handled by OggContainer instance
|
// Ogg is handled by OggContainer instance
|
||||||
m_container = make_unique<OggContainer>(*this, m_containerOffset);
|
m_container = make_unique<OggContainer>(*this, m_containerOffset);
|
||||||
static_cast<OggContainer *>(m_container.get())->setChecksumValidationEnabled(m_forceFullParse);
|
static_cast<OggContainer *>(m_container.get())->setChecksumValidationEnabled(isForcingFullParse());
|
||||||
break;
|
break;
|
||||||
case ContainerFormat::Unknown:
|
case ContainerFormat::Unknown:
|
||||||
// check for magic numbers at odd offsets
|
// check for magic numbers at odd offsets
|
||||||
|
@ -387,7 +386,7 @@ void MediaFileInfo::parseTags(Diagnostics &diag, AbortableProgressFeedback &prog
|
||||||
try {
|
try {
|
||||||
stream().seekg(-128, ios_base::end);
|
stream().seekg(-128, ios_base::end);
|
||||||
m_id3v1Tag->parse(stream(), diag);
|
m_id3v1Tag->parse(stream(), diag);
|
||||||
m_actualExistingId3v1Tag = true;
|
m_fileStructureFlags += MediaFileStructureFlags::ActualExistingId3v1Tag;
|
||||||
} catch (const NoDataFoundException &) {
|
} catch (const NoDataFoundException &) {
|
||||||
m_id3v1Tag.reset();
|
m_id3v1Tag.reset();
|
||||||
} catch (const OperationAbortedException &) {
|
} catch (const OperationAbortedException &) {
|
||||||
|
@ -1331,7 +1330,7 @@ void MediaFileInfo::clearParsingResults()
|
||||||
m_id3v1Tag.reset();
|
m_id3v1Tag.reset();
|
||||||
m_id3v2Tags.clear();
|
m_id3v2Tags.clear();
|
||||||
m_actualId3v2TagOffsets.clear();
|
m_actualId3v2TagOffsets.clear();
|
||||||
m_actualExistingId3v1Tag = false;
|
m_fileStructureFlags = MediaFileStructureFlags::None;
|
||||||
m_container.reset();
|
m_container.reset();
|
||||||
m_singleTrack.reset();
|
m_singleTrack.reset();
|
||||||
}
|
}
|
||||||
|
@ -1540,7 +1539,7 @@ void MediaFileInfo::makeMp3File(Diagnostics &diag, AbortableProgressFeedback &pr
|
||||||
// alter ID3v1 tag
|
// alter ID3v1 tag
|
||||||
if (!m_id3v1Tag) {
|
if (!m_id3v1Tag) {
|
||||||
// remove ID3v1 tag
|
// remove ID3v1 tag
|
||||||
if (!m_actualExistingId3v1Tag) {
|
if (!(m_fileStructureFlags & MediaFileStructureFlags::ActualExistingId3v1Tag)) {
|
||||||
diag.emplace_back(DiagLevel::Information, "Nothing to be changed.", context);
|
diag.emplace_back(DiagLevel::Information, "Nothing to be changed.", context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1555,7 +1554,7 @@ void MediaFileInfo::makeMp3File(Diagnostics &diag, AbortableProgressFeedback &pr
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// add or update ID3v1 tag
|
// add or update ID3v1 tag
|
||||||
if (m_actualExistingId3v1Tag) {
|
if (m_fileStructureFlags & MediaFileStructureFlags::ActualExistingId3v1Tag) {
|
||||||
progress.updateStep("Updating existing ID3v1 tag ...");
|
progress.updateStep("Updating existing ID3v1 tag ...");
|
||||||
// ensure the file is still open / not readonly
|
// ensure the file is still open / not readonly
|
||||||
open();
|
open();
|
||||||
|
@ -1740,7 +1739,7 @@ void MediaFileInfo::makeMp3File(Diagnostics &diag, AbortableProgressFeedback &pr
|
||||||
// copy / skip actual stream data
|
// copy / skip actual stream data
|
||||||
// -> determine media data size
|
// -> determine media data size
|
||||||
std::uint64_t mediaDataSize = size() - streamOffset;
|
std::uint64_t mediaDataSize = size() - streamOffset;
|
||||||
if (m_actualExistingId3v1Tag) {
|
if (m_fileStructureFlags & MediaFileStructureFlags::ActualExistingId3v1Tag) {
|
||||||
mediaDataSize -= 128;
|
mediaDataSize -= 128;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <c++utilities/misc/flagenumclass.h>
|
||||||
|
|
||||||
namespace TagParser {
|
namespace TagParser {
|
||||||
|
|
||||||
class Tag;
|
class Tag;
|
||||||
|
@ -42,6 +44,33 @@ enum class ParsingStatus : std::uint8_t {
|
||||||
CriticalFailure /**< tried to parse the part, but critical errors occurred */
|
CriticalFailure /**< tried to parse the part, but critical errors occurred */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief The MediaFileStructureFlags enum specifies flags which describing the structure of a media file.
|
||||||
|
*/
|
||||||
|
enum class MediaFileStructureFlags : std::uint64_t {
|
||||||
|
None, /**< all flags disabled */
|
||||||
|
ActualExistingId3v1Tag = (1 << 0), /**< whether an ID3v1 tag was found when parsing the file */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief The MediaFileHandlingFlags enum specifies flags which controls the behavior of MediaFileInfo objects.
|
||||||
|
*/
|
||||||
|
enum class MediaFileHandlingFlags : std::uint64_t {
|
||||||
|
None, /**< all flags disabled */
|
||||||
|
ForceFullParse
|
||||||
|
= (1 << 0), /**< causes the parser to analyse the file strucutre as deep as possible; might cause long loading times for big files */
|
||||||
|
ForceRewrite = (1 << 1), /**< enforces a re-write of the file when applying changes */
|
||||||
|
ForceTagPosition = (1 << 2), /**< enforces the tag position when applying changes, see remarks of MediaFileInfo::setTagPosition() */
|
||||||
|
ForceIndexPosition = (1 << 3), /**< enforces the index position when applying changes, see remarks of MediaFileInfo::setIndexPosition() */
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace TagParser
|
||||||
|
|
||||||
|
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(TagParser, TagParser::MediaFileStructureFlags)
|
||||||
|
CPP_UTILITIES_MARK_FLAG_ENUM_CLASS(TagParser, TagParser::MediaFileHandlingFlags)
|
||||||
|
|
||||||
|
namespace TagParser {
|
||||||
|
|
||||||
class TAG_PARSER_EXPORT MediaFileInfo : public BasicFileInfo {
|
class TAG_PARSER_EXPORT MediaFileInfo : public BasicFileInfo {
|
||||||
public:
|
public:
|
||||||
// constructor, destructor
|
// constructor, destructor
|
||||||
|
@ -164,9 +193,9 @@ private:
|
||||||
ContainerFormat m_containerFormat;
|
ContainerFormat m_containerFormat;
|
||||||
std::streamoff m_containerOffset;
|
std::streamoff m_containerOffset;
|
||||||
std::uint64_t m_paddingSize;
|
std::uint64_t m_paddingSize;
|
||||||
bool m_actualExistingId3v1Tag;
|
|
||||||
std::vector<std::streamoff> m_actualId3v2TagOffsets;
|
std::vector<std::streamoff> m_actualId3v2TagOffsets;
|
||||||
std::unique_ptr<AbstractContainer> m_container;
|
std::unique_ptr<AbstractContainer> m_container;
|
||||||
|
MediaFileStructureFlags m_fileStructureFlags;
|
||||||
|
|
||||||
// fields related to the tracks
|
// fields related to the tracks
|
||||||
ParsingStatus m_tracksParsingStatus;
|
ParsingStatus m_tracksParsingStatus;
|
||||||
|
@ -190,10 +219,7 @@ private:
|
||||||
std::size_t m_preferredPadding;
|
std::size_t m_preferredPadding;
|
||||||
ElementPosition m_tagPosition;
|
ElementPosition m_tagPosition;
|
||||||
ElementPosition m_indexPosition;
|
ElementPosition m_indexPosition;
|
||||||
bool m_forceFullParse;
|
MediaFileHandlingFlags m_fileHandlingFlags;
|
||||||
bool m_forceRewrite;
|
|
||||||
bool m_forceTagPosition;
|
|
||||||
bool m_forceIndexPosition;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -454,7 +480,7 @@ inline AbstractContainer *MediaFileInfo::container() const
|
||||||
*/
|
*/
|
||||||
inline bool MediaFileInfo::isForcingFullParse() const
|
inline bool MediaFileInfo::isForcingFullParse() const
|
||||||
{
|
{
|
||||||
return m_forceFullParse;
|
return m_fileHandlingFlags & MediaFileHandlingFlags::ForceFullParse;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -464,7 +490,7 @@ inline bool MediaFileInfo::isForcingFullParse() const
|
||||||
*/
|
*/
|
||||||
inline void MediaFileInfo::setForceFullParse(bool forceFullParse)
|
inline void MediaFileInfo::setForceFullParse(bool forceFullParse)
|
||||||
{
|
{
|
||||||
m_forceFullParse = forceFullParse;
|
CppUtilities::modFlagEnum(m_fileHandlingFlags, MediaFileHandlingFlags::ForceFullParse, forceFullParse);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -472,7 +498,7 @@ inline void MediaFileInfo::setForceFullParse(bool forceFullParse)
|
||||||
*/
|
*/
|
||||||
inline bool MediaFileInfo::isForcingRewrite() const
|
inline bool MediaFileInfo::isForcingRewrite() const
|
||||||
{
|
{
|
||||||
return m_forceRewrite;
|
return m_fileHandlingFlags & MediaFileHandlingFlags::ForceRewrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -480,7 +506,7 @@ inline bool MediaFileInfo::isForcingRewrite() const
|
||||||
*/
|
*/
|
||||||
inline void MediaFileInfo::setForceRewrite(bool forceRewrite)
|
inline void MediaFileInfo::setForceRewrite(bool forceRewrite)
|
||||||
{
|
{
|
||||||
m_forceRewrite = forceRewrite;
|
CppUtilities::modFlagEnum(m_fileHandlingFlags, MediaFileHandlingFlags::ForceRewrite, forceRewrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -591,7 +617,7 @@ inline void MediaFileInfo::setTagPosition(ElementPosition tagPosition)
|
||||||
*/
|
*/
|
||||||
inline bool MediaFileInfo::forceTagPosition() const
|
inline bool MediaFileInfo::forceTagPosition() const
|
||||||
{
|
{
|
||||||
return m_forceTagPosition;
|
return m_fileHandlingFlags & MediaFileHandlingFlags::ForceTagPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -601,7 +627,7 @@ inline bool MediaFileInfo::forceTagPosition() const
|
||||||
*/
|
*/
|
||||||
inline void MediaFileInfo::setForceTagPosition(bool forceTagPosition)
|
inline void MediaFileInfo::setForceTagPosition(bool forceTagPosition)
|
||||||
{
|
{
|
||||||
m_forceTagPosition = forceTagPosition;
|
CppUtilities::modFlagEnum(m_fileHandlingFlags, MediaFileHandlingFlags::ForceTagPosition, forceTagPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -631,7 +657,7 @@ inline void MediaFileInfo::setIndexPosition(ElementPosition indexPosition)
|
||||||
*/
|
*/
|
||||||
inline bool MediaFileInfo::forceIndexPosition() const
|
inline bool MediaFileInfo::forceIndexPosition() const
|
||||||
{
|
{
|
||||||
return m_forceIndexPosition;
|
return m_fileHandlingFlags & MediaFileHandlingFlags::ForceIndexPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -641,7 +667,7 @@ inline bool MediaFileInfo::forceIndexPosition() const
|
||||||
*/
|
*/
|
||||||
inline void MediaFileInfo::setForceIndexPosition(bool forceIndexPosition)
|
inline void MediaFileInfo::setForceIndexPosition(bool forceIndexPosition)
|
||||||
{
|
{
|
||||||
m_forceIndexPosition = forceIndexPosition;
|
CppUtilities::modFlagEnum(m_fileHandlingFlags, MediaFileHandlingFlags::ForceIndexPosition, forceIndexPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace TagParser
|
} // namespace TagParser
|
||||||
|
|
Loading…
Reference in New Issue