Rename "codec" variable to "mediaCodec"

This will allow to use "codec" for the Codec type.

PR #3757 <https://github.com/Genymobile/scrcpy/pull/3757>
This commit is contained in:
Romain Vimont 2023-02-19 19:51:50 +01:00
parent 10ce0f376a
commit 90d88a6927

View file

@ -64,7 +64,7 @@ public class ScreenEncoder implements Device.RotationListener {
public void streamScreen() throws IOException, ConfigurationException { public void streamScreen() throws IOException, ConfigurationException {
String videoMimeType = streamer.getCodec().getMimeType(); String videoMimeType = streamer.getCodec().getMimeType();
MediaCodec codec = createCodec(videoMimeType, encoderName); MediaCodec mediaCodec = createMediaCodec(videoMimeType, encoderName);
MediaFormat format = createFormat(videoMimeType, bitRate, maxFps, codecOptions); MediaFormat format = createFormat(videoMimeType, bitRate, maxFps, codecOptions);
IBinder display = createDisplay(); IBinder display = createDisplay();
device.setRotationListener(this); device.setRotationListener(this);
@ -84,8 +84,8 @@ public class ScreenEncoder implements Device.RotationListener {
Surface surface = null; Surface surface = null;
try { try {
codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE); mediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
surface = codec.createInputSurface(); surface = mediaCodec.createInputSurface();
// does not include the locked video orientation // does not include the locked video orientation
Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect(); Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect();
@ -93,11 +93,11 @@ public class ScreenEncoder implements Device.RotationListener {
int layerStack = device.getLayerStack(); int layerStack = device.getLayerStack();
setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack); setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack);
codec.start(); mediaCodec.start();
alive = encode(codec, streamer); alive = encode(mediaCodec, streamer);
// do not call stop() on exception, it would trigger an IllegalStateException // do not call stop() on exception, it would trigger an IllegalStateException
codec.stop(); mediaCodec.stop();
} catch (IllegalStateException | IllegalArgumentException e) { } catch (IllegalStateException | IllegalArgumentException e) {
Ln.e("Encoding error: " + e.getClass().getName() + ": " + e.getMessage()); Ln.e("Encoding error: " + e.getClass().getName() + ": " + e.getMessage());
if (!prepareRetry(device, screenInfo)) { if (!prepareRetry(device, screenInfo)) {
@ -106,14 +106,14 @@ public class ScreenEncoder implements Device.RotationListener {
Ln.i("Retrying..."); Ln.i("Retrying...");
alive = true; alive = true;
} finally { } finally {
codec.reset(); mediaCodec.reset();
if (surface != null) { if (surface != null) {
surface.release(); surface.release();
} }
} }
} while (alive); } while (alive);
} finally { } finally {
codec.release(); mediaCodec.release();
device.setRotationListener(null); device.setRotationListener(null);
SurfaceControl.destroyDisplay(display); SurfaceControl.destroyDisplay(display);
} }
@ -210,7 +210,7 @@ public class ScreenEncoder implements Device.RotationListener {
return result.toArray(new MediaCodecInfo[result.size()]); return result.toArray(new MediaCodecInfo[result.size()]);
} }
private static MediaCodec createCodec(String videoMimeType, String encoderName) throws IOException, ConfigurationException { private static MediaCodec createMediaCodec(String videoMimeType, String encoderName) throws IOException, ConfigurationException {
if (encoderName != null) { if (encoderName != null) {
Ln.d("Creating encoder by name: '" + encoderName + "'"); Ln.d("Creating encoder by name: '" + encoderName + "'");
try { try {
@ -220,9 +220,9 @@ public class ScreenEncoder implements Device.RotationListener {
throw new ConfigurationException("Unknown encoder: " + encoderName); throw new ConfigurationException("Unknown encoder: " + encoderName);
} }
} }
MediaCodec codec = MediaCodec.createEncoderByType(videoMimeType); MediaCodec mediaCodec = MediaCodec.createEncoderByType(videoMimeType);
Ln.d("Using encoder: '" + codec.getName() + "'"); Ln.d("Using encoder: '" + mediaCodec.getName() + "'");
return codec; return mediaCodec;
} }
private static String buildUnknownEncoderMessage(String videoMimeType, String encoderName) { private static String buildUnknownEncoderMessage(String videoMimeType, String encoderName) {