Message ID | 20200605141002.49119-3-jacopo@jmondi.org |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
Hi Jacopo, Thank you for the patch. On Fri, Jun 05, 2020 at 04:09:56PM +0200, Jacopo Mondi wrote: > As we move to have more and more dynamically generated static metadata > entries, the size of the metadata buffer has to be calculated > dynamically inspecting the information collected from the camera. > > Provide a method to perform metadata buffers size calculation and > use it when generating camera static metadata. > > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > src/android/camera_device.cpp | 34 ++++++++++++++++++++++++++++------ > src/android/camera_device.h | 2 ++ > 2 files changed, 30 insertions(+), 6 deletions(-) > > diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp > index cb9e4a6bc15b..c65295a32f3f 100644 > --- a/src/android/camera_device.cpp > +++ b/src/android/camera_device.cpp > @@ -8,6 +8,7 @@ > #include "camera_device.h" > #include "camera_ops.h" > > +#include <tuple> > #include <vector> > > #include <libcamera/controls.h> > @@ -368,6 +369,29 @@ void CameraDevice::setCallbacks(const camera3_callback_ops_t *callbacks) > callbacks_ = callbacks; > } > > +std::tuple<uint32_t, uint32_t> CameraDevice::calculateStaticMetadataSize() > +{ > + /* > + * \todo Keep this in sync with the actual number of entries. > + * Currently: 50 entries, 647 bytes of static metadata > + */ > + uint32_t numEntries = 50; > + uint32_t byteSize = 647; > + > + /* > + * Calculate space occupation in bytes for dynamically built metadata > + * entries. > + * > + * Each stream configuration entry requires 52 bytes: > + * 4 32bits integers for ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS > + * 1 32bits integer for ANDROID_SCALER_AVAILABLE_FORMATS > + * 4 64bits integers for ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS > + */ > + byteSize += streamConfigurations_.size() * 52; > + > + return { numEntries, byteSize }; > +} > + > /* > * Return static information for the camera. > */ > @@ -381,12 +405,10 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() > * example application, but a real camera implementation will require > * more. > */ > - > - /* > - * \todo Keep this in sync with the actual number of entries. > - * Currently: 50 entries, 666 bytes > - */ > - staticMetadata_ = new CameraMetadata(50, 700); > + uint32_t numEntries; > + uint32_t byteSize; > + std::tie(numEntries, byteSize) = calculateStaticMetadataSize(); > + staticMetadata_ = new CameraMetadata(numEntries, byteSize); > if (!staticMetadata_->isValid()) { > LOG(HAL, Error) << "Failed to allocate static metadata"; > delete staticMetadata_; > diff --git a/src/android/camera_device.h b/src/android/camera_device.h > index 4e8911da5770..ed11410a5577 100644 > --- a/src/android/camera_device.h > +++ b/src/android/camera_device.h > @@ -9,6 +9,7 @@ > > #include <map> > #include <memory> > +#include <tuple> > #include <vector> > > #include <hardware/camera3.h> > @@ -68,6 +69,7 @@ private: > }; > > int initializeStreamConfigurations(); > + std::tuple<uint32_t, uint32_t> calculateStaticMetadataSize(); > void notifyShutter(uint32_t frameNumber, uint64_t timestamp); > void notifyError(uint32_t frameNumber, camera3_stream_t *stream); > std::unique_ptr<CameraMetadata> getResultMetadata(int frame_number,
diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index cb9e4a6bc15b..c65295a32f3f 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -8,6 +8,7 @@ #include "camera_device.h" #include "camera_ops.h" +#include <tuple> #include <vector> #include <libcamera/controls.h> @@ -368,6 +369,29 @@ void CameraDevice::setCallbacks(const camera3_callback_ops_t *callbacks) callbacks_ = callbacks; } +std::tuple<uint32_t, uint32_t> CameraDevice::calculateStaticMetadataSize() +{ + /* + * \todo Keep this in sync with the actual number of entries. + * Currently: 50 entries, 647 bytes of static metadata + */ + uint32_t numEntries = 50; + uint32_t byteSize = 647; + + /* + * Calculate space occupation in bytes for dynamically built metadata + * entries. + * + * Each stream configuration entry requires 52 bytes: + * 4 32bits integers for ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS + * 1 32bits integer for ANDROID_SCALER_AVAILABLE_FORMATS + * 4 64bits integers for ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS + */ + byteSize += streamConfigurations_.size() * 52; + + return { numEntries, byteSize }; +} + /* * Return static information for the camera. */ @@ -381,12 +405,10 @@ const camera_metadata_t *CameraDevice::getStaticMetadata() * example application, but a real camera implementation will require * more. */ - - /* - * \todo Keep this in sync with the actual number of entries. - * Currently: 50 entries, 666 bytes - */ - staticMetadata_ = new CameraMetadata(50, 700); + uint32_t numEntries; + uint32_t byteSize; + std::tie(numEntries, byteSize) = calculateStaticMetadataSize(); + staticMetadata_ = new CameraMetadata(numEntries, byteSize); if (!staticMetadata_->isValid()) { LOG(HAL, Error) << "Failed to allocate static metadata"; delete staticMetadata_; diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 4e8911da5770..ed11410a5577 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -9,6 +9,7 @@ #include <map> #include <memory> +#include <tuple> #include <vector> #include <hardware/camera3.h> @@ -68,6 +69,7 @@ private: }; int initializeStreamConfigurations(); + std::tuple<uint32_t, uint32_t> calculateStaticMetadataSize(); void notifyShutter(uint32_t frameNumber, uint64_t timestamp); void notifyError(uint32_t frameNumber, camera3_stream_t *stream); std::unique_ptr<CameraMetadata> getResultMetadata(int frame_number,
As we move to have more and more dynamically generated static metadata entries, the size of the metadata buffer has to be calculated dynamically inspecting the information collected from the camera. Provide a method to perform metadata buffers size calculation and use it when generating camera static metadata. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> --- src/android/camera_device.cpp | 34 ++++++++++++++++++++++++++++------ src/android/camera_device.h | 2 ++ 2 files changed, 30 insertions(+), 6 deletions(-)