audio: fix AVFrame allocation (crash with opus encoding)

AVFrame doesn't have public code for pool allocation, so mpv does it
manually. AVFrame allocation is very tricky, so we added a bug.

This crashed with libopus encoding, but not some other audio codecs,
because the libopus libavcodec wrapper accesses AVFrame.data. Most code
tries to avoid accessing AVFrame.data and uses AVFrame.extended_data,
because using the former would subtly corrupt memory on more than 8
channels. The fact that this problem manifested only now shows that most
AVFrame consuming FFmpeg code indeed uses extended_data for audio.
This commit is contained in:
wm4 2020-09-01 21:25:34 +02:00
parent d96e2c7313
commit 99cd22af01
1 changed files with 2 additions and 0 deletions

View File

@ -645,6 +645,8 @@ int mp_aframe_pool_allocate(struct mp_aframe_pool *pool, struct mp_aframe *frame
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];
av_frame->nb_samples = samples;
return 0;