mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-25 01:25:08 +03:00
libcamera: stream: Add Stream memory type
Define the memory type a Stream uses and allow application to set it through the associated StreamConfiguration. A Stream can use either internal or external memory allocation methods, depending on where the data produced by the stream is actually saved. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
be3e3ebc92
commit
99e1e786b4
3 changed files with 42 additions and 5 deletions
|
@ -35,6 +35,11 @@ private:
|
||||||
std::map<unsigned int, std::vector<SizeRange>> formats_;
|
std::map<unsigned int, std::vector<SizeRange>> formats_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum MemoryType {
|
||||||
|
InternalMemory,
|
||||||
|
ExternalMemory,
|
||||||
|
};
|
||||||
|
|
||||||
struct StreamConfiguration {
|
struct StreamConfiguration {
|
||||||
StreamConfiguration();
|
StreamConfiguration();
|
||||||
StreamConfiguration(const StreamFormats &formats);
|
StreamConfiguration(const StreamFormats &formats);
|
||||||
|
@ -42,6 +47,7 @@ struct StreamConfiguration {
|
||||||
unsigned int pixelFormat;
|
unsigned int pixelFormat;
|
||||||
Size size;
|
Size size;
|
||||||
|
|
||||||
|
MemoryType memoryType;
|
||||||
unsigned int bufferCount;
|
unsigned int bufferCount;
|
||||||
|
|
||||||
Stream *stream() const { return stream_; }
|
Stream *stream() const { return stream_; }
|
||||||
|
@ -73,15 +79,17 @@ public:
|
||||||
BufferPool &bufferPool() { return bufferPool_; }
|
BufferPool &bufferPool() { return bufferPool_; }
|
||||||
std::vector<BufferMemory> &buffers() { return bufferPool_.buffers(); }
|
std::vector<BufferMemory> &buffers() { return bufferPool_.buffers(); }
|
||||||
const StreamConfiguration &configuration() const { return configuration_; }
|
const StreamConfiguration &configuration() const { return configuration_; }
|
||||||
|
MemoryType memoryType() const { return memoryType_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class Camera;
|
friend class Camera;
|
||||||
|
|
||||||
void createBuffers(unsigned int count);
|
void createBuffers(MemoryType memory, unsigned int count);
|
||||||
void destroyBuffers();
|
void destroyBuffers();
|
||||||
|
|
||||||
BufferPool bufferPool_;
|
BufferPool bufferPool_;
|
||||||
StreamConfiguration configuration_;
|
StreamConfiguration configuration_;
|
||||||
|
MemoryType memoryType_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace libcamera */
|
} /* namespace libcamera */
|
||||||
|
|
|
@ -683,7 +683,7 @@ int Camera::configure(CameraConfiguration *config)
|
||||||
* Allocate buffer objects in the pool.
|
* Allocate buffer objects in the pool.
|
||||||
* Memory will be allocated and assigned later.
|
* Memory will be allocated and assigned later.
|
||||||
*/
|
*/
|
||||||
stream->createBuffers(cfg.bufferCount);
|
stream->createBuffers(cfg.memoryType, cfg.bufferCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
state_ = CameraConfigured;
|
state_ = CameraConfigured;
|
||||||
|
|
|
@ -263,6 +263,17 @@ SizeRange StreamFormats::range(unsigned int pixelformat) const
|
||||||
return range;
|
return range;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \enum MemoryType
|
||||||
|
* \brief Define the memory type used by a Stream
|
||||||
|
* \var MemoryType::InternalMemory
|
||||||
|
* The Stream uses memory allocated internally by the library and exported to
|
||||||
|
* applications.
|
||||||
|
* \var MemoryType::ExternalMemory
|
||||||
|
* The Stream uses memory allocated externally by application and imported in
|
||||||
|
* the library.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \struct StreamConfiguration
|
* \struct StreamConfiguration
|
||||||
* \brief Configuration parameters for a stream
|
* \brief Configuration parameters for a stream
|
||||||
|
@ -276,7 +287,7 @@ SizeRange StreamFormats::range(unsigned int pixelformat) const
|
||||||
* handlers provied StreamFormats.
|
* handlers provied StreamFormats.
|
||||||
*/
|
*/
|
||||||
StreamConfiguration::StreamConfiguration()
|
StreamConfiguration::StreamConfiguration()
|
||||||
: stream_(nullptr)
|
: memoryType(InternalMemory), stream_(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +295,7 @@ StreamConfiguration::StreamConfiguration()
|
||||||
* \brief Construct a configuration with stream formats
|
* \brief Construct a configuration with stream formats
|
||||||
*/
|
*/
|
||||||
StreamConfiguration::StreamConfiguration(const StreamFormats &formats)
|
StreamConfiguration::StreamConfiguration(const StreamFormats &formats)
|
||||||
: stream_(nullptr), formats_(formats)
|
: memoryType(InternalMemory), stream_(nullptr), formats_(formats)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,6 +312,11 @@ StreamConfiguration::StreamConfiguration(const StreamFormats &formats)
|
||||||
* format described in V4L2 using the V4L2_PIX_FMT_* definitions.
|
* format described in V4L2 using the V4L2_PIX_FMT_* definitions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \var StreamConfiguration::memoryType
|
||||||
|
* \brief The memory type the stream shall use
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \var StreamConfiguration::bufferCount
|
* \var StreamConfiguration::bufferCount
|
||||||
* \brief Requested number of buffers to allocate for the stream
|
* \brief Requested number of buffers to allocate for the stream
|
||||||
|
@ -454,18 +470,26 @@ std::unique_ptr<Buffer> Stream::createBuffer(unsigned int index)
|
||||||
* \return The active configuration of the stream
|
* \return The active configuration of the stream
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \fn Stream::memoryType()
|
||||||
|
* \brief Retrieve the stream memory type
|
||||||
|
* \return The memory type used by the stream
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Create buffers for the stream
|
* \brief Create buffers for the stream
|
||||||
* \param[in] count The number of buffers to create
|
* \param[in] count The number of buffers to create
|
||||||
|
* \param[in] memory The stream memory type
|
||||||
*
|
*
|
||||||
* Create \a count empty buffers in the Stream's buffer pool.
|
* Create \a count empty buffers in the Stream's buffer pool.
|
||||||
*/
|
*/
|
||||||
void Stream::createBuffers(unsigned int count)
|
void Stream::createBuffers(MemoryType memory, unsigned int count)
|
||||||
{
|
{
|
||||||
destroyBuffers();
|
destroyBuffers();
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
memoryType_ = memory;
|
||||||
bufferPool_.createBuffers(count);
|
bufferPool_.createBuffers(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,4 +521,9 @@ void Stream::destroyBuffers()
|
||||||
* next call to Camera::configure() regardless of if it includes the stream.
|
* next call to Camera::configure() regardless of if it includes the stream.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \var Stream::memoryType_
|
||||||
|
* \brief The stream memory type
|
||||||
|
*/
|
||||||
|
|
||||||
} /* namespace libcamera */
|
} /* namespace libcamera */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue