History

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.

Andreas Rheinhardt committed 2 years ago

Commit 0aaabe11 parent 2786d341 file · +8 −12Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/get_buffer.c+8−12
@@ -65,20 +65,15 @@ static void frame_pool_free(FFRefStructOpaque unused, void *obj) · 64 unmodified lines
6565 static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame)
6666 {
6767 FramePool *pool = avctx->internal->pool;
68− int i, ret, ch, planes;
69−
70− if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
71− int planar = av_sample_fmt_is_planar(frame->format);
72− ch = frame->ch_layout.nb_channels;
73− planes = planar ? ch : 1;
74− }
68+ int i, ret;
7569
7670 if (pool && pool->format == frame->format) {
7771 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO &&
7872 pool->width == frame->width && pool->height == frame->height)
7973 return 0;
80− if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && pool->planes == planes &&
81− pool->channels == ch && frame->nb_samples == pool->samples)
74+ if (avctx->codec_type == AVMEDIA_TYPE_AUDIO &&
75+ pool->channels == frame->ch_layout.nb_channels &&
76+ frame->nb_samples == pool->samples)
8277 return 0;
8378 }
8479
@@ -141,7 +136,8 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame) · 56 unmodified lines
141136 break;
142137 }
143138 case AVMEDIA_TYPE_AUDIO: {
144− ret = av_samples_get_buffer_size(&pool->linesize[0], ch,
139+ ret = av_samples_get_buffer_size(&pool->linesize[0],
140+ frame->ch_layout.nb_channels,
145141 frame->nb_samples, frame->format, 0);
146142 if (ret < 0)
147143 goto fail;
@@ -153,9 +149,9 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame) · 5 unmodified lines
153149 }
154150
155151 pool->format = frame->format;
156− pool->planes = planes;
157− pool->channels = ch;
152+ pool->channels = frame->ch_layout.nb_channels;
158153 pool->samples = frame->nb_samples;
154+ pool->planes = av_sample_fmt_is_planar(pool->format) ? pool->channels : 1;
159155 break;
160156 }
161157 default: av_assert0(0);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t