org.webrtc.VideoRenderer Java Examples

The following examples show how to use org.webrtc.VideoRenderer. 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: RtcActivity.java    From imsdk-android with MIT License 6 votes vote down vote up
@Override
public void onLocalStream(final MediaStream localStream) {
    /*getHandler().post(new Runnable() {
        @Override
        public void run() {
            if(videoEnable) {

            }
        }
    });*/
    if(client==null||localRender ==  null) return;
    if(!videoEnable&&localStream.audioTracks.size()==1)
    {
        localStream.audioTracks.get(0).setEnabled(true);
    }
    if(localStream.videoTracks.size()==1) {
        localStream.videoTracks.get(0).addRenderer(new VideoRenderer(localRender));
        localStream.videoTracks.get(0).setEnabled(videoEnable);
        if (videoEnable) {
            VideoRendererGui.update(localRender,
                    LOCAL_X_CONNECTING, LOCAL_Y_CONNECTING,
                    LOCAL_WIDTH_CONNECTING, LOCAL_HEIGHT_CONNECTING,
                    scalingType, true);
        }
    }
}
 
Example #2
Source File: VideoConferenceActivity.java    From WebRTCapp with Apache License 2.0 6 votes vote down vote up
public void gotRemoteStream(MediaStream stream, final RemoteParticipant remoteParticipant) {
    final VideoTrack videoTrack = stream.videoTracks.getFirst();
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            remoteRenderer = new VideoRenderer(remoteParticipant.getVideoView());
            remoteParticipant.getVideoView().setVisibility(View.VISIBLE);
            videoTrack.addRenderer(remoteRenderer);
            MediaStream mediaStream = peersManager.getPeerConnectionFactory().createLocalMediaStream("105");
            remoteParticipant.setMediaStream(mediaStream);
            mediaStream.addTrack(peersManager.getLocalAudioTrack());
            mediaStream.addTrack(peersManager.getLocalVideoTrack());
            remoteParticipant.getPeerConnection().removeStream(mediaStream);
            remoteParticipant.getPeerConnection().addStream(mediaStream);
        }
    });
}
 
Example #3
Source File: VideoChatActivity.java    From AndroidRTC with MIT License 6 votes vote down vote up
@Override
public void onAddRemoteStream(final MediaStream remoteStream, final PnPeer peer) {
    super.onAddRemoteStream(remoteStream, peer); // Will log values
    VideoChatActivity.this.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(VideoChatActivity.this,"Connected to " + peer.getId(), Toast.LENGTH_SHORT).show();
            try {
                if(remoteStream.audioTracks.size()==0 || remoteStream.videoTracks.size()==0) return;
                mCallStatus.setVisibility(View.GONE);
                remoteStream.videoTracks.get(0).addRenderer(new VideoRenderer(remoteRender));
                VideoRendererGui.update(remoteRender, 0, 0, 100, 100, VideoRendererGui.ScalingType.SCALE_ASPECT_FILL, false);
                VideoRendererGui.update(localRender, 72, 65, 25, 25, VideoRendererGui.ScalingType.SCALE_ASPECT_FIT, true);
            }
            catch (Exception e){ e.printStackTrace(); }
        }
    });
}
 
Example #4
Source File: PeerConnectionClient.java    From sample-videoRTC with Apache License 2.0 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 (VideoRenderer.Callbacks remoteRender : remoteRenders) {
          remoteVideoTrack.addRenderer(new VideoRenderer(remoteRender));
        }
      }
    }
  });
}
 
Example #5
Source File: NBMWebRTCPeer.java    From webrtcpeer-android with Apache License 2.0 6 votes vote down vote up
/**
* NBMWebRTCPeer constructor
    * <p>
    *     This constructor should always be used in order to properly create a NBMWebRTCPeer instance
    * </p>
* @param  config			Media configuration instance
* @param  context			Android context instance
* @param  localRenderer	    Callback for rendering the locally produced media stream
* @param  observer			An observer instance which implements WebRTC callback functions
*/
   public NBMWebRTCPeer(NBMMediaConfiguration config, Context context,
                        VideoRenderer.Callbacks localRenderer, Observer observer) {

       this.context = context;
       this.localRender = localRenderer;
       this.observer = observer;
       this.masterRenderer = null;
       this.activeMasterStream = null;
       this.config = config;
       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 peerConnectionFactory is
       // created on the same thread as previously destroyed peerConnectionFactory.
       executor.requestStart();

       peerConnectionParameters = new NBMWebRTCPeer.NBMPeerConnectionParameters(true, false,
                        config.getReceiverVideoFormat().width, config.getReceiverVideoFormat().heigth,
                       (int)config.getReceiverVideoFormat().frameRate, config.getVideoBandwidth(), config.getVideoCodec().toString(), true,
                       config.getAudioBandwidth(), config.getAudioCodec().toString(),false, true);

       iceServers = new LinkedList<>();
       // Add Google's stun as a default ICE server
       addIceServer("stun:stun.l.google.com:19302");
   }
 
Example #6
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 #7
Source File: PeerConnectionClient.java    From Yahala-Messenger with MIT 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);
                remoteVideoTrack.addRenderer(new VideoRenderer(remoteRender));
            }
        }
    });
}
 
Example #8
Source File: PeerConnectionClient.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
public void createPeerConnection(
        final EGLContext renderEGLContext,
        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(renderEGLContext);
        }
    });
}
 
Example #9
Source File: RespokeCall.java    From respoke-sdk-android with MIT License 6 votes vote down vote up
@Override public void onAddStream(final MediaStream stream){
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        public void run() {
            if (isActive()) {
                if (stream.audioTracks.size() <= 1 && stream.videoTracks.size() <= 1) {
                    if (stream.videoTracks.size() == 1) {
                        stream.videoTracks.get(0).addRenderer(
                                new VideoRenderer(remoteRender));
                    }
                } else {
                    postErrorToListener("An invalid stream was added");
                }
            }
        }
    });
}
 
Example #10
Source File: RespokeCall.java    From respoke-sdk-android with MIT License 6 votes vote down vote up
private void addLocalStreams(Context context) {
    AudioManager audioManager = ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE));
    // TODO(fischman): figure out how to do this Right(tm) and remove the suppression.
    @SuppressWarnings("deprecation")
    boolean isWiredHeadsetOn = audioManager.isWiredHeadsetOn();
    audioManager.setMode(isWiredHeadsetOn ? AudioManager.MODE_IN_CALL : AudioManager.MODE_IN_COMMUNICATION);
    audioManager.setSpeakerphoneOn(!isWiredHeadsetOn);

    localStream = peerConnectionFactory.createLocalMediaStream("ARDAMS");

    if (!audioOnly) {
        VideoCapturer capturer = getVideoCapturer();
        MediaConstraints videoConstraints = new MediaConstraints();
        videoSource = peerConnectionFactory.createVideoSource(capturer, videoConstraints);
        VideoTrack videoTrack = peerConnectionFactory.createVideoTrack("ARDAMSv0", videoSource);
        videoTrack.addRenderer(new VideoRenderer(localRender));
        localStream.addTrack(videoTrack);
    }

    localStream.addTrack(peerConnectionFactory.createAudioTrack("ARDAMSa0", peerConnectionFactory.createAudioSource(new MediaConstraints())));

    peerConnection.addStream(localStream);
}
 
Example #11
Source File: MediaResourceManager.java    From webrtcpeer-android with Apache License 2.0 5 votes vote down vote up
public void run() {
    Log.d(TAG, "Attaching VideoRenderer to remote stream (" + remoteStream + ")");

    // Check if the remote stream has a video track
    if (remoteStream.videoTracks.size() == 1) {
        // Get the video track
        VideoTrack remoteVideoTrack = remoteStream.videoTracks.get(0);
        // Set video track enabled if we have enabled video rendering
        remoteVideoTrack.setEnabled(renderVideo);

        VideoRenderer videoRenderer = remoteVideoRenderers.get(remoteRender);
        if (videoRenderer != null) {
            MediaStream mediaStream = remoteVideoMediaStreams.get(videoRenderer);
            if (mediaStream != null) {
                VideoTrack videoTrack = remoteVideoTracks.get(mediaStream);
                if (videoTrack != null) {
                    videoTrack.removeRenderer(videoRenderer);
                }
            }
        }

        VideoRenderer newVideoRenderer = new VideoRenderer(remoteRender);
        remoteVideoTrack.addRenderer(newVideoRenderer);
        remoteVideoRenderers.put(remoteRender, newVideoRenderer);
        remoteVideoMediaStreams.put(newVideoRenderer, remoteStream);
        remoteVideoTracks.put(remoteStream, remoteVideoTrack);
        Log.d(TAG, "Attached.");
    }
}
 
Example #12
Source File: AppRTCDemoActivity.java    From droidkit-webrtc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override public void onAddStream(final MediaStream stream){
  runOnUiThread(new Runnable() {
      public void run() {
        abortUnless(stream.audioTracks.size() <= 1 &&
            stream.videoTracks.size() <= 1,
            "Weird-looking stream: " + stream);
        if (stream.videoTracks.size() == 1) {
          stream.videoTracks.get(0).addRenderer(
              new VideoRenderer(remoteRender));
        }
      }
    });
}
 
Example #13
Source File: VideoRoomTest.java    From janus-gateway-android with MIT License 5 votes vote down vote up
public VideoRoomTest(VideoRenderer.Callbacks localRender, VideoRenderer.Callbacks[] remoteRenders) {
    this.localRender = localRender;
    for(int i = 0; i < remoteRenders.length; i++)
    {
        this.availableRemoteRenderers.push(remoteRenders[i]);
    }
    janusServer = new JanusServer(new JanusGlobalCallbacks());
}
 
Example #14
Source File: VideoRoomTest.java    From janus-gateway-android with MIT License 5 votes vote down vote up
private void newRemoteFeed(BigInteger id) { //todo attach the plugin as a listener
    VideoRenderer.Callbacks myrenderer;
    if(!remoteRenderers.containsKey(id))
    {
        if(availableRemoteRenderers.isEmpty())
        {
            //TODO no more space
            return;
        }
        remoteRenderers.put(id, availableRemoteRenderers.pop());
    }
    myrenderer = remoteRenderers.get(id);
    janusServer.Attach(new ListenerAttachCallbacks(id, myrenderer));
}
 
Example #15
Source File: EchoTest.java    From janus-gateway-android with MIT License 5 votes vote down vote up
@Override
public void onRemoteStream(MediaStream stream) {
    stream.videoTracks.get(0).setEnabled(true);
    if(stream.videoTracks.get(0).enabled())
        Log.d("JANUSCLIENT", "video tracks enabled");
    stream.videoTracks.get(0).addRenderer(new VideoRenderer(remoteRender));
    VideoRendererGui.update(remoteRender, 0, 0, 25, 25, VideoRendererGui.ScalingType.SCALE_ASPECT_FILL, true);
    VideoRendererGui.update(localRender, 72, 72, 25, 25, VideoRendererGui.ScalingType.SCALE_ASPECT_FILL, false);
}
 
Example #16
Source File: AppRTCDemoActivity.java    From WebRTCDemo with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override public void onAddStream(final MediaStream stream){
  runOnUiThread(new Runnable() {
      public void run() {
        abortUnless(stream.audioTracks.size() <= 1 &&
            stream.videoTracks.size() <= 1,
            "Weird-looking stream: " + stream);
        if (stream.videoTracks.size() == 1) {
          stream.videoTracks.get(0).addRenderer(
              new VideoRenderer(remoteRender));
        }
      }
    });
}
 
Example #17
Source File: ConversationCallFragment.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
private void fillVideoView(QBRTCSurfaceView videoView, QBRTCVideoTrack videoTrack, boolean localRenderer) {
    videoTrack.cleanUp();
    videoTrack.addRenderer(new VideoRenderer(videoView));

    if (localRenderer) {
        updateVideoView(videoView, isFrontCameraSelected);
    }
    Log.d(TAG, (localRenderer ? "local" : "remote") + " Track is rendering");
}
 
Example #18
Source File: RTCGLVideoView.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
private VideoRenderer.Callbacks obtainMainVideoRenderer(){
    Log.i(TAG, "obtainMainVideoRenderer");
    if (mainRendererCallback == null) {
        mainRendererCallback = initRenderer(mainMirror, remoteCoords);
    }
    return mainRendererCallback;
}
 
Example #19
Source File: RTCGLVideoView.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
private VideoRenderer.Callbacks obtainSecondVideoRenderer(){
    Log.i(TAG, "obtainSecondVideoRenderer");
    if (localRendererCallback == null) {
        localRendererCallback = initRenderer(secondMirror, localCoords);
    }
    return localRendererCallback;
}
 
Example #20
Source File: RTCGLVideoView.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
public void updateRenderer(RendererSurface rendererSurface, RendererConfig config){
    boolean mainRenderer = RendererSurface.MAIN.equals(rendererSurface);
    VideoRenderer.Callbacks callbacks = mainRenderer ? mainRendererCallback
            :localRendererCallback;

    if (config.coordinates != null) {
        setViewCoordinates((mainRenderer ? remoteCoords : localCoords),
                config.coordinates);
    }
    setRendererMirror(config.mirror, rendererSurface);
    int[] viewCoordinates = mainRenderer ? remoteCoords : localCoords;
    VideoRendererGui.update(callbacks, viewCoordinates[0], viewCoordinates[1], viewCoordinates[2],
            viewCoordinates[3], RendererCommon.ScalingType.SCALE_ASPECT_FILL,
            (mainRenderer ? mainMirror : secondMirror));
}
 
Example #21
Source File: PeerConnectionClient.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addRemoteRenderer(final VideoRenderer.Callbacks remoteRender, boolean enabled)
{
  if (remoteVideoTrack != null) {
    remoteVideoTrack.setEnabled(enabled);
    remoteVideoRenderer = new VideoRenderer(remoteRender);
    remoteVideoTrack.addRenderer(remoteVideoRenderer);
    renderRemoteVideo = enabled;
  }
}
 
Example #22
Source File: PeerConnectionClient.java    From restcomm-android-sdk with GNU Affero General Public License v3.0 5 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(renderRemoteVideo);
            if (remoteRenders.size() > 1) {
              // until we get the backgrounding working let's only handle 1
              throw new RuntimeException("Only supporting size 1 remoteRenders");
            }
            else if (remoteRenders.size() == 1) {
              remoteVideoRenderer = new VideoRenderer(remoteRenders.get(0));
              remoteVideoTrack.addRenderer(remoteVideoRenderer);
            }
/*
            for (VideoRenderer.Callbacks remoteRender : remoteRenders) {
              remoteVideoTrack.addRenderer(new VideoRenderer(remoteRender));
            }
*/
            events.onRemoteVideo();
          }
        }
      });
    }
 
Example #23
Source File: StreamDescription.java    From licodeAndroidClient with MIT License 5 votes vote down vote up
/** attaches a complete renderer */
public synchronized void attachLocalRenderer(VideoRenderer renderer) {
	if (mRenderer != null) {
		return;
	}

	mRenderer = renderer;
}
 
Example #24
Source File: MediaResourceManager.java    From webrtcpeer-android with Apache License 2.0 5 votes vote down vote up
private VideoTrack createCapturerVideoTrack(VideoCapturerAndroid capturer) {
    videoSource = factory.createVideoSource(capturer, videoConstraints);
    localVideoTrack = factory.createVideoTrack(VIDEO_TRACK_ID, videoSource);
    localVideoTrack.setEnabled(renderVideo);
    localVideoTrack.addRenderer(new VideoRenderer(localRender));
    return localVideoTrack;
}
 
Example #25
Source File: RtcActivity.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public void onAddRemoteStream(final MediaStream remoteStream) {
    if(client == null||remoteRender ==  null) return;
    stopPlayTone();
    if(remoteStream.audioTracks.size()>1||
            remoteStream.videoTracks.size()>1)
    {
        LogUtil.e("Wired looking stream: "+remoteStream);
        return;
    }
    if(!videoEnable&&remoteStream.audioTracks.size()==1)
    {
        remoteStream.audioTracks.get(0).setEnabled(true);
    }
    if(remoteStream.videoTracks.size() == 1)
    {
        remoteStream.videoTracks.get(0).addRenderer(new VideoRenderer(remoteRender));
        remoteStream.videoTracks.get(0).setEnabled(videoEnable);
        if(videoEnable) {
            VideoRendererGui.update(remoteRender,
                    REMOTE_X, REMOTE_Y,
                    REMOTE_WIDTH, REMOTE_HEIGHT, scalingType, false);
            VideoRendererGui.update(localRender,
                    LOCAL_X_CONNECTED, LOCAL_Y_CONNECTED,
                    LOCAL_WIDTH_CONNECTED, LOCAL_HEIGHT_CONNECTED,
                    scalingType, true);
        }
    }
}
 
Example #26
Source File: PeersManager.java    From WebRTCapp with Apache License 2.0 5 votes vote down vote up
public void start() {
    PeerConnectionFactory.initializeAndroidGlobals(activity, true);

    PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
    peerConnectionFactory = new PeerConnectionFactory(options);

    videoGrabberAndroid = createVideoGrabber();
    MediaConstraints constraints = new MediaConstraints();

    VideoSource videoSource = peerConnectionFactory.createVideoSource(videoGrabberAndroid);
    localVideoTrack = peerConnectionFactory.createVideoTrack("100", videoSource);

    AudioSource audioSource = peerConnectionFactory.createAudioSource(constraints);
    localAudioTrack = peerConnectionFactory.createAudioTrack("101", audioSource);

    if (videoGrabberAndroid != null) {
        videoGrabberAndroid.startCapture(1000, 1000, 30);
    }

    localRenderer = new VideoRenderer(localVideoView);
    localVideoTrack.addRenderer(localRenderer);

    MediaConstraints sdpConstraints = new MediaConstraints();
    sdpConstraints.mandatory.add(new MediaConstraints.KeyValuePair("offerToReceiveAudio", "true"));
    sdpConstraints.mandatory.add(new MediaConstraints.KeyValuePair("offerToReceiveVideo", "true"));

    createLocalPeerConnection(sdpConstraints);
}
 
Example #27
Source File: CallActivity.java    From sample-videoRTC with Apache License 2.0 5 votes vote down vote up
@Override
synchronized public void renderFrame(VideoRenderer.I420Frame frame) {
    if (target == null) {
        Logging.d(TAG, "Dropping frame in proxy because target is null.");
        VideoRenderer.renderFrameDone(frame);
        return;
    }

    target.renderFrame(frame);
}
 
Example #28
Source File: MainActivity.java    From janus-gateway-android with MIT License 5 votes vote down vote up
@Override
    public void onRemoteRender(final JanusConnection connection) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
//                remoteRender = new SurfaceViewRenderer(MainActivity.this);
//                remoteRender.init(rootEglBase.getEglBaseContext(), null);
//                LinearLayout.LayoutParams params  = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
//                rootView.addView(remoteRender, params);
                connection.videoTrack.addRenderer(new VideoRenderer(remoteRender));
            }
        });
    }
 
Example #29
Source File: PeerConnectionClient.java    From janus-gateway-android with MIT License 5 votes vote down vote up
private VideoTrack createVideoTrack(VideoCapturer capturer) {
  videoSource = factory.createVideoSource(capturer);
  capturer.startCapture(videoWidth, videoHeight, videoFps);

  localVideoTrack = factory.createVideoTrack(VIDEO_TRACK_ID, videoSource);
  localVideoTrack.setEnabled(renderVideo);
  localVideoTrack.addRenderer(new VideoRenderer(localRender));
  return localVideoTrack;
}
 
Example #30
Source File: HwAvcEncoder.java    From VideoCRE with MIT License 5 votes vote down vote up
@Override
public void renderFrame(final VideoRenderer.I420Frame frame) {
    mMediaCodecHandler.post(new Runnable() {
        @Override
        public void run() {
            mVideoEncoder.encodeTexture(false, frame.textureId, frame.samplingMatrix,
                    TimeUnit.NANOSECONDS.toMicros(frame.timestamp));
        }
    });
}