org.webrtc.VideoSink Java Examples

The following examples show how to use org.webrtc.VideoSink. 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: PeerConnectionObserver.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onAddStream(MediaStream stream) {
    for (AudioTrack audioTrack : stream.audioTracks) {
        audioTrack.setEnabled(true);
    }

    if (stream.videoTracks != null && stream.videoTracks.size() == 1) {
        VideoTrack videoTrack = stream.videoTracks.get(0);
        videoTrack.setEnabled(true);

        videoTrack.addSink(new VideoSink() {
            @Override
            public void onFrame(VideoFrame videoFrame) {

                if (G.onVideoCallFrame != null) {
                    G.onVideoCallFrame.onRemoteFrame(videoFrame);
                }
            }
        });

    }


}
 
Example #2
Source File: WebRTC.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
private void addVideoTrack(MediaStream mediaStream) {

        if (callTYpe == ProtoSignalingOffer.SignalingOffer.Type.VIDEO_CALLING) {
            videoCapturer = createCameraCapturer(new Camera1Enumerator(false));
            videoSource = peerConnectionFactoryInstance().createVideoSource(videoCapturer);
            videoCapturer.startCapture(VIDEO_RESOLUTION_WIDTH, VIDEO_RESOLUTION_HEIGHT, FPS);
            videoTrackFromCamera = peerConnectionFactoryInstance().createVideoTrack(VIDEO_TRACK_ID, videoSource);
            videoTrackFromCamera.setEnabled(true);

            videoTrackFromCamera.addSink(new VideoSink() {
                @Override
                public void onFrame(VideoFrame videoFrame) {
                    if (G.onVideoCallFrame != null) {
                        G.onVideoCallFrame.onPeerFrame(videoFrame);
                    }
                }
            });

            mediaStream.addTrack(videoTrackFromCamera);
        }
    }
 
Example #3
Source File: PeerConnectionClient.java    From voip_android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onAddStream(final MediaStream stream) {
    executor.execute(new Runnable() {
        @Override
        public void run() {
            if (peerConnection == null || isError) {
                return;
            }
            if (stream.audioTracks.size() > 1 || stream.videoTracks.size() > 1) {
                reportError("Weird-looking stream: " + stream);
                return;
            }
            if (stream.videoTracks.size() == 1) {
                remoteVideoTrack = stream.videoTracks.get(0);
                remoteVideoTrack.setEnabled(renderVideo);
                for (VideoSink remoteRender : remoteSinks) {
                    remoteVideoTrack.addSink(remoteRender);
                }
            }
        }
    });
}
 
Example #4
Source File: PeerConnectionClient.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 6 votes vote down vote up
public void reattachVideo(final VideoSink localRender, final VideoRenderer.Callbacks remoteRender, boolean localEnabled)
{
  Log.d(TAG, "reattachVideo()");

  this.localRender = localRender;
  this.remoteRenders = Collections.singletonList(remoteRender);

  executor.execute(new Runnable() {
    @Override
    public void run()
    {
      // Important: when reattaching local video is subject to user's mute preference
      addLocalRenderer(localRender, localEnabled);
      // When reattaching remote video should always be enabled since it's not controlled by the user
      addRemoteRenderer(remoteRender, true);

      events.onVideoReattached();
    }
  });
}
 
Example #5
Source File: Stream.java    From owt-client-android with Apache License 2.0 5 votes vote down vote up
/**
 * Attach the video track of the media stream to videosink in order to display the video
 * content.
 *
 * @param videoSink VideoSink
 */
public void attach(VideoSink videoSink) {
    if (mediaStream == null) {
        return;
    }
    RCHECK(videoSink);
    CheckCondition.RCHECK(!mediaStream.videoTracks.isEmpty());
    mediaStream.videoTracks.get(0).addSink(videoSink);
}
 
Example #6
Source File: Stream.java    From owt-client-android with Apache License 2.0 5 votes vote down vote up
/**
 * Detach the video track of the media stream from a videosink.
 *
 * @param videoSink VideoSink
 */
public void detach(VideoSink videoSink) {
    if (mediaStream == null) {
        return;
    }
    RCHECK(videoSink);
    CheckCondition.RCHECK(!mediaStream.videoTracks.isEmpty());
    mediaStream.videoTracks.get(0).removeSink(videoSink);
}
 
Example #7
Source File: PeerConnectionClient.java    From voip_android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void createPeerConnection(final VideoSink localRender, final VideoSink remoteSink,
                                 final VideoCapturer videoCapturer) {
    if (peerConnectionParameters.videoCallEnabled && videoCapturer == null) {
        Log.w(TAG, "Video call enabled but no video capturer provided.");
    }
    createPeerConnection(
            localRender, Collections.singletonList(remoteSink), videoCapturer);
}
 
Example #8
Source File: PeerConnectionClient.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addLocalRenderer(final VideoSink localRender, boolean enabled)
{
  if (localVideoTrack != null) {
    localVideoTrack.setEnabled(enabled);
    localVideoTrack.addSink(localRender);
    renderLocalVideo = enabled;
    this.localRender = localRender;
  }
}
 
Example #9
Source File: ProxyVideoSink.java    From webrtc_android with MIT License 4 votes vote down vote up
synchronized public void setTarget(VideoSink target) {
    this.target = target;
}
 
Example #10
Source File: PeerConnectionWrapper.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
public PeerConnectionWrapper(@NonNull Context context,
                             @NonNull PeerConnectionFactory factory,
                             @NonNull PeerConnection.Observer observer,
                             @NonNull VideoSink localRenderer,
                             @NonNull List<PeerConnection.IceServer> turnServers,
                             @NonNull CameraEventListener cameraEventListener,
                             @NonNull EglBase eglBase,
                             boolean hideIp) {
    List<PeerConnection.IceServer> iceServers = new LinkedList<>();
    iceServers.add(STUN_SERVER);
    iceServers.addAll(turnServers);

    this.iceServers = iceServers;

    MediaConstraints constraints = new MediaConstraints();
    MediaConstraints audioConstraints = new MediaConstraints();
    PeerConnection.RTCConfiguration configuration = new PeerConnection.RTCConfiguration(iceServers);

    configuration.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE;
    configuration.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE;

    if (hideIp) {
        configuration.iceTransportsType = PeerConnection.IceTransportsType.RELAY;
    }

    constraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));
    audioConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));

    this.peerConnection = factory.createPeerConnection(configuration, constraints, observer);
    this.peerConnection.setAudioPlayout(false);
    this.peerConnection.setAudioRecording(false);

    this.mediaStream = factory.createLocalMediaStream("ARDAMS");
    this.audioSource = factory.createAudioSource(audioConstraints);
    this.audioTrack = factory.createAudioTrack("ARDAMSa0", audioSource);
    this.audioTrack.setEnabled(false);
    mediaStream.addTrack(audioTrack);

    this.camera = new Camera(context, cameraEventListener);

    if (camera.capturer != null) {
        this.videoSource = factory.createVideoSource(false);
        this.videoTrack = factory.createVideoTrack("ARDAMSv0", videoSource);

        camera.capturer.initialize(SurfaceTextureHelper.create("WebRTC-SurfaceTextureHelper", eglBase.getEglBaseContext()), context, videoSource.getCapturerObserver());

        this.videoTrack.addSink(localRenderer);
        this.videoTrack.setEnabled(false);
        mediaStream.addTrack(videoTrack);
    } else {
        this.videoSource = null;
        this.videoTrack = null;
    }

    this.peerConnection.addStream(mediaStream);
}
 
Example #11
Source File: CallActivity.java    From RTCStartupDemo with GNU General Public License v3.0 4 votes vote down vote up
synchronized void setTarget(VideoSink target) {
    this.mTarget = target;
}
 
Example #12
Source File: PeerConnectionClient.java    From sample-videoRTC with Apache License 2.0 4 votes vote down vote up
public void createPeerConnection(final VideoSink localRender,
    final VideoRenderer.Callbacks remoteRender, final VideoCapturer videoCapturer,
    final SignalingParameters signalingParameters) {
  createPeerConnection(
      localRender, Collections.singletonList(remoteRender), videoCapturer, signalingParameters);
}
 
Example #13
Source File: CallActivity.java    From sample-videoRTC with Apache License 2.0 4 votes vote down vote up
synchronized public void setTarget(VideoSink target) {
    this.target = target;
}
 
Example #14
Source File: PeerConnectionClient.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 4 votes vote down vote up
public void createPeerConnection(final VideoSink localRender,
    final VideoRenderer.Callbacks remoteRender, final VideoCapturer videoCapturer,
    final SignalingParameters signalingParameters) {
  createPeerConnection(
      localRender, Collections.singletonList(remoteRender), videoCapturer, signalingParameters);
}