[x265] [PATCH] Fix the buffer size issue

Mahesh Pittala mahesh at multicorewareinc.com
Tue Oct 29 11:36:14 UTC 2024


Pushed to the release_4.1 branch

On Thu, Oct 17, 2024 at 9:36 PM Ponsanthini Arunachalam <
ponsanthini.arunachalam at multicorewareinc.com> wrote:

> From dd1dc1f882b6f45422741e8b64da92c272e70e75 Mon Sep 17 00:00:00 2001
> From: Ponsanthini <ponsanthini.arunachalam at multicorewareinc.com>
> Date: Wed, 16 Oct 2024 19:37:39 +0530
> Subject: [PATCH] Fix the buffer size issue
>
> ---
>  source/encoder/encoder.cpp | 17 +++++++++--------
>  source/encoder/encoder.h   |  2 +-
>  2 files changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp
> index 21a4d5518..607c80d86 100644
> --- a/source/encoder/encoder.cpp
> +++ b/source/encoder/encoder.cpp
> @@ -2789,15 +2789,16 @@ void EncStats::addQP(double aveQp)
>      m_totalQp += aveQp;
>  }
>
> -char* Encoder::statsString(EncStats& stat, char* buffer)
> +char* Encoder::statsString(EncStats& stat, char* buffer, size_t
> bufferSize)
>  {
>      double fps = (double)m_param->fpsNum / m_param->fpsDenom;
>      double scale = fps / 1000 / (double)stat.m_numPics;
>
> -    int len = snprintf(buffer, sizeof(buffer), "%6u, ", stat.m_numPics);
> -
> -    len += snprintf(buffer + len, sizeof(buffer) - len, "Avg QP:%2.2lf",
> stat.m_totalQp / (double)stat.m_numPics);
> -    len += snprintf(buffer + len, sizeof(buffer) - len, "  kb/s:
> %-8.2lf", stat.m_accBits * scale);
> +    int len = snprintf(buffer, bufferSize, "%6u, ", stat.m_numPics);
> +
> +    len += snprintf(buffer + len, bufferSize - len, "Avg QP:%2.2lf",
> stat.m_totalQp / (double)stat.m_numPics);
> +    len += snprintf(buffer + len, bufferSize - len, "  kb/s: %-8.2lf",
> stat.m_accBits * scale);
> +
>      if (m_param->bEnablePsnr)
>      {
>          len += snprintf(buffer + len, sizeof(buffer) - len,"  PSNR Mean:
> Y:%.3lf U:%.3lf V:%.3lf",
> @@ -2823,11 +2824,11 @@ void Encoder::printSummary()
>      {
>          char buffer[200];
>          if (m_analyzeI[layer].m_numPics)
> -            x265_log(m_param, X265_LOG_INFO, "frame I: %s\n",
> statsString(m_analyzeI[layer], buffer));
> +            x265_log(m_param, X265_LOG_INFO, "frame I: %s\n",
> statsString(m_analyzeI[layer], buffer, sizeof(buffer)));
>          if (m_analyzeP[layer].m_numPics)
> -            x265_log(m_param, X265_LOG_INFO, "frame P: %s\n",
> statsString(m_analyzeP[layer], buffer));
> +            x265_log(m_param, X265_LOG_INFO, "frame P: %s\n",
> statsString(m_analyzeP[layer], buffer, sizeof(buffer)));
>          if (m_analyzeB[layer].m_numPics)
> -            x265_log(m_param, X265_LOG_INFO, "frame B: %s\n",
> statsString(m_analyzeB[layer], buffer));
> +            x265_log(m_param, X265_LOG_INFO, "frame B: %s\n",
> statsString(m_analyzeB[layer], buffer, sizeof(buffer)));
>          if (m_param->bEnableWeightedPred && m_analyzeP[layer].m_numPics)
>          {
>              x265_log(m_param, X265_LOG_INFO, "Weighted P-Frames: Y:%.1f%%
> UV:%.1f%%\n",
> diff --git a/source/encoder/encoder.h b/source/encoder/encoder.h
> index 4b72f8bf9..f50f783d0 100644
> --- a/source/encoder/encoder.h
> +++ b/source/encoder/encoder.h
> @@ -328,7 +328,7 @@ public:
>
>      void printReconfigureParams();
>
> -    char* statsString(EncStats&, char*);
> +    char* statsString(EncStats&, char* , size_t bufferSize);
>
>      void configure(x265_param *param);
>
> --
> 2.41.0.windows.3
>
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241029/b25da410/attachment.htm>


More information about the x265-devel mailing list