This question is targeted to high-speed video sessions, and not normal video sessions.
Currently in Android Camera2 API, to resolve the optimal preview size I use a target video output size as reference, and compute from it the best preview size by using the list of size choices returned by:
// SurfaceTexture.class to get the preview sizes supported by the surface
StreamConfigurationMap.getOutputSizes(SurfaceTexture.class);
The video output size is selected from the list returned by: StreamConfigurationMap.getHighSpeedVideoSizes();
The preview size computation is done by selecting the size from the SurfaceTexture.class list, with the same aspect ratio as the video output size, and within the 1920x0180 size constrain, which is the max preview size to be guaranteed by the camera2 API.
Said all that, when using createHighSpeedRequestList, this method will fail if it finds that any of the surfaces passed to the session doesn't have a size from the supported high-speed sizes, and this applies also to the preview surface. See the source in: android.hardware.camera2.utils.SurfaceUtils.checkConstrainedHighSpeedSurfaces
The question is, what is the optimal way to get a valid preview size for high-speed video sessions? I can’t rely in the list of choices returned by SurfaceTexture.class since these are unrelated to a high-speed session.
My best guess is that I should iterate through all of them and just find one that is within the list of high-speed sizes returned by StreamConfigurationMap.getHighSpeedVideoSizes, but I want to know if there is a more solid reliable way, or a good example which I could look at.
There is no need to call StreamConfigurationMap.getOutputSizes(SurfaceTexture.class) in your case. Any size in the list you get from StreamConfigurationMap.getHighSpeedVideoSizes() will satisfy the former condition. Note that if you choose some specific FPS, some sizes in the latter list may not be supported. Usually we prefer the largest of the available sizes, but if your requirements allow something smaller, go for it: this may significantly reduce battery consumption and improve device responsiveness.