diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 1a4c7e93..377ba034 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -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 diff --git a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/WebRTCClientBuilder.java b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/WebRTCClientBuilder.java index c022b3a8..08fab50e 100644 --- a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/WebRTCClientBuilder.java +++ b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/WebRTCClientBuilder.java @@ -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; diff --git a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/WebRTCClientConfig.java b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/WebRTCClientConfig.java index 531f6abb..fe1fa27f 100644 --- a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/WebRTCClientConfig.java +++ b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/WebRTCClientConfig.java @@ -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 diff --git a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/core/WebRTCClient.java b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/core/WebRTCClient.java index c625c1e7..1cc32df5 100644 --- a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/core/WebRTCClient.java +++ b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/core/WebRTCClient.java @@ -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; @@ -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); } }); diff --git a/webrtc-android-framework/src/test/java/io/antmedia/webrtcandroidframework/WebRTCClientTest.java b/webrtc-android-framework/src/test/java/io/antmedia/webrtcandroidframework/WebRTCClientTest.java index 36dfefa7..db73f4cd 100644 --- a/webrtc-android-framework/src/test/java/io/antmedia/webrtcandroidframework/WebRTCClientTest.java +++ b/webrtc-android-framework/src/test/java/io/antmedia/webrtcandroidframework/WebRTCClientTest.java @@ -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 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() {