tagparser/matroska/matroskatrack.h

104 lines
3.1 KiB
C
Raw Normal View History

#ifndef TAG_PARSER_MATROSKATRACK_H
#define TAG_PARSER_MATROSKATRACK_H
2015-04-22 19:22:01 +02:00
2015-09-06 19:57:33 +02:00
#include "../abstracttrack.h"
2015-04-22 19:22:01 +02:00
namespace TagParser {
2015-04-22 19:22:01 +02:00
class EbmlElement;
class MatroskaContainer;
class MatroskaTrack;
class MatroskaTag;
2018-03-07 01:17:50 +01:00
class TAG_PARSER_EXPORT MatroskaTrackHeaderMaker {
friend class MatroskaTrack;
public:
void make(std::ostream &stream) const;
const MatroskaTrack &track() const;
uint64 requiredSize() const;
private:
MatroskaTrackHeaderMaker(const MatroskaTrack &track, Diagnostics &diag);
const MatroskaTrack &m_track;
uint64 m_dataSize;
uint64 m_requiredSize;
byte m_sizeDenotationLength;
};
/*!
* \brief Returns the number of bytes which will be written when making the track.
*/
inline const MatroskaTrack &MatroskaTrackHeaderMaker::track() const
{
return m_track;
}
2015-04-22 19:22:01 +02:00
/*!
* \brief Returns the number of bytes which will be written when calling make().
*/
inline uint64 MatroskaTrackHeaderMaker::requiredSize() const
{
return m_requiredSize;
}
2018-03-07 01:17:50 +01:00
class TAG_PARSER_EXPORT MatroskaTrack : public AbstractTrack {
2015-04-22 19:22:01 +02:00
friend class MatroskaContainer;
friend class MatroskaTrackHeaderMaker;
2015-04-22 19:22:01 +02:00
public:
MatroskaTrack(EbmlElement &trackElement);
~MatroskaTrack() override;
2015-04-22 19:22:01 +02:00
TrackType type() const override;
2015-04-22 19:22:01 +02:00
static MediaFormat codecIdToMediaFormat(const std::string &codecId);
2018-03-07 01:17:50 +01:00
void readStatisticsFromTags(const std::vector<std::unique_ptr<MatroskaTag>> &tags, Diagnostics &diag);
MatroskaTrackHeaderMaker prepareMakingHeader(Diagnostics &diag) const;
void makeHeader(std::ostream &stream, Diagnostics &diag) const;
2015-04-22 19:22:01 +02:00
protected:
void internalParseHeader(Diagnostics &diag) override;
2015-04-22 19:22:01 +02:00
private:
2018-03-07 01:17:50 +01:00
template <typename PropertyType, typename ConversionFunction>
void assignPropertyFromTagValue(const std::unique_ptr<MatroskaTag> &tag, const char *fieldId, PropertyType &integer,
const ConversionFunction &conversionFunction, Diagnostics &diag);
2015-04-22 19:22:01 +02:00
EbmlElement *m_trackElement;
};
/*!
* \brief Prepares making header.
* \returns Returns a MatroskaTrackHeaderMaker object which can be used to actually make the track
* header.
* \remarks The track must NOT be mutated after making is prepared when it is intended to actually
* make the tag using the make() method of the returned object.
* \throws Throws TagParser::Failure or a derived exception when a making error occurs.
*
* This method might be useful when it is necessary to know the size of the track header before making
* it.
* \sa make()
*/
inline MatroskaTrackHeaderMaker MatroskaTrack::prepareMakingHeader(Diagnostics &diag) const
{
return MatroskaTrackHeaderMaker(*this, diag);
}
/*!
* \brief Writes header information to the specified \a stream (makes a "TrackEntry"-element).
* \throws Throws std::ios_base::failure when an IO error occurs.
* \throws Throws TagParser::Failure or a derived exception when a making
* error occurs.
* \sa prepareMaking()
*/
inline void MatroskaTrack::makeHeader(std::ostream &stream, Diagnostics &diag) const
{
prepareMakingHeader(diag).make(stream);
}
2018-03-07 01:17:50 +01:00
} // namespace TagParser
2015-04-22 19:22:01 +02:00
#endif // TAG_PARSER_MATROSKATRACK_H