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.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -65,20 +65,15 @@ static void frame_pool_free(FFRefStructOpaque unused, void *obj) · 64 unmodified lines | ||
| 65 | 65 | static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame) |
| 66 | 66 | { |
| 67 | 67 | 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; | |
| 75 | 69 | |
| 76 | 70 | if (pool && pool->format == frame->format) { |
| 77 | 71 | if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && |
| 78 | 72 | pool->width == frame->width && pool->height == frame->height) |
| 79 | 73 | 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) | |
| 82 | 77 | return 0; |
| 83 | 78 | } |
| 84 | 79 | |
| @@ -141,7 +136,8 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame) · 56 unmodified lines | ||
| 141 | 136 | break; |
| 142 | 137 | } |
| 143 | 138 | 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, | |
| 145 | 141 | frame->nb_samples, frame->format, 0); |
| 146 | 142 | if (ret < 0) |
| 147 | 143 | goto fail; |
| @@ -153,9 +149,9 @@ static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame) · 5 unmodified lines | ||
| 153 | 149 | } |
| 154 | 150 | |
| 155 | 151 | pool->format = frame->format; |
| 156 | − pool->planes = planes; | |
| 157 | − pool->channels = ch; | |
| 152 | + pool->channels = frame->ch_layout.nb_channels; | |
| 158 | 153 | pool->samples = frame->nb_samples; |
| 154 | + pool->planes = av_sample_fmt_is_planar(pool->format) ? pool->channels : 1; | |
| 159 | 155 | break; |
| 160 | 156 | } |
| 161 | 157 | default: av_assert0(0); |