コード例 #1
0
  private void setEuclideanDistance(WebSocketSession session, JsonObject jsonObject) {
    try {
      int euc_dis = jsonObject.get("val").getAsInt();

      if (null != face) face.euclideanDistance(euc_dis);

    } catch (Throwable t) {
      error(session, t.getClass().getSimpleName() + ": " + t.getMessage());
    }
  }
コード例 #2
0
  private void setTrackThreshold(WebSocketSession session, JsonObject jsonObject) {
    try {
      int track_thres = jsonObject.get("val").getAsInt();

      if (null != face) face.trackThreshold(track_thres);

    } catch (Throwable t) {
      error(session, t.getClass().getSimpleName() + ": " + t.getMessage());
    }
  }
コード例 #3
0
  private void setScaleFactor(WebSocketSession session, JsonObject jsonObject) {

    try {
      int scale = jsonObject.get("val").getAsInt();

      if (null != face) face.multiScaleFactor(scale);

    } catch (Throwable t) {
      error(session, t.getClass().getSimpleName() + ": " + t.getMessage());
    }
  }
コード例 #4
0
  private void setWidthToProcess(WebSocketSession session, JsonObject jsonObject) {

    try {
      int width = jsonObject.get("val").getAsInt();

      if (null != face) {
        face.widthToProcess(width);
      }
    } catch (Throwable t) {
      error(session, t.getClass().getSimpleName() + ": " + t.getMessage());
    }
  }
コード例 #5
0
  private void setVisualization(WebSocketSession session, JsonObject jsonObject) {

    try {

      visualizeFace = jsonObject.get("val").getAsInt();

      if (null != face) face.showFaces(visualizeFace);

    } catch (Throwable t) {
      error(session, t.getClass().getSimpleName() + ": " + t.getMessage());
    }
  }
コード例 #6
0
  private void setProcessNumberFrames(WebSocketSession session, JsonObject jsonObject) {

    try {
      int num_img = jsonObject.get("val").getAsInt();

      if (null != face) {
        log.debug("Sending process num frames...." + num_img);
        face.processXevery4Frames(num_img);
      }

    } catch (Throwable t) {
      error(session, t.getClass().getSimpleName() + ": " + t.getMessage());
    }
  }
コード例 #7
0
  private void start(final WebSocketSession session, JsonObject jsonMessage) {
    try {

      String sessionId = session.getId();
      UserSession user = new UserSession(sessionId);
      users.put(sessionId, user);
      webRtcEndpoint = user.getWebRtcEndpoint();

      // Ice Candidate
      webRtcEndpoint.addOnIceCandidateListener(
          new EventListener<OnIceCandidateEvent>() {
            @Override
            public void onEvent(OnIceCandidateEvent event) {
              JsonObject response = new JsonObject();
              response.addProperty("id", "iceCandidate");
              response.add("candidate", JsonUtils.toJsonObject(event.getCandidate()));
              sendMessage(session, new TextMessage(response.toString()));
            }
          });

      face = new NuboFaceDetector.Builder(user.getMediaPipeline()).build();
      face.activateServerEvents(1, 3000);
      addFaceListener();

      webRtcEndpoint.connect(face);
      face.connect(webRtcEndpoint);

      // SDP negotiation (offer and answer)
      String sdpOffer = jsonMessage.get("sdpOffer").getAsString();
      String sdpAnswer = webRtcEndpoint.processOffer(sdpOffer);

      // Sending response back to client
      JsonObject response = new JsonObject();
      response.addProperty("id", "startResponse");
      response.addProperty("sdpAnswer", sdpAnswer);

      synchronized (session) {
        sendMessage(session, new TextMessage(response.toString()));
      }
      webRtcEndpoint.gatherCandidates();

    } catch (NotEnoughResourcesException e) {
      log.warn("Not enough resources", e);
      notEnoughResources(session);
    } catch (Throwable t) {
      log.error("Exception starting session", t);
      error(session, t.getClass().getSimpleName() + ": " + t.getMessage());
    }
  }