Always release output buffer
If rotation changed, the dequeued output buffer was never released. Move it to a finally block to avoid the leak.
This commit is contained in:
parent
f39de46a39
commit
d5acc8adc5
1 changed files with 19 additions and 14 deletions
|
@ -86,6 +86,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
||||||
while (!checkRotationChanged() && !eof) {
|
while (!checkRotationChanged() && !eof) {
|
||||||
int outputBufferId = codec.dequeueOutputBuffer(bufferInfo, -1);
|
int outputBufferId = codec.dequeueOutputBuffer(bufferInfo, -1);
|
||||||
|
try {
|
||||||
if (checkRotationChanged()) {
|
if (checkRotationChanged()) {
|
||||||
// must restart encoding with new size
|
// must restart encoding with new size
|
||||||
break;
|
break;
|
||||||
|
@ -100,9 +101,13 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
outputBuffer.get(buf, 0, len);
|
outputBuffer.get(buf, 0, len);
|
||||||
outputStream.write(buf, 0, len);
|
outputStream.write(buf, 0, len);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (outputBufferId >= 0) {
|
||||||
codec.releaseOutputBuffer(outputBufferId, false);
|
codec.releaseOutputBuffer(outputBufferId, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return !eof;
|
return !eof;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue