diff --git a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/DefaultConferenceWebRTCListener.java b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/DefaultConferenceWebRTCListener.java index c06b03c7..d5254719 100644 --- a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/DefaultConferenceWebRTCListener.java +++ b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/DefaultConferenceWebRTCListener.java @@ -4,6 +4,10 @@ import android.os.Handler; import android.util.Log; +/** + * Default implementation of {@link IWebRTCListener} for conference applications + * You may extend this class and override methods that you need + */ public class DefaultConferenceWebRTCListener extends DefaultWebRTCListener { private final String roomId; private final String streamId; diff --git a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/DefaultDataChannelObserver.java b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/DefaultDataChannelObserver.java index aa70d311..c028fed9 100644 --- a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/DefaultDataChannelObserver.java +++ b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/DefaultDataChannelObserver.java @@ -9,6 +9,10 @@ import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; +/** + * Default implementation of {@link IDataChannelObserver} + * You may extend this class and override methods that you need + */ public class DefaultDataChannelObserver implements IDataChannelObserver { @Override public void onBufferedAmountChange(long previousAmount, String dataChannelLabel) { diff --git a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/DefaultWebRTCListener.java b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/DefaultWebRTCListener.java index 840edcec..daef43b8 100644 --- a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/DefaultWebRTCListener.java +++ b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/DefaultWebRTCListener.java @@ -10,6 +10,10 @@ import de.tavendo.autobahn.WebSocket; import io.antmedia.webrtcandroidframework.core.StreamInfo; +/** + * Default implementation of {@link IWebRTCListener} + * You may extend this class and override methods that you need + */ public class DefaultWebRTCListener implements IWebRTCListener { protected IWebRTCClient webRTCClient; diff --git a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IDataChannelObserver.java b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IDataChannelObserver.java index 121192fa..0076c451 100644 --- a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IDataChannelObserver.java +++ b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IDataChannelObserver.java @@ -2,6 +2,10 @@ import org.webrtc.DataChannel; +/** + * This interface is used to observe the data channel events + * You can use this interface to observe the data channel events or you can extend {@link DefaultDataChannelObserver} + */ public interface IDataChannelObserver { /** The data channel's bufferedAmount has changed. */ diff --git a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IWebRTCClient.java b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IWebRTCClient.java index 03a8cfca..54ffea6a 100644 --- a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IWebRTCClient.java +++ b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IWebRTCClient.java @@ -11,6 +11,10 @@ */ public interface IWebRTCClient { + + /** + * This enum is used to specify the stream source + */ enum StreamSource { SCREEN, @@ -19,178 +23,201 @@ enum StreamSource CUSTOM } + /** + * This method is used to initialize the WebRTCClient and configure it + */ + static WebRTCClientBuilder builder() { + return new WebRTCClientBuilder(); + } /** - * Switches the cameras + * This is used to strart a WebRTC publish stream + * @param streamId: any name */ - void switchCamera(); + void publish(String streamId); /** - * toggle microphone - * @return + * This is used to strart a WebRTC publish stream + * @param streamId: id for the stream to publish + * @param token: token to authenticate + * @param videoCallEnabled: true if it's a video call + * @param audioCallEnabled: true if it's an audio call + * @param subscriberId: id of the subscriber + * @param subscriberCode: code of the subscriber + * @param streamName: name of the stream + * @param mainTrackId: id of the main track */ - boolean toggleMic(); + void publish(String streamId, String token, boolean videoCallEnabled, boolean audioCallEnabled, + String subscriberId, String subscriberCode, String streamName, String mainTrackId); + /** - * Stops the video source + * This is used to play a WebRTC stream + * @param streamId: id for the stream to play */ - void stopVideoSource(); + void play(String streamId); /** - * Starts or restarts the video source + * This is used to play a multitrack WebRTC stream + * @param streamId: id for the stream to play + * @param tracks: subtracks to play in multitrack stream */ - void startVideoSource(); + void play(String streamId, String[] tracks); /** - * Swapeed the fullscreen renderer and pip renderer - * @param b + * This is used to play a WebRTC stream with all parameters + * @param streamId: id for the stream to play + * @param token: token to authenticate + * @param tracks: subtracks to play in multitrack stream + * @param subscriberId: id of the subscriber + * @param subscriberCode: code of the subscriber + * @param viewerInfo: viewer info, any string is accepted */ - void setSwappedFeeds(boolean b); + void play(String streamId, String token, String[] tracks, String subscriberId, String subscriberCode, String viewerInfo); /** - * Get the error - * @return error or null if not + * This is used to join a peer to peer call + * @param streamId: id for the call */ - String getError(); + void join(String streamId); /** - * Return if data channel is enabled and open - * @return true if data channel is available - * false if it's not opened either by mobile or server side + * This is used to join a conference room + * @param roomId: id for the conference room + * @param streamId: id for the participant */ - boolean isDataChannelEnabled(); + void joinToConferenceRoom(String roomId, String streamId); /** - * This is used to get stream info list + * This is used to leave from a conference room + * @param roomId: id for the conference room */ - void getStreamInfoList(String streamId); + void leaveFromConference(String roomId); /** - * This is used to play the specified resolution - * @param height + * This is used to stop a stream publishing, playing or peer to peer call + * @param streamId id for the stream */ - void forceStreamQuality(String streamId, int height); - - //FIXME: add comment - void onCameraSwitch(); - void onCaptureFormatChange(int width, int height, int framerate); - boolean onToggleMic(); - - static WebRTCClientBuilder builder() { - return new WebRTCClientBuilder(); - } + void stop(String streamId); /** - * This is used to strart a WebRTC publish stream - * @param streamId: any name + * This is used to send data via data channel + * @param streamId: id for the stream + * @param buffer: data to send */ - void publish(String streamId); - + void sendMessageViaDataChannel(String streamId, DataChannel.Buffer buffer); /** - * This is used to strart a WebRTC publish stream - * @param streamId: any name - * @param token: token for stream - * TODO: add comment + * This is used to change video source on the fly + * @param newSource: may be front camera, rear camera, screen or custom source which provides video frames */ - void publish(String streamId, String token, boolean videoCallEnabled, boolean audioCallEnabled, - String subscriberId, String subscriberCode, String streamName, String mainTrackId); - + void changeVideoSource(StreamSource newSource); /** - * This is used to play a WebRTC stream - * @param streamId + * This is used to play the specified resolution + * @param streamId: id for the stream + * @param height: desired height to play */ - void play(String streamId); + void forceStreamQuality(String streamId, int height); /** - * This is used to play a multitrack WebRTC stream - * @param streamId + * enable/disable video stream + * @param enabled true for enable, false for disable */ - void play(String streamId, String[] tracks); + void setVideoEnabled(boolean enabled); /** - * This is used to play a WebRTC stream with all parameters - * @param streamId + * enable/disable audio stream + * @param enabled true for enable, false for disable */ - void play(String streamId, String token, String[] tracks, String subscriberId, String subscriberCode, String viewerInfo); + void setAudioEnabled(boolean enabled); + /** + * enable/disable played track stream from the server + * @param streamId id for the main track + * @param selecetedTrack id for the subtrack + * @param enabled true for enable, false for disable + */ + void enableTrack(String streamId, String selecetedTrack, boolean enabled); + /** + * Called to set the renderer for a video track + * @param renderer: renderer for the video track + * @param videoTrack: video track to set + */ + void setRendererForVideoTrack(SurfaceViewRenderer renderer, VideoTrack videoTrack); /** - * This is used to get streaming status for a stream id - * @param streamId - * @return + * Called to swap the local renderer with the first remote renderer + * @param isSwappedFeeds: true if it's swapped */ - boolean isStreaming(String streamId); + void setSwappedFeeds(boolean isSwappedFeeds); /** - * This is used to join a conference room - * @param roomId - * @param streamId - * @return + * Switches the front and rear camera */ - void joinToConferenceRoom(String roomId, String streamId); + void switchCamera(); /** - * This is used to leave from a conference room - * @param roomId + * Return if data channel is enabled and open + * @return true if data channel is available + * false if it's not opened either by mobile or server side */ - void leaveFromConference(String roomId); + boolean isDataChannelEnabled(); /** - * This is used to send data via data channel - * @param streamId - * @param buffer + * This is used to get streaming status for a stream id + * @param streamId: id for the stream + * @return true if it's streaming at the moment */ - void sendMessageViaDataChannel(String streamId, DataChannel.Buffer buffer); + boolean isStreaming(String streamId); /** - * This is used to stop a stream - * @param streamId + * This is used to get room info from server + * @param roomId: id for the room + * @param streamId: id for the calling participant */ - void stop(String streamId); + void getRoomInfo(String roomId, String streamId); /** - * This is used to join a peer to peer stream - * @param streamId + * This is used to get stream info list for a stream from server + * @param streamId: id for the stream */ - void join(String streamId); + void getStreamInfoList(String streamId); /** * This is used to get reconnecting status + * @return true if it's reconnecting */ boolean isReconnectionInProgress(); /** - * This is used to get room info - * @param roomId - * @param streamId + * Get the error + * @return error or null if not */ - void getRoomInfo(String roomId, String streamId); + String getError(); /** - * This is used to change video source on the fly - * @param newSource + * Get the current configuration for the client + * @return current configuration */ - void changeVideoSource(StreamSource newSource); - - WebRTCClientConfig getConfig(); + /** + * Get the current video capturer, used for custom video feed + * @return current video capturer + */ VideoCapturer getVideoCapturer(); + /** + * Get the current audio input, used for custom audio feed + * @return current audio input + */ CustomWebRtcAudioRecord getAudioInput(); - void setVideoEnabled(boolean b); - - void setAudioEnabled(boolean b); - - void enableTrack(String streamId, String selecetedTrack, boolean enabled); - + /** + * Called to requesr the subtracks for a main track from server + */ void getTrackList(String streamId, String token); - - void setRendererForVideoTrack(SurfaceViewRenderer renderer, VideoTrack videoTrack); - } diff --git a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IWebRTCListener.java b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IWebRTCListener.java index 997de423..480f2cce 100644 --- a/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IWebRTCListener.java +++ b/webrtc-android-framework/src/main/java/io/antmedia/webrtcandroidframework/api/IWebRTCListener.java @@ -9,11 +9,14 @@ /** * Created by karinca on 23.10.2017. + * This interface is used to listen WebRTCClient (or SDK) events + * You may implement this interface or extend {@link DefaultWebRTCListener} class + * If you want to create a conference application, you may extend {@link DefaultConferenceWebRTCListener} class */ public interface IWebRTCListener { - /** + /** * It's called when websocket connection has been disconnected */ void onDisconnected(); @@ -108,8 +111,6 @@ public interface IWebRTCListener { */ void onReconnectionAttempt(String streamId); - - /** * It's called when joiened the room * 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 6dc3360e..8d3b7eb8 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 @@ -123,19 +123,58 @@ public class WebRTCClientConfig { */ public boolean screencaptureEnabled = false; + /* + * Data channel observer for the data channel events + */ public IDataChannelObserver dataChannelObserver = new DefaultDataChannelObserver(); - + /* + * Intent for screen capture got by calling activity + */ public Intent mediaProjectionIntent; + /* + * Media projection for screen capture + */ public MediaProjection mediaProjection; + + /* + * Current video source to publish + */ public IWebRTCClient.StreamSource videoSource; + + /* + * Flag indicating whether custom video capturer is enabled + */ public boolean customVideoCapturerEnabled; + + /* + * Flag indicating whether initate WebRTCClient (renderers, websocket, capturers etc.) before stream publish starts + */ public boolean initiateBeforeStream; + + /* + * Flag indicating whether custom audio feed is enabled + */ public boolean customAudioFeed; + + /* + * Scaling type for video rendering + */ public RendererCommon.ScalingType scalingType = RendererCommon.ScalingType.SCALE_ASPECT_FIT; + /* + * Stun server uri + */ public String stunServerUri = "stun:stun1.l.google.com:19302"; + + /* + * Flag indicating whether reconnection is enabled + */ public boolean reconnectionEnabled = true; + + /* + * Flag indicating whether AGC (automatic gain contol) and HPF (high pass filter) is disabled in audio processing + */ public boolean disableWebRtcAGCAndHPF = false; } 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 379ef1cd..431393d4 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 @@ -758,27 +758,6 @@ public VideoCapturer createCameraCapturer(CameraEnumerator enumerator) { return null; } - @Override - public void stopVideoSource() { - // Don't stop the video when using screencapture to allow user to show other apps to the remote - // end. - if (!config.screencaptureEnabled) { - executor.execute(this::stopVideoSourceInternal); - } - - localVideoSink.setTarget(null); - - } - - @Override - public void startVideoSource() { - // Video is not paused for screencapture. See onPause. - if (!config.screencaptureEnabled) { - executor.execute(this::startVideoSourceInternal); - } - } - - @Override public void setSwappedFeeds(boolean isSwappedFeeds) { localVideoSink.setTarget(isSwappedFeeds ? config.remoteVideoRenderers.get(0) : config.localVideoRenderer); remoteVideoSinks.get(0).setTarget(isSwappedFeeds ? config.localVideoRenderer : config.remoteVideoRenderers.get(0)); @@ -810,28 +789,6 @@ public void switchCamera() { executor.execute(this ::switchCameraInternal); } - @Override - public void onCameraSwitch() { - switchCamera(); - } - - @Override - public void onCaptureFormatChange(int width, int height, int framerate) { - executor.execute(() -> changeCaptureFormatInternal(width, height, framerate)); - } - - @Override - public boolean onToggleMic() { - micEnabled = !micEnabled; - setAudioEnabled(micEnabled); - return micEnabled; - } - - @Override - public boolean toggleMic() { - return onToggleMic(); - } - public void publish(String streamId) { publish(streamId, null, true, true, null, null, streamId, null);