The Buffer class is a large beast the stores information about the buffer memory, dynamic metadata related to the frame stored in the buffer, and buffer reference data (in the index). In order to implement buffer import we will need to extend this with dmabuf file descriptors, making usage of the class even more complex. Refactor the Buffer class by splitting the buffer memory information to a BufferMemory class, and repurposing the Buffer class to reference a buffer and to store dynamic metadata. The BufferMemory class becomes a long term storage, valid and stable from the time buffer memory is allocated to the time it is freed. The Buffer class, on the other hand, becomes transient, is created on demand when an application requires a buffer, is given to a request, and is deleted when the request completes. Buffer and BufferMemory don't need to be copied, so their copy constructor and assignment operators are deleted. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
86 lines
1.6 KiB
C++
86 lines
1.6 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2019, Google Inc.
|
|
*
|
|
* stream.h - Video stream for a Camera
|
|
*/
|
|
#ifndef __LIBCAMERA_STREAM_H__
|
|
#define __LIBCAMERA_STREAM_H__
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <libcamera/buffer.h>
|
|
#include <libcamera/geometry.h>
|
|
|
|
namespace libcamera {
|
|
|
|
class Camera;
|
|
class Stream;
|
|
|
|
class StreamFormats
|
|
{
|
|
public:
|
|
StreamFormats();
|
|
StreamFormats(const std::map<unsigned int, std::vector<SizeRange>> &formats);
|
|
|
|
std::vector<unsigned int> pixelformats() const;
|
|
std::vector<Size> sizes(unsigned int pixelformat) const;
|
|
|
|
SizeRange range(unsigned int pixelformat) const;
|
|
|
|
private:
|
|
std::map<unsigned int, std::vector<SizeRange>> formats_;
|
|
};
|
|
|
|
struct StreamConfiguration {
|
|
StreamConfiguration();
|
|
StreamConfiguration(const StreamFormats &formats);
|
|
|
|
unsigned int pixelFormat;
|
|
Size size;
|
|
|
|
unsigned int bufferCount;
|
|
|
|
Stream *stream() const { return stream_; }
|
|
void setStream(Stream *stream) { stream_ = stream; }
|
|
const StreamFormats &formats() const { return formats_; }
|
|
|
|
std::string toString() const;
|
|
|
|
private:
|
|
Stream *stream_;
|
|
StreamFormats formats_;
|
|
};
|
|
|
|
enum StreamRole {
|
|
StillCapture,
|
|
VideoRecording,
|
|
Viewfinder,
|
|
};
|
|
|
|
using StreamRoles = std::vector<StreamRole>;
|
|
|
|
class Stream
|
|
{
|
|
public:
|
|
Stream();
|
|
|
|
std::unique_ptr<Buffer> createBuffer(unsigned int index);
|
|
|
|
BufferPool &bufferPool() { return bufferPool_; }
|
|
const StreamConfiguration &configuration() const { return configuration_; }
|
|
|
|
protected:
|
|
friend class Camera;
|
|
|
|
BufferPool bufferPool_;
|
|
StreamConfiguration configuration_;
|
|
};
|
|
|
|
} /* namespace libcamera */
|
|
|
|
#endif /* __LIBCAMERA_STREAM_H__ */
|