Skip to content

Commit

Permalink
fix frameAvalible
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Mar 1, 2024
1 parent e07de10 commit 23aacf9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
Expand Up @@ -43,6 +43,7 @@ import java.util.concurrent.Semaphore
class GlStreamInterface(private val context: Context) : Runnable, OnFrameAvailableListener, GlInterface {

private var thread: Thread? = null
@Volatile
private var frameAvailable = false
private var takePhotoCallback: TakePhotoCallback? = null
var running = false
Expand Down Expand Up @@ -215,7 +216,7 @@ class GlStreamInterface(private val context: Context) : Runnable, OnFrameAvailab
}
synchronized(sync) {
val sleep = fpsLimiter.sleepTime
if (sleep > 0) sync.wait(sleep)
if (sleep > 0 && !frameAvailable) sync.wait(sleep)
}
}
} catch (ignore: InterruptedException) {
Expand All @@ -229,8 +230,8 @@ class GlStreamInterface(private val context: Context) : Runnable, OnFrameAvailab
}

override fun onFrameAvailable(surfaceTexture: SurfaceTexture?) {
frameAvailable = true
synchronized(sync) {
frameAvailable = true
sync.notifyAll()
}
}
Expand Down
Expand Up @@ -119,7 +119,7 @@ public void run() {
}
synchronized (sync) {
long sleep = fpsLimiter.getSleepTime();
if (sleep > 0) sync.wait(sleep);
if (sleep > 0 && !frameAvailable) sync.wait(sleep);
}
}
} catch (InterruptedException ignore) {
Expand Down
Expand Up @@ -47,7 +47,7 @@ public class OffScreenGlThread

private final Context context;
private Thread thread = null;
private boolean frameAvailable = false;
private volatile boolean frameAvailable = false;
private boolean running = true;
private final SurfaceManager surfaceManagerPhoto = new SurfaceManager();
private final SurfaceManager surfaceManager = new SurfaceManager();
Expand Down Expand Up @@ -301,7 +301,7 @@ public void run() {
}
synchronized (sync) {
long sleep = fpsLimiter.getSleepTime();
if (sleep > 0) sync.wait(sleep);
if (sleep > 0 && !frameAvailable) sync.wait(sleep);
}
}
} catch (InterruptedException ignore) {
Expand All @@ -316,8 +316,8 @@ public void run() {

@Override
public void onFrameAvailable(SurfaceTexture surfaceTexture) {
frameAvailable = true;
synchronized (sync) {
frameAvailable = true;
sync.notifyAll();
}
}
Expand Down
Expand Up @@ -194,7 +194,7 @@ public void run() {
}
synchronized (sync) {
long sleep = fpsLimiter.getSleepTime();
if (sleep > 0) sync.wait(sleep);
if (sleep > 0 && !frameAvailable) sync.wait(sleep);
}
}
} catch (InterruptedException ignore) {
Expand Down
Expand Up @@ -48,7 +48,7 @@ public abstract class OpenGlViewBase extends SurfaceView
public final static String TAG = "OpenGlViewBase";

protected Thread thread = null;
protected boolean frameAvailable = false;
protected volatile boolean frameAvailable = false;
protected boolean running = false;
protected final SurfaceManager surfaceManagerPhoto = new SurfaceManager();
protected final SurfaceManager surfaceManager = new SurfaceManager();
Expand Down Expand Up @@ -200,8 +200,8 @@ public void stop() {

@Override
public void onFrameAvailable(SurfaceTexture surfaceTexture) {
frameAvailable = true;
synchronized (sync) {
frameAvailable = true;
sync.notifyAll();
}
}
Expand Down

0 comments on commit 23aacf9

Please sign in to comment.