mirror of
https://github.com/Genymobile/scrcpy.git
synced 2025-08-02 22:29:25 +00:00
Extract MediaCodecListCompat.getEncoderInfosForType
This commit is contained in:
parent
953ba1021f
commit
042af5ca49
2 changed files with 16 additions and 14 deletions
|
@ -5,7 +5,9 @@ import android.media.MediaCodecList;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static android.media.MediaCodecList.REGULAR_CODECS;
|
import static android.media.MediaCodecList.REGULAR_CODECS;
|
||||||
import static android.os.Build.VERSION.SDK_INT;
|
import static android.os.Build.VERSION.SDK_INT;
|
||||||
|
@ -36,6 +38,18 @@ abstract class MediaCodecListCompat {
|
||||||
@NonNull
|
@NonNull
|
||||||
abstract MediaCodecInfo[] getCodecInfos();
|
abstract MediaCodecInfo[] getCodecInfos();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
final MediaCodecInfo[] getEncoderInfosForType(@NonNull String mimeType) {
|
||||||
|
List<MediaCodecInfo> result = new ArrayList<>();
|
||||||
|
MediaCodecInfo[] codecInfos = MediaCodecListCompat.regular().getCodecInfos();
|
||||||
|
for (MediaCodecInfo codecInfo : codecInfos) {
|
||||||
|
if (codecInfo.isEncoder() && Arrays.asList(codecInfo.getSupportedTypes()).contains(mimeType)) {
|
||||||
|
result.add(codecInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toArray(new MediaCodecInfo[result.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private static class Backport extends MediaCodecListCompat {
|
private static class Backport extends MediaCodecListCompat {
|
||||||
private final MediaCodecInfo[] mCodecInfos;
|
private final MediaCodecInfo[] mCodecInfos;
|
||||||
|
|
|
@ -13,8 +13,6 @@ import android.view.Surface;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
@ -201,24 +199,14 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
IO.writeFully(fd, headerBuffer);
|
IO.writeFully(fd, headerBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MediaCodecInfo[] listEncoders() {
|
|
||||||
List<MediaCodecInfo> result = new ArrayList<>();
|
|
||||||
MediaCodecInfo[] codecInfos = MediaCodecListCompat.regular().getCodecInfos();
|
|
||||||
for (MediaCodecInfo codecInfo : codecInfos) {
|
|
||||||
if (codecInfo.isEncoder() && Arrays.asList(codecInfo.getSupportedTypes()).contains(MediaFormat.MIMETYPE_VIDEO_AVC)) {
|
|
||||||
result.add(codecInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result.toArray(new MediaCodecInfo[result.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static MediaCodec createCodec(String encoderName) throws IOException {
|
private static MediaCodec createCodec(String encoderName) throws IOException {
|
||||||
if (encoderName != null) {
|
if (encoderName != null) {
|
||||||
Ln.d("Creating encoder by name: '" + encoderName + "'");
|
Ln.d("Creating encoder by name: '" + encoderName + "'");
|
||||||
try {
|
try {
|
||||||
return MediaCodec.createByCodecName(encoderName);
|
return MediaCodec.createByCodecName(encoderName);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
MediaCodecInfo[] encoders = listEncoders();
|
MediaCodecInfo[] encoders = MediaCodecListCompat.regular()
|
||||||
|
.getEncoderInfosForType(MediaFormat.MIMETYPE_VIDEO_AVC);
|
||||||
throw new InvalidEncoderException(encoderName, encoders);
|
throw new InvalidEncoderException(encoderName, encoders);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue