|
@@ -172,11 +172,62 @@ public class RtpServerServiceImpl implements IReceiveRtpServerService {
|
|
|
} catch (RuntimeException ex) {
|
|
} catch (RuntimeException ex) {
|
|
|
log.warn("[RTP close] {}/{} remains pending: {}", node.getId(), info.getStream(), ex.getMessage());
|
|
log.warn("[RTP close] {}/{} remains pending: {}", node.getId(), info.getStream(), ex.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
+ // ZLM reclaims an idle RTP server on its own (on_stream_none_reader), so the name-close above
|
|
|
|
|
+ // answers hit=0 even though the resource is genuinely gone. Without this the allocation would
|
|
|
|
|
+ // sit in CLOSING for ever and canReplaceAllocation() would reject every later play on the
|
|
|
|
|
+ // channel. hit=0 alone is still not evidence: finish only when ZLM positively reports the
|
|
|
|
|
+ // server absent, and stay unresolved when the node cannot be read.
|
|
|
|
|
+ if (!info.getStream().startsWith("managed_") && serverAbsent(node, info.getStream())) {
|
|
|
|
|
+ if (allocationState(node, info, RtpState.CLOSING, RtpState.CLOSED, actorGuard)) {
|
|
|
|
|
+ try { releaseClosedSsrc(node, info); }
|
|
|
|
|
+ catch (RuntimeException ex) { log.warn("[RTP close reclaimed] {}/{}: {}", node.getId(), info.getStream(), ex.getMessage()); }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
Snapshot after = stopReceipts.read(node.getId(), info.getStream());
|
|
Snapshot after = stopReceipts.read(node.getId(), info.getStream());
|
|
|
return after != null && after.allocation != null && after.allocation.matches(info)
|
|
return after != null && after.allocation != null && after.allocation.matches(info)
|
|
|
&& after.allocation.state == RtpState.CLOSED;
|
|
&& after.allocation.state == RtpState.CLOSED;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Positive absence evidence from ZLM: the query must answer code=0 and say the server does not
|
|
|
|
|
+ * exist. A failed request or a non-zero code is UNKNOWN and must never unlock the allocation.
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean serverAbsent(MediaServer node, String stream) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return mediaServerService.isRtpServerAbsent(node, stream);
|
|
|
|
|
+ } catch (RuntimeException ex) {
|
|
|
|
|
+ log.warn("[RTP absence check] {}/{} unreadable: {}", node.getId(), stream, ex.getMessage());
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Retire a legacy allocation whose stream ZLM no longer holds, so the channel can be played again.
|
|
|
|
|
+ * Only callers that already have positive absence evidence may reach this.
|
|
|
|
|
+ */
|
|
|
|
|
+ private boolean retireStaleAllocation(MediaServer node, String stream) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // ZLM positively reports this stream gone, so whatever the receipt still says about
|
|
|
|
|
+ // callId or bound viewers describes a handle that no longer exists. The state machine
|
|
|
|
|
+ // only permits OPEN -> CLOSING -> CLOSED, so walk both steps rather than jump.
|
|
|
|
|
+ Snapshot closing = stopReceipts.update(node.getId(), stream, snapshot -> {
|
|
|
|
|
+ if (snapshot.allocation == null || snapshot.allocation.state != RtpState.OPEN) return null;
|
|
|
|
|
+ // Play evidence is immutable once recorded; only the allocation state moves.
|
|
|
|
|
+ snapshot.allocation.state = RtpState.CLOSING;
|
|
|
|
|
+ return snapshot;
|
|
|
|
|
+ });
|
|
|
|
|
+ if (closing == null) return false;
|
|
|
|
|
+ Snapshot retired = stopReceipts.update(node.getId(), stream, snapshot -> {
|
|
|
|
|
+ if (snapshot.allocation == null || snapshot.allocation.state != RtpState.CLOSING) return null;
|
|
|
|
|
+ snapshot.allocation.state = RtpState.CLOSED;
|
|
|
|
|
+ return snapshot;
|
|
|
|
|
+ });
|
|
|
|
|
+ return retired != null;
|
|
|
|
|
+ } catch (RuntimeException ex) {
|
|
|
|
|
+ log.warn("[RTP stale retire] {}/{}: {}", node.getId(), stream, ex.getMessage());
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private boolean cancelled(String stream) {
|
|
private boolean cancelled(String stream) {
|
|
|
// Managed resource creation fails closed without the cancellation persistence seam.
|
|
// Managed resource creation fails closed without the cancellation persistence seam.
|
|
|
return videoLifecycleStore == null || videoLifecycleStore.isStreamCancelled(stream);
|
|
return videoLifecycleStore == null || videoLifecycleStore.isStreamCancelled(stream);
|
|
@@ -406,9 +457,20 @@ public class RtpServerServiceImpl implements IReceiveRtpServerService {
|
|
|
LegacyRtp entry = new LegacyRtp(ssrcInfo);
|
|
LegacyRtp entry = new LegacyRtp(ssrcInfo);
|
|
|
String allocationKey = managedKey(rtpServerParam.getMediaServerItem(), streamId);
|
|
String allocationKey = managedKey(rtpServerParam.getMediaServerItem(), streamId);
|
|
|
if (!reserveAllocation(rtpServerParam.getMediaServerItem(), ssrcInfo, rtpServerParam.getPresetSsrc() != null)) {
|
|
if (!reserveAllocation(rtpServerParam.getMediaServerItem(), ssrcInfo, rtpServerParam.getPresetSsrc() != null)) {
|
|
|
- if (rtpServerParam.getPresetSsrc() == null) ssrcFactory.releaseSsrc(rtpServerParam.getMediaServerItem().getId(), ssrc, timeOutTaskKey);
|
|
|
|
|
- callback.run(InviteErrorCode.FAIL.getCode(), "Adopted RTP close is still pending", null);
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ // A viewer that went away without a clean stop leaves the previous allocation OPEN while
|
|
|
|
|
+ // ZLM has already reclaimed the idle stream. That is a dead handle, not a live lease: once
|
|
|
|
|
+ // ZLM positively reports the stream gone, retire the stale allocation and allocate again.
|
|
|
|
|
+ // An unreadable node stays fenced, so UNKNOWN never unlocks the name.
|
|
|
|
|
+ if (!rtpServerParam.getMediaServerItem().getId().isEmpty()
|
|
|
|
|
+ && serverAbsent(rtpServerParam.getMediaServerItem(), streamId)
|
|
|
|
|
+ && retireStaleAllocation(rtpServerParam.getMediaServerItem(), streamId)
|
|
|
|
|
+ && reserveAllocation(rtpServerParam.getMediaServerItem(), ssrcInfo, rtpServerParam.getPresetSsrc() != null)) {
|
|
|
|
|
+ legacyRtp.put(allocationKey, entry);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (rtpServerParam.getPresetSsrc() == null) ssrcFactory.releaseSsrc(rtpServerParam.getMediaServerItem().getId(), ssrc, timeOutTaskKey);
|
|
|
|
|
+ callback.run(InviteErrorCode.FAIL.getCode(), "Adopted RTP close is still pending", null);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
legacyRtp.put(allocationKey, entry);
|
|
legacyRtp.put(allocationKey, entry);
|
|
|
if (!allocationState(rtpServerParam.getMediaServerItem(), ssrcInfo, RtpState.INTENT, RtpState.CREATING)) {
|
|
if (!allocationState(rtpServerParam.getMediaServerItem(), ssrcInfo, RtpState.INTENT, RtpState.CREATING)) {
|