mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-23 16:45:07 +03:00
libcamera: buffer: Add an accessor to the BufferMemory
Buffer instances reference memory, which is modelled internally by a BufferMemory instance. Store a pointer to the BufferMemory in the Buffer class, and populate it when the buffer is queued to the camera through a request. This is useful for applications to access the buffer memory in the buffer or request completion handler. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
f1199a1011
commit
689e8916ca
8 changed files with 26 additions and 11 deletions
|
@ -77,6 +77,7 @@ public:
|
|||
|
||||
unsigned int index() const { return index_; }
|
||||
const std::array<int, 3> &dmabufs() const { return dmabuf_; }
|
||||
BufferMemory *mem() { return mem_; }
|
||||
|
||||
unsigned int bytesused() const { return bytesused_; }
|
||||
uint64_t timestamp() const { return timestamp_; }
|
||||
|
@ -87,6 +88,7 @@ public:
|
|||
Stream *stream() const { return stream_; }
|
||||
|
||||
private:
|
||||
friend class Camera;
|
||||
friend class PipelineHandler;
|
||||
friend class Request;
|
||||
friend class Stream;
|
||||
|
@ -98,6 +100,7 @@ private:
|
|||
|
||||
unsigned int index_;
|
||||
std::array<int, 3> dmabuf_;
|
||||
BufferMemory *mem_;
|
||||
|
||||
unsigned int bytesused_;
|
||||
uint64_t timestamp_;
|
||||
|
|
|
@ -19,8 +19,7 @@ BufferWriter::BufferWriter(const std::string &pattern)
|
|||
{
|
||||
}
|
||||
|
||||
int BufferWriter::write(libcamera::Buffer *buffer, libcamera::BufferMemory *mem,
|
||||
const std::string &streamName)
|
||||
int BufferWriter::write(libcamera::Buffer *buffer, const std::string &streamName)
|
||||
{
|
||||
std::string filename;
|
||||
size_t pos;
|
||||
|
@ -41,6 +40,7 @@ int BufferWriter::write(libcamera::Buffer *buffer, libcamera::BufferMemory *mem,
|
|||
if (fd == -1)
|
||||
return -errno;
|
||||
|
||||
libcamera::BufferMemory *mem = buffer->mem();
|
||||
for (libcamera::Plane &plane : mem->planes()) {
|
||||
void *data = plane.mem();
|
||||
unsigned int length = plane.length();
|
||||
|
|
|
@ -16,8 +16,7 @@ class BufferWriter
|
|||
public:
|
||||
BufferWriter(const std::string &pattern = "frame-#.bin");
|
||||
|
||||
int write(libcamera::Buffer *buffer, libcamera::BufferMemory *mem,
|
||||
const std::string &streamName);
|
||||
int write(libcamera::Buffer *buffer, const std::string &streamName);
|
||||
|
||||
private:
|
||||
std::string pattern_;
|
||||
|
|
|
@ -154,7 +154,6 @@ 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->buffers()[buffer->index()];
|
||||
const std::string &name = streamName_[stream];
|
||||
|
||||
info << " " << name
|
||||
|
@ -163,7 +162,7 @@ void Capture::requestComplete(Request *request, const std::map<Stream *, Buffer
|
|||
<< " bytesused: " << buffer->bytesused();
|
||||
|
||||
if (writer_)
|
||||
writer_->write(buffer, mem, name);
|
||||
writer_->write(buffer, name);
|
||||
}
|
||||
|
||||
std::cout << info.str() << std::endl;
|
||||
|
|
|
@ -300,6 +300,17 @@ Buffer::Buffer(unsigned int index, const Buffer *metadata)
|
|||
* \return The dmabuf file descriptors
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn Buffer::mem()
|
||||
* \brief Retrieve the BufferMemory this buffer is associated with
|
||||
*
|
||||
* The association between the buffer and a BufferMemory instance is valid from
|
||||
* the time the request containing this buffer is queued to a camera to the end
|
||||
* of that request's completion handler.
|
||||
*
|
||||
* \return The BufferMemory this buffer is associated with
|
||||
*/
|
||||
|
||||
/**
|
||||
* \fn Buffer::bytesused()
|
||||
* \brief Retrieve the number of bytes occupied by the data in the buffer
|
||||
|
|
|
@ -811,10 +811,14 @@ int Camera::queueRequest(Request *request)
|
|||
|
||||
for (auto const &it : request->buffers()) {
|
||||
Stream *stream = it.first;
|
||||
Buffer *buffer = it.second;
|
||||
|
||||
if (activeStreams_.find(stream) == activeStreams_.end()) {
|
||||
LOG(Camera, Error) << "Invalid request";
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
buffer->mem_ = &stream->buffers()[buffer->index_];
|
||||
}
|
||||
|
||||
int ret = request->prepare();
|
||||
|
|
|
@ -221,7 +221,6 @@ void MainWindow::requestComplete(Request *request,
|
|||
|
||||
framesCaptured_++;
|
||||
|
||||
Stream *stream = buffers.begin()->first;
|
||||
Buffer *buffer = buffers.begin()->second;
|
||||
|
||||
double fps = buffer->timestamp() - lastBufferTime_;
|
||||
|
@ -235,8 +234,7 @@ void MainWindow::requestComplete(Request *request,
|
|||
<< " fps: " << std::fixed << std::setprecision(2) << fps
|
||||
<< std::endl;
|
||||
|
||||
BufferMemory *mem = &stream->buffers()[buffer->index()];
|
||||
display(buffer, mem);
|
||||
display(buffer);
|
||||
|
||||
request = camera_->createRequest();
|
||||
if (!request) {
|
||||
|
@ -261,8 +259,9 @@ void MainWindow::requestComplete(Request *request,
|
|||
camera_->queueRequest(request);
|
||||
}
|
||||
|
||||
int MainWindow::display(Buffer *buffer, BufferMemory *mem)
|
||||
int MainWindow::display(Buffer *buffer)
|
||||
{
|
||||
BufferMemory *mem = buffer->mem();
|
||||
if (mem->planes().size() != 1)
|
||||
return -EINVAL;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ private:
|
|||
|
||||
void requestComplete(Request *request,
|
||||
const std::map<Stream *, Buffer *> &buffers);
|
||||
int display(Buffer *buffer, BufferMemory *mem);
|
||||
int display(Buffer *buffer);
|
||||
|
||||
QString title_;
|
||||
QTimer titleTimer_;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue