Ejemplo n.º 1
0
  public void createPeerConnectionFactory(
      final Context context,
      final EGLContext renderEGLContext,
      final PeerConnectionParameters peerConnectionParameters,
      final PeerConnectionEvents events) {
    this.peerConnectionParameters = peerConnectionParameters;
    this.events = events;
    videoCallEnabled = peerConnectionParameters.videoCallEnabled;
    // Reset variables to initial states.
    factory = null;
    peerConnection = null;
    preferIsac = false;
    preferH264 = false;
    videoSourceStopped = false;
    isError = false;
    queuedRemoteCandidates = null;
    localSdp = null; // either offer or answer SDP
    mediaStream = null;
    videoCapturer = null;
    renderVideo = true;
    localVideoTrack = null;
    remoteVideoTrack = null;
    statsTimer = new Timer();

    executor.execute(
        new Runnable() {
          @Override
          public void run() {
            createPeerConnectionFactoryInternal(context, renderEGLContext);
          }
        });
  }
Ejemplo n.º 2
0
 private PeerConnectionClient() {
   executor = new LooperExecutor();
   // Looper thread is started once in private ctor and is used for all
   // peer connection API calls to ensure new peer connection factory is
   // created on the same thread as previously destroyed factory.
   executor.requestStart();
 }
Ejemplo n.º 3
0
 public void switchCamera() {
   executor.execute(
       new Runnable() {
         @Override
         public void run() {
           switchCameraInternal();
         }
       });
 }
Ejemplo n.º 4
0
 public void close() {
   executor.execute(
       new Runnable() {
         @Override
         public void run() {
           closeInternal();
         }
       });
 }
 public void changeCaptureFormat(final int width, final int height, final int framerate) {
   executor.execute(
       new Runnable() {
         @Override
         public void run() {
           changeCaptureFormatInternal(width, height, framerate);
         }
       });
 }
Ejemplo n.º 6
0
 private void reportError(final String errorMessage) {
   Log.e(TAG, "Peerconnection error: " + errorMessage);
   executor.execute(
       new Runnable() {
         @Override
         public void run() {
           if (!isError) {
             events.onPeerConnectionError(errorMessage);
             isError = true;
           }
         }
       });
 }
Ejemplo n.º 7
0
 public void startVideoSource() {
   executor.execute(
       new Runnable() {
         @Override
         public void run() {
           if (videoSource != null && videoSourceStopped) {
             Log.d(TAG, "Restart video source.");
             videoSource.restart();
             videoSourceStopped = false;
           }
         }
       });
 }
Ejemplo n.º 8
0
 public void stopVideoSource() {
   executor.execute(
       new Runnable() {
         @Override
         public void run() {
           if (videoSource != null && !videoSourceStopped) {
             Log.d(TAG, "Stop video source.");
             videoSource.stop();
             videoSourceStopped = true;
           }
         }
       });
 }
Ejemplo n.º 9
0
 public void createAnswer() {
   executor.execute(
       new Runnable() {
         @Override
         public void run() {
           if (peerConnection != null && !isError) {
             Log.d(TAG, "PC create ANSWER");
             isInitiator = false;
             peerConnection.createAnswer(sdpObserver, sdpMediaConstraints);
           }
         }
       });
 }
Ejemplo n.º 10
0
 public void setRemoteDescription(final SessionDescription sdp) {
   executor.execute(
       new Runnable() {
         @Override
         public void run() {
           if (peerConnection == null || isError) {
             return;
           }
           String sdpDescription = sdp.description;
           if (preferIsac) {
             sdpDescription = preferCodec(sdpDescription, AUDIO_CODEC_ISAC, true);
           }
           if (videoCallEnabled && preferH264) {
             sdpDescription = preferCodec(sdpDescription, VIDEO_CODEC_H264, false);
           }
           if (videoCallEnabled && peerConnectionParameters.videoStartBitrate > 0) {
             sdpDescription =
                 setStartBitrate(
                     VIDEO_CODEC_VP8,
                     true,
                     sdpDescription,
                     peerConnectionParameters.videoStartBitrate);
             sdpDescription =
                 setStartBitrate(
                     VIDEO_CODEC_VP9,
                     true,
                     sdpDescription,
                     peerConnectionParameters.videoStartBitrate);
             sdpDescription =
                 setStartBitrate(
                     VIDEO_CODEC_H264,
                     true,
                     sdpDescription,
                     peerConnectionParameters.videoStartBitrate);
           }
           if (peerConnectionParameters.audioStartBitrate > 0) {
             sdpDescription =
                 setStartBitrate(
                     AUDIO_CODEC_OPUS,
                     false,
                     sdpDescription,
                     peerConnectionParameters.audioStartBitrate);
           }
           Log.d(TAG, "Set remote SDP.");
           SessionDescription sdpRemote = new SessionDescription(sdp.type, sdpDescription);
           peerConnection.setRemoteDescription(sdpObserver, sdpRemote);
         }
       });
 }
Ejemplo n.º 11
0
 public void addRemoteIceCandidate(final IceCandidate candidate) {
   executor.execute(
       new Runnable() {
         @Override
         public void run() {
           if (peerConnection != null && !isError) {
             if (queuedRemoteCandidates != null) {
               queuedRemoteCandidates.add(candidate);
             } else {
               peerConnection.addIceCandidate(candidate);
             }
           }
         }
       });
 }
Ejemplo n.º 12
0
 public void setVideoEnabled(final boolean enable) {
   executor.execute(
       new Runnable() {
         @Override
         public void run() {
           renderVideo = enable;
           if (localVideoTrack != null) {
             localVideoTrack.setEnabled(renderVideo);
           }
           if (remoteVideoTrack != null) {
             remoteVideoTrack.setEnabled(renderVideo);
           }
         }
       });
 }
Ejemplo n.º 13
0
 public void createPeerConnection(
     final VideoRenderer.Callbacks localRender,
     final VideoRenderer.Callbacks remoteRender,
     final SignalingParameters signalingParameters) {
   if (peerConnectionParameters == null) {
     Log.e(TAG, "Creating peer connection without initializing factory.");
     return;
   }
   this.localRender = localRender;
   this.remoteRender = remoteRender;
   this.signalingParameters = signalingParameters;
   executor.execute(
       new Runnable() {
         @Override
         public void run() {
           createMediaConstraintsInternal();
           createPeerConnectionInternal();
         }
       });
 }