Java Code Examples for org.kurento.client.MediaPipeline

The following examples show how to use org.kurento.client.MediaPipeline. 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-java   Source File: TransactionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test(expected = TransactionNotCommitedException.class)
public void usePlainMethodsInNewObjectsInsideTx() 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
  httpEndpoint.connect(player);

}
 
Example 2
Source Project: kurento-java   Source File: WebRtcOneToOneTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testWebRtcOneToOneChrome() throws Exception {
  // Media Pipeline
  final MediaPipeline mp = kurentoClient.createMediaPipeline();
  final WebRtcEndpoint masterWebRtcEp = new WebRtcEndpoint.Builder(mp).build();
  final WebRtcEndpoint viewerWebRtcEP = new WebRtcEndpoint.Builder(mp).build();
  masterWebRtcEp.connect(viewerWebRtcEP);

  // WebRTC setup
  getPresenter().initWebRtc(masterWebRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_ONLY);
  getViewer().initWebRtc(viewerWebRtcEP, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY);
  getViewer().subscribeEvents("playing");
  getViewer().waitForEvent("playing");

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

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

  // Release Media Pipeline
  mp.release();
}
 
Example 3
Source Project: kurento-room   Source File: FakeParticipant.java    License: Apache License 2.0 6 votes vote down vote up
public FakeParticipant(String serviceUrl, String name, String room, String playerUri,
    MediaPipeline pipeline, boolean autoMedia, boolean loopMedia) {
  this.name = name;
  this.room = room;
  this.playerUri = playerUri;
  this.autoMedia = autoMedia;
  this.loopMedia = loopMedia;
  this.pipeline = pipeline;
  this.jsonRpcClient = new KurentoRoomClient(serviceUrl);
  this.notifThread = new Thread(name + "-notif") {
    @Override
    public void run() {
      try {
        internalGetNotification();
      } catch (InterruptedException e) {
        log.debug("Interrupted while running notification polling");
        return;
      }
    }
  };
  this.notifThread.start();
}
 
Example 4
Source Project: kurento-java   Source File: TransactionTest.java    License: 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 5
Source Project: kurento-java   Source File: FakeKmsService.java    License: Apache License 2.0 6 votes vote down vote up
public void releaseAllFakePipelines(long timeBetweenClientMs, SystemMonitorManager monitor) {
  for (int i = 0; i < fakeWebRtcList.size(); i++) {
    monitor.decrementNumClients();
    waitMs(timeBetweenClientMs);
  }
  for (WebRtcEndpoint fakeBrowser : fakeBrowserList) {
    fakeBrowser.release();
    waitMs(timeBetweenClientMs);
  }
  for (MediaPipeline fakeMediaPipeline : fakeMediaPipelineList) {
    fakeMediaPipeline.release();
  }
  fakeWebRtcList = new ArrayList<>();
  fakeBrowserList = new ArrayList<>();
  fakeMediaPipelineList = new ArrayList<MediaPipeline>();
}
 
Example 6
Source Project: kurento-tutorial-java   Source File: Handler.java    License: Apache License 2.0 6 votes vote down vote up
private RtpEndpoint makeRtpEndpoint(MediaPipeline pipeline, Boolean useSrtp)
{
  if (!useSrtp) {
    return new RtpEndpoint.Builder(pipeline).build();
  }

  // ---- SRTP configuration BEGIN ----
  // This is used by KMS to encrypt its SRTP/SRTCP packets.
  // Encryption key used by receiver (ASCII): "4321ZYXWVUTSRQPONMLKJIHGFEDCBA"
  // In Base64: "NDMyMVpZWFdWVVRTUlFQT05NTEtKSUhHRkVEQ0JB"
  CryptoSuite srtpCrypto = CryptoSuite.AES_128_CM_HMAC_SHA1_80;
  // CryptoSuite crypto = CryptoSuite.AES_256_CM_HMAC_SHA1_80;

  // You can provide the SRTP Master Key in either plain text or Base64.
  // The second form allows providing binary, non-ASCII keys.
  String srtpMasterKeyAscii = "4321ZYXWVUTSRQPONMLKJIHGFEDCBA";
  // String srtpMasterKeyBase64 = "NDMyMVpZWFdWVVRTUlFQT05NTEtKSUhHRkVEQ0JB";
  // ---- SRTP configuration END ----

  SDES sdes = new SDES();
  sdes.setCrypto(srtpCrypto);
  sdes.setKey(srtpMasterKeyAscii);
  // sdes.setKeyBase64(srtpMasterKeyBase64);

  return new RtpEndpoint.Builder(pipeline).withCrypto(sdes).build();
}
 
Example 7
Source Project: kurento-tutorial-java   Source File: Handler.java    License: Apache License 2.0 6 votes vote down vote up
private void stop(final WebSocketSession session)
{
  log.info("[Handler::stop]");

  // Update the UI
  sendPlayEnd(session);

  // Remove the user session and release all resources
  String sessionId = session.getId();
  UserSession user = users.remove(sessionId);
  if (user != null) {
    MediaPipeline mediaPipeline = user.getMediaPipeline();
    if (mediaPipeline != null) {
      log.info("[Handler::stop] Release the Media Pipeline");
      mediaPipeline.release();
    }
  }
}
 
Example 8
Source Project: openvidu   Source File: MediaEndpoint.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructor to set the owner, the endpoint's name and the media pipeline.
 *
 * @param web
 * @param owner
 * @param endpointName
 * @param pipeline
 * @param log
 */
public MediaEndpoint(EndpointType endpointType, KurentoParticipant owner, String endpointName,
		MediaPipeline pipeline, OpenviduConfig openviduConfig, Logger log) {
	if (log == null) {
		MediaEndpoint.log = LoggerFactory.getLogger(MediaEndpoint.class);
	} else {
		MediaEndpoint.log = log;
	}
	this.endpointType = endpointType;
	this.owner = owner;
	this.setEndpointName(endpointName);
	this.setMediaPipeline(pipeline);

	this.openviduConfig = openviduConfig;

	KurentoTokenOptions kurentoTokenOptions = this.owner.getToken().getKurentoTokenOptions();
	if (kurentoTokenOptions != null) {
		this.maxRecvKbps = kurentoTokenOptions.getVideoMaxRecvBandwidth() != null
				? kurentoTokenOptions.getVideoMaxRecvBandwidth()
				: this.openviduConfig.getVideoMaxRecvBandwidth();
		this.minRecvKbps = kurentoTokenOptions.getVideoMinRecvBandwidth() != null
				? kurentoTokenOptions.getVideoMinRecvBandwidth()
				: this.openviduConfig.getVideoMinRecvBandwidth();
		this.maxSendKbps = kurentoTokenOptions.getVideoMaxSendBandwidth() != null
				? kurentoTokenOptions.getVideoMaxSendBandwidth()
				: this.openviduConfig.getVideoMaxSendBandwidth();
		this.minSendKbps = kurentoTokenOptions.getVideoMinSendBandwidth() != null
				? kurentoTokenOptions.getVideoMinSendBandwidth()
				: this.openviduConfig.getVideoMinSendBandwidth();
	} else {
		this.maxRecvKbps = this.openviduConfig.getVideoMaxRecvBandwidth();
		this.minRecvKbps = this.openviduConfig.getVideoMinRecvBandwidth();
		this.maxSendKbps = this.openviduConfig.getVideoMaxSendBandwidth();
		this.minSendKbps = this.openviduConfig.getVideoMinSendBandwidth();
	}
}
 
Example 9
Source Project: kurento-java   Source File: WebRtcStabilityLoopbackTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWebRtcStabilityLoopback() throws Exception {
  final int playTime = Integer.parseInt(
      System.getProperty("test.webrtcstability.playtime", String.valueOf(DEFAULT_PLAYTIME)));

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

  // WebRTC
  getPage().subscribeEvents("playing");
  getPage().initWebRtc(webRtcEndpoint, WebRtcChannel.VIDEO_ONLY, WebRtcMode.SEND_RCV);

  // Latency assessment
  LatencyController cs = new LatencyController("WebRTC in loopback");
  getPage().activateLatencyControl(VideoTagType.LOCAL.getId(), VideoTagType.REMOTE.getId());
  cs.checkLatency(playTime, TimeUnit.MINUTES, getPage());

  // Release Media Pipeline
  mp.release();

  // Draw latency results (PNG chart and CSV file)
  cs.drawChart(getDefaultOutputFile(".png"), 500, 270);
  cs.writeCsv(getDefaultOutputFile(".csv"));
  cs.logLatencyErrorrs();
}
 
Example 10
Source Project: openvidu   Source File: IntegrationTestConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public KmsManager kmsManager() throws Exception {
	final KmsManager spy = Mockito.spy(new FixedOneKmsManager());
	doAnswer(invocation -> {
		List<Kms> successfullyConnectedKmss = new ArrayList<>();
		List<KmsProperties> kmsProperties = invocation.getArgument(0);
		for (KmsProperties kmsProp : kmsProperties) {
			Kms kms = new Kms(kmsProp, spy.getLoadManager());
			KurentoClient kClient = mock(KurentoClient.class);

			doAnswer(i -> {
				Thread.sleep((long) (Math.random() * 1000));
				((Continuation<MediaPipeline>) i.getArgument(0)).onSuccess(mock(MediaPipeline.class));
				return null;
			}).when(kClient).createMediaPipeline((Continuation<MediaPipeline>) any());

			ServerManager serverManagerMock = mock(ServerManager.class);
			when(serverManagerMock.getCpuCount()).thenReturn(new Random().nextInt(32) + 1);
			when(kClient.getServerManager()).thenReturn(serverManagerMock);

			kms.setKurentoClient(kClient);
			kms.setKurentoClientConnected(true);
			kms.setTimeOfKurentoClientConnection(System.currentTimeMillis());

			spy.addKms(kms);
			successfullyConnectedKmss.add(kms);
		}
		return successfullyConnectedKmss;
	}).when(spy).initializeKurentoClients(any(List.class), any(Boolean.class));
	return spy;
}
 
Example 11
Source Project: openmeetings   Source File: TestStreamProcessor.java    License: Apache License 2.0 5 votes vote down vote up
private MediaPipeline createTestPipeline() {
	Transaction t = kHandler.beginTransaction();
	MediaPipeline pipe = kHandler.getClient().createMediaPipeline(t);
	pipe.addTag(t, TAG_KUID, kHandler.getKuid());
	pipe.addTag(t, TAG_MODE, MODE_TEST);
	pipe.addTag(t, TAG_ROOM, MODE_TEST);
	t.commit();
	return pipe;
}
 
Example 12
Source Project: openmeetings   Source File: KRoom.java    License: Apache License 2.0 5 votes vote down vote up
public KRoom(StreamProcessor processor, Room r, MediaPipeline pipeline, RecordingChunkDao chunkDao) {
	this.processor = processor;
	this.roomId = r.getId();
	this.type = r.getType();
	this.pipeline = pipeline;
	this.chunkDao = chunkDao;
	log.info("ROOM {} has been created", roomId);
}
 
Example 13
Source Project: openmeetings   Source File: KTestStream.java    License: Apache License 2.0 5 votes vote down vote up
public void play(final IWsClient inClient, JSONObject msg, MediaPipeline inPipeline) {
	this.pipeline = inPipeline;
	webRtcEndpoint = createWebRtcEndpoint(pipeline);
	player = createPlayerEndpoint(pipeline, recPath);
	player.connect(webRtcEndpoint);
	webRtcEndpoint.addMediaSessionStartedListener(evt -> {
			log.info("Media session started {}", evt);
			player.addErrorListener(event -> {
					log.info("ErrorEvent for player with uid '{}': {}", inClient.getUid(), event.getDescription());
					sendPlayEnd(inClient);
				});
			player.addEndOfStreamListener(event -> {
					log.info("EndOfStreamEvent for player with uid '{}'", inClient.getUid());
					sendPlayEnd(inClient);
				});
			player.play();
		});

	String sdpOffer = msg.getString("sdpOffer");
	String sdpAnswer = webRtcEndpoint.processOffer(sdpOffer);

	addIceListener(inClient);

	WebSocketHelper.sendClient(inClient, newTestKurentoMsg()
			.put("id", "playResponse")
			.put("sdpAnswer", sdpAnswer));

	webRtcEndpoint.gatherCandidates();
}
 
Example 14
Source Project: openmeetings   Source File: TestRecordingFlowMocked.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setup() {
	super.setup();
	doReturn(mock(MediaPipeline.class)).when(client).createMediaPipeline(any(Transaction.class));
	User u = new User();
	u.setId(USER_ID);
	u.setFirstname("firstname");
	u.setLastname("lastname");
	doReturn(u).when(userDao).get(USER_ID);
	doReturn(true).when(handler).isConnected();
	when(recDao.update(any(Recording.class))).thenAnswer((invocation) ->  {
		Object[] args = invocation.getArguments();
		Recording r = (Recording) args[0];
		r.setId(1L);
		return r;
	});

	PowerMockito.mockStatic(LabelDao.class);
	BDDMockito.given(LabelDao.getLanguage(any(Long.class))).willReturn(new OmLanguage(Locale.ENGLISH));

	// init client object for this test
	c = getClientFull();
	doReturn(c.getRoom()).when(roomDao).get(ROOM_ID);

	// Mock out the methods that do webRTC
	doReturn(null).when(streamProcessor).startBroadcast(any(), any(), any());

}
 
Example 15
Source Project: kurento-room   Source File: TestPipeline.java    License: Apache License 2.0 5 votes vote down vote up
public MediaPipeline getPipeline() {
  try {
    pipelineLatch.await(Room.ASYNC_LATCH_TIMEOUT, TimeUnit.SECONDS);
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
  return this.pipeline;
}
 
Example 16
Source Project: kurento-room   Source File: Room.java    License: Apache License 2.0 5 votes vote down vote up
public MediaPipeline getPipeline() {
  try {
    pipelineLatch.await(Room.ASYNC_LATCH_TIMEOUT, TimeUnit.SECONDS);
  } catch (InterruptedException e) {
    throw new RuntimeException(e);
  }
  return this.pipeline;
}
 
Example 17
Source Project: kurento-room   Source File: MediaEndpoint.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructor to set the owner, the endpoint's name and the media pipeline.
 *
 * @param web
 * @param dataChannels
 * @param owner
 * @param endpointName
 * @param pipeline
 * @param log
 */
public MediaEndpoint(boolean web, boolean dataChannels, Participant owner, String endpointName,
    MediaPipeline pipeline, Logger log) {
  if (log == null) {
    MediaEndpoint.log = LoggerFactory.getLogger(MediaEndpoint.class);
  } else {
    MediaEndpoint.log = log;
  }
  this.web = web;
  this.dataChannels = dataChannels;
  this.owner = owner;
  this.setEndpointName(endpointName);
  this.setMediaPipeline(pipeline);
}
 
Example 18
Source Project: kurento-java   Source File: WebRtcStabilitySwitchTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWebRtcStabilitySwitch() throws Exception {
  final int numSwitch = parseInt(getProperty("test.webrtcstability.switch", valueOf(DEFAULT_NUM_SWITCH)));

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

  // WebRTC
  getPresenter().subscribeEvents("playing");
  getPresenter().initWebRtc(webRtcEndpoint1, VIDEO_ONLY, SEND_RCV);
  getViewer().subscribeEvents("playing");
  getViewer().initWebRtc(webRtcEndpoint2, VIDEO_ONLY, SEND_RCV);

  for (int i = 0; i < numSwitch; i++) {
    if (i % 2 == 0) {
      log.debug("Switch #" + i + ": loopback");
      webRtcEndpoint1.connect(webRtcEndpoint1);
      webRtcEndpoint2.connect(webRtcEndpoint2);
    } else {
      log.debug("Switch #" + i + ": B2B");
      webRtcEndpoint1.connect(webRtcEndpoint2);
      webRtcEndpoint2.connect(webRtcEndpoint1);
    }
    sleep(SECONDS.toMillis(PLAYTIME_PER_SWITCH));
  }

  // Release Media Pipeline
  mp.release();
}
 
Example 19
Source Project: kurento-java   Source File: TransactionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void waitCommitedTest() 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);

  final CountDownLatch readyLatch = new CountDownLatch(1);

  new Thread() {
    @Override
    public void run() {
      try {
        player.waitCommited();
        readyLatch.countDown();
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }.start();

  assertThat(readyLatch.getCount(), is(1l));

  tx.commit();

  if (!readyLatch.await(5000, TimeUnit.SECONDS)) {
    fail("waitForReady not unblocked in 5s");
  }
}
 
Example 20
Source Project: kurento-java   Source File: WebRtcStabilityBack2BackTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testWebRtcStabilityBack2Back() throws Exception {
  final int playTime = Integer.parseInt(System
      .getProperty("test.webrtc.stability.back2back.playtime", String.valueOf(DEFAULT_PLAYTIME)));

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

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

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

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

  // Release Media Pipeline
  mp.release();

  // Draw latency results (PNG chart and CSV file)
  cs.drawChart(getDefaultOutputFile(".png"), 500, 270);
  cs.writeCsv(getDefaultOutputFile(".csv"));
  cs.logLatencyErrorrs();
}
 
Example 21
Source Project: kurento-java   Source File: KurentoClientBrowserTest.java    License: Apache License 2.0 5 votes vote down vote up
@FailedTest
public static void retrieveGstreamerDots() {
  if (kurentoClient != null) {
    try {
      List<MediaPipeline> pipelines = kurentoClient.getServerManager().getPipelines();
      log.debug("Retrieving GStreamerDots for all pipelines in KMS ({})", pipelines.size());

      for (MediaPipeline pipeline : pipelines) {

        String pipelineName = pipeline.getName();
        log.debug("Saving GstreamerDot for pipeline {}", pipelineName);

        String gstreamerDotFile = KurentoTest.getDefaultOutputFile("-" + pipelineName);

        try {
          FileUtils.writeStringToFile(new File(gstreamerDotFile), pipeline.getGstreamerDot());

        } catch (IOException ioe) {
          log.error("Exception writing GstreamerDot file", ioe);
        }
      }
    } catch (WebSocketException e) {
      log.warn("WebSocket exception while reading existing pipelines. Maybe KMS is closed: {}:{}",
          e.getClass().getName(), e.getMessage());
    }
  }
}
 
Example 22
public void sendPlayEnd(WebSocketSession session, MediaPipeline pipeline) {
  try {
    JsonObject response = new JsonObject();
    response.addProperty("id", "playEnd");
    session.sendMessage(new TextMessage(response.toString()));
  } catch (IOException e) {
    log.error("Error sending playEndOfStream message", e);
  }
  // Release pipeline
  pipeline.release();
}
 
Example 23
Source Project: kurento-tutorial-java   Source File: Handler.java    License: Apache License 2.0 5 votes vote down vote up
private void stop(final WebSocketSession session)
{
  // Remove the user session and release all resources
  final UserSession user = users.remove(session.getId());
  if (user != null) {
    MediaPipeline mediaPipeline = user.getMediaPipeline();
    if (mediaPipeline != null) {
      log.info("[Handler::stop] Release the Media Pipeline");
      mediaPipeline.release();
    }
  }
}
 
Example 24
Source Project: kurento-java   Source File: PlayerMultiplePauseTest.java    License: 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 25
Source Project: kurento-java   Source File: WebRtcQualityLoopbackTest.java    License: Apache License 2.0 5 votes vote down vote up
public void doTest(BrowserType browserType, String videoPath, String audioUrl, Color color)
    throws InterruptedException {
  // Media Pipeline
  MediaPipeline mp = kurentoClient.createMediaPipeline();
  WebRtcEndpoint webRtcEndpoint = new WebRtcEndpoint.Builder(mp).build();
  webRtcEndpoint.connect(webRtcEndpoint);

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

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

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

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

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

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

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

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

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

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

  Thread.sleep(8000);

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

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

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

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

  // Release Media Pipeline
  mp.release();
}
 
Example 27
Source Project: kurento-java   Source File: TransactionTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void isCommitedTest() throws InterruptedException, ExecutionException {

  Transaction tx = kurentoClient.beginTransaction();

  MediaPipeline pipeline = kurentoClient.createMediaPipeline(tx);

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

  assertThat(player.isCommited(), is(false));

  tx.commit();

  assertThat(player.isCommited(), is(true));
}
 
Example 28
Source Project: kurento-java   Source File: TransactionTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void futureTest() throws InterruptedException, ExecutionException {

  // Pipeline creation (no transaction)

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

  // End pipeline creation

  // Atomic operation
  String url = httpEndpoint.getUrl();
  MediaPipeline rPipeline = httpEndpoint.getMediaPipeline();
  String uri = player.getUri();
  // End atomic operation

  // Explicit transaction
  Transaction tx = pipeline.beginTransaction();
  TFuture<String> fUrl = httpEndpoint.getUrl(tx);
  TFuture<MediaPipeline> fRPipeline = httpEndpoint.getMediaPipeline(tx);
  TFuture<String> fUri = player.getUri(tx);
  tx.commit();
  // End explicit transaction

  assertThat(url, is(fUrl.get()));
  assertThat(uri, is(fUri.get()));

  MediaPipeline fRPipelineGet = fRPipeline.get();

  System.out.println(rPipeline);
  System.out.println(fRPipelineGet);

  assertThat(rPipeline, is(fRPipelineGet));
}
 
Example 29
Source Project: openvidu   Source File: KurentoParticipant.java    License: Apache License 2.0 4 votes vote down vote up
public MediaPipeline getPipeline() {
	return this.session.getPipeline();
}
 
Example 30
Source Project: kurento-java   Source File: TransactionTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void asyncCommit() 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<Void> async = new AsyncResultManager<>("commit");

  tx.commit(async.getContinuation());

  async.waitForResult();

  assertThat(player.isCommited(), is(true));

}