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

Commit b71ca7f7 authored by Ján Sebechlebský's avatar Ján Sebechlebský Committed by Android (Google) Code Review
Browse files

Merge "Make handling input surface in test camera more robust." into main

parents c4045cad f8bb9756
Loading
Loading
Loading
Loading
+22 −7
Original line number Diff line number Diff line
@@ -125,10 +125,18 @@ ScopedAStatus VirtualCameraTestInstance::onStreamConfigured(
  ALOGV("%s: streamId %d, %dx%d pixFmt=%s", __func__, streamId, width, height,
        toString(pixelFormat).c_str());

  std::lock_guard<std::mutex> lock(mLock);
  mRenderer = std::make_shared<TestPatternRenderer>(
  auto renderer = std::make_shared<TestPatternRenderer>(
      nativeWindowFromSurface(surface), mFps);
  mRenderer->start();

  std::lock_guard<std::mutex> lock(mLock);
  if (mInputRenderers.try_emplace(streamId, renderer).second) {
    renderer->start();
  } else {
    ALOGE(
        "%s: Input stream with id %d is already active, ignoring "
        "onStreamConfigured call",
        __func__, streamId);
  }

  return ScopedAStatus::ok();
}
@@ -141,10 +149,17 @@ ScopedAStatus VirtualCameraTestInstance::onProcessCaptureRequest(
ScopedAStatus VirtualCameraTestInstance::onStreamClosed(const int32_t streamId) {
  ALOGV("%s: streamId %d", __func__, streamId);

  std::shared_ptr<TestPatternRenderer> renderer;
  {
    std::lock_guard<std::mutex> lock(mLock);
  if (mRenderer != nullptr) {
    mRenderer->stop();
    mRenderer.reset();
    auto it = mInputRenderers.find(streamId);
    if (it != mInputRenderers.end()) {
      renderer = std::move(it->second);
      mInputRenderers.erase(it);
    }
  }
  if (renderer != nullptr) {
    renderer->stop();
  }
  return ScopedAStatus::ok();
}
+5 −2
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
#define ANDROID_COMPANION_VIRTUALCAMERA_VIRTUALCAMERATESTINSTANCE_H

#include <atomic>
#include <condition_variable>
#include <map>
#include <memory>
#include <thread>

@@ -80,7 +80,10 @@ class VirtualCameraTestInstance
  const int mFps;

  std::mutex mLock;
  std::shared_ptr<TestPatternRenderer> mRenderer GUARDED_BY(mLock);
  // Map maintaining streamId -> TestPatternRenderer mapping for active
  // input streams.
  std::map<int, std::shared_ptr<TestPatternRenderer>> mInputRenderers
      GUARDED_BY(mLock);
};

}  // namespace virtualcamera