Skip to content

Instantly share code, notes, and snippets.

@ruslo
Last active October 2, 2015 15:52
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/4be4a3e3381dd8488771 to your computer and use it in GitHub Desktop.
Save ruslo/4be4a3e3381dd8488771 to your computer and use it in GitHub Desktop.
Process camera frames in parallel manner
/**
* Callback from SurfaceTexture.OnFrameAvailableListener. Is called each time a new
* camera frame for the SurfaceTexture is available.
*/
@Override
public void onFrameAvailable(SurfaceTexture) {
synchronized (lock) {
frameAvailable = true;
lock.notify();
}
}
/**
* Thread run loop. Will run until terminate() is called.
*/
@Override
public void run() {
Log.i(TAG, "starting thread CameraProcThread");
while (running) {
synchronized (lock) {
lock.wait();
if (frameAvailable) {
processFrame();
frameAvailable = false;
}
}
}
Log.i(TAG, "stopped thread CameraProcThread");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment