From f673675843144785658a010bab455972d83af004 Mon Sep 17 00:00:00 2001 From: peak3d Date: Thu, 22 Jul 2021 11:09:37 +0200 Subject: [PATCH] Implemented GetSampleIndexForTimeStamp/GetNearestSyncSampleIndex Signed-off-by: Bernd Kuhls --- Source/C++/Core/Ap4FragmentSampleTable.cpp | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Source/C++/Core/Ap4FragmentSampleTable.cpp b/Source/C++/Core/Ap4FragmentSampleTable.cpp index cea5c7d..1c62f24 100644 --- a/Source/C++/Core/Ap4FragmentSampleTable.cpp +++ b/Source/C++/Core/Ap4FragmentSampleTable.cpp @@ -297,10 +297,19 @@ AP4_FragmentSampleTable::GetSampleChunkPosition(AP4_Ordinal sample_index, | AP4_FragmentSampleTable::GetSampleIndexForTimeStamp +---------------------------------------------------------------------*/ AP4_Result -AP4_FragmentSampleTable::GetSampleIndexForTimeStamp(AP4_UI64 /*ts*/, +AP4_FragmentSampleTable::GetSampleIndexForTimeStamp(AP4_UI64 ts, AP4_Ordinal& sample_index) { - sample_index = 0; // TODO + if (!m_Samples.ItemCount()) + return AP4_ERROR_NOT_ENOUGH_DATA; + + sample_index = 0; + while (sample_index < m_Samples.ItemCount() && m_Samples[sample_index].GetCts() + m_Samples[sample_index].GetDuration() < ts) + ++sample_index; + + if (sample_index == m_Samples.ItemCount()) + return AP4_ERROR_NOT_ENOUGH_DATA; + return AP4_SUCCESS; } @@ -308,8 +317,16 @@ AP4_FragmentSampleTable::GetSampleIndexForTimeStamp(AP4_UI64 /*ts*/, | AP4_FragmentSampleTable::GetNearestSyncSampleIndex +---------------------------------------------------------------------*/ AP4_Ordinal -AP4_FragmentSampleTable::GetNearestSyncSampleIndex(AP4_Ordinal /*sample_index*/, bool /*before*/) +AP4_FragmentSampleTable::GetNearestSyncSampleIndex(AP4_Ordinal sample_index, bool before) { - return 0; // TODO + if (sample_index >= m_Samples.ItemCount()) + return sample_index; + + AP4_Ordinal end(before ? 0 : m_Samples.ItemCount()); + + while (sample_index != end && !m_Samples[sample_index].IsSync()) + sample_index = sample_index + (before ? -1 : 1); + + return sample_index; } -- 2.30.2