Keep the same MediaCodec instance across sessions
Calling codec.reset() is sufficient.
This commit is contained in:
parent
91c69ad95c
commit
52f85fd6f1
1 changed files with 3 additions and 2 deletions
|
@ -75,13 +75,13 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void internalStreamScreen(Device device, FileDescriptor fd) throws IOException {
|
private void internalStreamScreen(Device device, FileDescriptor fd) throws IOException {
|
||||||
|
MediaCodec codec = createCodec(encoderName);
|
||||||
MediaFormat format = createFormat(bitRate, maxFps, codecOptions);
|
MediaFormat format = createFormat(bitRate, maxFps, codecOptions);
|
||||||
IBinder display = createDisplay();
|
IBinder display = createDisplay();
|
||||||
device.setRotationListener(this);
|
device.setRotationListener(this);
|
||||||
boolean alive;
|
boolean alive;
|
||||||
try {
|
try {
|
||||||
do {
|
do {
|
||||||
MediaCodec codec = createCodec(encoderName);
|
|
||||||
ScreenInfo screenInfo = device.getScreenInfo();
|
ScreenInfo screenInfo = device.getScreenInfo();
|
||||||
Rect contentRect = screenInfo.getContentRect();
|
Rect contentRect = screenInfo.getContentRect();
|
||||||
// include the locked video orientation
|
// include the locked video orientation
|
||||||
|
@ -120,13 +120,14 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
device.setMaxSize(newMaxSize);
|
device.setMaxSize(newMaxSize);
|
||||||
alive = true;
|
alive = true;
|
||||||
} finally {
|
} finally {
|
||||||
codec.release();
|
codec.reset();
|
||||||
if (surface != null) {
|
if (surface != null) {
|
||||||
surface.release();
|
surface.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (alive);
|
} while (alive);
|
||||||
} finally {
|
} finally {
|
||||||
|
codec.release();
|
||||||
device.setRotationListener(null);
|
device.setRotationListener(null);
|
||||||
SurfaceControl.destroyDisplay(display);
|
SurfaceControl.destroyDisplay(display);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue