Skip to content

Commit

Permalink
Rename "codec" variable to "mediaCodec"
Browse files Browse the repository at this point in the history
This will allow to use "codec" for the Codec type.

PR #3757 <#3757>
  • Loading branch information
rom1v committed Mar 3, 2023
1 parent 3c670dc commit 883a998
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions server/src/main/java/com/genymobile/scrcpy/ScreenEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public boolean consumeRotationChange() {

public void streamScreen() throws IOException, ConfigurationException {
String videoMimeType = streamer.getCodec().getMimeType();
MediaCodec codec = createCodec(videoMimeType, encoderName);
MediaCodec mediaCodec = createMediaCodec(videoMimeType, encoderName);
MediaFormat format = createFormat(videoMimeType, bitRate, maxFps, codecOptions);
IBinder display = createDisplay();
device.setRotationListener(this);
Expand All @@ -84,20 +84,20 @@ public void streamScreen() throws IOException, ConfigurationException {

Surface surface = null;
try {
codec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
surface = codec.createInputSurface();
mediaCodec.configure(format, null, null, MediaCodec.CONFIGURE_FLAG_ENCODE);
surface = mediaCodec.createInputSurface();

// does not include the locked video orientation
Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect();
int videoRotation = screenInfo.getVideoRotation();
int layerStack = device.getLayerStack();
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
codec.stop();
mediaCodec.stop();
} catch (IllegalStateException | IllegalArgumentException e) {
Ln.e("Encoding error: " + e.getClass().getName() + ": " + e.getMessage());
if (!prepareRetry(device, screenInfo)) {
Expand All @@ -106,14 +106,14 @@ public void streamScreen() throws IOException, ConfigurationException {
Ln.i("Retrying...");
alive = true;
} finally {
codec.reset();
mediaCodec.reset();
if (surface != null) {
surface.release();
}
}
} while (alive);
} finally {
codec.release();
mediaCodec.release();
device.setRotationListener(null);
SurfaceControl.destroyDisplay(display);
}
Expand Down Expand Up @@ -210,7 +210,7 @@ private static MediaCodecInfo[] listEncoders(String videoMimeType) {
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) {
Ln.d("Creating encoder by name: '" + encoderName + "'");
try {
Expand All @@ -220,9 +220,9 @@ private static MediaCodec createCodec(String videoMimeType, String encoderName)
throw new ConfigurationException("Unknown encoder: " + encoderName);
}
}
MediaCodec codec = MediaCodec.createEncoderByType(videoMimeType);
Ln.d("Using encoder: '" + codec.getName() + "'");
return codec;
MediaCodec mediaCodec = MediaCodec.createEncoderByType(videoMimeType);
Ln.d("Using encoder: '" + mediaCodec.getName() + "'");
return mediaCodec;
}

private static String buildUnknownEncoderMessage(String videoMimeType, String encoderName) {
Expand Down

0 comments on commit 883a998

Please sign in to comment.