tagparser/matroska/matroskacontainer.h

143 lines
3.9 KiB
C++

#ifndef MATROSKACONTAINER_H
#define MATROSKACONTAINER_H
#include "./ebmlelement.h"
#include "./matroskatag.h"
#include "./matroskatrack.h"
#include "./matroskachapter.h"
#include "./matroskaattachment.h"
#include "../genericcontainer.h"
#include <c++utilities/conversion/types.h>
#include <memory>
#include <string>
#include <vector>
namespace Media {
class MatroskaSeekInfo;
class MatroskaEditionEntry;
class MediaFileInfo;
class LIB_EXPORT MatroskaContainer : public GenericContainer<MediaFileInfo, MatroskaTag, MatroskaTrack, EbmlElement>
{
public:
MatroskaContainer(MediaFileInfo &stream, uint64 startOffset);
~MatroskaContainer();
void validateIndex();
uint64 maxIdLength() const;
uint64 maxSizeLength() const;
const std::vector<std::unique_ptr<MatroskaSeekInfo> > &seekInfos() const;
static uint64 maxFullParseSize();
void setMaxFullParseSize(uint64 maxFullParseSize);
const std::vector<std::unique_ptr<MatroskaEditionEntry> > &editionEntires() const;
MatroskaChapter *chapter(std::size_t index);
std::size_t chapterCount() const;
MatroskaAttachment *createAttachment();
MatroskaAttachment *attachment(std::size_t index);
std::size_t attachmentCount() const;
protected:
void internalParseHeader();
void internalParseTags();
void internalParseTracks();
void internalParseChapters();
void internalParseAttachments();
void internalMakeFile();
private:
void parseSegmentInfo();
void fetchEditionEntryElements();
uint64 m_maxIdLength;
uint64 m_maxSizeLength;
std::vector<EbmlElement *> m_tracksElements;
std::vector<EbmlElement *> m_segmentInfoElements;
std::vector<EbmlElement *> m_tagsElements;
std::vector<EbmlElement *> m_chaptersElements;
std::vector<EbmlElement *> m_attachmentsElements;
std::vector<std::unique_ptr<MatroskaSeekInfo> > m_seekInfos;
std::vector<std::unique_ptr<MatroskaEditionEntry> > m_editionEntries;
std::vector<std::unique_ptr<MatroskaAttachment> > m_attachments;
static uint64 m_maxFullParseSize;
};
/*!
* \brief Returns the maximal ID length in bytes.
*/
inline uint64 MatroskaContainer::maxIdLength() const
{
return m_maxIdLength;
}
/*!
* \brief Returns the maximal size length in bytes.
*/
inline uint64 MatroskaContainer::maxSizeLength() const
{
return m_maxSizeLength;
}
/*!
* \brief Returns seek information read from "SeekHead" elements when parsing segment info.
*/
inline const std::vector<std::unique_ptr<MatroskaSeekInfo> > &MatroskaContainer::seekInfos() const
{
return m_seekInfos;
}
/*!
* \brief Returns the maximal file size for a "full parse" in byte.
*
* The "Tags" element (which holds the tag information) is commonly at the end of a Matroska file. Hence the
* parser needs to walk through the entire file to find the tag information if no "SeekHead" element is present
* which might causes long loading times. To avoid this a maximal file size for a "full parse" can be specified.
* The disadvantage is that the parser relies on the presence of a SeekHead element on larger files to retrieve
* tag information.
*
* The default value is 50 MiB.
*
* \sa setMaxFullParseSize()
*/
inline uint64 MatroskaContainer::maxFullParseSize()
{
return m_maxFullParseSize;
}
/*!
* \brief Sets the maximal file size for a "full parse" in byte.
* \sa maxFullParseSize()
*/
inline void MatroskaContainer::setMaxFullParseSize(uint64 maxFullParseSize)
{
m_maxFullParseSize = maxFullParseSize;
}
/*!
* \brief Returns the edition entries.
*/
inline const std::vector<std::unique_ptr<MatroskaEditionEntry> > &MatroskaContainer::editionEntires() const
{
return m_editionEntries;
}
inline MatroskaAttachment *MatroskaContainer::attachment(std::size_t index)
{
return m_attachments.at(index).get();
}
inline std::size_t MatroskaContainer::attachmentCount() const
{
return m_attachments.size();
}
}
#endif // MATROSKACONTAINER_H