Message ID | 20220325092555.1799897-4-kieran.bingham@ideasonboard.com |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
Hi Kieran, Thanks for the patch ! On 25/03/2022 10:25, Kieran Bingham wrote: > The af statistics can be accessed directly from the mapped buffer. > Remove the redundant memcpy, and simplify the call to > afEstimateVariance(). > > Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com> > > --- > - Fix ASSERT > > src/ipa/ipu3/algorithms/af.cpp | 12 ++++-------- > src/ipa/ipu3/algorithms/af.h | 2 +- > 2 files changed, 5 insertions(+), 9 deletions(-) > > diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp > index 4476857fa772..6893a15fdc07 100644 > --- a/src/ipa/ipu3/algorithms/af.cpp > +++ b/src/ipa/ipu3/algorithms/af.cpp > @@ -335,7 +335,7 @@ void Af::afIgnoreFrameReset() > * > * \return The variance of the values in the data set \a y_item selected by \a isY1 > */ > -double Af::afEstimateVariance(y_table_item_t *y_item, uint32_t len, > +double Af::afEstimateVariance(const y_table_item_t *y_item, uint32_t len, > bool isY1) > { > uint32_t z = 0; > @@ -405,25 +405,21 @@ bool Af::afIsOutOfFocus(IPAContext context) > */ > void Af::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) > { > - y_table_item_t y_item[IPU3_UAPI_AF_Y_TABLE_MAX_SIZE / sizeof(y_table_item_t)]; > + const y_table_item_t *y_item = reinterpret_cast<const y_table_item_t *>(&stats->af_raw_buffer.y_table); > uint32_t afRawBufferLen; > > /* Evaluate the AF buffer length */ > afRawBufferLen = context.configuration.af.afGrid.width * > context.configuration.af.afGrid.height; > > - memcpy(y_item, stats->af_raw_buffer.y_table, > - afRawBufferLen * sizeof(y_table_item_t)); > + ASSERT(afRawBufferLen < IPU3_UAPI_AF_Y_TABLE_MAX_SIZE); > > /* > * Calculate the mean and the variance of AF statistics for a given grid. > * For coarse: y1 are used. > * For fine: y2 results are used. > */ > - if (coarseCompleted_) > - currentVariance_ = afEstimateVariance(y_item, afRawBufferLen, false); > - else > - currentVariance_ = afEstimateVariance(y_item, afRawBufferLen, true); > + currentVariance_ = afEstimateVariance(y_item, afRawBufferLen, !coarseCompleted_); > > if (!context.frameContext.af.stable) { > afCoarseScan(context); > diff --git a/src/ipa/ipu3/algorithms/af.h b/src/ipa/ipu3/algorithms/af.h > index 906f2843dd49..3b5758e868ea 100644 > --- a/src/ipa/ipu3/algorithms/af.h > +++ b/src/ipa/ipu3/algorithms/af.h > @@ -41,7 +41,7 @@ private: > void afReset(IPAContext &context); > bool afNeedIgnoreFrame(); > void afIgnoreFrameReset(); > - double afEstimateVariance(y_table_item_t *y_item, uint32_t len, > + double afEstimateVariance(const y_table_item_t *y_item, uint32_t len, > bool isY1); > bool afIsOutOfFocus(IPAContext context); >
diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp index 4476857fa772..6893a15fdc07 100644 --- a/src/ipa/ipu3/algorithms/af.cpp +++ b/src/ipa/ipu3/algorithms/af.cpp @@ -335,7 +335,7 @@ void Af::afIgnoreFrameReset() * * \return The variance of the values in the data set \a y_item selected by \a isY1 */ -double Af::afEstimateVariance(y_table_item_t *y_item, uint32_t len, +double Af::afEstimateVariance(const y_table_item_t *y_item, uint32_t len, bool isY1) { uint32_t z = 0; @@ -405,25 +405,21 @@ bool Af::afIsOutOfFocus(IPAContext context) */ void Af::process(IPAContext &context, const ipu3_uapi_stats_3a *stats) { - y_table_item_t y_item[IPU3_UAPI_AF_Y_TABLE_MAX_SIZE / sizeof(y_table_item_t)]; + const y_table_item_t *y_item = reinterpret_cast<const y_table_item_t *>(&stats->af_raw_buffer.y_table); uint32_t afRawBufferLen; /* Evaluate the AF buffer length */ afRawBufferLen = context.configuration.af.afGrid.width * context.configuration.af.afGrid.height; - memcpy(y_item, stats->af_raw_buffer.y_table, - afRawBufferLen * sizeof(y_table_item_t)); + ASSERT(afRawBufferLen < IPU3_UAPI_AF_Y_TABLE_MAX_SIZE); /* * Calculate the mean and the variance of AF statistics for a given grid. * For coarse: y1 are used. * For fine: y2 results are used. */ - if (coarseCompleted_) - currentVariance_ = afEstimateVariance(y_item, afRawBufferLen, false); - else - currentVariance_ = afEstimateVariance(y_item, afRawBufferLen, true); + currentVariance_ = afEstimateVariance(y_item, afRawBufferLen, !coarseCompleted_); if (!context.frameContext.af.stable) { afCoarseScan(context); diff --git a/src/ipa/ipu3/algorithms/af.h b/src/ipa/ipu3/algorithms/af.h index 906f2843dd49..3b5758e868ea 100644 --- a/src/ipa/ipu3/algorithms/af.h +++ b/src/ipa/ipu3/algorithms/af.h @@ -41,7 +41,7 @@ private: void afReset(IPAContext &context); bool afNeedIgnoreFrame(); void afIgnoreFrameReset(); - double afEstimateVariance(y_table_item_t *y_item, uint32_t len, + double afEstimateVariance(const y_table_item_t *y_item, uint32_t len, bool isY1); bool afIsOutOfFocus(IPAContext context);