tagparser/matroska/matroskachapter.cpp

131 lines
4.6 KiB
C++
Raw Normal View History

2015-09-06 19:57:33 +02:00
#include "./matroskachapter.h"
#include "./ebmlelement.h"
#include "./matroskaid.h"
2015-04-22 19:22:01 +02:00
#include <c++utilities/misc/memory.h>
using namespace std;
2015-09-16 17:26:20 +02:00
using namespace ChronoUtilities;
2015-04-22 19:22:01 +02:00
namespace Media {
2016-08-04 00:16:19 +02:00
/*!
* \class MatroskaChapter
* \brief The MatroskaChapter class provides an implementation of AbstractAttachment for Matroska files.
*/
2015-04-22 19:22:01 +02:00
/*!
* \brief Constructs a new MatroskaChapter for the specified \a chapterAtomElement.
*/
MatroskaChapter::MatroskaChapter(EbmlElement *chapterAtomElement) :
m_chapterAtomElement(chapterAtomElement)
{}
/*!
* \brief Destroys the chapter.
*/
MatroskaChapter::~MatroskaChapter()
{}
/*!
* \fn MatroskaChapter::parse()
* \brief Parses the "ChapterAtom"-element which has been specified when constructing the object.
2016-06-10 23:08:01 +02:00
* \remarks
* - Fetches nested chapters but does not parse them.
* - Clears all previous parsing results.
2015-04-22 19:22:01 +02:00
*/
void MatroskaChapter::internalParse()
{
// clear previous values and status
static const string context("parsing \"ChapterAtom\"-element");
invalidateStatus();
clear();
// iterate through childs of "ChapterAtom"-element
EbmlElement *chapterAtomChild = m_chapterAtomElement->firstChild();
EbmlElement *subElement;
while(chapterAtomChild) {
chapterAtomChild->parse();
switch(chapterAtomChild->id()) {
case MatroskaIds::ChapterUID:
m_id = chapterAtomChild->readUInteger();
break;
case MatroskaIds::ChapterStringUID:
break;
case MatroskaIds::ChapterTimeStart:
2015-09-16 17:26:20 +02:00
m_startTime = TimeSpan(chapterAtomChild->readUInteger() / 100);
2015-04-22 19:22:01 +02:00
break;
case MatroskaIds::ChapterTimeEnd:
2015-09-16 17:26:20 +02:00
m_endTime = TimeSpan(chapterAtomChild->readUInteger() / 100);
2015-04-22 19:22:01 +02:00
break;
case MatroskaIds::ChapterFlagHidden:
m_hidden = chapterAtomChild->readUInteger() == 1;
break;
case MatroskaIds::ChapterFlagEnabled:
m_enabled = chapterAtomChild->readUInteger() == 1;
break;
case MatroskaIds::ChapterSegmentUID:
case MatroskaIds::ChapterSegmentEditionUID:
case MatroskaIds::ChapterPhysicalEquiv:
break;
case MatroskaIds::ChapterTrack:
subElement = chapterAtomChild->firstChild();
while(subElement) {
subElement->parse();
switch(subElement->id()) {
case MatroskaIds::ChapterTrack:
m_tracks.emplace_back(subElement->readUInteger());
break;
default:
addNotification(NotificationType::Warning, "\"ChapterTrack\"-element contains unknown child element \"" + chapterAtomChild->idToString() + "\". It will be ignored.", context);
}
subElement = subElement->nextSibling();
}
break;
case MatroskaIds::ChapterDisplay:
subElement = chapterAtomChild->firstChild();
m_names.emplace_back();
while(subElement) {
subElement->parse();
switch(subElement->id()) {
case MatroskaIds::ChapString:
if(m_names.back().empty()) {
m_names.back().assign(subElement->readString());
} else {
addNotification(NotificationType::Warning, "\"ChapterDisplay\"-element contains multiple \"ChapString\"-elements. Surplus occurrences will be ignored.", context);
}
break;
case MatroskaIds::ChapLanguage:
m_names.back().languages().emplace_back(subElement->readString());
break;
case MatroskaIds::ChapCountry:
m_names.back().countries().emplace_back(subElement->readString());
break;
}
subElement = subElement->nextSibling();
}
break;
case MatroskaIds::ChapProcess:
break;
case MatroskaIds::ChapterAtom:
m_nestedChapters.emplace_back(make_unique<MatroskaChapter>(chapterAtomChild));
default:
addNotification(NotificationType::Warning, "\"ChapterAtom\"-element contains unknown child element \"" + chapterAtomChild->idToString() + "\". It will be ignored.", context);
}
chapterAtomChild = chapterAtomChild->nextSibling();
}
// "eng" is declared to be default language
if(m_names.back().languages().empty()) {
m_names.back().languages().emplace_back("eng");
}
}
void MatroskaChapter::clear()
{
AbstractChapter::clear();
m_nestedChapters.clear();
}
} // namespace Media