Java Code Examples for org.kurento.client.PlayerEndpoint#connect()

The following examples show how to use org.kurento.client.PlayerEndpoint#connect() . 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: TransactionTest.java    From kurento-java with Apache License 2.0 6 votes vote down vote up
@Test(expected = TransactionNotCommitedException.class)
public void usePlainMethodsWithNewObjectsAsParamsInsideTx() throws InterruptedException,
    ExecutionException {

  // Pipeline creation (no transaction)
  MediaPipeline pipeline = kurentoClient.createMediaPipeline();
  PlayerEndpoint player =
      new PlayerEndpoint.Builder(pipeline, "http://" + getTestFilesHttpPath()
          + "/video/format/small.webm").build();

  // Creation in explicit transaction
  Transaction tx = pipeline.beginTransaction();
  HttpPostEndpoint httpEndpoint = new HttpPostEndpoint.Builder(pipeline).build(tx);

  // TransactionNotExecutedExcetion should be thrown
  player.connect(httpEndpoint);

}
 
Example 2
Source File: RtpEndpointAsyncTest.java    From kurento-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testRtpEndpointSimulatingAndroidSdp() throws InterruptedException {

  PlayerEndpoint player = new PlayerEndpoint.Builder(pipeline, URL_BARCODES).build();

  RtpEndpoint rtpEndpoint = new RtpEndpoint.Builder(pipeline).build();

  String requestSdp = "v=0\r\n" + "o=- 12345 12345 IN IP4 95.125.31.136\r\n" + "s=-\r\n"
      + "c=IN IP4 95.125.31.136\r\n" + "t=0 0\r\n" + "m=video 52126 RTP/AVP 96 97 98\r\n"
      + "a=rtpmap:96 H264/90000\r\n" + "a=rtpmap:97 MP4V-ES/90000\r\n"
      + "a=rtpmap:98 H263-1998/90000\r\n" + "a=recvonly\r\n" + "b=AS:384\r\n";

  rtpEndpoint.processOffer(requestSdp);
  player.connect(rtpEndpoint, MediaType.VIDEO);
  player.play();

  // just a little bit of time before destroying
  Thread.sleep(2000);
}
 
Example 3
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 4
Source File: TransactionTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Test
public void transactionTest() throws InterruptedException, ExecutionException {

  // Pipeline creation (no transaction)
  MediaPipeline pipeline = kurentoClient.createMediaPipeline();

  PlayerEndpoint player =
      new PlayerEndpoint.Builder(pipeline, "http://" + getTestFilesHttpPath()
          + "/video/format/small.webm").useEncodedMedia().build();

  HttpPostEndpoint httpEndpoint = new HttpPostEndpoint.Builder(pipeline).build();

  player.connect(httpEndpoint);

  String url = httpEndpoint.getUrl();
  // End pipeline creation

  // Explicit transaction
  Transaction tx = pipeline.beginTransaction();
  player.play(tx);
  TFuture<String> fUrl = httpEndpoint.getUrl(tx);
  pipeline.release(tx);
  tx.commit();
  // End explicit transaction

  assertThat(url, is(fUrl.get()));
}
 
Example 5
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 6
Source File: TransactionTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Test
public void creationInTransaction() throws InterruptedException, ExecutionException {

  // Pipeline creation (transaction)
  Transaction tx1 = kurentoClient.beginTransaction();

  MediaPipeline pipeline = kurentoClient.createMediaPipeline(tx1);

  PlayerEndpoint player =
      new PlayerEndpoint.Builder(pipeline, "http://" + getTestFilesHttpPath()
          + "/video/format/small.webm").useEncodedMedia().build(tx1);

  HttpPostEndpoint httpEndpoint = new HttpPostEndpoint.Builder(pipeline).build(tx1);

  player.connect(tx1, httpEndpoint);
  TFuture<String> url1 = httpEndpoint.getUrl(tx1);
  tx1.commit();
  // End pipeline creation

  // Explicit transaction
  Transaction tx2 = pipeline.beginTransaction();
  player.play(tx2);
  TFuture<String> url2 = httpEndpoint.getUrl(tx2);
  pipeline.release(tx2);
  tx2.commit();
  // End explicit transaction

  assertThat(url1.get(), is(url2.get()));
}
 
Example 7
Source File: DispatcherOneToManyPlayerTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testDispatcherOneToManyPlayer() throws Exception {
  MediaPipeline mp = kurentoClient.createMediaPipeline();

  PlayerEndpoint playerEp =
      new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/30sec/red.webm")
          .build();
  PlayerEndpoint playerEp2 = new PlayerEndpoint.Builder(mp,
      "http://" + getTestFilesHttpPath() + "/video/30sec/blue.webm").build();
  WebRtcEndpoint webRtcEp1 = new WebRtcEndpoint.Builder(mp).build();
  WebRtcEndpoint webRtcEp2 = new WebRtcEndpoint.Builder(mp).build();
  WebRtcEndpoint webRtcEp3 = new WebRtcEndpoint.Builder(mp).build();

  DispatcherOneToMany dispatcherOneToMany = new DispatcherOneToMany.Builder(mp).build();
  HubPort hubPort1 = new HubPort.Builder(dispatcherOneToMany).build();
  HubPort hubPort2 = new HubPort.Builder(dispatcherOneToMany).build();
  HubPort hubPort3 = new HubPort.Builder(dispatcherOneToMany).build();
  HubPort hubPort4 = new HubPort.Builder(dispatcherOneToMany).build();
  HubPort hubPort5 = new HubPort.Builder(dispatcherOneToMany).build();

  playerEp.connect(hubPort1);
  playerEp2.connect(hubPort2);
  hubPort3.connect(webRtcEp1);
  hubPort4.connect(webRtcEp2);
  hubPort5.connect(webRtcEp3);
  dispatcherOneToMany.setSource(hubPort1);

  final CountDownLatch eosLatch = new CountDownLatch(1);
  playerEp2.addEndOfStreamListener(new EventListener<EndOfStreamEvent>() {
    @Override
    public void onEvent(EndOfStreamEvent event) {
      eosLatch.countDown();
    }
  });

  // Test execution
  getPage(BROWSER1).subscribeEvents("playing");
  getPage(BROWSER1).initWebRtc(webRtcEp2, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY);

  getPage(BROWSER2).subscribeEvents("playing");
  getPage(BROWSER2).initWebRtc(webRtcEp1, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY);

  getPage(BROWSER3).subscribeEvents("playing");
  getPage(BROWSER3).initWebRtc(webRtcEp3, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY);

  playerEp.play();

  // Assertions
  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage(BROWSER1).waitForEvent("playing"));
  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage(BROWSER2).waitForEvent("playing"));
  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage(BROWSER3).waitForEvent("playing"));

  Assert.assertTrue("The color of the video should be red",
      getPage(BROWSER1).similarColor(Color.RED));
  Assert.assertTrue("The color of the video should be red",
      getPage(BROWSER2).similarColor(Color.RED));
  Assert.assertTrue("The color of the video should be red",
      getPage(BROWSER3).similarColor(Color.RED));

  Thread.sleep(3000);
  playerEp2.play();
  dispatcherOneToMany.setSource(hubPort2);

  Assert.assertTrue("The color of the video should be blue",
      getPage(BROWSER1).similarColor(Color.BLUE));
  Assert.assertTrue("The color of the video should be blue",
      getPage(BROWSER2).similarColor(Color.BLUE));
  Assert.assertTrue("The color of the video should be blue",
      getPage(BROWSER3).similarColor(Color.BLUE));

  Thread.sleep(3000);
  dispatcherOneToMany.setSource(hubPort1);

  Assert.assertTrue("The color of the video should be red",
      getPage(BROWSER1).similarColor(Color.RED));
  Assert.assertTrue("The color of the video should be red",
      getPage(BROWSER2).similarColor(Color.RED));
  Assert.assertTrue("The color of the video should be red",
      getPage(BROWSER3).similarColor(Color.RED));

  Thread.sleep(3000);

  dispatcherOneToMany.setSource(hubPort2);

  Assert.assertTrue("The color of the video should be red",
      getPage(BROWSER1).similarColor(Color.BLUE));
  Assert.assertTrue("The color of the video should be red",
      getPage(BROWSER2).similarColor(Color.BLUE));
  Assert.assertTrue("The color of the video should be red",
      getPage(BROWSER3).similarColor(Color.BLUE));

  Thread.sleep(3000);

  Assert.assertTrue("Not received EOS event in player",
      eosLatch.await(TIMEOUT_EOS, TimeUnit.SECONDS));
}
 
Example 8
Source File: FaceOverlayFilterTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
/**
 * Test if a {@link FaceOverlayFilter} can be created in the KMS. The filter is pipelined with a
 * {@link PlayerEndpoint}, which feeds video to the filter. This test depends on the correct
 * behaviour of the player and its events.
 *
 * @throws InterruptedException
 */
@Test
public void testFaceOverlayFilter() throws InterruptedException {
  PlayerEndpoint player = new PlayerEndpoint.Builder(pipeline, URL_POINTER_DETECTOR).build();

  player.connect(overlayFilter);

  AsyncEventManager<EndOfStreamEvent> async = new AsyncEventManager<>("EndOfStream event");

  player.addEndOfStreamListener(async.getMediaEventListener());

  player.play();

  async.waitForResult();

  player.stop();
  player.release();
}
 
Example 9
Source File: CompositeAudioRecorderTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testCompositeRecorder() throws Exception {
  // MediaPipeline
  MediaPipeline mp = kurentoClient.createMediaPipeline();

  PlayerEndpoint playerRed =
      new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/30sec/red.webm")
          .build();
  PlayerEndpoint playerGreen = new PlayerEndpoint.Builder(mp,
      "http://" + getTestFilesHttpPath() + "/video/30sec/green.webm").build();
  PlayerEndpoint playerBlue = new PlayerEndpoint.Builder(mp,
      "http://" + getTestFilesHttpPath() + "/video/30sec/blue.webm").build();

  Composite composite = new Composite.Builder(mp).build();
  HubPort hubPort1 = new HubPort.Builder(composite).build();
  HubPort hubPort2 = new HubPort.Builder(composite).build();
  HubPort hubPort3 = new HubPort.Builder(composite).build();

  playerRed.connect(hubPort1);
  playerGreen.connect(hubPort2, MediaType.AUDIO);
  playerBlue.connect(hubPort3, MediaType.AUDIO);

  PlayerEndpoint playerWhite = new PlayerEndpoint.Builder(mp,
      "http://" + getTestFilesHttpPath() + "/video/30sec/white.webm").build();
  HubPort hubPort4 = new HubPort.Builder(composite).build();
  playerWhite.connect(hubPort4, MediaType.AUDIO);

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

  playerRed.play();
  playerGreen.play();
  playerBlue.play();
  playerWhite.play();

  recorderEp.record();

  Thread.sleep(RECORDTIME * 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().getTimeout(), TimeUnit.SECONDS));

  playerRed.stop();
  playerGreen.stop();
  playerBlue.stop();
  playerWhite.stop();

  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 recording
  launchBrowser(mp, 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 10
Source File: ZBarFilterTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testCodeFoundEvent() throws InterruptedException {

  PlayerEndpoint player = new PlayerEndpoint.Builder(pipeline, URL_BARCODES).build();
  player.connect(zbar);

  AsyncEventManager<CodeFoundEvent> async = new AsyncEventManager<>("CodeFound event");

  zbar.addCodeFoundListener(async.getMediaEventListener());

  player.play();

  async.waitForResult();

  player.stop();
  player.release();
}
 
Example 11
Source File: CompositePlayerTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testCompositePlayer() throws Exception {
  // Media Pipeline
  MediaPipeline mp = kurentoClient.createMediaPipeline();

  PlayerEndpoint playerRed =
      new PlayerEndpoint.Builder(mp, "http://" + getTestFilesHttpPath() + "/video/30sec/red.webm")
          .build();
  PlayerEndpoint playerGreen = new PlayerEndpoint.Builder(mp,
      "http://" + getTestFilesHttpPath() + "/video/30sec/green.webm").build();
  PlayerEndpoint playerBlue = new PlayerEndpoint.Builder(mp,
      "http://" + getTestFilesHttpPath() + "/video/30sec/blue.webm").build();

  Composite composite = new Composite.Builder(mp).build();
  HubPort hubPort1 = new HubPort.Builder(composite).build();
  HubPort hubPort2 = new HubPort.Builder(composite).build();
  HubPort hubPort3 = new HubPort.Builder(composite).build();

  playerRed.connect(hubPort1);
  playerGreen.connect(hubPort2);
  playerBlue.connect(hubPort3);

  PlayerEndpoint playerWhite = new PlayerEndpoint.Builder(mp,
      "http://" + getTestFilesHttpPath() + "/video/30sec/white.webm").build();
  HubPort hubPort4 = new HubPort.Builder(composite).build();
  playerWhite.connect(hubPort4);

  WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(mp).build();
  HubPort hubPort5 = new HubPort.Builder(composite).build();
  hubPort5.connect(webRtcEp);

  // Test execution
  getPage().subscribeEvents("playing");
  getPage().initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY);

  playerRed.play();
  playerGreen.play();
  playerBlue.play();
  playerWhite.play();

  // Assertions
  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage().waitForEvent("playing"));
  Assert.assertTrue("Upper left part of the video must be red",
      getPage().similarColorAt(Color.RED, 0, 0));
  Assert.assertTrue("Upper right part of the video must be green",
      getPage().similarColorAt(Color.GREEN, 450, 0));
  Assert.assertTrue("Lower left part of the video must be blue",
      getPage().similarColorAt(Color.BLUE, 0, 450));
  Assert.assertTrue("Lower right part of the video must be white",
      getPage().similarColorAt(Color.WHITE, 450, 450));

  // Guard time to see the composite result
  Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME));

  // Release Media Pipeline
  mp.release();
}
 
Example 12
Source File: RecorderSwitchPlayerWebRtcTest.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();
  WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(mp).build();
  PlayerEndpoint playerRed =
      new PlayerEndpoint.Builder(mp, getPlayerUrl("/video/10sec/red.webm")).build();
  playerRed.connect(webRtcEp);

  // Test execution
  getPage(0).subscribeLocalEvents("playing");
  getPage(0).initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_ONLY);
  playerRed.play();

  // red
  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage(0).waitForEvent("playing"));

  PlayerEndpoint playerGreen =
      new PlayerEndpoint.Builder(mp, getPlayerUrl("/video/10sec/green.webm")).build();

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

  playerGreen.play();
  recorderEp.record();
  for (int i = 0; i < NUM_SWAPS; i++) {
    if (i % 2 == 0) {
      playerRed.connect(recorderEp);
    } else {
      playerGreen.connect(recorderEp);
    }

    Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / NUM_SWAPS);
  }

  // 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(0).getTimeout(), TimeUnit.SECONDS));
  mp.release();

  // Reloading browser
  getPage(0).close();

  checkRecordingFile(recordingFile, "browser1", EXPECTED_COLORS, PLAYTIME, expectedVideoCodec,
      expectedAudioCodec);
  success = true;
}
 
Example 13
Source File: RecorderSwitchWebRtcWebRtcAndPlayerTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public void doTestWithPlayer(MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec,
    String expectedAudioCodec, String extension, String mediaUrlPlayer) throws Exception {
  // Media Pipeline #1
  getPage(BROWSER2).close();
  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();
  PlayerEndpoint playerEp = new PlayerEndpoint.Builder(mp, mediaUrlPlayer).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);

  startWebrtc = System.currentTimeMillis();

  playerEp.play();
  playerEp.connect(recorderEp);
  long playerEpConnectionTime = System.currentTimeMillis() - startWebrtc;
  Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / N_PLAYER);

  webRtcEpRed.connect(recorderEp);
  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(BROWSER1).getTimeout(), TimeUnit.SECONDS));
  mp.release();

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

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

  checkRecordingFile(recordingFile, BROWSER3, EXPECTED_COLORS, playtime, expectedVideoCodec,
      expectedAudioCodec);
  success = true;
}
 
Example 14
Source File: RecorderPlayerDisconnectTest.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);

  // Media Pipeline #1
  MediaPipeline mp = kurentoClient.createMediaPipeline();
  PlayerEndpoint playerGreen =
      new PlayerEndpoint.Builder(mp, getPlayerUrl("/video/10sec/green.webm")).build();

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

  playerGreen.play();
  recorderEp.record();
  for (int i = 0; i < NUM_SWAPS; i++) {
    if (i % 2 == 0) {
      playerGreen.connect(recorderEp);
    } else {
      playerGreen.disconnect(recorderEp);
    }

    Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / NUM_SWAPS);
  }

  // Release Media Pipeline #1
  saveGstreamerDot(mp);

  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));

  mp.release();

  // Wait until file exists
  waitForFileExists(recordingFile);

  // 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
  getPage().subscribeEvents("playing");
  getPage().initWebRtc(webRtcEp2, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY);
  final CountDownLatch eosLatch = new CountDownLatch(1);
  playerEp2.addEndOfStreamListener(new EventListener<EndOfStreamEvent>() {
    @Override
    public void onEvent(EndOfStreamEvent event) {
      eosLatch.countDown();
    }
  });
  playerEp2.play();

  // Assertions in recording
  final String messageAppend = "[played file with media pipeline]";
  final int playtime = PLAYTIME;

  Assert.assertTrue(
      "Not received media in the recording (timeout waiting playing event) " + messageAppend,
      getPage().waitForEvent("playing"));
  for (Color color : EXPECTED_COLORS) {
    Assert.assertTrue("The color of the recorded video should be " + color + " " + messageAppend,
        getPage().similarColor(color));
  }
  Assert.assertTrue("Not received EOS event in player",
      eosLatch.await(getPage().getTimeout(), TimeUnit.SECONDS));

  double currentTime = getPage().getCurrentTime();
  Assert.assertTrue("Error in play time in the recorded video (expected: " + playtime
      + " sec, real: " + currentTime + " sec) " + messageAppend,
      getPage().compare(playtime, currentTime));

  AssertMedia.assertCodecs(recordingFile, expectedVideoCodec, expectedAudioCodec);
  AssertMedia.assertDuration(recordingFile, TimeUnit.SECONDS.toMillis(playtime),
      TimeUnit.SECONDS.toMillis(getPage().getThresholdTime()));

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

  success = true;
}
 
Example 15
Source File: RecorderSwitchWebRtcWebRtcPlayerWithPassThroughTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public void doTestWithPlayer(MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec,
    String expectedAudioCodec, String extension, String mediaUrlPlayer) throws Exception {
  // Media Pipeline #1
  getPage(BROWSER2).close();
  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();
  PlayerEndpoint playerEp = new PlayerEndpoint.Builder(mp, mediaUrlPlayer).build();

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

  PassThrough passThrough = new PassThrough.Builder(mp).build();
  passThrough.connect(recorderEp);

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

  webRtcEpRed.connect(passThrough);
  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);

  startWebrtc = System.currentTimeMillis();

  playerEp.play();
  playerEp.connect(passThrough);
  long playerEpConnectionTime = System.currentTimeMillis() - startWebrtc;
  Thread.sleep(TimeUnit.SECONDS.toMillis(PLAYTIME) / N_PLAYER);

  webRtcEpRed.connect(passThrough);
  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(BROWSER1).getTimeout(), TimeUnit.SECONDS));
  mp.release();

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

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

  checkRecordingFile(recordingFile, BROWSER3, EXPECTED_COLORS, playtime, expectedVideoCodec,
      expectedAudioCodec);
  success = true;
}
 
Example 16
Source File: TransactionTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void asyncTransaction() throws InterruptedException, ExecutionException {

  Transaction tx = kurentoClient.beginTransaction();

  MediaPipeline pipeline = kurentoClient.createMediaPipeline();

  PlayerEndpoint player =
      new PlayerEndpoint.Builder(pipeline, "http://" + getTestFilesHttpPath()
          + "/video/format/small.webm").build();

  HttpPostEndpoint httpEndpoint = new HttpPostEndpoint.Builder(pipeline).build();

  player.connect(httpEndpoint);

  AsyncResultManager<Void> async = new AsyncResultManager<>("async start");

  tx.commit(async.getContinuation());

  async.waitForResult();

  assertThat(pipeline.isCommited(), is(true));
}
 
Example 17
Source File: RecorderPlayerSwitchSequentialTest.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 = null;

  // Media Pipeline
  mp = kurentoClient.createMediaPipeline();
  PlayerEndpoint playerEp1 =
      new PlayerEndpoint.Builder(mp, getPlayerUrl("/video/60sec/ball.webm")).build();
  PlayerEndpoint playerEp2 =
      new PlayerEndpoint.Builder(mp, getPlayerUrl("/video/60sec/smpte.webm")).build();

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

  // Start play and record
  playerEp1.play();
  playerEp2.play();
  recorderEp.record();

  // Switch players
  for (int i = 0; i < SWITCH_TIMES; i++) {
    if (i % 2 == 0) {
      playerEp1.connect(recorderEp);
    } else {
      playerEp2.connect(recorderEp);
    }

    Thread.sleep(SWITCH_RATE_MS);
  }

  // Stop play and record
  playerEp1.stop();
  playerEp2.stop();
  recorderEp.stop(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(TIMEOUT, TimeUnit.SECONDS));

  // Assessments
  long expectedTimeMs = SWITCH_TIMES * SWITCH_RATE_MS;
  AssertMedia.assertCodecs(recordingFile, expectedVideoCodec, expectedAudioCodec);
  AssertMedia.assertDuration(recordingFile, expectedTimeMs, THRESHOLD_MS);

  // Release Media Pipeline
  if (mp != null) {
    mp.release();
  }

}
 
Example 18
Source File: RepositoryRecorderTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testRepositoryRecorder() throws Exception {

  final CountDownLatch recorderLatch = new CountDownLatch(1);

  // Media Pipeline
  MediaPipeline mp = kurentoClient.createMediaPipeline();
  PlayerEndpoint playerEp = new PlayerEndpoint.Builder(mp,
      "http://" + getTestFilesHttpPath() + "/video/10sec/ball.webm").build();
  WebRtcEndpoint webRtcEp1 = new WebRtcEndpoint.Builder(mp).build();

  RepositoryItem repositoryItem = repository.createRepositoryItem();
  RepositoryHttpRecorder recorder = repositoryItem.createRepositoryHttpRecorder();

  RecorderEndpoint recorderEp = new RecorderEndpoint.Builder(mp, recorder.getURL()).build();
  playerEp.connect(webRtcEp1);
  playerEp.connect(recorderEp);

  final CountDownLatch eosLatch = new CountDownLatch(1);
  playerEp.addEndOfStreamListener(new EventListener<EndOfStreamEvent>() {
    @Override
    public void onEvent(EndOfStreamEvent event) {
      eosLatch.countDown();
    }
  });

  // Test execution #1. Play the video while it is recorded
  launchBrowser(webRtcEp1, playerEp, recorderEp);

  // Wait for EOS
  Assert.assertTrue("Not received EOS event in player",
      eosLatch.await(getPage().getTimeout(), TimeUnit.SECONDS));

  // Release Media Pipeline #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().getTimeout(), TimeUnit.SECONDS));

  mp.release();
  Thread.sleep(500);
}
 
Example 19
Source File: TransactionTest.java    From kurento-java with Apache License 2.0 3 votes vote down vote up
@Test
public void whenCommitedTest() throws InterruptedException, ExecutionException {

  // Pipeline creation (transaction)

  Transaction tx = kurentoClient.beginTransaction();

  MediaPipeline pipeline = kurentoClient.createMediaPipeline(tx);

  final PlayerEndpoint player =
      new PlayerEndpoint.Builder(pipeline, "http://" + getTestFilesHttpPath()
          + "/video/format/small.webm").build(tx);

  HttpPostEndpoint httpEndpoint = new HttpPostEndpoint.Builder(pipeline).build(tx);

  player.connect(tx, httpEndpoint);

  AsyncResultManager<PlayerEndpoint> async = new AsyncResultManager<>("whenCommited");

  player.whenCommited(async.getContinuation());

  tx.commit();

  PlayerEndpoint newPlayer = async.waitForResult();

  assertThat(player, is(newPlayer));
}
 
Example 20
Source File: BasicPipelineTest.java    From kurento-java with Apache License 2.0 3 votes vote down vote up
@Test
public void basicPipelineTest() {

  PlayerEndpoint player =
      new PlayerEndpoint.Builder(pipeline, "http://" + getTestFilesHttpPath()
          + "/video/format/small.webm").build();

  HttpPostEndpoint httpEndpoint = new HttpPostEndpoint.Builder(pipeline).build();

  player.connect(httpEndpoint);

  for (int i = 0; i < 100; i++) {

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

    player.connect(webRtc);

  }

  System.out.println("Dot length: " + pipeline.getGstreamerDot().getBytes().length);

  String url = httpEndpoint.getUrl();

  player.release();

  Assert.assertNotSame("The URL shouldn't be empty", "", url);
}