62
62
import org .webrtc .SdpObserver ;
63
63
import org .webrtc .SessionDescription ;
64
64
import org .webrtc .SessionDescription .Type ;
65
+ import org .webrtc .SoftwareVideoDecoderFactory ;
66
+ import org .webrtc .SoftwareVideoEncoderFactory ;
65
67
import org .webrtc .VideoTrack ;
66
68
import org .webrtc .WrappedVideoDecoderFactory ;
67
69
import org .webrtc .audio .AudioDeviceModule ;
@@ -138,7 +140,7 @@ void dispose() {
138
140
mPeerConnectionObservers .clear ();
139
141
}
140
142
141
- private void initialize (int networkIgnoreMask ) {
143
+ private void initialize (int networkIgnoreMask , boolean forceSWCodec ) {
142
144
if (mFactory != null ) {
143
145
return ;
144
146
}
@@ -148,8 +150,7 @@ private void initialize(int networkIgnoreMask) {
148
150
.setEnableInternalTracer (true )
149
151
.createInitializationOptions ());
150
152
151
- // Initialize EGL contexts required for HW acceleration.
152
- EglBase .Context eglContext = EglUtils .getRootEglBaseContext ();
153
+
153
154
154
155
getUserMediaImpl = new GetUserMediaImpl (this , context );
155
156
@@ -166,12 +167,25 @@ private void initialize(int networkIgnoreMask) {
166
167
final Options options = new Options ();
167
168
options .networkIgnoreMask = networkIgnoreMask ;
168
169
169
- mFactory = PeerConnectionFactory .builder ()
170
- .setOptions (options )
171
- .setVideoEncoderFactory (new SimulcastVideoEncoderFactoryWrapper (eglContext , true , true ))
172
- .setVideoDecoderFactory (new WrappedVideoDecoderFactory (eglContext ))
170
+ final PeerConnectionFactory .Builder factoryBuilder = PeerConnectionFactory .builder ()
171
+ .setOptions (options );
172
+
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 ();
180
+
181
+ factoryBuilder
182
+ .setVideoEncoderFactory (new SimulcastVideoEncoderFactoryWrapper (eglContext , true , true ))
183
+ .setVideoDecoderFactory (new WrappedVideoDecoderFactory (eglContext ));
184
+ }
185
+ mFactory = factoryBuilder
173
186
.setAudioDeviceModule (audioDeviceModule )
174
187
.createPeerConnectionFactory ();
188
+
175
189
}
176
190
177
191
@ Override
@@ -212,7 +226,13 @@ public void onMethodCall(MethodCall call, @NonNull Result notSafeResult) {
212
226
213
227
}
214
228
}
215
- initialize (networkIgnoreMask );
229
+ boolean forceSWCodec = false ;
230
+ if (constraintsMap .hasKey ("forceSWCodec" )
231
+ && constraintsMap .getType ("forceSWCodec" ) == ObjectType .Boolean ) {
232
+ final boolean v = constraintsMap .getBoolean ("forceSWCodec" );
233
+ forceSWCodec = v ;
234
+ }
235
+ initialize (networkIgnoreMask ,forceSWCodec );
216
236
result .success (null );
217
237
break ;
218
238
}
0 commit comments