From 730880a5b200502a5c45975ca4c646b1447e3fb0 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sat, 2 Mar 2024 13:39:04 +0100 Subject: [PATCH] Revert "Use typed children macros instead of local casts" --- matroska/KaxTracks.h | 2 +- src/KaxBlock.cpp | 18 +++++++++--------- src/KaxCluster.cpp | 4 ++-- src/KaxCues.cpp | 2 +- src/KaxCuesData.cpp | 24 ++++++++++++------------ src/KaxSeekHead.cpp | 18 ++++++++++-------- test/ebml/test00.cpp | 14 +++++++------- test/mux/test8.cpp | 6 +++--- 8 files changed, 45 insertions(+), 43 deletions(-) diff --git a/matroska/KaxTracks.h b/matroska/KaxTracks.h index 85fcd043..54ab6407 100644 --- a/matroska/KaxTracks.h +++ b/matroska/KaxTracks.h @@ -18,7 +18,7 @@ namespace libmatroska { DECLARE_MKX_MASTER(KaxTrackEntry) public: - libebml::EbmlUInteger & TrackNumber() const { return *(static_cast(FindFirstElt(EBML_INFO(KaxTrackNumber)))); } + libebml::EbmlUInteger & TrackNumber() const { return *(static_cast(FindElt(EBML_INFO(KaxTrackNumber)))); } void EnableLacing(bool bEnable = true); diff --git a/src/KaxBlock.cpp b/src/KaxBlock.cpp index 80f6d529..b03ce312 100644 --- a/src/KaxBlock.cpp +++ b/src/KaxBlock.cpp @@ -830,13 +830,13 @@ bool KaxBlockGroup::AddFrame(const KaxTrackEntry & track, std::uint64_t timestam std::uint64_t KaxBlockGroup::GlobalTimestamp() const { assert(ParentCluster); // impossible otherwise - auto MyBlock = FindChild(*this); + auto MyBlock = static_cast(this->FindElt(EBML_INFO(KaxBlock))); return MyBlock->GlobalTimestamp(); } std::uint16_t KaxBlockGroup::TrackNumber() const { - auto MyBlock = FindChild(*this); + auto MyBlock = static_cast(this->FindElt(EBML_INFO(KaxBlock))); return MyBlock->TrackNum(); } @@ -855,10 +855,10 @@ std::uint64_t KaxInternalBlock::ClusterPosition() const unsigned int KaxBlockGroup::ReferenceCount() const { unsigned int Result = 0; - auto MyBlockAdds = FindChild(*this); + auto MyBlockAdds = static_cast(FindFirstElt(EBML_INFO(KaxReferenceBlock))); if (MyBlockAdds) { Result++; - while ((MyBlockAdds = FindNextChild(*this, *MyBlockAdds))) { + while ((MyBlockAdds = static_cast(FindNextElt(*MyBlockAdds)))) { Result++; } } @@ -867,11 +867,11 @@ unsigned int KaxBlockGroup::ReferenceCount() const const KaxReferenceBlock & KaxBlockGroup::Reference(unsigned int Index) const { - auto MyBlockAdds = FindChild(*this); + auto MyBlockAdds = static_cast(FindFirstElt(EBML_INFO(KaxReferenceBlock))); assert(MyBlockAdds); // call of a non existing reference while (Index != 0) { - MyBlockAdds = FindNextChild(*this, *MyBlockAdds); + MyBlockAdds = static_cast(FindNextElt(*MyBlockAdds)); assert(MyBlockAdds); Index--; } @@ -880,7 +880,7 @@ const KaxReferenceBlock & KaxBlockGroup::Reference(unsigned int Index) const void KaxBlockGroup::ReleaseFrames() { - auto MyBlock = FindChild(*this); + auto MyBlock = static_cast(this->FindElt(EBML_INFO(KaxBlock))); MyBlock->ReleaseFrames(); } @@ -900,13 +900,13 @@ void KaxBlockGroup::SetBlockDuration(std::uint64_t TimeLength) { assert(ParentTrack); const std::int64_t scale = ParentTrack->GlobalTimestampScale(); - const auto myDuration = FindChild(*this); + const auto myDuration = static_cast(FindFirstElt(EBML_INFO(KaxBlockDuration), true)); myDuration->SetValue(TimeLength / static_cast(scale)); } bool KaxBlockGroup::GetBlockDuration(std::uint64_t &TheTimestamp) const { - const auto myDuration = FindChild(*this); + const auto myDuration = static_cast(FindElt(EBML_INFO(KaxBlockDuration))); if (!myDuration) { return false; } diff --git a/src/KaxCluster.cpp b/src/KaxCluster.cpp index c5f2c44f..5b802bf4 100644 --- a/src/KaxCluster.cpp +++ b/src/KaxCluster.cpp @@ -118,7 +118,7 @@ filepos_t KaxCluster::Render(IOCallback & output, KaxCues & CueToUpdate, const S filepos_t Result = 0; // update the timestamp of the Cluster before writing - auto ClusterTimestamp = FindChild(*this); + auto ClusterTimestamp = static_cast(this->FindElt(EBML_INFO(KaxClusterTimestamp))); ClusterTimestamp->SetValue(GlobalTimestamp() / GlobalTimestampScale()); if (Blobs.empty()) { @@ -181,7 +181,7 @@ std::int16_t KaxCluster::GetBlockLocalTimestamp(std::uint64_t aGlobalTimestamp) std::uint64_t KaxCluster::GetBlockGlobalTimestamp(std::int16_t LocalTimestamp) { if (!bFirstFrameInside) { - auto ClusterTimestamp = FindChild(*this); + auto ClusterTimestamp = static_cast(this->FindElt(EBML_INFO(KaxClusterTimestamp))); assert (bFirstFrameInside); // use the InitTimestamp() hack for now MinTimestamp = MaxTimestamp = PreviousTimestamp = static_cast(*static_cast(ClusterTimestamp)); bFirstFrameInside = true; diff --git a/src/KaxCues.cpp b/src/KaxCues.cpp index 3c1bdf4a..18c347bb 100644 --- a/src/KaxCues.cpp +++ b/src/KaxCues.cpp @@ -97,7 +97,7 @@ const KaxCuePoint * KaxCues::GetTimestampPoint(std::uint64_t aTimestamp) const if (EbmlId(*e) == EBML_ID(KaxCuePoint)) { auto tmp = static_cast(e); // check the tile - auto aTime = FindChild(*tmp); + auto aTime = static_cast(tmp->FindFirstElt(EBML_INFO(KaxCueTime))); if (aTime) { auto _Time = static_cast(*aTime); if (_Time > aPrevTime && _Time < TimestampToLocate) { diff --git a/src/KaxCuesData.cpp b/src/KaxCuesData.cpp index ae26ae61..986d7ee1 100644 --- a/src/KaxCuesData.cpp +++ b/src/KaxCuesData.cpp @@ -45,7 +45,7 @@ void KaxCuePoint::PositionSet(const KaxBlockGroup & BlockReference, std::uint64_ } } - auto CodecState = FindChild(BlockReference); + auto CodecState = static_cast(BlockReference.FindFirstElt(EBML_INFO(KaxCodecState))); if (CodecState) { auto &CueCodecState = AddNewChild(NewPositions); CueCodecState.SetValue(BlockReference.GetParentCluster()->GetParentSegment()->GetRelativePosition(CodecState->GetElementPosition())); @@ -96,7 +96,7 @@ void KaxCuePoint::PositionSet(const KaxInternalBlock & BlockReference, const Kax #endif // MATROSKA_VERSION if (BlockGroup) { - const auto CodecState = FindChild(*BlockGroup); + const auto CodecState = static_cast(BlockGroup->FindFirstElt(EBML_INFO(KaxCodecState))); if (CodecState) { auto &CueCodecState = AddNewChild(NewPositions); CueCodecState.SetValue(BlockGroup->GetParentCluster()->GetParentSegment()->GetRelativePosition(CodecState->GetElementPosition())); @@ -127,11 +127,11 @@ bool KaxCuePoint::IsSmallerThan(const EbmlElement * Cmp) const auto theCmp = static_cast(Cmp); // compare timestamp - auto TimestampA = FindChild(*this); + auto TimestampA = static_cast(FindElt(EBML_INFO(KaxCueTime))); if (!TimestampA) return false; - auto TimestampB = FindChild(*theCmp); + auto TimestampB = static_cast(theCmp->FindElt(EBML_INFO(KaxCueTime))); if (!TimestampB) return false; @@ -142,11 +142,11 @@ bool KaxCuePoint::IsSmallerThan(const EbmlElement * Cmp) const return false; // compare tracks (timestamp are equal) - const auto TrackA = FindChild(*this); + const auto TrackA = static_cast(FindElt(EBML_INFO(KaxCueTrack))); if (!TrackA) return false; - const auto TrackB = FindChild(*theCmp); + const auto TrackB = static_cast(theCmp->FindElt(EBML_INFO(KaxCueTrack))); if (!TrackB) return false; @@ -161,7 +161,7 @@ bool KaxCuePoint::IsSmallerThan(const EbmlElement * Cmp) const bool KaxCuePoint::Timestamp(std::uint64_t & aTimestamp, std::uint64_t GlobalTimestampScale) const { - const auto aTime = FindChild(*this); + const auto aTime = static_cast(FindFirstElt(EBML_INFO(KaxCueTime))); if (!aTime) return false; aTimestamp = static_cast(*aTime) * GlobalTimestampScale; @@ -176,22 +176,22 @@ const KaxCueTrackPositions * KaxCuePoint::GetSeekPosition() const const KaxCueTrackPositions * result = nullptr; std::uint64_t aPosition = 0xFFFFFFFFFFFFFFFLL; // find the position of the "earlier" Cluster - auto aPoss = FindChild(*this); + auto aPoss = static_cast(FindFirstElt(EBML_INFO(KaxCueTrackPositions))); while (aPoss) { - auto aPos = FindChild(*aPoss); + auto aPos = static_cast(aPoss->FindFirstElt(EBML_INFO(KaxCueClusterPosition))); if (aPos && static_cast(*aPos) < aPosition) { aPosition = static_cast(*aPos); result = aPoss; } - aPoss = FindNextChild(*this, *aPoss); + aPoss = static_cast(FindNextElt(*aPoss)); } return result; } std::uint64_t KaxCueTrackPositions::ClusterPosition() const { - const auto aPos = FindChild(*this); + const auto aPos = static_cast(FindFirstElt(EBML_INFO(KaxCueClusterPosition))); if (!aPos) return 0; @@ -200,7 +200,7 @@ std::uint64_t KaxCueTrackPositions::ClusterPosition() const std::uint16_t KaxCueTrackPositions::TrackNumber() const { - const auto aTrack = FindChild(*this); + const auto aTrack = static_cast(FindFirstElt(EBML_INFO(KaxCueTrack))); if (!aTrack) return 0; diff --git a/src/KaxSeekHead.cpp b/src/KaxSeekHead.cpp index 971c2421..c23cae6e 100644 --- a/src/KaxSeekHead.cpp +++ b/src/KaxSeekHead.cpp @@ -39,16 +39,18 @@ KaxSeek * KaxSeekHead::IndexThis(const EbmlElement & aElt, const KaxSegment & Pa KaxSeek * KaxSeekHead::FindFirstOf(const EbmlCallbacks & Callbacks) const { // parse all the Entries and find the first to match the type - auto aElt = FindChild(*this); + auto aElt = static_cast(FindFirstElt(EBML_INFO(KaxSeek))); while (aElt) { - const auto aId = FindChild(*aElt); - if (aId != nullptr) { + auto it = std::find_if(aElt->begin(), aElt->end(), [&](auto Elt) + { return (EbmlId(*Elt) == EBML_ID(KaxSeekID)); }); + if (it != aElt->end()) { + const auto aId = static_cast(*it); const auto aEbmlId = EbmlId(EbmlId::FromBuffer(aId->GetBuffer(), aId->GetSize())); if (aEbmlId == EBML_INFO_ID(Callbacks)) { return aElt; } } - aElt = FindNextChild(*this,*aElt); + aElt = static_cast(FindNextElt(*aElt)); } return nullptr; @@ -71,7 +73,7 @@ KaxSeek * KaxSeekHead::FindNextOf(const KaxSeek &aPrev) const std::int64_t KaxSeek::Location() const { - auto aPos = FindChild(*this); + auto aPos = static_cast(FindFirstElt(EBML_INFO(KaxSeekPosition))); if (!aPos) return 0; return static_cast(*aPos); @@ -79,7 +81,7 @@ std::int64_t KaxSeek::Location() const bool KaxSeek::IsEbmlId(const EbmlId & aId) const { - auto _Id = FindChild(*this); + auto _Id = static_cast(FindFirstElt(EBML_INFO(KaxSeekID))); if (!_Id) return false; const auto aEbmlId = EbmlId(EbmlId::FromBuffer(_Id->GetBuffer(), _Id->GetSize())); @@ -88,10 +90,10 @@ bool KaxSeek::IsEbmlId(const EbmlId & aId) const bool KaxSeek::IsEbmlId(const KaxSeek & aPoint) const { - auto _IdA = FindChild(*this); + auto _IdA = static_cast(FindFirstElt(EBML_INFO(KaxSeekID))); if (!_IdA) return false; - auto _IdB = FindChild(aPoint); + auto _IdB = static_cast(aPoint.FindFirstElt(EBML_INFO(KaxSeekID))); if (!_IdB) return false; const auto aEbmlIdA = EbmlId(EbmlId::FromBuffer(_IdA->GetBuffer(), _IdA->GetSize())); diff --git a/test/ebml/test00.cpp b/test/ebml/test00.cpp index bd537a0e..09cd46e4 100644 --- a/test/ebml/test00.cpp +++ b/test/ebml/test00.cpp @@ -59,21 +59,21 @@ int main(void) // size is unknown and will always be, we can render it right away FirstSegment.Render(Ebml_file); - KaxAttachments * pAllAttachments = &GetChild(FirstSegment); + KaxAttachments * pAllAttachments = static_cast(FirstSegment.FindFirstElt(EBML_INFO(KaxAttachments), true)); if (pAllAttachments == NULL) return -1; pAllAttachments->SetSizeInfinite(); // size is unknown and will always be, we can render it right away pAllAttachments->Render(Ebml_file); - KaxAttached * pAttachment1 = &GetChild(*pAllAttachments); + KaxAttached * pAttachment1 = static_cast(pAllAttachments->FindFirstElt(EBML_INFO(KaxAttached), true)); if (pAttachment1 == NULL) return -1; - KaxFileName * pFileName1 = &GetChild(*pAttachment1); + KaxFileName * pFileName1 = static_cast(pAttachment1->FindFirstElt(EBML_INFO(KaxFileName), true)); if (pFileName1 == NULL) return -1; pFileName1->SetValue(UTFstring{L"file1.txt"}); - KaxFileData * pFileData1 = &GetChild(*pAttachment1); + KaxFileData * pFileData1 = static_cast(pAttachment1->FindFirstElt(EBML_INFO(KaxFileData), true)); if (pFileData1 == NULL) return -1; char Buffer1[] = "Ah ah ah !"; @@ -81,15 +81,15 @@ int main(void) // should produce an error if the size is not infinite and the data has been rendered pAttachment1->Render(Ebml_file); - KaxAttached * pAttachment2 = &AddNewChild(*pAllAttachments); + KaxAttached * pAttachment2 = static_cast(pAllAttachments->AddNewElt(EBML_INFO(KaxAttached))); if (pAttachment2 == NULL) return -1; - KaxFileName * pFileName2 = &GetChild(*pAttachment2); + KaxFileName * pFileName2 = static_cast(pAttachment2->FindFirstElt(EBML_INFO(KaxFileName), true)); if (pFileName2 == NULL) return -1; pFileName2->SetValue(UTFstring{L"file2.txt"}); // Add a void element (data is discarded) - EbmlVoid * pVoid = &GetChild(*pAttachment2); + EbmlVoid * pVoid = static_cast(pAttachment2->FindFirstElt(EBML_INFO(EbmlVoid), true)); if (pVoid == NULL) return -1; static_cast(pVoid)->SetBuffer((const binary*) Buffer1, countof(Buffer1)); diff --git a/test/mux/test8.cpp b/test/mux/test8.cpp index 49454f03..c75fc210 100644 --- a/test/mux/test8.cpp +++ b/test/mux/test8.cpp @@ -307,7 +307,7 @@ int main(int argc, char **argv) // Extract the valuable data from the Block aBlockGroup.Read(aStream, EBML_CLASS_CONTEXT(KaxBlockGroup), UpperElementLevel, ElementLevel3, bAllowDummy); - KaxBlock * DataBlock = FindChild(aBlockGroup); + KaxBlock * DataBlock = static_cast(aBlockGroup.FindElt(EBML_INFO(KaxBlock))); if (DataBlock != NULL) { // DataBlock->ReadData(aStream.I_O()); DataBlock->SetParent(*SegmentCluster); @@ -315,11 +315,11 @@ int main(int argc, char **argv) } else { printf(" A BlockGroup without a Block !!!"); } - KaxBlockDuration * BlockDuration = FindChild(aBlockGroup); + KaxBlockDuration * BlockDuration = static_cast(aBlockGroup.FindElt(EBML_INFO(KaxBlockDuration))); if (BlockDuration != NULL) { printf(" Block Duration %d scaled ticks : %ld ns\n", std::uint32_t(*BlockDuration), std::uint32_t(*BlockDuration) * TimestampScale); } - KaxReferenceBlock * RefTime = FindChild(aBlockGroup); + KaxReferenceBlock * RefTime = static_cast(aBlockGroup.FindElt(EBML_INFO(KaxReferenceBlock))); if (RefTime != NULL) { printf(" Reference frame at scaled (%d) timestamp %ld\n", std::int32_t(*RefTime), std::int32_t(std::int64_t(*RefTime) * TimestampScale)); }