Support injecting custom native codecs from Java.
This CL extends our support for injecting native codecs such that
downstream users can create Java codecs that are backed by custom
native codecs.
After this CL, the Java codec interfaces expose
createNativeVideo{En,Decoder}() methods that may return a value
representing a pointer to the backing native codec. Previously,
a similar mechanism was used for the special case of non-public
Java codecs extending from the internal
WrappedNativeVideo{En,De}coder classes.
Tested: AppRTCMobile on Pixel XL and Pixel 2.
Bug: webrtc:9495
Change-Id: I079ff744afc7bf9873ff983e775c136a6667266d
Reviewed-on: https://webrtc-review.googlesource.com/87264
Commit-Queue: Rasmus Brandt <brandtr@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23883}
diff --git a/sdk/android/api/org/webrtc/VideoDecoder.java b/sdk/android/api/org/webrtc/VideoDecoder.java
index 7bf9ac5..879b694 100644
--- a/sdk/android/api/org/webrtc/VideoDecoder.java
+++ b/sdk/android/api/org/webrtc/VideoDecoder.java
@@ -52,6 +52,28 @@
}
/**
+ * The decoder implementation backing this interface is either 1) a Java
+ * decoder (e.g., an Android platform decoder), or alternatively 2) a native
+ * decoder (e.g., a software decoder or a C++ decoder adapter).
+ *
+ * For case 1), createNativeVideoDecoder() should return zero.
+ * In this case, we expect the native library to call the decoder through
+ * JNI using the Java interface declared below.
+ *
+ * For case 2), createNativeVideoDecoder() should return a non-zero value.
+ * In this case, we expect the native library to treat the returned value as
+ * a raw pointer of type webrtc::VideoDecoder* (ownership is transferred to
+ * the caller). The native library should then directly call the
+ * webrtc::VideoDecoder interface without going through JNI. All calls to
+ * the Java interface methods declared below should thus throw an
+ * UnsupportedOperationException.
+ */
+ @CalledByNative
+ default long createNativeVideoDecoder() {
+ return 0;
+ }
+
+ /**
* Initializes the decoding process with specified settings. Will be called on the decoding thread
* before any decode calls.
*/
diff --git a/sdk/android/api/org/webrtc/VideoDecoderFallback.java b/sdk/android/api/org/webrtc/VideoDecoderFallback.java
index 743a614..ddfa3ec 100644
--- a/sdk/android/api/org/webrtc/VideoDecoderFallback.java
+++ b/sdk/android/api/org/webrtc/VideoDecoderFallback.java
@@ -23,7 +23,7 @@
}
@Override
- long createNativeDecoder() {
+ public long createNativeVideoDecoder() {
return nativeCreateDecoder(fallback, primary);
}
diff --git a/sdk/android/api/org/webrtc/VideoEncoder.java b/sdk/android/api/org/webrtc/VideoEncoder.java
index 3001120..b739e99 100644
--- a/sdk/android/api/org/webrtc/VideoEncoder.java
+++ b/sdk/android/api/org/webrtc/VideoEncoder.java
@@ -164,6 +164,36 @@
}
/**
+ * The encoder implementation backing this interface is either 1) a Java
+ * encoder (e.g., an Android platform encoder), or alternatively 2) a native
+ * encoder (e.g., a software encoder or a C++ encoder adapter).
+ *
+ * For case 1), createNativeVideoEncoder() should return zero.
+ * In this case, we expect the native library to call the encoder through
+ * JNI using the Java interface declared below.
+ *
+ * For case 2), createNativeVideoEncoder() should return a non-zero value.
+ * In this case, we expect the native library to treat the returned value as
+ * a raw pointer of type webrtc::VideoEncoder* (ownership is transferred to
+ * the caller). The native library should then directly call the
+ * webrtc::VideoEncoder interface without going through JNI. All calls to
+ * the Java interface methods declared below should thus throw an
+ * UnsupportedOperationException.
+ */
+ @CalledByNative
+ default long createNativeVideoEncoder() {
+ return 0;
+ }
+
+ /**
+ * Returns true if the encoder is backed by hardware.
+ */
+ @CalledByNative
+ default boolean isHardwareEncoder() {
+ return true;
+ }
+
+ /**
* Initializes the encoding process. Call before any calls to encode.
*/
@CalledByNative VideoCodecStatus initEncode(Settings settings, Callback encodeCallback);
diff --git a/sdk/android/api/org/webrtc/VideoEncoderFallback.java b/sdk/android/api/org/webrtc/VideoEncoderFallback.java
index cd45eb7..fa36b7c 100644
--- a/sdk/android/api/org/webrtc/VideoEncoderFallback.java
+++ b/sdk/android/api/org/webrtc/VideoEncoderFallback.java
@@ -23,13 +23,13 @@
}
@Override
- long createNativeEncoder() {
+ public long createNativeVideoEncoder() {
return nativeCreateEncoder(fallback, primary);
}
@Override
- boolean isSoftwareEncoder() {
- return isWrappedSoftwareEncoder(primary);
+ public boolean isHardwareEncoder() {
+ return primary.isHardwareEncoder();
}
private static native long nativeCreateEncoder(VideoEncoder fallback, VideoEncoder primary);