Skip to content

Commit 7a30661

Browse files
committed
add custom encoder factory
1 parent 755b379 commit 7a30661

File tree

6 files changed

+330
-111
lines changed

6 files changed

+330
-111
lines changed

webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/core/AMSDefaultVideoDecoderFactory.java

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

webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/core/AMSHardwareVideoEncoderFactory.java

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

webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/core/WebRTCClient.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import android.util.DisplayMetrics;
1717
import android.util.Log;
1818
import android.view.WindowManager;
19-
import android.widget.GridLayout;
2019
import android.widget.Toast;
2120

2221
import androidx.annotation.NonNull;
@@ -31,8 +30,6 @@
3130
import org.webrtc.CameraVideoCapturer;
3231
import org.webrtc.CandidatePairChangeEvent;
3332
import org.webrtc.DataChannel;
34-
import org.webrtc.DefaultVideoDecoderFactory;
35-
import org.webrtc.DefaultVideoEncoderFactory;
3633
import org.webrtc.EglBase;
3734
import org.webrtc.IceCandidate;
3835
import org.webrtc.IceCandidateErrorEvent;
@@ -84,6 +81,8 @@
8481
import io.antmedia.webrtcandroidframework.api.IWebRTCClient;
8582
import io.antmedia.webrtcandroidframework.api.WebRTCClientConfig;
8683
import io.antmedia.webrtcandroidframework.apprtc.AppRTCAudioManager;
84+
import org.webrtc.AMSDefaultVideoDecoderFactory;
85+
import org.webrtc.AMSDefaultVideoEncoderFactory;
8786
import io.antmedia.webrtcandroidframework.websocket.AntMediaSignallingEvents;
8887
import io.antmedia.webrtcandroidframework.websocket.Broadcast;
8988
import io.antmedia.webrtcandroidframework.websocket.WebSocketHandler;
@@ -1897,7 +1896,7 @@ private void createPeerConnectionFactoryInternal(PeerConnectionFactory.Options o
18971896
final VideoDecoderFactory decoderFactory;
18981897

18991898
if (config.hwCodecAcceleration) {
1900-
encoderFactory = new AMSDefaultVideoEncoderFactory(eglBase.getEglBaseContext(), false /* enableIntelVp8Encoder */, true);
1899+
encoderFactory = new AMSDefaultVideoEncoderFactory(eglBase.getEglBaseContext(), true /* enableIntelVp8Encoder */, enableH264HighProfile);
19011900
decoderFactory = new AMSDefaultVideoDecoderFactory(eglBase.getEglBaseContext());
19021901
} else {
19031902
encoderFactory = new SoftwareVideoEncoderFactory();
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.webrtc;
2+
3+
import androidx.annotation.Nullable;
4+
5+
import java.util.Arrays;
6+
import java.util.LinkedHashSet;
7+
8+
public class AMSDefaultVideoDecoderFactory implements VideoDecoderFactory {
9+
private final VideoDecoderFactory hardwareVideoDecoderFactory;
10+
private final VideoDecoderFactory softwareVideoDecoderFactory = new SoftwareVideoDecoderFactory();
11+
private final @Nullable VideoDecoderFactory platformSoftwareVideoDecoderFactory;
12+
13+
/**
14+
* Create decoder factory using default hardware decoder factory.
15+
*/
16+
public AMSDefaultVideoDecoderFactory(@Nullable EglBase.Context eglContext) {
17+
this.hardwareVideoDecoderFactory = new HardwareVideoDecoderFactory(eglContext);
18+
this.platformSoftwareVideoDecoderFactory = new PlatformSoftwareVideoDecoderFactory(eglContext);
19+
}
20+
21+
/**
22+
* Create decoder factory using explicit hardware decoder factory.
23+
*/
24+
AMSDefaultVideoDecoderFactory(VideoDecoderFactory hardwareVideoDecoderFactory) {
25+
this.hardwareVideoDecoderFactory = hardwareVideoDecoderFactory;
26+
this.platformSoftwareVideoDecoderFactory = null;
27+
}
28+
29+
@Override
30+
public @Nullable VideoDecoder createDecoder(VideoCodecInfo codecType) {
31+
VideoDecoder softwareDecoder = softwareVideoDecoderFactory.createDecoder(codecType);
32+
final VideoDecoder hardwareDecoder = hardwareVideoDecoderFactory.createDecoder(codecType);
33+
if (softwareDecoder == null && platformSoftwareVideoDecoderFactory != null) {
34+
softwareDecoder = platformSoftwareVideoDecoderFactory.createDecoder(codecType);
35+
}
36+
if (hardwareDecoder != null && softwareDecoder != null) {
37+
// Both hardware and software supported, wrap it in a software fallback
38+
return new VideoDecoderFallback(
39+
/* fallback= */ softwareDecoder, /* primary= */ hardwareDecoder);
40+
}
41+
return hardwareDecoder != null ? hardwareDecoder : softwareDecoder;
42+
}
43+
44+
@Override
45+
public VideoCodecInfo[] getSupportedCodecs() {
46+
LinkedHashSet<VideoCodecInfo> supportedCodecInfos = new LinkedHashSet<VideoCodecInfo>();
47+
48+
supportedCodecInfos.addAll(Arrays.asList(softwareVideoDecoderFactory.getSupportedCodecs()));
49+
supportedCodecInfos.addAll(Arrays.asList(hardwareVideoDecoderFactory.getSupportedCodecs()));
50+
if (platformSoftwareVideoDecoderFactory != null) {
51+
supportedCodecInfos.addAll(
52+
Arrays.asList(platformSoftwareVideoDecoderFactory.getSupportedCodecs()));
53+
}
54+
55+
return supportedCodecInfos.toArray(new VideoCodecInfo[supportedCodecInfos.size()]);
56+
}
57+
}
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
package io.antmedia.webrtcandroidframework.core;
1+
package org.webrtc;
22

33
import androidx.annotation.Nullable;
44

5-
import org.webrtc.EglBase;
6-
import org.webrtc.HardwareVideoEncoderFactory;
7-
import org.webrtc.SoftwareVideoEncoderFactory;
8-
import org.webrtc.VideoCodecInfo;
9-
import org.webrtc.VideoEncoder;
10-
import org.webrtc.VideoEncoderFactory;
11-
import org.webrtc.VideoEncoderFallback;
12-
135
import java.util.Arrays;
146
import java.util.LinkedHashSet;
157

0 commit comments

Comments
 (0)