openvidu-server: fix NullPointer on KurentoParticipant#releaseSubscriberEndpoint

pull/370/head
pabloFuente 2019-10-30 19:34:54 +01:00
parent b41036ead3
commit fb74074d9e
4 changed files with 55 additions and 30 deletions

View File

@ -55,6 +55,18 @@ public class KurentoMediaOptions extends MediaOptions {
this.onlyPlayWithSubscribers = onlyPlayWithSubscribers; this.onlyPlayWithSubscribers = onlyPlayWithSubscribers;
} }
public KurentoMediaOptions(Boolean hasAudio, Boolean hasVideo, Boolean audioActive, Boolean videoActive,
String typeOfVideo, Integer frameRate, String videoDimensions, KurentoFilter filter,
KurentoMediaOptions streamProperties) {
super(hasAudio, hasVideo, audioActive, videoActive, typeOfVideo, frameRate, videoDimensions, filter);
this.isOffer = streamProperties.isOffer;
this.sdpOffer = streamProperties.sdpOffer;
this.doLoopback = streamProperties.doLoopback;
this.rtspUri = streamProperties.rtspUri;
this.adaptativeBitrate = streamProperties.adaptativeBitrate;
this.onlyPlayWithSubscribers = streamProperties.onlyPlayWithSubscribers;
}
@Override @Override
public JsonObject toJson() { public JsonObject toJson() {
JsonObject json = super.toJson(); JsonObject json = super.toJson();

View File

@ -196,9 +196,9 @@ public class KurentoParticipant extends Participant {
public void unpublishMedia(EndReason reason, long kmsDisconnectionTime) { public void unpublishMedia(EndReason reason, long kmsDisconnectionTime) {
log.info("PARTICIPANT {}: unpublishing media stream from room {}", this.getParticipantPublicId(), log.info("PARTICIPANT {}: unpublishing media stream from room {}", this.getParticipantPublicId(),
this.session.getSessionId()); this.session.getSessionId());
final MediaOptions mediaOptions = this.getPublisher().getMediaOptions();
releasePublisherEndpoint(reason, kmsDisconnectionTime); releasePublisherEndpoint(reason, kmsDisconnectionTime);
this.publisher = new PublisherEndpoint(endpointType, this, this.getParticipantPublicId(), this.getPipeline(), resetPublisherEndpoint(mediaOptions);
this.openviduConfig);
log.info("PARTICIPANT {}: released publisher endpoint and left it initialized (ready for future streaming)", log.info("PARTICIPANT {}: released publisher endpoint and left it initialized (ready for future streaming)",
this.getParticipantPublicId()); this.getParticipantPublicId());
} }
@ -286,19 +286,21 @@ public class KurentoParticipant extends Participant {
log.error("Exception connecting subscriber endpoint " + "to publisher endpoint", e); log.error("Exception connecting subscriber endpoint " + "to publisher endpoint", e);
} }
this.subscribers.remove(senderName); this.subscribers.remove(senderName);
releaseSubscriberEndpoint(senderName, subscriber, null); releaseSubscriberEndpoint((KurentoParticipant) sender, subscriber, null);
} }
return null; return null;
} }
public void cancelReceivingMedia(String senderName, EndReason reason) { public void cancelReceivingMedia(KurentoParticipant senderKurentoParticipant, EndReason reason) {
final String senderName = senderKurentoParticipant.getParticipantPublicId();
log.info("PARTICIPANT {}: cancel receiving media from {}", this.getParticipantPublicId(), senderName); log.info("PARTICIPANT {}: cancel receiving media from {}", this.getParticipantPublicId(), senderName);
SubscriberEndpoint subscriberEndpoint = subscribers.remove(senderName); SubscriberEndpoint subscriberEndpoint = subscribers.remove(senderName);
if (subscriberEndpoint == null || subscriberEndpoint.getEndpoint() == null) { if (subscriberEndpoint == null || subscriberEndpoint.getEndpoint() == null) {
log.warn("PARTICIPANT {}: Trying to cancel receiving video from user {}. " log.warn("PARTICIPANT {}: Trying to cancel receiving video from user {}. "
+ "But there is no such subscriber endpoint.", this.getParticipantPublicId(), senderName); + "But there is no such subscriber endpoint.", this.getParticipantPublicId(), senderName);
} else { } else {
releaseSubscriberEndpoint(senderName, subscriberEndpoint, reason); releaseSubscriberEndpoint(senderKurentoParticipant, subscriberEndpoint, reason);
log.info("PARTICIPANT {}: stopped receiving media from {} in room {}", this.getParticipantPublicId(), log.info("PARTICIPANT {}: stopped receiving media from {} in room {}", this.getParticipantPublicId(),
senderName, this.session.getSessionId()); senderName, this.session.getSessionId());
} }
@ -318,7 +320,9 @@ public class KurentoParticipant extends Participant {
final SubscriberEndpoint subscriber = entry.getValue(); final SubscriberEndpoint subscriber = entry.getValue();
it.remove(); it.remove();
if (subscriber != null && subscriber.getEndpoint() != null) { if (subscriber != null && subscriber.getEndpoint() != null) {
releaseSubscriberEndpoint(remoteParticipantName, subscriber, reason); releaseSubscriberEndpoint(
(KurentoParticipant) this.session.getParticipantByPublicId(remoteParticipantName), subscriber,
reason);
log.debug("PARTICIPANT {}: Released subscriber endpoint to {}", this.getParticipantPublicId(), log.debug("PARTICIPANT {}: Released subscriber endpoint to {}", this.getParticipantPublicId(),
remoteParticipantName); remoteParticipantName);
} else { } else {
@ -405,7 +409,9 @@ public class KurentoParticipant extends Participant {
} }
} }
private void releaseSubscriberEndpoint(String senderName, SubscriberEndpoint subscriber, EndReason reason) { private void releaseSubscriberEndpoint(KurentoParticipant senderKurentoParticipant, SubscriberEndpoint subscriber,
EndReason reason) {
final String senderName = senderKurentoParticipant.getParticipantPublicId();
if (subscriber != null) { if (subscriber != null) {
subscriber.unregisterErrorListeners(); subscriber.unregisterErrorListeners();
@ -416,21 +422,19 @@ public class KurentoParticipant extends Participant {
releaseElement(senderName, subscriber.getEndpoint()); releaseElement(senderName, subscriber.getEndpoint());
// Stop PlayerEndpoint of IP CAM if last subscriber disconnected // Stop PlayerEndpoint of IP CAM if last subscriber disconnected
final KurentoParticipant sender = (KurentoParticipant) this.session.getParticipantByPublicId(senderName); final PublisherEndpoint senderPublisher = senderKurentoParticipant.publisher;
if (sender != null && ((KurentoMediaOptions) sender.getPublisherMediaOptions()).onlyPlayWithSubscribers) { final KurentoMediaOptions options = (KurentoMediaOptions) senderPublisher.getMediaOptions();
final PublisherEndpoint publisher = sender.publisher; if (options.onlyPlayWithSubscribers != null && options.onlyPlayWithSubscribers) {
if (publisher != null) { synchronized (senderPublisher) {
synchronized (publisher) { senderPublisher.numberOfSubscribers--;
publisher.numberOfSubscribers--; if (senderPublisher.isPlayerEndpoint() && senderPublisher.numberOfSubscribers == 0) {
if (publisher.isPlayerEndpoint() && publisher.numberOfSubscribers == 0) { try {
try { senderPublisher.getPlayerEndpoint().stop();
publisher.getPlayerEndpoint().stop(); log.info("IP Camera stream {} feed is now disabled because there are no subscribers",
log.info("IP Camera stream {} feed is now disabled because there are no subscribers", senderPublisher.getStreamId());
publisher.getStreamId()); } catch (Exception e) {
} catch (Exception e) { log.info("Error while disabling feed for IP camera {}: {}", senderPublisher.getStreamId(),
log.info("Error while disabling feed for IP camera {}: {}", publisher.getStreamId(), e.getMessage());
e.getMessage());
}
} }
} }
} }
@ -478,10 +482,19 @@ public class KurentoParticipant extends Participant {
return this.publisher.getStreamId(); return this.publisher.getStreamId();
} }
public void resetPublisherEndpoint() { public void resetPublisherEndpoint(MediaOptions mediaOptions) {
log.info("Reseting publisher endpoint for participant {}", this.getParticipantPublicId()); log.info("Reseting publisher endpoint for participant {}", this.getParticipantPublicId());
this.publisher = new PublisherEndpoint(endpointType, this, this.getParticipantPublicId(), this.publisher = new PublisherEndpoint(endpointType, this, this.getParticipantPublicId(),
this.session.getPipeline(), this.openviduConfig); this.session.getPipeline(), this.openviduConfig);
this.publisher.setMediaOptions(mediaOptions);
}
public void resetPublisherEndpoint() {
MediaOptions mediaOptions = null;
if (this.getPublisher() != null) {
mediaOptions = this.getPublisher().getMediaOptions();
}
this.resetPublisherEndpoint(mediaOptions);
} }
@Override @Override

View File

@ -105,7 +105,7 @@ public class KurentoSession extends Session {
if (participant.equals(subscriber)) { if (participant.equals(subscriber)) {
continue; continue;
} }
((KurentoParticipant) subscriber).cancelReceivingMedia(participant.getParticipantPublicId(), reason); ((KurentoParticipant) subscriber).cancelReceivingMedia((KurentoParticipant) participant, reason);
} }
log.debug("SESSION {}: Unsubscribed other participants {} from the publisher {}", sessionId, log.debug("SESSION {}: Unsubscribed other participants {} from the publisher {}", sessionId,
@ -176,12 +176,12 @@ public class KurentoSession extends Session {
checkClosed(); checkClosed();
participants.remove(participant.getParticipantPrivateId()); KurentoParticipant removedParticipant = (KurentoParticipant) participants.remove(participant.getParticipantPrivateId());
log.debug("SESSION {}: Cancel receiving media from participant '{}' for other participant", this.sessionId, log.debug("SESSION {}: Cancel receiving media from participant '{}' for other participant", this.sessionId,
participant.getParticipantPublicId()); participant.getParticipantPublicId());
for (Participant other : participants.values()) { for (Participant other : participants.values()) {
((KurentoParticipant) other).cancelReceivingMedia(participant.getParticipantPublicId(), reason); ((KurentoParticipant) other).cancelReceivingMedia(removedParticipant, reason);
} }
} }

View File

@ -436,7 +436,7 @@ public class KurentoSessionManager extends SessionManager {
"User " + senderName + " not found in session " + session.getSessionId()); "User " + senderName + " not found in session " + session.getSessionId());
} }
kParticipant.cancelReceivingMedia(senderName, EndReason.unsubscribe); kParticipant.cancelReceivingMedia((KurentoParticipant) sender, EndReason.unsubscribe);
sessionEventsHandler.onUnsubscribe(participant, transactionId, null); sessionEventsHandler.onUnsubscribe(participant, transactionId, null);
} }
@ -446,7 +446,7 @@ public class KurentoSessionManager extends SessionManager {
JsonElement newValue, String reason) { JsonElement newValue, String reason) {
KurentoParticipant kParticipant = (KurentoParticipant) participant; KurentoParticipant kParticipant = (KurentoParticipant) participant;
streamId = kParticipant.getPublisherStreamId(); streamId = kParticipant.getPublisherStreamId();
MediaOptions streamProperties = kParticipant.getPublisherMediaOptions(); KurentoMediaOptions streamProperties = (KurentoMediaOptions) kParticipant.getPublisherMediaOptions();
Boolean hasAudio = streamProperties.hasAudio(); Boolean hasAudio = streamProperties.hasAudio();
Boolean hasVideo = streamProperties.hasVideo(); Boolean hasVideo = streamProperties.hasVideo();
@ -469,8 +469,8 @@ public class KurentoSessionManager extends SessionManager {
break; break;
} }
kParticipant.setPublisherMediaOptions(new MediaOptions(hasAudio, hasVideo, audioActive, videoActive, kParticipant.setPublisherMediaOptions(new KurentoMediaOptions(hasAudio, hasVideo, audioActive, videoActive,
typeOfVideo, frameRate, videoDimensions, filter)); typeOfVideo, frameRate, videoDimensions, filter, streamProperties));
sessionEventsHandler.onStreamPropertyChanged(participant, transactionId, sessionEventsHandler.onStreamPropertyChanged(participant, transactionId,
kParticipant.getSession().getParticipants(), streamId, property, newValue, reason); kParticipant.getSession().getParticipants(), streamId, property, newValue, reason);