Skip to content

Commit

Permalink
[r5982] MP4Splitter/Bento4 - корректировка обработки атома 'ctts'. Эт…
Browse files Browse the repository at this point in the history
…о исправит отсутствие дорожек при открытии файлов с пустым атомом 'ctts'. Косметика кода.
  • Loading branch information
Aleksoid1978 committed Jan 21, 2021
1 parent 74619e1 commit 6dc7756
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
50 changes: 24 additions & 26 deletions src/ExtLib/Bento4/Core/Ap4AtomSampleTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
/*----------------------------------------------------------------------
| AP4_AtomSampleTable::AP4_AtomSampleTable
+---------------------------------------------------------------------*/
AP4_AtomSampleTable::AP4_AtomSampleTable(AP4_ContainerAtom* stbl,
AP4_AtomSampleTable::AP4_AtomSampleTable(AP4_ContainerAtom* stbl,
AP4_ByteStream& sample_stream) :
m_SampleStream(sample_stream)
, m_tsDelay(0)
Expand All @@ -65,13 +65,13 @@ AP4_AtomSampleTable::AP4_AtomSampleTable(AP4_ContainerAtom* stbl,
// keep a reference to the sample stream
m_SampleStream.AddReference();

if (m_StsdAtom && m_StszAtom && m_StscAtom && m_SttsAtom
if (m_StsdAtom && m_StszAtom && m_StscAtom && m_SttsAtom
&& (m_StszAtom->m_SampleSize == 1
|| (m_SttsAtom->m_Entries.ItemCount() == 1 && m_SttsAtom->m_Entries[0].m_SampleDuration == 1)))
{
// fix mov files
for (AP4_List<AP4_Atom>::Item* item = m_StsdAtom->GetChildren().FirstItem();
item;
for (AP4_List<AP4_Atom>::Item* item = m_StsdAtom->GetChildren().FirstItem();
item;
item = item->GetNext()) {
AP4_Atom* atom = item->GetData();

Expand Down Expand Up @@ -112,7 +112,7 @@ AP4_AtomSampleTable::~AP4_AtomSampleTable()
| AP4_AtomSampleTable::GetSample
+---------------------------------------------------------------------*/
AP4_Result
AP4_AtomSampleTable::GetSample(AP4_Ordinal index,
AP4_AtomSampleTable::GetSample(AP4_Ordinal index,
AP4_Sample& sample)
{
AP4_Result result;
Expand All @@ -129,21 +129,21 @@ AP4_AtomSampleTable::GetSample(AP4_Ordinal index,
AP4_Ordinal chunk, skip, desc;
result = m_StscAtom->GetChunkForSample(index, chunk, skip, desc);
if (AP4_FAILED(result)) return result;

// check that the result is within bounds
if (skip > index) return AP4_ERROR_INTERNAL;

// get the atom offset for this chunk
AP4_Offset offset;
if (m_StcoAtom) result = m_StcoAtom->GetChunkOffset(chunk, offset);
else if (m_Co64Atom) result = m_Co64Atom->GetChunkOffset(chunk, offset);
else result = AP4_ERROR_INTERNAL;
if (m_StcoAtom) result = m_StcoAtom->GetChunkOffset(chunk, offset);
else if (m_Co64Atom) result = m_Co64Atom->GetChunkOffset(chunk, offset);
else result = AP4_ERROR_INTERNAL;
if (AP4_FAILED(result)) return result;
/*
// compute the additional offset inside the chunk
for (unsigned int i = index-skip; i < index; i++) {
AP4_Size size;
result = m_StszAtom->GetSampleSize(i, size);
result = m_StszAtom->GetSampleSize(i, size);
if (AP4_FAILED(result)) return result;
offset += size;
}
Expand All @@ -163,14 +163,12 @@ AP4_AtomSampleTable::GetSample(AP4_Ordinal index,
if (AP4_FAILED(result)) return result;
sample.SetDts(dts);
sample.SetDuration(duration);
if (m_CttsAtom == NULL) {
sample.SetCts(dts + m_tsDelay);
} else {
AP4_SI32 cts_offset;
result = m_CttsAtom->GetCtsOffset(index, cts_offset);
if (AP4_FAILED(result)) return result;
sample.SetCts(dts + cts_offset + m_tsDelay);
}

AP4_SI32 cts_offset = 0;
if (m_CttsAtom) {
m_CttsAtom->GetCtsOffset(index, cts_offset);
}
sample.SetCts(dts + cts_offset + m_tsDelay);

// set the size
AP4_Size sample_size;
Expand Down Expand Up @@ -224,7 +222,7 @@ AP4_AtomSampleTable::GetSampleDescriptionCount()
/*----------------------------------------------------------------------
| AP4_AtomSampleTable::GetChunkForSample
+---------------------------------------------------------------------*/
AP4_Result
AP4_Result
AP4_AtomSampleTable::GetChunkForSample(AP4_Ordinal sample,
AP4_Ordinal& chunk,
AP4_Ordinal& skip,
Expand All @@ -236,7 +234,7 @@ AP4_AtomSampleTable::GetChunkForSample(AP4_Ordinal sample,
/*----------------------------------------------------------------------
| AP4_AtomSampleTable::GetChunkOffset
+---------------------------------------------------------------------*/
AP4_Result
AP4_Result
AP4_AtomSampleTable::GetChunkOffset(AP4_Ordinal chunk, AP4_Offset& offset)
{
return
Expand All @@ -248,19 +246,19 @@ AP4_AtomSampleTable::GetChunkOffset(AP4_Ordinal chunk, AP4_Offset& offset)
/*----------------------------------------------------------------------
| AP4_AtomSampleTable::SetChunkOffset
+---------------------------------------------------------------------*/
AP4_Result
AP4_Result
AP4_AtomSampleTable::SetChunkOffset(AP4_Ordinal chunk, AP4_Offset offset)
{
return
m_StcoAtom ? m_StcoAtom->SetChunkOffset(chunk, offset) :
m_Co64Atom ? m_Co64Atom->SetChunkOffset(chunk, offset) :
return
m_StcoAtom ? m_StcoAtom->SetChunkOffset(chunk, offset) :
m_Co64Atom ? m_Co64Atom->SetChunkOffset(chunk, offset) :
AP4_FAILURE;
}

/*----------------------------------------------------------------------
| AP4_AtomSampleTable::SetSampleSize
+---------------------------------------------------------------------*/
AP4_Result
AP4_Result
AP4_AtomSampleTable::SetSampleSize(AP4_Ordinal sample, AP4_Size size)
{
return m_StszAtom ? m_StszAtom->SetSampleSize(sample, size) : AP4_FAILURE;
Expand All @@ -269,7 +267,7 @@ AP4_AtomSampleTable::SetSampleSize(AP4_Ordinal sample, AP4_Size size)
/*----------------------------------------------------------------------
| AP4_AtomSampleTable::GetSampleIndexForTimeStamp
+---------------------------------------------------------------------*/
AP4_Result
AP4_Result
AP4_AtomSampleTable::GetSampleIndexForTimeStamp(AP4_TimeStamp ts,
AP4_Ordinal& index)
{
Expand Down
8 changes: 4 additions & 4 deletions src/ExtLib/Bento4/Core/Ap4CttsAtom.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*****************************************************************
|
| AP4 - ctts Atoms
| AP4 - ctts Atoms
|
| Copyright 2003 Gilles Boccon-Gibod & Julien Boeuf
|
Expand Down Expand Up @@ -64,10 +64,10 @@ AP4_CttsAtom::GetCtsOffset(AP4_Ordinal sample, AP4_SI32& cts_offset)
{
// default value
cts_offset = 0;

// sample indexes start at 1
if (sample == 0) return AP4_ERROR_OUT_OF_RANGE;

// check the lookup cache
AP4_Ordinal lookup_start = 0;
AP4_Ordinal sample_start = 0;
Expand All @@ -93,7 +93,7 @@ AP4_CttsAtom::GetCtsOffset(AP4_Ordinal sample, AP4_SI32& cts_offset)
}

// update the upper bound
sample_start += entry.m_SampleCount;
sample_start += entry.m_SampleCount;
}

// sample is greater than the number of samples
Expand Down
8 changes: 4 additions & 4 deletions src/ExtLib/Bento4/Core/Ap4CttsAtom.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*****************************************************************
|
| AP4 - ctts Atoms
| AP4 - ctts Atoms
|
| Copyright 2003 Gilles Boccon-Gibod & Julien Boeuf
|
Expand Down Expand Up @@ -41,8 +41,8 @@
+---------------------------------------------------------------------*/
class AP4_CttsTableEntry {
public:
AP4_CttsTableEntry() :
m_SampleCount(0),
AP4_CttsTableEntry() :
m_SampleCount(0),
m_SampleOffset(0) {}
AP4_CttsTableEntry(AP4_Cardinal sample_count,
AP4_SI32 sample_offset) :
Expand All @@ -63,7 +63,7 @@ class AP4_CttsAtom : public AP4_Atom
AP4_CttsAtom(AP4_Size size, AP4_ByteStream& stream);
virtual AP4_Result InspectFields(AP4_AtomInspector& inspector);
virtual AP4_Result WriteFields(AP4_ByteStream& stream);
virtual AP4_Result GetCtsOffset(AP4_Ordinal sample,
virtual AP4_Result GetCtsOffset(AP4_Ordinal sample,
AP4_SI32& cts_offset);

private:
Expand Down

0 comments on commit 6dc7756

Please sign in to comment.