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

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

Merge "Simple dump for Virtual Caemra device" into main

parents 15927e4e 918e6dc8
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@
#include <string>
#include <vector>

#include "VirtualCameraService.h"
#include "VirtualCameraSession.h"
#include "aidl/android/companion/virtualcamera/SupportedStreamConfiguration.h"
#include "aidl/android/companion/virtualcamera/VirtualCameraConfiguration.h"
@@ -575,12 +576,18 @@ ndk::ScopedAStatus VirtualCameraDevice::getTorchStrengthLevel(
  return cameraStatus(Status::OPERATION_NOT_SUPPORTED);
}

binder_status_t VirtualCameraDevice::dump(int fd, const char** args,
                                          uint32_t numArgs) {
  // TODO(b/301023410) Implement.
  (void)fd;
  (void)args;
  (void)numArgs;
binder_status_t VirtualCameraDevice::dump(int fd, const char**, uint32_t) {
  ALOGD("Dumping virtual camera %d", mCameraId);
  const char* indent = "  ";
  const char* doubleIndent = "    ";
  dprintf(fd, "%svirtual_camera %d belongs to virtual device %d\n", indent,
          mCameraId,
          getDeviceId(mCameraCharacteristics)
              .value_or(VirtualCameraService::kDefaultDeviceId));
  dprintf(fd, "%sSupportedStreamConfiguration:\n", indent);
  for (auto& config : mSupportedInputConfigurations) {
    dprintf(fd, "%s%s", doubleIndent, config.toString().c_str());
  }
  return STATUS_OK;
}

+0 −1
Original line number Diff line number Diff line
@@ -64,7 +64,6 @@ namespace {
constexpr int kVgaWidth = 640;
constexpr int kVgaHeight = 480;
constexpr int kMaxFps = 60;
constexpr int kDefaultDeviceId = 0;
constexpr char kEnableTestCameraCmd[] = "enable_test_camera";
constexpr char kDisableTestCameraCmd[] = "disable_test_camera";
constexpr char kHelp[] = "help";
+3 −0
Original line number Diff line number Diff line
@@ -75,6 +75,9 @@ class VirtualCameraService
    mVerifyEglExtensions = false;
  }

  // Default virtual device id (the host device id)
  static constexpr int kDefaultDeviceId = 0;

 private:
  // Create and enable test camera instance if there's none.
  binder_status_t enableTestCameraCmd(
+27 −0
Original line number Diff line number Diff line
@@ -363,6 +363,33 @@ TEST_F(VirtualCameraDeviceTest, thumbnailSizeWithCompatibleAspectRatio) {
              ElementsAre(Resolution(0, 0), Resolution(240, 180)));
}

TEST_F(VirtualCameraDeviceTest, dump) {
  std::string expected = R"(  virtual_camera 42 belongs to virtual device 0
  SupportedStreamConfiguration:
    SupportedStreamConfiguration{width: 640, height: 480, pixelFormat: YUV_420_888, maxFps: 30})";
  int expectedSize = expected.size() * sizeof(char);
  char buffer[expectedSize];

  // Create an in memory fd
  int fd = memfd_create("tmpFile", 0);
  mCamera->dump(fd, {}, 0);

  // Check that we wrote the expected size
  int dumpSize = lseek(fd, 0, SEEK_END);

  // Rewind and read from the fd
  lseek(fd, 0, SEEK_SET);
  read(fd, buffer, expectedSize);
  close(fd);

  // Check the content of the dump
  std::string name = std::string(buffer, expectedSize);
  ASSERT_EQ(expected, name);
  // Check the size after the content to display the string mismatch when a
  // failure occurs
  ASSERT_EQ(expectedSize, dumpSize);
}

}  // namespace
}  // namespace virtualcamera
}  // namespace companion
+14 −0
Original line number Diff line number Diff line
@@ -947,6 +947,20 @@ getPrecaptureTrigger(
      entry.data.u8[0]);
}

std::optional<int32_t> getDeviceId(
    const aidl::android::hardware::camera::device::CameraMetadata& cameraMetadata) {
  auto metadata =
      reinterpret_cast<const camera_metadata_t*>(cameraMetadata.metadata.data());

  camera_metadata_ro_entry_t entry;
  if (find_camera_metadata_ro_entry(metadata, ANDROID_INFO_DEVICE_ID, &entry) !=
      OK) {
    return std::nullopt;
  }

  return static_cast<int32_t>(entry.data.i32[0]);
}

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