2018-03-06 23:09:15 +01:00
|
|
|
#ifndef TAG_PARSER_EBMLELEMENT_H
|
|
|
|
#define TAG_PARSER_EBMLELEMENT_H
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2015-09-06 19:57:33 +02:00
|
|
|
#include "./ebmlid.h"
|
|
|
|
#include "./matroskaid.h"
|
2015-09-06 15:42:18 +02:00
|
|
|
|
2015-09-06 19:57:33 +02:00
|
|
|
#include "../genericfileelement.h"
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2017-01-27 21:27:24 +01:00
|
|
|
#include <c++utilities/conversion/stringbuilder.h>
|
|
|
|
#include <c++utilities/conversion/stringconversion.h>
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2019-03-13 19:06:42 +01:00
|
|
|
#include <cstdint>
|
2015-04-22 19:22:01 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
|
|
|
|
2018-03-06 23:09:15 +01:00
|
|
|
namespace TagParser {
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
class EbmlElement;
|
|
|
|
class MatroskaContainer;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Defines traits for the GenericFileElement implementation EbmlElement.
|
|
|
|
*/
|
2018-03-07 01:17:50 +01:00
|
|
|
template <> class TAG_PARSER_EXPORT FileElementTraits<EbmlElement> {
|
2015-04-22 19:22:01 +02:00
|
|
|
public:
|
2018-07-11 13:19:43 +02:00
|
|
|
using ContainerType = MatroskaContainer;
|
2019-03-13 19:06:42 +01:00
|
|
|
using IdentifierType = std::uint32_t;
|
|
|
|
using DataSizeType = std::uint64_t;
|
2015-04-22 19:22:01 +02:00
|
|
|
};
|
|
|
|
|
2018-03-07 01:17:50 +01:00
|
|
|
class TAG_PARSER_EXPORT EbmlElement : public GenericFileElement<EbmlElement> {
|
2015-04-22 19:22:01 +02:00
|
|
|
friend class GenericFileElement<EbmlElement>;
|
|
|
|
|
|
|
|
public:
|
2019-03-13 19:06:42 +01:00
|
|
|
EbmlElement(MatroskaContainer &container, std::uint64_t startOffset);
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
std::string idToString() const;
|
|
|
|
bool isParent() const;
|
|
|
|
bool isPadding() const;
|
2019-03-13 19:06:42 +01:00
|
|
|
std::uint64_t firstChildOffset() const;
|
2015-04-22 19:22:01 +02:00
|
|
|
std::string readString();
|
2019-03-13 19:06:42 +01:00
|
|
|
std::uint64_t readUInteger();
|
|
|
|
double readFloat();
|
|
|
|
|
|
|
|
static std::uint8_t calculateIdLength(IdentifierType id);
|
|
|
|
static std::uint8_t calculateSizeDenotationLength(std::uint64_t size);
|
|
|
|
static std::uint8_t makeId(IdentifierType id, char *buff);
|
|
|
|
static std::uint8_t makeSizeDenotation(std::uint64_t size, char *buff);
|
|
|
|
static std::uint8_t makeSizeDenotation(std::uint64_t size, char *buff, std::uint8_t minBytes);
|
|
|
|
static std::uint8_t calculateUIntegerLength(std::uint64_t integer);
|
|
|
|
static std::uint8_t makeUInteger(std::uint64_t value, char *buff);
|
|
|
|
static std::uint8_t makeUInteger(std::uint64_t value, char *buff, std::uint8_t minBytes);
|
|
|
|
static void makeSimpleElement(std::ostream &stream, IdentifierType id, std::uint64_t content);
|
2017-03-07 17:16:17 +01:00
|
|
|
static void makeSimpleElement(std::ostream &stream, IdentifierType id, const std::string &content);
|
|
|
|
static void makeSimpleElement(std::ostream &stream, IdentifierType id, const char *data, std::size_t dataSize);
|
2019-03-13 19:06:42 +01:00
|
|
|
static std::uint64_t bytesToBeSkipped;
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
protected:
|
2019-03-13 19:06:42 +01:00
|
|
|
EbmlElement(EbmlElement &parent, std::uint64_t startOffset);
|
|
|
|
EbmlElement(MatroskaContainer &container, std::uint64_t startOffset, std::uint64_t maxSize);
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2018-03-05 17:49:29 +01:00
|
|
|
void internalParse(Diagnostics &diag);
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::string parsingContext() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Converts the specified EBML \a ID to a printable string.
|
|
|
|
*/
|
|
|
|
inline std::string EbmlElement::idToString() const
|
|
|
|
{
|
2019-06-10 22:49:11 +02:00
|
|
|
using namespace CppUtilities;
|
2017-09-14 18:19:12 +02:00
|
|
|
const char *const name = matroskaIdName(id());
|
2018-03-07 01:17:50 +01:00
|
|
|
if (*name) {
|
2017-09-14 18:19:12 +02:00
|
|
|
return argsToString('0', 'x', numberToString(id(), 16), ' ', '\"', name, '\"');
|
2017-01-27 21:27:24 +01:00
|
|
|
} else {
|
|
|
|
return "0x" + numberToString(id(), 16);
|
2015-04-22 19:22:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns an indication whether the element is a parent element.
|
|
|
|
* \remarks This information is not read from the element header. Some
|
|
|
|
* elements are simply known to be parents whereas all other
|
|
|
|
* are considered as non-parents.
|
|
|
|
*/
|
|
|
|
inline bool EbmlElement::isParent() const
|
|
|
|
{
|
|
|
|
using namespace EbmlIds;
|
|
|
|
using namespace MatroskaIds;
|
2018-03-07 01:17:50 +01:00
|
|
|
switch (id()) {
|
2015-04-22 19:22:01 +02:00
|
|
|
case Header:
|
2018-03-07 01:17:50 +01:00
|
|
|
case SignatureSlot:
|
|
|
|
case SignatureElements:
|
|
|
|
case SignatureElementList:
|
|
|
|
case Segment:
|
|
|
|
case SeekHead:
|
|
|
|
case Seek:
|
|
|
|
case SegmentInfo:
|
|
|
|
case ChapterTranslate:
|
|
|
|
case Cluster:
|
|
|
|
case SilentTracks:
|
|
|
|
case BlockGroup:
|
|
|
|
case BlockAdditions:
|
|
|
|
case BlockMore:
|
|
|
|
case Slices:
|
|
|
|
case TimeSlice:
|
|
|
|
case ReferenceFrame:
|
|
|
|
case Tracks:
|
|
|
|
case TrackEntry:
|
|
|
|
case TrackTranslate:
|
|
|
|
case TrackVideo:
|
|
|
|
case TrackAudio:
|
|
|
|
case TrackOperation:
|
|
|
|
case TrackCombinePlanes:
|
|
|
|
case TrackPlane:
|
|
|
|
case TrackJoinBlocks:
|
|
|
|
case ContentEncodings:
|
|
|
|
case ContentEncoding:
|
|
|
|
case ContentCompression:
|
|
|
|
case ContentEncryption:
|
|
|
|
case Cues:
|
|
|
|
case CuePoint:
|
|
|
|
case CueTrackPositions:
|
|
|
|
case CueReference:
|
|
|
|
case Attachments:
|
|
|
|
case AttachedFile:
|
|
|
|
case Chapters:
|
|
|
|
case EditionEntry:
|
|
|
|
case ChapterAtom:
|
|
|
|
case ChapterTrack:
|
|
|
|
case ChapterDisplay:
|
|
|
|
case ChapProcess:
|
|
|
|
case ChapProcessCommand:
|
|
|
|
case Tags:
|
|
|
|
case MatroskaIds::Tag:
|
|
|
|
case Targets:
|
|
|
|
case SimpleTag:
|
2015-04-22 19:22:01 +02:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns an indication whether the element is considered as padding.
|
|
|
|
*/
|
|
|
|
inline bool EbmlElement::isPadding() const
|
|
|
|
{
|
|
|
|
return id() == EbmlIds::Void;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the offset of the first child of the element.
|
2016-03-13 22:00:23 +01:00
|
|
|
* \remarks The returned offset is relative to the start offset if this element.
|
2015-04-22 19:22:01 +02:00
|
|
|
*/
|
2019-03-13 19:06:42 +01:00
|
|
|
inline std::uint64_t EbmlElement::firstChildOffset() const
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
return isParent() ? (idLength() + sizeLength()) : 0;
|
|
|
|
}
|
|
|
|
|
2018-03-07 01:17:50 +01:00
|
|
|
} // namespace TagParser
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2018-03-06 23:09:15 +01:00
|
|
|
#endif // TAG_PARSER_EBMLELEMENT_H
|