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

Commit f8bb9756 authored by Jan Sebechlebsky's avatar Jan Sebechlebsky
Browse files

Make handling input surface in test camera more robust.

Bug: 301023410
Test: Manual with OpenCamera and test camera instance
Change-Id: I59a27c1ba2a1074d38650e58cce61c5587a1c1d3
parent 58a7ac4c
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