Java Code Examples for org.kurento.client.MediaType

The following examples show how to use org.kurento.client.MediaType. 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: openvidu   Source File: SingleStreamRecordingService.java    License: 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 2
Source Project: openvidu   Source File: PublisherEndpoint.java    License: Apache License 2.0 6 votes vote down vote up
public synchronized void mute(TrackType muteType) {
	MediaElement sink = passThru;
	if (!elements.isEmpty()) {
		String sinkId = elementIds.peekLast();
		if (!elements.containsKey(sinkId)) {
			throw new OpenViduException(Code.MEDIA_ENDPOINT_ERROR_CODE,
					"This endpoint (" + getEndpointName() + ") has no media element with id " + sinkId
							+ " (should've been connected to the internal ep)");
		}
		sink = elements.get(sinkId);
	} else {
		log.debug("Will mute connection of WebRTC and PassThrough (no other elems)");
	}
	switch (muteType) {
	case ALL:
		internalSinkDisconnect(this.getEndpoint(), sink);
		break;
	case AUDIO:
		internalSinkDisconnect(this.getEndpoint(), sink, MediaType.AUDIO);
		break;
	case VIDEO:
		internalSinkDisconnect(this.getEndpoint(), sink, MediaType.VIDEO);
		break;
	}
}
 
Example 3
Source Project: openvidu   Source File: PublisherEndpoint.java    License: Apache License 2.0 6 votes vote down vote up
public synchronized void unmute(TrackType muteType) {
	MediaElement sink = passThru;
	if (!elements.isEmpty()) {
		String sinkId = elementIds.peekLast();
		if (!elements.containsKey(sinkId)) {
			throw new OpenViduException(Code.MEDIA_ENDPOINT_ERROR_CODE,
					"This endpoint (" + getEndpointName() + ") has no media element with id " + sinkId
							+ " (should've been connected to the internal ep)");
		}
		sink = elements.get(sinkId);
	} else {
		log.debug("Will unmute connection of WebRTC and PassThrough (no other elems)");
	}
	switch (muteType) {
	case ALL:
		internalSinkConnect(this.getEndpoint(), sink);
		break;
	case AUDIO:
		internalSinkConnect(this.getEndpoint(), sink, MediaType.AUDIO);
		break;
	case VIDEO:
		internalSinkConnect(this.getEndpoint(), sink, MediaType.VIDEO);
		break;
	}
}
 
Example 4
Source Project: openvidu   Source File: PublisherEndpoint.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Same as {@link #internalSinkConnect(MediaElement, MediaElement)}, but can
 * specify the type of the media that will be streamed.
 *
 * @param source
 * @param sink
 * @param type   if null,
 *               {@link #internalSinkConnect(MediaElement, MediaElement)} will
 *               be used instead
 * @see #internalSinkConnect(MediaElement, MediaElement)
 */
private void internalSinkConnect(final MediaElement source, final MediaElement sink, final MediaType type) {
	if (type == null) {
		internalSinkConnect(source, sink);
	} else {
		source.connect(sink, type, new Continuation<Void>() {
			@Override
			public void onSuccess(Void result) throws Exception {
				log.debug("EP {}: {} media elements have been connected (source {} -> sink {})", getEndpointName(),
						type, source.getId(), sink.getId());
			}

			@Override
			public void onError(Throwable cause) throws Exception {
				log.warn("EP {}: Failed to connect {} media elements (source {} -> sink {})", getEndpointName(),
						type, source.getId(), sink.getId(), cause);
			}
		});
	}
}
 
Example 5
Source Project: openvidu   Source File: PublisherEndpoint.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Same as {@link #internalSinkDisconnect(MediaElement, MediaElement)}, but can
 * specify the type of the media that will be disconnected.
 *
 * @param source
 * @param sink
 * @param type   if null,
 *               {@link #internalSinkConnect(MediaElement, MediaElement)} will
 *               be used instead
 * @see #internalSinkConnect(MediaElement, MediaElement)
 */
private void internalSinkDisconnect(final MediaElement source, final MediaElement sink, final MediaType type) {
	if (type == null) {
		internalSinkDisconnect(source, sink);
	} else {
		source.disconnect(sink, type, new Continuation<Void>() {
			@Override
			public void onSuccess(Void result) throws Exception {
				log.debug("EP {}: {} media elements have been disconnected (source {} -> sink {})",
						getEndpointName(), type, source.getId(), sink.getId());
			}

			@Override
			public void onError(Throwable cause) throws Exception {
				log.warn("EP {}: Failed to disconnect {} media elements (source {} -> sink {})", getEndpointName(),
						type, source.getId(), sink.getId(), cause);
			}
		});
	}
}
 
Example 6
Source Project: kurento-room   Source File: NotificationRoomManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param request instance of {@link ParticipantRequest} POJO
 * @see RoomManager#publishMedia(String, boolean, String, MediaElement, MediaType, boolean, *
 * MediaElement...)
 */
public void publishMedia(ParticipantRequest request, boolean isOffer, String sdp,
    MediaElement loopbackAlternativeSrc, MediaType loopbackConnectionType, boolean doLoopback,
    MediaElement... mediaElements) {
  String pid = request.getParticipantId();
  String userName = null;
  Set<UserParticipant> participants = null;
  String sdpAnswer = null;
  try {
    userName = internalManager.getParticipantName(pid);
    sdpAnswer = internalManager
        .publishMedia(request.getParticipantId(), isOffer, sdp, loopbackAlternativeSrc,
            loopbackConnectionType, doLoopback, mediaElements);
    participants = internalManager.getParticipants(internalManager.getRoomName(pid));
  } catch (RoomException e) {
    log.warn("PARTICIPANT {}: Error publishing media", userName, e);
    notificationRoomHandler.onPublishMedia(request, null, null, null, e);
  }
  if (sdpAnswer != null) {
    notificationRoomHandler.onPublishMedia(request, userName, sdpAnswer, participants, null);
  }
}
 
Example 7
Source Project: kurento-room   Source File: SubscriberEndpoint.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void mute(MutedMediaType muteType) {
  if (this.publisher == null) {
    throw new RoomException(Code.MEDIA_MUTE_ERROR_CODE, "Publisher endpoint not found");
  }
  switch (muteType) {
    case ALL :
      this.publisher.disconnectFrom(this.getEndpoint());
      break;
    case AUDIO :
      this.publisher.disconnectFrom(this.getEndpoint(), MediaType.AUDIO);
      break;
    case VIDEO :
      this.publisher.disconnectFrom(this.getEndpoint(), MediaType.VIDEO);
      break;
  }
  resolveCurrentMuteType(muteType);
}
 
Example 8
Source Project: kurento-room   Source File: PublisherEndpoint.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Same as {@link #internalSinkConnect(MediaElement, MediaElement)}, but can specify the type of
 * the media that will be streamed.
 *
 * @param source
 * @param sink
 * @param type   if null, {@link #internalSinkConnect(MediaElement, MediaElement)} will be used
 *               instead
 * @see #internalSinkConnect(MediaElement, MediaElement)
 */
private void internalSinkConnect(final MediaElement source, final MediaElement sink,
    final MediaType type) {
  if (type == null) {
    internalSinkConnect(source, sink);
  } else {
    source.connect(sink, type, new Continuation<Void>() {
      @Override
      public void onSuccess(Void result) throws Exception {
        log.debug("EP {}: {} media elements have been connected (source {} -> sink {})",
            getEndpointName(), type, source.getId(), sink.getId());
      }

      @Override
      public void onError(Throwable cause) throws Exception {
        log.warn("EP {}: Failed to connect {} media elements (source {} -> sink {})",
            getEndpointName(), type, source.getId(), sink.getId(), cause);
      }
    });
  }
}
 
Example 9
Source Project: kurento-room   Source File: PublisherEndpoint.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Same as {@link #internalSinkDisconnect(MediaElement, MediaElement)}, but can specify the type
 * of the media that will be disconnected.
 *
 * @param source
 * @param sink
 * @param type   if null, {@link #internalSinkConnect(MediaElement, MediaElement)} will be used
 *               instead
 * @see #internalSinkConnect(MediaElement, MediaElement)
 */
private void internalSinkDisconnect(final MediaElement source, final MediaElement sink,
    final MediaType type) {
  if (type == null) {
    internalSinkDisconnect(source, sink);
  } else {
    source.disconnect(sink, type, new Continuation<Void>() {
      @Override
      public void onSuccess(Void result) throws Exception {
        log.debug("EP {}: {} media elements have been disconnected (source {} -> sink {})",
            getEndpointName(), type, source.getId(), sink.getId());
      }

      @Override
      public void onError(Throwable cause) throws Exception {
        log.warn("EP {}: Failed to disconnect {} media elements (source {} -> sink {})",
            getEndpointName(), type, source.getId(), sink.getId(), cause);
      }
    });
  }
}
 
Example 10
Source Project: kurento-java   Source File: AgnosticBenchmarkTest.java    License: Apache License 2.0 6 votes vote down vote up
private double getInputLatency(MediaElement mediaElement, Multimap<String, Object> statTimeMap,
    String mediaElementName) {
  long now = System.currentTimeMillis();
  Map<String, Stats> filterStats = mediaElement.getStats(MediaType.VIDEO);
  long time = System.currentTimeMillis() - now;
  statTimeMap.put(mediaElementName + "MiliSec", time);

  double inputLatency = 0;
  for (Stats s : filterStats.values()) {
    if (s instanceof ElementStats) {
      List<MediaLatencyStat> inputLatencyList = ((ElementStats) s).getInputLatency();
      if (!inputLatencyList.isEmpty()) {
        inputLatency = inputLatencyList.get(0).getAvg();
      }
    }
  }
  return inputLatency;
}
 
Example 11
Source Project: kurento-java   Source File: RtpEndpointAsyncTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testRtpEndpointSimulatingAndroidSdp() throws InterruptedException {

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

  RtpEndpoint rtpEndpoint = new RtpEndpoint.Builder(pipeline).build();

  String requestSdp = "v=0\r\n" + "o=- 12345 12345 IN IP4 95.125.31.136\r\n" + "s=-\r\n"
      + "c=IN IP4 95.125.31.136\r\n" + "t=0 0\r\n" + "m=video 52126 RTP/AVP 96 97 98\r\n"
      + "a=rtpmap:96 H264/90000\r\n" + "a=rtpmap:97 MP4V-ES/90000\r\n"
      + "a=rtpmap:98 H263-1998/90000\r\n" + "a=recvonly\r\n" + "b=AS:384\r\n";

  rtpEndpoint.processOffer(requestSdp);
  player.connect(rtpEndpoint, MediaType.VIDEO);
  player.play();

  // just a little bit of time before destroying
  Thread.sleep(2000);
}
 
Example 12
Source Project: kurento-java   Source File: SdpBaseTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testRtpEndpointSimulatingAndroidSdp() throws InterruptedException {

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

  String requestSdp = "v=0\r\n" + "o=- 12345 12345 IN IP4 95.125.31.136\r\n" + "s=-\r\n"
      + "c=IN IP4 95.125.31.136\r\n" + "t=0 0\r\n" + "m=video 52126 RTP/AVP 96 97 98\r\n"
      + "a=rtpmap:96 H264/90000\r\n" + "a=rtpmap:97 MP4V-ES/90000\r\n"
      + "a=rtpmap:98 H263-1998/90000\r\n" + "a=recvonly\r\n" + "b=AS:384\r\n";

  player.connect(sdp, MediaType.VIDEO);
  sdp.processOffer(requestSdp);
  player.play();

  // just a little bit of time before destroying
  Thread.sleep(2000);
}
 
Example 13
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 14
Source Project: openvidu   Source File: PublisherEndpoint.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized void connect(MediaElement sink, MediaType type) {
	if (!connected) {
		innerConnect();
	}
	internalSinkConnect(passThru, sink, type);
	this.enableIpCameraIfNecessary();
}
 
Example 15
Source Project: openvidu   Source File: PublisherEndpoint.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Same as {@link #apply(MediaElement)}, can specify the media type that will be
 * streamed through the shaper element.
 *
 * @param shaper {@link MediaElement} that will be linked to the end of the
 *               chain (e.g. a filter)
 * @param type   indicates which type of media will be connected to the shaper
 *               ({@link MediaType}), if null then the connection is mixed
 * @return the element's id
 * @throws OpenViduException if thrown, the media element was not added
 */
public synchronized String apply(GenericMediaElement shaper, MediaType type) throws OpenViduException {
	String id = shaper.getId();
	if (id == null) {
		throw new OpenViduException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE,
				"Unable to connect media element with null id");
	}
	if (elements.containsKey(id)) {
		throw new OpenViduException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE,
				"This endpoint already has a media element with id " + id);
	}
	MediaElement first = null;
	if (!elementIds.isEmpty()) {
		first = elements.get(elementIds.getFirst());
	}
	if (connected) {
		if (first != null) {
			internalSinkConnect(first, shaper, type);
		} else {
			internalSinkConnect(this.getEndpoint(), shaper, type);
		}
		internalSinkConnect(shaper, passThru, type);
	}
	elementIds.addFirst(id);
	elements.put(id, shaper);

	this.filter = shaper;

	elementsErrorSubscriptions.put(id, registerElemErrListener(shaper));
	return id;
}
 
Example 16
Source Project: openmeetings   Source File: KStream.java    License: Apache License 2.0 5 votes vote down vote up
private WebRtcEndpoint getEndpointForUser(final StreamProcessor processor, String sid, String uid) {
	if (uid.equals(this.uid)) {
		log.debug("PARTICIPANT {}: configuring loopback", this.uid);
		return outgoingMedia;
	}

	log.debug("PARTICIPANT {}: receiving video from {}", uid, this.uid);
	WebRtcEndpoint listener = listeners.remove(uid);
	if (listener != null) {
		log.debug("PARTICIPANT {}: re-started video receiving, will drop previous endpoint", uid);
		listener.release();
	}
	log.debug("PARTICIPANT {}: creating new endpoint for {}", uid, this.uid);
	listener = createEndpoint(processor, sid, uid);
	listeners.put(uid, listener);

	log.debug("PARTICIPANT {}: obtained endpoint for {}", uid, this.uid);
	Client cur = processor.getBySid(this.sid);
	if (cur == null) {
		log.warn("Client for endpoint dooesn't exists");
	} else {
		StreamDesc sd = cur.getStream(this.uid);
		if (sd == null) {
			log.warn("Stream for endpoint dooesn't exists");
		} else {
			if (sd.hasActivity(Activity.AUDIO)) {
				outgoingMedia.connect(listener, MediaType.AUDIO);
			}
			if (StreamType.SCREEN == streamType || sd.hasActivity(Activity.VIDEO)) {
				outgoingMedia.connect(listener, MediaType.VIDEO);
			}
		}
	}
	return listener;
}
 
Example 17
Source Project: openmeetings   Source File: KStream.java    License: Apache License 2.0 5 votes vote down vote up
public void startRecord(StreamProcessor processor) {
	log.debug("startRecord outMedia OK ? {}", outgoingMedia != null);
	if (outgoingMedia == null) {
		release(processor, true);
		return;
	}
	final String chunkUid = "rec_" + room.getRecordingId() + "_" + randomUUID();
	recorder = createRecorderEndpoint(room.getPipeline(), getRecUri(getRecordingChunk(room.getRoomId(), chunkUid)), profile);
	recorder.addTag("outUid", uid);
	recorder.addTag("uid", uid);

	recorder.addRecordingListener(evt -> chunkId = room.getChunkDao().start(room.getRecordingId(), type, chunkUid, sid));
	recorder.addStoppedListener(evt -> room.getChunkDao().stop(chunkId));
	switch (profile) {
		case WEBM:
			outgoingMedia.connect(recorder, MediaType.AUDIO);
			outgoingMedia.connect(recorder, MediaType.VIDEO);
			break;
		case WEBM_VIDEO_ONLY:
			outgoingMedia.connect(recorder, MediaType.VIDEO);
			break;
		case WEBM_AUDIO_ONLY:
		default:
			outgoingMedia.connect(recorder, MediaType.AUDIO);
			break;
	}
	recorder.record(new Continuation<Void>() {
		@Override
		public void onSuccess(Void result) throws Exception {
			log.info("Recording started successfully");
		}

		@Override
		public void onError(Throwable cause) throws Exception {
			log.error("Failed to start recording", cause);
		}
	});
}
 
Example 18
Source Project: kurento-room   Source File: Participant.java    License: Apache License 2.0 5 votes vote down vote up
public void shapePublisherMedia(MediaElement element, MediaType type) {
  if (type == null) {
    this.publisher.apply(element);
  } else {
    this.publisher.apply(element, type);
  }
}
 
Example 19
Source Project: kurento-room   Source File: Participant.java    License: Apache License 2.0 5 votes vote down vote up
public String publishToRoom(SdpType sdpType, String sdpString, boolean doLoopback,
    MediaElement loopbackAlternativeSrc, MediaType loopbackConnectionType) {
  log.info("USER {}: Request to publish video in room {} (sdp type {})", this.name,
      this.room.getName(), sdpType);
  log.trace("USER {}: Publishing Sdp ({}) is {}", this.name, sdpType, sdpString);

  String sdpResponse = this.getPublisher()
      .publish(sdpType, sdpString, doLoopback, loopbackAlternativeSrc, loopbackConnectionType);
  this.streaming = true;

  log.trace("USER {}: Publishing Sdp ({}) is {}", this.name, sdpType, sdpResponse);
  log.info("USER {}: Is now publishing video in room {}", this.name, this.room.getName());

  return sdpResponse;
}
 
Example 20
Source Project: kurento-room   Source File: PublisherEndpoint.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Initializes this media endpoint for publishing media and processes the SDP offer or answer. If
 * the internal endpoint is an {@link WebRtcEndpoint}, it first registers an event listener for
 * the ICE candidates and instructs the endpoint to start gathering the candidates. If required,
 * it connects to itself (after applying the intermediate media elements and the
 * {@link PassThrough}) to allow loopback of the media stream.
 *
 * @param sdpType                indicates the type of the sdpString (offer or answer)
 * @param sdpString              offer or answer from the remote peer
 * @param doLoopback             loopback flag
 * @param loopbackAlternativeSrc alternative loopback source
 * @param loopbackConnectionType how to connect the loopback source
 * @return the SDP response (the answer if processing an offer SDP, otherwise is the updated offer
 * generated previously by this endpoint)
 */
public synchronized String publish(SdpType sdpType, String sdpString, boolean doLoopback,
    MediaElement loopbackAlternativeSrc, MediaType loopbackConnectionType) {
  registerOnIceCandidateEventListener();
  if (doLoopback) {
    if (loopbackAlternativeSrc == null) {
      connect(this.getEndpoint(), loopbackConnectionType);
    } else {
      connectAltLoopbackSrc(loopbackAlternativeSrc, loopbackConnectionType);
    }
  } else {
    innerConnect();
  }
  String sdpResponse = null;
  switch (sdpType) {
    case ANSWER:
      sdpResponse = processAnswer(sdpString);
      break;
    case OFFER:
      sdpResponse = processOffer(sdpString);
      break;
    default:
      throw new RoomException(Code.MEDIA_SDP_ERROR_CODE, "Sdp type not supported: " + sdpType);
  }
  gatherCandidates();
  return sdpResponse;
}
 
Example 21
Source Project: kurento-room   Source File: PublisherEndpoint.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Same as {@link #apply(MediaElement)}, can specify the media type that will be streamed through
 * the shaper element.
 *
 * @param shaper {@link MediaElement} that will be linked to the end of the chain (e.g. a filter)
 * @param type   indicates which type of media will be connected to the shaper
 *               ({@link MediaType}), if
 *               null then the connection is mixed
 * @return the element's id
 * @throws RoomException if thrown, the media element was not added
 */
public synchronized String apply(MediaElement shaper, MediaType type) throws RoomException {
  String id = shaper.getId();
  if (id == null) {
    throw new RoomException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE,
        "Unable to connect media element with null id");
  }
  if (elements.containsKey(id)) {
    throw new RoomException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE,
        "This endpoint already has a media element with id " + id);
  }
  MediaElement first = null;
  if (!elementIds.isEmpty()) {
    first = elements.get(elementIds.getFirst());
  }
  if (connected) {
    if (first != null) {
      internalSinkConnect(first, shaper, type);
    } else {
      internalSinkConnect(this.getEndpoint(), shaper, type);
    }
    internalSinkConnect(shaper, passThru, type);
  }
  elementIds.addFirst(id);
  elements.put(id, shaper);
  elementsErrorSubscriptions.put(id, registerElemErrListener(shaper));
  return id;
}
 
Example 22
Source Project: kurento-room   Source File: PublisherEndpoint.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void mute(MutedMediaType muteType) {
  MediaElement sink = passThru;
  if (!elements.isEmpty()) {
    String sinkId = elementIds.peekLast();
    if (!elements.containsKey(sinkId)) {
      throw new RoomException(Code.MEDIA_ENDPOINT_ERROR_CODE,
          "This endpoint (" + getEndpointName() + ") has no media element with id " + sinkId
              + " (should've been connected to the internal ep)");
    }
    sink = elements.get(sinkId);
  } else {
    log.debug("Will mute connection of WebRTC and PassThrough (no other elems)");
  }
  switch (muteType) {
    case ALL:
      internalSinkDisconnect(this.getEndpoint(), sink);
      break;
    case AUDIO:
      internalSinkDisconnect(this.getEndpoint(), sink, MediaType.AUDIO);
      break;
    case VIDEO:
      internalSinkDisconnect(this.getEndpoint(), sink, MediaType.VIDEO);
      break;
  }
  resolveCurrentMuteType(muteType);
}
 
Example 23
Source Project: kurento-room   Source File: PublisherEndpoint.java    License: Apache License 2.0 5 votes vote down vote up
private void connectAltLoopbackSrc(MediaElement loopbackAlternativeSrc,
    MediaType loopbackConnectionType) {
  if (!connected) {
    innerConnect();
  }
  internalSinkConnect(loopbackAlternativeSrc, this.getEndpoint(), loopbackConnectionType);
}
 
Example 24
Source Project: kurento-java   Source File: WebRtcClient.java    License: Apache License 2.0 5 votes vote down vote up
private WebRtcEndpointStats getStats(WebRtcEndpoint webRtcEndpoint) {
  Map<String, Stats> stats = new HashMap<>();
  MediaType[] types = { MediaType.VIDEO, MediaType.AUDIO, MediaType.DATA };

  for (MediaType type : types) {
    Map<String, Stats> trackStats = webRtcEndpoint.getStats(type);
    for (Stats track : trackStats.values()) {
      stats.put(type.name().toLowerCase() + "_" + getRtcStatsType(track.getClass()), track);
    }
  }

  return new WebRtcEndpointStats(stats);
}
 
Example 25
Source Project: kurento-java   Source File: CompositeWebRtcRecorderTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCompositeRecorder() throws Exception {

  // MediaPipeline
  MediaPipeline mp = kurentoClient.createMediaPipeline();

  Composite composite = new Composite.Builder(mp).build();

  HubPort hubPort1 = new HubPort.Builder(composite).build();
  WebRtcEndpoint webRtcEpRed = new WebRtcEndpoint.Builder(mp).build();
  webRtcEpRed.connect(hubPort1);

  HubPort hubPort2 = new HubPort.Builder(composite).build();
  WebRtcEndpoint webRtcEpGreen = new WebRtcEndpoint.Builder(mp).build();
  webRtcEpGreen.connect(hubPort2, MediaType.AUDIO);

  HubPort hubPort3 = new HubPort.Builder(composite).build();
  WebRtcEndpoint webRtcEpBlue = new WebRtcEndpoint.Builder(mp).build();
  webRtcEpBlue.connect(hubPort3, MediaType.AUDIO);

  HubPort hubPort4 = new HubPort.Builder(composite).build();
  WebRtcEndpoint webRtcEpWhite = new WebRtcEndpoint.Builder(mp).build();
  webRtcEpWhite.connect(hubPort4, MediaType.AUDIO);

  String recordingFile = getDefaultOutputFile(EXTENSION_WEBM);
  RecorderEndpoint recorderEp =
      new RecorderEndpoint.Builder(mp, Protocol.FILE + recordingFile).build();
  HubPort hubPort5 = new HubPort.Builder(composite).build();
  hubPort5.connect(recorderEp);

  // WebRTC browsers
  getPage(BROWSER2).initWebRtc(webRtcEpRed, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_ONLY);
  getPage(BROWSER3).initWebRtc(webRtcEpGreen, WebRtcChannel.AUDIO_AND_VIDEO,
      WebRtcMode.SEND_ONLY);
  getPage(BROWSER4).initWebRtc(webRtcEpBlue, WebRtcChannel.AUDIO_AND_VIDEO, WebRtcMode.SEND_ONLY);
  getPage(BROWSER5).initWebRtc(webRtcEpWhite, WebRtcChannel.AUDIO_AND_VIDEO,
      WebRtcMode.SEND_ONLY);

  recorderEp.record();

  Thread.sleep(PLAYTIME * 1000);

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

  // Media Pipeline #2
  MediaPipeline mp2 = kurentoClient.createMediaPipeline();
  PlayerEndpoint playerEp2 =
      new PlayerEndpoint.Builder(mp2, Protocol.FILE + recordingFile).build();
  WebRtcEndpoint webRtcEp2 = new WebRtcEndpoint.Builder(mp2).build();
  playerEp2.connect(webRtcEp2);

  // Playing the recorded file
  launchBrowser(mp2, webRtcEp2, playerEp2, null, EXPECTED_VIDEO_CODEC_WEBM,
      EXPECTED_AUDIO_CODEC_WEBM, recordingFile, Color.RED, 0, 0, PLAYTIME);

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

  success = true;
}
 
Example 26
Source Project: openvidu   Source File: KmsMediaEvent.java    License: Apache License 2.0 4 votes vote down vote up
public KmsMediaEvent(MediaEvent event, Participant participant, String endpointName, MediaType mediaType,
		long createdAt) {
	super(event, participant, endpointName, createdAt);
	this.mediaType = mediaType;
}
 
Example 27
Source Project: openmeetings   Source File: KTestStream.java    License: Apache License 2.0 4 votes vote down vote up
public KTestStream(IWsClient c, JSONObject msg, MediaPipeline pipeline) {
	super(null, c.getUid());
	this.pipeline = pipeline;
	webRtcEndpoint = createWebRtcEndpoint(pipeline);
	webRtcEndpoint.connect(webRtcEndpoint);

	MediaProfileSpecType profile = getProfile(msg);
	initRecPath();
	recorder = createRecorderEndpoint(pipeline, recPath, profile);

	recorder.addRecordingListener(evt -> {
			recTime = 0;
			recHandle = scheduler.scheduleAtFixedRate(
					() -> WebSocketHelper.sendClient(c, newTestKurentoMsg().put("id", "recording").put("time", recTime++))
					, 0, 1, TimeUnit.SECONDS);
			scheduler.schedule(() -> {
					recorder.stop();
					recHandle.cancel(true);
				}, 5, TimeUnit.SECONDS);
		});
	recorder.addStoppedListener(evt -> {
			WebSocketHelper.sendClient(c, newTestKurentoMsg().put("id", "recStopped"));
			releaseRecorder();
		});
	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:
			//no-op
			break;
	}

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

	addIceListener(c);

	WebSocketHelper.sendClient(c, newTestKurentoMsg()
			.put("id", "startResponse")
			.put("sdpAnswer", sdpAnswer));
	webRtcEndpoint.gatherCandidates();
	recorder.record(new Continuation<Void>() {
		@Override
		public void onSuccess(Void result) throws Exception {
			log.info("Recording started successfully");
		}

		@Override
		public void onError(Throwable cause) throws Exception {
			sendError(c, "Failed to start recording");
			log.error("Failed to start recording", cause);
		}
	});
}
 
Example 28
Source Project: kurento-room   Source File: NotificationRoomManager.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @see RoomManager#addMediaElement(String, MediaElement, MediaType)
 */
public void addMediaElement(String participantId, MediaElement element, MediaType type)
    throws RoomException {
  internalManager.addMediaElement(participantId, element, type);
}
 
Example 29
Source Project: kurento-room   Source File: PublisherEndpoint.java    License: Apache License 2.0 4 votes vote down vote up
public synchronized void connect(MediaElement sink, MediaType type) {
  if (!connected) {
    innerConnect();
  }
  internalSinkConnect(passThru, sink, type);
}
 
Example 30
Source Project: kurento-room   Source File: PublisherEndpoint.java    License: Apache License 2.0 4 votes vote down vote up
public synchronized void disconnectFrom(MediaElement sink, MediaType type) {
  internalSinkDisconnect(passThru, sink, type);
}