Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Use typed children macros instead of local casts" #193

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 *>(FindFirstElt(EBML_INFO(KaxTrackNumber)))); }
libebml::EbmlUInteger & TrackNumber() const { return *(static_cast<libebml::EbmlUInteger *>(FindElt(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 = FindChild<KaxBlock>(*this);
auto MyBlock = static_cast<KaxBlock *>(this->FindElt(EBML_INFO(KaxBlock)));
return MyBlock->GlobalTimestamp();
}

std::uint16_t KaxBlockGroup::TrackNumber() const
{
auto MyBlock = FindChild<KaxBlock>(*this);
auto MyBlock = static_cast<KaxBlock *>(this->FindElt(EBML_INFO(KaxBlock)));
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 = FindChild<KaxReferenceBlock>(*this);
auto MyBlockAdds = static_cast<KaxReferenceBlock *>(FindFirstElt(EBML_INFO(KaxReferenceBlock)));
if (MyBlockAdds) {
Result++;
while ((MyBlockAdds = FindNextChild<KaxReferenceBlock>(*this, *MyBlockAdds))) {
while ((MyBlockAdds = static_cast<KaxReferenceBlock *>(FindNextElt(*MyBlockAdds)))) {
Result++;
}
}
Expand All @@ -867,11 +867,11 @@ unsigned int KaxBlockGroup::ReferenceCount() const

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

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

void KaxBlockGroup::ReleaseFrames()
{
auto MyBlock = FindChild<KaxBlock>(*this);
auto MyBlock = static_cast<KaxBlock *>(this->FindElt(EBML_INFO(KaxBlock)));
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 = FindChild<KaxBlockDuration>(*this);
const auto myDuration = static_cast<KaxBlockDuration *>(FindFirstElt(EBML_INFO(KaxBlockDuration), true));
myDuration->SetValue(TimeLength / static_cast<std::uint64_t>(scale));
}

bool KaxBlockGroup::GetBlockDuration(std::uint64_t &TheTimestamp) const
{
const auto myDuration = FindChild<KaxBlockDuration>(*this);
const auto myDuration = static_cast<KaxBlockDuration *>(FindElt(EBML_INFO(KaxBlockDuration)));
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 = FindChild<KaxClusterTimestamp>(*this);
auto ClusterTimestamp = static_cast<KaxClusterTimestamp *>(this->FindElt(EBML_INFO(KaxClusterTimestamp)));
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 = FindChild<KaxClusterTimestamp>(*this);
auto ClusterTimestamp = static_cast<KaxClusterTimestamp *>(this->FindElt(EBML_INFO(KaxClusterTimestamp)));
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 = FindChild<const KaxCueTime>(*tmp);
auto aTime = static_cast<const KaxCueTime *>(tmp->FindFirstElt(EBML_INFO(KaxCueTime)));
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 = FindChild<KaxCodecState>(BlockReference);
auto CodecState = static_cast<KaxCodecState *>(BlockReference.FindFirstElt(EBML_INFO(KaxCodecState)));
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 = FindChild<const KaxCodecState>(*BlockGroup);
const auto CodecState = static_cast<const KaxCodecState *>(BlockGroup->FindFirstElt(EBML_INFO(KaxCodecState)));
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 = FindChild<const KaxCueTime>(*this);
auto TimestampA = static_cast<const KaxCueTime *>(FindElt(EBML_INFO(KaxCueTime)));
if (!TimestampA)
return false;

auto TimestampB = FindChild<const KaxCueTime>(*theCmp);
auto TimestampB = static_cast<const KaxCueTime *>(theCmp->FindElt(EBML_INFO(KaxCueTime)));
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 = FindChild<const KaxCueTrack>(*this);
const auto TrackA = static_cast<const KaxCueTrack *>(FindElt(EBML_INFO(KaxCueTrack)));
if (!TrackA)
return false;

const auto TrackB = FindChild<const KaxCueTrack>(*theCmp);
const auto TrackB = static_cast<const KaxCueTrack *>(theCmp->FindElt(EBML_INFO(KaxCueTrack)));
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 = FindChild<const KaxCueTime>(*this);
const auto aTime = static_cast<const KaxCueTime *>(FindFirstElt(EBML_INFO(KaxCueTime)));
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 = FindChild<const KaxCueTrackPositions>(*this);
auto aPoss = static_cast<const KaxCueTrackPositions *>(FindFirstElt(EBML_INFO(KaxCueTrackPositions)));
while (aPoss) {
auto aPos = FindChild<const KaxCueClusterPosition>(*aPoss);
auto aPos = static_cast<const KaxCueClusterPosition *>(aPoss->FindFirstElt(EBML_INFO(KaxCueClusterPosition)));
if (aPos && static_cast<std::uint64_t>(*aPos) < aPosition) {
aPosition = static_cast<std::uint64_t>(*aPos);
result = aPoss;
}

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

std::uint64_t KaxCueTrackPositions::ClusterPosition() const
{
const auto aPos = FindChild<const KaxCueClusterPosition>(*this);
const auto aPos = static_cast<const KaxCueClusterPosition *>(FindFirstElt(EBML_INFO(KaxCueClusterPosition)));
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 = FindChild<const KaxCueTrack>(*this);
const auto aTrack = static_cast<const KaxCueTrack *>(FindFirstElt(EBML_INFO(KaxCueTrack)));
if (!aTrack)
return 0;

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

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

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

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

bool KaxSeek::IsEbmlId(const KaxSeek & aPoint) const
{
auto _IdA = FindChild<KaxSeekID>(*this);
auto _IdA = static_cast<KaxSeekID*>(FindFirstElt(EBML_INFO(KaxSeekID)));
if (!_IdA)
return false;
auto _IdB = FindChild<KaxSeekID>(aPoint);
auto _IdB = static_cast<KaxSeekID*>(aPoint.FindFirstElt(EBML_INFO(KaxSeekID)));
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 = &GetChild<KaxAttachments>(FirstSegment);
KaxAttachments * pAllAttachments = static_cast<KaxAttachments *>(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<KaxAttached>(*pAllAttachments);
KaxAttached * pAttachment1 = static_cast<KaxAttached *>(pAllAttachments->FindFirstElt(EBML_INFO(KaxAttached), true));
if (pAttachment1 == NULL)
return -1;
KaxFileName * pFileName1 = &GetChild<KaxFileName>(*pAttachment1);
KaxFileName * pFileName1 = static_cast<KaxFileName *>(pAttachment1->FindFirstElt(EBML_INFO(KaxFileName), true));
if (pFileName1 == NULL)
return -1;
pFileName1->SetValue(UTFstring{L"file1.txt"});
KaxFileData * pFileData1 = &GetChild<KaxFileData>(*pAttachment1);
KaxFileData * pFileData1 = static_cast<KaxFileData *>(pAttachment1->FindFirstElt(EBML_INFO(KaxFileData), true));
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 = &AddNewChild<KaxAttached>(*pAllAttachments);
KaxAttached * pAttachment2 = static_cast<KaxAttached *>(pAllAttachments->AddNewElt(EBML_INFO(KaxAttached)));
if (pAttachment2 == NULL)
return -1;
KaxFileName * pFileName2 = &GetChild<KaxFileName>(*pAttachment2);
KaxFileName * pFileName2 = static_cast<KaxFileName *>(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<EbmlVoid>(*pAttachment2);
EbmlVoid * pVoid = static_cast<EbmlVoid *>(pAttachment2->FindFirstElt(EBML_INFO(EbmlVoid), true));
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 = FindChild<KaxBlock>(aBlockGroup);
KaxBlock * DataBlock = static_cast<KaxBlock *>(aBlockGroup.FindElt(EBML_INFO(KaxBlock)));
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 = FindChild<KaxBlockDuration>(aBlockGroup);
KaxBlockDuration * BlockDuration = static_cast<KaxBlockDuration *>(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<KaxReferenceBlock>(aBlockGroup);
KaxReferenceBlock * RefTime = static_cast<KaxReferenceBlock *>(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));
}
Expand Down