Always release output buffer
If rotation changed, the dequeued output buffer was never released. Move
it to a finally block to avoid the leak.
@@ -86,6 +86,7 @@ public class ScreenEncoder implements Device.RotationListener {
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
while (!checkRotationChanged() && !eof) {
int outputBufferId = codec.dequeueOutputBuffer(bufferInfo, -1);
+ try {
if (checkRotationChanged()) {
// must restart encoding with new size
break;
@@ -100,9 +101,13 @@ public class ScreenEncoder implements Device.RotationListener {
outputBuffer.get(buf, 0, len);
outputStream.write(buf, 0, len);
}
+ }
+ } finally {
+ if (outputBufferId >= 0) {
codec.releaseOutputBuffer(outputBufferId, false);
}
}
+ }
return !eof;
}
