android: camera_stream: Delegate Encoder construction
Delegate the construction of the encoder to the CameraStream class for streams that need post-processing. Reviewed-by: Umang Jain <email@uajain.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
This commit is contained in:
parent
94c4d49ebe
commit
3c84d88193
3 changed files with 26 additions and 17 deletions
|
@ -1273,19 +1273,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
|
||||||
|
|
||||||
StreamConfiguration &cfg = config_->at(index);
|
StreamConfiguration &cfg = config_->at(index);
|
||||||
|
|
||||||
/*
|
streams_.emplace_back(formats::MJPEG, cfg.size, type, index);
|
||||||
* Construct a software encoder for the MJPEG streams from the
|
|
||||||
* chosen libcamera source stream.
|
|
||||||
*/
|
|
||||||
Encoder *encoder = new EncoderLibJpeg();
|
|
||||||
int ret = encoder->configure(cfg);
|
|
||||||
if (ret) {
|
|
||||||
LOG(HAL, Error) << "Failed to configure encoder";
|
|
||||||
delete encoder;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
streams_.emplace_back(formats::MJPEG, cfg.size, type, index, encoder);
|
|
||||||
jpegStream->priv = static_cast<void *>(&streams_.back());
|
jpegStream->priv = static_cast<void *>(&streams_.back());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1306,11 +1294,20 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Configure the HAL CameraStream instances using the associated
|
||||||
|
* StreamConfiguration and set the number of required buffers in
|
||||||
|
* the Android camera3_stream_t.
|
||||||
|
*/
|
||||||
for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
|
for (unsigned int i = 0; i < stream_list->num_streams; ++i) {
|
||||||
camera3_stream_t *stream = stream_list->streams[i];
|
camera3_stream_t *stream = stream_list->streams[i];
|
||||||
CameraStream *cameraStream = static_cast<CameraStream *>(stream->priv);
|
CameraStream *cameraStream = static_cast<CameraStream *>(stream->priv);
|
||||||
StreamConfiguration &cfg = config_->at(cameraStream->index());
|
StreamConfiguration &cfg = config_->at(cameraStream->index());
|
||||||
|
|
||||||
|
int ret = cameraStream->configure(cfg);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
/* Use the bufferCount confirmed by the validation process. */
|
/* Use the bufferCount confirmed by the validation process. */
|
||||||
stream->max_buffers = cfg.bufferCount;
|
stream->max_buffers = cfg.bufferCount;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,21 @@
|
||||||
#include "camera_stream.h"
|
#include "camera_stream.h"
|
||||||
|
|
||||||
#include "jpeg/encoder.h"
|
#include "jpeg/encoder.h"
|
||||||
|
#include "jpeg/encoder_libjpeg.h"
|
||||||
|
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
|
||||||
CameraStream::CameraStream(PixelFormat format, Size size,
|
CameraStream::CameraStream(PixelFormat format, Size size, Type type, unsigned int index)
|
||||||
Type type, unsigned int index, Encoder *encoder)
|
: format_(format), size_(size), type_(type), index_(index)
|
||||||
: format_(format), size_(size), type_(type), index_(index), encoder_(encoder)
|
|
||||||
{
|
{
|
||||||
|
if (type_ == Type::Internal || type_ == Type::Mapped)
|
||||||
|
encoder_ = std::make_unique<EncoderLibJpeg>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int CameraStream::configure(const libcamera::StreamConfiguration &cfg)
|
||||||
|
{
|
||||||
|
if (encoder_)
|
||||||
|
return encoder_->configure(cfg);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public:
|
||||||
Mapped,
|
Mapped,
|
||||||
};
|
};
|
||||||
CameraStream(libcamera::PixelFormat format, libcamera::Size size,
|
CameraStream(libcamera::PixelFormat format, libcamera::Size size,
|
||||||
Type type, unsigned int index, Encoder *encoder = nullptr);
|
Type type, unsigned int index);
|
||||||
|
|
||||||
const libcamera::PixelFormat &format() const { return format_; }
|
const libcamera::PixelFormat &format() const { return format_; }
|
||||||
const libcamera::Size &size() const { return size_; }
|
const libcamera::Size &size() const { return size_; }
|
||||||
|
@ -108,6 +108,8 @@ public:
|
||||||
unsigned int index() const { return index_; }
|
unsigned int index() const { return index_; }
|
||||||
Encoder *encoder() const { return encoder_.get(); }
|
Encoder *encoder() const { return encoder_.get(); }
|
||||||
|
|
||||||
|
int configure(const libcamera::StreamConfiguration &cfg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
libcamera::PixelFormat format_;
|
libcamera::PixelFormat format_;
|
||||||
libcamera::Size size_;
|
libcamera::Size size_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue