private LiveStreamResult StartTimeShifting(Channel channel, TvDatabase.Card card, TvDatabase.Channel mpChannel,
ref IUser tve3User, ref LiveStream liveStream)
{
IChannel tuningChannel = Utility.FindTuningChannelOnCard(mpChannel, card.IdCard);
if (tuningChannel != null)
{
if (TvServerPlugin.TvController_Tune(ref tve3User, tuningChannel, mpChannel.IdChannel) == TvResult.Succeeded)
{
string timeshiftFileName = Path.Combine(card.TimeShiftFolder,
String.Format(CultureInfo.InvariantCulture, @"live{0}-{1}", tve3User.CardId, tve3User.SubChannel));
switch (TvServerPlugin.TvController_StartTimeShifting(ref tve3User, ref timeshiftFileName))
{
case TvResult.Succeeded:
if (liveStream == null)
{
string rtspUrl = TvServerPlugin.TvController_GetStreamingUrl(tve3User);
string tsBufferFile = GetTsBufferFile(tve3User);
liveStream = new LiveStream(channel, rtspUrl);
liveStream.TimeshiftFile = tsBufferFile;
#if USE_ARGUS_RTSP
string rtspUrlSuffix = String.Format(_rtspUrlSuffixFormat, tve3User.CardId, tve3User.SubChannel);
liveStream.RtspUrl = StartRtspStream(tsBufferFile, rtspUrlSuffix);
#endif
}
liveStream.Channel = channel;
liveStream.CardId = tve3User.CardId.ToString(CultureInfo.InvariantCulture);
liveStream.StreamLastAliveTimeUtc = DateTime.UtcNow;
lock (_liveStreamsLock)
{
_liveStreams[liveStream.RtspUrl] = liveStream;
_liveStreamUsers[liveStream.RtspUrl] = tve3User;
}
return(LiveStreamResult.Succeeded);
case TvResult.AllCardsBusy:
return(LiveStreamResult.NoFreeCardFound);
case TvResult.ChannelIsScrambled:
return(LiveStreamResult.IsScrambled);
case TvResult.ChannelNotMappedToAnyCard:
case TvResult.NoSignalDetected:
case TvResult.NoTuningDetails:
case TvResult.NoVideoAudioDetected:
case TvResult.UnknownChannel:
return(LiveStreamResult.ChannelTuneFailed);
default:
return(LiveStreamResult.UnknownError);
}
}
else
{
Log(TraceEventType.Error, "StartTimeShifting(): failed to tune to {0}", tuningChannel.Name);
return(LiveStreamResult.ChannelTuneFailed);
}
}
else
{
Log(TraceEventType.Error, "StartTimeShifting(): no tuning channel found for {0}", mpChannel.DisplayName);
return(LiveStreamResult.ChannelTuneFailed);
}
}