Skip to content

Instantly share code, notes, and snippets.

@ruslo
Created October 2, 2015 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruslo/564dfa44e87ae3f32e84 to your computer and use it in GitHub Desktop.
Save ruslo/564dfa44e87ae3f32e84 to your computer and use it in GitHub Desktop.
/**
* Callback from SurfaceTexture.OnFrameAvailableListener. Is called each time a new
* camera frame for the SurfaceTexture is available.
*/
@Override
public void onFrameAvailable(SurfaceTexture) {
synchronized (lock) {
frameNotification = true;
lock.notify();
}
}
/**
* Thread run loop. Will run until terminate() is called.
*/
@Override
public void run() {
Log.i(TAG, "starting thread CameraProcThread");
while (running) {
boolean frameAvailable = false;
synchronized (lock) {
lock.wait();
if (frameNotification) {
// Do release lock as soon as possible so if one more
// call to onFrameAvailable occurs there will be no need
// to wait.
frameAvailable = true;
frameNotification = false;
}
}
if (frameAvailable) {
processFrame();
}
}
Log.i(TAG, "stopped thread CameraProcThread");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment