org.kurento.client.MediaProfileSpecType Java Examples

The following examples show how to use org.kurento.client.MediaProfileSpecType. 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: HelloWorldRecHandler.java    From kurento-tutorial-java with Apache License 2.0 6 votes vote down vote up
private void connectAccordingToProfile(WebRtcEndpoint webRtcEndpoint, RecorderEndpoint recorder,
    MediaProfileSpecType profile) {
  switch (profile) {
    case WEBM:
      webRtcEndpoint.connect(recorder, MediaType.AUDIO);
      webRtcEndpoint.connect(recorder, MediaType.VIDEO);
      break;
    case WEBM_AUDIO_ONLY:
      webRtcEndpoint.connect(recorder, MediaType.AUDIO);
      break;
    case WEBM_VIDEO_ONLY:
      webRtcEndpoint.connect(recorder, MediaType.VIDEO);
      break;
    default:
      throw new UnsupportedOperationException("Unsupported profile for this tutorial: " + profile);
  }
}
 
Example #2
Source File: SingleStreamRecordingService.java    From openvidu with Apache License 2.0 6 votes vote down vote up
private void connectAccordingToProfile(PublisherEndpoint publisherEndpoint, RecorderEndpoint recorder,
		MediaProfileSpecType profile) {
	switch (profile) {
	case WEBM:
		publisherEndpoint.connect(recorder, MediaType.AUDIO);
		publisherEndpoint.connect(recorder, MediaType.VIDEO);
		break;
	case WEBM_AUDIO_ONLY:
		publisherEndpoint.connect(recorder, MediaType.AUDIO);
		break;
	case WEBM_VIDEO_ONLY:
		publisherEndpoint.connect(recorder, MediaType.VIDEO);
		break;
	default:
		throw new UnsupportedOperationException("Unsupported profile when single stream recording: " + profile);
	}
}
 
Example #3
Source File: HelloWorldRecHandler.java    From kurento-tutorial-java with Apache License 2.0 6 votes vote down vote up
private MediaProfileSpecType getMediaProfileFromMessage(JsonObject jsonMessage) {

    MediaProfileSpecType profile;
    switch (jsonMessage.get("mode").getAsString()) {
      case "audio-only":
        profile = MediaProfileSpecType.WEBM_AUDIO_ONLY;
        break;
      case "video-only":
        profile = MediaProfileSpecType.WEBM_VIDEO_ONLY;
        break;
      default:
        profile = MediaProfileSpecType.WEBM;
    }

    return profile;
  }
 
Example #4
Source File: RecordingManager.java    From openvidu with Apache License 2.0 6 votes vote down vote up
public void startOneIndividualStreamRecording(Session session, String recordingId, MediaProfileSpecType profile,
		Participant participant) {
	Recording recording = this.sessionsRecordings.get(session.getSessionId());
	if (recording == null) {
		recording = this.sessionsRecordingsStarting.get(session.getSessionId());
		if (recording == null) {
			log.error("Cannot start recording of new stream {}. Session {} is not being recorded",
					participant.getPublisherStreamId(), session.getSessionId());
			return;
		}
	}
	if (io.openvidu.java.client.Recording.OutputMode.INDIVIDUAL.equals(recording.getOutputMode())) {
		// Start new RecorderEndpoint for this stream
		log.info("Starting new RecorderEndpoint in session {} for new stream of participant {}",
				session.getSessionId(), participant.getParticipantPublicId());
		final CountDownLatch startedCountDown = new CountDownLatch(1);
		this.singleStreamRecordingService.startRecorderEndpointForPublisherEndpoint(session, recordingId, profile,
				participant, startedCountDown);
	} else if (io.openvidu.java.client.Recording.OutputMode.COMPOSED.equals(recording.getOutputMode())
			&& !recording.hasVideo()) {
		// Connect this stream to existing Composite recorder
		log.info("Joining PublisherEndpoint to existing Composite in session {} for new stream of participant {}",
				session.getSessionId(), participant.getParticipantPublicId());
		this.composedRecordingService.joinPublisherEndpointToComposite(session, recordingId, participant);
	}
}
 
Example #5
Source File: RecorderSwitchPlayerWithPassThroughTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void doTestSameFormats(MediaProfileSpecType mediaProfileSpecType,
    String expectedVideoCodec, String expectedAudioCodec, String extension) throws Exception {
  String[] mediaUrls = { getPlayerUrl("/video/10sec/red.webm"),
      getPlayerUrl("/video/10sec/green.webm"), getPlayerUrl("/video/10sec/red.webm") };
  Color[] expectedColors = { Color.RED, Color.GREEN, Color.RED };

  doTest(mediaProfileSpecType, expectedVideoCodec, expectedAudioCodec, extension, mediaUrls,
      expectedColors);
}
 
Example #6
Source File: RecorderSwitchPlayerWithPassThroughTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void doTestDifferentFormats(MediaProfileSpecType mediaProfileSpecType,
    String expectedVideoCodec, String expectedAudioCodec, String extension) throws Exception {
  String[] mediaUrls = { getPlayerUrl("/video/10sec/ball.mkv"),
      getPlayerUrl("/video/10sec/white.webm"), getPlayerUrl("/video/10sec/ball.mkv") };
  Color[] expectedColors = { Color.BLACK, Color.WHITE, Color.BLACK };

  doTest(mediaProfileSpecType, expectedVideoCodec, expectedAudioCodec, extension, mediaUrls,
      expectedColors);
}
 
Example #7
Source File: RecorderSwitchPlayerWithPassThroughTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void doTestFrameRateDifferent(MediaProfileSpecType mediaProfileSpecType,
    String expectedVideoCodec, String expectedAudioCodec, String extension) throws Exception {
  String[] mediaUrls = { getPlayerUrl("/video/10sec/ball25fps.webm"),
      getPlayerUrl("/video/10sec/blue.webm"), getPlayerUrl("/video/10sec/ball25fps.webm") };
  Color[] expectedColors = { Color.BLACK, Color.BLUE, Color.BLACK };

  doTest(mediaProfileSpecType, expectedVideoCodec, expectedAudioCodec, extension, mediaUrls,
      expectedColors);
}
 
Example #8
Source File: RecorderSwitchPlayerWithPassThroughTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void doTestFrameRateAndFrameSizeDifferent(MediaProfileSpecType mediaProfileSpecType,
    String expectedVideoCodec, String expectedAudioCodec, String extension) throws Exception {
  String[] mediaUrls = { getPlayerUrl("/video/15sec/rgb640x360.mov"),
      getPlayerUrl("/video/15sec/rgb.mov"), getPlayerUrl("/video/15sec/rgb640x360.mov") };
  Color[] expectedColors = { Color.RED, Color.GREEN, Color.RED };

  doTest(mediaProfileSpecType, expectedVideoCodec, expectedAudioCodec, extension, mediaUrls,
      expectedColors);
}
 
Example #9
Source File: RecorderSwitchPlayerWithPassThroughTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void doTestFrameSizeDifferent(MediaProfileSpecType mediaProfileSpecType,
    String expectedVideoCodec, String expectedAudioCodec, String extension) throws Exception {
  String[] mediaUrls = { getPlayerUrl("/video/format/sintel.webm"),
      getPlayerUrl("/video/format/chrome640x360.mp4"),
      getPlayerUrl("/video/format/sintel.webm") };
  Color[] expectedColors =
    { Color.BLACK, new Color(150, 50, 50), Color.BLACK };

  doTest(mediaProfileSpecType, expectedVideoCodec, expectedAudioCodec, extension, mediaUrls,
      expectedColors);
}
 
Example #10
Source File: RecorderSwitchPlayerTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void doTestFrameSizeDifferent(MediaProfileSpecType mediaProfileSpecType,
    String expectedVideoCodec, String expectedAudioCodec, String extension) throws Exception {
  String[] mediaUrls = { getPlayerUrl("/video/format/sintel.webm"),
      getPlayerUrl("/video/format/chrome640x360.mp4"),
      getPlayerUrl("/video/format/sintel.webm") };
  Color[] expectedColors =
    { Color.BLACK, new Color(150, 50, 50), Color.BLACK };

  doTest(mediaProfileSpecType, expectedVideoCodec, expectedAudioCodec, extension, mediaUrls,
      expectedColors);
}
 
Example #11
Source File: RecorderSwitchPlayerTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void doTestFrameRateAndFrameSizeDifferent(MediaProfileSpecType mediaProfileSpecType,
    String expectedVideoCodec, String expectedAudioCodec, String extension) throws Exception {
  String[] mediaUrls = { getPlayerUrl("/video/15sec/rgb640x360.webm"),
      getPlayerUrl("/video/15sec/rgb.webm"), getPlayerUrl("/video/15sec/rgb640x360.webm") };
  Color[] expectedColors = { Color.RED, Color.GREEN, Color.RED };

  doTest(mediaProfileSpecType, expectedVideoCodec, expectedAudioCodec, extension, mediaUrls,
      expectedColors);
}
 
Example #12
Source File: RecorderSwitchPlayerTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void doTestFrameRateDifferent(MediaProfileSpecType mediaProfileSpecType,
    String expectedVideoCodec, String expectedAudioCodec, String extension) throws Exception {
  String[] mediaUrls = { getPlayerUrl("/video/10sec/ball25fps.webm"),
      getPlayerUrl("/video/10sec/blue.webm"), getPlayerUrl("/video/10sec/ball25fps.webm") };
  Color[] expectedColors = { Color.BLACK, Color.BLUE, Color.BLACK };

  doTest(mediaProfileSpecType, expectedVideoCodec, expectedAudioCodec, extension, mediaUrls,
      expectedColors);
}
 
Example #13
Source File: RecorderSwitchPlayerTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void doTestDifferentFormats(MediaProfileSpecType mediaProfileSpecType,
    String expectedVideoCodec, String expectedAudioCodec, String extension) throws Exception {
  String[] mediaUrls = { getPlayerUrl("/video/10sec/ball.mkv"),
      getPlayerUrl("/video/10sec/white.webm"), getPlayerUrl("/video/10sec/ball.mkv") };
  Color[] expectedColors = { Color.BLACK, Color.WHITE, Color.BLACK };

  doTest(mediaProfileSpecType, expectedVideoCodec, expectedAudioCodec, extension, mediaUrls,
      expectedColors);
}
 
Example #14
Source File: RecorderSwitchPlayerTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void doTestSameFormats(MediaProfileSpecType mediaProfileSpecType,
    String expectedVideoCodec, String expectedAudioCodec, String extension) throws Exception {
  String[] mediaUrls = { getPlayerUrl("/video/10sec/red.webm"),
      getPlayerUrl("/video/10sec/green.webm"), getPlayerUrl("/video/10sec/red.webm") };
  Color[] expectedColors = { Color.RED, Color.GREEN, Color.RED };

  doTest(mediaProfileSpecType, expectedVideoCodec, expectedAudioCodec, extension, mediaUrls,
      expectedColors);
}
 
Example #15
Source File: TestSetupFlowMocked.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
@Test
public void testMsgTestRecord1() throws Exception {
	doReturn(mock(MediaPipeline.class)).when(client).createMediaPipeline(any(Transaction.class));
	WebRtcEndpoint.Builder builder = mock(WebRtcEndpoint.Builder.class);
	whenNew(WebRtcEndpoint.Builder.class).withArguments(any(MediaPipeline.class)).thenReturn(builder);
	doReturn(mock(WebRtcEndpoint.class)).when(builder).build();

	RecorderEndpoint.Builder recBuilder = mock(RecorderEndpoint.Builder.class);
	whenNew(RecorderEndpoint.Builder.class).withArguments(any(MediaPipeline.class), anyString()).thenReturn(recBuilder);
	doReturn(recBuilder).when(recBuilder).stopOnEndOfStream();
	doReturn(recBuilder).when(recBuilder).withMediaProfile(any(MediaProfileSpecType.class));
	doReturn(mock(RecorderEndpoint.class)).when(recBuilder).build();

	WsClient c = new WsClient("sessionId", 0);
	for (boolean audio : new boolean[] {true, false}) {
		for (boolean video : new boolean[] {true, false}) {
			JSONObject msg = new JSONObject(MSG_BASE.toString())
					.put("id", "record")
					.put("sdpOffer", "")
					.put("audio", audio)
					.put("video", video);
			handler.onMessage(c, msg);
		}
	}
	JSONObject iceMsg = new JSONObject(MSG_BASE.toString())
			.put("id", "iceCandidate")
			.put(PARAM_CANDIDATE, new JSONObject()
					.put(PARAM_CANDIDATE, "candidate")
					.put("sdpMid", "sdpMid")
					.put("sdpMLineIndex", 1));
	handler.onMessage(c, iceMsg);
	PlayerEndpoint.Builder playBuilder = mock(PlayerEndpoint.Builder.class);
	whenNew(PlayerEndpoint.Builder.class).withArguments(any(MediaPipeline.class), anyString()).thenReturn(playBuilder);
	doReturn(mock(PlayerEndpoint.class)).when(playBuilder).build();
	handler.onMessage(c, new JSONObject(MSG_BASE.toString())
			.put("id", "play")
			.put("sdpOffer", "sdpOffer"));
	testProcessor.destroy();
}
 
Example #16
Source File: KTestStream.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
private static MediaProfileSpecType getProfile(JSONObject msg) {
	boolean a  = msg.getBoolean("audio")
			, v = msg.getBoolean("video");
	if (a && v) {
		return MediaProfileSpecType.WEBM;
	} else if (v) {
		return MediaProfileSpecType.WEBM_VIDEO_ONLY;
	} else {
		return MediaProfileSpecType.WEBM_AUDIO_ONLY;
	}
}
 
Example #17
Source File: CompositeWrapper.java    From openvidu with Apache License 2.0 5 votes vote down vote up
public CompositeWrapper(KurentoSession session, String path) {
	this.session = session;
	this.composite = new Composite.Builder(session.getPipeline()).build();
	this.recorderEndpoint = new RecorderEndpoint.Builder(composite.getMediaPipeline(), path)
			.withMediaProfile(MediaProfileSpecType.WEBM_AUDIO_ONLY).build();
	this.compositeToRecorderHubPort = new HubPort.Builder(composite).build();
	this.compositeToRecorderHubPort.connect(recorderEndpoint);
}
 
Example #18
Source File: RecorderWebRtcSwitchSequentialTest.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();
  WebRtcEndpoint webRtcEp1 = new WebRtcEndpoint.Builder(mp).build();
  WebRtcEndpoint webRtcEp2 = new WebRtcEndpoint.Builder(mp).build();

  // WebRTC negotiation
  getPage(0).subscribeLocalEvents("playing");
  getPage(0).initWebRtc(webRtcEp1, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_ONLY);
  getPage(1).subscribeLocalEvents("playing");
  getPage(1).initWebRtc(webRtcEp2, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_ONLY);

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

  // Switch webrtcs
  for (int i = 0; i < SWITCH_TIMES; i++) {
    if (i % 2 == 0) {
      webRtcEp1.connect(recorderEp);
    } else {
      webRtcEp2.connect(recorderEp);
    }

    Thread.sleep(SWITCH_RATE_MS);
  }

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

  // Assessment
  Assert.assertTrue("Not received media in browser 1", getPage(0).waitForEvent("playing"));
  Assert.assertTrue("Not received media in browser 2", getPage(1).waitForEvent("playing"));

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

  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 #19
Source File: RecorderWebRtcOneToManyTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public void doTest(final MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec,
    String expectedAudioCodec, final String extension) throws Exception {

  MediaPipeline mp = null;

  // Media Pipeline
  mp = kurentoClient.createMediaPipeline();
  final WebRtcEndpoint webRtcSender = new WebRtcEndpoint.Builder(mp).build();
  final WebRtcEndpoint[] webRtcReceiver = new WebRtcEndpoint[numViewers];
  final RecorderEndpoint[] recorder = new RecorderEndpoint[numViewers];
  final String[] recordingFile = new String[numViewers];

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

  ExecutorService executor = Executors.newFixedThreadPool(numViewers);
  final CountDownLatch latch = new CountDownLatch(numViewers);
  final MediaPipeline pipeline = mp;
  for (int j = 1; j <= numViewers; j++) {
    final int i = j;
    executor.execute(new Runnable() {
      @Override
      public void run() {
        // N Receiver WebRTC and Recorder
        webRtcReceiver[i - 1] = new WebRtcEndpoint.Builder(pipeline).build();
        recordingFile[i - 1] = getRecordUrl("-receiver" + i + extension);
        recorder[i - 1] = new RecorderEndpoint.Builder(pipeline, recordingFile[i - 1])
            .withMediaProfile(mediaProfileSpecType).build();

        webRtcSender.connect(webRtcReceiver[i - 1]);
        webRtcSender.connect(recorder[i - 1]);

        try {
          // WebRTC receiver negotiation
          getPage(i).subscribeEvents("playing");
          getPage(i).initWebRtc(webRtcReceiver[i - 1], WebRtcChannel.AUDIO_AND_VIDEO,
              WebRtcMode.RCV_ONLY);
          Assert.assertTrue("Not received media in receiver " + i,
              getPage(i).waitForEvent("playing"));

          // Start record
          recorder[i - 1].record();

          // Wait play time
          Thread.sleep(PLAYTIME_MS);

          // Stop record
          recorder[i - 1].stopAndWait();

          // Guard time to stop recording
          Thread.sleep(4000);

        } catch (InterruptedException e) {
          log.error("InterruptedException in receiver " + i, e);
        }

        latch.countDown();
      }
    });
  }

  // Wait to finish all receivers
  latch.await(getPage(0).getTimeout(), TimeUnit.SECONDS);

  // Assessments
  for (int j = 1; j <= numViewers; j++) {
    AssertMedia.assertCodecs(recordingFile[j - 1], expectedVideoCodec, expectedAudioCodec);
    AssertMedia.assertDuration(recordingFile[j - 1], PLAYTIME_MS, THRESHOLD_MS);
  }

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

}
 
Example #20
Source File: RecorderPlayerOneToManyTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public void doTest(final MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec,
    String expectedAudioCodec, final String extension) throws Exception {

  MediaPipeline mp = null;

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

  final RecorderEndpoint[] recorder = new RecorderEndpoint[numViewers];
  final String[] recordingFile = new String[numViewers];
  playerEp.play();

  ExecutorService executor = Executors.newFixedThreadPool(numViewers);
  final CountDownLatch latch = new CountDownLatch(numViewers);
  final MediaPipeline pipeline = mp;
  for (int j = 0; j < numViewers; j++) {
    final int i = j;
    executor.execute(new Runnable() {
      @Override
      public void run() {
        try {
          // N recorders
          recordingFile[i] = getRecordUrl("-recorder" + i + extension);
          recorder[i] = new RecorderEndpoint.Builder(pipeline, recordingFile[i])
              .withMediaProfile(mediaProfileSpecType).build();
          playerEp.connect(recorder[i]);

          // Start record
          recorder[i].record();

          // Wait play time
          Thread.sleep(PLAYTIME_MS);

          // Stop record
          recorder[i].stopAndWait();

          // Guard time to stop recording
          Thread.sleep(4000);

        } catch (Throwable t) {
          log.error("Exception in receiver " + i, t);
        }

        latch.countDown();
      }
    });
  }

  // Wait to finish all recordings
  latch.await();

  // Assessments
  for (int j = 0; j < numViewers; j++) {
    AssertMedia.assertCodecs(recordingFile[j], expectedVideoCodec, expectedAudioCodec);
    AssertMedia.assertDuration(recordingFile[j], PLAYTIME_MS, THRESHOLD_MS);
  }

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

}
 
Example #21
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 #22
Source File: RecorderWebRtcShortFileTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public void doTest(final MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec,
    String expectedAudioCodec, final String extension) throws Exception {

  final CountDownLatch recorderLatch = new CountDownLatch(1);

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

  endTestTime = System.currentTimeMillis() + testDurationMillis;

  MediaPipeline pipeline = kurentoClient.createMediaPipeline();
  final WebRtcEndpoint webRtcSender = new WebRtcEndpoint.Builder(pipeline).build();
  final String recordingFile = getRecordUrl(extension);
  final RecorderEndpoint recorder = new RecorderEndpoint.Builder(pipeline, recordingFile)
      .withMediaProfile(mediaProfileSpecType).build();

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

  webRtcSender.connect(recorder);

  while (!isTimeToFinishTest()) {
    // Start record
    recorder.record();
    // Wait play time
    Thread.sleep(RECORD_MS);
    // Pause record
    recorder.pause();
    Thread.sleep(RECORD_MS);
  }

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

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

  AssertMedia.assertCodecs(recordingFile, expectedVideoCodec, expectedAudioCodec);
  AssertMedia.assertDuration(recordingFile, testDurationMillis / 2,
      (testDurationMillis / 2) + THRESHOLD_MS);

  // Release Media Pipeline
  if (pipeline != null) {
    pipeline.release();
  }
}
 
Example #23
Source File: RecorderThreeWebRtcSimultaneous.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public void doTest(final MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec,
    String expectedAudioCodec, final String extension) throws Exception {

  MediaPipeline mp = null;

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

  final WebRtcEndpoint[] webRtcSender = new WebRtcEndpoint[NUM_BROWSERS];
  final RecorderEndpoint[] recorder = new RecorderEndpoint[NUM_BROWSERS];
  final String[] recordingFile = new String[NUM_BROWSERS];

  ExecutorService executor = Executors.newFixedThreadPool(NUM_BROWSERS);
  final CountDownLatch latch = new CountDownLatch(NUM_BROWSERS);
  final MediaPipeline pipeline = mp;
  for (int j = 0; j < NUM_BROWSERS; j++) {
    final int i = j;
    executor.execute(new Runnable() {
      @Override
      public void run() {
        try {
          // N viewer
          webRtcSender[i] = new WebRtcEndpoint.Builder(pipeline).build();
          // N recorders
          recordingFile[i] = getRecordUrl("-receiver" + i + extension);
          recorder[i] = new RecorderEndpoint.Builder(pipeline, recordingFile[i])
              .withMediaProfile(mediaProfileSpecType).build();

          // WebRTC receiver negotiation
          getPage(i).subscribeLocalEvents("playing");
          getPage(i).initWebRtc(webRtcSender[i], WebRtcChannel.AUDIO_AND_VIDEO,
              WebRtcMode.SEND_ONLY);
          Assert.assertTrue("Not received media in sender" + i,
              getPage(i).waitForEvent("playing"));

          webRtcSender[i].connect(recorder[i]);

          // Start record
          recorder[i].record();

          // Wait play time
          Thread.sleep(RECORD_MS);

          // Stop record
          recorder[i].stopAndWait();

          // Guard time to stop recording
          Thread.sleep(4000);
          getPage(i).reload();
        } catch (Throwable e) {
          log.error("Exception in receiver " + i, e);

        } finally {
          latch.countDown();
        }
      }
    });
  }

  // Wait to finish all recorders
  latch.await();

  // Assessment
  for (int j = 0; j < NUM_BROWSERS; j++) {
    AssertMedia.assertCodecs(recordingFile[j], expectedVideoCodec, expectedAudioCodec);
    AssertMedia.assertDuration(recordingFile[j], RECORD_MS, THRESHOLD_MS);
  }

  // Release Media Pipeline
  if (mp != null) {
    mp.release();
  }
}
 
Example #24
Source File: RecorderStopTest.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 playerEp =
      new PlayerEndpoint.Builder(mp, getPlayerUrl("/video/10sec/green.webm")).build();
  WebRtcEndpoint webRtcEp1 = new WebRtcEndpoint.Builder(mp).build();

  String recordingFile = getRecordUrl(extension);

  final RecorderEndpoint recorderEp = new RecorderEndpoint.Builder(mp, recordingFile)
      .withMediaProfile(mediaProfileSpecType).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(mp, webRtcEp1, playerEp, recorderEp, expectedVideoCodec, expectedAudioCodec,
      recordingFile, EXPECTED_COLOR, 0, 0, PLAYTIME);

  ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
  executor.schedule(new Runnable() {

    @Override
    public void run() {
      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();
        }
      });
    }
  }, PLAYTIME / 2, TimeUnit.SECONDS);

  // Wait for EOS
  Assert.assertTrue("No EOS event", eosLatch.await(getPage().getTimeout(), TimeUnit.SECONDS));

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

  // Release Media Pipeline #1
  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
  launchBrowser(null, webRtcEp2, playerEp2, null, expectedVideoCodec, expectedAudioCodec,
      recordingFile, EXPECTED_COLOR, 0, 0, PLAYTIME / 2);

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

  executor.shutdown();

  success = true;
}
 
Example #25
Source File: RecorderSwitchPlayerWithPassThroughTest.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, 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 #26
Source File: RecorderWebRtcLongFileTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public void doTest(final MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec,
    String expectedAudioCodec, final String extension) throws Exception {

  MediaPipeline mp = null;

  // Media Pipeline
  mp = kurentoClient.createMediaPipeline();
  final WebRtcEndpoint webRtcSender = new WebRtcEndpoint.Builder(mp).build();

  // WebRTC sender negotiation
  getPage().subscribeLocalEvents("playing");
  getPage().initWebRtc(webRtcSender, WebRtcChannel.AUDIO_AND_VIDEO, 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(RECORD_MS);

  // Stop recorder
  recorder.stopAndWait();

  // Guard time to stop recording
  Thread.sleep(4000);

  // Assessments
  AssertMedia.assertCodecs(recordingFile, expectedVideoCodec, expectedAudioCodec);
  AssertMedia.assertDuration(recordingFile, RECORD_MS, THRESHOLD_MS);

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

}
 
Example #27
Source File: LongStabilityRecorderS3Test.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testLongStabilityRecorderS3Webm() throws Exception {
  doTest(MediaProfileSpecType.WEBM_AUDIO_ONLY, EXPECTED_AUDIO_CODEC_WEBM, EXTENSION_WEBM);
}
 
Example #28
Source File: LongStabilityRecorderS3Test.java    From kurento-java with 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);

}
 
Example #29
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 #30
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();
}