tagparser/matroska/matroskacues.h

131 lines
3.7 KiB
C
Raw Normal View History

#ifndef TAG_PARSER_MATROSKACUES_H
#define TAG_PARSER_MATROSKACUES_H
2015-04-22 19:22:01 +02:00
2015-09-06 19:57:33 +02:00
#include "./ebmlelement.h"
2015-04-22 19:22:01 +02:00
#include <ostream>
2018-03-07 01:17:50 +01:00
#include <unordered_map>
2015-04-22 19:22:01 +02:00
namespace TagParser {
2015-04-22 19:22:01 +02:00
2018-03-07 01:17:50 +01:00
class TAG_PARSER_EXPORT MatroskaOffsetStates {
2015-04-22 19:22:01 +02:00
public:
2019-03-13 19:06:42 +01:00
constexpr MatroskaOffsetStates(std::uint64_t initialValue);
constexpr std::uint64_t currentValue() const;
void update(std::uint64_t newValue);
constexpr std::uint64_t initialValue() const;
2018-03-07 01:17:50 +01:00
2015-04-22 19:22:01 +02:00
private:
2019-03-13 19:06:42 +01:00
std::uint64_t m_initialValue;
std::uint64_t m_currentValue;
2015-04-22 19:22:01 +02:00
};
2019-03-13 19:06:42 +01:00
constexpr MatroskaOffsetStates::MatroskaOffsetStates(std::uint64_t initialValue)
2018-03-07 01:17:50 +01:00
: m_initialValue(initialValue)
, m_currentValue(initialValue)
{
}
2015-04-22 19:22:01 +02:00
2019-03-13 19:06:42 +01:00
constexpr std::uint64_t MatroskaOffsetStates::currentValue() const
2015-04-22 19:22:01 +02:00
{
return m_currentValue;
}
2019-03-13 19:06:42 +01:00
inline void MatroskaOffsetStates::update(std::uint64_t newValue)
2015-04-22 19:22:01 +02:00
{
m_currentValue = newValue;
}
2019-03-13 19:06:42 +01:00
constexpr std::uint64_t MatroskaOffsetStates::initialValue() const
2015-04-22 19:22:01 +02:00
{
return m_initialValue;
}
2018-03-07 01:17:50 +01:00
class TAG_PARSER_EXPORT MatroskaReferenceOffsetPair : public MatroskaOffsetStates {
2015-04-22 19:22:01 +02:00
public:
2019-03-13 19:06:42 +01:00
constexpr MatroskaReferenceOffsetPair(std::uint64_t referenceOffset, std::uint64_t initialValue);
constexpr std::uint64_t referenceOffset() const;
2018-03-07 01:17:50 +01:00
2015-04-22 19:22:01 +02:00
private:
2019-03-13 19:06:42 +01:00
std::uint64_t m_referenceOffset;
2015-04-22 19:22:01 +02:00
};
2019-03-13 19:06:42 +01:00
constexpr MatroskaReferenceOffsetPair::MatroskaReferenceOffsetPair(std::uint64_t referenceOffset, std::uint64_t initialValue)
2018-03-07 01:17:50 +01:00
: MatroskaOffsetStates(initialValue)
, m_referenceOffset(referenceOffset)
{
}
2015-04-22 19:22:01 +02:00
2019-03-13 19:06:42 +01:00
constexpr std::uint64_t MatroskaReferenceOffsetPair::referenceOffset() const
2015-04-22 19:22:01 +02:00
{
return m_referenceOffset;
}
2018-03-07 01:17:50 +01:00
class TAG_PARSER_EXPORT MatroskaCuePositionUpdater {
2015-04-22 19:22:01 +02:00
public:
MatroskaCuePositionUpdater();
EbmlElement *cuesElement() const;
2019-03-13 19:06:42 +01:00
std::uint64_t totalSize() const;
2015-04-22 19:22:01 +02:00
void parse(EbmlElement *cuesElement, Diagnostics &diag);
2019-03-13 19:06:42 +01:00
bool updateOffsets(std::uint64_t originalOffset, std::uint64_t newOffset);
bool updateRelativeOffsets(std::uint64_t referenceOffset, std::uint64_t originalRelativeOffset, std::uint64_t newRelativeOffset);
void make(std::ostream &stream, Diagnostics &diag);
2015-04-22 19:22:01 +02:00
void clear();
private:
struct PairHash {
template <class T1, class T2> inline std::size_t operator()(const std::pair<T1, T2> &pair) const
{
std::size_t seed = 0;
seed ^= std::hash<T1>()(pair.first) + 0x9e3779b9;
seed ^= std::hash<T2>()(pair.second) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
return seed;
}
};
2015-04-22 19:22:01 +02:00
bool updateSize(EbmlElement *element, int shift);
EbmlElement *m_cuesElement;
std::unordered_map<EbmlElement *, MatroskaOffsetStates> m_offsets;
std::unordered_multimap<std::uint64_t, EbmlElement *> m_cueElementByOriginalOffset;
std::unordered_map<EbmlElement *, MatroskaReferenceOffsetPair> m_relativeOffsets;
std::unordered_multimap<std::pair<std::uint64_t, std::uint64_t>, EbmlElement *, PairHash> m_cueRelativePositionElementByOriginalOffsets;
2019-03-13 19:06:42 +01:00
std::unordered_map<EbmlElement *, std::uint64_t> m_sizes;
2015-04-22 19:22:01 +02:00
};
/*!
* \brief Creates a new MatroskaCuePositionUpdater.
*
* The parse() method should be called to do further initialization.
*/
2018-03-07 01:17:50 +01:00
inline MatroskaCuePositionUpdater::MatroskaCuePositionUpdater()
: m_cuesElement(nullptr)
{
}
2015-04-22 19:22:01 +02:00
/*!
* \brief Returns the "Cues"-element specified when calling the parse() method.
*
* Returns nullptr if no "Cues"-element is set.
*/
inline EbmlElement *MatroskaCuePositionUpdater::cuesElement() const
{
return m_cuesElement;
}
/*!
* \brief Resets the object to its initial state. Parsing results and updates are cleared.
*/
inline void MatroskaCuePositionUpdater::clear()
{
m_cuesElement = nullptr;
m_offsets.clear();
m_sizes.clear();
}
2018-03-07 01:17:50 +01:00
} // namespace TagParser
2015-04-22 19:22:01 +02:00
#endif // TAG_PARSER_MATROSKACUES_H