mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Revert AndroidTestUtil.canDecode to use EncoderUtil.findCodecForFormat
208eefc0fd
introduced using `DefaultDecoderFactory.getDecoderInfo(format) != null` caused certain tests not to be skipped when they were expected to be, creating more mh failures.
PiperOrigin-RevId: 537820370
(cherry picked from commit 2af57527853beb7ee40e5b70efde74e72f8d60f1)
This commit is contained in:
parent
83957eb67f
commit
a8dbea74ce
@ -834,7 +834,7 @@ public final class AndroidTestUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean canDecode(Format format) throws MediaCodecUtil.DecoderQueryException {
|
||||
private static boolean canDecode(Format format) {
|
||||
// Check decoding capability in the same way as the default decoder factory.
|
||||
MediaFormat mediaFormat = MediaFormatUtil.createMediaFormatFromFormat(format);
|
||||
@Nullable
|
||||
@ -843,7 +843,7 @@ public final class AndroidTestUtil {
|
||||
MediaFormatUtil.maybeSetInteger(
|
||||
mediaFormat, MediaFormat.KEY_PROFILE, codecProfileAndLevel.first);
|
||||
}
|
||||
return DefaultDecoderFactory.getDecoderInfo(format) != null;
|
||||
return EncoderUtil.findCodecForFormat(mediaFormat, /* isDecoder= */ true) != null;
|
||||
}
|
||||
|
||||
private static boolean canEncode(Format format) {
|
||||
|
@ -24,6 +24,7 @@ import android.media.CamcorderProfile;
|
||||
import android.media.MediaCodec;
|
||||
import android.media.MediaCodecInfo;
|
||||
import android.media.MediaCodecList;
|
||||
import android.media.MediaFormat;
|
||||
import android.util.Pair;
|
||||
import android.util.Range;
|
||||
import android.util.Size;
|
||||
@ -37,6 +38,7 @@ import androidx.media3.common.C.ColorTransfer;
|
||||
import androidx.media3.common.ColorInfo;
|
||||
import androidx.media3.common.Format;
|
||||
import androidx.media3.common.MimeTypes;
|
||||
import androidx.media3.common.util.MediaFormatUtil;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.base.Ascii;
|
||||
@ -301,6 +303,37 @@ public final class EncoderUtil {
|
||||
return maxSupportedLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a {@link MediaCodec} that supports the {@link MediaFormat}, or {@code null} if none is
|
||||
* found.
|
||||
*/
|
||||
@Nullable
|
||||
public static String findCodecForFormat(MediaFormat format, boolean isDecoder) {
|
||||
MediaCodecList mediaCodecList = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
|
||||
// Format must not include KEY_FRAME_RATE on API21.
|
||||
// https://developer.android.com/reference/android/media/MediaCodecList#findDecoderForFormat(android.media.MediaFormat)
|
||||
float frameRate = Format.NO_VALUE;
|
||||
if (Util.SDK_INT == 21 && format.containsKey(MediaFormat.KEY_FRAME_RATE)) {
|
||||
try {
|
||||
frameRate = format.getFloat(MediaFormat.KEY_FRAME_RATE);
|
||||
} catch (ClassCastException e) {
|
||||
frameRate = format.getInteger(MediaFormat.KEY_FRAME_RATE);
|
||||
}
|
||||
// Clears the frame rate field.
|
||||
format.setString(MediaFormat.KEY_FRAME_RATE, null);
|
||||
}
|
||||
|
||||
String mediaCodecName =
|
||||
isDecoder
|
||||
? mediaCodecList.findDecoderForFormat(format)
|
||||
: mediaCodecList.findEncoderForFormat(format);
|
||||
|
||||
if (Util.SDK_INT == 21) {
|
||||
MediaFormatUtil.maybeSetInteger(format, MediaFormat.KEY_FRAME_RATE, round(frameRate));
|
||||
}
|
||||
return mediaCodecName;
|
||||
}
|
||||
|
||||
/** Returns the range of supported bitrates for the given {@linkplain MimeTypes MIME type}. */
|
||||
public static Range<Integer> getSupportedBitrateRange(
|
||||
MediaCodecInfo encoderInfo, String mimeType) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user