private bool TryLinkToLiveStream(BaseRTMPProtocol pFrom, uint streamId, string streamName, out bool linked)
{
linked = false;
//1. Get get the short version of the stream name
var parts = streamName.Split('?');
var shortName = parts[0];
//2. Search for the long version first
var inboundStreams = Application.StreamsManager.FindByTypeByName(StreamTypes.ST_IN_NET, streamName, true,
false);
//3. Search for the short version if necessary
if (inboundStreams.Count == 0)
inboundStreams = Application.StreamsManager.FindByTypeByName(StreamTypes.ST_IN_NET, shortName + "?",
true, true);
//4. Do we have some streams?
if (inboundStreams.Count == 0)
{
Logger.WARN("No live streams found: `{0}` or `{1}`", streamName, shortName);
return true;
}
//5. Get the first stream in the inboundStreams
var pBaseInNetStream = inboundStreams.Values.OfType<IInStream>()
.FirstOrDefault(
x =>
x.IsCompatibleWithType(StreamTypes.ST_OUT_NET_RTMP_4_TS) ||
x.IsCompatibleWithType(StreamTypes.ST_OUT_NET_RTMP_4_RTMP));
if (pBaseInNetStream == null)
{
Logger.WARN("No live streams found: `{0}` or `{1}`", streamName, shortName);
return true;
}
//6. Create the outbound stream
var pBaseOutNetRTMPStream = pFrom.CreateONS(streamId, streamName, (pBaseInNetStream as InClusterStream)?.ContentStreamType ?? pBaseInNetStream.Type);
if (pBaseOutNetRTMPStream == null)
{
Logger.FATAL("Unable to create network outbound stream");
return false;
}
//7. Link them
if (!pBaseInNetStream.Link(pBaseOutNetRTMPStream))
{
Logger.FATAL("Link failed");
return false;
}
//8. Done
linked = true;
return true;
}