Tag Parser 12.5.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
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;
21
26public:
28 using IdentifierType = std::uint32_t;
29 using DataSizeType = std::uint64_t;
30};
31
33 friend class GenericFileElement<EbmlElement>;
34
35public:
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:
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
71inline 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
87inline 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
148inline bool EbmlElement::isPadding() const
149{
150 return id() == EbmlIds::Void;
151}
152
157inline 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
The Diagnostics class is a container for DiagMessage.
The EbmlElement class helps to parse EBML files such as Matroska files.
Definition ebmlelement.h:32
static void makeSimpleElement(std::ostream &stream, IdentifierType id, std::string_view content)
std::uint64_t firstChildOffset() const
Returns the offset of the first child of the element.
bool isPadding() const
Returns an indication whether the element is considered as padding.
static std::uint8_t makeUInteger(std::uint64_t value, char *buff)
Writes value to buff.
EbmlElement(MatroskaContainer &container, std::uint64_t startOffset)
Constructs a new top level element with the specified container at the specified startOffset.
static std::uint8_t calculateIdLength(IdentifierType id)
Returns the length of the specified id in byte.
static void makeSimpleElement(std::ostream &stream, IdentifierType id, std::uint64_t content)
Makes a simple EBML element.
static std::uint8_t calculateSizeDenotationLength(std::uint64_t size)
Returns the length of the size denotation for the specified size in byte.
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.
double readFloat()
Reads the content of the element as float.
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
std::string idToString() const
Converts the specified EBML ID to a printable string.
Definition ebmlelement.h:71
std::string readString()
Reads the content of the element as string.
std::uint64_t readUInteger()
Reads the content of the element as unsigned integer.
static std::uint8_t makeSizeDenotation(std::uint64_t size, char *buff)
Makes the size denotation for the specified size and stores it to buff.
void internalParse(Diagnostics &diag)
Parses the EBML element.
static std::uint8_t calculateUIntegerLength(std::uint64_t integer)
Returns the length of the specified unsigned integer in byte.
bool isParent() const
Returns an indication whether the element is a parent element.
Definition ebmlelement.h:87
Defines traits for the specified ImplementationType.
GenericFileElement(ContainerType &container, std::uint64_t startOffset)
typename FileElementTraits< EbmlElement >::IdentifierType IdentifierType
Implementation of GenericContainer<MediaFileInfo, MatroskaTag, MatroskaTrack, EbmlElement>.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
Encapsulates all EBML ID values.
Definition ebmlid.h:9
Encapsulates the most common Matroska element IDs.
Definition matroskaid.h:11
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
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.