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

Commit 20eca0db authored by Vadim Caen's avatar Vadim Caen
Browse files

Expose camera open event to virtual camera owner

Introduce a new callback in VirtualCameraCallback to notify the owner of
the camera being opened by the client appliation.

Bug: 409241122
Bug: 371167033
Test: atest VirtualCameraTest
Flag: android.companion.virtualdevice.flags.virtual_camera_on_open
Change-Id: Ibfcf4ad68096376ecdf1a8549c5a2da50924a56b
parent 7a299db3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3633,6 +3633,7 @@ package android.companion.virtual.camera {
  }
  public interface VirtualCameraCallback {
    method @FlaggedApi("android.companion.virtualdevice.flags.virtual_camera_on_open") public default void onOpenCamera();
    method public default void onProcessCaptureRequest(int, long);
    method public void onStreamClosed(int);
    method public void onStreamConfigured(int, @NonNull android.view.Surface, @IntRange(from=1) int, @IntRange(from=1) int, int);
+14 −0
Original line number Diff line number Diff line
@@ -26,6 +26,20 @@ import android.view.Surface;
 */
interface IVirtualCameraCallback {

    /**
     * Called when the client application calls
     * {@link android.hardware.camera2.CameraManager#openCamera}. This is the earliest signal that
     * this camera will be used. At this point, no stream is opened yet, nor any configuration took
     * place. The owner of the virtual camera can use this as signal to prepare the camera and
     * reduce latency for when
     * {@link android.hardware.camera2.CameraDevice#createCaptureSession(SessionConfiguration)} is
     * called and before
     * {@link
     * android.hardware.camera2.CameraCaptureSession.StateCallback#onConfigured(CameraCaptureSession)}
     * is called.
     */
    oneway void onOpenCamera();

    /**
     * Called when one of the requested stream has been configured by the virtual camera service and
     * is ready to receive data onto its {@link Surface}
+22 −0
Original line number Diff line number Diff line
@@ -16,10 +16,14 @@

package android.companion.virtual.camera;

import android.annotation.FlaggedApi;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.companion.virtualdevice.flags.Flags;
import android.graphics.ImageFormat;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.params.SessionConfiguration;
import android.view.Surface;

import java.util.concurrent.Executor;
@@ -34,9 +38,27 @@ import java.util.concurrent.Executor;
@SystemApi
public interface VirtualCameraCallback {

    /**
     * Called when the client application calls
     * {@link android.hardware.camera2.CameraManager#openCamera}. This is the earliest signal that
     * this camera will be used. At this point, no stream is opened yet, nor any configuration took
     * place. The owner of the virtual camera can use this as signal to prepare the camera and
     * reduce latency for when
     * {@link android.hardware.camera2.CameraDevice#createCaptureSession(SessionConfiguration)} is
     * called and before
     * {@link CameraCaptureSession.StateCallback#onConfigured(CameraCaptureSession)}
     * is called.
     */
    @FlaggedApi(Flags.FLAG_VIRTUAL_CAMERA_ON_OPEN)
    default void onOpenCamera() {
    }

    /**
     * Called when one of the requested stream has been configured by the virtual camera service and
     * is ready to receive data onto its {@link Surface}
     * <p>
     * This corresponds to the client calling
     * {@link android.hardware.camera2.CameraDevice#createCaptureSession(SessionConfiguration)}
     *
     * @param streamId The id of the configured stream
     * @param surface The surface to write data into for this stream
+6 −0
Original line number Diff line number Diff line
@@ -351,6 +351,12 @@ public final class VirtualCameraConfig implements Parcelable {
            mExecutor = executor;
        }

        public void onOpenCamera() {
            if (Flags.virtualCameraOnOpen()) {
                mExecutor.execute(mCallback::onOpenCamera);
            }
        }

        @Override
        public void onStreamConfigured(int streamId, Surface surface, int width, int height,
                int format) {
+10 −1
Original line number Diff line number Diff line
@@ -187,3 +187,12 @@ flag {
    description: "Enable VDM access for computer control"
    bug: "410570802"
}

flag {
    name: "virtual_camera_on_open"
    namespace: "virtual_devices"
    description: "Callback called when the virtual camera device is requested to be opened"
    bug: "409241122"
    is_exported: true
}
Loading