Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to set degradation parameter #41

Merged
merged 9 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2320,6 +2320,28 @@ private boolean isDataChannelCreator() {
|| streamMode.equals(IWebRTCClient.MODE_TRACK_BASED_CONFERENCE);
}

public void setDegradationPreference(String streamId , RtpParameters.DegradationPreference degradationPreference) {

if (context == null || peers.get(streamId) == null || peers.get(streamId).peerConnection == null) {
Log.d(TAG, "Cannot set Degradation Preference");
return;
}
PeerConnection peerConnection = peers.get(streamId).peerConnection;

for (RtpSender sender : peerConnection.getSenders()) {
if (sender.track() != null) {
String trackType = sender.track().kind();
if (trackType.equals(VIDEO_TRACK_TYPE)) {
RtpParameters newParameters = sender.getParameters();
if(newParameters != null) {
newParameters.degradationPreference = degradationPreference;
sender.setParameters(newParameters);
}
}
}
}
}

private File createRtcEventLogOutputFile() {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_hhmm_ss", Locale.getDefault());
Date date = new Date();
Expand Down Expand Up @@ -2425,11 +2447,10 @@ public boolean isHDVideo() {
}

public void getStats(String streamId) {
PeerConnection pc = peers.get(streamId).peerConnection;
if (pc == null || isError) {
if (peers.get(streamId) == null || peers.get(streamId).peerConnection == null) {
return;
}
pc.getStats(this::onPeerConnectionStatsReady);
peers.get(streamId).peerConnection.getStats(this::onPeerConnectionStatsReady);
}

public void enableStatsEvents(String streamId, boolean enable, int periodMs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@
import org.webrtc.IceCandidate;
import org.webrtc.IceCandidateErrorEvent;
import org.webrtc.MediaStream;
import org.webrtc.MediaStreamTrack;
import org.webrtc.PeerConnection;
import org.webrtc.PeerConnectionFactory;
import org.webrtc.RtpParameters;
import org.webrtc.RtpReceiver;
import org.webrtc.RtpSender;
import org.webrtc.RtpTransceiver;
import org.webrtc.ScreenCapturerAndroid;
import org.webrtc.SessionDescription;
Expand Down Expand Up @@ -898,12 +901,12 @@ public void testCreatePeerConnection() {
doNothing().when(webRTCClient).createMediaConstraintsInternal();
doNothing().when(webRTCClient).createPeerConnectionInternal(streamId);
doNothing().when(webRTCClient).maybeCreateAndStartRtcEventLog(streamId);
doNothing().when(webRTCClient).reportError(anyString(), anyString());

webRTCClient.createPeerConnection(streamId);

verify(webRTCClient, never()).reportError(eq(streamId), anyString());

doNothing().when(webRTCClient).reportError(anyString(), anyString());
doThrow(new NullPointerException()).when(webRTCClient).createMediaConstraintsInternal();
webRTCClient.createPeerConnection(streamId);
verify(webRTCClient, timeout(10000)).reportError(eq(streamId), anyString());
Expand Down Expand Up @@ -1114,11 +1117,46 @@ public void testAddRemoveRemoteIceCandidate() {
webRTCClient.removeRemoteIceCandidates(streamId, iceCandidatesTorRemove);

verify(pc, timeout(1000).times(1)).removeIceCandidates(any());
}

@Test
public void testDegradationPreference() {
String streamId = "stream1";

IWebRTCListener listener = Mockito.mock(IWebRTCListener.class);
WebRTCClient webRTCClientReal = new WebRTCClient(listener, mock(Context.class));
WebSocketHandler wsHandler = mock(WebSocketHandler.class);
webRTCClientReal.setWsHandler(wsHandler);

WebRTCClient webRTCClient = spy(webRTCClientReal);
final Handler handler = getMockHandler();
webRTCClient.setHandler(handler);

RtpParameters.DegradationPreference degradationPreference = RtpParameters.DegradationPreference.BALANCED;
webRTCClient.setDegradationPreference(streamId, degradationPreference);
//will return imediately

WebRTCClient.PeerInfo peerInfo = new WebRTCClient.PeerInfo(streamId, IWebRTCClient.MODE_PUBLISH);
webRTCClient.peers.put(streamId, peerInfo);

PeerConnection pc = mock(PeerConnection.class);
peerInfo.peerConnection = pc;

List<RtpSender> senders = new ArrayList<>();
RtpSender sender = mock(RtpSender.class);
senders.add(sender);
when(pc.getSenders()).thenReturn(senders);

MediaStreamTrack track = mock(MediaStreamTrack.class);
when(sender.track()).thenReturn(track);

when(track.kind()).thenReturn(WebRTCClient.VIDEO_TRACK_TYPE);

}
RtpParameters parameters = mock(RtpParameters.class);
when(sender.getParameters()).thenReturn(parameters);

webRTCClient.setDegradationPreference(streamId, degradationPreference);

verify(sender, timeout(1000).times(1)).setParameters(parameters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public void onIceDisconnected(String streamId) {
}

public void makeToast(String messageText, int lengthLong) {
Toast.makeText(this, messageText, lengthLong).show();
runOnUiThread(() -> Toast.makeText(AbstractSampleSDKActivity.this, messageText, lengthLong).show());
}

@Override
Expand Down