Skip to content

Commit

Permalink
Bento4: косметика для AP4_AtomSampleTable::GetSampleIndexForTimeStamp.
Browse files Browse the repository at this point in the history
  • Loading branch information
v0lt committed Apr 29, 2024
1 parent 10e8eb5 commit fbcb75b
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/ExtLib/Bento4/Core/Ap4AtomSampleTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,15 @@ AP4_AtomSampleTable::GetSampleIndexForTimeStamp(AP4_TimeStamp ts,
AP4_Ordinal& index)
{
AP4_Result result = m_SttsAtom ? m_SttsAtom->GetSampleIndexForTimeStamp(ts, m_tsDelay, index) : AP4_FAILURE;
if AP4_SUCCEEDED(result) {
if (AP4_SUCCEEDED(result)) {
auto GetCts = [&](AP4_Ordinal i, AP4_SI64& cts) {
AP4_TimeStamp dts;
AP4_Duration duration;
const AP4_Ordinal index = i + 1;
result = m_SttsAtom->GetDts(index, dts, duration);
if (AP4_FAILED(result)) return result;
if (AP4_FAILED(result)) {
return result;
}
AP4_SI32 cts_offset = 0;
if (m_CttsAtom) {
m_CttsAtom->GetCtsOffset(index, cts_offset);
Expand All @@ -296,10 +298,12 @@ AP4_AtomSampleTable::GetSampleIndexForTimeStamp(AP4_TimeStamp ts,

AP4_SI64 cts;
result = GetCts(index, cts);
if (AP4_FAILED(result)) return result;
if (AP4_FAILED(result)) {
return result;
}

bool validStssAtom = m_StssAtom && m_StssAtom->GetEntries().ItemCount();
auto searched_ts = static_cast<AP4_SI64>(ts);
const bool validStssAtom = m_StssAtom && m_StssAtom->GetEntries().ItemCount();
const auto searched_ts = static_cast<AP4_SI64>(ts);

if (cts == searched_ts
&& (!validStssAtom || m_StssAtom->IsSampleSync(index + 1))) {
Expand All @@ -314,7 +318,9 @@ AP4_AtomSampleTable::GetSampleIndexForTimeStamp(AP4_TimeStamp ts,
}

result = GetCts(i, cts);
if (AP4_FAILED(result)) return result;
if (AP4_FAILED(result)) {
return result;
}

if (cts <= searched_ts) {
index = i;
Expand All @@ -330,7 +336,9 @@ AP4_AtomSampleTable::GetSampleIndexForTimeStamp(AP4_TimeStamp ts,
}

result = GetCts(i, cts);
if (AP4_FAILED(result)) return result;
if (AP4_FAILED(result)) {
return result;
}

if (cts > searched_ts) {
if (!validStssAtom) {
Expand Down

0 comments on commit fbcb75b

Please sign in to comment.