private void Tuner_OnAfterCancelTuneEvent(int subchannelId) { try { if (_cardHandler.DataBaseCard.Enabled == false) { return; } Log.Debug("TimeShifterBase: tuning interrupted."); _cancelled = true; ITvSubChannel subchannel = GetSubChannel(subchannelId); if (subchannel is BaseSubChannel) { Log.Write("card {2}: Cancel Timeshifting sub:{1}", subchannel, _cardHandler.Card.Name); ((BaseSubChannel)subchannel).AudioVideoEvent -= AudioVideoEventHandler; _eventAudio.Set(); _eventVideo.Set(); _eventTimeshift.WaitOne(); } } catch (Exception ex) { Log.Write(ex); } finally { _cancelled = false; } }
/// <summary> /// Scans the specified channel. /// </summary> /// <param name="subChannelId">The sub channel id.</param> /// <param name="channel">The channel.</param> /// <returns>true if succeeded else false</returns> public override ITvSubChannel Scan(int subChannelId, IChannel channel) { Log.Log.WriteFile("atsc:Tune:{0} ", channel); try { if (!BeforeTune(channel)) { return(null); } ITvSubChannel ch = base.Scan(subChannelId, channel); return(ch); } catch (TvExceptionNoSignal) { throw; } catch (TvExceptionNoPMT) { throw; } catch (TvExceptionTuneCancelled) { throw; } catch (Exception ex) { Log.Log.Write(ex); throw; } }
private TvResult AfterTune(IUser user, int idChannel, ITvSubChannel result) { bool isLocked = _cardHandler.Card.IsTunerLocked; Log.Debug("card: Tuner locked: {0}", isLocked); Log.Info("**************************************************"); Log.Info("***** SIGNAL LEVEL: {0}, SIGNAL QUALITY: {1} *****", _cardHandler.Card.SignalLevel, _cardHandler.Card.SignalQuality); Log.Info("**************************************************"); ITvCardContext context = _cardHandler.Card.Context as ITvCardContext; if (result != null) { Log.Debug("card: tuned user: {0} subchannel: {1}", user.Name, result.SubChannelId); user.SubChannel = result.SubChannelId; user.IdChannel = idChannel; context.Add(user); } else { return(TvResult.AllCardsBusy); } if (result.IsTimeShifting || result.IsRecording) { context.OnZap(user); } return(TvResult.Succeeded); }
protected void DetachAudioVideoEventHandler(ITvSubChannel subchannel) { if (subchannel is BaseSubChannel) { ((BaseSubChannel)subchannel).AudioVideoEvent -= AudioVideoEventHandler; } }
/// <summary> /// Gets the current video stream. /// </summary> /// <returns></returns> public IVideoStream GetCurrentVideoStream(IUser user) { if (_dbsCard.Enabled == false) { return(null); } if (IsLocal == false) { try { RemoteControl.HostName = _dbsCard.ReferencedServer().HostName; return(RemoteControl.Instance.GetCurrentVideoStream(user)); } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _dbsCard.ReferencedServer().HostName); return(null); } } ITvCardContext context = _card.Context as ITvCardContext; if (context == null) { return(null); } context.GetUser(ref user); ITvSubChannel subchannel = _card.GetSubChannel(user.SubChannel); if (subchannel == null) { return(null); } return(subchannel.GetCurrentVideoStream); }
/// <summary> /// Tunes the specified channel. /// </summary> /// <param name="subChannelId">The sub channel id</param> /// <param name="channel">The channel.</param> /// <returns></returns> public override ITvSubChannel Tune(int subChannelId, IChannel channel) { Log.Log.WriteFile("dvbc: Tune:{0}", channel); try { if (!BeforeTune(channel, ref subChannelId)) { return(null); } ITvSubChannel ch = base.Tune(subChannelId, channel); return(ch); } catch (TvExceptionNoSignal) { throw; } catch (TvExceptionNoPMT) { throw; } catch (Exception ex) { Log.Log.Write(ex); throw; } }
/// <summary> /// Tunes the specified channel. /// </summary> /// <param name="subChannelId">The sub channel id</param> /// <param name="channel">The channel.</param> /// <returns></returns> public override ITvSubChannel Tune(int subChannelId, IChannel channel) { Log.Log.WriteFile("dvbt: Tune:{0}", channel); try { if (!BeforeTune(channel, ref subChannelId)) { return(null); } ITvSubChannel ch = base.Tune(subChannelId, channel); Log.Log.Info("dvbt: tune: Graph running. Returning {0}", ch.ToString()); return(ch); } catch (TvExceptionTuneCancelled) { throw; } catch (TvExceptionNoSignal) { throw; } catch (TvExceptionNoPMT) { throw; } catch (Exception ex) { Log.Log.Write(ex); throw; } }
/// <summary> /// Gets the teletext page. /// </summary> /// <param name="user">User</param> /// <param name="pageNumber">The page number.</param> /// <param name="subPageNumber">The sub page number.</param> /// <returns></returns> public byte[] GetTeletextPage(IUser user, int pageNumber, int subPageNumber) { try { if (_cardHandler.DataBaseCard.Enabled == false) { return new byte[] { 1 } } ; try { RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName; if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard)) { return new byte[] { 1 } } ; if (_cardHandler.IsLocal == false) { return(RemoteControl.Instance.GetTeletextPage(user, pageNumber, subPageNumber)); } } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _cardHandler.DataBaseCard.ReferencedServer().HostName); return(new byte[] { 1 }); } ITvCardContext context = _cardHandler.Card.Context as ITvCardContext; if (context == null) { return new byte[] { 1 } } ; context.GetUser(ref user); ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel); if (subchannel == null) { return new byte[] { 1 } } ; if (subchannel.TeletextDecoder == null) { return new byte[] { 1 } } ; return(subchannel.TeletextDecoder.GetRawPage(pageNumber, subPageNumber)); } catch (Exception ex) { Log.Write(ex); return(new byte[] { 1 }); } }
/// <summary> /// Gets the first sub channel. /// </summary> /// <returns></returns> public ITvSubChannel GetFirstSubChannel() { ITvSubChannel subChannel = null; if (_mapSubChannels.Count > 0) { subChannel = _mapSubChannels.FirstOrDefault().Value; } return(subChannel); }
/// <summary> /// Returns if the card is timeshifting or not /// </summary> /// <returns>true when card is timeshifting otherwise false</returns> public bool IsTimeShifting(ref IUser user) { try { if (_cardHandler.DataBaseCard.Enabled == false) { return(false); } try { RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName; if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard)) { return(false); } if (_cardHandler.IsLocal == false) { return(RemoteControl.Instance.IsTimeShifting(ref user)); } } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _cardHandler.DataBaseCard.ReferencedServer().HostName); return(false); } ITvCardContext context = _cardHandler.Card.Context as ITvCardContext; if (context == null) { return(false); } bool userExists; context.GetUser(ref user, out userExists); if (!userExists) { return(false); } ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel); if (subchannel == null) { return(false); } return(subchannel.IsTimeShifting); } catch (Exception ex) { Log.Write(ex); return(false); } }
/// <summary> /// Gets the current channel name. /// </summary> /// <param name="user">The user.</param> /// <returns>channel</returns> public string CurrentChannelName(ref IUser user) { try { if (_dbsCard.Enabled == false) { return(""); } if (IsLocal == false) { try { RemoteControl.HostName = _dbsCard.ReferencedServer().HostName; return(RemoteControl.Instance.CurrentChannelName(ref user)); } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _dbsCard.ReferencedServer().HostName); return(""); } } ITvCardContext context = _card.Context as ITvCardContext; if (context == null) { return(""); } context.GetUser(ref user); ITvSubChannel subchannel = _card.GetSubChannel(user.SubChannel); if (subchannel == null) { return(""); } if (subchannel.CurrentChannel == null) { return(""); } return(subchannel.CurrentChannel.Name); } catch (ThreadAbortException) { return(""); } catch (Exception ex) { Log.Write(ex); return(""); } }
/// <summary> /// Returns the position in the current timeshift file and the id of the current timeshift file /// </summary> /// <param name="user">The user.</param> /// <param name="position">The position in the current timeshift buffer file</param> /// <param name="bufferId">The id of the current timeshift buffer file</param> public bool GetCurrentFilePosition(ref IUser user, ref Int64 position, ref long bufferId) { try { if (_cardHandler.DataBaseCard.Enabled == false) { return(false); } try { RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName; if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard)) { return(false); } if (_cardHandler.IsLocal == false) { return(RemoteControl.Instance.TimeShiftGetCurrentFilePosition(ref user, ref position, ref bufferId)); } } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _cardHandler.DataBaseCard.ReferencedServer().HostName); return(false); } var context = _cardHandler.Card.Context as ITvCardContext; if (context == null) { return(false); } context.GetUser(ref user); ITvSubChannel subchannel = GetSubChannel(user.SubChannel); if (subchannel == null) { return(false); } subchannel.TimeShiftGetCurrentFilePosition(ref position, ref bufferId); return(position != -1); } catch (Exception ex) { Log.Write(ex); return(false); } }
/// <summary> /// Returns the current filename used for recording /// </summary> /// <param name="user">User</param> /// <returns>filename or null when not recording</returns> public string FileName(ref IUser user) { try { if (_cardHandler.DataBaseCard.Enabled == false) { return(""); } try { RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName; if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard)) { return(""); } if (_cardHandler.IsLocal == false) { return(RemoteControl.Instance.RecordingFileName(ref user)); } } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _cardHandler.DataBaseCard.ReferencedServer().HostName); return(""); } TvCardContext context = _cardHandler.Card.Context as TvCardContext; if (context == null) { return(null); } context.GetUser(ref user); ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel); if (subchannel == null) { return(null); } return(subchannel.RecordingFileName); } catch (Exception ex) { Log.Write(ex); return(""); } }
/// <summary> /// Sets the current audio stream. /// </summary> /// <param name="user">User</param> /// <param name="stream">The stream.</param> public void Set(IUser user, IAudioStream stream) { if (_cardHandler.DataBaseCard.Enabled == false) { return; } try { RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName; if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard)) { return; } Log.WriteFile("card: SetCurrentAudioStream: {0} - {1}", _cardHandler.DataBaseCard.IdCard, stream); if (_cardHandler.IsLocal == false) { Log.WriteFile("card: SetCurrentAudioStream: controlling remote instance {0}", RemoteControl.HostName); RemoteControl.Instance.SetCurrentAudioStream(user, stream); } } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _cardHandler.DataBaseCard.ReferencedServer().HostName); return; } ITvCardContext context = _cardHandler.Card.Context as ITvCardContext; if (context == null) { Log.WriteFile("card: SetCurrentAudioStream: TvCardContext == null"); return; } context.GetUser(ref user); ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel); if (subchannel == null) { Log.WriteFile("card: SetCurrentAudioStream: ITvSubChannel == null"); return; } subchannel.CurrentAudioStream = stream; }
/// <summary> /// returns the date/time when timeshifting has been started for the card specified /// </summary> /// <returns>DateTime containg the date/time when timeshifting was started</returns> public DateTime TimeShiftStarted(IUser user) { try { if (_cardHandler.DataBaseCard.Enabled == false) { return(DateTime.MinValue); } try { RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName; if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard)) { return(DateTime.MinValue); } if (_cardHandler.IsLocal == false) { return(RemoteControl.Instance.TimeShiftStarted(user)); } } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _cardHandler.DataBaseCard.ReferencedServer().HostName); return(DateTime.MinValue); } ITvCardContext context = _cardHandler.Card.Context as ITvCardContext; if (context == null) { return(DateTime.MinValue); } context.GetUser(ref user); ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel); if (subchannel == null) { return(DateTime.MinValue); } return(subchannel.StartOfTimeShift); } catch (Exception ex) { Log.Write(ex); return(DateTime.MinValue); } }
private void SetContextOwnerToNextRecUser(ITvCardContext context) { IUser[] users = context.Users; foreach (IUser t in users) { ITvSubChannel subchannel = GetSubChannel(t.SubChannel); if (subchannel != null) { if (subchannel.IsRecording) { Log.Write("card: StopRecording setting new context owner on user '{0}'", t.Name); context.Owner = t; break; } } } }
/// <summary> /// Returns the rotation time for a specific teletext page /// </summary> /// <param name="user">User</param> /// <param name="pageNumber">The pagenumber (0x100-0x899)</param> /// <returns>timespan containing the rotation time</returns> public TimeSpan TeletextRotation(IUser user, int pageNumber) { try { if (_cardHandler.DataBaseCard.Enabled == false) { return(new TimeSpan(0, 0, 0, 15)); } try { RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName; if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard)) { return(new TimeSpan(0, 0, 0, 15)); } if (_cardHandler.IsLocal == false) { return(RemoteControl.Instance.TeletextRotation(user, pageNumber)); } } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _cardHandler.DataBaseCard.ReferencedServer().HostName); return(new TimeSpan(0, 0, 0, 15)); } ITvCardContext context = _cardHandler.Card.Context as ITvCardContext; if (context == null) { return(new TimeSpan(0, 0, 0, 15)); } context.GetUser(ref user); ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel); if (subchannel == null) { return(new TimeSpan(0, 0, 0, 15)); } return(subchannel.TeletextDecoder.RotationTime(pageNumber)); } catch (Exception ex) { Log.Write(ex); return(new TimeSpan(0, 0, 0, 15)); } }
/// <summary> /// turn on/off teletext grabbing /// </summary> /// <param name="user">User</param> /// <param name="onOff">turn on/off teletext grabbing</param> public void GrabTeletext(IUser user, bool onOff) { try { if (_cardHandler.DataBaseCard.Enabled == false) { return; } try { RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName; if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard)) { return; } if (_cardHandler.IsLocal == false) { RemoteControl.Instance.GrabTeletext(user, onOff); } } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _cardHandler.DataBaseCard.ReferencedServer().HostName); return; } ITvCardContext context = _cardHandler.Card.Context as ITvCardContext; if (context == null) { return; } context.GetUser(ref user); ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel); if (subchannel == null) { return; } subchannel.GrabTeletext = onOff; } catch (Exception ex) { Log.Write(ex); return; } }
/// <summary> /// Gets the teletext pagenumber for the blue button /// </summary> /// <param name="user">The user.</param> /// <returns>Teletext pagenumber for the blue button</returns> public int GetTeletextBluePageNumber(IUser user) { try { if (_cardHandler.DataBaseCard.Enabled == false) { return(-1); } if (_cardHandler.IsLocal == false) { try { RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName; return(RemoteControl.Instance.GetTeletextBluePageNumber(user)); } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _cardHandler.DataBaseCard.ReferencedServer().HostName); return(-1); } } ITvCardContext context = _cardHandler.Card.Context as ITvCardContext; if (context == null) { return(-1); } context.GetUser(ref user); ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel); if (subchannel == null) { return(-1); } if (subchannel.TeletextDecoder == null) { return(-1); } return(subchannel.TeletextDecoder.PageBlue); } catch (Exception ex) { Log.Write(ex); return(-1); } }
/// <summary> /// Returns the current filename used for recording /// </summary> /// <param name="user">User</param> /// <returns>filename or null when not recording</returns> public string FileName(ref IUser user) { string recordingFileName = ""; try { ITvSubChannel subchannel = GetSubChannel(ref user); if (subchannel != null) { recordingFileName = subchannel.RecordingFileName; } } catch (Exception ex) { Log.Write(ex); } return(recordingFileName); }
/// <summary> /// returns the date/time when timeshifting has been started for the card specified /// </summary> /// <returns>DateTime containg the date/time when timeshifting was started</returns> public DateTime TimeShiftStarted(IUser user) { DateTime timeShiftStarted = DateTime.MinValue; try { ITvSubChannel subchannel = GetSubChannel(ref user); if (subchannel != null) { timeShiftStarted = subchannel.StartOfTimeShift; } } catch (Exception ex) { Log.Write(ex); } return(timeShiftStarted); }
/// <summary> /// returns the date/time when recording has been started for the card specified /// </summary> /// <param name="user">User</param> /// <returns>DateTime containg the date/time when recording was started</returns> public DateTime RecordingStarted(IUser user) { DateTime recordingStarted = DateTime.MinValue; try { ITvSubChannel subchannel = GetSubChannel(ref user); if (subchannel != null) { recordingStarted = subchannel.RecordingStarted; } } catch (Exception ex) { Log.Write(ex); } return(recordingStarted); }
/// <summary> /// Fetches the stream quality information /// </summary> /// <param name="user">user</param> /// <param name="totalTSpackets">Amount of packets processed</param> /// <param name="discontinuityCounter">Number of stream discontinuities</param> /// <returns></returns> public void GetStreamQualityCounters(IUser user, out int totalTSpackets, out int discontinuityCounter) { totalTSpackets = 0; discontinuityCounter = 0; ITvCardContext context = _cardHandler.Card.Context as ITvCardContext; bool userExists; context.GetUser(ref user, out userExists); ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel); TvDvbChannel dvbSubchannel = subchannel as TvDvbChannel; if (dvbSubchannel != null) { dvbSubchannel.GetStreamQualityCounters(out totalTSpackets, out discontinuityCounter); } }
protected ITvSubChannel GetSubChannel(ref IUser user) { ITvSubChannel subchannel = null; if (_cardHandler.DataBaseCard.Enabled) { var context = _cardHandler.Card.Context as TvCardContext; if (context != null) { bool userExists; context.GetUser(ref user, out userExists); if (userExists) { subchannel = GetSubChannel(user.SubChannel); } } } return(subchannel); }
/// <summary> /// Gets the current audio stream. /// </summary> /// <returns></returns> public IAudioStream GetCurrent(IUser user) { if (_cardHandler.DataBaseCard.Enabled == false) { return(null); } try { RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName; if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard)) { return(null); } if (_cardHandler.IsLocal == false) { return(RemoteControl.Instance.GetCurrentAudioStream(user)); } } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _cardHandler.DataBaseCard.ReferencedServer().HostName); return(null); } ITvCardContext context = _cardHandler.Card.Context as ITvCardContext; if (context == null) { return(null); } context.GetUser(ref user); ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel); if (subchannel == null) { return(null); } return(subchannel.CurrentAudioStream); }
/// <summary> /// Returns whether the channel to which the card is tuned is /// scrambled or not. /// </summary> /// <returns>yes if channel is scrambled and CI/CAM cannot decode it, otherwise false</returns> public bool IsScrambled(ref IUser user) { try { if (_dbsCard.Enabled == false) { return(true); } if (IsLocal == false) { try { RemoteControl.HostName = _dbsCard.ReferencedServer().HostName; return(RemoteControl.Instance.IsScrambled(ref user)); } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _dbsCard.ReferencedServer().HostName); return(false); } } ITvCardContext context = _card.Context as ITvCardContext; if (context == null) { return(false); } context.GetUser(ref user); ITvSubChannel subchannel = _card.GetSubChannel(user.SubChannel); if (subchannel == null) { return(false); } return(false == subchannel.IsReceivingAudioVideo); } catch (Exception ex) { Log.Write(ex); return(false); } }
private bool StopRecording(ref IUser user, TvCardContext context) { bool stop = false; context.GetUser(ref user); ITvSubChannel subchannel = GetSubChannel(user.SubChannel); if (subchannel != null) { subchannel.StopRecording(); _cardHandler.Card.FreeSubChannel(user.SubChannel); if (subchannel.IsTimeShifting == false || context.Users.Length <= 1) { _cardHandler.Users.RemoveUser(user); } stop = true; } else { Log.Write("card: StopRecording subchannel null, skipping"); } return(stop); }
/// <summary> /// Stops the time shifting. /// </summary> /// <returns></returns> public bool Stop(ref IUser user) { bool stop = false; try { if (_cardHandler.DataBaseCard.Enabled) { ITvSubChannel subchannel = GetSubChannel(user.SubChannel); DetachAudioVideoEventHandler(subchannel); Log.Write("card {2}: StopTimeShifting user:{0} sub:{1}", user.Name, user.SubChannel, _cardHandler.Card.Name); var context = _cardHandler.Card.Context as ITvCardContext; if (context != null) { ResetLinkageScanner(); if (_cardHandler.IsIdle) { _cardHandler.PauseCard(user); } else { Log.Debug("card not IDLE - removing user: {0}", user.Name); _cardHandler.Users.RemoveUser(user); } context.Remove(user); stop = true; } } } catch (Exception ex) { Log.Write(ex); } return(stop); }
/// <summary> /// Start timeshifting. /// </summary> /// <param name="user">User</param> /// <param name="fileName">Name of the timeshiftfile.</param> /// <returns>TvResult indicating whether method succeeded</returns> public TvResult Start(ref IUser user, ref string fileName) { TvResult result = TvResult.UnknownError; try { #if DEBUG if (File.Exists(@"\failts_" + _cardHandler.DataBaseCard.IdCard)) { throw new Exception("failed ts on purpose"); } #endif if (IsTuneCancelled()) { result = TvResult.TuneCancelled; return(result); } _eventTimeshift.Reset(); if (_cardHandler.DataBaseCard.Enabled) { // Let's verify if hard disk drive has enough free space before we start time shifting. The function automatically handles both local and UNC paths if (!IsTimeShifting(ref user) && !HasFreeDiskSpace(fileName)) { result = TvResult.NoFreeDiskSpace; } else { Log.Write("card: StartTimeShifting {0} {1} ", _cardHandler.DataBaseCard.IdCard, fileName); var context = _cardHandler.Card.Context as ITvCardContext; if (context != null) { context.GetUser(ref user); ITvSubChannel subchannel = GetSubChannel(user.SubChannel); if (subchannel != null) { _subchannel = subchannel; Log.Write("card: CAM enabled : {0}", _cardHandler.HasCA); AttachAudioVideoEventHandler(subchannel); if (subchannel.IsTimeShifting) { result = GetTvResultFromTimeshiftingSubchannel(ref user, context); } else { bool tsStarted = subchannel.StartTimeShifting(fileName); if (tsStarted) { fileName += ".tsbuffer"; result = GetTvResultFromTimeshiftingSubchannel(ref user, context); } else { result = TvResult.UnableToStartGraph; } } } } } } else { result = TvResult.CardIsDisabled; } } catch (Exception ex) { Log.Write(ex); result = TvResult.UnknownError; } finally { _eventTimeshift.Set(); _cancelled = false; if (result != TvResult.Succeeded) { Stop(ref user); } } return(result); }
/// <summary> /// Starts recording. /// </summary> /// <param name="user">User</param> /// <param name="fileName">Name of the recording file.</param> /// <param name="contentRecording">if true then create a content recording else a reference recording</param> /// <param name="startTime">not used</param> /// <returns></returns> public TvResult Start(ref IUser user, ref string fileName, bool contentRecording, long startTime) { bool useErrorDetection = false; try { if (_cardHandler.DataBaseCard.Enabled == false) { return TvResult.CardIsDisabled; } lock (this) { try { RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName; if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard)) return TvResult.CardIsDisabled; if (_cardHandler.IsLocal == false) { return RemoteControl.Instance.StartRecording(ref user, ref fileName, contentRecording, startTime); } } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _cardHandler.DataBaseCard.ReferencedServer().HostName); return TvResult.UnknownError; } TvCardContext context = _cardHandler.Card.Context as TvCardContext; if (context == null) return TvResult.UnknownChannel; context.GetUser(ref user); ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel); if (subchannel == null) return TvResult.UnknownChannel; _subchannel = subchannel; //gibman // RecordingFormat 0 = ts // RecordingFormat 1 = mpeg fileName = fileName.Replace("\r\n", " "); fileName = System.IO.Path.ChangeExtension(fileName, ".ts"); useErrorDetection = true; if (useErrorDetection) { // fix mantis 0002807: A/V detection for recordings is not working correctly // reset the events ONLY before attaching the observer, at a later position it can already miss the a/v callback. _eventVideo.Reset(); _eventAudio.Reset(); Log.Debug("Recorder.start add audioVideoEventHandler"); ((BaseSubChannel)subchannel).AudioVideoEvent += AudioVideoEventHandler; } Log.Write("card: StartRecording {0} {1}", _cardHandler.DataBaseCard.IdCard, fileName); bool result = subchannel.StartRecording(fileName); bool isScrambled; if (result) { fileName = subchannel.RecordingFileName; context.Owner = user; if (useErrorDetection) { if (!WaitForRecordingFile(ref user, out isScrambled)) { Log.Write("card: Recording failed! {0} {1}", _cardHandler.DataBaseCard.IdCard, fileName); string cardRecordingFolderName = _cardHandler.DataBaseCard.RecordingFolder; Stop(ref user); _cardHandler.Users.RemoveUser(user); string recordingfolderName = System.IO.Path.GetDirectoryName(fileName); if (recordingfolderName == cardRecordingFolderName) { Utils.FileDelete(fileName); } else { // delete 0-byte file in case of error Utils.DeleteFileAndEmptyDirectory(fileName); } ((BaseSubChannel)subchannel).AudioVideoEvent -= AudioVideoEventHandler; if (isScrambled) { return TvResult.ChannelIsScrambled; } return TvResult.NoVideoAudioDetected; } ((BaseSubChannel)subchannel).AudioVideoEvent -= AudioVideoEventHandler; } } if (_timeshiftingEpgGrabberEnabled) { Channel channel = Channel.Retrieve(user.IdChannel); if (channel.GrabEpg) _cardHandler.Card.GrabEpg(); else Log.Info("TimeshiftingEPG: channel {0} is not configured for grabbing epg", channel.DisplayName); } return TvResult.Succeeded; } } catch (Exception ex) { Log.Write(ex); } return TvResult.UnknownError; }
/// <summary> /// Start timeshifting. /// </summary> /// <param name="user">User</param> /// <param name="fileName">Name of the timeshiftfile.</param> /// <returns>TvResult indicating whether method succeeded</returns> public TvResult Start(ref IUser user, ref string fileName) { try { // Is the card enabled ? if (_cardHandler.DataBaseCard.Enabled == false) { return TvResult.CardIsDisabled; } lock (this) { try { RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName; if (!RemoteControl.Instance.CardPresent(_cardHandler.DataBaseCard.IdCard)) return TvResult.CardIsDisabled; // Let's verify if hard disk drive has enough free space before we start time shifting. The function automatically handles both local and UNC paths if (!IsTimeShifting(ref user)) { ulong FreeDiskSpace = Utils.GetFreeDiskSpace(fileName); TvBusinessLayer layer = new TvBusinessLayer(); UInt32 MaximumFileSize = UInt32.Parse(layer.GetSetting("timeshiftMaxFileSize", "256").Value); // in MB ulong DiskSpaceNeeded = Convert.ToUInt64(MaximumFileSize); DiskSpaceNeeded *= 1000000 * 2; // Convert to bytes; 2 times of timeshiftMaxFileSize if (FreeDiskSpace < DiskSpaceNeeded) // TimeShifter need at least this free disk space otherwise, it will not start. { Stop(ref user); return TvResult.NoFreeDiskSpace; } } Log.Write("card: StartTimeShifting {0} {1} ", _cardHandler.DataBaseCard.IdCard, fileName); if (_cardHandler.IsLocal == false) { return RemoteControl.Instance.StartTimeShifting(ref user, ref fileName); } } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _cardHandler.DataBaseCard.ReferencedServer().HostName); Stop(ref user); return TvResult.UnknownError; } ITvCardContext context = _cardHandler.Card.Context as ITvCardContext; if (context == null) { Stop(ref user); return TvResult.UnknownChannel; } context.GetUser(ref user); ITvSubChannel subchannel = _cardHandler.Card.GetSubChannel(user.SubChannel); if (subchannel == null) { Stop(ref user); return TvResult.UnknownChannel; } _subchannel = subchannel; Log.Write("card: CAM enabled : {0}", _cardHandler.HasCA); if (subchannel is TvDvbChannel) { if (!((TvDvbChannel)subchannel).PMTreceived) { Log.Info("start subch:{0} No PMT received. Timeshifting failed", subchannel.SubChannelId); Stop(ref user); return TvResult.UnableToStartGraph; } } if (subchannel is BaseSubChannel) { ((BaseSubChannel)subchannel).AudioVideoEvent += AudioVideoEventHandler; } bool isScrambled; if (subchannel.IsTimeShifting) { if (!WaitForTimeShiftFile(ref user, out isScrambled)) { Stop(ref user); if (isScrambled) { return TvResult.ChannelIsScrambled; } return TvResult.NoVideoAudioDetected; } context.OnZap(user); if (_linkageScannerEnabled) _cardHandler.Card.StartLinkageScanner(_linkageGrabber); if (_timeshiftingEpgGrabberEnabled) { Channel channel = Channel.Retrieve(user.IdChannel); if (channel.GrabEpg) _cardHandler.Card.GrabEpg(); else Log.Info("TimeshiftingEPG: channel {0} is not configured for grabbing epg", channel.DisplayName); } return TvResult.Succeeded; } bool result = subchannel.StartTimeShifting(fileName); if (result == false) { Stop(ref user); return TvResult.UnableToStartGraph; } fileName += ".tsbuffer"; if (!WaitForTimeShiftFile(ref user, out isScrambled)) { Stop(ref user); if (isScrambled) { return TvResult.ChannelIsScrambled; } return TvResult.NoVideoAudioDetected; } context.OnZap(user); if (_linkageScannerEnabled) _cardHandler.Card.StartLinkageScanner(_linkageGrabber); if (_timeshiftingEpgGrabberEnabled) { Channel channel = Channel.Retrieve(user.IdChannel); if (channel.GrabEpg) _cardHandler.Card.GrabEpg(); else Log.Info("TimeshiftingEPG: channel {0} is not configured for grabbing epg", channel.DisplayName); } return TvResult.Succeeded; } } catch (Exception ex) { Log.Write(ex); } Stop(ref user); return TvResult.UnknownError; }
private TvResult AfterTune(IUser user, int idChannel, ITvSubChannel result) { bool isLocked = _cardHandler.Card.IsTunerLocked; Log.Debug("card: Tuner locked: {0}", isLocked); Log.Info("**************************************************"); Log.Info("***** SIGNAL LEVEL: {0}, SIGNAL QUALITY: {1} *****", _cardHandler.Card.SignalLevel, _cardHandler.Card.SignalQuality); Log.Info("**************************************************"); ITvCardContext context = _cardHandler.Card.Context as ITvCardContext; if (result != null) { Log.Debug("card: tuned user: {0} subchannel: {1}", user.Name, result.SubChannelId); user.SubChannel = result.SubChannelId; user.IdChannel = idChannel; context.Add(user); } else { return TvResult.AllCardsBusy; } if (result.IsTimeShifting || result.IsRecording) { context.OnZap(user); } return TvResult.Succeeded; }
/// <summary> /// Removes the user from this card /// </summary> /// <param name="user">The user.</param> public void RemoveUser(IUser user) { if (_cardHandler.IsLocal == false) { try { RemoteControl.HostName = _cardHandler.DataBaseCard.ReferencedServer().HostName; RemoteControl.Instance.RemoveUserFromOtherCards(_cardHandler.DataBaseCard.IdCard, user); return; } catch (Exception) { Log.Error("card: unable to connect to slave controller at:{0}", _cardHandler.DataBaseCard.ReferencedServer().HostName); return; } } ITvCardContext context = _cardHandler.Card.Context as ITvCardContext; if (context == null) { return; } if (!context.DoesExists(user)) { return; } context.GetUser(ref user, _cardHandler.DataBaseCard.IdCard); Log.Debug("usermanagement.RemoveUser: {0}, subch: {1} of {2}, card: {3}", user.Name, user.SubChannel, _cardHandler.Card.SubChannels.Length, _cardHandler.DataBaseCard.IdCard); context.Remove(user); if (!context.ContainsUsersForSubchannel(user.SubChannel)) { //only remove subchannel if it exists. if (_cardHandler.Card.GetSubChannel(user.SubChannel) != null) { int usedSubChannel = user.SubChannel; // Before we remove the subchannel we have to stop it ITvSubChannel subChannel = _cardHandler.Card.GetSubChannel(user.SubChannel); if (subChannel.IsTimeShifting) { subChannel.StopTimeShifting(); } else if (subChannel.IsRecording) { subChannel.StopRecording(); } _cardHandler.Card.FreeSubChannel(user.SubChannel); CleanTimeshiftFilesThread cleanTimeshiftFilesThread = new CleanTimeshiftFilesThread(_cardHandler.DataBaseCard.TimeShiftFolder, String.Format("live{0}-{1}.ts", _cardHandler.DataBaseCard.IdCard, usedSubChannel)); Thread cleanupThread = new Thread(cleanTimeshiftFilesThread.CleanTimeshiftFiles); cleanupThread.IsBackground = true; cleanupThread.Name = "TS_File_Cleanup"; cleanupThread.Priority = ThreadPriority.Lowest; cleanupThread.Start(); } } if (_cardHandler.IsIdle) { if (_cardHandler.Card.SupportsPauseGraph) { _cardHandler.Card.PauseGraph(); } else { _cardHandler.Card.StopGraph(); } } }
private static bool IsPMTreceived(ITvSubChannel subchannel) { var tvDvbChannel = subchannel as TvDvbChannel; bool pmtReceived = (tvDvbChannel != null && tvDvbChannel.PMTreceived); return pmtReceived; }