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
|
|
|
|
2018-03-05 17:49:29 +01:00
|
|
|
#include "../diagnostics.h"
|
|
|
|
|
2017-01-27 18:59:22 +01:00
|
|
|
#include <c++utilities/conversion/stringbuilder.h>
|
2017-02-05 21:02:40 +01:00
|
|
|
|
|
|
|
#include <memory>
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
using namespace std;
|
2019-06-10 22:49:11 +02:00
|
|
|
using namespace CppUtilities;
|
2015-04-22 19:22:01 +02:00
|
|
|
|
2018-03-06 23:09:15 +01:00
|
|
|
namespace TagParser {
|
2015-04-22 19:22:01 +02:00
|
|
|
|
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.
|
|
|
|
*/
|
2018-03-07 01:17:50 +01:00
|
|
|
MatroskaChapter::MatroskaChapter(EbmlElement *chapterAtomElement)
|
|
|
|
: m_chapterAtomElement(chapterAtomElement)
|
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Destroys the chapter.
|
|
|
|
*/
|
|
|
|
MatroskaChapter::~MatroskaChapter()
|
2018-03-07 01:17:50 +01:00
|
|
|
{
|
|
|
|
}
|
2015-04-22 19:22:01 +02:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \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
|
|
|
*/
|
2021-02-04 23:21:50 +01:00
|
|
|
void MatroskaChapter::internalParse(Diagnostics &diag, AbortableProgressFeedback &progress)
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
2021-02-04 23:21:50 +01:00
|
|
|
CPP_UTILITIES_UNUSED(progress)
|
|
|
|
|
2015-04-22 19:22:01 +02:00
|
|
|
// clear previous values and status
|
|
|
|
static const string context("parsing \"ChapterAtom\"-element");
|
|
|
|
clear();
|
2019-12-30 22:54:11 +01:00
|
|
|
// iterate through children of "ChapterAtom"-element
|
2018-03-07 01:17:50 +01:00
|
|
|
for (EbmlElement *chapterAtomChild = m_chapterAtomElement->firstChild(); chapterAtomChild; chapterAtomChild = chapterAtomChild->nextSibling()) {
|
2018-03-05 17:49:29 +01:00
|
|
|
chapterAtomChild->parse(diag);
|
2018-03-07 01:17:50 +01:00
|
|
|
switch (chapterAtomChild->id()) {
|
2015-04-22 19:22:01 +02:00
|
|
|
case MatroskaIds::ChapterUID:
|
|
|
|
m_id = chapterAtomChild->readUInteger();
|
|
|
|
break;
|
|
|
|
case MatroskaIds::ChapterStringUID:
|
|
|
|
break;
|
|
|
|
case MatroskaIds::ChapterTimeStart:
|
2021-03-20 21:26:25 +01:00
|
|
|
m_startTime = TimeSpan(static_cast<std::int64_t>(chapterAtomChild->readUInteger() / 100u));
|
2015-04-22 19:22:01 +02:00
|
|
|
break;
|
|
|
|
case MatroskaIds::ChapterTimeEnd:
|
2021-03-20 21:26:25 +01:00
|
|
|
m_endTime = TimeSpan(static_cast<std::int64_t>(chapterAtomChild->readUInteger() / 100u));
|
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:
|
2018-03-07 01:17:50 +01:00
|
|
|
for (EbmlElement *chapterTrackElement = chapterAtomChild->firstChild(); chapterTrackElement;
|
|
|
|
chapterTrackElement = chapterTrackElement->nextSibling()) {
|
2018-03-05 17:49:29 +01:00
|
|
|
chapterTrackElement->parse(diag);
|
2018-03-07 01:17:50 +01:00
|
|
|
switch (chapterTrackElement->id()) {
|
2015-04-22 19:22:01 +02:00
|
|
|
case MatroskaIds::ChapterTrack:
|
2016-08-06 20:51:57 +02:00
|
|
|
m_tracks.emplace_back(chapterTrackElement->readUInteger());
|
2015-04-22 19:22:01 +02:00
|
|
|
break;
|
|
|
|
default:
|
2018-03-07 01:17:50 +01:00
|
|
|
diag.emplace_back(DiagLevel::Warning,
|
|
|
|
"\"ChapterTrack\"-element contains unknown child element \"" % chapterAtomChild->idToString() + "\". It will be ignored.",
|
|
|
|
context);
|
2015-04-22 19:22:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MatroskaIds::ChapterDisplay:
|
|
|
|
m_names.emplace_back();
|
2018-03-07 01:17:50 +01:00
|
|
|
for (EbmlElement *chapterDisplayElement = chapterAtomChild->firstChild(); chapterDisplayElement;
|
|
|
|
chapterDisplayElement = chapterDisplayElement->nextSibling()) {
|
2018-03-05 17:49:29 +01:00
|
|
|
chapterDisplayElement->parse(diag);
|
2018-03-07 01:17:50 +01:00
|
|
|
switch (chapterDisplayElement->id()) {
|
2015-04-22 19:22:01 +02:00
|
|
|
case MatroskaIds::ChapString:
|
2018-03-07 01:17:50 +01:00
|
|
|
if (m_names.back().empty()) {
|
2016-08-06 20:51:57 +02:00
|
|
|
m_names.back().assign(chapterDisplayElement->readString());
|
2015-04-22 19:22:01 +02:00
|
|
|
} else {
|
2018-03-07 01:17:50 +01:00
|
|
|
diag.emplace_back(DiagLevel::Warning,
|
|
|
|
"\"ChapterDisplay\"-element contains multiple \"ChapString\"-elements. Surplus occurrences will be ignored.", context);
|
2015-04-22 19:22:01 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MatroskaIds::ChapLanguage:
|
2020-12-13 18:37:15 +01:00
|
|
|
m_names.back().locale().emplace_back(chapterDisplayElement->readString(), LocaleFormat::ISO_639_2_B);
|
2015-04-22 19:22:01 +02:00
|
|
|
break;
|
2020-11-26 23:18:14 +01:00
|
|
|
case MatroskaIds::ChapLanguageIETF:
|
2020-12-13 18:37:15 +01:00
|
|
|
m_names.back().locale().emplace_back(chapterDisplayElement->readString(), LocaleFormat::BCP_47);
|
2020-11-26 23:18:14 +01:00
|
|
|
break;
|
2015-04-22 19:22:01 +02:00
|
|
|
case MatroskaIds::ChapCountry:
|
2020-12-13 18:37:15 +01:00
|
|
|
m_names.back().locale().emplace_back(chapterDisplayElement->readString(), LocaleFormat::DomainCountry);
|
2015-04-22 19:22:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MatroskaIds::ChapProcess:
|
|
|
|
break;
|
|
|
|
case MatroskaIds::ChapterAtom:
|
|
|
|
m_nestedChapters.emplace_back(make_unique<MatroskaChapter>(chapterAtomChild));
|
2018-06-02 22:56:33 +02:00
|
|
|
break;
|
2015-04-22 19:22:01 +02:00
|
|
|
default:
|
2018-03-07 01:17:50 +01:00
|
|
|
diag.emplace_back(DiagLevel::Warning,
|
|
|
|
"\"ChapterAtom\"-element contains unknown child element \"" % chapterAtomChild->idToString() + "\". It will be ignored.", context);
|
2015-04-22 19:22:01 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-06 20:51:57 +02:00
|
|
|
// "eng" is default language
|
2018-03-07 01:17:50 +01:00
|
|
|
for (LocaleAwareString &name : m_names) {
|
2020-12-13 18:37:15 +01:00
|
|
|
if (name.locale().empty()) {
|
|
|
|
name.locale().emplace_back("eng"sv, LocaleFormat::ISO_639_2_B);
|
2016-08-06 20:51:57 +02:00
|
|
|
}
|
2015-04-22 19:22:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MatroskaChapter::clear()
|
|
|
|
{
|
|
|
|
AbstractChapter::clear();
|
|
|
|
m_nestedChapters.clear();
|
|
|
|
}
|
|
|
|
|
2018-03-07 01:17:50 +01:00
|
|
|
} // namespace TagParser
|