Fix NPE if no compatible capture format was found

Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int org.webrtc.CameraEnumerationAndroid$CaptureFormat.width' on a null object reference
       at org.webrtc.Camera2Session$CameraStateCallback.onOpened(Camera2Session.java:122)
       at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:151)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:246)
       at android.os.HandlerThread.run(HandlerThread.java:67)


Fix NPE when setting the camera2 stabilization mode

Fatal Exception: java.lang.NullPointerException: Attempt to get length of null array
       at org.webrtc.Camera2Session$CaptureSessionCallback.chooseStabilizationMode(Camera2Session.java:234)
       at org.webrtc.Camera2Session$CaptureSessionCallback.onConfigured(Camera2Session.java:172)
       at android.hardware.camera2.impl.CallbackProxies$SessionStateCallbackProxy.lambda$onConfigured$0(CallbackProxies.java:53)
       at android.hardware.camera2.impl.-$$Lambda$CallbackProxies$SessionStateCallbackProxy$soW0qC12Osypoky6AfL3P2-TeDw.run(-.java:4)
       at android.os.Handler.handleCallback(Handler.java:873)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:193)
       at android.os.HandlerThread.run(HandlerThread.java:65)

Bug: webrtc:13032
Change-Id: I6edd9f0061c445f90ab0881d78183077f89e391f
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227294
Reviewed-by: Xavier Lepaul‎ <xalep@webrtc.org>
Commit-Queue: Xavier Lepaul‎ <xalep@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#34851}
diff --git a/sdk/android/src/java/org/webrtc/Camera2Session.java b/sdk/android/src/java/org/webrtc/Camera2Session.java
index 63eabe9..1b96339 100644
--- a/sdk/android/src/java/org/webrtc/Camera2Session.java
+++ b/sdk/android/src/java/org/webrtc/Camera2Session.java
@@ -311,6 +311,12 @@
         == CameraMetadata.LENS_FACING_FRONT;
 
     findCaptureFormat();
+
+    if (captureFormat == null) {
+      // findCaptureFormat reports an error already.
+      return;
+    }
+
     openCamera();
   }