[libcamera-devel,v4,29/31] src: cam: Handle multiple streams in request complete

Message ID 20190320163055.22056-30-jacopo@jmondi.org
State Superseded
Headers show
Series
  • libcamera: ipu3: Add ImgU support + multiple streams
Related show

Commit Message

Jacopo Mondi March 20, 2019, 4:30 p.m. UTC
Add support for requests with multiple streams in 'requestComplete()'
method. Each stream content is optionally dumped to disk with its output
name.

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

Patch

diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index 201dbda765fe..a2364ef92bad 100644
--- a/src/cam/main.cpp
+++ b/src/cam/main.cpp
@@ -98,28 +98,40 @@  static int configureStreams(Camera *camera, std::set<Stream *> &streams)
 	return camera->configureStreams(config);
 }
 
-static void requestComplete(Request *request, const std::map<Stream *, Buffer *> &buffers)
+static void requestComplete(Request *request,
+			    const std::map<Stream *, Buffer *> &streamMap)
 {
 	static uint64_t last = 0;
 
 	if (request->status() == Request::RequestCancelled)
 		return;
 
-	Buffer *buffer = buffers.begin()->second;
-
-	double fps = buffer->timestamp() - last;
-	fps = last && fps ? 1000000000.0 / fps : 0.0;
-	last = buffer->timestamp();
+	Camera *camera = request->camera();
+	std::set<Stream *> streams = camera->streams();
+	for (const auto &completedStream : streamMap) {
+		Stream *stream = completedStream.first;
+		Buffer *buffer = completedStream.second;
+
+		/* Dump the buffer content! */
+		double fps = buffer->timestamp() - last;
+		fps = last && fps ? 1000000000.0 / fps : 0.0;
+		last = buffer->timestamp();
+
+		std::string streamName = stream == (*streams.begin()) ?
+					 "output" : "viewfinder";
+		std::cout << "stream: " << streamName
+			  << " seq: " << std::setw(6) << std::setfill('0')
+			  << buffer->sequence()
+			  << " buf: " << buffer->index()
+			  << " bytesused: " << buffer->bytesused()
+			  << " timestamp: " << buffer->timestamp()
+			  << " fps: " << std::fixed << std::setprecision(2) << fps
+			  << std::endl;
 
-	std::cout << "seq: " << std::setw(6) << std::setfill('0') << buffer->sequence()
-		  << " buf: " << buffer->index()
-		  << " bytesused: " << buffer->bytesused()
-		  << " timestamp: " << buffer->timestamp()
-		  << " fps: " << std::fixed << std::setprecision(2) << fps
-		  << std::endl;
 
-	if (writer)
-		writer->write(buffer);
+		if (writer)
+			writer->write(buffer, streamName);
+	}
 
 	request = camera->createRequest();
 	if (!request) {
@@ -127,7 +139,7 @@  static void requestComplete(Request *request, const std::map<Stream *, Buffer *>
 		return;
 	}
 
-	request->setBuffers(buffers);
+	request->setBuffers(streamMap);
 	camera->queueRequest(request);
 }