feat(android): update isCodecSupported
to return enum
This commit is contained in:
parent
01a47840be
commit
812e9dc84f
@ -1,6 +1,7 @@
|
|||||||
package com.brentvatne.react;
|
package com.brentvatne.react;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.media.MediaCodecInfo;
|
||||||
import android.media.MediaCodecList;
|
import android.media.MediaCodecList;
|
||||||
import android.media.MediaDrm;
|
import android.media.MediaDrm;
|
||||||
import android.media.MediaFormat;
|
import android.media.MediaFormat;
|
||||||
@ -79,18 +80,36 @@ public class VideoDecoderPropertiesModule extends ReactContextBaseJavaModule {
|
|||||||
@SuppressLint("ObsoleteSdkInt")
|
@SuppressLint("ObsoleteSdkInt")
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void isCodecSupported(String mimeType, int width, int height, Promise p) {
|
public void isCodecSupported(String mimeType, int width, int height, Promise p) {
|
||||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||||
p.resolve(false);
|
p.resolve("unsupported");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaCodecList mRegularCodecs = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
|
MediaCodecList mRegularCodecs = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
|
||||||
MediaFormat format = MediaFormat.createVideoFormat(mimeType, width, height);
|
MediaFormat format = MediaFormat.createVideoFormat(mimeType, width, height);
|
||||||
String codecName = mRegularCodecs.findDecoderForFormat(format);
|
String codecName = mRegularCodecs.findDecoderForFormat(format);
|
||||||
|
|
||||||
if (codecName == null) {
|
if (codecName == null) {
|
||||||
p.resolve(false);
|
p.resolve("unsupported");
|
||||||
} else {
|
return;
|
||||||
p.resolve(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fallback for android < 10
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||||
|
p.resolve("software");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isHardwareAccelerated = false;
|
||||||
|
|
||||||
|
for (MediaCodecInfo codecInfo : mRegularCodecs.getCodecInfos()) {
|
||||||
|
if (codecInfo.getName().equalsIgnoreCase(codecName)) {
|
||||||
|
isHardwareAccelerated = codecInfo.isHardwareAccelerated();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p.resolve(isHardwareAccelerated ? "software" : "hardware");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user