diff options
Diffstat (limited to 'audio/audio.c')
-rw-r--r-- | audio/audio.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/audio/audio.c b/audio/audio.c index 263470261e..baf00c08b2 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -160,8 +160,8 @@ void mp_audio_realloc(struct mp_audio *mpa, int samples) if (!mpa->allocated[n] || size != mpa->allocated[n]->size) { if (av_buffer_realloc(&mpa->allocated[n], size) < 0) abort(); // OOM - mpa->planes[n] = mpa->allocated[n]->data; } + mpa->planes[n] = mpa->allocated[n]->data; } for (int n = mpa->num_planes; n < MP_NUM_CHANNELS; n++) { av_buffer_unref(&mpa->allocated[n]); @@ -192,8 +192,18 @@ int mp_audio_get_allocated_size(struct mp_audio *mpa) { int size = 0; for (int n = 0; n < mpa->num_planes; n++) { - int s = mpa->allocated[n] ? mpa->allocated[n]->size / mpa->sstride : 0; - size = n == 0 ? s : MPMIN(size, s); + for (int i = 0; i < MP_NUM_CHANNELS && mpa->allocated[i]; i++) { + uint8_t *start = mpa->allocated[i]->data; + uint8_t *end = start + mpa->allocated[i]->size; + uint8_t *plane = mpa->planes[n]; + if (plane >= start && plane < end) { + int s = MPMIN((end - plane) / mpa->sstride, INT_MAX); + size = n == 0 ? s : MPMIN(size, s); + goto next; + } + } + return 0; // plane is not covered by any buffer + next: ; } return size; } |