chromium/media/capture/video/chromeos/mojom/cros_camera_service.mojom

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Next min version: 16

module cros.mojom;

import "components/chromeos_camera/common/jpeg_encode_accelerator.mojom";
import "components/chromeos_camera/common/mjpeg_decode_accelerator.mojom";
import "media/capture/video/chromeos/mojom/camera_common.mojom";
import "media/capture/video/chromeos/mojom/cros_camera_client.mojom";
import "media/capture/video/chromeos/mojom/effects_pipeline.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";

// CameraClientType indicates the type of a CameraHalClient.
// It should be kept in sync with the ChromeOSCameraClientType enum in
// tools/metrics/histograms/enums.xml in chromium.
[Extensible]
enum CameraClientType {
  UNKNOWN = 0,
  TESTING = 1,
  CHROME = 2,
  ANDROID = 3,
  PLUGINVM = 4,
  ASH_CHROME = 5,
  LACROS_CHROME = 6,
};

// CameraPrivacySwitchState indicates the state of the camera privacy switch.
// This can represent both software and hardware privacy switch statuses.
enum CameraPrivacySwitchState {
  // [HW] For devices which can only read the privacy switch status while the
  // camera is streaming, it is possible that the state of privacy switch is
  // currently unknown.
  // [SW] If the CrOS Camera Service is not reachable, UNKNOWN will be returned
  // as the result of GetCameraSWPrivacySwitchState.
  UNKNOWN = 0,

  // State when the privacy switch is on, which means the black frames will be
  // delivered when streaming.
  ON = 1,

  // State when the privacy switch is off, which means camera should stream
  // normally.
  OFF = 2,
};

// CameraAutoFramingState indicates the state of the camera autozoom feature.
// Note that this enum is saved into user prefs, so enum values should not be
// reordered, deleted or repurposed.
[Stable, Extensible]
enum CameraAutoFramingState {
  // Auto framing is disabled.
  [Default]
  OFF = 0,

  // Auto framing is enabled and set to single person mode.
  ON_SINGLE = 1,

  // Auto framing is enabled and set to multi people mode.
  ON_MULTI = 2,
};

// Interface called by CrosCameraService to notify Chrome of Kiosk Vision
// events. The data being transferred and the processes involved are trusted.
//
// Next method ID: 3
interface KioskVisionObserver {
  // Notifies the observer that a new detection has happened.
  OnFrameProcessed@0(KioskVisionDetection detection);

  // Notifies the observer that a track has completed. Emitted when a previously
  // detected person goes undetected long enough and the tracker forgets them.
  OnTrackCompleted@1(KioskVisionTrack track);

  // Notifies the observer that an error has happened.
  OnError@2(KioskVisionError error);
};

// Output detection of the Kiosk Vision graph.
struct KioskVisionDetection {
  // The timestamp in microseconds of this detection.
  int64 timestamp_in_us;
  // The persons detected.
  array<KioskVisionAppearance> appearances;
};

// A track is the full sequence of appearances of a given person.
struct KioskVisionTrack {
  // The ID of the person in this track.
  int32 person_id;
  // The timestamp in microseconds for when this track started.
  int64 start_timestamp_in_us;
  // The timestamp in microseconds for when this track ended.
  int64 end_timestamp_in_us;
  // The appearances in this track. Must be non-empty. All appearances must have
  // the same `person_id`. Appearances are sorted by `timestamp_in_us`.
  array<KioskVisionAppearance> appearances;
};

// An appearance represents one person in a detection set.
struct KioskVisionAppearance {
  // The timestamp in microseconds of this appearance.
  int64 timestamp_in_us;
  // The tracking ID of this person.
  int32 person_id;
  // The face detection of this person.  At least one of `body` and `face` must
  // be present.
  KioskVisionFaceDetection? face;
  // The detection of this person. At least one of `body` and `face` must be
  // present.
  KioskVisionBodyDetection? body;
};

// The face angles of a person detected.
struct KioskVisionFaceDetection {
  // The confidence level of this detection. Value in the [0,1] interval.
  double confidence;
  // The roll angle of this face in the [-180, 180] interval.
  float roll;
  // The pan angle of this face in the [-180, 180] interval.
  float pan;
  // The tilt angle of this face in the [-180, 180] interval.
  float tilt;
  // The bounding box of this face.
  KioskVisionBoundingBox box;
};

// The body description of a detected person.
struct KioskVisionBodyDetection {
  // The confidence level of this detection. Value in the [0,1] interval.
  double confidence;
  // The bounding box of this body.
  KioskVisionBoundingBox box;
};

// Describes the size and coordinates of a bounding box.
struct KioskVisionBoundingBox {
  // The x of the top-left point of the bounding box.
  int32 x;
  // The y of the top-left point of the bounding box.
  int32 y;
  // The width of the bounding box.
  int32 width;
  // The height of the bounding box.
  int32 height;
};

// Describes errors that may happen when running the Kiosk Vision feature.
[Extensible]
enum KioskVisionError {
  [Default] UNKNOWN = 0,
  // E.g. failed to open the shared library from the DLC path.
  DLC_ERROR = 1,
  // E.g. failed to start or run the ML model.
  MODEL_ERROR = 2,
};

// The CrOS camera HAL v3 Mojo dispatcher.  The dispatcher acts as a proxy and
// waits for the server and the clients to register.  There can only be one
// server registered, with multiple clients requesting connections to the
// server.  For each client, the dispatcher is responsible for creating a Mojo
// channel to the server and pass the established Mojo channel to the client in
// order to set up a Mojo channel between the client and the server.
//
// Next method ID: 8
// Deprecated method IDs: 0, 1, 2, 3, 4, 6, 7
interface CameraHalDispatcher {
  // A CameraHalClient calls RegisterClient to register itself with the
  // dispatcher. CameraHalDispatcher would authenticate the client with the
  // given |type| and |auth_token|.
  [MinVersion=4] RegisterClientWithToken@5(
      pending_remote<CameraHalClient> client,
      CameraClientType type,
      mojo_base.mojom.UnguessableToken auth_token) => (int32 result);
};

// CrosCameraServiceObserver is an interface for CrosCameraService to notify
// observers for any changes on the server side, for example when a
// CameraHalClient opens or closes a camera device.
//
// Next method ID: 5
interface CrosCameraServiceObserver {
  // Fired when a CameraHalClient opens or closes a camera device. When a
  // CameraHalClient loses mojo connection to CameraHalServer, CameraHalServer
  // would also use this to notify that cameras are closed (not being used).
  CameraDeviceActivityChange@0(int32 camera_id,
                               bool opened,
                               CameraClientType type);

  // Fired when the camera privacy switch status is changed. If the device has
  // such switch, this observer will get the notification.
  CameraPrivacySwitchStateChange@1(CameraPrivacySwitchState state,
                                   int32 camera_id);

  // Fired when the camera software privacy switch status is changed.
  CameraSWPrivacySwitchStateChange@2(CameraPrivacySwitchState state);

  // Fired when the camera effect is changed.
  [MinVersion=14] CameraEffectChange@3(EffectsConfig config);

  // Fired when the auto framing state is changed.
  [MinVersion=15] AutoFramingStateChange@4(CameraAutoFramingState state);
};

// A client can request the CrosCameraService service from Mojo Service Manager
// and get the camera module or set/get the camera states.
//
// Next method ID: 9
interface CrosCameraService {
  // A caller calls GetCameraModule to create a new Mojo channel to the camera
  // HAL v3 adapter.
  GetCameraModule@0(CameraClientType type)
                    => (pending_remote<CameraModule> camera_module_receiver);

  // Enable or disable tracing.
  SetTracingEnabled@1(bool enabled);

  // Enable or disable auto framing.
  SetAutoFramingState@2(CameraAutoFramingState state);

  // Get the current camera software privacy switch state.
  GetCameraSWPrivacySwitchState@3() => (CameraPrivacySwitchState state);

  // Enable or disable the camera software privacy switch.
  SetCameraSWPrivacySwitchState@4(CameraPrivacySwitchState state);

  // Get if the HAL supports auto framing.
  GetAutoFramingSupported@5() => (bool supported);

  // Turn ON/OFF and configure specified effect.
  SetCameraEffect@6(EffectsConfig config) => (SetEffectResult result);

  // Add an obersever which observes the event of the camera service.
  AddCrosCameraServiceObserver@7(
      pending_remote<CrosCameraServiceObserver> observer);

  // Start and observe Kiosk Vision detections. There is no separate "stop"
  // method. The feature should remain active for the lifetime of the
  // connection to the observer remote.
  StartKioskVisionDetection@8(
      string dlc_path, pending_remote<KioskVisionObserver> observer);
};