Skip to content

Commit

Permalink
fix(Render): dont call updateTexImg() when frame not available, fix b…
Browse files Browse the repository at this point in the history
…lank screen
  • Loading branch information
I-m-SuperMan authored and pingkai committed Feb 13, 2020
1 parent 70041a1 commit 0007970
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
24 changes: 23 additions & 1 deletion framework/render/video/glRender/OESProgramContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//
#define LOG_TAG "GLRender_OESContext"

#include <utils/timer.h>
#include "OESProgramContext.h"

using namespace cicada;
Expand Down Expand Up @@ -131,7 +132,7 @@ void OESProgramContext::createDecoderSurface() {
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

mDecoderSurface = new DecoderSurface(nullptr);
mDecoderSurface = new DecoderSurface(this);
mDecoderSurface->Init(mOutTextureId, nullptr);
}

Expand Down Expand Up @@ -344,6 +345,22 @@ int OESProgramContext::updateFrame(std::unique_ptr<IAFFrame> &frame) {

frame = nullptr;

{
std::unique_lock<std::mutex> waitLock(mFrameAvailableMutex);
if (!mFrameAvailable) {
mFrameAvailableCon.wait_for(waitLock, std::chrono::milliseconds(10), [this]() {
return mFrameAvailable;
});
}

if (mFrameAvailable) {
mFrameAvailable = false;
} else {
AF_LOGW("frame not available after 10ms");
return -1;
}
}

if (mRegionChanged) {
AF_LOGD("0918, mRegionChanged");
updateDrawRegion();
Expand Down Expand Up @@ -396,3 +413,8 @@ int OESProgramContext::updateFrame(std::unique_ptr<IAFFrame> &frame) {

return 0;
}

void OESProgramContext::onFrameAvailable() {
std::unique_lock<std::mutex> lock(mFrameAvailableMutex);
mFrameAvailable = true;
}
7 changes: 6 additions & 1 deletion framework/render/video/glRender/OESProgramContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "platform/android/decoder_surface.h"
#include "GLRender.h"

class OESProgramContext : public IProgramContext {
class OESProgramContext : public IProgramContext , private DecoderSurfaceCallback{
public:
OESProgramContext();

Expand Down Expand Up @@ -37,6 +37,8 @@ class OESProgramContext : public IProgramContext {
void updateFlipCoords();

void updateDrawRegion();

void onFrameAvailable() override ;
private:

IVideoRender::Rotate mRotate = IVideoRender::Rotate_None;
Expand Down Expand Up @@ -72,6 +74,9 @@ class OESProgramContext : public IProgramContext {
bool mRegionChanged = false;
GLfloat mDrawRegion[12]={0.0f};

std::mutex mFrameAvailableMutex;
std::condition_variable mFrameAvailableCon;
bool mFrameAvailable = false;
};


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define LOG_TAG "DecoderSurface"

#include "decoder_surface.h"
#include <utils/Android/AndroidJniHandle.h>
Expand Down Expand Up @@ -208,7 +209,7 @@ namespace Cicada {

void DecoderSurface::onFrameAvailable()
{
// mCallback->onFrameAvailable();
mCallback->onFrameAvailable();
// UpdateTexImg();
}

Expand Down

0 comments on commit 0007970

Please sign in to comment.