summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-07-31 18:45:05 +0200
committerwm4 <wm4@nowhere>2016-07-31 18:51:02 +0200
commit98af572484dca052a0dbf276ac782f68f6bfbf44 (patch)
tree42d7a19c8793df8d8c0baebc43d37e8d5956632b
parent5bcb22beea14bb48a84c610425d5693e0305e434 (diff)
downloadmpv-98af572484dca052a0dbf276ac782f68f6bfbf44.tar.bz2
mpv-98af572484dca052a0dbf276ac782f68f6bfbf44.tar.xz
audio: make mp_audio_realloc[_min] ensure frame is writeable
This is logical: the function makes sense only in situations where you are going to write to the audio data. To make it worse, av_buffer_realloc() also handles this situation, but only if the buffer size changes (simply because it can't realloc memory in use), so we have to explicitly force reallocation by unreffing the buffers first.
-rw-r--r--audio/audio.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/audio/audio.c b/audio/audio.c
index 4c67a9aa5a..502bbf2134 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -138,6 +138,9 @@ static void mp_audio_destructor(void *ptr)
* available on every plane. The previous data is kept (for the smallest
* common number of samples before/after resize).
*
+ * This also makes sure the resulting buffer is writable (even in the case
+ * the buffer has the correct size).
+ *
* mpa->samples is not set or used.
*
* This function is flexible enough to handle format and channel layout
@@ -153,6 +156,12 @@ void mp_audio_realloc(struct mp_audio *mpa, int samples)
int size = get_plane_size(mpa, samples);
if (size < 0)
abort(); // oom or invalid parameters
+ if (!mp_audio_is_writeable(mpa)) {
+ for (int n = 0; n < MP_NUM_CHANNELS; n++) {
+ av_buffer_unref(&mpa->allocated[n]);
+ mpa->planes[n] = NULL;
+ }
+ }
for (int n = 0; n < mpa->num_planes; n++) {
if (!mpa->allocated[n] || size != mpa->allocated[n]->size) {
if (av_buffer_realloc(&mpa->allocated[n], size) < 0)
@@ -171,7 +180,7 @@ void mp_audio_realloc(struct mp_audio *mpa, int samples)
// If the buffer is reallocated, also preallocate.
void mp_audio_realloc_min(struct mp_audio *mpa, int samples)
{
- if (samples > mp_audio_get_allocated_size(mpa)) {
+ if (samples > mp_audio_get_allocated_size(mpa) || !mp_audio_is_writeable(mpa)) {
size_t alloc = ta_calc_prealloc_elems(samples);
if (alloc > INT_MAX)
abort(); // oom