Skip to content

Commit

Permalink
fix(render): make sure video render be paused in background
Browse files Browse the repository at this point in the history
  • Loading branch information
skufly authored and pingkai committed Feb 28, 2020
1 parent 4bda5ba commit 1802dd5
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions framework/render/video/glRender/GLRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ GLRender::GLRender(float Hz)
mVSyncPeriod = static_cast<int64_t>(1000000 / Hz);
#if TARGET_OS_IPHONE
IOSNotificationManager::Instance()->RegisterObserver(this, 0);
mInBackground = IOSNotificationManager::Instance()->GetActiveStatus() == 0;
setenv("METAL_DEVICE_WRAPPER_TYPE", "0", 1);
// setenv("CG_CONTEXT_SHOW_BACKTRACE", "1", 1);
#endif
Expand All @@ -56,12 +57,13 @@ GLRender::~GLRender()
int GLRender::init()
{
AF_LOGD("-----> init .");
mVSync->start();
// std::unique_lock<std::mutex> locker(mInitMutex);
// mInitCondition.wait(locker, [this]() -> int {
// return mInitRet != INT32_MIN;
// });
// return mInitRet;
// don't auto start in background
std::unique_lock<std::mutex> locker(mInitMutex);

if (!mInBackground) {
mVSync->start();
}

return 0;
}

Expand Down Expand Up @@ -528,13 +530,15 @@ void GLRender::setSpeed(float speed)

void GLRender::AppWillResignActive()
{
std::unique_lock<std::mutex> locker(mInitMutex);
mInBackground = true;
AF_LOGE("0919, mInBackground = true");
mVSync->pause();
};

void GLRender::AppDidBecomeActive()
{
std::unique_lock<std::mutex> locker(mInitMutex);
mInBackground = false;
AF_LOGE("0919, mInBackground = false");
mVSync->start();
Expand Down

0 comments on commit 1802dd5

Please sign in to comment.