Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d84b6794 authored by Sahil Sonar's avatar Sahil Sonar 💬 Committed by Mohammed Althaf T
Browse files

camera2: Allow enabling high speed batching

   - setBatchSize() func expects the stream size to be 1 for HSR.
   - Conditionalise the checks to avoid altering behaviour of other devices.
   - Fixes: setBatchSize: change batch size from 8 to 8 dynamically is not supported
   - [0] https://gitlab.e.foundation/e/os/android_frameworks_av/-/blob/v1-t/services/camera/libcameraservice/device3/Camera3OutputStream.cpp#L1383



Signed-off-by: default avatarSahilSonar <sss.sonar2003@gmail.com>
parent f5d279f0
Loading
Loading
Loading
Loading
+33 −1
Original line number Diff line number Diff line
@@ -26,10 +26,13 @@ import android.hardware.camera2.CameraOfflineSession.CameraOfflineSessionCallbac
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.params.OutputConfiguration;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.hardware.camera2.params.HighSpeedVideoConfiguration;
import android.hardware.camera2.utils.SurfaceUtils;
import android.os.Handler;
import android.os.ConditionVariable;
import android.os.SystemProperties;
import android.util.Range;
import android.util.Size;
import android.util.Log;
import android.view.Surface;

@@ -118,7 +121,7 @@ public class CameraConstrainedHighSpeedCaptureSessionImpl
        }
        Log.v(TAG, "previewFps: " + previewFps);

        int requestListSize = fpsRange.getUpper() / previewFps;
        int requestListSize = getHighSpeedRequestListSize(fpsRange, outputSurfaces, previewFps);
        // If it's a preview, keep requestList size fixed = 1.
        if (fpsRange.getUpper() > fpsRange.getLower()) {
            requestListSize = 1;
@@ -203,6 +206,35 @@ public class CameraConstrainedHighSpeedCaptureSessionImpl
        return true;
    }

    private int getHighSpeedRequestListSize(Range<Integer> fpsRange, Collection<Surface> surfaces, int previewFps) {
        boolean enableHighSpeedBatching = SystemProperties.getBoolean("sys.camera.enable.hsbatch", false);
        int requestListSize = 0;

        for (Surface surface : surfaces) {

            if (SurfaceUtils.isSurfaceForHwVideoEncoder(surface)) {
                Size surfaceSize = SurfaceUtils.getSurfaceSize(surface);
                HighSpeedVideoConfiguration[] highSpeedVideoConfigurations =
                    mCharacteristics.get(CameraCharacteristics.CONTROL_AVAILABLE_HIGH_SPEED_VIDEO_CONFIGURATIONS);

                // Get the batchsize for matching FPS & video size
                for (HighSpeedVideoConfiguration config : highSpeedVideoConfigurations) {
                    if (config.getSize().equals(surfaceSize) && config.getFpsRange().equals(fpsRange)) {
                        requestListSize = config.getBatchSizeMax();
                        break;
                     }
                }
                break;
            }
        }

        if (!enableHighSpeedBatching || requestListSize == 0) {
            // If cant' find the matching batch size,  limit the preview to 30fps.
            requestListSize = fpsRange.getUpper() / previewFps;
        }
        return requestListSize;
    }

    @Override
    public CameraDevice getDevice() {
        return mSessionImpl.getDevice();