diff options
author | sfan5 <sfan5@live.de> | 2021-04-06 07:44:03 +0200 |
---|---|---|
committer | Jan Ekström <jeebjp@gmail.com> | 2021-04-08 23:47:35 +0300 |
commit | 3c34e6fec4b942c92313546cacd14be539cd951f (patch) | |
tree | eefb62d083e5c6f4e759bc8f68b05465b94b6df3 /audio | |
parent | 5117fa70afc0431e57231e216474a1f530094fd0 (diff) | |
download | mpv-3c34e6fec4b942c92313546cacd14be539cd951f.tar.bz2 mpv-3c34e6fec4b942c92313546cacd14be539cd951f.tar.xz |
audio/aframe: reuse data buffer if less than 8 channels
This fixes audio encoding crashing under ASan.
When extended_data != data, FFmpeg copies more pointers from
extended_data (= the number of channels) than there really
are for non-planar formats (= exactly 1), but that's not our fault.
Regardless, this commit makes it work in all common cases.
Diffstat (limited to 'audio')
-rw-r--r-- | audio/aframe.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/audio/aframe.c b/audio/aframe.c index fc5d73be2d..c2c0df7c9b 100644 --- a/audio/aframe.c +++ b/audio/aframe.c @@ -635,18 +635,24 @@ int mp_aframe_pool_allocate(struct mp_aframe_pool *pool, struct mp_aframe *frame AVFrame *av_frame = frame->av_frame; if (av_frame->extended_data != av_frame->data) av_freep(&av_frame->extended_data); // sigh - av_frame->extended_data = - av_mallocz_array(planes, sizeof(av_frame->extended_data[0])); - if (!av_frame->extended_data) - abort(); + if (planes > AV_NUM_DATA_POINTERS) { + av_frame->extended_data = + av_mallocz_array(planes, sizeof(av_frame->extended_data[0])); + if (!av_frame->extended_data) + abort(); + } else { + av_frame->extended_data = av_frame->data; + } av_frame->buf[0] = av_buffer_pool_get(pool->avpool); if (!av_frame->buf[0]) return -1; av_frame->linesize[0] = samples * sstride; for (int n = 0; n < planes; n++) av_frame->extended_data[n] = av_frame->buf[0]->data + n * plane_size; - for (int n = 0; n < MPMIN(planes, AV_NUM_DATA_POINTERS); n++) - av_frame->data[n] = av_frame->extended_data[n]; + if (planes > AV_NUM_DATA_POINTERS) { + for (int n = 0; n < AV_NUM_DATA_POINTERS; n++) + av_frame->data[n] = av_frame->extended_data[n]; + } av_frame->nb_samples = samples; return 0; |