Skip to content

Commit

Permalink
[Players][EDL] Use single direction enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
enen92 committed Jun 22, 2024
1 parent 579236d commit 6c51ece
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 41 deletions.
4 changes: 2 additions & 2 deletions xbmc/SeekHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ bool CSeekHandler::OnAction(const CAction &action)
}
case ACTION_NEXT_SCENE:
{
appPlayer->SeekScene(PlayerSeekDirection::FORWARD);
appPlayer->SeekScene(Direction::FORWARD);
return true;
}
case ACTION_PREV_SCENE:
{
appPlayer->SeekScene(PlayerSeekDirection::BACKWARD);
appPlayer->SeekScene(Direction::BACKWARD);
return true;
}
case ACTION_ANALOG_SEEK_FORWARD:
Expand Down
2 changes: 1 addition & 1 deletion xbmc/application/ApplicationPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ bool CApplicationPlayer::CanSeek() const
return (player && player->CanSeek());
}

bool CApplicationPlayer::SeekScene(PlayerSeekDirection seekDirection)
bool CApplicationPlayer::SeekScene(Direction seekDirection)
{
std::shared_ptr<IPlayer> player = GetInternal();
return (player && player->SeekScene(seekDirection));
Expand Down
2 changes: 1 addition & 1 deletion xbmc/application/ApplicationPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class CApplicationPlayer : public IApplicationComponent
void Seek(bool bPlus = true, bool bLargeStep = false, bool bChapterOverride = false);
int SeekChapter(int iChapter);
void SeekPercentage(float fPercent = 0);
bool SeekScene(PlayerSeekDirection seekDirection);
bool SeekScene(Direction seekDirection);
void SeekTime(int64_t iTime = 0);
void SeekTimeRelative(int64_t iTime = 0);
void SetAudioStream(int iStream);
Expand Down
18 changes: 18 additions & 0 deletions xbmc/cores/Direction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (C) 2024 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/

#pragma once

/*!
* @brief Specifies/Abstracts a direction
*/
enum class Direction : bool
{
FORWARD, /*!< Forward */
BACKWARD /*!< Backward */
};
9 changes: 0 additions & 9 deletions xbmc/cores/EdlEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,4 @@ struct Edit
Action action = Action::CUT;
};

/*!
* @brief Specify the search direction for an EDL edit
*/
enum class EditDirection
{
FORWARD, /*!< Search forward */
BACKWARD /*!< Search backwards */
};

} // namespace EDL
12 changes: 2 additions & 10 deletions xbmc/cores/IPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma once

#include "Direction.h"
#include "IPlayerCallback.h"
#include "Interface/StreamInfo.h"
#include "MenuType.h"
Expand Down Expand Up @@ -84,15 +85,6 @@ enum ERENDERFEATURE
RENDERFEATURE_TONEMAP
};

/*!
* @brief Specify the Seek Direction
*/
enum class PlayerSeekDirection
{
FORWARD, /*!< Seek forward */
BACKWARD /*!< Seek backwards */
};

class IPlayer
{
public:
Expand All @@ -114,7 +106,7 @@ class IPlayer
virtual bool IsPassthrough() const { return false;}
virtual bool CanSeek() const { return true; }
virtual void Seek(bool bPlus = true, bool bLargeStep = false, bool bChapterOverride = false) = 0;
virtual bool SeekScene(PlayerSeekDirection seekDirection) { return false; }
virtual bool SeekScene(Direction seekDirection) { return false; }
virtual void SeekPercentage(float fPercent = 0){}
virtual float GetCachePercentage() const { return 0; }
virtual void SetMute(bool bOnOff){}
Expand Down
6 changes: 3 additions & 3 deletions xbmc/cores/VideoPlayer/Edl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ EDL::Action CEdl::GetLastEditActionType() const
return m_lastEditActionType;
}

bool CEdl::GetNextSceneMarker(EDL::EditDirection direction, int clock, int* sceneMarker)
bool CEdl::GetNextSceneMarker(Direction direction, int clock, int* sceneMarker)
{
if (!HasSceneMarker())
return false;
Expand All @@ -894,7 +894,7 @@ bool CEdl::GetNextSceneMarker(EDL::EditDirection direction, int clock, int* scen
int diff = 10 * 60 * 60 * 1000; // 10 hours to ms.
bool found = false;

if (direction == EDL::EditDirection::FORWARD) // Find closest scene forwards
if (direction == Direction::FORWARD) // Find closest scene forwards
{
for (int i = 0; i < (int)m_vecSceneMarkers.size(); i++)
{
Expand All @@ -906,7 +906,7 @@ bool CEdl::GetNextSceneMarker(EDL::EditDirection direction, int clock, int* scen
}
}
}
else if (direction == EDL::EditDirection::BACKWARD) // Find closest scene backwards
else if (direction == Direction::BACKWARD) // Find closest scene backwards
{
for (int i = 0; i < (int)m_vecSceneMarkers.size(); i++)
{
Expand Down
3 changes: 2 additions & 1 deletion xbmc/cores/VideoPlayer/Edl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#pragma once

#include "cores/Direction.h"
#include "cores/EdlEdit.h"

#include <string>
Expand Down Expand Up @@ -141,7 +142,7 @@ class CEdl
*/
EDL::Action GetLastEditActionType() const;

bool GetNextSceneMarker(EDL::EditDirection direction, int clock, int* sceneMarker);
bool GetNextSceneMarker(Direction direction, int clock, int* sceneMarker);

static std::string MillisecondsToTimeString(int milliSeconds);

Expand Down
15 changes: 6 additions & 9 deletions xbmc/cores/VideoPlayer/VideoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3254,7 +3254,7 @@ void CVideoPlayer::Seek(bool bPlus, bool bLargeStep, bool bChapterOverride)
m_callback.OnPlayBackSeek(seekTarget, seekTarget - time);
}

bool CVideoPlayer::SeekScene(PlayerSeekDirection seekDirection)
bool CVideoPlayer::SeekScene(Direction seekDirection)
{
if (!m_Edl.HasSceneMarker())
return false;
Expand All @@ -3264,21 +3264,18 @@ bool CVideoPlayer::SeekScene(PlayerSeekDirection seekDirection)
* grace period applied it is impossible to go backwards past a scene marker.
*/
int64_t clock = GetTime();
if (seekDirection == PlayerSeekDirection::BACKWARD && clock > 5 * 1000) // 5 seconds
if (seekDirection == Direction::BACKWARD && clock > 5 * 1000) // 5 seconds
clock -= 5 * 1000;

int iScenemarker;
if (m_Edl.GetNextSceneMarker(seekDirection == PlayerSeekDirection::FORWARD
? EDL::EditDirection::FORWARD
: EDL::EditDirection::BACKWARD,
clock, &iScenemarker))
if (m_Edl.GetNextSceneMarker(seekDirection, clock, &iScenemarker))
{
/*
* Seeking is flushed and inaccurate, just like Seek()
*/
CDVDMsgPlayerSeek::CMode mode;
mode.time = iScenemarker;
mode.backward = seekDirection == PlayerSeekDirection::BACKWARD;
mode.backward = seekDirection == Direction::BACKWARD;
mode.accurate = false;
mode.restore = false;
mode.trickplay = false;
Expand Down Expand Up @@ -4530,7 +4527,7 @@ bool CVideoPlayer::OnAction(const CAction &action)
m_processInfo->SeekFinished(0);
return true;
}
else if (SeekScene(PlayerSeekDirection::FORWARD))
else if (SeekScene(Direction::FORWARD))
return true;
else
break;
Expand All @@ -4541,7 +4538,7 @@ bool CVideoPlayer::OnAction(const CAction &action)
m_processInfo->SeekFinished(0);
return true;
}
else if (SeekScene(PlayerSeekDirection::BACKWARD))
else if (SeekScene(Direction::BACKWARD))
return true;
else
break;
Expand Down
2 changes: 1 addition & 1 deletion xbmc/cores/VideoPlayer/VideoPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class CVideoPlayer : public IPlayer, public CThread, public IVideoPlayer,
bool IsPassthrough() const override;
bool CanSeek() const override;
void Seek(bool bPlus, bool bLargeStep, bool bChapterOverride) override;
bool SeekScene(PlayerSeekDirection seekDirection) override;
bool SeekScene(Direction seekDirection) override;
void SeekPercentage(float iPercent) override;
float GetCachePercentage() const override;

Expand Down
8 changes: 4 additions & 4 deletions xbmc/cores/VideoPlayer/test/edl/TestEdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ TEST_F(TestEdl, TestParsingMplayerTimeBasedEDL)
// We should have a scenemarker at the commbreak start and another on commbreak end
int time;
// lets cycle to the next scenemarker if starting from 1 msec before the start (or end) of the commbreak
EXPECT_EQ(edl.GetNextSceneMarker(EDL::EditDirection::FORWARD, commbreak.start - 1, &time), true);
EXPECT_EQ(edl.GetNextSceneMarker(Direction::FORWARD, commbreak.start - 1, &time), true);
EXPECT_EQ(edl.GetTimeWithoutCuts(time), commbreak.start);
EXPECT_EQ(edl.GetNextSceneMarker(EDL::EditDirection::FORWARD, commbreak.end - 1, &time), true);
EXPECT_EQ(edl.GetNextSceneMarker(Direction::FORWARD, commbreak.end - 1, &time), true);
EXPECT_EQ(edl.GetTimeWithoutCuts(time), commbreak.end);
// same if we cycle backwards
EXPECT_EQ(edl.GetNextSceneMarker(EDL::EditDirection::BACKWARD, commbreak.start + 1, &time), true);
EXPECT_EQ(edl.GetNextSceneMarker(Direction::BACKWARD, commbreak.start + 1, &time), true);
EXPECT_EQ(edl.GetTimeWithoutCuts(time), commbreak.start);
EXPECT_EQ(edl.GetNextSceneMarker(EDL::EditDirection::BACKWARD, commbreak.end + 1, &time), true);
EXPECT_EQ(edl.GetNextSceneMarker(Direction::BACKWARD, commbreak.end + 1, &time), true);
EXPECT_EQ(edl.GetTimeWithoutCuts(time), 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)
Expand Down

0 comments on commit 6c51ece

Please sign in to comment.