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

Commit 8e4d51a1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Expose timestamp source & thumbnail sizes characteristic" into main

parents 89588107 ad8d35f6
Loading
Loading
Loading
Loading
+5 −19
Original line number Diff line number Diff line
@@ -76,22 +76,6 @@ const std::array<PixelFormat, 3> kOutputFormats{
    PixelFormat::IMPLEMENTATION_DEFINED, PixelFormat::YCBCR_420_888,
    PixelFormat::BLOB};

struct Resolution {
  Resolution(const int w, const int h) : width(w), height(h) {
  }

  bool operator<(const Resolution& other) const {
    return width * height < other.width * other.height;
  }

  bool operator==(const Resolution& other) const {
    return width == other.width && height == other.height;
  }

  const int width;
  const int height;
};

bool isSupportedOutputFormat(const PixelFormat pixelFormat) {
  return std::find(kOutputFormats.begin(), kOutputFormats.end(), pixelFormat) !=
         kOutputFormats.end();
@@ -159,6 +143,7 @@ std::optional<CameraMetadata> initCameraCharacteristics(
          .setSensorOrientation(static_cast<int32_t>(sensorOrientation))
          .setSensorReadoutTimestamp(
              ANDROID_SENSOR_READOUT_TIMESTAMP_NOT_SUPPORTED)
          .setSensorTimestampSource(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN)
          .setSensorPhysicalSize(36.0, 24.0)
          .setAvailableFaceDetectModes({ANDROID_STATISTICS_FACE_DETECT_MODE_OFF})
          .setAvailableMaxDigitalZoom(1.0)
@@ -177,6 +162,8 @@ std::optional<CameraMetadata> initCameraCharacteristics(
          .setControlAeLockAvailable(false)
          .setControlAvailableAwbModes({ANDROID_CONTROL_AWB_MODE_AUTO})
          .setControlZoomRatioRange(/*min=*/1.0, /*max=*/1.0)
          // TODO(b/301023410) Add JPEG Exif + thumbnail support.
          .setJpegAvailableThumbnailSizes({Resolution(0, 0)})
          .setMaxJpegSize(kMaxJpegSize)
          .setMaxNumberOutputStreams(
              VirtualCameraDevice::kMaxNumberOfRawStreams,
@@ -187,8 +174,7 @@ std::optional<CameraMetadata> initCameraCharacteristics(
          .setAvailableRequestKeys({ANDROID_CONTROL_AF_MODE})
          .setAvailableResultKeys({ANDROID_CONTROL_AF_MODE})
          .setAvailableCapabilities(
              {ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE})
          .setAvailableCharacteristicKeys();
              {ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE});

  // Active array size must correspond to largest supported input resolution.
  std::optional<Resolution> maxResolution =
@@ -227,7 +213,7 @@ std::optional<CameraMetadata> initCameraCharacteristics(
  ALOGV("Adding %zu output configurations", outputConfigurations.size());
  builder.setAvailableOutputStreamConfigurations(outputConfigurations);

  auto metadata = builder.build();
  auto metadata = builder.setAvailableCharacteristicKeys().build();
  if (metadata == nullptr) {
    ALOGE("Failed to build metadata!");
    return CameraMetadata();
+34 −9
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
#include "aidl/android/hardware/camera/device/CameraMetadata.h"
#include "log/log.h"
#include "system/camera_metadata.h"
#include "util/Util.h"
#include "utils/Errors.h"

namespace android {
@@ -95,6 +96,14 @@ MetadataBuilder& MetadataBuilder::setSensorOrientation(int32_t sensorOrientation
  return *this;
}

MetadataBuilder& MetadataBuilder::setSensorTimestampSource(
    const camera_metadata_enum_android_sensor_info_timestamp_source_t
        timestampSource) {
  mEntryMap[ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE] =
      std::vector<uint8_t>({static_cast<uint8_t>(timestampSource)});
  return *this;
}

MetadataBuilder& MetadataBuilder::setSensorTimestamp(
    std::chrono::nanoseconds timestamp) {
  mEntryMap[ANDROID_SENSOR_TIMESTAMP] =
@@ -247,6 +256,18 @@ MetadataBuilder& MetadataBuilder::setMaxJpegSize(const int32_t size) {
  return *this;
}

MetadataBuilder& MetadataBuilder::setJpegAvailableThumbnailSizes(
    const std::vector<Resolution>& thumbnailSizes) {
  std::vector<int32_t> sizes;
  sizes.reserve(thumbnailSizes.size() * 2);
  for (const Resolution& resolution : thumbnailSizes) {
    sizes.push_back(resolution.width);
    sizes.push_back(resolution.height);
  }
  mEntryMap[ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES] = sizes;
  return *this;
}

MetadataBuilder& MetadataBuilder::setMaxNumberOutputStreams(
    const int32_t maxRawStreams, const int32_t maxProcessedStreams,
    const int32_t maxStallStreams) {
@@ -381,6 +402,13 @@ MetadataBuilder& MetadataBuilder::setAvailableCharacteristicKeys(
}

MetadataBuilder& MetadataBuilder::setAvailableCharacteristicKeys() {
  mExtendWithAvailableCharacteristicsKeys = true;
  return *this;
}

std::unique_ptr<aidl::android::hardware::camera::device::CameraMetadata>
MetadataBuilder::build() {
  if (mExtendWithAvailableCharacteristicsKeys) {
    std::vector<camera_metadata_tag_t> availableKeys;
    availableKeys.reserve(mEntryMap.size());
    for (const auto& [key, _] : mEntryMap) {
@@ -389,11 +417,8 @@ MetadataBuilder& MetadataBuilder::setAvailableCharacteristicKeys() {
      }
    }
    setAvailableCharacteristicKeys(availableKeys);
  return *this;
  }

std::unique_ptr<aidl::android::hardware::camera::device::CameraMetadata>
MetadataBuilder::build() const {
  CameraMetadata metadataHelper;
  for (const auto& entry : mEntryMap) {
    status_t ret = std::visit(
+13 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@

#include "aidl/android/hardware/camera/device/CameraMetadata.h"
#include "system/camera_metadata.h"
#include "util/Util.h"

namespace android {
namespace companion {
@@ -91,6 +92,10 @@ class MetadataBuilder {
  // See ANDROID_SENSOR_TIMESTAMP in CameraMetadataTag.aidl.
  MetadataBuilder& setSensorTimestamp(std::chrono::nanoseconds timestamp);

  // See SENSOR_INFO_TIMESTAMP_SOURCE in CameraCharacteristic.java.
  MetadataBuilder& setSensorTimestampSource(
      camera_metadata_enum_android_sensor_info_timestamp_source_t timestampSource);

  // See ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE in CameraMetadataTag.aidl.
  MetadataBuilder& setSensorActiveArraySize(int x0, int y0, int x1, int y1);

@@ -183,6 +188,10 @@ class MetadataBuilder {
  // See ANDROID_JPEG_SIZE in CameraMetadataTag.aidl.
  MetadataBuilder& setMaxJpegSize(int32_t size);

  // See JPEG_AVAILABLE_THUMBNAIL_SIZES in CameraCharacteristic.java.
  MetadataBuilder& setJpegAvailableThumbnailSizes(
      const std::vector<Resolution>& thumbnailSizes);

  // The maximum numbers of different types of output streams
  // that can be configured and used simultaneously by a camera device.
  //
@@ -232,14 +241,14 @@ class MetadataBuilder {
      const std::vector<camera_metadata_tag_t>& keys);

  // Extends metadata with ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS
  // containing all previously set tags.
  // containing all set tags.
  MetadataBuilder& setAvailableCharacteristicKeys();

  // Build CameraMetadata instance.
  //
  // Returns nullptr in case something went wrong.
  std::unique_ptr<::aidl::android::hardware::camera::device::CameraMetadata>
  build() const;
  build();

 private:
  // Maps metadata tags to vectors of values for the given tag.
@@ -248,6 +257,8 @@ class MetadataBuilder {
                        std::vector<uint8_t>, std::vector<float>,
                        std::vector<camera_metadata_rational_t>>>
      mEntryMap;
  // Extend metadata with ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS.
  bool mExtendWithAvailableCharacteristicsKeys = false;
};

}  // namespace virtualcamera
+21 −0
Original line number Diff line number Diff line
@@ -52,6 +52,27 @@ bool isFormatSupportedForInput(
    int width, int height,
    ::aidl::android::companion::virtualcamera::Format format, int maxFps);

// Representation of resolution / size.
struct Resolution {
  Resolution(const int w, const int h) : width(w), height(h) {
  }

  // Order by increasing pixel count, and by width for same pixel count.
  bool operator<(const Resolution& other) const {
    const int pixCount = width * height;
    const int otherPixCount = other.width * other.height;
    return pixCount == otherPixCount ? width < other.width
                                     : pixCount < otherPixCount;
  }

  bool operator==(const Resolution& other) const {
    return width == other.width && height == other.height;
  }

  const int width;
  const int height;
};

}  // namespace virtualcamera
}  // namespace companion
}  // namespace android