ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinha...@outlook.com> | 
Sat Apr 20 03:11:39 2024 +0200| [0aaabe1fd72fb4d302a433ce33e45fb8c2301d6f] | 
committer: Andreas Rheinhardt

avcodec/get_buffer: Remove redundant check

It is unnecessary to check for whether the number of planes
of an already existing audio pool coincides with the number
of planes to use for the frame: If the common format of both
is planar, then the number of planes coincides with the number
of channels for which there is already a check*; if not,
then both the existing pool as well as the frame use one pool.

*: In fact, one could reuse the pool in this case even if the
number of channels changes.

Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0aaabe1fd72fb4d302a433ce33e45fb8c2301d6f
---

 libavcodec/get_buffer.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/libavcodec/get_buffer.c b/libavcodec/get_buffer.c
index 9b35fde7c6..ff19f61e86 100644
--- a/libavcodec/get_buffer.c
+++ b/libavcodec/get_buffer.c
@@ -65,20 +65,15 @@ static void frame_pool_free(FFRefStructOpaque unused, void 
*obj)
 static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
 {
     FramePool *pool = avctx->internal->pool;
-    int i, ret, ch, planes;
-
-    if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
-        int planar = av_sample_fmt_is_planar(frame->format);
-        ch     = frame->ch_layout.nb_channels;
-        planes = planar ? ch : 1;
-    }
+    int i, ret;
 
     if (pool && pool->format == frame->format) {
         if (avctx->codec_type == AVMEDIA_TYPE_VIDEO &&
             pool->width == frame->width && pool->height == frame->height)
             return 0;
-        if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && pool->planes == planes 
&&
-            pool->channels == ch && frame->nb_samples == pool->samples)
+        if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
+            pool->channels == frame->ch_layout.nb_channels &&
+            frame->nb_samples == pool->samples)
             return 0;
     }
 
@@ -141,7 +136,8 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame 
*frame)
         break;
         }
     case AVMEDIA_TYPE_AUDIO: {
-        ret = av_samples_get_buffer_size(&pool->linesize[0], ch,
+        ret = av_samples_get_buffer_size(&pool->linesize[0],
+                                         frame->ch_layout.nb_channels,
                                          frame->nb_samples, frame->format, 0);
         if (ret < 0)
             goto fail;
@@ -153,9 +149,9 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame 
*frame)
         }
 
         pool->format     = frame->format;
-        pool->planes     = planes;
-        pool->channels   = ch;
+        pool->channels   = frame->ch_layout.nb_channels;
         pool->samples = frame->nb_samples;
+        pool->planes     = av_sample_fmt_is_planar(pool->format) ? 
pool->channels : 1;
         break;
         }
     default: av_assert0(0);

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to