mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-21 11:25:08 +03:00
qcam: viewfinder: Add MappedBuffer to store memory mapping information
The new MappedBuffer structure replaces the std::pair<> used in the mapped buffers map, and allows passing data to the ViewFinder::display() function in a more structured way. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
494da4467d
commit
275fd5bd33
4 changed files with 21 additions and 19 deletions
|
@ -27,8 +27,6 @@
|
||||||
#include <libcamera/camera_manager.h>
|
#include <libcamera/camera_manager.h>
|
||||||
#include <libcamera/version.h>
|
#include <libcamera/version.h>
|
||||||
|
|
||||||
#include "viewfinder.h"
|
|
||||||
|
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -354,8 +352,7 @@ int MainWindow::startCapture()
|
||||||
const FrameBuffer::Plane &plane = buffer->planes().front();
|
const FrameBuffer::Plane &plane = buffer->planes().front();
|
||||||
void *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED,
|
void *memory = mmap(NULL, plane.length, PROT_READ, MAP_SHARED,
|
||||||
plane.fd.fd(), 0);
|
plane.fd.fd(), 0);
|
||||||
mappedBuffers_[plane.fd.fd()] =
|
mappedBuffers_[buffer.get()] = { memory, plane.length };
|
||||||
std::make_pair(memory, plane.length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Start the title timer and the camera. */
|
/* Start the title timer and the camera. */
|
||||||
|
@ -395,9 +392,8 @@ error:
|
||||||
delete request;
|
delete request;
|
||||||
|
|
||||||
for (auto &iter : mappedBuffers_) {
|
for (auto &iter : mappedBuffers_) {
|
||||||
void *memory = iter.second.first;
|
const MappedBuffer &buffer = iter.second;
|
||||||
unsigned int length = iter.second.second;
|
munmap(buffer.memory, buffer.size);
|
||||||
munmap(memory, length);
|
|
||||||
}
|
}
|
||||||
mappedBuffers_.clear();
|
mappedBuffers_.clear();
|
||||||
|
|
||||||
|
@ -425,9 +421,8 @@ void MainWindow::stopCapture()
|
||||||
camera_->requestCompleted.disconnect(this, &MainWindow::requestComplete);
|
camera_->requestCompleted.disconnect(this, &MainWindow::requestComplete);
|
||||||
|
|
||||||
for (auto &iter : mappedBuffers_) {
|
for (auto &iter : mappedBuffers_) {
|
||||||
void *memory = iter.second.first;
|
const MappedBuffer &buffer = iter.second;
|
||||||
unsigned int length = iter.second.second;
|
munmap(buffer.memory, buffer.size);
|
||||||
munmap(memory, length);
|
|
||||||
}
|
}
|
||||||
mappedBuffers_.clear();
|
mappedBuffers_.clear();
|
||||||
|
|
||||||
|
@ -534,10 +529,7 @@ int MainWindow::display(FrameBuffer *buffer)
|
||||||
if (buffer->planes().size() != 1)
|
if (buffer->planes().size() != 1)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
const FrameBuffer::Plane &plane = buffer->planes().front();
|
viewfinder_->display(buffer, &mappedBuffers_[buffer]);
|
||||||
void *memory = mappedBuffers_[plane.fd.fd()].first;
|
|
||||||
unsigned char *raw = static_cast<unsigned char *>(memory);
|
|
||||||
viewfinder_->display(raw, buffer->metadata().planes[0].bytesused);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,11 @@
|
||||||
#include <libcamera/stream.h>
|
#include <libcamera/stream.h>
|
||||||
|
|
||||||
#include "../cam/options.h"
|
#include "../cam/options.h"
|
||||||
|
#include "viewfinder.h"
|
||||||
|
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
|
||||||
class QAction;
|
class QAction;
|
||||||
class ViewFinder;
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
OptCamera = 'c',
|
OptCamera = 'c',
|
||||||
|
@ -89,7 +89,7 @@ private:
|
||||||
FrameBufferAllocator *allocator_;
|
FrameBufferAllocator *allocator_;
|
||||||
|
|
||||||
std::unique_ptr<CameraConfiguration> config_;
|
std::unique_ptr<CameraConfiguration> config_;
|
||||||
std::map<int, std::pair<void *, unsigned int>> mappedBuffers_;
|
std::map<FrameBuffer *, MappedBuffer> mappedBuffers_;
|
||||||
|
|
||||||
/* Capture state, buffers queue and statistics */
|
/* Capture state, buffers queue and statistics */
|
||||||
bool isCapturing_;
|
bool isCapturing_;
|
||||||
|
|
|
@ -24,7 +24,8 @@ ViewFinder::~ViewFinder()
|
||||||
delete image_;
|
delete image_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewFinder::display(const unsigned char *raw, size_t size)
|
void ViewFinder::display(const libcamera::FrameBuffer *buffer,
|
||||||
|
MappedBuffer *map)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&mutex_);
|
QMutexLocker locker(&mutex_);
|
||||||
|
|
||||||
|
@ -34,7 +35,8 @@ void ViewFinder::display(const unsigned char *raw, size_t size)
|
||||||
* impacting performances.
|
* impacting performances.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
converter_.convert(raw, size, image_);
|
converter_.convert(static_cast<unsigned char *>(map->memory),
|
||||||
|
buffer->metadata().planes[0].bytesused, image_);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,16 +7,24 @@
|
||||||
#ifndef __QCAM_VIEWFINDER_H__
|
#ifndef __QCAM_VIEWFINDER_H__
|
||||||
#define __QCAM_VIEWFINDER_H__
|
#define __QCAM_VIEWFINDER_H__
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include <libcamera/buffer.h>
|
||||||
#include <libcamera/pixelformats.h>
|
#include <libcamera/pixelformats.h>
|
||||||
|
|
||||||
#include "format_converter.h"
|
#include "format_converter.h"
|
||||||
|
|
||||||
class QImage;
|
class QImage;
|
||||||
|
|
||||||
|
struct MappedBuffer {
|
||||||
|
void *memory;
|
||||||
|
size_t size;
|
||||||
|
};
|
||||||
|
|
||||||
class ViewFinder : public QWidget
|
class ViewFinder : public QWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -24,7 +32,7 @@ public:
|
||||||
~ViewFinder();
|
~ViewFinder();
|
||||||
|
|
||||||
int setFormat(const libcamera::PixelFormat &format, const QSize &size);
|
int setFormat(const libcamera::PixelFormat &format, const QSize &size);
|
||||||
void display(const unsigned char *rgb, size_t size);
|
void display(const libcamera::FrameBuffer *buffer, MappedBuffer *map);
|
||||||
|
|
||||||
QImage getCurrentImage();
|
QImage getCurrentImage();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue