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 for audio only #112

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:

- name: Install Dependencies
run: |
sudo apt-get remove python3-typing-extensions
sudo apt-get update
sudo apt-get install -y python3-pip python3-dev libffi-dev libssl-dev
sudo apt-get remove --purge python3-typing-extensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ public WebRTCClientBuilder setVideoSource(IWebRTCClient.StreamSource rearCamera)
return this;
}

public WebRTCClientBuilder audioOnly() {
webRTCClientConfig.audioOnly = true;
webRTCClientConfig.videoCallEnabled = false; // do not send video
return this;
}

public WebRTCClientBuilder setBluetoothEnabled(boolean bluetoothEnabled) {
webRTCClientConfig.bluetoothEnabled = bluetoothEnabled;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public class WebRTCClientConfig {
*/
public IWebRTCClient.StreamSource videoSource = IWebRTCClient.StreamSource.FRONT_CAMERA;

/*
* no video will be sent or recieved
*/
public boolean audioOnly = false;

/*
* Flag indicating whether initate WebRTCClient (renderers, websocket, capturers etc.) before stream publish starts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.webrtc.RtpParameters;
import org.webrtc.RtpReceiver;
import org.webrtc.RtpSender;
import org.webrtc.RtpTransceiver;
import org.webrtc.ScreenCapturerAndroid;
import org.webrtc.SdpObserver;
import org.webrtc.SessionDescription;
Expand Down Expand Up @@ -2332,6 +2333,13 @@ public void createAnswer(String streamId) {
if (pc != null) {
Log.d(TAG, "PC create ANSWER");
isInitiator = false;
if(config.audioOnly){
for (RtpTransceiver trans:pc.getTransceivers()) {
if(trans.getMediaType() == MediaStreamTrack.MediaType.MEDIA_TYPE_VIDEO){
trans.setDirection(RtpTransceiver.RtpTransceiverDirection.INACTIVE);
}
}
}
pc.createAnswer(getSdpObserver(streamId), sdpMediaConstraints);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,47 @@ public void testOnTakeConfiguration() {
verify(webRTCClient, times(1)).setRemoteDescription(streamId, sdpAnswer);
verify(webRTCClient, times(1)).createAnswer(streamId);
}
@Test
public void audioOnlyTest() throws InterruptedException{

PeerConnection pc = mock(PeerConnection.class);
webRTCClient.addPeerConnection("test",pc);
webRTCClient.getConfig().audioOnly = true;

List<RtpTransceiver> transceivers = new ArrayList<>();

RtpTransceiver videoTransceiver1 = mock(RtpTransceiver.class);
doReturn(MediaStreamTrack.MediaType.MEDIA_TYPE_VIDEO).when(videoTransceiver1).getMediaType();
doReturn(true).when(videoTransceiver1).setDirection(any());
transceivers.add(videoTransceiver1);

RtpTransceiver videoTransceiver2 = mock(RtpTransceiver.class);
doReturn(MediaStreamTrack.MediaType.MEDIA_TYPE_VIDEO).when(videoTransceiver2).getMediaType();
doReturn(true).when(videoTransceiver2).setDirection(any());
transceivers.add(videoTransceiver2);

RtpTransceiver videoTransceiver3 = mock(RtpTransceiver.class);
doReturn(MediaStreamTrack.MediaType.MEDIA_TYPE_VIDEO).when(videoTransceiver3).getMediaType();
doReturn(true).when(videoTransceiver3).setDirection(any());
transceivers.add(videoTransceiver3);

RtpTransceiver audioTransceiver = mock(RtpTransceiver.class);
doReturn(MediaStreamTrack.MediaType.MEDIA_TYPE_AUDIO).when(audioTransceiver).getMediaType();
doReturn(true).when(audioTransceiver).setDirection(any());
transceivers.add(audioTransceiver);

doReturn(transceivers).when(pc).getTransceivers();

webRTCClient.createAnswer("test");
Thread.sleep(3000);

verify(videoTransceiver1).setDirection(RtpTransceiver.RtpTransceiverDirection.INACTIVE);
verify(videoTransceiver2).setDirection(RtpTransceiver.RtpTransceiverDirection.INACTIVE);
verify(videoTransceiver3).setDirection(RtpTransceiver.RtpTransceiverDirection.INACTIVE);

verify(audioTransceiver,times(0)).setDirection(RtpTransceiver.RtpTransceiverDirection.INACTIVE);

}

@Test
public void testDatachannel() {
Expand Down
Loading