tagparser/matroska/matroskacues.h

119 lines
2.9 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:
2018-07-10 14:11:11 +02:00
constexpr MatroskaOffsetStates(uint64 initialValue);
constexpr uint64 currentValue() const;
2015-04-22 19:22:01 +02:00
void update(uint64 newValue);
2018-07-10 14:11:11 +02:00
constexpr uint64 initialValue() const;
2018-03-07 01:17:50 +01:00
2015-04-22 19:22:01 +02:00
private:
uint64 m_initialValue;
uint64 m_currentValue;
};
2018-07-10 14:11:11 +02:00
constexpr MatroskaOffsetStates::MatroskaOffsetStates(uint64 initialValue)
2018-03-07 01:17:50 +01:00
: m_initialValue(initialValue)
, m_currentValue(initialValue)
{
}
2015-04-22 19:22:01 +02:00
2018-07-10 14:11:11 +02:00
constexpr uint64 MatroskaOffsetStates::currentValue() const
2015-04-22 19:22:01 +02:00
{
return m_currentValue;
}
inline void MatroskaOffsetStates::update(uint64 newValue)
{
m_currentValue = newValue;
}
2018-07-10 14:11:11 +02:00
constexpr uint64 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:
2018-07-10 14:11:11 +02:00
constexpr MatroskaReferenceOffsetPair(uint64 referenceOffset, uint64 initialValue);
constexpr uint64 referenceOffset() const;
2018-03-07 01:17:50 +01:00
2015-04-22 19:22:01 +02:00
private:
uint64 m_referenceOffset;
};
2018-07-10 14:11:11 +02:00
constexpr MatroskaReferenceOffsetPair::MatroskaReferenceOffsetPair(uint64 referenceOffset, uint64 initialValue)
2018-03-07 01:17:50 +01:00
: MatroskaOffsetStates(initialValue)
, m_referenceOffset(referenceOffset)
{
}
2015-04-22 19:22:01 +02:00
2018-07-10 14:11:11 +02:00
constexpr uint64 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;
uint64 totalSize() const;
void parse(EbmlElement *cuesElement, Diagnostics &diag);
2015-04-22 19:22:01 +02:00
bool updateOffsets(uint64 originalOffset, uint64 newOffset);
bool updateRelativeOffsets(uint64 referenceOffset, uint64 originalRelativeOffset, uint64 newRelativeOffset);
void make(std::ostream &stream, Diagnostics &diag);
2015-04-22 19:22:01 +02:00
void clear();
private:
bool updateSize(EbmlElement *element, int shift);
EbmlElement *m_cuesElement;
std::unordered_map<EbmlElement *, MatroskaOffsetStates> m_offsets;
std::unordered_map<EbmlElement *, MatroskaReferenceOffsetPair> m_relativeOffsets;
std::unordered_map<EbmlElement *, uint64> 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