MediaCodec: release all output buffers on release

This prevents leaking video memory
This commit is contained in:
Julian Winkler
2024-11-06 23:25:28 +01:00
parent fc0091a989
commit 7c9a32d041
2 changed files with 15 additions and 1 deletions

View File

@@ -465,6 +465,10 @@ JNIEXPORT jint JNICALL Java_android_media_MediaCodec_native_1dequeueOutputBuffer
_SET_INT_FIELD(buffer_info, "size", 0);
_SET_LONG_FIELD(buffer_info, "presentationTimeUs", 0);
av_frame_free(&frame);
// set the buffer to NULL, so we don't try to render it
uint8_t *raw_buffer = get_nio_buffer(env, buffer, &array_ref, &array);
*((AVFrame **)raw_buffer) = NULL;
release_nio_buffer(env, array_ref, array);
return 0;
}
if (ret != AVERROR(EAGAIN)) {
@@ -569,6 +573,9 @@ JNIEXPORT void JNICALL Java_android_media_MediaCodec_native_1releaseOutputBuffer
*raw_buffer = NULL;
release_nio_buffer(env, array_ref, array);
if (!frame)
return;
if (!render) {
fprintf(stderr, "skipping %dx%d frame!\n", frame->width, frame->height);
av_frame_free(&frame);