2018-03-06 23:09:15 +01:00
|
|
|
#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>
|
|
|
|
|
2019-03-13 19:06:42 +01:00
|
|
|
#include <cstdint>
|
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:
|
2018-07-11 13:19:43 +02:00
|
|
|
using ContainerType = Mp4Container;
|
2019-03-13 19:06:42 +01:00
|
|
|
using IdentifierType = std::uint32_t;
|
|
|
|
using DataSizeType = std::uint64_t;
|
2015-07-13 00:57:38 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the minimal atom size which is 8 byte.
|
|
|
|
*/
|
2019-03-13 19:06:42 +01:00
|
|
|
static constexpr std::uint8_t minimumElementSize()
|
2015-07-13 00:57:38 +02:00
|
|
|
{
|
|
|
|
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:
|
2019-03-13 19:06:42 +01:00
|
|
|
Mp4Atom(ContainerType &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
|
|
|
|
2018-07-10 17:07:34 +02:00
|
|
|
static void seekBackAndWriteAtomSize(std::ostream &stream, const std::ostream::pos_type &startOffset, Diagnostics &diag);
|
2015-11-07 15:23:36 +01:00
|
|
|
static void seekBackAndWriteAtomSize64(std::ostream &stream, const std::ostream::pos_type &startOffset);
|
2019-03-13 19:06:42 +01:00
|
|
|
static constexpr void addHeaderSize(std::uint64_t &dataSize);
|
2019-06-10 22:49:11 +02:00
|
|
|
static void makeHeader(std::uint64_t size, std::uint32_t id, CppUtilities::BinaryWriter &writer);
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
protected:
|
2019-03-13 19:06:42 +01:00
|
|
|
Mp4Atom(ContainerType &container, std::uint64_t startOffset, std::uint64_t maxSize);
|
|
|
|
Mp4Atom(Mp4Atom &parent, std::uint64_t startOffset);
|
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 atom \a ID to a printable string.
|
|
|
|
*/
|
|
|
|
inline std::string Mp4Atom::idToString() const
|
|
|
|
{
|
2019-06-10 22:49:11 +02:00
|
|
|
auto idString = CppUtilities::interpretIntegerAsString<IdentifierType>(id());
|
2018-03-07 01:17:50 +01:00
|
|
|
for (char &c : idString) {
|
|
|
|
if (c < ' ') {
|
2017-05-28 20:59:01 +02:00
|
|
|
c = '?';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return idString;
|
2015-04-22 19:22:01 +02:00
|
|
|
}
|
|
|
|
|
2015-12-21 00:04:56 +01:00
|
|
|
/*!
|
|
|
|
* \brief Adds the header size to the specified \a data size.
|
|
|
|
*/
|
2019-03-13 19:06:42 +01:00
|
|
|
constexpr void Mp4Atom::addHeaderSize(std::uint64_t &dataSize)
|
2015-12-21 00:04:56 +01:00
|
|
|
{
|
2017-09-14 18:19:30 +02:00
|
|
|
dataSize += (dataSize < 0xFFFFFFF7 ? 8 : 16);
|
2015-12-21 00:04:56 +01:00
|
|
|
}
|
|
|
|
|
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_MP4ATOM_H
|