summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-09-01 21:25:34 +0200
committerwm4 <wm4@nowhere>2020-09-01 21:28:13 +0200
commit99cd22af01be30db7462ab781c768dae7ddb2174 (patch)
tree41b6596d6261234e129800ca5d8436c2322d8816 /audio
parentd96e2c731315daa3157f4892cc70267abf4d1a21 (diff)
downloadmpv-99cd22af01be30db7462ab781c768dae7ddb2174.tar.bz2
mpv-99cd22af01be30db7462ab781c768dae7ddb2174.tar.xz
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.
Diffstat (limited to 'audio')
-rw-r--r--audio/aframe.c2
1 files changed, 2 insertions, 0 deletions
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;