Skip to content

Commit

Permalink
Merge pull request xbmc#13696 from Razzeee/add-onavchanged-to-python-api
Browse files Browse the repository at this point in the history
Expose OnAVChange and OnAVStarted to python api
  • Loading branch information
razzeee authored Mar 30, 2018
2 parents 59c7bc9 + fb50ae8 commit 5141e05
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 2 deletions.
14 changes: 14 additions & 0 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3478,12 +3478,16 @@ void CApplication::OnPlayBackSeekChapter(int iChapter)

void CApplication::OnAVStarted(const CFileItem &file)
{
CLog::LogF(LOGDEBUG, "CApplication::OnAVStarted");

CGUIMessage msg(GUI_MSG_PLAYBACK_AVSTARTED, 0, 0);
g_windowManager.SendThreadMessage(msg);
}

void CApplication::OnAVChange()
{
CLog::LogF(LOGDEBUG, "CApplication::OnAVChange");

CStereoscopicsManager::GetInstance().OnStreamChange();

CGUIMessage msg(GUI_MSG_PLAYBACK_AVCHANGE, 0, 0);
Expand Down Expand Up @@ -4079,9 +4083,19 @@ bool CApplication::OnMessage(CGUIMessage& message)

case GUI_MSG_PLAYBACK_AVSTARTED:
m_playerEvent.Set();
#ifdef HAS_PYTHON
// informs python script currently running playback has started
// (does nothing if python is not loaded)
g_pythonParser.OnAVStarted(*m_itemCurrentFile);
#endif
return true;

case GUI_MSG_PLAYBACK_AVCHANGE:
#ifdef HAS_PYTHON
// informs python script currently running playback has started
// (does nothing if python is not loaded)
g_pythonParser.OnAVChange();
#endif
return true;

case GUI_MSG_PLAYBACK_ERROR:
Expand Down
30 changes: 29 additions & 1 deletion xbmc/interfaces/legacy/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,26 @@ namespace XBMCAddon

void Player::OnPlayBackStarted(const CFileItem &file)
{
// We only have fileItem due to us having to
// implement the interface, we can't send it to python
// as we're not able to serialize it.
XBMC_TRACE;
invokeCallback(new CallbackFunction<Player>(this,&Player::onPlayBackStarted));
invokeCallback(new CallbackFunction<Player>(this, &Player::onPlayBackStarted));
}

void Player::OnAVStarted(const CFileItem &file)
{
// We only have fileItem due to us having to
// implement the interface, we can't send it to python
// as we're not able to serialize it.
XBMC_TRACE;
invokeCallback(new CallbackFunction<Player>(this, &Player::onAVStarted));
}

void Player::OnAVChange()
{
XBMC_TRACE;
invokeCallback(new CallbackFunction<Player>(this, &Player::onAVChange));
}

void Player::OnPlayBackEnded()
Expand Down Expand Up @@ -251,6 +269,16 @@ namespace XBMCAddon
XBMC_TRACE;
}

void Player::onAVStarted()
{
XBMC_TRACE;
}

void Player::onAVChange()
{
XBMC_TRACE;
}

void Player::onPlayBackEnded()
{
XBMC_TRACE;
Expand Down
34 changes: 33 additions & 1 deletion xbmc/interfaces/legacy/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,43 @@ namespace XBMCAddon
///-----------------------------------------------------------------------
/// onPlayBackStarted method.
///
/// Will be called when Kodi starts playing a file.
/// Will be called when Kodi starts playing a file. Video or audio might not be available at this point.
///
onPlayBackStarted();
#else
virtual void onPlayBackStarted();
#endif


#ifdef DOXYGEN_SHOULD_USE_THIS
///
/// \ingroup python_PlayerCB
/// @brief \python_func{ onAVStarted() }
///-----------------------------------------------------------------------
/// onAVStarted method.
///
/// Will be called when Kodi has a video- or audiostream.
///
onAVStarted();
#else
virtual void onAVStarted();
#endif


#ifdef DOXYGEN_SHOULD_USE_THIS
///
/// \ingroup python_PlayerCB
/// @brief \python_func{ onAVChange() }
///-----------------------------------------------------------------------
/// onAVChange method.
///
/// Will be called when Kodi has a video- or audiostream. Also happens when the stream changes.
///
onAVChange();
#else
virtual void onAVChange();
#endif

#ifdef DOXYGEN_SHOULD_USE_THIS
///
/// \ingroup python_PlayerCB
Expand Down Expand Up @@ -758,6 +788,8 @@ namespace XBMCAddon

#if !defined SWIG && !defined DOXYGEN_SHOULD_SKIP_THIS
SWIGHIDDENVIRTUAL void OnPlayBackStarted(const CFileItem &file) override;
SWIGHIDDENVIRTUAL void OnAVStarted(const CFileItem &file) override;
SWIGHIDDENVIRTUAL void OnAVChange() override;
SWIGHIDDENVIRTUAL void OnPlayBackEnded() override;
SWIGHIDDENVIRTUAL void OnPlayBackStopped() override;
SWIGHIDDENVIRTUAL void OnPlayBackError() override;
Expand Down
24 changes: 24 additions & 0 deletions xbmc/interfaces/python/XBPython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,30 @@ void XBPython::OnPlayBackStarted(const CFileItem &file)
}
}

// message all registered callbacks that we changed stream
void XBPython::OnAVStarted(const CFileItem &file)
{
XBMC_TRACE;
LOCK_AND_COPY(std::vector<void*>, tmp, m_vecPlayerCallbackList);
for (PlayerCallbackList::iterator it = tmp.begin(); (it != tmp.end()); ++it)
{
if (CHECK_FOR_ENTRY(m_vecPlayerCallbackList, (*it)))
((IPlayerCallback*)(*it))->OnAVStarted(file);
}
}

// message all registered callbacks that we changed stream
void XBPython::OnAVChange()
{
XBMC_TRACE;
LOCK_AND_COPY(std::vector<void*>, tmp, m_vecPlayerCallbackList);
for (PlayerCallbackList::iterator it = tmp.begin(); (it != tmp.end()); ++it)
{
if (CHECK_FOR_ENTRY(m_vecPlayerCallbackList, (*it)))
((IPlayerCallback*)(*it))->OnAVChange();
}
}

// message all registered callbacks that we paused playing
void XBPython::OnPlayBackPaused()
{
Expand Down
2 changes: 2 additions & 0 deletions xbmc/interfaces/python/XBPython.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class XBPython :
~XBPython() override;
void OnPlayBackEnded() override;
void OnPlayBackStarted(const CFileItem &file) override;
void OnAVStarted(const CFileItem &file) override;
void OnAVChange() override;
void OnPlayBackPaused() override;
void OnPlayBackResumed() override;
void OnPlayBackStopped() override;
Expand Down

0 comments on commit 5141e05

Please # to comment.