[libcamera-devel,v4,12/12,HACK] still capture every 10 frames

Message ID 20190409192548.20325-13-jacopo@jmondi.org
State Superseded
Headers show
Series
  • libcamera: ipu3: Multiple streams support
Related show

Commit Message

Jacopo Mondi April 9, 2019, 7:25 p.m. UTC
Not for inclusion, just to demonstrate how an application could track
its streams to their assigned usages.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/cam/main.cpp | 46 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)

Patch

diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index 46aba728393c..fce694bf26d5 100644
--- a/src/cam/main.cpp
+++ b/src/cam/main.cpp
@@ -28,6 +28,11 @@  std::map<Stream *, std::string> streamInfo;
 EventLoop *loop;
 BufferWriter *writer;
 
+unsigned int streamCount = 0;
+unsigned int outBuf = 0;
+std::map<Stream *, StreamUsage::Role> streamMap;
+CameraConfiguration config;
+
 enum {
 	OptCamera = 'c',
 	OptCapture = 'C',
@@ -129,6 +134,11 @@  static int prepareCameraConfig(CameraConfiguration *config)
 		return -EINVAL;
 	}
 
+	/* Associate each stream returned by the Camera with its role. */
+	unsigned int i = 0;
+	for (auto *stream : *config)
+		streamMap[stream] = roles[i++].role();
+
 	/* Apply configuration explicitly requested. */
 	CameraConfiguration::iterator it = config->begin();
 	for (auto const &value : streamOptions) {
@@ -158,6 +168,7 @@  static int prepareCameraConfig(CameraConfiguration *config)
 
 static void requestComplete(Request *request, const std::map<Stream *, Buffer *> &buffers)
 {
+	std::map<Stream *, Buffer *> map;
 	static uint64_t now, last = 0;
 	double fps = 0.0;
 
@@ -196,13 +207,37 @@  static void requestComplete(Request *request, const std::map<Stream *, Buffer *>
 		return;
 	}
 
-	request->setBuffers(buffers);
+	/* Viewfinder in every request. */
+	for (auto &b : buffers) {
+		Stream *s = b.first;
+		if (streamMap[s] != StreamUsage::Role::Viewfinder)
+			continue;
+
+		map[s] = b.second;
+	}
+
+	/* Still capture every ten requests. */
+	streamCount++;
+	if (!(streamCount % 10)) {
+		streamCount = 0;
+		for (Stream *stream : config) {
+			if (streamMap[stream] != StreamUsage::Role::StillCapture)
+				continue;
+
+			map[stream] =
+				&stream->bufferPool().buffers()[outBuf];
+			outBuf = (outBuf + 1) %
+				 stream->bufferPool().count();
+			break;
+		}
+	}
+
+	request->setBuffers(map);
 	camera->queueRequest(request);
 }
 
 static int capture()
 {
-	CameraConfiguration config;
 	int ret;
 
 	ret = prepareCameraConfig(&config);
@@ -246,8 +281,13 @@  static int capture()
 		}
 
 		std::map<Stream *, Buffer *> map;
-		for (Stream *stream : config)
+		for (Stream *stream : config) {
+			if (streamMap[stream] != StreamUsage::Role::Viewfinder)
+				continue;
+
+			/* Only require the viewfinder to begin with. */
 			map[stream] = &stream->bufferPool().buffers()[i];
+		}
 
 		ret = request->setBuffers(map);
 		if (ret < 0) {