Skip to content

Commit

Permalink
VideoPlayer: make video abort faster on flush
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed Feb 21, 2016
1 parent 48fba41 commit 826c4ab
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
13 changes: 9 additions & 4 deletions xbmc/cores/VideoPlayer/VideoPlayerVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ CVideoPlayerVideo::CVideoPlayerVideo(CDVDClock* pClock

CVideoPlayerVideo::~CVideoPlayerVideo()
{
m_bAbortOutput = true;
StopThread();
g_VideoReferenceClock.Stop();
}
Expand Down Expand Up @@ -207,7 +208,8 @@ void CVideoPlayerVideo::CloseStream(bool bWaitForBuffers)
// wait for decode_video thread to end
CLog::Log(LOGNOTICE, "waiting for video thread to exit");

StopThread(); // will set this->m_bStop to true
m_bAbortOutput = true;
StopThread();

m_messageQueue.End();

Expand Down Expand Up @@ -695,6 +697,7 @@ void CVideoPlayerVideo::Flush(bool sync)
/* be disposed of before we flush */
m_messageQueue.Flush();
m_messageQueue.Put(new CDVDMsgBool(CDVDMsg::GENERAL_FLUSH, sync), 1);
m_bAbortOutput = true;
}

#ifdef HAS_VIDEO_PLAYBACK
Expand Down Expand Up @@ -763,6 +766,8 @@ std::string CVideoPlayerVideo::GetStereoMode()

int CVideoPlayerVideo::OutputPicture(const DVDVideoPicture* src, double pts)
{
m_bAbortOutput = false;

/* picture buffer is not allowed to be modified in this call */
DVDVideoPicture picture(*src);
DVDVideoPicture* pPicture = &picture;
Expand Down Expand Up @@ -929,7 +934,7 @@ int CVideoPlayerVideo::OutputPicture(const DVDVideoPicture* src, double pts)
// don't wait when going ff
if (m_speed > DVD_PLAYSPEED_NORMAL)
maxWaitTime = std::max(DVD_TIME_TO_MSEC(iSleepTime), 0);
int buffer = m_renderManager.WaitForBuffer(m_bStop, maxWaitTime);
int buffer = m_renderManager.WaitForBuffer(m_bAbortOutput, maxWaitTime);
if (buffer < 0)
{
m_droppingStats.AddOutputDropGain(pts, 1/m_fFrameRate);
Expand All @@ -941,7 +946,7 @@ int CVideoPlayerVideo::OutputPicture(const DVDVideoPicture* src, double pts)
int index = m_renderManager.AddVideoPicture(*pPicture);

// video device might not be done yet
while (index < 0 && !CThread::m_bStop &&
while (index < 0 && !m_bAbortOutput &&
CDVDClock::GetAbsoluteClock(false) < iCurrentClock + iSleepTime + DVD_MSEC_TO_TIME(500) )
{
Sleep(1);
Expand All @@ -954,7 +959,7 @@ int CVideoPlayerVideo::OutputPicture(const DVDVideoPicture* src, double pts)
return EOS_DROPPED;
}

m_renderManager.FlipPage(CThread::m_bStop, (iCurrentClock + iSleepTime) / DVD_TIME_BASE, pts_org, -1, mDisplayField);
m_renderManager.FlipPage(m_bAbortOutput, (iCurrentClock + iSleepTime) / DVD_TIME_BASE, pts_org, -1, mDisplayField);

return result;
}
Expand Down
4 changes: 2 additions & 2 deletions xbmc/cores/VideoPlayer/VideoPlayerVideo.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
#include "DVDClock.h"
#include "DVDOverlayContainer.h"
#include "DVDTSCorrection.h"
#ifdef HAS_VIDEO_PLAYBACK
#include "cores/VideoPlayer/VideoRenderers/RenderManager.h"
#endif
#include "utils/BitstreamStats.h"
#include <atomic>

class CDemuxStreamVideo;

Expand Down Expand Up @@ -147,6 +146,7 @@ class CVideoPlayerVideo : public CThread, public IDVDStreamPlayerVideo
bool m_stalled;
IDVDStreamPlayer::ESyncState m_syncState;
std::string m_codecname;
std::atomic_bool m_bAbortOutput;

BitstreamStats m_videoStats;

Expand Down
4 changes: 2 additions & 2 deletions xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ void CRenderManager::SetViewMode(int iViewMode)
m_playerPort->VideoParamsChange();
}

void CRenderManager::FlipPage(volatile bool& bStop, double timestamp /* = 0LL*/, double pts /* = 0 */, int source /*= -1*/, EFIELDSYNC sync /*= FS_NONE*/)
void CRenderManager::FlipPage(volatile std::atomic_bool& bStop, double timestamp /* = 0LL*/, double pts /* = 0 */, int source /*= -1*/, EFIELDSYNC sync /*= FS_NONE*/)
{
{ CSingleLock lock(m_statelock);

Expand Down Expand Up @@ -1315,7 +1315,7 @@ EINTERLACEMETHOD CRenderManager::AutoInterlaceMethodInternal(EINTERLACEMETHOD mI
return mInt;
}

int CRenderManager::WaitForBuffer(volatile bool& bStop, int timeout)
int CRenderManager::WaitForBuffer(volatile std::atomic_bool&bStop, int timeout)
{
CSingleLock lock(m_presentlock);

Expand Down
5 changes: 3 additions & 2 deletions xbmc/cores/VideoPlayer/VideoRenderers/RenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "OverlayRenderer.h"
#include <deque>
#include <map>
#include <atomic>
#include "PlatformDefs.h"
#include "threads/Event.h"
#include "DVDClock.h"
Expand Down Expand Up @@ -127,7 +128,7 @@ class CRenderManager
* @param source depreciated
* @param sync signals frame, top, or bottom field
*/
void FlipPage(volatile bool& bStop, double timestamp = 0.0, double pts = 0.0, int source = -1, EFIELDSYNC sync = FS_NONE);
void FlipPage(volatile std::atomic_bool& bStop, double timestamp = 0.0, double pts = 0.0, int source = -1, EFIELDSYNC sync = FS_NONE);

void AddOverlay(CDVDOverlay* o, double pts);

Expand All @@ -142,7 +143,7 @@ class CRenderManager
* If no buffering is requested in Configure, player does not need to call this,
* because FlipPage will block.
*/
int WaitForBuffer(volatile bool& bStop, int timeout = 100);
int WaitForBuffer(volatile std::atomic_bool& bStop, int timeout = 100);

/**
* Can be called by player for lateness detection. This is done best by
Expand Down

0 comments on commit 826c4ab

Please sign in to comment.