Skip to content

Commit

Permalink
Merge pull request #9179 from FernetMenta/comskip
Browse files Browse the repository at this point in the history
VideoPlayer fix comskip
  • Loading branch information
FernetMenta committed Feb 26, 2016
2 parents 0b65b2c + 74e839a commit 287179f
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 64 deletions.
1 change: 0 additions & 1 deletion xbmc/cores/VideoPlayer/DVDMessage.cpp
Expand Up @@ -82,7 +82,6 @@ bool CDVDMsgGeneralSynchronize::Wait(unsigned int milliseconds, unsigned int sou
}
if (timeout.IsTimePast())
{
CLog::Log(LOGERROR, "CDVDMsgGeneralSynchronize - timeout");
return false; /* request timeout, should be retried */
}
}
Expand Down
4 changes: 2 additions & 2 deletions xbmc/cores/VideoPlayer/VideoPlayer.cpp
Expand Up @@ -2256,7 +2256,7 @@ void CVideoPlayer::CheckAutoSceneSkip()
/*
* Seeking is NOT flushed so any content up to the demux point is retained when playing forwards.
*/
m_messenger.Put(new CDVDMsgPlayerSeek(seek, true, m_omxplayer_mode, true, false, true));
m_messenger.Put(new CDVDMsgPlayerSeek(seek, true, false, m_omxplayer_mode, true, false, true));
/*
* Seek doesn't always work reliably. Last physical seek time is recorded to prevent looping
* if there was an error with seeking and it landed somewhere unexpected, perhaps back in the
Expand All @@ -2274,7 +2274,7 @@ void CVideoPlayer::CheckAutoSceneSkip()
/*
* Seeking is NOT flushed so any content up to the demux point is retained when playing forwards.
*/
m_messenger.Put(new CDVDMsgPlayerSeek(cut.end + 1, true, m_omxplayer_mode, true, false, true));
m_messenger.Put(new CDVDMsgPlayerSeek(cut.end + 1, true, false, m_omxplayer_mode, true, false, true));
/*
* Each commercial break is only skipped once so poorly detected commercial breaks can be
* manually re-entered. Start and end are recorded to prevent looping and to allow seeking back
Expand Down
9 changes: 1 addition & 8 deletions xbmc/cores/VideoPlayer/VideoPlayerAudio.cpp
Expand Up @@ -209,11 +209,6 @@ void CVideoPlayerAudio::CloseStream(bool bWaitForBuffers)

void CVideoPlayerAudio::OnStartup()
{
m_decode.Release();

#ifdef TARGET_WINDOWS
CoInitializeEx(NULL, COINIT_MULTITHREADED);
#endif
}

void CVideoPlayerAudio::UpdatePlayerInfo()
Expand Down Expand Up @@ -317,7 +312,7 @@ void CVideoPlayerAudio::Process()
{
if (m_pAudioCodec)
m_pAudioCodec->Reset();
m_decode.Release();
m_syncState = IDVDStreamPlayer::SYNC_STARTING;
}
else if (pMsg->IsType(CDVDMsg::GENERAL_FLUSH))
{
Expand All @@ -334,8 +329,6 @@ void CVideoPlayerAudio::Process()

if (m_pAudioCodec)
m_pAudioCodec->Reset();

m_decode.Release();
}
else if (pMsg->IsType(CDVDMsg::GENERAL_EOF))
{
Expand Down
41 changes: 0 additions & 41 deletions xbmc/cores/VideoPlayer/VideoPlayerAudio.h
Expand Up @@ -94,47 +94,6 @@ class CVideoPlayerAudio : public CThread, public IDVDStreamPlayerAudio

double m_audioClock;

// data for audio decoding
struct PacketStatus
{
PacketStatus()
{
msg = NULL;
Release();
}

~PacketStatus()
{
Release();
}

CDVDMsgDemuxerPacket* msg;
uint8_t* data;
int size;
double dts;
double pts;

void Attach(CDVDMsgDemuxerPacket* msg2)
{
if(msg) msg->Release();
msg = msg2;
msg->Acquire();
DemuxPacket* p = msg->GetPacket();
data = p->pData;
size = p->iSize;
dts = p->dts;
pts = p->pts;
}
void Release()
{
if(msg) msg->Release();
msg = NULL;
data = NULL;
size = 0;
dts = DVD_NOPTS_VALUE;
}
} m_decode;

CDVDAudio m_dvdAudio; // audio output device
CDVDClock* m_pClock; // dvd master clock
CDVDAudioCodec* m_pAudioCodec; // audio codec
Expand Down
14 changes: 10 additions & 4 deletions xbmc/cores/VideoPlayer/VideoPlayerVideo.cpp
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 @@ -335,6 +337,7 @@ void CVideoPlayerVideo::Process()
m_picture.iFlags &= ~DVP_FLAG_ALLOCATED;
m_packets.clear();
m_droppingStats.Reset();
m_syncState = IDVDStreamPlayer::SYNC_STARTING;
}
else if (pMsg->IsType(CDVDMsg::GENERAL_FLUSH)) // private message sent by (CVideoPlayerVideo::Flush())
{
Expand Down Expand Up @@ -695,6 +698,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 +767,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 +935,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 +947,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 +960,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
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
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 @@ -1310,7 +1310,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
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
9 changes: 7 additions & 2 deletions xbmc/cores/omxplayer/OMXPlayerVideo.cpp
Expand Up @@ -166,7 +166,10 @@ void OMXPlayerVideo::CloseStream(bool bWaitForBuffers)
m_messageQueue.Abort();

if(IsRunning())
{
m_bAbortOutput = true;
StopThread();
}

m_messageQueue.End();

Expand Down Expand Up @@ -301,7 +304,8 @@ void OMXPlayerVideo::Output(double pts, bool bDropPacket)
if (m_nextOverlay != DVD_NOPTS_VALUE && media_pts != 0.0 && media_pts + preroll <= m_nextOverlay)
return;

int buffer = m_renderManager.WaitForBuffer(CThread::m_bStop);
m_bAbortOutput = false;
int buffer = m_renderManager.WaitForBuffer(m_bAbortOutput);
if (buffer < 0)
return;

Expand All @@ -313,7 +317,7 @@ void OMXPlayerVideo::Output(double pts, bool bDropPacket)
ProcessOverlays(media_pts + preroll);

time += m_av_clock->GetAbsoluteClock();
m_renderManager.FlipPage(CThread::m_bStop, time/DVD_TIME_BASE);
m_renderManager.FlipPage(m_bAbortOutput, time/DVD_TIME_BASE);
}

void OMXPlayerVideo::Process()
Expand Down Expand Up @@ -506,6 +510,7 @@ void OMXPlayerVideo::Flush(bool sync)
m_messageQueue.Flush();
m_messageQueue.Flush(CDVDMsg::GENERAL_EOF);
m_messageQueue.Put(new CDVDMsgBool(CDVDMsg::GENERAL_FLUSH, sync), 1);
m_bAbortOutput = true;
}

bool OMXPlayerVideo::OpenDecoder()
Expand Down
2 changes: 2 additions & 0 deletions xbmc/cores/omxplayer/OMXPlayerVideo.h
Expand Up @@ -36,6 +36,7 @@
#include "utils/BitstreamStats.h"
#include "linux/DllBCM.h"
#include "cores/VideoPlayer/VideoRenderers/RenderManager.h"
#include <atomic>

class OMXPlayerVideo : public CThread, public IDVDStreamPlayerVideo
{
Expand All @@ -57,6 +58,7 @@ class OMXPlayerVideo : public CThread, public IDVDStreamPlayerVideo
bool m_sync;
bool m_flush;
std::string m_codecname;
std::atomic_bool m_bAbortOutput;
double m_iSubtitleDelay;
bool m_bRenderSubs;
bool m_bAllowFullscreen;
Expand Down

0 comments on commit 287179f

Please sign in to comment.