Skip to content

Commit

Permalink
CHG: [droid;vsync] use vblank event for videosync
Browse files Browse the repository at this point in the history
  • Loading branch information
koying committed Jun 20, 2017
1 parent 9734a20 commit b37df59
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
14 changes: 0 additions & 14 deletions xbmc/platform/android/activity/XBMCApp.cpp
Expand Up @@ -116,7 +116,6 @@ IInputDeviceCallbacks* CXBMCApp::m_inputDeviceCallbacks = nullptr;
IInputDeviceEventHandler* CXBMCApp::m_inputDeviceEventHandler = nullptr;
CCriticalSection CXBMCApp::m_applicationsMutex;
std::vector<androidPackage> CXBMCApp::m_applications;
CVideoSyncAndroid* CXBMCApp::m_syncImpl = NULL;
CEvent CXBMCApp::m_vsyncEvent;
std::vector<CActivityResultEvent*> CXBMCApp::m_activityResultEvents;
std::vector<GLuint> CXBMCApp::m_texturePool;
Expand Down Expand Up @@ -985,21 +984,8 @@ void CXBMCApp::onAudioFocusChange(int focusChange)
}
}

void CXBMCApp::InitFrameCallback(CVideoSyncAndroid* syncImpl)
{
m_syncImpl = syncImpl;
}

void CXBMCApp::DeinitFrameCallback()
{
m_syncImpl = NULL;
}

void CXBMCApp::doFrame(int64_t frameTimeNanos)
{
if (m_syncImpl)
m_syncImpl->FrameCallback(frameTimeNanos);

m_vsyncEvent.Set();
}

Expand Down
4 changes: 0 additions & 4 deletions xbmc/platform/android/activity/XBMCApp.h
Expand Up @@ -186,9 +186,6 @@ class CXBMCApp
static void UnregisterInputDeviceEventHandler();
static bool onInputDeviceEvent(const AInputEvent* event);

static void InitFrameCallback(CVideoSyncAndroid *syncImpl);
static void DeinitFrameCallback();

static bool WaitVSync(unsigned int milliSeconds);

bool getVideosurfaceInUse();
Expand Down Expand Up @@ -232,7 +229,6 @@ class CXBMCApp
static CEvent m_windowCreated;
static std::vector<GLuint> m_texturePool;

static CVideoSyncAndroid* m_syncImpl;
static CEvent m_vsyncEvent;

bool XBMC_DestroyDisplay();
Expand Down
35 changes: 27 additions & 8 deletions xbmc/video/videosync/VideoSyncAndroid.cpp
Expand Up @@ -35,30 +35,49 @@
bool CVideoSyncAndroid::Setup(PUPDATECLOCK func)
{
CLog::Log(LOGDEBUG, "CVideoSyncAndroid::%s setting up", __FUNCTION__);

//init the vblank timestamp
m_LastVBlankTime = CurrentHostCounter();
UpdateClock = func;
m_abort = false;

CXBMCApp::InitFrameCallback(this);
g_Windowing.Register(this);

return true;
}

void CVideoSyncAndroid::Run(std::atomic<bool>& stop)
{
while(!stop && !m_abort)
int NrVBlanks;
double VBlankTime;
int64_t nowtime = CurrentHostCounter();
int64_t lastSync = 0;

while (!stop && !m_abort)
{
Sleep(100);
if (!CXBMCApp::WaitVSync(1000))
{
CLog::Log(LOGERROR, "CVideoSyncAndroid: timeout waiting for sync");
return;
}

nowtime = CurrentHostCounter();

//calculate how many vblanks happened
int64_t FT = (nowtime - lastSync);
VBlankTime = FT / (double)g_VideoReferenceClock.GetFrequency();
NrVBlanks = MathUtils::round_int(VBlankTime * m_fps);

if (NrVBlanks > 1)
CLog::Log(LOGDEBUG, "CVideoSyncAndroid::FrameCallback late: %lld(%f fps), %d", FT, 1.0/((double)FT/1000000000), NrVBlanks);

//save the timestamp of this vblank so we can calculate how many happened next time
lastSync = nowtime;

//update the vblank timestamp, update the clock and send a signal that we got a vblank
UpdateClock(NrVBlanks, nowtime);
}
}

void CVideoSyncAndroid::Cleanup()
{
CLog::Log(LOGDEBUG, "CVideoSyncAndroid::%s cleaning up", __FUNCTION__);
CXBMCApp::DeinitFrameCallback();
g_Windowing.Unregister(this);
}

Expand Down

0 comments on commit b37df59

Please sign in to comment.