Skip to content

Commit

Permalink
[EDL] Move GetNextSceneMarker to std::optional
Browse files Browse the repository at this point in the history
  • Loading branch information
enen92 committed Jun 22, 2024
1 parent c27ff4b commit b872735
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
18 changes: 8 additions & 10 deletions xbmc/cores/VideoPlayer/Edl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,15 +884,15 @@ EDL::Action CEdl::GetLastEditActionType() const
return m_lastEditActionType;
}

bool CEdl::GetNextSceneMarker(Direction direction, int clock, int* sceneMarker)
std::optional<int> CEdl::GetNextSceneMarker(Direction direction, int clock)
{
if (!HasSceneMarker())
return false;
return std::nullopt;

std::optional<int> sceneMarker;
const int seekTime = GetTimeAfterRestoringCuts(clock);

int diff = 10 * 60 * 60 * 1000; // 10 hours to ms.
bool found = false;

if (direction == Direction::FORWARD) // Find closest scene forwards
{
Expand All @@ -901,8 +901,7 @@ bool CEdl::GetNextSceneMarker(Direction direction, int clock, int* sceneMarker)
if ((m_vecSceneMarkers[i] > seekTime) && ((m_vecSceneMarkers[i] - seekTime) < diff))
{
diff = m_vecSceneMarkers[i] - seekTime;
*sceneMarker = m_vecSceneMarkers[i];
found = true;
sceneMarker = m_vecSceneMarkers[i];
}
}
}
Expand All @@ -913,8 +912,7 @@ bool CEdl::GetNextSceneMarker(Direction direction, int clock, int* sceneMarker)
if ((m_vecSceneMarkers[i] < seekTime) && ((seekTime - m_vecSceneMarkers[i]) < diff))
{
diff = seekTime - m_vecSceneMarkers[i];
*sceneMarker = m_vecSceneMarkers[i];
found = true;
sceneMarker = m_vecSceneMarkers[i];
}
}
}
Expand All @@ -924,10 +922,10 @@ bool CEdl::GetNextSceneMarker(Direction direction, int clock, int* sceneMarker)
* picked up when scene markers are added.
*/
Edit edit;
if (found && InEdit(*sceneMarker, &edit) && edit.action == Action::CUT)
*sceneMarker = edit.end;
if (sceneMarker && InEdit(sceneMarker.value(), &edit) && edit.action == Action::CUT)
sceneMarker = edit.end;

return found;
return sceneMarker;
}

std::string CEdl::MillisecondsToTimeString(int milliSeconds)
Expand Down
9 changes: 8 additions & 1 deletion xbmc/cores/VideoPlayer/Edl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "cores/Direction.h"
#include "cores/EdlEdit.h"

#include <optional>
#include <string>
#include <vector>

Expand Down Expand Up @@ -142,7 +143,13 @@ class CEdl
*/
EDL::Action GetLastEditActionType() const;

bool GetNextSceneMarker(Direction direction, int clock, int* sceneMarker);
/*!
* @brief Get the next scene marker with respect to the provided clock time
* @param direction (the direction of the search - backward or forward)
* @param clock the current position of the clock
* @return the position of the scenemarker (nullopt if none)
*/
std::optional<int> GetNextSceneMarker(Direction direction, int clock);

static std::string MillisecondsToTimeString(int milliSeconds);

Expand Down
7 changes: 4 additions & 3 deletions xbmc/cores/VideoPlayer/VideoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3267,14 +3267,15 @@ bool CVideoPlayer::SeekScene(Direction seekDirection)
if (seekDirection == Direction::BACKWARD && clock > 5 * 1000) // 5 seconds
clock -= 5 * 1000;

int iScenemarker;
if (m_Edl.GetNextSceneMarker(seekDirection, clock, &iScenemarker))
const std::optional<int> sceneMarker =
m_Edl.GetNextSceneMarker(seekDirection, static_cast<int>(clock));
if (sceneMarker)
{
/*
* Seeking is flushed and inaccurate, just like Seek()
*/
CDVDMsgPlayerSeek::CMode mode;
mode.time = iScenemarker;
mode.time = sceneMarker.value();
mode.backward = seekDirection == Direction::BACKWARD;
mode.accurate = false;
mode.restore = false;
Expand Down
21 changes: 12 additions & 9 deletions xbmc/cores/VideoPlayer/test/edl/TestEdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,20 @@ TEST_F(TestEdl, TestParsingMplayerTimeBasedEDL)
const auto commbreak = edl.GetEditList().at(1);
EXPECT_EQ(commbreak.action, Action::COMM_BREAK);
// We should have a scenemarker at the commbreak start and another on commbreak end
int time;
std::optional<int> time = edl.GetNextSceneMarker(Direction::FORWARD, commbreak.start - 1);
// lets cycle to the next scenemarker if starting from 1 msec before the start (or end) of the commbreak
EXPECT_EQ(edl.GetNextSceneMarker(Direction::FORWARD, commbreak.start - 1, &time), true);
EXPECT_EQ(edl.GetTimeWithoutCuts(time), commbreak.start);
EXPECT_EQ(edl.GetNextSceneMarker(Direction::FORWARD, commbreak.end - 1, &time), true);
EXPECT_EQ(edl.GetTimeWithoutCuts(time), commbreak.end);
EXPECT_NE(time, std::nullopt);
EXPECT_EQ(edl.GetTimeWithoutCuts(time.value()), commbreak.start);
time = edl.GetNextSceneMarker(Direction::FORWARD, commbreak.end - 1);
EXPECT_NE(time, std::nullopt);
EXPECT_EQ(edl.GetTimeWithoutCuts(time.value()), commbreak.end);
// same if we cycle backwards
EXPECT_EQ(edl.GetNextSceneMarker(Direction::BACKWARD, commbreak.start + 1, &time), true);
EXPECT_EQ(edl.GetTimeWithoutCuts(time), commbreak.start);
EXPECT_EQ(edl.GetNextSceneMarker(Direction::BACKWARD, commbreak.end + 1, &time), true);
EXPECT_EQ(edl.GetTimeWithoutCuts(time), commbreak.end);
time = edl.GetNextSceneMarker(Direction::BACKWARD, commbreak.start + 1);
EXPECT_NE(time, std::nullopt);
EXPECT_EQ(edl.GetTimeWithoutCuts(time.value()), commbreak.start);
time = edl.GetNextSceneMarker(Direction::BACKWARD, commbreak.end + 1);
EXPECT_NE(time, std::nullopt);
EXPECT_EQ(edl.GetTimeWithoutCuts(time.value()), commbreak.end);
// We should be in an edit if we are in the middle of a commbreak...
// lets check and confirm the edits match (after restoring cuts)
Edit thisEdit;
Expand Down

0 comments on commit b872735

Please sign in to comment.