tagparser/mp4/mp4atom.h

89 lines
2.2 KiB
C
Raw Normal View History

#ifndef TAG_PARSER_MP4ATOM_H
#define TAG_PARSER_MP4ATOM_H
2015-04-22 19:22:01 +02:00
2015-09-06 19:57:33 +02:00
#include "./mp4ids.h"
2015-04-22 19:22:01 +02:00
2015-09-06 19:57:33 +02:00
#include "../genericfileelement.h"
2015-04-22 19:22:01 +02:00
#include <c++utilities/conversion/stringconversion.h>
2018-03-07 01:17:50 +01:00
#include <c++utilities/conversion/types.h>
2015-04-22 19:22:01 +02:00
#include <iostream>
2018-03-07 01:17:50 +01:00
#include <list>
2015-04-22 19:22:01 +02:00
#include <memory>
2018-03-07 01:17:50 +01:00
namespace TagParser {
2015-04-22 19:22:01 +02:00
class Mp4Atom;
class Mp4Container;
/*!
* \brief Defines traits for the GenericFileElement implementation Mp4Atom.
*/
2018-03-07 01:17:50 +01:00
template <> class TAG_PARSER_EXPORT FileElementTraits<Mp4Atom> {
2015-04-22 19:22:01 +02:00
public:
typedef Mp4Container ContainerType;
typedef uint32 IdentifierType;
typedef uint64 DataSizeType;
/*!
* \brief Returns the minimal atom size which is 8 byte.
*/
static constexpr byte minimumElementSize()
{
return 8;
}
2015-04-22 19:22:01 +02:00
};
2018-03-07 01:17:50 +01:00
class TAG_PARSER_EXPORT Mp4Atom : public GenericFileElement<Mp4Atom> {
2015-04-22 19:22:01 +02:00
friend class GenericFileElement<Mp4Atom>;
public:
Mp4Atom(ContainerType &container, uint64 startOffset);
2015-04-22 19:22:01 +02:00
std::string idToString() const;
bool isParent() const;
bool isPadding() const;
uint64 firstChildOffset() const;
2018-07-10 17:07:34 +02:00
static void seekBackAndWriteAtomSize(std::ostream &stream, const std::ostream::pos_type &startOffset, Diagnostics &diag);
static void seekBackAndWriteAtomSize64(std::ostream &stream, const std::ostream::pos_type &startOffset);
2018-07-10 14:11:11 +02:00
static constexpr void addHeaderSize(uint64 &dataSize);
static void makeHeader(uint64 size, uint32 id, IoUtilities::BinaryWriter &writer);
2015-04-22 19:22:01 +02:00
protected:
Mp4Atom(ContainerType &container, uint64 startOffset, uint64 maxSize);
Mp4Atom(Mp4Atom &parent, uint64 startOffset);
2015-04-22 19:22:01 +02:00
void internalParse(Diagnostics &diag);
2015-04-22 19:22:01 +02:00
private:
std::string parsingContext() const;
};
/*!
* \brief Converts the specified atom \a ID to a printable string.
*/
inline std::string Mp4Atom::idToString() const
{
auto idString = ConversionUtilities::interpretIntegerAsString<IdentifierType>(id());
2018-03-07 01:17:50 +01:00
for (char &c : idString) {
if (c < ' ') {
c = '?';
}
}
return idString;
2015-04-22 19:22:01 +02:00
}
/*!
* \brief Adds the header size to the specified \a data size.
*/
2018-07-10 14:11:11 +02:00
constexpr void Mp4Atom::addHeaderSize(uint64 &dataSize)
{
2017-09-14 18:19:30 +02:00
dataSize += (dataSize < 0xFFFFFFF7 ? 8 : 16);
}
2018-03-07 01:17:50 +01:00
} // namespace TagParser
2015-04-22 19:22:01 +02:00
#endif // TAG_PARSER_MP4ATOM_H