Java Code Examples for org.webrtc.VideoRenderer#Callbacks

The following examples show how to use org.webrtc.VideoRenderer#Callbacks . 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: 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 2
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 3
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 4
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 5
Source File: RoomChatPresenter.java    From VideoMeeting with Apache License 2.0 5 votes vote down vote up
private void addRender(MediaStream stream, int position) {
    VideoRenderer.Callbacks render;
    L.d("addRender position is " + position);
    if (position == 0) {
        render = localRender;
    } else {
        render = VideoRendererGui.create(position % 2 == 0 ? 0 : 50,
                position / 2 * 50,
                50, 50,
                scalingType, false);
    }
    stream.videoTracks.get(0).addRenderer(new VideoRenderer(render));
}
 
Example 6
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 7
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 8
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 9
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 10
Source File: CallActivity.java    From sample-videoRTC with Apache License 2.0 4 votes vote down vote up
synchronized public void setTarget(VideoRenderer.Callbacks target) {
    this.target = target;
}
 
Example 11
Source File: RTCGLVideoView.java    From q-municate-android with Apache License 2.0 4 votes vote down vote up
private VideoRenderer.Callbacks initRenderer(boolean mirror, int[] viewCoordinates) {
    return VideoRendererGui.createGuiRenderer(viewCoordinates[0], viewCoordinates[1], viewCoordinates[2],
            viewCoordinates[3], RendererCommon.ScalingType.SCALE_ASPECT_FILL, mirror);

}
 
Example 12
Source File: RTCGLVideoView.java    From q-municate-android with Apache License 2.0 4 votes vote down vote up
public VideoRenderer.Callbacks obtainVideoRenderer(RendererSurface rendererSurface){
    Log.i(TAG, "obtainVideoRenderer");

    return RendererSurface.MAIN.equals(rendererSurface) ? obtainMainVideoRenderer() :
            obtainSecondVideoRenderer() ;
}
 
Example 13
Source File: EchoTest.java    From janus-gateway-android with MIT License 4 votes vote down vote up
public EchoTest(VideoRenderer.Callbacks localRender, VideoRenderer.Callbacks remoteRender) {
    this.localRender = localRender;
    this.remoteRender = remoteRender;
    janusServer = new JanusServer(new JanusGlobalCallbacks());
}
 
Example 14
Source File: NBMWebRTCPeer.java    From webrtcpeer-android with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
public void registerMasterRenderer(VideoRenderer.Callbacks masterRenderer) {
    this.masterRenderer = masterRenderer;
    updateMasterRenderer();
}
 
Example 15
Source File: MediaResourceManager.java    From webrtcpeer-android with Apache License 2.0 4 votes vote down vote up
void createLocalMediaStream(Object renderEGLContext,final VideoRenderer.Callbacks localRender) {
    if (factory == null) {
        Log.e(TAG, "Peerconnection factory is not created");
        return;
    }
    this.localRender = localRender;
    if (videoCallEnabled) {
        factory.setVideoHwAccelerationOptions(renderEGLContext, renderEGLContext);
    }

    // Set default WebRTC tracing and INFO libjingle logging.
    // NOTE: this _must_ happen while |factory| is alive!
    Logging.enableTracing("logcat:", EnumSet.of(Logging.TraceLevel.TRACE_DEFAULT), Logging.Severity.LS_INFO);

    localMediaStream = factory.createLocalMediaStream("ARDAMS");

    // If video call is enabled and the device has camera(s)
    if (videoCallEnabled && numberOfCameras > 0) {
        String cameraDeviceName; // = CameraEnumerationAndroid.getDeviceName(0);
        String frontCameraDeviceName = CameraEnumerationAndroid.getNameOfFrontFacingDevice();
        String backCameraDeviceName = CameraEnumerationAndroid.getNameOfBackFacingDevice();

        // If current camera is set to front and the device has one
        if (currentCameraPosition==NBMCameraPosition.FRONT && frontCameraDeviceName!=null) {
            cameraDeviceName = frontCameraDeviceName;
        }
        // If current camera is set to back and the device has one
        else if (currentCameraPosition==NBMCameraPosition.BACK && backCameraDeviceName!=null) {
            cameraDeviceName = backCameraDeviceName;
        }
        // If current camera is set to any then we pick the first camera of the device, which
        // should be a back-facing camera according to libjingle API
        else {
            cameraDeviceName = CameraEnumerationAndroid.getDeviceName(0);
            currentCameraPosition = NBMCameraPosition.BACK;
        }

        Log.d(TAG, "Opening camera: " + cameraDeviceName);
        videoCapturer = VideoCapturerAndroid.create(cameraDeviceName, null);
        if (videoCapturer == null) {
            Log.d(TAG, "Error while opening camera");
            return;
        }
        localMediaStream.addTrack(createCapturerVideoTrack(videoCapturer));
    }

    // Create audio track
    localMediaStream.addTrack(factory.createAudioTrack(AUDIO_TRACK_ID, factory.createAudioSource(audioConstraints)));

    Log.d(TAG, "Local media stream created.");
}
 
Example 16
Source File: MediaResourceManager.java    From webrtcpeer-android with Apache License 2.0 4 votes vote down vote up
void attachRendererToRemoteStream(VideoRenderer.Callbacks remoteRender, MediaStream remoteStream){
    Log.d(TAG, "Schedule attaching VideoRenderer to remote stream (" + remoteStream + ")");
    executor.execute(new AttachRendererTask(remoteRender, remoteStream));
}
 
Example 17
Source File: MediaResourceManager.java    From webrtcpeer-android with Apache License 2.0 4 votes vote down vote up
private AttachRendererTask(VideoRenderer.Callbacks remoteRender, MediaStream remoteStream){
    this.remoteRender = remoteRender;
    this.remoteStream = remoteStream;
}
 
Example 18
Source File: VideoSink.java    From VideoCRE with MIT License 4 votes vote down vote up
public VideoSink(final VideoRenderer.Callbacks... callbacks) {
    mCallbacks = Arrays.asList(callbacks);
    mMatrixHelper = new MatrixHelper();
}
 
Example 19
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);
}
 
Example 20
Source File: NBMWebRTCPeer.java    From webrtcpeer-android with Apache License 2.0 2 votes vote down vote up
/**
 * Attaches remote stream to renderer
 * @param remoteRender A render callback for rendering the remote media
 * @param remoteStream The remote media stream
 */
@SuppressWarnings("unused")
public void attachRendererToRemoteStream(VideoRenderer.Callbacks remoteRender, MediaStream remoteStream){
    mediaResourceManager.attachRendererToRemoteStream(remoteRender, remoteStream);
}