Skip to content

Commit

Permalink
FIX: [droid;videosync] use actual vsync time
Browse files Browse the repository at this point in the history
  • Loading branch information
koying committed Jun 20, 2017
1 parent 2f80363 commit e8131b6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 2 additions & 0 deletions xbmc/platform/android/activity/XBMCApp.cpp
Expand Up @@ -116,6 +116,7 @@ IInputDeviceCallbacks* CXBMCApp::m_inputDeviceCallbacks = nullptr;
IInputDeviceEventHandler* CXBMCApp::m_inputDeviceEventHandler = nullptr;
CCriticalSection CXBMCApp::m_applicationsMutex;
std::vector<androidPackage> CXBMCApp::m_applications;
uint64_t CXBMCApp::m_vsynctime = 0;
CEvent CXBMCApp::m_vsyncEvent;
std::vector<CActivityResultEvent*> CXBMCApp::m_activityResultEvents;
std::vector<GLuint> CXBMCApp::m_texturePool;
Expand Down Expand Up @@ -986,6 +987,7 @@ void CXBMCApp::onAudioFocusChange(int focusChange)

void CXBMCApp::doFrame(int64_t frameTimeNanos)
{
m_vsynctime = frameTimeNanos;
m_vsyncEvent.Set();
}

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

static bool WaitVSync(unsigned int milliSeconds);
static uint64_t GetVsyncTime() { return m_vsynctime; }

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

static uint64_t m_vsynctime;
static CEvent m_vsyncEvent;

bool XBMC_DestroyDisplay();
Expand Down
22 changes: 11 additions & 11 deletions xbmc/video/videosync/VideoSyncAndroid.cpp
Expand Up @@ -56,23 +56,23 @@ void CVideoSyncAndroid::Run(std::atomic<bool>& stop)
CLog::Log(LOGERROR, "CVideoSyncAndroid: timeout waiting for sync");
return;
}

#if 0
int64_t nowtime = CurrentHostCounter();
uint64_t vsynctime = CXBMCApp::GetVsyncTime();

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

CLog::Log(LOGDEBUG, "CVideoSyncAndroid heartbeat: %lld(%f fps), %d", FT, 1.0/((double)FT/1000000000), NrVBlanks);
// CLog::Log(LOGDEBUG, "CVideoSyncAndroid heartbeat: %lld(%f fps), %f", FT, 1.0/((double)FT/1000000000), NrVBlanks);

//save the timestamp of this vblank so we can calculate how many happened next time
lastSync = nowtime;
#endif
int iNrVBlanks = MathUtils::round_int(NrVBlanks);
if (iNrVBlanks >= 1)
{
//save the timestamp of this vblank so we can calculate how many happened next time
lastSync = vsynctime;

uint64_t now = CurrentHostCounter();
UpdateClock(1, now);
UpdateClock(iNrVBlanks, vsynctime);
}
}
}

Expand Down

0 comments on commit e8131b6

Please sign in to comment.