コード例 #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);
          }
        });
  }
コード例 #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();
 }
コード例 #3
0
 public void switchCamera() {
   executor.execute(
       new Runnable() {
         @Override
         public void run() {
           switchCameraInternal();
         }
       });
 }
コード例 #4
0
 public void close() {
   executor.execute(
       new Runnable() {
         @Override
         public void run() {
           closeInternal();
         }
       });
 }
コード例 #5
0
 public void changeCaptureFormat(final int width, final int height, final int framerate) {
   executor.execute(
       new Runnable() {
         @Override
         public void run() {
           changeCaptureFormatInternal(width, height, framerate);
         }
       });
 }
コード例 #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;
           }
         }
       });
 }
コード例 #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;
           }
         }
       });
 }
コード例 #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;
           }
         }
       });
 }
コード例 #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);
           }
         }
       });
 }
コード例 #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);
         }
       });
 }
コード例 #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);
             }
           }
         }
       });
 }
コード例 #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);
           }
         }
       });
 }
コード例 #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();
         }
       });
 }