googlearchive/android-Camera2Video

Unnecessary thread creation and leakage in Camera2VideoFragment.updatePreview()

Closed this issue · 2 comments

There seems to be an unintentionally created extra thread in Camera2VideoFragment.updatePreview():

/**
 * Update the camera preview. {@link #startPreview()} needs to be called in advance.
 */
private void updatePreview() {
    if (null == mCameraDevice) {
        return;
    }
    try {
        setUpCaptureRequestBuilder(mPreviewBuilder);
        HandlerThread thread = new HandlerThread("CameraPreview");
        thread.start();
        mPreviewSession.setRepeatingRequest(mPreviewBuilder.build(), null, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

Apparently, thread is local to the method and is never exported, thus it is completely unnecessary.
It seems that the writer of this code was going to use it to create the Handler passed to CameraCaptureSession.setRepeatingRequest(), but the later is already handled separately in startBackgroundThread().

Please, remove.

or another reason is that Preview must use a different thread, but the writer forget to use it?

This sample has been migrated to a new location (check README for more information).

As recommended by GitHub, we are closing all issues and pull requests now that this older repo will be archived.

If you still see this issue in the updated repo, please reopen the issue/PR there. Thank you!