org.kurento.client.FaceOverlayFilter Java Examples

The following examples show how to use org.kurento.client.FaceOverlayFilter. 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: DemoJsonRpcUserControl.java    From kurento-room with Apache License 2.0 6 votes vote down vote up
private void handleHatRequest(Transaction transaction, Request<JsonObject> request,
    ParticipantRequest participantRequest) throws IOException {
  boolean filterOn = request.getParams().get(filterType.getCustomRequestParam()).getAsBoolean();
  String pid = participantRequest.getParticipantId();
  if (filterOn) {
    if (transaction.getSession().getAttributes().containsKey(SESSION_ATTRIBUTE_FILTER)) {
      throw new RuntimeException(filterType + " filter already on");
    }
    log.info("Applying {} filter to session {}", filterType, pid);

    FaceOverlayFilter filter =
        new FaceOverlayFilter.Builder(roomManager.getPipeline(pid)).build();
    filter.setOverlayedImage(this.hatUrl, this.offsetXPercent, this.offsetYPercent,
        this.widthPercent, this.heightPercent);

    addFilter(transaction, pid, filter);
  } else {
    removeFilter(transaction, pid);
  }
  transaction.sendResponse(new JsonObject());
}
 
Example #2
Source File: RoomManagerTest.java    From kurento-room with Apache License 2.0 5 votes vote down vote up
@Test
public void addMediaFilterBeforePublishing() throws InterruptedException, ExecutionException {
  joinManyUsersOneRoom();

  final FaceOverlayFilter filter = new FaceOverlayFilter.Builder(pipeline).build();
  assertNotNull("FaceOverlayFiler is null", filter);
  assertThat("Filter returned by the builder is not the same as the mocked one", filter,
      is(faceFilter));

  final String participantId0 = usersParticipantIds.get(users[0]);

  System.out.println("Starting execution of addMediaElement");
  manager.addMediaElement(participantId0, filter);
  System.out.println("Execution of addMediaElement ended");

  assertEquals("SDP answer doesn't match", SDP_WEB_ANSWER,
      manager.publishMedia(participantId0, true, SDP_WEB_OFFER, false));

  assertThat(manager.getPublishers(roomx).size(), is(1));

  for (String pid : usersParticipantIds.values()) {
    if (!pid.equals(participantId0)) {
      assertEquals("SDP answer doesn't match", SDP_WEB_ANSWER,
          manager.subscribe(users[0], SDP_WEB_OFFER, pid));
    }
  }
  assertThat(manager.getSubscribers(roomx).size(), is(users.length - 1));

  verify(faceFilter, times(1)).connect(passThru, faceFilterConnectCaptor.getValue());
  verify(endpoint, times(1)).connect(faceFilter, webRtcConnectCaptor.getValue());

  Set<UserParticipant> remainingUsers = manager.leaveRoom(participantId0);
  Set<UserParticipant> roomParticipants = manager.getParticipants(roomx);
  assertEquals(roomParticipants, remainingUsers);
  assertThat(roomParticipants, not(hasItem(usersParticipants.get(users[0]))));
  assertThat(manager.getPublishers(roomx).size(), is(0));

  // peers are automatically unsubscribed
  assertThat(manager.getSubscribers(roomx).size(), is(0));
}
 
Example #3
Source File: WebRtcOneFaceOverlayTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testWebRtcFaceOverlay() throws InterruptedException {

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

  // Start WebRTC and wait for playing event
  getPage().subscribeEvents("playing");
  getPage().initWebRtc(webRtcEndpoint, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_RCV);
  Assert.assertTrue("Not received media (timeout waiting playing event)",
      getPage().waitForEvent("playing"));

  // Guard time to play the video
  int playTime = Integer.parseInt(
      System.getProperty("test.webrtcfaceoverlay.playtime", String.valueOf(DEFAULT_PLAYTIME)));
  waitSeconds(playTime);

  // Assertions
  double currentTime = getPage().getCurrentTime();
  Assert.assertTrue(
      "Error in play time (expected: " + playTime + " sec, real: " + currentTime + " sec)",
      getPage().compare(playTime, currentTime));
  Assert.assertTrue("The color of the video should be green",
      getPage().similarColor(CHROME_VIDEOTEST_COLOR));

  // Release Media Pipeline
  mp.release();
}
 
Example #4
Source File: CallMediaPipeline.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
public CallMediaPipeline(KurentoClient kurento, String from, String to) {

    // Media pipeline
    pipeline = kurento.createMediaPipeline();

    // Media Elements (WebRtcEndpoint, RecorderEndpoint, FaceOverlayFilter)
    webRtcCaller = new WebRtcEndpoint.Builder(pipeline).build();
    webRtcCallee = new WebRtcEndpoint.Builder(pipeline).build();

    recorderCaller = new RecorderEndpoint.Builder(pipeline, RECORDING_PATH + from + RECORDING_EXT)
        .build();
    recorderCallee = new RecorderEndpoint.Builder(pipeline, RECORDING_PATH + to + RECORDING_EXT)
        .build();

    // String appServerUrl = System.getProperty("app.server.url",
    //    One2OneCallAdvApp.DEFAULT_APP_SERVER_URL);
    String appServerUrl = "http://files.openvidu.io";
    FaceOverlayFilter faceOverlayFilterCaller = new FaceOverlayFilter.Builder(pipeline).build();
    faceOverlayFilterCaller.setOverlayedImage(appServerUrl + "/img/mario-wings.png", -0.35F, -1.2F,
        1.6F, 1.6F);

    FaceOverlayFilter faceOverlayFilterCallee = new FaceOverlayFilter.Builder(pipeline).build();
    faceOverlayFilterCallee.setOverlayedImage(appServerUrl + "/img/Hat.png", -0.2F, -1.35F, 1.5F,
        1.5F);

    // Connections
    webRtcCaller.connect(faceOverlayFilterCaller);
    faceOverlayFilterCaller.connect(webRtcCallee);
    faceOverlayFilterCaller.connect(recorderCaller);

    webRtcCallee.connect(faceOverlayFilterCallee);
    faceOverlayFilterCallee.connect(webRtcCaller);
    faceOverlayFilterCallee.connect(recorderCallee);
  }
 
Example #5
Source File: RoomManagerTest.java    From kurento-room with Apache License 2.0 4 votes vote down vote up
@Test
public void addMediaFilterInParallel() throws InterruptedException, ExecutionException {
  joinManyUsersOneRoom();

  final FaceOverlayFilter filter = new FaceOverlayFilter.Builder(pipeline).build();
  assertNotNull("FaceOverlayFiler is null", filter);
  assertThat("Filter returned by the builder is not the same as the mocked one", filter,
      is(faceFilter));

  final String participantId0 = usersParticipantIds.get(users[0]);

  ExecutorService threadPool = Executors.newFixedThreadPool(1);
  ExecutorCompletionService<Void> exec = new ExecutorCompletionService<>(threadPool);
  exec.submit(new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      System.out.println("Starting execution of addMediaElement");
      manager.addMediaElement(participantId0, filter);
      return null;
    }
  });

  Thread.sleep(10);

  assertEquals("SDP answer doesn't match", SDP_WEB_ANSWER,
      manager.publishMedia(participantId0, true, SDP_WEB_OFFER, false));

  assertThat(manager.getPublishers(roomx).size(), is(1));

  boolean firstSubscriber = true;
  for (String pid : usersParticipantIds.values()) {
    if (pid.equals(participantId0)) {
      continue;
    }
    assertEquals("SDP answer doesn't match", SDP_WEB_ANSWER,
        manager.subscribe(users[0], SDP_WEB_OFFER, pid));
    if (firstSubscriber) {
      firstSubscriber = false;
      try {
        exec.take().get();
        System.out
        .println("Execution of addMediaElement ended (just after first peer subscribed)");
      } finally {
        threadPool.shutdownNow();
      }
    }
  }
  assertThat(manager.getSubscribers(roomx).size(), is(users.length - 1));

  verify(faceFilter, times(1)).connect(passThru, faceFilterConnectCaptor.getValue());
  verify(endpoint, times(1)).connect(faceFilter, webRtcConnectCaptor.getValue());

  Set<UserParticipant> remainingUsers = manager.leaveRoom(participantId0);
  Set<UserParticipant> roomParticipants = manager.getParticipants(roomx);
  assertEquals(roomParticipants, remainingUsers);
  assertThat(roomParticipants, not(hasItem(usersParticipants.get(users[0]))));
  assertThat(manager.getPublishers(roomx).size(), is(0));

  // peers are automatically unsubscribed
  assertThat(manager.getSubscribers(roomx).size(), is(0));
}
 
Example #6
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 #7
Source File: RecorderFaceOverlayTest.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/filter/fiwarecut.mp4")).build();
  WebRtcEndpoint webRtcEp1 = new WebRtcEndpoint.Builder(mp).build();

  FaceOverlayFilter filter = new FaceOverlayFilter.Builder(mp).build();
  filter.setOverlayedImage("http://" + getTestFilesHttpPath() + "/img/red-square.png", -0.2F,
      -1.2F, 1.6F, 1.6F);

  String recordingFile = getRecordUrl(extension);
  RecorderEndpoint recorderEp = new RecorderEndpoint.Builder(mp, recordingFile)
      .withMediaProfile(mediaProfileSpecType).build();
  playerEp.connect(filter);
  filter.connect(webRtcEp1);
  filter.connect(recorderEp);

  // Test execution #1. Play and record
  getPage().setThresholdTime(THRESHOLD);
  launchBrowser(mp, webRtcEp1, playerEp, recorderEp, expectedVideoCodec, expectedAudioCodec,
      recordingFile, EXPECTED_COLOR, EXPECTED_COLOR_X, EXPECTED_COLOR_Y, PLAYTIME);

  // 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(mp, webRtcEp2, playerEp2, null, expectedVideoCodec, expectedAudioCodec,
      recordingFile, EXPECTED_COLOR, EXPECTED_COLOR_X, EXPECTED_COLOR_Y, PLAYTIME);

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

  success = true;
}
 
Example #8
Source File: KmsPerformanceTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
private void connectWithMediaProcessing(WebRtcEndpoint inputEndpoint,
    WebRtcEndpoint outputEndpoint) {

  switch (mediaProcessingType) {
    case ENCODER:
      Filter filter = new GStreamerFilter.Builder(mp, "capsfilter caps=video/x-raw")
          .withFilterType(FilterType.VIDEO).build();
      inputEndpoint.connect(filter);
      filter.connect(outputEndpoint);
      log.debug("Pipeline: WebRtcEndpoint -> GStreamerFilter -> WebRtcEndpoint");
      break;

    case FILTER:
    case FACEOVERLAY:
      filter = new FaceOverlayFilter.Builder(mp).build();
      inputEndpoint.connect(filter);
      filter.connect(outputEndpoint);
      log.debug("Pipeline: WebRtcEndpoint -> FaceOverlayFilter -> WebRtcEndpoint");
      break;

    case ZBAR:
      filter = new ZBarFilter.Builder(mp).build();
      inputEndpoint.connect(filter);
      filter.connect(outputEndpoint);
      log.debug("Pipeline: WebRtcEndpoint -> ZBarFilter -> WebRtcEndpoint");
      break;

    case IMAGEOVERLAY:
      filter = new ImageOverlayFilter.Builder(mp).build();
      inputEndpoint.connect(filter);
      filter.connect(outputEndpoint);
      log.debug("Pipeline: WebRtcEndpoint -> ImageOverlayFilter -> WebRtcEndpoint");
      break;

    case PLATEDETECTOR:
      filter = new PlateDetectorFilter.Builder(mp).build();
      inputEndpoint.connect(filter);
      filter.connect(outputEndpoint);
      log.debug("Pipeline: WebRtcEndpoint -> PlateDetectorFilter -> WebRtcEndpoint");
      break;

    case CROWDDETECTOR:
      List<RegionOfInterest> rois = getDummyRois();
      filter = new CrowdDetectorFilter.Builder(mp, rois).build();
      inputEndpoint.connect(filter);
      filter.connect(outputEndpoint);
      log.debug("Pipeline: WebRtcEndpoint -> CrowdDetectorFilter -> WebRtcEndpoint");
      break;

    case CHROMA:
      filter = new ChromaFilter.Builder(mp, new WindowParam(0, 0, 640, 480)).build();
      inputEndpoint.connect(filter);
      filter.connect(outputEndpoint);
      log.debug("Pipeline: WebRtcEndpoint -> ChromaFilter -> WebRtcEndpoint");
      break;

    case NONE:
    default:
      inputEndpoint.connect(outputEndpoint);
      log.debug("Pipeline: WebRtcEndpoint -> WebRtcEndpoint");
      break;
  }
}
 
Example #9
Source File: FaceOverlayFilterTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Before
public void setupMediaElements() {

  overlayFilter = new FaceOverlayFilter.Builder(pipeline).build();
}
 
Example #10
Source File: FaceOverlayFilterAsyncTest.java    From kurento-java with Apache License 2.0 3 votes vote down vote up
@Before
public void setupMediaElements() throws InterruptedException {

  player = new PlayerEndpoint.Builder(pipeline, URL_POINTER_DETECTOR).build();

  AsyncResultManager<FaceOverlayFilter> async =
      new AsyncResultManager<>("FaceOverlayFilter creation");

  new FaceOverlayFilter.Builder(pipeline).buildAsync(async.getContinuation());

  overlayFilter = async.waitForResult();
}