diff --git a/sdk/android/api/org/webrtc/DefaultVideoDecoderFactory.java b/sdk/android/api/org/webrtc/DefaultVideoDecoderFactory.java index 837662f5bd..4e5c082fd8 100644 --- a/sdk/android/api/org/webrtc/DefaultVideoDecoderFactory.java +++ b/sdk/android/api/org/webrtc/DefaultVideoDecoderFactory.java @@ -31,7 +31,7 @@ public class DefaultVideoDecoderFactory implements VideoDecoderFactory { } @Override - public @Nullable VideoDecoder createDecoder(String codecType) { + public @Nullable VideoDecoder createDecoder(VideoCodecInfo codecType) { final VideoDecoder softwareDecoder = softwareVideoDecoderFactory.createDecoder(codecType); final VideoDecoder hardwareDecoder = hardwareVideoDecoderFactory.createDecoder(codecType); if (hardwareDecoder != null && softwareDecoder != null) { diff --git a/sdk/android/api/org/webrtc/HardwareVideoDecoderFactory.java b/sdk/android/api/org/webrtc/HardwareVideoDecoderFactory.java index a901045a8e..8c62c20d7c 100644 --- a/sdk/android/api/org/webrtc/HardwareVideoDecoderFactory.java +++ b/sdk/android/api/org/webrtc/HardwareVideoDecoderFactory.java @@ -46,8 +46,8 @@ public class HardwareVideoDecoderFactory implements VideoDecoderFactory { @Nullable @Override - public VideoDecoder createDecoder(String codecType) { - VideoCodecType type = VideoCodecType.valueOf(codecType); + public VideoDecoder createDecoder(VideoCodecInfo codecType) { + VideoCodecType type = VideoCodecType.valueOf(codecType.getName()); MediaCodecInfo info = findCodecForType(type); if (info == null) { diff --git a/sdk/android/api/org/webrtc/SoftwareVideoDecoderFactory.java b/sdk/android/api/org/webrtc/SoftwareVideoDecoderFactory.java index 095e01a1bd..e0a3dc80db 100644 --- a/sdk/android/api/org/webrtc/SoftwareVideoDecoderFactory.java +++ b/sdk/android/api/org/webrtc/SoftwareVideoDecoderFactory.java @@ -18,11 +18,11 @@ import javax.annotation.Nullable; public class SoftwareVideoDecoderFactory implements VideoDecoderFactory { @Nullable @Override - public VideoDecoder createDecoder(String codecType) { - if (codecType.equalsIgnoreCase("VP8")) { + public VideoDecoder createDecoder(VideoCodecInfo codecType) { + if (codecType.getName().equalsIgnoreCase("VP8")) { return new VP8Decoder(); } - if (codecType.equalsIgnoreCase("VP9") && VP9Decoder.nativeIsSupported()) { + if (codecType.getName().equalsIgnoreCase("VP9") && VP9Decoder.nativeIsSupported()) { return new VP9Decoder(); } diff --git a/sdk/android/api/org/webrtc/VideoDecoderFactory.java b/sdk/android/api/org/webrtc/VideoDecoderFactory.java index 77abd79c81..c54f61d9a3 100644 --- a/sdk/android/api/org/webrtc/VideoDecoderFactory.java +++ b/sdk/android/api/org/webrtc/VideoDecoderFactory.java @@ -18,7 +18,18 @@ public interface VideoDecoderFactory { * Creates a VideoDecoder for the given codec. Supports the same codecs supported by * VideoEncoderFactory. */ - @Nullable @CalledByNative VideoDecoder createDecoder(String codecType); + @Deprecated + @Nullable + default VideoDecoder createDecoder(String codecType) { + throw new UnsupportedOperationException("Deprecated and not implemented."); + } + + /** Creates a decoder for the given video codec. */ + @Nullable + @CalledByNative + default VideoDecoder createDecoder(VideoCodecInfo info) { + return createDecoder(info.getName()); + } /** * Enumerates the list of supported video codecs. diff --git a/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoDecoderTest.java b/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoDecoderTest.java index 6ca92decbe..e641aac06c 100644 --- a/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoDecoderTest.java +++ b/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoDecoderTest.java @@ -40,24 +40,28 @@ public final class HardwareVideoDecoderTest { static { CLASS_PARAMS.add(new ParameterSet() - .value("VP8" /* codecType */, false /* useEglContext */) + .value(/* codecName= */ "VP8", false /* useEglContext */) .name("VP8WithoutEglContext")); CLASS_PARAMS.add(new ParameterSet() - .value("VP8" /* codecType */, true /* useEglContext */) + .value(/* codecName= */ "VP8", true /* useEglContext */) .name("VP8WithEglContext")); CLASS_PARAMS.add(new ParameterSet() - .value("H264" /* codecType */, false /* useEglContext */) + .value(/* codecName= */ "H264", false /* useEglContext */) .name("H264WithoutEglContext")); CLASS_PARAMS.add(new ParameterSet() - .value("H264" /* codecType */, true /* useEglContext */) + .value(/* codecName= */ "H264", true /* useEglContext */) .name("H264WithEglContext")); } - private final String codecType; + private final VideoCodecInfo codecType; private final boolean useEglContext; - public HardwareVideoDecoderTest(String codecType, boolean useEglContext) { - this.codecType = codecType; + public HardwareVideoDecoderTest(String codecName, boolean useEglContext) { + if (codecName.equals("H264")) { + this.codecType = H264Utils.DEFAULT_H264_BASELINE_PROFILE_CODEC; + } else { + this.codecType = new VideoCodecInfo(codecName, new HashMap<>()); + } this.useEglContext = useEglContext; } @@ -134,8 +138,7 @@ public final class HardwareVideoDecoderTest { private void encodeTestFrames() { VideoEncoderFactory encoderFactory = new HardwareVideoEncoderFactory( eglBase.getEglBaseContext(), ENABLE_INTEL_VP8_ENCODER, ENABLE_H264_HIGH_PROFILE); - VideoEncoder encoder = - encoderFactory.createEncoder(new VideoCodecInfo(codecType, new HashMap<>())); + VideoEncoder encoder = encoderFactory.createEncoder(codecType); HardwareVideoEncoderTest.MockEncoderCallback encodeCallback = new HardwareVideoEncoderTest.MockEncoderCallback(); assertEquals(VideoCodecStatus.OK, encoder.initEncode(ENCODER_SETTINGS, encodeCallback)); diff --git a/sdk/android/src/jni/videodecoderfactorywrapper.cc b/sdk/android/src/jni/videodecoderfactorywrapper.cc index 30640ea802..94b44676e1 100644 --- a/sdk/android/src/jni/videodecoderfactorywrapper.cc +++ b/sdk/android/src/jni/videodecoderfactorywrapper.cc @@ -31,8 +31,10 @@ VideoDecoderFactoryWrapper::~VideoDecoderFactoryWrapper() = default; std::unique_ptr VideoDecoderFactoryWrapper::CreateVideoDecoder( const SdpVideoFormat& format) { JNIEnv* jni = AttachCurrentThreadIfNeeded(); + ScopedJavaLocalRef j_codec_info = + SdpVideoFormatToVideoCodecInfo(jni, format); ScopedJavaLocalRef decoder = Java_VideoDecoderFactory_createDecoder( - jni, decoder_factory_, NativeToJavaString(jni, format.name)); + jni, decoder_factory_, j_codec_info); if (!decoder.obj()) return nullptr; return JavaToNativeVideoDecoder(jni, decoder);