Java Code Examples for org.kurento.client.ErrorEvent

The following examples show how to use org.kurento.client.ErrorEvent. These examples are extracted from open source projects. 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 Project: kurento-tutorial-java   Source File: PlayMediaPipeline.java    License: 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 2
Source Project: kurento-tutorial-java   Source File: PlayMediaPipeline.java    License: 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 3
Source Project: openvidu   Source File: MediaEndpoint.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Registers a listener for when the {@link MediaElement} triggers an
 * {@link ErrorEvent}. Notifies the owner with the error.
 *
 * @param element the {@link MediaElement}
 * @return {@link ListenerSubscription} that can be used to deregister the
 *         listener
 */
protected ListenerSubscription registerElemErrListener(MediaElement element) {
	return element.addErrorListener(new EventListener<ErrorEvent>() {
		@Override
		public void onEvent(ErrorEvent event) {
			owner.sendMediaError(event);
		}
	});
}
 
Example 4
Source Project: kurento-room   Source File: TestPipeline.java    License: Apache License 2.0 5 votes vote down vote up
public void createPipeline() {
  synchronized (pipelineCreateLock) {
    if (pipeline != null) {
      return;
    }
    log.info("Session '{}': Creating MediaPipeline-{}", room, description);
    try {
      pipeline = kurento.createMediaPipeline();
      pipelineLatch.countDown();
      log.debug("Session '{}': Created MediaPipeline-{}", room, description);
    } catch (Exception e) {
      log.error("Unable to create MediaPipeline-{} for Session '{}'", description, room, e);
      pipelineLatch.countDown();
    }
    if (getPipeline() == null) {
      throw new RuntimeException("Unable to create MediaPipeline-" + description
          + " for session '" + room + "'");
    }

    pipeline.addErrorListener(new EventListener<ErrorEvent>() {
      @Override
      public void onEvent(ErrorEvent event) {
        String desc = event.getType() + ": " + event.getDescription() + "(errCode="
            + event.getErrorCode() + ")";
        log.warn("Session '{}': Pipeline error encountered for MediaPipeline-{}: {}", room,
            description, desc);
      }
    });
  }
}
 
Example 5
Source Project: kurento-room   Source File: MediaEndpoint.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Registers a listener for when the {@link MediaElement} triggers an {@link ErrorEvent}. Notifies
 * the owner with the error.
 *
 * @param element
 *          the {@link MediaElement}
 * @return {@link ListenerSubscription} that can be used to deregister the listener
 */
protected ListenerSubscription registerElemErrListener(MediaElement element) {
  return element.addErrorListener(new EventListener<ErrorEvent>() {
    @Override
    public void onEvent(ErrorEvent event) {
      owner.sendMediaError(event);
    }
  });
}
 
Example 6
@Test
public void pipelineError() {
  joinManyUsersOneRoom();

  // verifies pipeline error listener is added to room
  verify(pipeline, times(1)).addErrorListener(pipelineErrorEventCaptor.capture());

  // stub sendNotification of type MEDIAERROR_METHOD
  final String expectedErrorMessage = "TEST_PP_ERR: Fake pipeline error(errCode=505)";
  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocation) throws Throwable {
      Object[] args = invocation.getArguments();
      assertThat(args.length, is(3));

      assertThat(args[0], instanceOf(String.class));
      String participantId = (String) args[0];
      assertThat(usersParticipantRequests.keySet(), hasItem(participantId));
      assertThat(participantId, is(not(userx)));

      assertThat(args[2], instanceOf(JsonObject.class));
      JsonObject params = (JsonObject) args[2];
      assertNotNull(params.get(ProtocolElements.MEDIAERROR_ERROR_PARAM));
      String error = params.get(ProtocolElements.MEDIAERROR_ERROR_PARAM).getAsString();
      assertThat(error, is(expectedErrorMessage));

      return null;
    }
  }).when(notificationService).sendNotification(anyString(),
      eq(ProtocolElements.MEDIAERROR_METHOD), Matchers.isA(JsonObject.class));

  // triggers the last captured listener
  pipelineErrorEventCaptor.getValue().onEvent(
      new ErrorEvent(pipeline, "12345", null, "Fake pipeline error", 505, "TEST_PP_ERR"));

  // the error was "triggered" one time and all participants get notified
  verifyNotificationService(users.length, 0, usersParticipantRequests.size(),
      ProtocolElements.MEDIAERROR_METHOD);
}
 
Example 7
Source Project: kurento-java   Source File: MetaTestMountedVolumeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws InterruptedException {

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

  String videoPath = "file://" + getTestFilesDiskPath() + "/video/filter/barcodes.webm";

  PlayerEndpoint p = new PlayerEndpoint.Builder(mp, videoPath).build();

  final CountDownLatch latch = new CountDownLatch(1);

  p.addErrorListener(new EventListener<ErrorEvent>() {
    @Override
    public void onEvent(ErrorEvent event) {
      log.warn("Error un player: " + event.getDescription());
      latch.countDown();
    }
  });

  p.play();

  if (latch.await(5, TimeUnit.SECONDS)) {
    fail("Player error");
  }

  // Release Media Pipeline
  mp.release();
}
 
Example 8
Source Project: openvidu   Source File: KurentoSession.java    License: Apache License 2.0 4 votes vote down vote up
private void createPipeline() {
	synchronized (pipelineCreateLock) {
		if (pipeline != null) {
			return;
		}
		log.info("SESSION {}: Creating MediaPipeline", sessionId);
		try {
			kms.getKurentoClient().createMediaPipeline(new Continuation<MediaPipeline>() {
				@Override
				public void onSuccess(MediaPipeline result) throws Exception {
					pipeline = result;
					pipelineLatch.countDown();
					log.debug("SESSION {}: Created MediaPipeline", sessionId);
				}

				@Override
				public void onError(Throwable cause) throws Exception {
					pipelineCreationErrorCause = cause;
					pipelineLatch.countDown();
					log.error("SESSION {}: Failed to create MediaPipeline", sessionId, cause);
				}
			});
		} catch (Exception e) {
			log.error("Unable to create media pipeline for session '{}'", sessionId, e);
			pipelineLatch.countDown();
		}
		if (getPipeline() == null) {
			final String message = pipelineCreationErrorCause != null
					? pipelineCreationErrorCause.getLocalizedMessage()
					: "Unable to create media pipeline for session '" + sessionId + "'";
			pipelineCreationErrorCause = null;
			throw new OpenViduException(Code.ROOM_CANNOT_BE_CREATED_ERROR_CODE, message);
		}

		pipeline.addErrorListener(new EventListener<ErrorEvent>() {
			@Override
			public void onEvent(ErrorEvent event) {
				String desc = event.getType() + ": " + event.getDescription() + "(errCode=" + event.getErrorCode()
						+ ")";
				log.warn("SESSION {}: Pipeline error encountered: {}", sessionId, desc);
				kurentoSessionHandler.onPipelineError(sessionId, getParticipants(), desc);
			}
		});
	}
}
 
Example 9
Source Project: openvidu   Source File: KurentoParticipant.java    License: Apache License 2.0 4 votes vote down vote up
public void sendMediaError(ErrorEvent event) {
	String desc = event.getType() + ": " + event.getDescription() + "(errCode=" + event.getErrorCode() + ")";
	log.warn("PARTICIPANT {}: Media error encountered: {}", getParticipantPublicId(), desc);
	session.sendMediaError(this.getParticipantPrivateId(), desc);
}
 
Example 10
Source Project: kurento-room   Source File: Participant.java    License: Apache License 2.0 4 votes vote down vote up
public void sendMediaError(ErrorEvent event) {
  String desc =
      event.getType() + ": " + event.getDescription() + "(errCode=" + event.getErrorCode() + ")";
  log.warn("PARTICIPANT {}: Media error encountered: {}", name, desc);
  room.sendMediaError(id, desc);
}
 
Example 11
Source Project: kurento-room   Source File: Room.java    License: Apache License 2.0 4 votes vote down vote up
private void createPipeline() {
  synchronized (pipelineCreateLock) {
    if (pipeline != null) {
      return;
    }
    log.info("ROOM {}: Creating MediaPipeline", name);
    try {
      kurentoClient.createMediaPipeline(new Continuation<MediaPipeline>() {
        @Override
        public void onSuccess(MediaPipeline result) throws Exception {
          pipeline = result;
          pipelineLatch.countDown();
          log.debug("ROOM {}: Created MediaPipeline", name);
        }

        @Override
        public void onError(Throwable cause) throws Exception {
          pipelineLatch.countDown();
          log.error("ROOM {}: Failed to create MediaPipeline", name, cause);
        }
      });
    } catch (Exception e) {
      log.error("Unable to create media pipeline for room '{}'", name, e);
      pipelineLatch.countDown();
    }
    if (getPipeline() == null) {
      throw new RoomException(Code.ROOM_CANNOT_BE_CREATED_ERROR_CODE,
          "Unable to create media pipeline for room '" + name + "'");
    }

    pipeline.addErrorListener(new EventListener<ErrorEvent>() {
      @Override
      public void onEvent(ErrorEvent event) {
        String desc =
            event.getType() + ": " + event.getDescription() + "(errCode=" + event.getErrorCode()
                + ")";
        log.warn("ROOM {}: Pipeline error encountered: {}", name, desc);
        roomHandler.onPipelineError(name, getParticipantIds(), desc);
      }
    });
  }
}
 
Example 12
Source Project: kurento-room   Source File: RoomManagerTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void pipelineError() {
  joinManyUsersOneRoom();

  // verifies pipeline error listener is added to room
  verify(pipeline, times(1)).addErrorListener(pipelineErrorEventCaptor.capture());

  final String expectedErrorMessage = "TEST_PP_ERR: Fake pipeline error(errCode=505)";

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocation) throws Throwable {
      Object[] args = invocation.getArguments();
      assertThat(args.length, is(3));

      // first arg : roomName
      assertThat(args[0], instanceOf(String.class));
      assertEquals(roomx, args[0]);

      // second arg : participantIds
      assertThat(args[1], instanceOf(Set.class));
      Set<String> pids = new HashSet<String>();
      for (Object o : (Set<?>) args[1]) {
        assertThat(o, instanceOf(String.class));
        pids.add((String) o);
      }
      assertThat(
          pids,
          CoreMatchers.hasItems(usersParticipantIds.values().toArray(
              new String[usersParticipantIds.size()])));

      // third arg : error description
      assertThat(args[2], instanceOf(String.class));
      assertEquals(expectedErrorMessage, args[2]);

      return null;
    }
  }).when(roomHandler).onPipelineError(anyString(), Matchers.<Set<String>> any(), anyString());

  // triggers the last captured listener
  pipelineErrorEventCaptor.getValue().onEvent(
      new ErrorEvent(pipeline, "12345", null, "Fake pipeline error", 505, "TEST_PP_ERR"));

  // verifies the handler's method was called only once (one captor event)
  verify(roomHandler, times(1)).onPipelineError(anyString(), Matchers.<Set<String>> any(),
      anyString());;
}
 
Example 13
Source Project: kurento-java   Source File: RecorderSwitchPlayerTest.java    License: Apache License 2.0 4 votes vote down vote up
public void doTest(MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec,
    String expectedAudioCodec, String extension, String[] mediaUrls, Color[] expectedColors)
        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();
    }
  });

  int numPlayers = mediaUrls.length;
  PlayerEndpoint[] players = new PlayerEndpoint[numPlayers];

  for (int i = 0; i < numPlayers; i++) {
    players[i] = new PlayerEndpoint.Builder(mp, mediaUrls[i]).build();
  }

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

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

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

  boolean startRecord = false;
  for (int i = 0; i < numPlayers; i++) {
    players[i].connect(webRtcEp);
    players[i].connect(recorderEp);
    players[i].play();

    if (!startRecord) {

      Assert.assertTrue("Not received media (timeout waiting playing event)",
          getPage().waitForEvent("playing"));
      recorderEp.record();
      startRecord = true;
    }

    waitSeconds(PLAYTIME / numPlayers);
  }

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

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

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

  checkRecordingFile(recordingFile, "browser", expectedColors, PLAYTIME, expectedVideoCodec,
      expectedAudioCodec);
  success = true;
}
 
Example 14
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 15
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();

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

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

  // green
  webRtcEpGreen.connect(passThrough);

  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(passThrough);
  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 16
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 17
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 18
public void doTest(MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec,
    String expectedAudioCodec, String extension, String[] mediaUrls, Color[] expectedColors)
        throws Exception {

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

  int numPlayers = mediaUrls.length;
  PlayerEndpoint[] players = new PlayerEndpoint[numPlayers];

  for (int i = 0; i < numPlayers; i++) {
    players[i] = new PlayerEndpoint.Builder(mp, mediaUrls[i]).build();
  }

  WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(mp).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().subscribeEvents("playing");
  getPage().initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY);

  final CountDownLatch recorderLatch = new CountDownLatch(1);

  boolean startRecord = false;
  for (int i = 0; i < numPlayers; i++) {
    players[i].connect(webRtcEp);
    players[i].connect(passThrough);
    players[i].play();

    if (!startRecord) {

      Assert.assertTrue("Not received media (timeout waiting playing event)",
          getPage().waitForEvent("playing"));
      recorderEp.record();
      startRecord = true;
    }

    waitSeconds(PLAYTIME / numPlayers);
  }

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

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

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

  checkRecordingFile(recordingFile, "browser", expectedColors, PLAYTIME, expectedVideoCodec,
      expectedAudioCodec);
  success = true;
}
 
Example 19
Source Project: kurento-java   Source File: LongStabilityRecorderS3Test.java    License: Apache License 2.0 4 votes vote down vote up
public void doTest(final MediaProfileSpecType mediaProfileSpecType, String expectedAudioCodec,
    final String extension) throws Exception {

  long testDurationMillis =
      PropertiesManager.getProperty(TEST_DURATION_PROPERTY, DEFAULT_TEST_DURATION);

  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();
      log.error(msgError);
      errorPipelinelatch.countDown();
    }
  });
  final WebRtcEndpoint webRtcSender = new WebRtcEndpoint.Builder(mp).build();

  // WebRTC sender negotiation
  getPage().subscribeLocalEvents("playing");
  getPage().initWebRtc(webRtcSender, WebRtcChannel.AUDIO_ONLY, WebRtcMode.SEND_ONLY);
  Assert.assertTrue("Not received media in sender webrtc", getPage().waitForEvent("playing"));

  // Recorder
  String recordingFile = getRecordUrl(extension);
  RecorderEndpoint recorder = new RecorderEndpoint.Builder(mp, recordingFile)
      .withMediaProfile(mediaProfileSpecType).build();
  webRtcSender.connect(recorder);

  // Start recorder
  recorder.record();

  // Wait recording time
  Thread.sleep(testDurationMillis);

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

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

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

  // Release Media Pipeline
  Assert.assertTrue("Not stop properly",
      recorderLatch.await(getPage().getTimeout(), TimeUnit.SECONDS));
  if (mp != null) {
    mp.release();
  }

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

  waitForFileExists(recordingFile);

  // Assessments
  AssertMedia.assertDuration(recordingFile, testDurationMillis, THRESHOLD_MS);

}