Implement determine tag/index pos for MKV

This commit is contained in:
Martchus 2016-11-16 22:06:12 +01:00
parent a8dce14514
commit 554351810a
3 changed files with 36 additions and 2 deletions

View File

@ -175,6 +175,9 @@ bool AbstractContainer::supportsTrackModifications() const
* \brief Determines the position of the index.
* \returns Returns ElementPosition::BeforeData or ElementPosition::AfterData if the position could
* be determined; otherwise returns ElementPosition::Keep.
* \remarks
* - It might be required to parse tracks before the index position can be determined.
* - Not be applicable for files composed of multiple segments.
*/
ElementPosition AbstractContainer::determineIndexPosition() const
{
@ -329,6 +332,9 @@ void AbstractContainer::removeAllTags()
* \brief Determines the position of the tags inside the file.
* \returns Returns ElementPosition::BeforeData or ElementPosition::AfterData if the position could
* be determined; otherwise returns ElementPosition::Keep.
* \remarks
* - It might be required to parse tags before the tag position can be determined.
* - Not be applicable for files composed of multiple segments.
*/
ElementPosition AbstractContainer::determineTagPosition() const
{

View File

@ -332,14 +332,41 @@ generateRandomId:
return attachment.get();
}
/*!
* \brief Determines the position of the element with the specified \a elementId.
* \sa determineTagPosition() and determineIndexPosition()
*/
ElementPosition MatroskaContainer::determineElementPosition(uint64 elementId) const
{
if(m_firstElement && m_segmentCount == 1) {
if(const EbmlElement *segmentElement = m_firstElement->siblingById(MatroskaIds::Segment, true)) {
for(const EbmlElement *childElement = segmentElement->firstChild(); childElement; childElement = childElement->nextSibling()) {
if(childElement->id() == elementId) {
return ElementPosition::BeforeData;
} else if(childElement->id() == MatroskaIds::Cluster) {
for(const auto &seekInfo : m_seekInfos) {
for(const auto &info : seekInfo->info()) {
if(info.first == elementId) {
return ElementPosition::AfterData;
}
}
}
return ElementPosition::Keep;
}
}
}
}
return ElementPosition::Keep;
}
ElementPosition MatroskaContainer::determineTagPosition() const
{
return ElementPosition::Keep; // TODO
return determineElementPosition(MatroskaIds::Tags);
}
ElementPosition MatroskaContainer::determineIndexPosition() const
{
return ElementPosition::Keep; // TODO
return determineElementPosition(MatroskaIds::Cues);
}
void MatroskaContainer::internalParseHeader()

View File

@ -41,6 +41,7 @@ public:
MatroskaAttachment *createAttachment();
MatroskaAttachment *attachment(std::size_t index);
std::size_t attachmentCount() const;
ElementPosition determineElementPosition(uint64 elementId) const;
ElementPosition determineTagPosition() const;
ElementPosition determineIndexPosition() const;