public new DialogResult ShowDialog(IWin32Window owner) { Text = "Preview " + _channel.DisplayName; TvServer server = new TvServer(); IUser user = new User("setuptv", false); TvResult result = server.StartTimeShifting(ref user, _channel.IdChannel, out _card); if (result != TvResult.Succeeded) { MessageBox.Show("Preview failed:" + result); Close(); return DialogResult.None; } Log.Info("preview {0} user:{1} {2} {3} {4}", _channel.DisplayName, user.CardId, user.SubChannel, user.Name, _card.TimeShiftFileName); _player = new Player(); _player.Play(_card.TimeShiftFileName, this); return base.ShowDialog(owner); }
/// <summary> /// Tunes to a new channel /// </summary> /// <param name="channel"></param> /// <returns></returns> public static bool ViewChannelAndCheck(Channel channel) { bool checkResult; bool doContinue; if (!Connected) { return false; } _status.Clear(); _doingChannelChange = false; try { checkResult = PreTuneChecks(channel, out doContinue); if (doContinue == false) return checkResult; _doingChannelChange = true; TvResult succeeded; IUser user = new User(); if (Card != null) { user.CardId = Card.Id; } if ((g_Player.Playing && g_Player.IsTimeShifting && !g_Player.Stopped) && (g_Player.IsTV || g_Player.IsRadio)) { _status.Set(LiveTvStatus.WasPlaying); } //Start timeshifting the new tv channel TvServer server = new TvServer(); VirtualCard card; int newCardId = -1; // check which card will be used newCardId = server.TimeShiftingWouldUseCard(ref user, channel.IdChannel); //Added by joboehl - If any major related to the timeshifting changed during the start, restart the player. if (newCardId != -1 && Card.Id != newCardId) { _status.Set(LiveTvStatus.CardChange); RegisterCiMenu(newCardId); } // we need to stop player HERE if card has changed. if (_status.AllSet(LiveTvStatus.WasPlaying | LiveTvStatus.CardChange)) { Log.Debug("TVHome.ViewChannelAndCheck(): Stopping player. CardId:{0}/{1}, RTSP:{2}", Card.Id, newCardId, Card.RTSPUrl); Log.Debug("TVHome.ViewChannelAndCheck(): Stopping player. Timeshifting:{0}", Card.TimeShiftFileName); Log.Debug("TVHome.ViewChannelAndCheck(): rebuilding graph (card changed) - timeshifting continueing."); } if (_status.IsSet(LiveTvStatus.WasPlaying)) { RenderBlackImage(); g_Player.PauseGraph(); } else { // if CI menu is not attached due to card change, do it if graph was not playing // (some handlers use polling threads that get stopped on graph stop) if (_status.IsNotSet(LiveTvStatus.CardChange)) RegisterCiMenu(newCardId); } // if card was not changed if (_status.IsNotSet(LiveTvStatus.CardChange)) { g_Player.OnZapping(0x80); // Setup Zapping for TsReader, requesting new PAT from stream } bool cardChanged = false; succeeded = server.StartTimeShifting(ref user, channel.IdChannel, out card, out cardChanged); if (_status.IsSet(LiveTvStatus.WasPlaying)) { if (card != null) g_Player.OnZapping((int)card.Type); else g_Player.OnZapping(-1); } if (succeeded != TvResult.Succeeded) { //timeshifting new channel failed. g_Player.Stop(); // ensure right channel name, even if not watchable:Navigator.Channel = channel; ChannelTuneFailedNotifyUser(succeeded, _status.IsSet(LiveTvStatus.WasPlaying), channel); _doingChannelChange = true; // keep fullscreen false; return true; // "success" } if (card != null && card.NrOfOtherUsersTimeshiftingOnCard > 0) { _status.Set(LiveTvStatus.SeekToEndAfterPlayback); } if (cardChanged) { _status.Set(LiveTvStatus.CardChange); if (card != null) { RegisterCiMenu(card.Id); } _status.Reset(LiveTvStatus.WasPlaying); } else { _status.Reset(LiveTvStatus.CardChange); _status.Set(LiveTvStatus.SeekToEnd); } // Update channel navigator if (Navigator.Channel != null && (channel.IdChannel != Navigator.Channel.IdChannel || (Navigator.LastViewedChannel == null))) { Navigator.LastViewedChannel = Navigator.Channel; } Log.Info("succeeded:{0} {1}", succeeded, card); Card = card; //Moved by joboehl - Only touch the card if starttimeshifting succeeded. // if needed seek to end if (_status.IsSet(LiveTvStatus.SeekToEnd)) { SeekToEnd(true); } // continue graph g_Player.ContinueGraph(); if (!g_Player.Playing || _status.IsSet(LiveTvStatus.CardChange) || (g_Player.Playing && !(g_Player.IsTV || g_Player.IsRadio))) { StartPlay(); // if needed seek to end if (_status.IsSet(LiveTvStatus.SeekToEndAfterPlayback)) { double dTime = g_Player.Duration - 5; g_Player.SeekAbsolute(dTime); } } _playbackStopped = false; _doingChannelChange = false; _ServerNotConnectedHandled = false; return true; } catch (Exception ex) { Log.Debug("TvPlugin:ViewChannelandCheckV2 Exception {0}", ex.ToString()); _doingChannelChange = false; Card.User.Name = new User().Name; g_Player.Stop(); Card.StopTimeShifting(); return false; } finally { StopRenderBlackImage(); _userChannelChanged = false; FireOnChannelChangedEvent(); Navigator.UpdateCurrentChannel(); } }
private void mpButtonTimeShift_Click(object sender, EventArgs e) { if (ServiceHelper.IsStopped) return; if (mpComboBoxChannels.SelectedItem == null) return; int id = ((ComboBoxExItem)mpComboBoxChannels.SelectedItem).Id; TvServer server = new TvServer(); VirtualCard card = GetCardTimeShiftingChannel(id); if (card != null) { card.StopTimeShifting(); mpButtonRec.Enabled = false; } else { string timeShiftingFilename = string.Empty; int cardId = -1; foreach (ListViewItem listViewItem in mpListView1.SelectedItems) { if (listViewItem.SubItems[2].Text != "disabled") { cardId = Convert.ToInt32(listViewItem.SubItems[0].Tag); break; // Keep the first card enabled selected only } } IUser user = new User(); user.Name = "setuptv-" + id + "-" + cardId; user.IsAdmin = true; user.CardId = cardId; TvResult result = server.StartTimeShifting(ref user, id, out card, cardId != -1); if (result != TvResult.Succeeded) { switch (result) { case TvResult.NoPmtFound: MessageBox.Show(this, "No PMT found"); break; case TvResult.NoSignalDetected: MessageBox.Show(this, "No signal"); break; case TvResult.CardIsDisabled: MessageBox.Show(this, "Card is not enabled"); break; case TvResult.AllCardsBusy: MessageBox.Show(this, "All cards are busy"); break; case TvResult.ChannelIsScrambled: MessageBox.Show(this, "Channel is scrambled"); break; case TvResult.NoVideoAudioDetected: MessageBox.Show(this, "No Video/Audio detected"); break; case TvResult.UnableToStartGraph: MessageBox.Show(this, "Unable to create/start graph"); break; case TvResult.ChannelNotMappedToAnyCard: MessageBox.Show(this, "Channel is not mapped to any card"); break; case TvResult.NoTuningDetails: MessageBox.Show(this, "No tuning information available for this channel"); break; case TvResult.UnknownChannel: MessageBox.Show(this, "Unknown channel"); break; case TvResult.UnknownError: MessageBox.Show(this, "Unknown error occured"); break; case TvResult.ConnectionToSlaveFailed: MessageBox.Show(this, "Cannot connect to slave server"); break; case TvResult.NotTheOwner: MessageBox.Show(this, "Failed since card is in use and we are not the owner"); break; case TvResult.GraphBuildingFailed: MessageBox.Show(this, "Unable to create graph"); break; case TvResult.SWEncoderMissing: MessageBox.Show(this, "No suppported software encoder installed"); break; case TvResult.NoFreeDiskSpace: MessageBox.Show(this, "No free disk space"); break; } } else { mpButtonRec.Enabled = true; } } }
private void ScanForUsableChannels() { _abortScanning = false; _isScanning = true; NotifyForm dlg = new NotifyForm("Testing all checked tv channels...", "Please be patient..."); dlg.Show(this); dlg.WaitForDisplay(); // Create tunning objects Server, User and Card TvServer _server = new TvServer(); IUser _user = new User(); VirtualCard _card; foreach (ListViewItem item in mpListView1.Items) { if (item.Checked == false) { continue; // do not test "un-checked" channels } Channel _channel = (Channel)item.Tag; // get channel dlg.SetMessage( string.Format("Please be patient...\n\nTesting channel {0} ( {1} of {2} )", _channel.DisplayName, item.Index + 1, mpListView1.Items.Count)); Application.DoEvents(); TvResult result = _server.StartTimeShifting(ref _user, _channel.IdChannel, out _card); if (result == TvResult.Succeeded) { _card.StopTimeShifting(); } else { item.Checked = false; _channel.VisibleInGuide = false; _channel.Persist(); } if (_abortScanning) { break; } } mpButtonTestAvailable.Text = "Test"; dlg.Close(); _isScanning = false; _abortScanning = false; }