private SdpEndpoint buildAndConnectSdpEndpoint(MediaPipeline mediaPipeline,
MediaElement sourceElement, MediaElement sinkElement) {
getLogger().info("Creating SdpEndpoint ...");
SdpEndpoint sdpEndpoint = buildSdpEndpoint(mediaPipeline);
releaseOnTerminate(sdpEndpoint);
// If no source is provided, jut loopback for having some media back
// to the client
if (sourceElement == null) {
sourceElement = sdpEndpoint; // This produces a loopback.
}
getLogger().info("Connecting media pads ...");
// TODO: should we double check constraints?
if (sinkElement != null) {
sdpEndpoint.connect(sinkElement);
}
if (sourceElement != null) {
sourceElement.connect(sdpEndpoint);
}