PR #24409 opened by sfan5 URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24409 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24409.patch
more context in this [comment thread](https://github.com/mpv-player/mpv/pull/18453#discussion_r3945199065) open questions: * would `AVERROR_EOF` instead of `AVERROR(ENOENT)` be more suitable? * do I need to bump any versions? (would be useful for me in mpv, but not a must) >From 64e4ff0d6ee2416da21bdd32289cafab97dacb11 Mon Sep 17 00:00:00 2001 From: sfan5 <[email protected]> Date: Mon, 7 Sep 2026 21:28:04 +0200 Subject: [PATCH] avcodec/mediacodec: return error when buffer is released a second time If the caller does any further processing (e.g. with AImageReader), it's very important to know if he can expect the frame to actually arrive at the surface or not. This provides a clearly detectable error in case the buffer was released multiple times *or* the codec was flushed in the meantime. --- libavcodec/mediacodec.c | 4 +++- libavcodec/mediacodec.h | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libavcodec/mediacodec.c b/libavcodec/mediacodec.c index 33bde8112e..2701f35ef0 100644 --- a/libavcodec/mediacodec.c +++ b/libavcodec/mediacodec.c @@ -96,6 +96,8 @@ int av_mediacodec_release_buffer(AVMediaCodecBuffer *buffer, int render) "Releasing output buffer %zd (%p) ts=%"PRId64" with render=%d [%d pending]\n", buffer->index, buffer, buffer->pts, render, atomic_load(&ctx->hw_buffer_count)); return ff_AMediaCodec_releaseOutputBuffer(ctx->codec, buffer->index, render); + } else if (render) { + return AVERROR(ENOENT); } return 0; @@ -114,7 +116,7 @@ int av_mediacodec_render_buffer_at_time(AVMediaCodecBuffer *buffer, int64_t time return ff_AMediaCodec_releaseOutputBufferAtTime(ctx->codec, buffer->index, time); } - return 0; + return AVERROR(ENOENT); } #else diff --git a/libavcodec/mediacodec.h b/libavcodec/mediacodec.h index 4e9b56a618..98b85be853 100644 --- a/libavcodec/mediacodec.h +++ b/libavcodec/mediacodec.h @@ -81,7 +81,9 @@ typedef struct MediaCodecBuffer AVMediaCodecBuffer; * @param buffer the buffer to render * @param render 1 to release and render the buffer to the surface or 0 to * discard the buffer - * @return 0 on success, < 0 otherwise + * @return 0 on success, < 0 otherwise. + * AVERROR(ENOENT) is returned when trying to render a buffer that has already + * been released. */ int av_mediacodec_release_buffer(AVMediaCodecBuffer *buffer, int render); @@ -95,6 +97,8 @@ int av_mediacodec_release_buffer(AVMediaCodecBuffer *buffer, int render); * @param buffer the buffer to render * @param time timestamp in nanoseconds of when to render the buffer * @return 0 on success, < 0 otherwise + * AVERROR(ENOENT) is returned when trying to render a buffer that has already + * been released. * * [0]: https://developer.android.com/reference/android/media/MediaCodec#releaseOutputBuffer(int,%20long) */ -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
