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