Skip to content

Commit

Permalink
Merge remote-tracking branch 'robux4/typed_children'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbunkus committed Mar 2, 2024
2 parents 2b4a0ca + b2efa89 commit 72d1291
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 45 deletions.
2 changes: 1 addition & 1 deletion matroska/KaxTracks.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace libmatroska {

DECLARE_MKX_MASTER(KaxTrackEntry)
public:
libebml::EbmlUInteger & TrackNumber() const { return *(static_cast<libebml::EbmlUInteger *>(FindElt(EBML_INFO(KaxTrackNumber)))); }
libebml::EbmlUInteger & TrackNumber() const { return *(static_cast<libebml::EbmlUInteger *>(FindFirstElt(EBML_INFO(KaxTrackNumber)))); }

void EnableLacing(bool bEnable = true);

Expand Down
18 changes: 9 additions & 9 deletions src/KaxBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = static_cast<KaxBlock *>(this->FindElt(EBML_INFO(KaxBlock)));
auto MyBlock = FindChild<KaxBlock>(*this);
return MyBlock->GlobalTimestamp();
}

std::uint16_t KaxBlockGroup::TrackNumber() const
{
auto MyBlock = static_cast<KaxBlock *>(this->FindElt(EBML_INFO(KaxBlock)));
auto MyBlock = FindChild<KaxBlock>(*this);
return MyBlock->TrackNum();
}

Expand All @@ -855,10 +855,10 @@ std::uint64_t KaxInternalBlock::ClusterPosition() const
unsigned int KaxBlockGroup::ReferenceCount() const
{
unsigned int Result = 0;
auto MyBlockAdds = static_cast<KaxReferenceBlock *>(FindFirstElt(EBML_INFO(KaxReferenceBlock)));
auto MyBlockAdds = FindChild<KaxReferenceBlock>(*this);
if (MyBlockAdds) {
Result++;
while ((MyBlockAdds = static_cast<KaxReferenceBlock *>(FindNextElt(*MyBlockAdds)))) {
while ((MyBlockAdds = FindNextChild<KaxReferenceBlock>(*this, *MyBlockAdds))) {
Result++;
}
}
Expand All @@ -867,11 +867,11 @@ unsigned int KaxBlockGroup::ReferenceCount() const

const KaxReferenceBlock & KaxBlockGroup::Reference(unsigned int Index) const
{
auto MyBlockAdds = static_cast<KaxReferenceBlock *>(FindFirstElt(EBML_INFO(KaxReferenceBlock)));
auto MyBlockAdds = FindChild<KaxReferenceBlock>(*this);
assert(MyBlockAdds); // call of a non existing reference

while (Index != 0) {
MyBlockAdds = static_cast<KaxReferenceBlock *>(FindNextElt(*MyBlockAdds));
MyBlockAdds = FindNextChild<KaxReferenceBlock>(*this, *MyBlockAdds);
assert(MyBlockAdds);
Index--;
}
Expand All @@ -880,7 +880,7 @@ const KaxReferenceBlock & KaxBlockGroup::Reference(unsigned int Index) const

void KaxBlockGroup::ReleaseFrames()
{
auto MyBlock = static_cast<KaxBlock *>(this->FindElt(EBML_INFO(KaxBlock)));
auto MyBlock = FindChild<KaxBlock>(*this);
MyBlock->ReleaseFrames();
}

Expand All @@ -900,13 +900,13 @@ void KaxBlockGroup::SetBlockDuration(std::uint64_t TimeLength)
{
assert(ParentTrack);
const std::int64_t scale = ParentTrack->GlobalTimestampScale();
const auto myDuration = static_cast<KaxBlockDuration *>(FindFirstElt(EBML_INFO(KaxBlockDuration), true));
const auto myDuration = FindChild<KaxBlockDuration>(*this);
myDuration->SetValue(TimeLength / static_cast<std::uint64_t>(scale));
}

bool KaxBlockGroup::GetBlockDuration(std::uint64_t &TheTimestamp) const
{
const auto myDuration = static_cast<KaxBlockDuration *>(FindElt(EBML_INFO(KaxBlockDuration)));
const auto myDuration = FindChild<KaxBlockDuration>(*this);
if (!myDuration) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/KaxCluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = static_cast<KaxClusterTimestamp *>(this->FindElt(EBML_INFO(KaxClusterTimestamp)));
auto ClusterTimestamp = FindChild<KaxClusterTimestamp>(*this);
ClusterTimestamp->SetValue(GlobalTimestamp() / GlobalTimestampScale());

if (Blobs.empty()) {
Expand Down Expand Up @@ -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 = static_cast<KaxClusterTimestamp *>(this->FindElt(EBML_INFO(KaxClusterTimestamp)));
auto ClusterTimestamp = FindChild<KaxClusterTimestamp>(*this);
assert (bFirstFrameInside); // use the InitTimestamp() hack for now
MinTimestamp = MaxTimestamp = PreviousTimestamp = static_cast<std::uint64_t>(*static_cast<EbmlUInteger *>(ClusterTimestamp));
bFirstFrameInside = true;
Expand Down
2 changes: 1 addition & 1 deletion src/KaxCues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const KaxCuePoint * KaxCues::GetTimestampPoint(std::uint64_t aTimestamp) const
if (EbmlId(*e) == EBML_ID(KaxCuePoint)) {
auto tmp = static_cast<const KaxCuePoint *>(e);
// check the tile
auto aTime = static_cast<const KaxCueTime *>(tmp->FindFirstElt(EBML_INFO(KaxCueTime)));
auto aTime = FindChild<const KaxCueTime>(*tmp);
if (aTime) {
auto _Time = static_cast<std::uint64_t>(*aTime);
if (_Time > aPrevTime && _Time < TimestampToLocate) {
Expand Down
24 changes: 12 additions & 12 deletions src/KaxCuesData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void KaxCuePoint::PositionSet(const KaxBlockGroup & BlockReference, std::uint64_
}
}

auto CodecState = static_cast<KaxCodecState *>(BlockReference.FindFirstElt(EBML_INFO(KaxCodecState)));
auto CodecState = FindChild<KaxCodecState>(BlockReference);
if (CodecState) {
auto &CueCodecState = AddNewChild<KaxCueCodecState>(NewPositions);
CueCodecState.SetValue(BlockReference.GetParentCluster()->GetParentSegment()->GetRelativePosition(CodecState->GetElementPosition()));
Expand Down Expand Up @@ -96,7 +96,7 @@ void KaxCuePoint::PositionSet(const KaxInternalBlock & BlockReference, const Kax
#endif // MATROSKA_VERSION

if (BlockGroup) {
const auto CodecState = static_cast<const KaxCodecState *>(BlockGroup->FindFirstElt(EBML_INFO(KaxCodecState)));
const auto CodecState = FindChild<const KaxCodecState>(*BlockGroup);
if (CodecState) {
auto &CueCodecState = AddNewChild<KaxCueCodecState>(NewPositions);
CueCodecState.SetValue(BlockGroup->GetParentCluster()->GetParentSegment()->GetRelativePosition(CodecState->GetElementPosition()));
Expand Down Expand Up @@ -127,11 +127,11 @@ bool KaxCuePoint::IsSmallerThan(const EbmlElement * Cmp) const
auto theCmp = static_cast<const KaxCuePoint *>(Cmp);

// compare timestamp
auto TimestampA = static_cast<const KaxCueTime *>(FindElt(EBML_INFO(KaxCueTime)));
auto TimestampA = FindChild<const KaxCueTime>(*this);
if (!TimestampA)
return false;

auto TimestampB = static_cast<const KaxCueTime *>(theCmp->FindElt(EBML_INFO(KaxCueTime)));
auto TimestampB = FindChild<const KaxCueTime>(*theCmp);
if (!TimestampB)
return false;

Expand All @@ -142,11 +142,11 @@ bool KaxCuePoint::IsSmallerThan(const EbmlElement * Cmp) const
return false;

// compare tracks (timestamp are equal)
const auto TrackA = static_cast<const KaxCueTrack *>(FindElt(EBML_INFO(KaxCueTrack)));
const auto TrackA = FindChild<const KaxCueTrack>(*this);
if (!TrackA)
return false;

const auto TrackB = static_cast<const KaxCueTrack *>(theCmp->FindElt(EBML_INFO(KaxCueTrack)));
const auto TrackB = FindChild<const KaxCueTrack>(*theCmp);
if (!TrackB)
return false;

Expand All @@ -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 = static_cast<const KaxCueTime *>(FindFirstElt(EBML_INFO(KaxCueTime)));
const auto aTime = FindChild<const KaxCueTime>(*this);
if (!aTime)
return false;
aTimestamp = static_cast<std::uint64_t>(*aTime) * GlobalTimestampScale;
Expand All @@ -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 = static_cast<const KaxCueTrackPositions *>(FindFirstElt(EBML_INFO(KaxCueTrackPositions)));
auto aPoss = FindChild<const KaxCueTrackPositions>(*this);
while (aPoss) {
auto aPos = static_cast<const KaxCueClusterPosition *>(aPoss->FindFirstElt(EBML_INFO(KaxCueClusterPosition)));
auto aPos = FindChild<const KaxCueClusterPosition>(*aPoss);
if (aPos && static_cast<std::uint64_t>(*aPos) < aPosition) {
aPosition = static_cast<std::uint64_t>(*aPos);
result = aPoss;
}

aPoss = static_cast<const KaxCueTrackPositions *>(FindNextElt(*aPoss));
aPoss = FindNextChild<const KaxCueTrackPositions>(*this, *aPoss);
}
return result;
}

std::uint64_t KaxCueTrackPositions::ClusterPosition() const
{
const auto aPos = static_cast<const KaxCueClusterPosition *>(FindFirstElt(EBML_INFO(KaxCueClusterPosition)));
const auto aPos = FindChild<const KaxCueClusterPosition>(*this);
if (!aPos)
return 0;

Expand All @@ -200,7 +200,7 @@ std::uint64_t KaxCueTrackPositions::ClusterPosition() const

std::uint16_t KaxCueTrackPositions::TrackNumber() const
{
const auto aTrack = static_cast<const KaxCueTrack *>(FindFirstElt(EBML_INFO(KaxCueTrack)));
const auto aTrack = FindChild<const KaxCueTrack>(*this);
if (!aTrack)
return 0;

Expand Down
18 changes: 8 additions & 10 deletions src/KaxSeekHead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,16 @@ 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 = static_cast<KaxSeek *>(FindFirstElt(EBML_INFO(KaxSeek)));
auto aElt = FindChild<KaxSeek>(*this);
while (aElt) {
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<KaxSeekID*>(*it);
const auto aId = FindChild<KaxSeekID>(*aElt);
if (aId != nullptr) {
const auto aEbmlId = EbmlId(EbmlId::FromBuffer(aId->GetBuffer(), aId->GetSize()));
if (aEbmlId == EBML_INFO_ID(Callbacks)) {
return aElt;
}
}
aElt = static_cast<KaxSeek *>(FindNextElt(*aElt));
aElt = FindNextChild<KaxSeek>(*this,*aElt);
}

return nullptr;
Expand All @@ -73,15 +71,15 @@ KaxSeek * KaxSeekHead::FindNextOf(const KaxSeek &aPrev) const

std::int64_t KaxSeek::Location() const
{
auto aPos = static_cast<KaxSeekPosition*>(FindFirstElt(EBML_INFO(KaxSeekPosition)));
auto aPos = FindChild<KaxSeekPosition>(*this);
if (!aPos)
return 0;
return static_cast<std::uint64_t>(*aPos);
}

bool KaxSeek::IsEbmlId(const EbmlId & aId) const
{
auto _Id = static_cast<KaxSeekID*>(FindFirstElt(EBML_INFO(KaxSeekID)));
auto _Id = FindChild<KaxSeekID>(*this);
if (!_Id)
return false;
const auto aEbmlId = EbmlId(EbmlId::FromBuffer(_Id->GetBuffer(), _Id->GetSize()));
Expand All @@ -90,10 +88,10 @@ bool KaxSeek::IsEbmlId(const EbmlId & aId) const

bool KaxSeek::IsEbmlId(const KaxSeek & aPoint) const
{
auto _IdA = static_cast<KaxSeekID*>(FindFirstElt(EBML_INFO(KaxSeekID)));
auto _IdA = FindChild<KaxSeekID>(*this);
if (!_IdA)
return false;
auto _IdB = static_cast<KaxSeekID*>(aPoint.FindFirstElt(EBML_INFO(KaxSeekID)));
auto _IdB = FindChild<KaxSeekID>(aPoint);
if (!_IdB)
return false;
const auto aEbmlIdA = EbmlId(EbmlId::FromBuffer(_IdA->GetBuffer(), _IdA->GetSize()));
Expand Down
14 changes: 7 additions & 7 deletions test/ebml/test00.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,37 +59,37 @@ int main(void)
// size is unknown and will always be, we can render it right away
FirstSegment.Render(Ebml_file);

KaxAttachments * pAllAttachments = static_cast<KaxAttachments *>(FirstSegment.FindFirstElt(EBML_INFO(KaxAttachments), true));
KaxAttachments * pAllAttachments = &GetChild<KaxAttachments>(FirstSegment);
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 = static_cast<KaxAttached *>(pAllAttachments->FindFirstElt(EBML_INFO(KaxAttached), true));
KaxAttached * pAttachment1 = &GetChild<KaxAttached>(*pAllAttachments);
if (pAttachment1 == NULL)
return -1;
KaxFileName * pFileName1 = static_cast<KaxFileName *>(pAttachment1->FindFirstElt(EBML_INFO(KaxFileName), true));
KaxFileName * pFileName1 = &GetChild<KaxFileName>(*pAttachment1);
if (pFileName1 == NULL)
return -1;
pFileName1->SetValue(UTFstring{L"file1.txt"});
KaxFileData * pFileData1 = static_cast<KaxFileData *>(pAttachment1->FindFirstElt(EBML_INFO(KaxFileData), true));
KaxFileData * pFileData1 = &GetChild<KaxFileData>(*pAttachment1);
if (pFileData1 == NULL)
return -1;
char Buffer1[] = "Ah ah ah !";
static_cast<EbmlBinary *>(pFileData1)->SetBuffer((const binary*) Buffer1, countof(Buffer1));
// should produce an error if the size is not infinite and the data has been rendered
pAttachment1->Render(Ebml_file);

KaxAttached * pAttachment2 = static_cast<KaxAttached *>(pAllAttachments->AddNewElt(EBML_INFO(KaxAttached)));
KaxAttached * pAttachment2 = &AddNewChild<KaxAttached>(*pAllAttachments);
if (pAttachment2 == NULL)
return -1;
KaxFileName * pFileName2 = static_cast<KaxFileName *>(pAttachment2->FindFirstElt(EBML_INFO(KaxFileName), true));
KaxFileName * pFileName2 = &GetChild<KaxFileName>(*pAttachment2);
if (pFileName2 == NULL)
return -1;
pFileName2->SetValue(UTFstring{L"file2.txt"});
// Add a void element (data is discarded)
EbmlVoid * pVoid = static_cast<EbmlVoid *>(pAttachment2->FindFirstElt(EBML_INFO(EbmlVoid), true));
EbmlVoid * pVoid = &GetChild<EbmlVoid>(*pAttachment2);
if (pVoid == NULL)
return -1;
static_cast<EbmlBinary *>(pVoid)->SetBuffer((const binary*) Buffer1, countof(Buffer1));
Expand Down
6 changes: 3 additions & 3 deletions test/mux/test8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,19 +307,19 @@ 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 = static_cast<KaxBlock *>(aBlockGroup.FindElt(EBML_INFO(KaxBlock)));
KaxBlock * DataBlock = FindChild<KaxBlock>(aBlockGroup);
if (DataBlock != NULL) {
// DataBlock->ReadData(aStream.I_O());
DataBlock->SetParent(*SegmentCluster);
printf(" Track # %d / %d frame%s / Timestamp %I64d\n",DataBlock->TrackNum(), DataBlock->NumberFrames(), (DataBlock->NumberFrames() > 1)?"s":"", DataBlock->GlobalTimestamp());
} else {
printf(" A BlockGroup without a Block !!!");
}
KaxBlockDuration * BlockDuration = static_cast<KaxBlockDuration *>(aBlockGroup.FindElt(EBML_INFO(KaxBlockDuration)));
KaxBlockDuration * BlockDuration = FindChild<KaxBlockDuration>(aBlockGroup);
if (BlockDuration != NULL) {
printf(" Block Duration %d scaled ticks : %ld ns\n", std::uint32_t(*BlockDuration), std::uint32_t(*BlockDuration) * TimestampScale);
}
KaxReferenceBlock * RefTime = static_cast<KaxReferenceBlock *>(aBlockGroup.FindElt(EBML_INFO(KaxReferenceBlock)));
KaxReferenceBlock * RefTime = FindChild<KaxReferenceBlock>(aBlockGroup);
if (RefTime != NULL) {
printf(" Reference frame at scaled (%d) timestamp %ld\n", std::int32_t(*RefTime), std::int32_t(std::int64_t(*RefTime) * TimestampScale));
}
Expand Down

0 comments on commit 72d1291

Please sign in to comment.