summaryrefslogtreecommitdiff
path: root/src/cam
diff options
context:
space:
mode:
Diffstat (limited to 'src/cam')
-rw-r--r--src/cam/buffer_writer.cpp4
-rw-r--r--src/cam/buffer_writer.h3
-rw-r--r--src/cam/capture.cpp37
3 files changed, 32 insertions, 12 deletions
diff --git a/src/cam/buffer_writer.cpp b/src/cam/buffer_writer.cpp
index e0374ffc..b7f2ed4f 100644
--- a/src/cam/buffer_writer.cpp
+++ b/src/cam/buffer_writer.cpp
@@ -19,7 +19,7 @@ BufferWriter::BufferWriter(const std::string &pattern)
{
}
-int BufferWriter::write(libcamera::Buffer *buffer,
+int BufferWriter::write(libcamera::Buffer *buffer, libcamera::BufferMemory *mem,
const std::string &streamName)
{
std::string filename;
@@ -41,7 +41,7 @@ int BufferWriter::write(libcamera::Buffer *buffer,
if (fd == -1)
return -errno;
- for (libcamera::Plane &plane : buffer->planes()) {
+ for (libcamera::Plane &plane : mem->planes()) {
void *data = plane.mem();
unsigned int length = plane.length();
diff --git a/src/cam/buffer_writer.h b/src/cam/buffer_writer.h
index 7bf785d1..9bea205f 100644
--- a/src/cam/buffer_writer.h
+++ b/src/cam/buffer_writer.h
@@ -16,7 +16,8 @@ class BufferWriter
public:
BufferWriter(const std::string &pattern = "frame-#.bin");
- int write(libcamera::Buffer *buffer, const std::string &streamName);
+ int write(libcamera::Buffer *buffer, libcamera::BufferMemory *mem,
+ const std::string &streamName);
private:
std::string pattern_;
diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp
index 6b842d73..1cf59063 100644
--- a/src/cam/capture.cpp
+++ b/src/cam/capture.cpp
@@ -95,13 +95,14 @@ int Capture::capture(EventLoop *loop)
std::map<Stream *, Buffer *> map;
for (StreamConfiguration &cfg : *config_) {
Stream *stream = cfg.stream();
- map[stream] = &stream->bufferPool().buffers()[i];
- }
-
- ret = request->setBuffers(map);
- if (ret < 0) {
- std::cerr << "Can't set buffers for request" << std::endl;
- return ret;
+ std::unique_ptr<Buffer> buffer = stream->createBuffer(i);
+
+ ret = request->addBuffer(std::move(buffer));
+ if (ret < 0) {
+ std::cerr << "Can't set buffer for request"
+ << std::endl;
+ return ret;
+ }
}
requests.push_back(request);
@@ -155,6 +156,7 @@ void Capture::requestComplete(Request *request, const std::map<Stream *, Buffer
for (auto it = buffers.begin(); it != buffers.end(); ++it) {
Stream *stream = it->first;
Buffer *buffer = it->second;
+ BufferMemory *mem = &stream->bufferPool().buffers()[buffer->index()];
const std::string &name = streamName_[stream];
info << " " << name
@@ -163,17 +165,34 @@ void Capture::requestComplete(Request *request, const std::map<Stream *, Buffer
<< " bytesused: " << buffer->bytesused();
if (writer_)
- writer_->write(buffer, name);
+ writer_->write(buffer, mem, name);
}
std::cout << info.str() << std::endl;
+ /*
+ * Create a new request and populate it with one buffer for each
+ * stream.
+ */
request = camera_->createRequest();
if (!request) {
std::cerr << "Can't create request" << std::endl;
return;
}
- request->setBuffers(buffers);
+ for (auto it = buffers.begin(); it != buffers.end(); ++it) {
+ Stream *stream = it->first;
+ Buffer *buffer = it->second;
+ unsigned int index = buffer->index();
+
+ std::unique_ptr<Buffer> newBuffer = stream->createBuffer(index);
+ if (!newBuffer) {
+ std::cerr << "Can't create buffer " << index << std::endl;
+ return;
+ }
+
+ request->addBuffer(std::move(newBuffer));
+ }
+
camera_->queueRequest(request);
}