Skip to content

Commit

Permalink
Merge pull request #243 from GetStream/fix/video-encoder-decoder
Browse files Browse the repository at this point in the history
Fix video encoder and decoder
  • Loading branch information
skydoves authored Dec 10, 2024
2 parents 18705b8 + ffab481 commit 811857a
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 49 deletions.
17 changes: 6 additions & 11 deletions stream-webrtc-android/api/stream-webrtc-android.api
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public final class org/webrtc/DataChannel$State : java/lang/Enum {

public class org/webrtc/Dav1dDecoder : org/webrtc/WrappedNativeVideoDecoder {
public fun <init> ()V
public fun createNativeVideoDecoder ()J
public fun createNative (J)J
}

public final class org/webrtc/DefaultAlignedVideoEncoderFactory : org/webrtc/VideoEncoderFactory {
Expand Down Expand Up @@ -619,11 +619,6 @@ public class org/webrtc/JniCommon {
public static fun nativeReleaseRef (J)V
}

public class org/webrtc/LibaomAv1Decoder : org/webrtc/WrappedNativeVideoDecoder {
public fun <init> ()V
public fun createNativeVideoDecoder ()J
}

public class org/webrtc/LibaomAv1Encoder : org/webrtc/WrappedNativeVideoEncoder {
public fun <init> ()V
public fun createNative (J)J
Expand All @@ -632,7 +627,7 @@ public class org/webrtc/LibaomAv1Encoder : org/webrtc/WrappedNativeVideoEncoder

public class org/webrtc/LibvpxVp8Decoder : org/webrtc/WrappedNativeVideoDecoder {
public fun <init> ()V
public fun createNativeVideoDecoder ()J
public fun createNative (J)J
}

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

public class org/webrtc/LibvpxVp9Decoder : org/webrtc/WrappedNativeVideoDecoder {
public fun <init> ()V
public fun createNativeVideoDecoder ()J
public fun createNative (J)J
}

public class org/webrtc/LibvpxVp9Encoder : org/webrtc/WrappedNativeVideoEncoder {
Expand Down Expand Up @@ -1791,7 +1786,7 @@ public final class org/webrtc/VideoCodecStatus : java/lang/Enum {
}

public abstract interface class org/webrtc/VideoDecoder {
public fun createNativeVideoDecoder ()J
public fun createNative (J)J
public abstract fun decode (Lorg/webrtc/EncodedImage;Lorg/webrtc/VideoDecoder$DecodeInfo;)Lorg/webrtc/VideoCodecStatus;
public abstract fun getImplementationName ()Ljava/lang/String;
public abstract fun initDecode (Lorg/webrtc/VideoDecoder$Settings;Lorg/webrtc/VideoDecoder$Callback;)Lorg/webrtc/VideoCodecStatus;
Expand Down Expand Up @@ -1822,7 +1817,7 @@ public abstract interface class org/webrtc/VideoDecoderFactory {

public class org/webrtc/VideoDecoderFallback : org/webrtc/WrappedNativeVideoDecoder {
public fun <init> (Lorg/webrtc/VideoDecoder;Lorg/webrtc/VideoDecoder;)V
public fun createNativeVideoDecoder ()J
public fun createNative (J)J
}

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

public abstract class org/webrtc/WrappedNativeVideoDecoder : org/webrtc/VideoDecoder {
public fun <init> ()V
public abstract fun createNativeVideoDecoder ()J
public abstract fun createNative (J)J
public final fun decode (Lorg/webrtc/EncodedImage;Lorg/webrtc/VideoDecoder$DecodeInfo;)Lorg/webrtc/VideoCodecStatus;
public final fun getImplementationName ()Ljava/lang/String;
public final fun initDecode (Lorg/webrtc/VideoDecoder$Settings;Lorg/webrtc/VideoDecoder$Callback;)Lorg/webrtc/VideoCodecStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
*
Expand All @@ -12,7 +13,7 @@

public class Dav1dDecoder extends WrappedNativeVideoDecoder {
@Override
public long createNativeVideoDecoder() {
public long createNative(long webrtcEnvRef) {
return nativeCreateDecoder();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

public class LibvpxVp8Decoder extends WrappedNativeVideoDecoder {
@Override
public long createNativeVideoDecoder() {
return nativeCreateDecoder();
public long createNative(long webrtcEnvRef) {
return nativeCreateDecoder(webrtcEnvRef);
}

static native long nativeCreateDecoder();
}
static native long nativeCreateDecoder(long webrtcEnvRef);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

public class LibvpxVp9Decoder extends WrappedNativeVideoDecoder {
@Override
public long createNativeVideoDecoder() {
public long createNative(long webrtcEnvRef) {
return nativeCreateDecoder();
}

static native long nativeCreateDecoder();

static native boolean nativeIsSupported();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
package org.webrtc;

import androidx.annotation.Nullable;
import java.util.Arrays;
import java.util.List;

public class SoftwareVideoDecoderFactory implements VideoDecoderFactory {
Expand All @@ -26,16 +25,14 @@ public SoftwareVideoDecoderFactory() {
@Nullable
@Override
public VideoDecoder createDecoder(VideoCodecInfo info) {
long nativeDecoder = nativeCreateDecoder(nativeFactory, info);
if (nativeDecoder == 0) {
if (!nativeIsSupported(nativeFactory, info)) {
Logging.w(TAG, "Trying to create decoder for unsupported format. " + info);
return null;
}

return new WrappedNativeVideoDecoder() {
@Override
public long createNativeVideoDecoder() {
return nativeDecoder;
public long createNative(long webrtcEnvRef) {
return nativeCreate(nativeFactory, webrtcEnvRef, info);
}
};
}
Expand All @@ -47,7 +44,10 @@ public VideoCodecInfo[] getSupportedCodecs() {

private static native long nativeCreateFactory();

private static native long nativeCreateDecoder(long factory, VideoCodecInfo videoCodecInfo);
private static native boolean nativeIsSupported(long factory, VideoCodecInfo info);

private static native long nativeCreate(
long factory, long webrtcEnvRef, VideoCodecInfo info);

private static native List<VideoCodecInfo> nativeGetSupportedCodecs(long factory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public interface Callback {
* 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.
* For case 1), createNative() 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.
* For case 2), createNative() 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
Expand All @@ -69,7 +69,7 @@ public interface Callback {
* UnsupportedOperationException.
*/
@CalledByNative
default long createNativeVideoDecoder() {
default long createNative(long webrtcEnvRef) {
return 0;
}

Expand All @@ -91,4 +91,4 @@ default long createNativeVideoDecoder() {
* called from arbitrary thread.
*/
@CalledByNative String getImplementationName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public VideoDecoderFallback(VideoDecoder fallback, VideoDecoder primary) {
}

@Override
public long createNativeVideoDecoder() {
return nativeCreateDecoder(fallback, primary);
public long createNative(long webrtcEnvRef) {
return nativeCreate(webrtcEnvRef, fallback, primary);
}

private static native long nativeCreateDecoder(VideoDecoder fallback, VideoDecoder primary);
}
private static native long nativeCreate(
long webrtcEnvRef, VideoDecoder fallback, VideoDecoder primary);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Wraps a native webrtc::VideoDecoder.
*/
public abstract class WrappedNativeVideoDecoder implements VideoDecoder {
@Override public abstract long createNativeVideoDecoder();
@Override public abstract long createNative(long webrtcEnvRef);

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

0 comments on commit 811857a

Please sign in to comment.