org.kurento.client.MediaPipeline Java Examples

The following examples show how to use org.kurento.client.MediaPipeline. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransactionTest.java    From kurento-java with Apache License 2.0 6 votes vote down vote up
@Test(expected = TransactionNotCommitedException.class)
public void 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 File: WebRtcOneToOneTest.java    From kurento-java with 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 File: TransactionTest.java    From kurento-java with Apache License 2.0 6 votes vote down vote up
@Test(expected = TransactionNotCommitedException.class)
public void usePlainMethodsWithNewObjectsAsParamsInsideTx() throws InterruptedException,
    ExecutionException {

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

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

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

}
 
Example #4
Source File: Handler.java    From kurento-tutorial-java with 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 #5
Source File: FakeKmsService.java    From kurento-java with 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 File: FakeParticipant.java    From kurento-room with 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 #7
Source File: Handler.java    From kurento-tutorial-java with 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 #8
Source File: WebRtcStabilityLoopbackTest.java    From kurento-java with 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 #9
Source File: KTestStream.java    From openmeetings with 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 #10
Source File: Handler.java    From kurento-tutorial-java with 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 #11
Source File: MediaEndpoint.java    From openvidu with 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 #12
Source File: WebRtcStabilityBack2BackTest.java    From kurento-java with 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 #13
Source File: IntegrationTestConfiguration.java    From openvidu with 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 #14
Source File: TestStreamProcessor.java    From openmeetings with 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 #15
Source File: KRoom.java    From openmeetings with 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 #16
Source File: DatachannelsB2BTest.java    From kurento-java with 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 #17
Source File: HelloWorldRecHandler.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
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 #18
Source File: WebRtcQualityLoopbackTest.java    From kurento-java with 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 #19
Source File: TestRecordingFlowMocked.java    From openmeetings with 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 #20
Source File: TestPipeline.java    From kurento-room with 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 #21
Source File: Room.java    From kurento-room with 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 #22
Source File: PlayerMultiplePauseTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testPlayerMultiplePause() throws Exception {
  // Test data
  final String mediaUrl = "http://" + getTestFilesHttpPath() + "/video/60sec/red.webm";
  final Color expectedColor = Color.RED;
  final int playTimeSeconds = 2;
  final int pauseTimeSeconds = 2;
  final int numPauses = 30;

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

  // WebRTC in receive-only mode
  getPage().subscribeEvents("playing");
  getPage().initWebRtc(webRtcEp, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.RCV_ONLY);
  playerEp.play();
  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage().waitForEvent("playing"));

  for (int i = 0; i < numPauses; i++) {
    // Assert color
    Assert.assertTrue("The color of the video should be " + expectedColor,
        getPage().similarColor(expectedColor));

    // Pause and wait
    playerEp.pause();
    Thread.sleep(TimeUnit.SECONDS.toMillis(pauseTimeSeconds));

    // Resume video
    playerEp.play();
    Thread.sleep(TimeUnit.SECONDS.toMillis(playTimeSeconds));
  }

  // Release Media Pipeline
  mp.release();
}
 
Example #23
Source File: KurentoClientBrowserTest.java    From kurento-java with 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 #24
Source File: MediaEndpoint.java    From kurento-room with 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 #25
Source File: WebRtcStabilitySwitchTest.java    From kurento-java with 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 #26
Source File: TransactionTest.java    From kurento-java with 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 #27
Source File: PlayerFaceOverlayTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testPlayerFaceOverlay() throws Exception {
  // Test data
  final int playTimeSeconds = 30;
  final String mediaUrl = "http://" + getTestFilesHttpPath() + "/video/filter/fiwarecut.mp4";
  final Color expectedColor = Color.RED;
  final int xExpectedColor = 420;
  final int yExpectedColor = 45;
  final String imgOverlayUrl = "http://" + getTestFilesHttpPath() + "/img/red-square.png";
  final float offsetXPercent = -0.2F;
  final float offsetYPercent = -1.2F;
  final float widthPercent = 1.6F;
  final float heightPercent = 1.6F;

  // Media Pipeline
  MediaPipeline mp = kurentoClient.createMediaPipeline();
  PlayerEndpoint playerEp = new PlayerEndpoint.Builder(mp, mediaUrl).build();
  WebRtcEndpoint webRtcEp = new WebRtcEndpoint.Builder(mp).build();
  FaceOverlayFilter filter = new FaceOverlayFilter.Builder(mp).build();
  filter.setOverlayedImage(imgOverlayUrl, offsetXPercent, offsetYPercent, widthPercent,
      heightPercent);
  playerEp.connect(filter);
  filter.connect(webRtcEp);

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

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

  // Assertions
  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage().waitForEvent("playing"));
  Assert.assertTrue(
      "Color at coordinates " + xExpectedColor + "," + yExpectedColor + " must be "
          + expectedColor,
      getPage().similarColorAt(expectedColor, xExpectedColor, yExpectedColor));
  Assert.assertTrue("Not received EOS event in player",
      eosLatch.await(getPage().getTimeout(), TimeUnit.SECONDS));
  double currentTime = getPage().getCurrentTime();
  Assert.assertTrue(
      "Error in play time (expected: " + playTimeSeconds + " sec, real: " + currentTime + " sec)",
      getPage().compare(playTimeSeconds, currentTime));

  // Release Media Pipeline
  mp.release();
}
 
Example #28
Source File: BaseRecorder.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
protected void saveGstreamerDot(MediaPipeline mp) {
  if (mp != null) {
    gstreamerDot = mp.getGstreamerDot();
    pipelineName = mp.getName();
  }
}
 
Example #29
Source File: RecorderPlayerTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public void doTest(MediaProfileSpecType mediaProfileSpecType, String expectedVideoCodec,
    String expectedAudioCodec, String extension) throws Exception {

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

  String recordingFile = getRecordUrl(extension);

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

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

  // Release Media Pipeline #1
  mp.release();

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

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

  success = true;
}
 
Example #30
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
public MediaPipeline getMediaPipeline() {
  return mediaPipeline;
}