Skip to content

Commit

Permalink
Added controls for Next item/Prev item in video playback with EDL
Browse files Browse the repository at this point in the history
(commercials) to go to the end of the next commercial block, or
prev to the beginning of the previous commercial block.
  • Loading branch information
terry authored and terry committed Jul 6, 2016
1 parent 76d92ca commit 35f3a77
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
45 changes: 45 additions & 0 deletions xbmc/cores/VideoPlayer/Edl.cpp
Expand Up @@ -840,6 +840,51 @@ bool CEdl::InCut(const int iSeek, Cut *pCut) const
return false;
}

bool CEdl::GetNearestCut(bool bPlus, const int iSeek, Cut *pCut) const
{
if (bPlus)
{
// Searching forwards
for (auto &cut : m_vecCuts)
{
if (iSeek >= cut.start && iSeek <= cut.end) // Inside cut.
{
if (pCut)
*pCut = cut;
return true;
}
else if (iSeek < cut.start) // before this cut
{
if (pCut)
*pCut = cut;
return true;
}
}
return false;
}
else
{
// Searching backwards
for (int i = (int)m_vecCuts.size() - 1; i >= 0; i--)
{
if (iSeek - 20000 >= m_vecCuts[i].start && iSeek <= m_vecCuts[i].end)
// Inside cut. We ignore if we're closer to 20 seconds inside
{
if (pCut)
*pCut = m_vecCuts[i];
return true;
}
else if (iSeek > m_vecCuts[i].end) // after this cut
{
if (pCut)
*pCut = m_vecCuts[i];
return true;
}
}
return false;
}
}

bool CEdl::GetNextSceneMarker(bool bPlus, const int iClock, int *iSceneMarker) const
{
if (!HasSceneMarker())
Expand Down
1 change: 1 addition & 0 deletions xbmc/cores/VideoPlayer/Edl.h
Expand Up @@ -54,6 +54,7 @@ class CEdl
int RestoreCutTime(int iClock) const;

bool InCut(int iSeek, Cut *pCut = NULL) const;
bool GetNearestCut(bool bPlus, const int iSeek, Cut *pCut) const;

bool GetNextSceneMarker(bool bPlus, const int iClock, int *iSceneMarker) const;

Expand Down
30 changes: 30 additions & 0 deletions xbmc/cores/VideoPlayer/VideoPlayer.cpp
Expand Up @@ -4357,6 +4357,18 @@ bool CVideoPlayer::OnAction(const CAction &action)
case ACTION_NEXT_ITEM:
case ACTION_CHANNEL_UP:
{
if (m_Edl.HasCut())
{
// If the clip has an EDL, we'll search through that instead of sending a CHANNEL message
int nNext = 0;
const int64_t clock = m_omxplayer_mode ? GetTime() : DVD_TIME_TO_MSEC(std::min(m_CurrentAudio.dts, m_CurrentVideo.dts) + m_offset_pts);
CEdl::Cut cut;
if (m_Edl.GetNearestCut(true, clock, &cut))
{
m_messenger.Put(new CDVDMsgPlayerSeek(cut.end + 1, false, true, false, true, false, true));
return true;
}
}
bool bPreview(action.GetID() == ACTION_MOVE_UP && // only up/down shows a preview, all others do switch
CSettings::GetInstance().GetBool(CSettings::SETTING_PVRPLAYBACK_CONFIRMCHANNELSWITCH));

Expand All @@ -4378,6 +4390,24 @@ bool CVideoPlayer::OnAction(const CAction &action)
case ACTION_PREV_ITEM:
case ACTION_CHANNEL_DOWN:
{
if (m_Edl.HasCut())
{
// If the clip has an EDL, we'll search through that instead of sending a CHANNEL message
int nNext = 0;
const int64_t clock = m_omxplayer_mode ? GetTime() : DVD_TIME_TO_MSEC(std::min(m_CurrentAudio.dts, m_CurrentVideo.dts) + m_offset_pts);
CEdl::Cut cut;
if (m_Edl.GetNearestCut(false, clock, &cut))
{
m_messenger.Put(new CDVDMsgPlayerSeek(cut.start - 1, true, true, false, true, false, true));
return true;
}
else
{
// Go back to beginning
m_messenger.Put(new CDVDMsgPlayerSeek(0, true, true, false, true, false, true));
return true;
}
}
bool bPreview(action.GetID() == ACTION_MOVE_DOWN && // only up/down shows a preview, all others do switch
CSettings::GetInstance().GetBool(CSettings::SETTING_PVRPLAYBACK_CONFIRMCHANNELSWITCH));

Expand Down

0 comments on commit 35f3a77

Please sign in to comment.