Skip to content

Commit 811857a

Browse files
authored
Merge pull request #243 from GetStream/fix/video-encoder-decoder
Fix video encoder and decoder
2 parents 18705b8 + ffab481 commit 811857a

File tree

9 files changed

+32
-49
lines changed

9 files changed

+32
-49
lines changed

stream-webrtc-android/api/stream-webrtc-android.api

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public final class org/webrtc/DataChannel$State : java/lang/Enum {
262262

263263
public class org/webrtc/Dav1dDecoder : org/webrtc/WrappedNativeVideoDecoder {
264264
public fun <init> ()V
265-
public fun createNativeVideoDecoder ()J
265+
public fun createNative (J)J
266266
}
267267

268268
public final class org/webrtc/DefaultAlignedVideoEncoderFactory : org/webrtc/VideoEncoderFactory {
@@ -619,11 +619,6 @@ public class org/webrtc/JniCommon {
619619
public static fun nativeReleaseRef (J)V
620620
}
621621

622-
public class org/webrtc/LibaomAv1Decoder : org/webrtc/WrappedNativeVideoDecoder {
623-
public fun <init> ()V
624-
public fun createNativeVideoDecoder ()J
625-
}
626-
627622
public class org/webrtc/LibaomAv1Encoder : org/webrtc/WrappedNativeVideoEncoder {
628623
public fun <init> ()V
629624
public fun createNative (J)J
@@ -632,7 +627,7 @@ public class org/webrtc/LibaomAv1Encoder : org/webrtc/WrappedNativeVideoEncoder
632627

633628
public class org/webrtc/LibvpxVp8Decoder : org/webrtc/WrappedNativeVideoDecoder {
634629
public fun <init> ()V
635-
public fun createNativeVideoDecoder ()J
630+
public fun createNative (J)J
636631
}
637632

638633
public class org/webrtc/LibvpxVp8Encoder : org/webrtc/WrappedNativeVideoEncoder {
@@ -643,7 +638,7 @@ public class org/webrtc/LibvpxVp8Encoder : org/webrtc/WrappedNativeVideoEncoder
643638

644639
public class org/webrtc/LibvpxVp9Decoder : org/webrtc/WrappedNativeVideoDecoder {
645640
public fun <init> ()V
646-
public fun createNativeVideoDecoder ()J
641+
public fun createNative (J)J
647642
}
648643

649644
public class org/webrtc/LibvpxVp9Encoder : org/webrtc/WrappedNativeVideoEncoder {
@@ -1791,7 +1786,7 @@ public final class org/webrtc/VideoCodecStatus : java/lang/Enum {
17911786
}
17921787

17931788
public abstract interface class org/webrtc/VideoDecoder {
1794-
public fun createNativeVideoDecoder ()J
1789+
public fun createNative (J)J
17951790
public abstract fun decode (Lorg/webrtc/EncodedImage;Lorg/webrtc/VideoDecoder$DecodeInfo;)Lorg/webrtc/VideoCodecStatus;
17961791
public abstract fun getImplementationName ()Ljava/lang/String;
17971792
public abstract fun initDecode (Lorg/webrtc/VideoDecoder$Settings;Lorg/webrtc/VideoDecoder$Callback;)Lorg/webrtc/VideoCodecStatus;
@@ -1822,7 +1817,7 @@ public abstract interface class org/webrtc/VideoDecoderFactory {
18221817

18231818
public class org/webrtc/VideoDecoderFallback : org/webrtc/WrappedNativeVideoDecoder {
18241819
public fun <init> (Lorg/webrtc/VideoDecoder;Lorg/webrtc/VideoDecoder;)V
1825-
public fun createNativeVideoDecoder ()J
1820+
public fun createNative (J)J
18261821
}
18271822

18281823
public abstract interface class org/webrtc/VideoEncoder {
@@ -2079,7 +2074,7 @@ public final class org/webrtc/WebRTCException : java/lang/RuntimeException {
20792074

20802075
public abstract class org/webrtc/WrappedNativeVideoDecoder : org/webrtc/VideoDecoder {
20812076
public fun <init> ()V
2082-
public abstract fun createNativeVideoDecoder ()J
2077+
public abstract fun createNative (J)J
20832078
public final fun decode (Lorg/webrtc/EncodedImage;Lorg/webrtc/VideoDecoder$DecodeInfo;)Lorg/webrtc/VideoCodecStatus;
20842079
public final fun getImplementationName ()Ljava/lang/String;
20852080
public final fun initDecode (Lorg/webrtc/VideoDecoder$Settings;Lorg/webrtc/VideoDecoder$Callback;)Lorg/webrtc/VideoCodecStatus;

stream-webrtc-android/src/main/java/org/webrtc/Dav1dDecoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/*
23
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
34
*
@@ -12,7 +13,7 @@
1213

1314
public class Dav1dDecoder extends WrappedNativeVideoDecoder {
1415
@Override
15-
public long createNativeVideoDecoder() {
16+
public long createNative(long webrtcEnvRef) {
1617
return nativeCreateDecoder();
1718
}
1819

stream-webrtc-android/src/main/java/org/webrtc/LibaomAv1Decoder.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

stream-webrtc-android/src/main/java/org/webrtc/LibvpxVp8Decoder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
public class LibvpxVp8Decoder extends WrappedNativeVideoDecoder {
1414
@Override
15-
public long createNativeVideoDecoder() {
16-
return nativeCreateDecoder();
15+
public long createNative(long webrtcEnvRef) {
16+
return nativeCreateDecoder(webrtcEnvRef);
1717
}
1818

19-
static native long nativeCreateDecoder();
20-
}
19+
static native long nativeCreateDecoder(long webrtcEnvRef);
20+
}

stream-webrtc-android/src/main/java/org/webrtc/LibvpxVp9Decoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
public class LibvpxVp9Decoder extends WrappedNativeVideoDecoder {
1414
@Override
15-
public long createNativeVideoDecoder() {
15+
public long createNative(long webrtcEnvRef) {
1616
return nativeCreateDecoder();
1717
}
1818

1919
static native long nativeCreateDecoder();
2020

2121
static native boolean nativeIsSupported();
22-
}
22+
}

stream-webrtc-android/src/main/java/org/webrtc/SoftwareVideoDecoderFactory.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
package org.webrtc;
1212

1313
import androidx.annotation.Nullable;
14-
import java.util.Arrays;
1514
import java.util.List;
1615

1716
public class SoftwareVideoDecoderFactory implements VideoDecoderFactory {
@@ -26,16 +25,14 @@ public SoftwareVideoDecoderFactory() {
2625
@Nullable
2726
@Override
2827
public VideoDecoder createDecoder(VideoCodecInfo info) {
29-
long nativeDecoder = nativeCreateDecoder(nativeFactory, info);
30-
if (nativeDecoder == 0) {
28+
if (!nativeIsSupported(nativeFactory, info)) {
3129
Logging.w(TAG, "Trying to create decoder for unsupported format. " + info);
3230
return null;
3331
}
34-
3532
return new WrappedNativeVideoDecoder() {
3633
@Override
37-
public long createNativeVideoDecoder() {
38-
return nativeDecoder;
34+
public long createNative(long webrtcEnvRef) {
35+
return nativeCreate(nativeFactory, webrtcEnvRef, info);
3936
}
4037
};
4138
}
@@ -47,7 +44,10 @@ public VideoCodecInfo[] getSupportedCodecs() {
4744

4845
private static native long nativeCreateFactory();
4946

50-
private static native long nativeCreateDecoder(long factory, VideoCodecInfo videoCodecInfo);
47+
private static native boolean nativeIsSupported(long factory, VideoCodecInfo info);
48+
49+
private static native long nativeCreate(
50+
long factory, long webrtcEnvRef, VideoCodecInfo info);
5151

5252
private static native List<VideoCodecInfo> nativeGetSupportedCodecs(long factory);
5353
}

stream-webrtc-android/src/main/java/org/webrtc/VideoDecoder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public interface Callback {
5656
* decoder (e.g., an Android platform decoder), or alternatively 2) a native
5757
* decoder (e.g., a software decoder or a C++ decoder adapter).
5858
*
59-
* For case 1), createNativeVideoDecoder() should return zero.
59+
* For case 1), createNative() should return zero.
6060
* In this case, we expect the native library to call the decoder through
6161
* JNI using the Java interface declared below.
6262
*
63-
* For case 2), createNativeVideoDecoder() should return a non-zero value.
63+
* For case 2), createNative() should return a non-zero value.
6464
* In this case, we expect the native library to treat the returned value as
6565
* a raw pointer of type webrtc::VideoDecoder* (ownership is transferred to
6666
* the caller). The native library should then directly call the
@@ -69,7 +69,7 @@ public interface Callback {
6969
* UnsupportedOperationException.
7070
*/
7171
@CalledByNative
72-
default long createNativeVideoDecoder() {
72+
default long createNative(long webrtcEnvRef) {
7373
return 0;
7474
}
7575

@@ -91,4 +91,4 @@ default long createNativeVideoDecoder() {
9191
* called from arbitrary thread.
9292
*/
9393
@CalledByNative String getImplementationName();
94-
}
94+
}

stream-webrtc-android/src/main/java/org/webrtc/VideoDecoderFallback.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ public VideoDecoderFallback(VideoDecoder fallback, VideoDecoder primary) {
2323
}
2424

2525
@Override
26-
public long createNativeVideoDecoder() {
27-
return nativeCreateDecoder(fallback, primary);
26+
public long createNative(long webrtcEnvRef) {
27+
return nativeCreate(webrtcEnvRef, fallback, primary);
2828
}
2929

30-
private static native long nativeCreateDecoder(VideoDecoder fallback, VideoDecoder primary);
31-
}
30+
private static native long nativeCreate(
31+
long webrtcEnvRef, VideoDecoder fallback, VideoDecoder primary);
32+
}

stream-webrtc-android/src/main/java/org/webrtc/WrappedNativeVideoDecoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Wraps a native webrtc::VideoDecoder.
1515
*/
1616
public abstract class WrappedNativeVideoDecoder implements VideoDecoder {
17-
@Override public abstract long createNativeVideoDecoder();
17+
@Override public abstract long createNative(long webrtcEnvRef);
1818

1919
@Override
2020
public final VideoCodecStatus initDecode(Settings settings, Callback decodeCallback) {
@@ -35,4 +35,4 @@ public final VideoCodecStatus decode(EncodedImage frame, DecodeInfo info) {
3535
public final String getImplementationName() {
3636
throw new UnsupportedOperationException("Not implemented.");
3737
}
38-
}
38+
}

0 commit comments

Comments
 (0)