org.webrtc.MediaConstraints Java Examples
The following examples show how to use
org.webrtc.MediaConstraints.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebRTCNativeMgr.java From appinventor-extensions with Apache License 2.0 | 7 votes |
public void initiate(ReplForm form, Context context, String code) { this.form = form; rCode = code; /* Initialize WebRTC globally */ PeerConnectionFactory.initializeAndroidGlobals(context, false); /* Setup factory options */ PeerConnectionFactory.Options options = new PeerConnectionFactory.Options(); /* Create the factory */ PeerConnectionFactory factory = new PeerConnectionFactory(options); /* Create the peer connection using the iceServers we received in the constructor */ RTCConfiguration rtcConfig = new RTCConfiguration(iceServers); rtcConfig.continualGatheringPolicy = ContinualGatheringPolicy.GATHER_CONTINUALLY; peerConnection = factory.createPeerConnection(rtcConfig, new MediaConstraints(), observer); timer.schedule(new TimerTask() { @Override public void run() { Poller(); } }, 0, 1000); // Start the Poller now and then every second }
Example #2
Source File: PeersManager.java From WebRTCapp with Apache License 2.0 | 6 votes |
public void createLocalOffer(MediaConstraints sdpConstraints) { localPeer.createOffer(new CustomSdpObserver("localCreateOffer") { @Override public void onCreateSuccess(SessionDescription sessionDescription) { super.onCreateSuccess(sessionDescription); localPeer.setLocalDescription(new CustomSdpObserver("localSetLocalDesc"), sessionDescription); Map<String, String> localOfferParams = new HashMap<>(); localOfferParams.put("audioActive", "true"); localOfferParams.put("videoActive", "true"); localOfferParams.put("doLoopback", "false"); localOfferParams.put("frameRate", "30"); localOfferParams.put("typeOfVideo", "CAMERA"); localOfferParams.put("sdpOffer", sessionDescription.description); if (webSocketAdapter.getId() > 1) { webSocketAdapter.sendJson(webSocket, "publishVideo", localOfferParams); } else { webSocketAdapter.setLocalOfferParams(localOfferParams); } } }, sdpConstraints); }
Example #3
Source File: MainActivity.java From webrtc-android-tutorial with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // create PeerConnectionFactory PeerConnectionFactory.InitializationOptions initializationOptions = PeerConnectionFactory.InitializationOptions.builder(this).createInitializationOptions(); PeerConnectionFactory.initialize(initializationOptions); PeerConnectionFactory peerConnectionFactory = PeerConnectionFactory.builder().createPeerConnectionFactory(); // create AudioSource AudioSource audioSource = peerConnectionFactory.createAudioSource(new MediaConstraints()); AudioTrack audioTrack = peerConnectionFactory.createAudioTrack("101", audioSource); EglBase.Context eglBaseContext = EglBase.create().getEglBaseContext(); SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", eglBaseContext); // create VideoCapturer VideoCapturer videoCapturer = createCameraCapturer(); VideoSource videoSource = peerConnectionFactory.createVideoSource(videoCapturer.isScreencast()); videoCapturer.initialize(surfaceTextureHelper, getApplicationContext(), videoSource.getCapturerObserver()); videoCapturer.startCapture(480, 640, 30); SurfaceViewRenderer localView = findViewById(R.id.localView); localView.setMirror(true); localView.init(eglBaseContext, null); // create VideoTrack VideoTrack videoTrack = peerConnectionFactory.createVideoTrack("100", videoSource); // display in localView videoTrack.addSink(localView); }
Example #4
Source File: WebSocketTask.java From WebRTCapp with Apache License 2.0 | 6 votes |
@Override protected void onPostExecute(Void results) { if (!isCancelled) { MediaConstraints sdpConstraints = new MediaConstraints(); sdpConstraints.mandatory.add(new MediaConstraints.KeyValuePair("offerToReceiveAudio", "true")); sdpConstraints.mandatory.add(new MediaConstraints.KeyValuePair("offerToReceiveVideo", "true")); MediaStream stream = peerConnectionFactory.createLocalMediaStream("102"); stream.addTrack(localAudioTrack); stream.addTrack(localVideoTrack); localPeer.addStream(stream); peersManager.createLocalOffer(sdpConstraints); } else { isCancelled = false; } }
Example #5
Source File: PeersManager.java From WebRTCapp with Apache License 2.0 | 6 votes |
private void createLocalPeerConnection(MediaConstraints sdpConstraints) { final List<PeerConnection.IceServer> iceServers = new ArrayList<>(); PeerConnection.IceServer iceServer = new PeerConnection.IceServer("stun:stun.l.google.com:19302"); iceServers.add(iceServer); localPeer = peerConnectionFactory.createPeerConnection(iceServers, sdpConstraints, new CustomPeerConnectionObserver("localPeerCreation") { @Override public void onIceCandidate(IceCandidate iceCandidate) { super.onIceCandidate(iceCandidate); Map<String, String> iceCandidateParams = new HashMap<>(); iceCandidateParams.put("sdpMid", iceCandidate.sdpMid); iceCandidateParams.put("sdpMLineIndex", Integer.toString(iceCandidate.sdpMLineIndex)); iceCandidateParams.put("candidate", iceCandidate.sdp); if (webSocketAdapter.getUserId() != null) { iceCandidateParams.put("endpointName", webSocketAdapter.getUserId()); webSocketAdapter.sendJson(webSocket, "onIceCandidate", iceCandidateParams); } else { webSocketAdapter.addIceCandidate(iceCandidateParams); } } }); }
Example #6
Source File: CallActivity.java From RTCStartupDemo with GNU General Public License v3.0 | 6 votes |
public void doAnswerCall() { logcatOnUI("Answer Call, Wait ..."); if (mPeerConnection == null) { mPeerConnection = createPeerConnection(); } MediaConstraints sdpMediaConstraints = new MediaConstraints(); Log.i(TAG, "Create answer ..."); mPeerConnection.createAnswer(new SimpleSdpObserver() { @Override public void onCreateSuccess(SessionDescription sessionDescription) { Log.i(TAG, "Create answer success !"); mPeerConnection.setLocalDescription(new SimpleSdpObserver(), sessionDescription); JSONObject message = new JSONObject(); try { message.put("userId", RTCSignalClient.getInstance().getUserId()); message.put("msgType", RTCSignalClient.MESSAGE_TYPE_ANSWER); message.put("sdp", sessionDescription.description); RTCSignalClient.getInstance().sendMessage(message); } catch (JSONException e) { e.printStackTrace(); } } }, sdpMediaConstraints); updateCallState(false); }
Example #7
Source File: CallActivity.java From RTCStartupDemo with GNU General Public License v3.0 | 6 votes |
public void doStartCall() { logcatOnUI("Start Call, Wait ..."); if (mPeerConnection == null) { mPeerConnection = createPeerConnection(); } MediaConstraints mediaConstraints = new MediaConstraints(); mediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true")); mediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true")); mediaConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true")); mPeerConnection.createOffer(new SimpleSdpObserver() { @Override public void onCreateSuccess(SessionDescription sessionDescription) { Log.i(TAG, "Create local offer success: \n" + sessionDescription.description); mPeerConnection.setLocalDescription(new SimpleSdpObserver(), sessionDescription); JSONObject message = new JSONObject(); try { message.put("userId", RTCSignalClient.getInstance().getUserId()); message.put("msgType", RTCSignalClient.MESSAGE_TYPE_OFFER); message.put("sdp", sessionDescription.description); RTCSignalClient.getInstance().sendMessage(message); } catch (JSONException e) { e.printStackTrace(); } } }, mediaConstraints); }
Example #8
Source File: CustomWebSocketListener.java From WebRTCapp with Apache License 2.0 | 6 votes |
private void addParticipantsAlreadyInRoom(JSONObject result, final WebSocket webSocket) throws JSONException { for (int i = 0; i < result.getJSONArray(JSONConstants.VALUE).length(); i++) { remoteParticipantId = result.getJSONArray(JSONConstants.VALUE).getJSONObject(i).getString(JSONConstants.ID); final RemoteParticipant remoteParticipant = new RemoteParticipant(); remoteParticipant.setId(remoteParticipantId); participants.put(remoteParticipantId, remoteParticipant); createVideoView(remoteParticipant); setRemoteParticipantName(new JSONObject(result.getJSONArray(JSONConstants.VALUE).getJSONObject(i).getString(JSONConstants.METADATA)).getString("clientData"), remoteParticipant); peersManager.createRemotePeerConnection(remoteParticipant); remoteParticipant.getPeerConnection().createOffer(new CustomSdpObserver("remoteCreateOffer") { @Override public void onCreateSuccess(SessionDescription sessionDescription) { super.onCreateSuccess(sessionDescription); remoteParticipant.getPeerConnection().setLocalDescription(new CustomSdpObserver("remoteSetLocalDesc"), sessionDescription); Map<String, String> remoteOfferParams = new HashMap<>(); remoteOfferParams.put("sdpOffer", sessionDescription.description); remoteOfferParams.put("sender", remoteParticipantId + "_CAMERA"); sendJson(webSocket, "receiveVideoFrom", remoteOfferParams); } }, new MediaConstraints()); } }
Example #9
Source File: WebRTCWrapper.java From Pix-Art-Messenger with GNU General Public License v3.0 | 6 votes |
ListenableFuture<SessionDescription> createOffer() { return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> { final SettableFuture<SessionDescription> future = SettableFuture.create(); peerConnection.createOffer(new CreateSdpObserver() { @Override public void onCreateSuccess(SessionDescription sessionDescription) { future.set(sessionDescription); } @Override public void onCreateFailure(String s) { future.setException(new IllegalStateException("Unable to create offer: " + s)); } }, new MediaConstraints()); return future; }, MoreExecutors.directExecutor()); }
Example #10
Source File: WebRTCWrapper.java From Pix-Art-Messenger with GNU General Public License v3.0 | 6 votes |
ListenableFuture<SessionDescription> createAnswer() { return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> { final SettableFuture<SessionDescription> future = SettableFuture.create(); peerConnection.createAnswer(new CreateSdpObserver() { @Override public void onCreateSuccess(SessionDescription sessionDescription) { future.set(sessionDescription); } @Override public void onCreateFailure(String s) { future.setException(new IllegalStateException("Unable to create answer: " + s)); } }, new MediaConstraints()); return future; }, MoreExecutors.directExecutor()); }
Example #11
Source File: PeerConnectionChannel.java From owt-client-android with Apache License 2.0 | 6 votes |
protected PeerConnectionChannel(String key, PeerConnection.RTCConfiguration configuration, boolean receiveVideo, boolean receiveAudio, PeerConnectionChannelObserver observer) { this.key = key; this.observer = observer; videoRtpSenders = new ConcurrentHashMap<>(); audioRtpSenders = new ConcurrentHashMap<>(); queuedRemoteCandidates = new LinkedList<>(); queuedMessage = new ArrayList<>(); sdpConstraints = new MediaConstraints(); sdpConstraints.mandatory.add( new KeyValuePair("OfferToReceiveAudio", String.valueOf(receiveAudio))); sdpConstraints.mandatory.add( new KeyValuePair("OfferToReceiveVideo", String.valueOf(receiveVideo))); peerConnection = PCFactoryProxy.instance().createPeerConnection(configuration, this); RCHECK(peerConnection); signalingState = peerConnection.signalingState(); }
Example #12
Source File: MainActivity.java From webrtc-android-tutorial with Apache License 2.0 | 6 votes |
@Override public void onOfferReceived(JSONObject data) { runOnUiThread(() -> { peerConnection.setRemoteDescription(new SdpAdapter("localSetRemote"), new SessionDescription(SessionDescription.Type.OFFER, data.optString("sdp"))); peerConnection.createAnswer(new SdpAdapter("localAnswerSdp") { @Override public void onCreateSuccess(SessionDescription sdp) { super.onCreateSuccess(sdp); peerConnection.setLocalDescription(new SdpAdapter("localSetLocal"), sdp); SignalingClient.get().sendSessionDescription(sdp); } }, new MediaConstraints()); }); }
Example #13
Source File: WebRTCWrapper.java From Conversations with GNU General Public License v3.0 | 6 votes |
ListenableFuture<SessionDescription> createOffer() { return Futures.transformAsync(getPeerConnectionFuture(), peerConnection -> { final SettableFuture<SessionDescription> future = SettableFuture.create(); peerConnection.createOffer(new CreateSdpObserver() { @Override public void onCreateSuccess(SessionDescription sessionDescription) { future.set(sessionDescription); } @Override public void onCreateFailure(String s) { future.setException(new IllegalStateException("Unable to create offer: " + s)); } }, new MediaConstraints()); return future; }, MoreExecutors.directExecutor()); }
Example #14
Source File: RespokeCall.java From respoke-sdk-android with MIT License | 5 votes |
@Override public void onSetSuccess() { new Handler(Looper.getMainLooper()).post(new Runnable() { public void run() { if (isActive()) { Log.d(TAG, "onSuccess(Set SDP)"); if (caller) { if (peerConnection.getRemoteDescription() != null) { // We've set our local offer and received & set the remote // answer, so drain candidates. drainRemoteCandidates(); } } else { if (peerConnection.getLocalDescription() == null) { // We just set the remote offer, time to create our answer. MediaConstraints sdpMediaConstraints = new MediaConstraints(); sdpMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair( "OfferToReceiveAudio", "true")); sdpMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair( "OfferToReceiveVideo", audioOnly ? "false" : "true")); peerConnection.createAnswer(SDPObserver.this, sdpMediaConstraints); } else { drainRemoteCandidates(); } } } } }); }
Example #15
Source File: RTCCall.java From Meshenger with GNU General Public License v3.0 | 5 votes |
private void initRTC(Context c) { log("initializing"); PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions.builder(c).createInitializationOptions()); log("initialized"); factory = PeerConnectionFactory.builder().createPeerConnectionFactory(); log("created"); constraints = new MediaConstraints(); constraints.optional.add(new MediaConstraints.KeyValuePair("offerToReceiveAudio", "true")); constraints.optional.add(new MediaConstraints.KeyValuePair("offerToReceiveVideo", "false")); constraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true")); //initVideoTrack(); }
Example #16
Source File: RespokeCall.java From respoke-sdk-android with MIT License | 5 votes |
private void createOffer() { MediaConstraints sdpMediaConstraints = new MediaConstraints(); sdpMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair( "OfferToReceiveAudio", directConnectionOnly ? "false" : "true")); sdpMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair( "OfferToReceiveVideo", (directConnectionOnly || audioOnly) ? "false" : "true")); peerConnection.createOffer(sdpObserver, sdpMediaConstraints); }
Example #17
Source File: NBMPeerConnection.java From webrtcpeer-android with Apache License 2.0 | 5 votes |
public void createAnswer(final MediaConstraints sdpMediaConstraints) { executor.execute(new Runnable() { @Override public void run() { if (pc != null){// && !isError) { Log.d(TAG, "PC create ANSWER"); isInitiator = false; pc.createAnswer(NBMPeerConnection.this, sdpMediaConstraints); } } }); }
Example #18
Source File: AndroidAudioSource.java From actor-platform with GNU Affero General Public License v3.0 | 5 votes |
public AndroidAudioSource() { this.count = 1; this.isReleased = false; MediaConstraints audioConstraints = new MediaConstraints(); audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googNoiseSuppression", "true")); audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("googEchoCancellation", "true")); this.audioSource = AndroidWebRTCRuntimeProvider.FACTORY.createAudioSource(audioConstraints); }
Example #19
Source File: PnSignalingParams.java From android-webrtc-api with MIT License | 5 votes |
private static MediaConstraints defaultPcConstraints(){ MediaConstraints pcConstraints = new MediaConstraints(); pcConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true")); pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true")); pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true")); return pcConstraints; }
Example #20
Source File: PnSignalingParams.java From android-webrtc-api with MIT License | 5 votes |
public PnSignalingParams( List<PeerConnection.IceServer> iceServers, MediaConstraints pcConstraints, MediaConstraints videoConstraints, MediaConstraints audioConstraints) { this.iceServers = (iceServers==null) ? defaultIceServers() : iceServers; this.pcConstraints = (pcConstraints==null) ? defaultPcConstraints() : pcConstraints; this.videoConstraints = (videoConstraints==null) ? defaultVideoConstraints() : videoConstraints; this.audioConstraints = (audioConstraints==null) ? defaultAudioConstraints() : audioConstraints; }
Example #21
Source File: PnSignalingParams.java From android-webrtc-api with MIT License | 5 votes |
/** * Default Ice Servers, but specified parameters. * @param pcConstraints * @param videoConstraints * @param audioConstraints */ public PnSignalingParams( MediaConstraints pcConstraints, MediaConstraints videoConstraints, MediaConstraints audioConstraints) { this.iceServers = PnSignalingParams.defaultIceServers(); this.pcConstraints = (pcConstraints==null) ? defaultPcConstraints() : pcConstraints; this.videoConstraints = (videoConstraints==null) ? defaultVideoConstraints() : videoConstraints; this.audioConstraints = (audioConstraints==null) ? defaultAudioConstraints() : audioConstraints; }
Example #22
Source File: PnSignalingParams.java From android-webrtc-api with MIT License | 5 votes |
/** * The default parameters for media constraints. Might have to tweak in future. * @return default parameters */ public static PnSignalingParams defaultInstance() { MediaConstraints pcConstraints = PnSignalingParams.defaultPcConstraints(); MediaConstraints videoConstraints = PnSignalingParams.defaultVideoConstraints(); MediaConstraints audioConstraints = PnSignalingParams.defaultAudioConstraints(); List<PeerConnection.IceServer> iceServers = PnSignalingParams.defaultIceServers(); return new PnSignalingParams(iceServers, pcConstraints, videoConstraints, audioConstraints); }
Example #23
Source File: AndroidPeerConnection.java From actor-platform with GNU Affero General Public License v3.0 | 5 votes |
@NonNull public MediaConstraints getMediaConstraints() { MediaConstraints constraints = new MediaConstraints(); constraints.mandatory.add(new MediaConstraints.KeyValuePair( "OfferToReceiveAudio", "true")); constraints.mandatory.add(new MediaConstraints.KeyValuePair( "OfferToReceiveVideo", "true")); return constraints; }
Example #24
Source File: PnSignalingParams.java From AndroidRTC with MIT License | 5 votes |
private static MediaConstraints defaultVideoConstraints(){ MediaConstraints videoConstraints = new MediaConstraints(); videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxWidth","1280")); videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxHeight","720")); videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("minWidth", "640")); videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("minHeight","480")); return videoConstraints; }
Example #25
Source File: WebRTC.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
PeerConnection peerConnectionInstance() { if (peerConnection == null) { List<PeerConnection.IceServer> iceServers = new ArrayList<>(); Realm realm = Realm.getDefaultInstance(); RealmCallConfig realmCallConfig = realm.where(RealmCallConfig.class).findFirst(); for (RealmIceServer ice : realmCallConfig.getIceServer()) { iceServers.add(new PeerConnection.IceServer(ice.getUrl(), ice.getUsername(), ice.getCredential())); } realm.close(); PeerConnection.RTCConfiguration configuration = new PeerConnection.RTCConfiguration(iceServers); configuration.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE; configuration.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE; configuration.iceTransportsType = PeerConnection.IceTransportsType.RELAY; PeerConnection.Observer observer = new PeerConnectionObserver(); MediaConstraints mediaConstraints = mediaConstraintsGetInstance(); peerConnection = peerConnectionFactoryInstance().createPeerConnection(iceServers, mediaConstraints, observer); mediaStream = peerConnectionFactoryInstance().createLocalMediaStream("ARDAMS"); addAudioTrack(mediaStream); addVideoTrack(mediaStream); peerConnection.addStream(mediaStream); } return peerConnection; }
Example #26
Source File: NBMPeerConnection.java From webrtcpeer-android with Apache License 2.0 | 5 votes |
public void createOffer(MediaConstraints sdpMediaConstraints) { this.sdpMediaConstraints = sdpMediaConstraints; if (pc != null){// && !isError) { Log.d(TAG, "PC Create OFFER"); isInitiator = true; pc.createOffer(this,this.sdpMediaConstraints); } }
Example #27
Source File: PnSignalingParams.java From AndroidRTC with MIT License | 5 votes |
public PnSignalingParams( List<PeerConnection.IceServer> iceServers, MediaConstraints pcConstraints, MediaConstraints videoConstraints, MediaConstraints audioConstraints) { this.iceServers = (iceServers==null) ? defaultIceServers() : iceServers; this.pcConstraints = (pcConstraints==null) ? defaultPcConstraints() : pcConstraints; this.videoConstraints = (videoConstraints==null) ? defaultVideoConstraints() : videoConstraints; this.audioConstraints = (audioConstraints==null) ? defaultAudioConstraints() : audioConstraints; }
Example #28
Source File: PnSignalingParams.java From AndroidRTC with MIT License | 5 votes |
/** * Default Ice Servers, but specified parameters. * @param pcConstraints * @param videoConstraints * @param audioConstraints */ public PnSignalingParams( MediaConstraints pcConstraints, MediaConstraints videoConstraints, MediaConstraints audioConstraints) { this.iceServers = PnSignalingParams.defaultIceServers(); this.pcConstraints = (pcConstraints==null) ? defaultPcConstraints() : pcConstraints; this.videoConstraints = (videoConstraints==null) ? defaultVideoConstraints() : videoConstraints; this.audioConstraints = (audioConstraints==null) ? defaultAudioConstraints() : audioConstraints; }
Example #29
Source File: PnSignalingParams.java From AndroidRTC with MIT License | 5 votes |
private static MediaConstraints defaultPcConstraints(){ MediaConstraints pcConstraints = new MediaConstraints(); pcConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true")); pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true")); pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true")); return pcConstraints; }
Example #30
Source File: PnSignalingParams.java From AndroidRTC with MIT License | 5 votes |
/** * The default parameters for media constraints. Might have to tweak in future. * @return default parameters */ public static PnSignalingParams defaultInstance() { MediaConstraints pcConstraints = PnSignalingParams.defaultPcConstraints(); MediaConstraints videoConstraints = PnSignalingParams.defaultVideoConstraints(); MediaConstraints audioConstraints = PnSignalingParams.defaultAudioConstraints(); List<PeerConnection.IceServer> iceServers = PnSignalingParams.defaultIceServers(); return new PnSignalingParams(iceServers, pcConstraints, videoConstraints, audioConstraints); }