2015-04-22 19:22:01 +02:00
|
|
|
#ifndef MP4ATOM_H
|
|
|
|
#define MP4ATOM_H
|
|
|
|
|
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/types.h>
|
|
|
|
#include <c++utilities/conversion/stringconversion.h>
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <iostream>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace Media
|
|
|
|
{
|
|
|
|
|
|
|
|
class Mp4Atom;
|
|
|
|
class Mp4Container;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Defines traits for the GenericFileElement implementation Mp4Atom.
|
|
|
|
*/
|
|
|
|
template <>
|
|
|
|
class LIB_EXPORT FileElementTraits<Mp4Atom>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/*!
|
|
|
|
* \brief The container type used to store such elements is Mp4Container.
|
|
|
|
*/
|
|
|
|
typedef Mp4Container containerType;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The type used to store atom 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 Mp4Atom.
|
|
|
|
*/
|
|
|
|
typedef Mp4Atom implementationType;
|
2015-07-13 00:57:38 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Returns the minimal atom size which is 8 byte.
|
|
|
|
*/
|
|
|
|
static constexpr byte minimumElementSize()
|
|
|
|
{
|
|
|
|
return 8;
|
|
|
|
}
|
2015-04-22 19:22:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class LIB_EXPORT Mp4Atom : public GenericFileElement<Mp4Atom>
|
|
|
|
{
|
|
|
|
friend class GenericFileElement<Mp4Atom>;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Mp4Atom(containerType& container, uint64 startOffset);
|
|
|
|
|
|
|
|
std::string idToString() const;
|
|
|
|
bool isParent() const;
|
|
|
|
bool isPadding() const;
|
|
|
|
uint64 firstChildOffset() const;
|
|
|
|
|
2015-11-07 15:23:36 +01:00
|
|
|
static void seekBackAndWriteAtomSize(std::ostream &stream, const std::ostream::pos_type &startOffset);
|
|
|
|
static void seekBackAndWriteAtomSize64(std::ostream &stream, const std::ostream::pos_type &startOffset);
|
2015-12-21 00:04:56 +01:00
|
|
|
static void addHeaderSize(uint64 &dataSize);
|
|
|
|
static void makeHeader(uint64 size, uint32 id, IoUtilities::BinaryWriter &writer);
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
protected:
|
2015-06-07 00:18:28 +02:00
|
|
|
Mp4Atom(containerType& container, uint64 startOffset, uint64 maxSize);
|
2015-04-22 19:22:01 +02:00
|
|
|
Mp4Atom(implementationType &parent, uint64 startOffset);
|
|
|
|
|
|
|
|
void internalParse();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string parsingContext() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Converts the specified atom \a ID to a printable string.
|
|
|
|
*/
|
|
|
|
inline std::string Mp4Atom::idToString() const
|
|
|
|
{
|
|
|
|
return ConversionUtilities::interpretIntegerAsString<identifierType>(id());
|
|
|
|
}
|
|
|
|
|
2015-12-21 00:04:56 +01:00
|
|
|
/*!
|
|
|
|
* \brief Adds the header size to the specified \a data size.
|
|
|
|
*/
|
|
|
|
inline void Mp4Atom::addHeaderSize(uint64 &dataSize)
|
|
|
|
{
|
|
|
|
dataSize += dataSize < 0xFFFFFFF7 ? 8 : 16;
|
|
|
|
}
|
|
|
|
|
2015-04-22 19:22:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // MP4ATOM_H
|