2015-04-22 19:22:01 +02:00
|
|
|
#ifndef EBMLELEMENT_H
|
|
|
|
#define EBMLELEMENT_H
|
|
|
|
|
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 "../statusprovider.h"
|
|
|
|
#include "../genericfileelement.h"
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
#include <c++utilities/conversion/types.h>
|
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
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace Media {
|
|
|
|
|
|
|
|
class EbmlElement;
|
|
|
|
class MatroskaContainer;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Defines traits for the GenericFileElement implementation EbmlElement.
|
|
|
|
*/
|
|
|
|
template <>
|
2016-08-29 15:43:05 +02:00
|
|
|
class TAG_PARSER_EXPORT FileElementTraits<EbmlElement>
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/*!
|
|
|
|
* \brief The container type used to store such elements is MatroskaContainer.
|
|
|
|
*/
|
|
|
|
typedef MatroskaContainer containerType;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The type used to store element IDs is an unsigned 32-bit integer.
|
|
|
|
*/
|
|
|
|
typedef uint32 identifierType;
|
|
|
|
|
2015-06-07 00:18:28 +02:00
|
|
|
/*!
|
|
|
|
* \brief The type used to store element sizes is an unsigned 64-bit integer.
|
|
|
|
*/
|
|
|
|
typedef uint64 dataSizeType;
|
|
|
|
|
2015-04-22 19:22:01 +02:00
|
|
|
/*!
|
|
|
|
* \brief The implementation type is EbmlElement.
|
|
|
|
*/
|
|
|
|
typedef EbmlElement implementationType;
|
|
|
|
};
|
|
|
|
|
2016-08-29 15:43:05 +02:00
|
|
|
class TAG_PARSER_EXPORT EbmlElement : public GenericFileElement<EbmlElement>
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
|
|
|
friend class GenericFileElement<EbmlElement>;
|
|
|
|
|
|
|
|
public:
|
|
|
|
EbmlElement(MatroskaContainer &container, uint64 startOffset);
|
|
|
|
|
|
|
|
std::string idToString() const;
|
|
|
|
bool isParent() const;
|
|
|
|
bool isPadding() const;
|
|
|
|
uint64 firstChildOffset() const;
|
|
|
|
std::string readString();
|
|
|
|
uint64 readUInteger();
|
|
|
|
float64 readFloat();
|
|
|
|
|
|
|
|
static byte calculateIdLength(identifierType id);
|
|
|
|
static byte calculateSizeDenotationLength(uint64 size);
|
|
|
|
static byte makeId(identifierType id, char *buff);
|
2015-12-22 17:00:14 +01:00
|
|
|
static byte makeSizeDenotation(uint64 size, char *buff);
|
|
|
|
static byte makeSizeDenotation(uint64 size, char *buff, byte minBytes);
|
2015-04-22 19:22:01 +02:00
|
|
|
static byte calculateUIntegerLength(uint64 integer);
|
|
|
|
static byte makeUInteger(uint64 value, char *buff);
|
2015-12-22 17:00:14 +01:00
|
|
|
static byte makeUInteger(uint64 value, char *buff, byte minBytes);
|
2015-04-22 19:22:01 +02:00
|
|
|
static void makeSimpleElement(std::ostream &stream, identifierType id, uint64 content);
|
|
|
|
static void makeSimpleElement(std::ostream &stream, identifierType id, const std::string &content);
|
2015-10-14 19:42:48 +02:00
|
|
|
static void makeSimpleElement(std::ostream &stream, GenericFileElement::identifierType id, const char *data, std::size_t dataSize);
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
EbmlElement(EbmlElement &parent, uint64 startOffset);
|
2015-06-07 00:18:28 +02:00
|
|
|
EbmlElement(MatroskaContainer &container, uint64 startOffset, uint64 maxSize);
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
void internalParse();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string parsingContext() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Converts the specified EBML \a ID to a printable string.
|
|
|
|
*/
|
|
|
|
inline std::string EbmlElement::idToString() const
|
|
|
|
{
|
2017-01-27 21:27:24 +01:00
|
|
|
using namespace ConversionUtilities;
|
2015-04-22 19:22:01 +02:00
|
|
|
const char *name = matroskaIdName(id());
|
2017-01-27 21:27:24 +01:00
|
|
|
if(*name) {
|
|
|
|
return '0' % 'x' % numberToString(id(), 16) % ' ' % '\"' % name + '\"';
|
|
|
|
} 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;
|
|
|
|
switch(id()) {
|
|
|
|
case Header:
|
|
|
|
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:
|
|
|
|
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
|
|
|
*/
|
|
|
|
inline uint64 EbmlElement::firstChildOffset() const
|
|
|
|
{
|
|
|
|
return isParent() ? (idLength() + sizeLength()) : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif // EBMLELEMENT_H
|