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

The following examples show how to use org.kurento.client.PlayerEndpoint#stop() . 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: PlayerEndTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public void doTest(PlayerOperation playerOperation) throws Exception {
  // Test data
  final String mediaUrl = "http://" + getTestFilesHttpPath() + "/video/format/small.webm";
  final int guardTimeSeconds = 10;

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

  // Subscription to EOS event
  final boolean[] eos = new boolean[1];
  eos[0] = false;
  playerEp.addEndOfStreamListener(new EventListener<EndOfStreamEvent>() {
    @Override
    public void onEvent(EndOfStreamEvent event) {
      log.error("EOS event received: {} {}", event.getType(), event.getTimestamp());
      eos[0] = true;
    }
  });

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

  // Stop/release stream and wait x seconds
  switch (playerOperation) {
    case STOP:
      playerEp.stop();
      break;
    case RELEASE:
      playerEp.release();
      break;
  }
  Thread.sleep(TimeUnit.SECONDS.toMillis(guardTimeSeconds));

  // Verify that EOS event has not being received
  Assert.assertFalse("EOS event has been received. "
      + "This should not be happenning because the stream has been stopped", eos[0]);

  // Release Media Pipeline
  mp.release();
}
 
Example 2
Source File: CompositeRecorderTest.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);
  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);

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

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

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

  success = true;
}
 
Example 3
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 4
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 5
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 6
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();
}