org.kurento.client.WebRtcEndpoint Java Examples

The following examples show how to use org.kurento.client.WebRtcEndpoint. 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: Handler.java    From kurento-tutorial-java with Apache License 2.0 6 votes vote down vote up
private void handleAddIceCandidate(final WebSocketSession session,
    JsonObject jsonMessage)
{
  final String sessionId = session.getId();
  if (!users.containsKey(sessionId)) {
    log.warn("[Handler::handleAddIceCandidate] Skip, unknown user, id: {}",
        sessionId);
    return;
  }

  final UserSession user = users.get(sessionId);
  final JsonObject jsonCandidate =
      jsonMessage.get("candidate").getAsJsonObject();
  final IceCandidate candidate =
      new IceCandidate(jsonCandidate.get("candidate").getAsString(),
      jsonCandidate.get("sdpMid").getAsString(),
      jsonCandidate.get("sdpMLineIndex").getAsInt());

  WebRtcEndpoint webRtcEp = user.getWebRtcEndpoint();
  webRtcEp.addIceCandidate(candidate);
}
 
Example #2
Source File: Handler.java    From kurento-tutorial-java with Apache License 2.0 6 votes vote down vote up
private void handleAddIceCandidate(final WebSocketSession session,
    JsonObject jsonMessage)
{
  String sessionId = session.getId();
  UserSession user = users.get(sessionId);

  if (user != null) {
    JsonObject jsonCandidate = jsonMessage.get("candidate").getAsJsonObject();
    IceCandidate candidate =
        new IceCandidate(jsonCandidate.get("candidate").getAsString(),
        jsonCandidate.get("sdpMid").getAsString(),
        jsonCandidate.get("sdpMLineIndex").getAsInt());

    WebRtcEndpoint webRtcEp = user.getWebRtcEndpoint();
    webRtcEp.addIceCandidate(candidate);
  }
}
 
Example #3
Source File: PlayMediaPipeline.java    From kurento-tutorial-java with Apache License 2.0 6 votes vote down vote up
public PlayMediaPipeline(KurentoClient kurento, String user, final WebSocketSession session) {
  // Media pipeline
  pipeline = kurento.createMediaPipeline();

  // Media Elements (WebRtcEndpoint, PlayerEndpoint)
  webRtc = new WebRtcEndpoint.Builder(pipeline).build();
  player = new PlayerEndpoint.Builder(pipeline, RECORDING_PATH + user + RECORDING_EXT).build();

  // Connection
  player.connect(webRtc);

  // Player listeners
  player.addErrorListener(new EventListener<ErrorEvent>() {
    @Override
    public void onEvent(ErrorEvent event) {
      log.info("ErrorEvent: {}", event.getDescription());
      sendPlayEnd(session);
    }
  });
}
 
Example #4
Source File: RoomParticipant.java    From kurento-java with Apache License 2.0 6 votes vote down vote up
public RoomParticipant(String name, Room room, WebSocketSession session, MediaPipeline pipeline) {

    this.pipeline = pipeline;
    this.name = name;
    this.session = session;
    this.room = room;
    this.receivingEndpoint = new WebRtcEndpoint.Builder(pipeline).build();

    this.senderThread = new Thread("sender:" + name) {
      @Override
      public void run() {
        try {
          internalSendMessage();
        } catch (InterruptedException e) {
          return;
        }
      }
    };

    this.senderThread.start();
  }
 
Example #5
Source File: Handler.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
private void startWebRtcEndpoint(WebRtcEndpoint webRtcEp)
{
  // Calling gatherCandidates() is when the Endpoint actually starts working.
  // In this tutorial, this is emphasized for demonstration purposes by
  // launching the ICE candidate gathering in its own method.
  webRtcEp.gatherCandidates();
}
 
Example #6
Source File: FakeParticipant.java    From kurento-room with Apache License 2.0 5 votes vote down vote up
private void releaseRemote(String remote) {
  WebRtcEndpoint peer = peerEndpoints.get(remote);
  if (peer != null) {
    peer.release();
  }
  peerEndpoints.remove(remote);
}
 
Example #7
Source File: KStream.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
public void addCandidate(IceCandidate candidate, String uid) {
	if (this.uid.equals(uid)) {
		outgoingMedia.addIceCandidate(candidate);
	} else {
		WebRtcEndpoint endpoint = listeners.get(uid);
		log.debug("Add candidate for {}, listener found ? {}", uid, endpoint != null);
		if (endpoint != null) {
			endpoint.addIceCandidate(candidate);
		}
	}
}
 
Example #8
Source File: FakeParticipant.java    From kurento-room with Apache License 2.0 5 votes vote down vote up
private void onIceCandidate(Notification notif) {
  IceCandidateInfo info = (IceCandidateInfo) notif;
  log.debug("Notif details {}: {}", info.getClass().getSimpleName(), info);
  String epname = info.getEndpointName();
  if (name.equals(epname)) {
    if (webRtc != null) {
      webRtc.addIceCandidate(info.getIceCandidate());
    }
  } else {
    WebRtcEndpoint peer = peerEndpoints.get(epname);
    if (peer != null) {
      peer.addIceCandidate(info.getIceCandidate());
    }
  }
}
 
Example #9
Source File: Pipeline.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
public void setFeedUrl(String feedUrl) {
  this.feedUrl = feedUrl;

  if (this.playerEndpoint != null) {
    log.debug("Releasing previous elements");
    this.crowdDetectorFilter.release();
    this.playerEndpoint.release();
  }

  log.debug("Creating new elements");

  this.crowdDetectorFilter = new CrowdDetectorFilter.Builder(this.pipe, this.rois).build();
  this.crowdDetectorFilter.setProcessingWidth(640);

  addOrionListeners();

  this.playerEndpoint = new PlayerEndpoint.Builder(this.pipe, this.feedUrl).build();
  addPlayerListeners();
  this.playing = true;

  this.playerEndpoint.connect(this.crowdDetectorFilter);
  this.playerEndpoint.play();

  log.debug("New player is now runing");
  log.debug("Connecting " + this.webRtcEndpoints.size() + " webrtcendpoints");
  // change the feed for all the webrtc clients connected.
  for (Entry<String, WebRtcEndpoint> ep : this.webRtcEndpoints.entrySet()) {
    this.crowdDetectorFilter.connect(ep.getValue());
  }
}
 
Example #10
Source File: PlayerMultiplePauseTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testPlayerMultiplePause() throws Exception {
  // Test data
  final String mediaUrl = "http://" + getTestFilesHttpPath() + "/video/60sec/red.webm";
  final Color expectedColor = Color.RED;
  final int playTimeSeconds = 2;
  final int pauseTimeSeconds = 2;
  final int numPauses = 30;

  // Media Pipeline
  MediaPipeline mp = kurentoClient.createMediaPipeline();
  PlayerEndpoint playerEp = new PlayerEndpoint.Builder(mp, mediaUrl).build();
  WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(mp).build();
  playerEp.connect(webRtcEp);

  // WebRTC in receive-only mode
  getPage().subscribeEvents("playing");
  getPage().initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY);
  playerEp.play();
  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage().waitForEvent("playing"));

  for (int i = 0; i < numPauses; i++) {
    // Assert color
    Assert.assertTrue("The color of the video should be " + expectedColor,
        getPage().similarColor(expectedColor));

    // Pause and wait
    playerEp.pause();
    Thread.sleep(TimeUnit.SECONDS.toMillis(pauseTimeSeconds));

    // Resume video
    playerEp.play();
    Thread.sleep(TimeUnit.SECONDS.toMillis(playTimeSeconds));
  }

  // Release Media Pipeline
  mp.release();
}
 
Example #11
Source File: WebRtcStabilityBack2BackTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testWebRtcStabilityBack2Back() throws Exception {
  final int playTime = Integer.parseInt(System
      .getProperty("test.webrtc.stability.back2back.playtime", String.valueOf(DEFAULT_PLAYTIME)));

  // Media Pipeline
  MediaPipeline mp = kurentoClient.createMediaPipeline();
  WebRtcEndpoint webRtcEndpoint1 = new WebRtcEndpoint.Builder(mp).build();
  WebRtcEndpoint webRtcEndpoint2 = new WebRtcEndpoint.Builder(mp).build();
  webRtcEndpoint1.connect(webRtcEndpoint2);
  webRtcEndpoint2.connect(webRtcEndpoint1);

  // Latency control
  LatencyController cs = new LatencyController("WebRTC latency control");

  // WebRTC
  getPresenter().subscribeLocalEvents("playing");
  getPresenter().initWebRtc(webRtcEndpoint1, WebRtcChannel.VIDEO_ONLY, WebRtcMode.SEND_ONLY);
  getViewer().subscribeEvents("playing");
  getViewer().initWebRtc(webRtcEndpoint2, WebRtcChannel.VIDEO_ONLY, WebRtcMode.RCV_ONLY);

  // Latency assessment
  cs.checkLatency(playTime, TimeUnit.MINUTES, getPresenter(), getViewer());

  // Release Media Pipeline
  mp.release();

  // Draw latency results (PNG chart and CSV file)
  cs.drawChart(getDefaultOutputFile(".png"), 500, 270);
  cs.writeCsv(getDefaultOutputFile(".csv"));
  cs.logLatencyErrorrs();
}
 
Example #12
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
public UserSession(final String name, String roomName, final WebSocketSession session,
    MediaPipeline pipeline) {

  this.pipeline = pipeline;
  this.name = name;
  this.session = session;
  this.roomName = roomName;
  this.outgoingMedia = new WebRtcEndpoint.Builder(pipeline).build();

  this.outgoingMedia.addIceCandidateFoundListener(new EventListener<IceCandidateFoundEvent>() {

    @Override
    public void onEvent(IceCandidateFoundEvent event) {
      JsonObject response = new JsonObject();
      response.addProperty("id", "iceCandidate");
      response.addProperty("name", name);
      response.add("candidate", JsonUtils.toJsonObject(event.getCandidate()));
      try {
        synchronized (session) {
          session.sendMessage(new TextMessage(response.toString()));
        }
      } catch (IOException e) {
        log.debug(e.getMessage());
      }
    }
  });
}
 
Example #13
Source File: WebRtcOneFaceOverlayTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testWebRtcFaceOverlay() throws InterruptedException {

  // Media Pipeline
  MediaPipeline mp = kurentoClient.createMediaPipeline();
  WebRtcEndpoint webRtcEndpoint = new WebRtcEndpoint.Builder(mp).build();
  FaceOverlayFilter faceOverlayFilter = new FaceOverlayFilter.Builder(mp).build();
  webRtcEndpoint.connect(faceOverlayFilter);
  faceOverlayFilter.connect(webRtcEndpoint);

  // Start WebRTC and wait for playing event
  getPage().subscribeEvents("playing");
  getPage().initWebRtc(webRtcEndpoint, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_RCV);
  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage().waitForEvent("playing"));

  // Guard time to play the video
  int playTime = Integer.parseInt(
      System.getProperty("test.webrtcfaceoverlay.playtime", String.valueOf(DEFAULT_PLAYTIME)));
  waitSeconds(playTime);

  // Assertions
  double currentTime = getPage().getCurrentTime();
  Assert.assertTrue(
      "Error in play time (expected: " + playTime + " sec, real: " + currentTime + " sec)",
      getPage().compare(playTime, currentTime));
  Assert.assertTrue("The color of the video should be green",
      getPage().similarColor(CHROME_VIDEOTEST_COLOR));

  // Release Media Pipeline
  mp.release();
}
 
Example #14
Source File: DatachannelsB2BTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testDispatcherPlayer() throws Exception {
  // Media Pipeline
  MediaPipeline mp = kurentoClient.createMediaPipeline();

  WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(mp).useDataChannels().build();
  WebRtcEndpoint webRtcEp2 = new WebRtcEndpoint.Builder(mp).useDataChannels().build();

  webRtcEp.connect(webRtcEp2);
  webRtcEp2.connect(webRtcEp);

  // Test execution
  getPage(0).initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY, true);
  getPage(1).initWebRtc(webRtcEp2, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY, true);

  Thread.sleep(8000);

  for (int i = 0; i < TIMES; i++) {
    String messageSentBrower0 = "Data sent from the browser0. Message" + i;
    String messageSentBrower1 = "Data sent from the browser1. Message" + i;

    getPage(0).sendDataByDataChannel(messageSentBrower0);
    getPage(1).sendDataByDataChannel(messageSentBrower1);

    Assert.assertTrue("The message should be: " + messageSentBrower1,
        getPage(0).compareDataChannelMessage(messageSentBrower1));

    Assert.assertTrue("The message should be: " + messageSentBrower0,
        getPage(1).compareDataChannelMessage(messageSentBrower0));
  }

  // Release Media Pipeline
  mp.release();
}
 
Example #15
Source File: RepositoryRecorderTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
private void launchBrowser(WebRtcEndpoint webRtcEp, PlayerEndpoint playerEp,
    RecorderEndpoint recorderEp) throws InterruptedException {

  getPage().subscribeEvents("playing");
  getPage().initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY);
  playerEp.play();
  final CountDownLatch eosLatch = new CountDownLatch(1);
  playerEp.addEndOfStreamListener(new EventListener<EndOfStreamEvent>() {
    @Override
    public void onEvent(EndOfStreamEvent event) {
      eosLatch.countDown();
    }
  });

  if (recorderEp != null) {
    recorderEp.record();
  }

  // Assertions
  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage().waitForEvent("playing"));
  Assert.assertTrue("The color of the video should be black",
      getPage().similarColor(Color.BLACK));
  Assert.assertTrue("Not received EOS event in player",
      eosLatch.await(getPage().getTimeout(), TimeUnit.SECONDS));
  double currentTime = getPage().getCurrentTime();
  Assert.assertTrue(
      "Error in play time (expected: " + PLAYTIME + " sec, real: " + currentTime + " sec)",
      getPage().compare(PLAYTIME, currentTime));
}
 
Example #16
Source File: WebRtcClient.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
private WebRtcEndpointStats getStats(WebRtcEndpoint webRtcEndpoint) {
  Map<String, Stats> stats = new HashMap<>();
  MediaType[] types = { MediaType.VIDEO, MediaType.AUDIO, MediaType.DATA };

  for (MediaType type : types) {
    Map<String, Stats> trackStats = webRtcEndpoint.getStats(type);
    for (Stats track : trackStats.values()) {
      stats.put(type.name().toLowerCase() + "_" + getRtcStatsType(track.getClass()), track);
    }
  }

  return new WebRtcEndpointStats(stats);
}
 
Example #17
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
private WebRtcEndpoint getEndpointForUser(final UserSession sender) {
  if (sender.getName().equals(name)) {
    log.debug("PARTICIPANT {}: configuring loopback", this.name);
    return outgoingMedia;
  }

  log.debug("PARTICIPANT {}: receiving video from {}", this.name, sender.getName());

  WebRtcEndpoint incoming = incomingMedia.get(sender.getName());
  if (incoming == null) {
    log.debug("PARTICIPANT {}: creating new endpoint for {}", this.name, sender.getName());
    incoming = new WebRtcEndpoint.Builder(pipeline).build();

    incoming.addIceCandidateFoundListener(new EventListener<IceCandidateFoundEvent>() {

      @Override
      public void onEvent(IceCandidateFoundEvent event) {
        JsonObject response = new JsonObject();
        response.addProperty("id", "iceCandidate");
        response.addProperty("name", sender.getName());
        response.add("candidate", JsonUtils.toJsonObject(event.getCandidate()));
        try {
          synchronized (session) {
            session.sendMessage(new TextMessage(response.toString()));
          }
        } catch (IOException e) {
          log.debug(e.getMessage());
        }
      }
    });

    incomingMedia.put(sender.getName(), incoming);
  }

  log.debug("PARTICIPANT {}: obtained endpoint for {}", this.name, sender.getName());
  sender.getOutgoingWebRtcPeer().connect(incoming);

  return incoming;
}
 
Example #18
Source File: KmsPerformanceTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
private void configureFakeClients(WebRtcEndpoint inputWebRtc) {

    int numFakeClients = numClients - 2;

    if (numFakeClients > 0) {
      log.debug("Adding {} fake clients", numFakeClients);
      addFakeClients(numFakeClients, mp, inputWebRtc, timeBetweenClients, monitor,
          new WebRtcConnector() {
            @Override
            public void connect(WebRtcEndpoint inputEndpoint, WebRtcEndpoint outputEndpoint) {
              connectWithMediaProcessing(inputEndpoint, outputEndpoint);
            }
          });
    }
  }
 
Example #19
Source File: FakeKmsService.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void removeAllFakeClients(long timeBetweenClientMs, WebRtcEndpoint inputWebRtc,
    SystemMonitorManager monitor) {
  for (WebRtcEndpoint fakeWebRtc : fakeWebRtcList) {
    inputWebRtc.disconnect(fakeWebRtc);
    monitor.decrementNumClients();

    waitMs(timeBetweenClientMs);
  }
}
 
Example #20
Source File: FakeKmsService.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void releaseAllFakeClients(long timeBetweenClientMs, WebRtcEndpoint inputWebRtc,
    SystemMonitorManager monitor) {
  for (WebRtcEndpoint fakeWebRtc : fakeWebRtcList) {
    fakeWebRtc.release();
    monitor.decrementNumClients();

    waitMs(timeBetweenClientMs);
  }
  for (WebRtcEndpoint fakeBrowser : fakeBrowserList) {
    fakeBrowser.release();
    waitMs(timeBetweenClientMs);
  }
  fakeWebRtcList = new ArrayList<>();
  fakeBrowserList = new ArrayList<>();
}
 
Example #21
Source File: WebRtcQualityLoopbackTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void doTest(BrowserType browserType, String videoPath, String audioUrl, Color color)
    throws InterruptedException {
  // Media Pipeline
  MediaPipeline mp = kurentoClient.createMediaPipeline();
  WebRtcEndpoint webRtcEndpoint = new WebRtcEndpoint.Builder(mp).build();
  webRtcEndpoint.connect(webRtcEndpoint);

  getPage().subscribeEvents("playing");
  getPage().initWebRtc(webRtcEndpoint, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_RCV);

  // Wait until event playing in the remote stream
  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage().waitForEvent("playing"));

  // Guard time to play the video
  Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME));

  // Assert play time
  double currentTime = getPage().getCurrentTime();
  Assert.assertTrue("Error in play time of player (expected: " + PLAYTIME + " sec, real: "
      + currentTime + " sec)", getPage().compare(PLAYTIME, currentTime));

  // Assert color
  if (color != null) {
    Assert.assertTrue("The color of the video should be " + color, getPage().similarColor(color));
  }

  // Assert audio quality
  if (audioUrl != null) {
    float realPesqMos = Ffmpeg.getPesqMos(audioUrl, AUDIO_SAMPLE_RATE);
    Assert.assertTrue("Bad perceived audio quality: PESQ MOS too low (expected=" + MIN_PESQ_MOS
        + ", real=" + realPesqMos + ")", realPesqMos >= MIN_PESQ_MOS);
  }

  // Release Media Pipeline
  mp.release();
}
 
Example #22
Source File: CompositeWebRtcRecorderTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompositeRecorder() throws Exception {

  // MediaPipeline
  MediaPipeline mp = kurentoClient.createMediaPipeline();

  Composite composite = new Composite.Builder(mp).build();

  HubPort hubPort1 = new HubPort.Builder(composite).build();
  WebRtcEndpoint webRtcEpRed = new WebRtcEndpoint.Builder(mp).build();
  webRtcEpRed.connect(hubPort1);

  HubPort hubPort2 = new HubPort.Builder(composite).build();
  WebRtcEndpoint webRtcEpGreen = new WebRtcEndpoint.Builder(mp).build();
  webRtcEpGreen.connect(hubPort2, MediaType.AUDIO);

  HubPort hubPort3 = new HubPort.Builder(composite).build();
  WebRtcEndpoint webRtcEpBlue = new WebRtcEndpoint.Builder(mp).build();
  webRtcEpBlue.connect(hubPort3, MediaType.AUDIO);

  HubPort hubPort4 = new HubPort.Builder(composite).build();
  WebRtcEndpoint webRtcEpWhite = new WebRtcEndpoint.Builder(mp).build();
  webRtcEpWhite.connect(hubPort4, MediaType.AUDIO);

  String recordingFile = getDefaultOutputFile(EXTENSION_WEBM);
  RecorderEndpoint recorderEp =
      new RecorderEndpoint.Builder(mp, Protocol.FILE + recordingFile).build();
  HubPort hubPort5 = new HubPort.Builder(composite).build();
  hubPort5.connect(recorderEp);

  // WebRTC browsers
  getPage(BROWSER2).initWebRtc(webRtcEpRed, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_ONLY);
  getPage(BROWSER3).initWebRtc(webRtcEpGreen, WebRtcChannel.AUDIO_AND_VIDEO,
      WebRtcMode.SEND_ONLY);
  getPage(BROWSER4).initWebRtc(webRtcEpBlue, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_ONLY);
  getPage(BROWSER5).initWebRtc(webRtcEpWhite, WebRtcChannel.AUDIO_AND_VIDEO,
      WebRtcMode.SEND_ONLY);

  recorderEp.record();

  Thread.sleep(PLAYTIME * 1000);

  final CountDownLatch recorderLatch = new CountDownLatch(1);
  recorderEp.stopAndWait(new Continuation<Void>() {

    @Override
    public void onSuccess(Void result) throws Exception {
      recorderLatch.countDown();
    }

    @Override
    public void onError(Throwable cause) throws Exception {
      recorderLatch.countDown();
    }
  });

  Assert.assertTrue("Not stop properly",
      recorderLatch.await(getPage(BROWSER1).getTimeout(), TimeUnit.SECONDS));

  mp.release();

  // Media Pipeline #2
  MediaPipeline mp2 = kurentoClient.createMediaPipeline();
  PlayerEndpoint playerEp2 =
      new PlayerEndpoint.Builder(mp2, Protocol.FILE + recordingFile).build();
  WebRtcEndpoint webRtcEp2 = new WebRtcEndpoint.Builder(mp2).build();
  playerEp2.connect(webRtcEp2);

  // Playing the recorded file
  launchBrowser(mp2, webRtcEp2, playerEp2, null, EXPECTED_VIDEO_CODEC_WEBM,
      EXPECTED_AUDIO_CODEC_WEBM, recordingFile, Color.RED, 0, 0, PLAYTIME);

  // Release Media Pipeline #2
  mp2.release();

  success = true;
}
 
Example #23
Source File: RecorderSwitchWebRtcWebRtcAndPlayerTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public void doTest(MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec,
    String expectedAudioCodec, String extension) throws Exception {
  // Media Pipeline #1
  MediaPipeline mp = kurentoClient.createMediaPipeline();
  final CountDownLatch errorPipelinelatch = new CountDownLatch(1);

  mp.addErrorListener(new EventListener<ErrorEvent>() {

    @Override
    public void onEvent(ErrorEvent event) {
      msgError = "Description:" + event.getDescription() + "; Error code:" + event.getType();
      errorPipelinelatch.countDown();
    }
  });

  WebRtcEndpoint webRtcEpRed = new WebRtcEndpoint.Builder(mp).build();
  WebRtcEndpoint webRtcEpGreen = new WebRtcEndpoint.Builder(mp).build();

  String recordingFile = getRecordUrl(extension);
  RecorderEndpoint recorderEp = new RecorderEndpoint.Builder(mp, recordingFile)
      .withMediaProfile(mediaProfileSpecType).build();

  // Test execution
  getPage(BROWSER1).subscribeLocalEvents("playing");
  long startWebrtc = System.currentTimeMillis();
  getPage(BROWSER1).initWebRtc(webRtcEpRed, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_ONLY);

  webRtcEpRed.connect(recorderEp);
  recorderEp.record();

  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage(BROWSER1).waitForEvent("playing"));
  long webrtcRedConnectionTime = System.currentTimeMillis() - startWebrtc;
  Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / N_PLAYER);

  getPage(BROWSER2).subscribeLocalEvents("playing");
  startWebrtc = System.currentTimeMillis();
  getPage(BROWSER2).initWebRtc(webRtcEpGreen, WebRtcChannel.AUDIO_AND_VIDEO,
      WebRtcMode.SEND_ONLY);

  // green
  webRtcEpGreen.connect(recorderEp);

  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage(BROWSER2).waitForEvent("playing"));
  long webrtcGreenConnectionTime = System.currentTimeMillis() - startWebrtc;
  Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / N_PLAYER);

  webRtcEpRed.connect(recorderEp);

  startWebrtc = System.currentTimeMillis();
  Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / N_PLAYER);

  // Release Media Pipeline #1
  saveGstreamerDot(mp);
  final CountDownLatch recorderLatch = new CountDownLatch(1);
  recorderEp.stopAndWait(new Continuation<Void>() {

    @Override
    public void onSuccess(Void result) throws Exception {
      recorderLatch.countDown();
    }

    @Override
    public void onError(Throwable cause) throws Exception {
      recorderLatch.countDown();
    }
  });

  Assert.assertTrue("Not stop properly",
      recorderLatch.await(getPage(BROWSER2).getTimeout(), TimeUnit.SECONDS));
  mp.release();

  Assert.assertTrue(msgError, errorPipelinelatch.getCount() == 1);

  final long playtime = PLAYTIME + TimeUnit.MILLISECONDS
      .toSeconds((2 * webrtcRedConnectionTime) + webrtcGreenConnectionTime);

  checkRecordingFile(recordingFile, BROWSER3, EXPECTED_COLORS, playtime, expectedVideoCodec,
      expectedAudioCodec);
  success = true;
}
 
Example #24
Source File: ServerManagerTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void readPipelineElements() throws IOException {

  MediaPipeline pipeline = kurentoClient.createMediaPipeline();

  new WebRtcEndpoint.Builder(pipeline).build();

  KurentoClient otherKurentoClient = kms.createKurentoClient();

  ServerManager serverManager = otherKurentoClient.getServerManager();

  List<MediaPipeline> mediaPipelines = serverManager.getPipelines();

  for (MediaObject o : mediaPipelines.get(0).getChildren()) {
    if (o.getId().indexOf("WebRtcEndpoint") >= 0) {
      WebRtcEndpoint webRtc = (WebRtcEndpoint) o;

      assertThat(pipeline, is(webRtc.getParent()));
    }
  }
}
 
Example #25
Source File: RecorderNonExistingDirectoryTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public void doTest(MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec,
    String expectedAudioCodec, String extension) throws Exception {

  final CountDownLatch recorderLatch = new CountDownLatch(1);

  MediaPipeline mp = kurentoClient.createMediaPipeline();
  WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(mp).build();

  String recordingFile = getRecordUrl(extension);

  recordingFile = recordingFile.replace(getSimpleTestName(),
      new Date().getTime() + File.separator + getSimpleTestName());

  log.debug("The path non existing is {} ", recordingFile);

  RecorderEndpoint recorderEp = new RecorderEndpoint.Builder(mp, recordingFile)
      .withMediaProfile(mediaProfileSpecType).build();
  webRtcEp.connect(webRtcEp);
  webRtcEp.connect(recorderEp);

  getPage().subscribeEvents("playing");
  getPage().initWebRtc(webRtcEp, AUDIO_AND_VIDEO, WebRtcMode.SEND_RCV);
  recorderEp.record();

  // Wait until event playing in the remote stream
  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage().waitForEvent("playing"));

  Thread.sleep(SECONDS.toMillis(PLAYTIME));

  recorderEp.stopAndWait(new Continuation<Void>() {

    @Override
    public void onSuccess(Void result) throws Exception {
      recorderLatch.countDown();
    }

    @Override
    public void onError(Throwable cause) throws Exception {
      recorderLatch.countDown();
    }
  });

  Assert.assertTrue("Not stop properly",
      recorderLatch.await(getPage().getTimeout(), TimeUnit.SECONDS));

  // Wait until file exists
  waitForFileExists(recordingFile);

  AssertMedia.assertCodecs(recordingFile, expectedVideoCodec, expectedAudioCodec);
  mp.release();
}
 
Example #26
Source File: WebRtcFakeMediaTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testWebRtcLoopback() throws Exception {

  // Media Pipeline
  MediaPipeline mp = kurentoClient.createMediaPipeline();
  WebRtcEndpoint webRtcEndpoint = new WebRtcEndpoint.Builder(mp).build();
  webRtcEndpoint.connect(webRtcEndpoint);

  final CountDownLatch flowingLatch = new CountDownLatch(1);
  webRtcEndpoint
      .addMediaFlowInStateChangeListener(new EventListener<MediaFlowInStateChangeEvent>() {

        @Override
        public void onEvent(MediaFlowInStateChangeEvent event) {
          if (event.getState().equals(MediaFlowState.FLOWING)) {
            flowingLatch.countDown();
          }
        }
      });

  // Start WebRTC and wait for playing event
  getPage().subscribeEvents("playing");
  getPage().initWebRtc(webRtcEndpoint, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_RCV);

  Assert.assertTrue("Not received FLOWING IN event in webRtcEp: " + WebRtcChannel.AUDIO_AND_VIDEO,
      flowingLatch.await(getPage().getTimeout(), TimeUnit.SECONDS));

  Assert.assertTrue(
      "Not received media (timeout waiting playing event): " + WebRtcChannel.AUDIO_AND_VIDEO,
      getPage().waitForEvent("playing"));

  // Guard time to play the video
  waitSeconds(PLAYTIME);

  // Assertions
  double currentTime = getPage().getCurrentTime();
  Assert.assertTrue(
      "Error in play time (expected: " + PLAYTIME + " sec, real: " + currentTime + " sec)",
      getPage().compare(PLAYTIME, currentTime));

  // Release Media Pipeline
  mp.release();
}
 
Example #27
Source File: WebRtcThreeSwitchTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testWebRtcSwitch() throws InterruptedException {
  // Media Pipeline
  MediaPipeline mp = kurentoClient.createMediaPipeline();
  WebRtcEndpoint[] webRtcEndpoints = new WebRtcEndpoint[NUM_BROWSERS];

  for (int i = 0; i < NUM_BROWSERS; i++) {
    webRtcEndpoints[i] = new WebRtcEndpoint.Builder(mp).build();
    webRtcEndpoints[i].connect(webRtcEndpoints[i]);

    // Start WebRTC in loopback in each browser
    getPage(i).subscribeEvents("playing");
    getPage(i).initWebRtc(webRtcEndpoints[i], WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_RCV);

    // Delay time (to avoid the same timing in videos)
    waitSeconds(1);

    // Wait until event playing in the remote streams
    Assert.assertTrue("Not received media #1 (timeout waiting playing event)",
        getPage(i).waitForEvent("playing"));

    // Assert color
    assertColor(i);
  }

  // Guard time to see switching #0
  waitSeconds(PLAYTIME);

  // Switching (round #1)
  for (int i = 0; i < NUM_BROWSERS; i++) {
    int next = i + 1 >= NUM_BROWSERS ? 0 : i + 1;
    webRtcEndpoints[i].connect(webRtcEndpoints[next]);
    getPage(i).consoleLog(ConsoleLogLevel.INFO,
        "Switch #1: webRtcEndpoint" + i + " -> webRtcEndpoint" + next);
    // Assert color
    assertColor(i);
  }

  // Guard time to see switching #1
  waitSeconds(PLAYTIME);

  // Switching (round #2)
  for (int i = 0; i < NUM_BROWSERS; i++) {
    int previous = i - 1 < 0 ? NUM_BROWSERS - 1 : i - 1;
    webRtcEndpoints[i].connect(webRtcEndpoints[previous]);
    getPage(i).consoleLog(ConsoleLogLevel.INFO,
        "Switch #2: webRtcEndpoint" + i + " -> webRtcEndpoint" + previous);
    // Assert color
    assertColor(i);
  }

  // Guard time to see switching #2
  waitSeconds(PLAYTIME);

  // Release Media Pipeline
  mp.release();
}
 
Example #28
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
public void setWebRtcEndpoint(WebRtcEndpoint webRtcEndpoint) {
  this.webRtcEndpoint = webRtcEndpoint;
}
 
Example #29
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
public void setWebRtcEndpoint(WebRtcEndpoint webRtcEndpoint) {
  this.webRtcEndpoint = webRtcEndpoint;
}
 
Example #30
Source File: RecorderFaceOverlayTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public void doTest(MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec,
    String expectedAudioCodec, String extension) throws Exception {

  // Media Pipeline #1
  MediaPipeline mp = kurentoClient.createMediaPipeline();
  PlayerEndpoint playerEp =
      new PlayerEndpoint.Builder(mp, getPlayerUrl("/video/filter/fiwarecut.mp4")).build();
  WebRtcEndpoint webRtcEp1 = new WebRtcEndpoint.Builder(mp).build();

  FaceOverlayFilter filter = new FaceOverlayFilter.Builder(mp).build();
  filter.setOverlayedImage("http://" + getTestFilesHttpPath() + "/img/red-square.png", -0.2F,
      -1.2F, 1.6F, 1.6F);

  String recordingFile = getRecordUrl(extension);
  RecorderEndpoint recorderEp = new RecorderEndpoint.Builder(mp, recordingFile)
      .withMediaProfile(mediaProfileSpecType).build();
  playerEp.connect(filter);
  filter.connect(webRtcEp1);
  filter.connect(recorderEp);

  // Test execution #1. Play and record
  getPage().setThresholdTime(THRESHOLD);
  launchBrowser(mp, webRtcEp1, playerEp, recorderEp, expectedVideoCodec, expectedAudioCodec,
      recordingFile, EXPECTED_COLOR, EXPECTED_COLOR_X, EXPECTED_COLOR_Y, PLAYTIME);

  // Release Media Pipeline #1
  mp.release();

  // Reloading browser
  getPage().reload();

  // Media Pipeline #2
  MediaPipeline mp2 = kurentoClient.createMediaPipeline();
  PlayerEndpoint playerEp2 = new PlayerEndpoint.Builder(mp2, recordingFile).build();
  WebRtcEndpoint webRtcEp2 = new WebRtcEndpoint.Builder(mp2).build();
  playerEp2.connect(webRtcEp2);

  // Playing the recording
  launchBrowser(mp, webRtcEp2, playerEp2, null, expectedVideoCodec, expectedAudioCodec,
      recordingFile, EXPECTED_COLOR, EXPECTED_COLOR_X, EXPECTED_COLOR_Y, PLAYTIME);

  // Release Media Pipeline #2
  mp2.release();

  success = true;
}