Tag Parser: matroska/ebmlelement.h Source File

Tag Parser 12.5.3 C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags

Loading...
Searching...
No Matches
ebmlelement.h
Go to the documentation of this file.
1#ifndef TAG_PARSER_EBMLELEMENT_H
2#define TAG_PARSER_EBMLELEMENT_H
3
4#include "./ebmlid.h"
5#include "./matroskaid.h"
6
7#include "../genericfileelement.h"
8
9#include <c++utilities/conversion/stringbuilder.h>
10#include <c++utilities/conversion/stringconversion.h>
11
12#include <cstdint>
13#include <iostream>
14#include <memory>
15#include <string_view>
16
17namespace TagParser {
18
19class EbmlElement;
20class MatroskaContainer;
21
25 template <> class TAG_PARSER_EXPORT FileElementTraits<EbmlElement> {
26public:
27 using ContainerType = MatroskaContainer;
28 using IdentifierType = std::uint32_t;
29 using DataSizeType = std::uint64_t;
30};
31
32 class TAG_PARSER_EXPORT EbmlElement : public GenericFileElement<EbmlElement> {
33 friend class GenericFileElement<EbmlElement>;
34
35public:
36 EbmlElement(MatroskaContainer &container, std::uint64_t startOffset);
37
38 std::string idToString() const;
39 bool isParent() const;
40 bool isPadding() const;
41 std::uint64_t firstChildOffset() const;
42 std::string readString();
43 std::uint64_t readUInteger();
44 double readFloat();
45
46 static std::uint8_t calculateIdLength(IdentifierType id);
47 static std::uint8_t calculateSizeDenotationLength(std::uint64_t size);
48 static std::uint8_t makeId(IdentifierType id, char *buff);
49 static std::uint8_t makeSizeDenotation(std::uint64_t size, char *buff);
50 static std::uint8_t makeSizeDenotation(std::uint64_t size, char *buff, std::uint8_t minBytes);
51 static std::uint8_t calculateUIntegerLength(std::uint64_t integer);
52 static std::uint8_t makeUInteger(std::uint64_t value, char *buff);
53 static std::uint8_t makeUInteger(std::uint64_t value, char *buff, std::uint8_t minBytes);
54 static void makeSimpleElement(std::ostream &stream, IdentifierType id, std::uint64_t content);
55 static void makeSimpleElement(std::ostream &stream, IdentifierType id, std::string_view content);
56 static std::uint64_t bytesToBeSkipped;
57
58protected:
59 EbmlElement(EbmlElement &parent, std::uint64_t startOffset);
60 EbmlElement(MatroskaContainer &container, std::uint64_t startOffset, std::uint64_t maxSize);
61
62 void internalParse(Diagnostics &diag);
63
64private:
65 std::string parsingContext() const;
66};
67
71 inline std::string EbmlElement::idToString() const
72{
73 using namespace CppUtilities;
74 if (const auto name = matroskaIdName(id()); !name.empty()) {
75 return argsToString('0', 'x', numberToString(id(), 16u), ' ', '\"', name, '\"');
76 } else {
77 return "0x" + numberToString(id(), 16u);
78 }
79}
80
87 inline bool EbmlElement::isParent() const
88{
89 using namespace EbmlIds;
90 using namespace MatroskaIds;
91 switch (id()) {
92 case Header:
93 case SignatureSlot:
94 case SignatureElements:
95 case SignatureElementList:
96 case Segment:
97 case SeekHead:
98 case Seek:
99 case SegmentInfo:
100 case ChapterTranslate:
101 case Cluster:
102 case SilentTracks:
103 case BlockGroup:
104 case BlockAdditions:
105 case BlockMore:
106 case Slices:
107 case TimeSlice:
108 case ReferenceFrame:
109 case Tracks:
110 case TrackEntry:
111 case TrackTranslate:
112 case TrackVideo:
113 case TrackAudio:
114 case TrackOperation:
115 case TrackCombinePlanes:
116 case TrackPlane:
117 case TrackJoinBlocks:
118 case ContentEncodings:
119 case ContentEncoding:
120 case ContentCompression:
121 case ContentEncryption:
122 case Cues:
123 case CuePoint:
124 case CueTrackPositions:
125 case CueReference:
126 case Attachments:
127 case AttachedFile:
128 case Chapters:
129 case EditionEntry:
130 case ChapterAtom:
131 case ChapterTrack:
132 case ChapterDisplay:
133 case ChapProcess:
134 case ChapProcessCommand:
135 case Tags:
136 case MatroskaIds::Tag:
137 case Targets:
138 case SimpleTag:
139 return true;
140 default:
141 return false;
142 }
143}
144
148 inline bool EbmlElement::isPadding() const
149{
150 return id() == EbmlIds::Void;
151}
152
157 inline std::uint64_t EbmlElement::firstChildOffset() const
158{
159 return isParent() ? (idLength() + sizeLength()) : 0;
160}
161
162} // namespace TagParser
163
164#endif // TAG_PARSER_EBMLELEMENT_H
TagParser::Diagnostics
The Diagnostics class is a container for DiagMessage.
Definition diagnostics.h:156
TagParser::EbmlElement
The EbmlElement class helps to parse EBML files such as Matroska files.
Definition ebmlelement.h:32
TagParser::EbmlElement::makeSimpleElement
static void makeSimpleElement(std::ostream &stream, IdentifierType id, std::string_view content)
TagParser::EbmlElement::firstChildOffset
std::uint64_t firstChildOffset() const
Returns the offset of the first child of the element.
Definition ebmlelement.h:157
TagParser::EbmlElement::isPadding
bool isPadding() const
Returns an indication whether the element is considered as padding.
Definition ebmlelement.h:148
TagParser::EbmlElement::makeUInteger
static std::uint8_t makeUInteger(std::uint64_t value, char *buff)
Writes value to buff.
Definition ebmlelement.cpp:441
TagParser::EbmlElement::EbmlElement
EbmlElement(MatroskaContainer &container, std::uint64_t startOffset)
Constructs a new top level element with the specified container at the specified startOffset.
Definition ebmlelement.cpp:37
TagParser::EbmlElement::calculateIdLength
static std::uint8_t calculateIdLength(IdentifierType id)
Returns the length of the specified id in byte.
Definition ebmlelement.cpp:269
TagParser::EbmlElement::makeSimpleElement
static void makeSimpleElement(std::ostream &stream, IdentifierType id, std::uint64_t content)
Makes a simple EBML element.
Definition ebmlelement.cpp:514
TagParser::EbmlElement::calculateSizeDenotationLength
static std::uint8_t calculateSizeDenotationLength(std::uint64_t size)
Returns the length of the size denotation for the specified size in byte.
Definition ebmlelement.cpp:288
TagParser::EbmlElement::makeId
static std::uint8_t makeId(IdentifierType id, char *buff)
Stores the specified id in the specified buffer which must be at least 8 bytes long.
Definition ebmlelement.cpp:317
TagParser::EbmlElement::readFloat
double readFloat()
Reads the content of the element as float.
Definition ebmlelement.cpp:252
TagParser::EbmlElement::bytesToBeSkipped
static std::uint64_t bytesToBeSkipped
Specifies the number of bytes to be skipped till a valid EBML element is found in the stream.
Definition ebmlelement.h:56
TagParser::EbmlElement::idToString
std::string idToString() const
Converts the specified EBML ID to a printable string.
Definition ebmlelement.h:71
TagParser::EbmlElement::readString
std::string readString()
Reads the content of the element as string.
Definition ebmlelement.cpp:226
TagParser::EbmlElement::readUInteger
std::uint64_t readUInteger()
Reads the content of the element as unsigned integer.
Definition ebmlelement.cpp:238
TagParser::EbmlElement::makeSizeDenotation
static std::uint8_t makeSizeDenotation(std::uint64_t size, char *buff)
Makes the size denotation for the specified size and stores it to buff.
Definition ebmlelement.cpp:343
TagParser::EbmlElement::internalParse
void internalParse(Diagnostics &diag)
Parses the EBML element.
Definition ebmlelement.cpp:69
TagParser::EbmlElement::calculateUIntegerLength
static std::uint8_t calculateUIntegerLength(std::uint64_t integer)
Returns the length of the specified unsigned integer in byte.
Definition ebmlelement.cpp:416
TagParser::EbmlElement::isParent
bool isParent() const
Returns an indication whether the element is a parent element.
Definition ebmlelement.h:87
TagParser::FileElementTraits< EbmlElement >::ContainerType
MatroskaContainer ContainerType
Definition ebmlelement.h:27
TagParser::FileElementTraits< EbmlElement >::DataSizeType
std::uint64_t DataSizeType
Definition ebmlelement.h:29
TagParser::FileElementTraits< EbmlElement >::IdentifierType
std::uint32_t IdentifierType
Definition ebmlelement.h:28
TagParser::FileElementTraits
Defines traits for the specified ImplementationType.
Definition genericfileelement.h:34
TagParser::GenericFileElement< EbmlElement >::GenericFileElement
GenericFileElement(ContainerType &container, std::uint64_t startOffset)
TagParser::GenericFileElement< EbmlElement >::startOffset
std::uint64_t startOffset() const
Definition genericfileelement.h:266
TagParser::GenericFileElement< EbmlElement >::id
const IdentifierType & id() const
Definition genericfileelement.h:283
TagParser::GenericFileElement< EbmlElement >::stream
std::iostream & stream()
Definition genericfileelement.h:242
TagParser::GenericFileElement< EbmlElement >::parent
EbmlElement * parent()
Definition genericfileelement.h:390
TagParser::GenericFileElement< EbmlElement >::sizeLength
std::uint32_t sizeLength() const
Definition genericfileelement.h:328
TagParser::GenericFileElement< EbmlElement >::IdentifierType
typename FileElementTraits< EbmlElement >::IdentifierType IdentifierType
Definition genericfileelement.h:56
TagParser::GenericFileElement< EbmlElement >::container
ContainerType & container()
Definition genericfileelement.h:225
TagParser::GenericFileElement< EbmlElement >::idLength
std::uint32_t idLength() const
Definition genericfileelement.h:299
TagParser::MatroskaContainer
Implementation of GenericContainer<MediaFileInfo, MatroskaTag, MatroskaTrack, EbmlElement>.
Definition matroskacontainer.h:24
ebmlid.h
genericfileelement.h
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
matroskaid.h
CppUtilities
Definition abstractcontainer.h:16
TagParser::EbmlIds
Encapsulates all EBML ID values.
Definition ebmlid.h:9
TagParser::EbmlIds::Void
@ Void
Definition ebmlid.h:28
TagParser::MatroskaIds
Encapsulates the most common Matroska element IDs.
Definition matroskaid.h:11
TagParser::MatroskaIds::Tag
@ Tag
Definition matroskaid.h:211
TagParser
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
TagParser::matroskaIdName
TAG_PARSER_EXPORT std::string_view matroskaIdName(std::uint32_t matroskaId)
Returns a string for the specified matroskaId if known; otherwise returns an empty string.
Definition matroskaid.cpp:22