Skip to content

Commit

Permalink
improve codec list support
Browse files Browse the repository at this point in the history
some device have the same name for multiple codecs
add is hw is sw boolean checks to improve detection
  • Loading branch information
fgl27 committed Aug 8, 2024
1 parent dc0318e commit fa38eb0
Show file tree
Hide file tree
Showing 7 changed files with 930 additions and 817 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package com.fgl27.twitch;

import androidx.annotation.NonNull;

import androidx.media3.exoplayer.mediacodec.MediaCodecInfo;
import androidx.media3.exoplayer.mediacodec.MediaCodecSelector;
import androidx.media3.exoplayer.mediacodec.MediaCodecUtil;
Expand Down Expand Up @@ -57,7 +56,7 @@ public List<MediaCodecInfo> getDecoderInfos(@NonNull String mimeType, boolean re
List<MediaCodecInfo> filteredCodecInfo = new ArrayList<>();

for (MediaCodecInfo codecInfo : codecInfoList) {
if (codecInfo != null && !blacklistedCodec(codecInfo.name.toLowerCase(Locale.US))) {
if (codecInfo != null && !blacklistedCodec(codecInfo.name.toLowerCase(Locale.US) + codecInfo.mimeType)) {

filteredCodecInfo.add(codecInfo);

Expand All @@ -66,11 +65,11 @@ public List<MediaCodecInfo> getDecoderInfos(@NonNull String mimeType, boolean re
return filteredCodecInfo;
}

private boolean blacklistedCodec(String codecName) {
private boolean blacklistedCodec(String codecNameMimeType) {

for (String blackListedCodec : BLACKLISTEDCODECS) {

if (codecName.contains(blackListedCodec)) {
if (codecNameMimeType.contains(blackListedCodec)) {
return true;
}

Expand Down
20 changes: 18 additions & 2 deletions apk/app/src/main/java/com/fgl27/twitch/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ static String codecCapabilities(String CodecType) {

String maxlevel;
String resolutions;
boolean supportsIsHw = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;

ArrayList<CodecList> result = new ArrayList<>();

Expand Down Expand Up @@ -439,6 +440,8 @@ static String codecCapabilities(String CodecType) {
new CodecList(
type, //type
codec.getName(), //name
codec.getName() + type, //nameType
supportsIsHw ? codec.getCanonicalName() : null, //name
String.format(
Locale.US,
"%dx%d",
Expand All @@ -452,7 +455,10 @@ static String codecCapabilities(String CodecType) {
), //maxbitrate
maxlevel, //maxlevel
instances, //instances
resolutions //resolutions
resolutions, //resolutions
supportsIsHw && codec.isHardwareAccelerated(),
supportsIsHw && codec.isSoftwareOnly(),
supportsIsHw
)
);

Expand Down Expand Up @@ -1319,20 +1325,30 @@ public static class ResponseObj {
private static class CodecList {
private final String type;
private final String name;
private final String nameType;
private final String CanonicalName;
private final String maxresolution;
private final String maxbitrate;
private final String maxlevel;
private final int instances;
private final String resolutions;
private final boolean isHardwareAccelerated;
private final boolean isSoftwareOnly;
private final boolean supportsIsHw;

CodecList(String type, String name, String maxresolution, String maxbitrate, String maxlevel, int instances, String resolutions) {
CodecList(String type, String name, String nameType, String CanonicalName, String maxresolution, String maxbitrate, String maxlevel, int instances, String resolutions, boolean isHardwareAccelerated, boolean isSoftwareOnly, boolean supportsIsHw) {
this.type = type;
this.name = name;
this.nameType = nameType;
this.CanonicalName = CanonicalName;
this.maxresolution = maxresolution;
this.maxbitrate = maxbitrate;
this.maxlevel = maxlevel;
this.instances = instances;
this.resolutions = resolutions;
this.isHardwareAccelerated = isHardwareAccelerated;
this.isSoftwareOnly = isSoftwareOnly;
this.supportsIsHw = supportsIsHw;
}
}

Expand Down
Loading

0 comments on commit fa38eb0

Please sign in to comment.