From 99cd22af01be30db7462ab781c768dae7ddb2174 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 1 Sep 2020 21:25:34 +0200 Subject: 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. --- audio/aframe.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'audio') diff --git a/audio/aframe.c b/audio/aframe.c index cc73bbd2a7..fc5d73be2d 100644 --- a/audio/aframe.c +++ b/audio/aframe.c @@ -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; -- cgit v1.2.3