You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
MediaCodec: release all output buffers on release
This prevents leaking video memory
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -147,8 +147,15 @@ public class MediaCodec {
|
||||
|
||||
public void release() {
|
||||
System.out.println("MediaCodec.release(): codecName=" + codecName);
|
||||
if (native_codec != 0)
|
||||
if (native_codec != 0) {
|
||||
if (outputBuffers != null) {
|
||||
for (int i=0; i<outputBuffers.length; i++) {
|
||||
if (!freeOutputBuffers.contains(i))
|
||||
releaseOutputBuffer(i, false);
|
||||
}
|
||||
}
|
||||
native_release(native_codec);
|
||||
}
|
||||
native_codec = 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user