68
68
import org .webrtc .WrappedVideoDecoderFactory ;
69
69
import org .webrtc .audio .AudioDeviceModule ;
70
70
import org .webrtc .audio .JavaAudioDeviceModule ;
71
+ import org .webrtc .video .CustomVideoDecoderFactory ;
72
+ import org .webrtc .video .CustomVideoEncoderFactory ;
71
73
72
74
import java .io .File ;
73
75
import java .io .UnsupportedEncodingException ;
@@ -112,6 +114,10 @@ public class MethodCallHandlerImpl implements MethodCallHandler, StateProvider {
112
114
113
115
private Activity activity ;
114
116
117
+ private CustomVideoEncoderFactory videoEncoderFactory ;
118
+
119
+ private CustomVideoDecoderFactory videoDecoderFactory ;
120
+
115
121
MethodCallHandlerImpl (Context context , BinaryMessenger messenger , TextureRegistry textureRegistry ) {
116
122
this .context = context ;
117
123
this .textures = textureRegistry ;
@@ -140,7 +146,7 @@ void dispose() {
140
146
mPeerConnectionObservers .clear ();
141
147
}
142
148
143
- private void initialize (int networkIgnoreMask , boolean forceSWCodec ) {
149
+ private void initialize (int networkIgnoreMask , boolean forceSWCodec , List < String > forceSWCodecList ) {
144
150
if (mFactory != null ) {
145
151
return ;
146
152
}
@@ -150,8 +156,6 @@ private void initialize(int networkIgnoreMask, boolean forceSWCodec) {
150
156
.setEnableInternalTracer (true )
151
157
.createInitializationOptions ());
152
158
153
-
154
-
155
159
getUserMediaImpl = new GetUserMediaImpl (this , context );
156
160
157
161
frameCryptor = new FlutterRTCFrameCryptor (this );
@@ -170,18 +174,21 @@ private void initialize(int networkIgnoreMask, boolean forceSWCodec) {
170
174
final PeerConnectionFactory .Builder factoryBuilder = PeerConnectionFactory .builder ()
171
175
.setOptions (options );
172
176
173
- if (forceSWCodec ) {
174
- factoryBuilder
175
- .setVideoEncoderFactory (new SoftwareVideoEncoderFactory ())
176
- .setVideoDecoderFactory (new SoftwareVideoDecoderFactory ());
177
- } else {
178
- // Initialize EGL contexts required for HW acceleration.
179
- EglBase .Context eglContext = EglUtils .getRootEglBaseContext ();
177
+ // Initialize EGL contexts required for HW acceleration.
178
+ EglBase .Context eglContext = EglUtils .getRootEglBaseContext ();
179
+
180
+ videoEncoderFactory = new CustomVideoEncoderFactory (eglContext , true , true );
181
+ videoDecoderFactory = new CustomVideoDecoderFactory (eglContext );
182
+
183
+ factoryBuilder
184
+ .setVideoEncoderFactory (videoEncoderFactory )
185
+ .setVideoDecoderFactory (videoDecoderFactory );
186
+
187
+ videoDecoderFactory .setForceSWCodec (forceSWCodec );
188
+ videoDecoderFactory .setForceSWCodecList (forceSWCodecList );
189
+ videoEncoderFactory .setForceSWCodec (forceSWCodec );
190
+ videoEncoderFactory .setForceSWCodecList (forceSWCodecList );
180
191
181
- factoryBuilder
182
- .setVideoEncoderFactory (new SimulcastVideoEncoderFactoryWrapper (eglContext , true , true ))
183
- .setVideoDecoderFactory (new WrappedVideoDecoderFactory (eglContext ));
184
- }
185
192
mFactory = factoryBuilder
186
193
.setAudioDeviceModule (audioDeviceModule )
187
194
.createPeerConnectionFactory ();
@@ -232,7 +239,18 @@ public void onMethodCall(MethodCall call, @NonNull Result notSafeResult) {
232
239
final boolean v = constraintsMap .getBoolean ("forceSWCodec" );
233
240
forceSWCodec = v ;
234
241
}
235
- initialize (networkIgnoreMask ,forceSWCodec );
242
+ List <String > forceSWCodecList = new ArrayList <>();
243
+ if (constraintsMap .hasKey ("forceSWCodecList" )
244
+ && constraintsMap .getType ("forceSWCodecList" ) == ObjectType .Array ) {
245
+ final List <Object > array = constraintsMap .getListArray ("forceSWCodecList" );
246
+ for (Object v : array ) {
247
+ forceSWCodecList .add (v .toString ());
248
+ }
249
+ } else {
250
+ // disable HW Codec for VP9 by default.
251
+ forceSWCodecList .add ("VP9" );
252
+ }
253
+ initialize (networkIgnoreMask ,forceSWCodec , forceSWC
57AE
odecList );
236
254
result .success (null );
237
255
break ;
238
256
}
0 commit comments