Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Transponder"/> class.
 /// </summary>
 /// <param name="detail">The detail.</param>
 public Transponder(TuningDetail detail)
 {
     _channels            = new List <Channel>();
     _detail              = detail;
     _currentChannelIndex = -1;
     _inUse = false;
 }
 private void menuButtonEdit_Click(object sender, EventArgs e)
 {
     if (mpListView1.SelectedIndices.Count == 1)
     {
         int                    index = mpListView1.SelectedIndices[0];
         TuningDetail           tuningDetailToEdit = _tuningDetails[index];
         FormTuningDetailCommon form = CreateDialog(tuningDetailToEdit.ChannelType);
         form.TuningDetail = tuningDetailToEdit;
         form.ShowDialog(this);
         UpdateTuningDetailList();
     }
 }
Exemplo n.º 3
0
        private static string GetPlayPath(Channel channel)
        {
            IList <TuningDetail> details = channel.ReferringTuningDetail();
            TuningDetail         detail  = details[0];

            if (channel.IsWebstream())
            {
                return(detail.Url);
            }
            {
                string fileName = String.Format("{0}.radio", detail.Frequency);
                return(fileName);
            }
        }
Exemplo n.º 4
0
        public static bool IsUserOnSameChannel(IChannel tuningDetail, TvBusinessLayer layer, DVBBaseChannel userDVBchannel)
        {
            bool isUserOnSameChannel = false;

            if (userDVBchannel != null)
            {
                var currentDVBchannel = tuningDetail as DVBBaseChannel;
                if (currentDVBchannel != null)
                {
                    TuningDetail currentDVBtuningDetail = layer.GetTuningDetail(currentDVBchannel);
                    TuningDetail userDVBtuningDetail    = layer.GetTuningDetail(userDVBchannel);
                    isUserOnSameChannel = (currentDVBtuningDetail != null && currentDVBtuningDetail.IdChannel == userDVBtuningDetail.IdChannel);
                }
            }
            return(isUserOnSameChannel);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructor
        /// </summary>
        public NowPlayingRadio()
        {
            TvPlugin.TVHome.Navigator.UpdateCurrentChannel();
            TvDatabase.Channel current = TvPlugin.Radio.CurrentChannel;

            if (current != null && current.IsWebstream())
            {
                if (current.ReferringTuningDetail() != null && current.ReferringTuningDetail().Count > 0)
                {
                    IList <TuningDetail> details = current.ReferringTuningDetail();
                    TuningDetail         detail  = details[0];
                    CurrentProgramName = detail.Name;
                    CurrentProgramId   = detail.IdChannel;
                    CurrentUrl         = detail.Url;
                    ChannelName        = GUIPropertyManager.GetProperty("#Play.Current.Album");
                    ArtistName         = GUIPropertyManager.GetProperty("#Play.Current.Artist");
                }
            }
            else if (current != null && !current.IsWebstream())
            {
                ChannelId   = current.IdChannel;
                ChannelName = current.DisplayName;
                ArtistName  = GUIPropertyManager.GetProperty("#Play.Current.Artist");

                if (current.CurrentProgram != null)
                {
                    CurrentProgramId          = current.CurrentProgram.IdProgram;
                    CurrentProgramName        = current.CurrentProgram.Title;
                    CurrentProgramDescription = current.CurrentProgram.Description;
                    CurrentProgramBegin       = current.CurrentProgram.StartTime;
                    CurrentProgramEnd         = current.CurrentProgram.EndTime;
                }

                if (current.NextProgram != null)
                {
                    NextProgramId          = current.NextProgram.IdProgram;
                    NextProgramName        = current.NextProgram.Title;
                    NextProgramDescription = current.NextProgram.Description;
                    NextProgramBegin       = current.NextProgram.StartTime;
                    NextProgramEnd         = current.NextProgram.EndTime;
                }
            }
        }
        private void menuButtonRemove_Click(object sender, EventArgs e)
        {
            if (mpListView1.SelectedIndices.Count > 0)
            {
                if (
                    MessageBox.Show(this, "Are you sure you want to delete the selected tuningdetails?", "",
                                    MessageBoxButtons.YesNo) ==
                    DialogResult.Yes)
                {
                    for (int i = 0; i < mpListView1.SelectedIndices.Count; i++)
                    {
                        int index = mpListView1.SelectedIndices[i];

                        TuningDetail tuningDetailToDelete = _tuningDetails[index];
                        _tuningDetailsToDelete.Add(tuningDetailToDelete);
                        _tuningDetails.Remove(tuningDetailToDelete);
                    }
                    UpdateTuningDetailList();
                }
            }
        }
        private IDictionary <int, IList <IChannel> > GetTuningChannels()
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            Dictionary <int, IList <IChannel> > result = new Dictionary <int, IList <IChannel> >();
            IList <TuningDetail> tuningDetails         = TuningDetail.ListAll();

            foreach (TuningDetail tuningDetail in tuningDetails)
            {
                IList <IChannel> tuningChannels;
                result.TryGetValue(tuningDetail.IdChannel, out tuningChannels);
                if (tuningChannels == null)
                {
                    tuningChannels = new List <IChannel>();
                    result.Add(tuningDetail.IdChannel, tuningChannels);
                }
                tuningChannels.Add(_businessLayer.GetTuningChannel(tuningDetail));
            }
            stopwatch.Stop();
            Log.Info("ChannelStates.GetTuningChannels took {0} msec", stopwatch.ElapsedMilliseconds);
            return(result);
        }
Exemplo n.º 8
0
        private void DoScan()
        {
            int tvChannelsNew        = 0;
            int radioChannelsNew     = 0;
            int tvChannelsUpdated    = 0;
            int radioChannelsUpdated = 0;

            IUser user = new User();

            user.CardId = _cardNumber;
            try
            {
                // First lock the card, because so that other parts of a hybrid card can't be used at the same time
                RemoteControl.Instance.EpgGrabberEnabled = false;

                TvBusinessLayer layer = new TvBusinessLayer();
                Card            card  = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));

                int index = -1;
                IEnumerator <PlayListItem> enumerator = playlist.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    string url  = enumerator.Current.FileName.Substring(enumerator.Current.FileName.LastIndexOf('\\') + 1);
                    string name = enumerator.Current.Description;

                    DVBIPChannel tuneChannel = new DVBIPChannel();
                    tuneChannel.Url  = url;
                    tuneChannel.Name = name;
                    string line = String.Format("{0}- {1} - {2}", 1 + index, tuneChannel.Name, tuneChannel.Url);
                    Log.Debug(line);

                    RemoteControl.Instance.Tune(ref user, tuneChannel, -1);
                    IChannel[] channels;
                    channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);

                    if (channels == null || channels.Length == 0)
                    {
                        if (RemoteControl.Instance.TunerLocked(_cardNumber) == false)
                        {
                            line = String.Format("{0}- {1} - {2} :No Signal", 1 + index, tuneChannel.Url, tuneChannel.Name);
                            Log.Debug(line);
                            continue;
                        }
                        else
                        {
                            line = String.Format("{0}- {1} - {2} :Nothing found", 1 + index, tuneChannel.Url, tuneChannel.Name);
                            Log.Debug(line);
                            continue;
                        }
                    }

                    int newChannels     = 0;
                    int updatedChannels = 0;

                    for (int i = 0; i < channels.Length; ++i)
                    {
                        Channel      dbChannel;
                        DVBIPChannel channel = (DVBIPChannel)channels[i];
                        if (channels.Length > 1)
                        {
                            if (channel.Name.IndexOf("Unknown") == 0)
                            {
                                channel.Name = name + (i + 1);
                            }
                        }
                        else
                        {
                            channel.Name = name;
                        }
                        bool         exists;
                        TuningDetail currentDetail;
                        //Check if we already have this tuningdetail. According to DVB-IP specifications there are two ways to identify DVB-IP
                        //services: one ONID + SID based, the other domain/URL based. At this time we don't fully and properly implement the DVB-IP
                        //specifications, so the safest method for service identification is the URL. The user has the option to enable the use of
                        //ONID + SID identification and channel move detection...
                        if (true)
                        {
                            currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.ServiceId,
                                                                  TvBusinessLayer.GetChannelType(channel));
                        }
                        else
                        {
                            currentDetail = layer.GetTuningDetail(channel.Url, TvBusinessLayer.GetChannelType(channel));
                        }

                        if (currentDetail == null)
                        {
                            //add new channel
                            exists              = false;
                            dbChannel           = layer.AddNewChannel(channel.Name, channel.LogicalChannelNumber);
                            dbChannel.SortOrder = 10000;
                            if (channel.LogicalChannelNumber >= 1)
                            {
                                dbChannel.SortOrder = channel.LogicalChannelNumber;
                            }
                            dbChannel.IsTv    = channel.IsTv;
                            dbChannel.IsRadio = channel.IsRadio;
                            dbChannel.Persist();
                        }
                        else
                        {
                            exists    = true;
                            dbChannel = currentDetail.ReferencedChannel();
                        }

                        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);

                        if (_defaultTVGroup != "")
                        {
                            layer.AddChannelToGroup(dbChannel, _defaultTVGroup);
                        }
                        if (currentDetail == null)
                        {
                            layer.AddTuningDetails(dbChannel, channel);
                        }
                        else
                        {
                            //update tuning details...
                            TuningDetail td = layer.UpdateTuningDetails(dbChannel, channel, currentDetail);
                            td.Persist();
                        }

                        if (channel.IsTv)
                        {
                            if (exists)
                            {
                                tvChannelsUpdated++;
                                updatedChannels++;
                            }
                            else
                            {
                                tvChannelsNew++;
                                newChannels++;
                            }
                        }
                        if (channel.IsRadio)
                        {
                            if (exists)
                            {
                                radioChannelsUpdated++;
                                updatedChannels++;
                            }
                            else
                            {
                                radioChannelsNew++;
                                newChannels++;
                            }
                        }
                        layer.MapChannelToCard(card, dbChannel, false);
                        line = String.Format("{0}- {1} :New:{2} Updated:{3}", 1 + index, tuneChannel.Name, newChannels,
                                             updatedChannels);
                        Log.Debug(line);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            finally
            {
                RemoteControl.Instance.StopCard(user);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Scan Thread
        /// </summary>
        private void DoScan()
        {
            suminfo tv    = new suminfo();
            suminfo radio = new suminfo();
            IUser   user  = new User();

            user.CardId = _cardNumber;
            try
            {
                scanState = ScanState.Scanning;
                if (_dvbcChannels.Count == 0)
                {
                    return;
                }

                RemoteControl.Instance.EpgGrabberEnabled = false;

                SetButtonState();
                TvBusinessLayer layer = new TvBusinessLayer();
                Card            card  = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));

                for (int index = 0; index < _dvbcChannels.Count; ++index)
                {
                    if (scanState == ScanState.Cancel)
                    {
                        return;
                    }

                    float percent = ((float)(index)) / _dvbcChannels.Count;
                    percent *= 100f;
                    if (percent > 100f)
                    {
                        percent = 100f;
                    }
                    progressBar1.Value = (int)percent;

                    Application.DoEvents();

                    DVBCChannel  tuneChannel = new DVBCChannel(_dvbcChannels[index]); // new DVBCChannel();
                    string       line        = String.Format("{0}tp- {1}", 1 + index, tuneChannel.TuningInfo.ToString());
                    ListViewItem item        = listViewStatus.Items.Add(new ListViewItem(line));
                    item.EnsureVisible();

                    if (index == 0)
                    {
                        RemoteControl.Instance.Scan(ref user, tuneChannel, -1);
                    }

                    IChannel[] channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);
                    UpdateStatus();

                    if (channels == null || channels.Length == 0)
                    {
                        if (RemoteControl.Instance.TunerLocked(_cardNumber) == false)
                        {
                            line = String.Format("{0}tp- {1} {2} {3}:No signal", 1 + index, tuneChannel.Frequency,
                                                 tuneChannel.ModulationType, tuneChannel.SymbolRate);
                            item.Text      = line;
                            item.ForeColor = Color.Red;
                            continue;
                        }
                        line = String.Format("{0}tp- {1} {2} {3}:Nothing found", 1 + index, tuneChannel.Frequency,
                                             tuneChannel.ModulationType, tuneChannel.SymbolRate);
                        item.Text      = line;
                        item.ForeColor = Color.Red;
                        continue;
                    }

                    radio.newChannel = 0;
                    radio.updChannel = 0;
                    tv.newChannel    = 0;
                    tv.updChannel    = 0;
                    for (int i = 0; i < channels.Length; ++i)
                    {
                        Channel      dbChannel;
                        DVBCChannel  channel = (DVBCChannel)channels[i];
                        bool         exists;
                        TuningDetail currentDetail;
                        //Check if we already have this tuningdetail. The user has the option to enable channel move detection...
                        if (checkBoxEnableChannelMoveDetection.Checked)
                        {
                            //According to the DVB specs ONID + SID is unique, therefore we do not need to use the TSID to identify a service.
                            //The DVB spec recommends that the SID should not change if a service moves. This theoretically allows us to
                            //track channel movements.
                            currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.ServiceId,
                                                                  TvBusinessLayer.GetChannelType(channel));
                        }
                        else
                        {
                            //There are certain providers that do not maintain unique ONID + SID combinations.
                            //In those cases, ONID + TSID + SID is generally unique. The consequence of using the TSID to identify
                            //a service is that channel movement tracking won't work (each transponder/mux should have its own TSID).
                            currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.TransportId, channel.ServiceId,
                                                                  TvBusinessLayer.GetChannelType(channel));
                        }

                        if (currentDetail == null)
                        {
                            //add new channel
                            exists              = false;
                            dbChannel           = layer.AddNewChannel(channel.Name, channel.LogicalChannelNumber);
                            dbChannel.SortOrder = 10000;
                            if (channel.LogicalChannelNumber >= 1)
                            {
                                dbChannel.SortOrder = channel.LogicalChannelNumber;
                            }
                            dbChannel.IsTv    = channel.IsTv;
                            dbChannel.IsRadio = channel.IsRadio;
                            dbChannel.Persist();
                        }
                        else
                        {
                            exists    = true;
                            dbChannel = currentDetail.ReferencedChannel();
                        }

                        if (dbChannel.IsTv)
                        {
                            layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
                            if (checkBoxCreateSignalGroup.Checked)
                            {
                                layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.DVBC);
                            }
                            if (checkBoxCreateGroups.Checked)
                            {
                                layer.AddChannelToGroup(dbChannel, channel.Provider);
                            }
                        }
                        if (dbChannel.IsRadio)
                        {
                            layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.AllChannels);
                            if (checkBoxCreateSignalGroup.Checked)
                            {
                                layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.DVBC);
                            }
                            if (checkBoxCreateGroups.Checked)
                            {
                                layer.AddChannelToRadioGroup(dbChannel, channel.Provider);
                            }
                        }

                        if (currentDetail == null)
                        {
                            layer.AddTuningDetails(dbChannel, channel);
                        }
                        else
                        {
                            //update tuning details...
                            TuningDetail td = layer.UpdateTuningDetails(dbChannel, channel, currentDetail);
                            td.Persist();
                        }

                        if (channel.IsTv)
                        {
                            if (exists)
                            {
                                tv.updChannel++;
                            }
                            else
                            {
                                tv.newChannel++;
                                tv.newChannels.Add(channel);
                            }
                        }
                        if (channel.IsRadio)
                        {
                            if (exists)
                            {
                                radio.updChannel++;
                            }
                            else
                            {
                                radio.newChannel++;
                                radio.newChannels.Add(channel);
                            }
                        }
                        layer.MapChannelToCard(card, dbChannel, false);
                        line = String.Format("{0}tp- {1} {2} {3}:New TV/Radio:{4}/{5} Updated TV/Radio:{6}/{7}", 1 + index,
                                             tuneChannel.Frequency, tuneChannel.ModulationType, tuneChannel.SymbolRate,
                                             tv.newChannel, radio.newChannel, tv.updChannel, radio.updChannel);
                        item.Text = line;
                    }
                    tv.updChannelSum    += tv.updChannel;
                    radio.updChannelSum += radio.updChannel;
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            finally
            {
                RemoteControl.Instance.StopCard(user);
                RemoteControl.Instance.EpgGrabberEnabled = true;
                progressBar1.Value = 100;

                scanState = ScanState.Done;
                SetButtonState();
            }
            listViewStatus.Items.Add(
                new ListViewItem(String.Format("Total radio channels updated:{0}, new:{1}", radio.updChannelSum,
                                               radio.newChannelSum)));
            foreach (IChannel newChannel in radio.newChannels)
            {
                listViewStatus.Items.Add(new ListViewItem(String.Format("  -> new channel: {0}", newChannel.Name)));
            }

            listViewStatus.Items.Add(
                new ListViewItem(String.Format("Total tv channels updated:{0}, new:{1}", tv.updChannelSum, tv.newChannelSum)));
            foreach (IChannel newChannel in tv.newChannels)
            {
                listViewStatus.Items.Add(new ListViewItem(String.Format("  -> new channel: {0}", newChannel.Name)));
            }
            ListViewItem lastItem = listViewStatus.Items.Add(new ListViewItem("Scan done..."));

            lastItem.EnsureVisible();
        }
        protected override void OnPageLoad()
        {
            base.OnPageLoad();
            GUIPropertyManager.SetProperty("#TV.TuningDetails.ChannelName", TVHome.Card.ChannelName);
            GUIPropertyManager.SetProperty("#TV.TuningDetails.RTSPURL", TVHome.Card.RTSPUrl);
            Channel chan = TVHome.Navigator.Channel;

            if (chan != null)
            {
                try
                {
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.HasCiMenuSupport", TVHome.Card.CiMenuSupported().ToString());
                }
                catch (System.Exception ex)
                {
                    Log.Error("Error loading TuningDetails /  HasCiMenuSupport:" + ex.StackTrace);
                }

                IList <TuningDetail> details = chan.ReferringTuningDetail();
                if (details.Count > 0)
                {
                    TuningDetail detail = null;
                    switch (TVHome.Card.Type)
                    {
                    case TvLibrary.Interfaces.CardType.Analog:
                        foreach (TuningDetail t in details)
                        {
                            if (t.ChannelType == 0)
                            {
                                detail = t;
                            }
                        }
                        break;

                    case TvLibrary.Interfaces.CardType.Atsc:
                        foreach (TuningDetail t in details)
                        {
                            if (t.ChannelType == 1)
                            {
                                detail = t;
                            }
                        }
                        break;

                    case TvLibrary.Interfaces.CardType.DvbC:
                        foreach (TuningDetail t in details)
                        {
                            if (t.ChannelType == 2)
                            {
                                detail = t;
                            }
                        }
                        break;

                    case TvLibrary.Interfaces.CardType.DvbS:
                        foreach (TuningDetail t in details)
                        {
                            if (t.ChannelType == 3)
                            {
                                detail = t;
                            }
                        }
                        break;

                    case TvLibrary.Interfaces.CardType.DvbT:
                        foreach (TuningDetail t in details)
                        {
                            if (t.ChannelType == 4)
                            {
                                detail = t;
                            }
                        }
                        break;

                    default:
                        detail = details[0];
                        break;
                    }
                    if (detail != null)
                    {
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.Band", detail.Band.ToString());
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.BandWidth", detail.Bandwidth.ToString());
                        switch (detail.ChannelType)
                        {
                        case 0:
                            GUIPropertyManager.SetProperty("#TV.TuningDetails.ChannelType", "Analog");
                            break;

                        case 1:
                            GUIPropertyManager.SetProperty("#TV.TuningDetails.ChannelType", "Atsc");
                            break;

                        case 2:
                            GUIPropertyManager.SetProperty("#TV.TuningDetails.ChannelType", "DVB-C");
                            break;

                        case 3:
                            GUIPropertyManager.SetProperty("#TV.TuningDetails.ChannelType", "DVB-S");
                            break;

                        case 4:
                            GUIPropertyManager.SetProperty("#TV.TuningDetails.ChannelType", "DVB-T");
                            break;
                        }

                        IUser          user         = TVHome.Card.User;
                        IVideoStream   videoStream  = TVHome.Card.GetCurrentVideoStream((User)user);
                        IAudioStream[] audioStreams = TVHome.Card.AvailableAudioStreams;
                        MediaPortal.Player.VideoStreamFormat videoFormat = MediaPortal.Player.g_Player.GetVideoFormat();

                        String audioPids = String.Empty;
                        String videoPid  = String.Empty;

                        audioPids = audioStreams.Aggregate(audioPids, (current, stream) => current + (stream.Pid + " (" + stream.StreamType + ") "));

                        if (videoStream != null)
                        {
                            videoPid = videoStream.Pid.ToString() + " (" + videoStream.StreamType + ")";
                        }

                        GUIPropertyManager.SetProperty("#Play.Current.TSBitRate",
                                                       ((float)MediaPortal.Player.g_Player.GetVideoFormat().bitrate / 1024 / 1024).ToString("0.00", CultureInfo.InvariantCulture));

                        GUIPropertyManager.SetProperty("#Play.Current.VideoFormat.RawResolution",
                                                       videoFormat.width.ToString() + "x" + videoFormat.height.ToString());

                        GUIPropertyManager.SetProperty("#TV.TuningDetails.CountryId", detail.CountryId.ToString());
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.FreeToAir", detail.FreeToAir.ToString());
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.Frequency", detail.Frequency.ToString());
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.InnerFecRate", detail.InnerFecRate.ToString());
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.Modulation", detail.Modulation.ToString());
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.NetworkId", detail.NetworkId.ToString());
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.PmtPid", detail.PmtPid.ToString());
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.Polarisation", detail.Polarisation.ToString());
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.Provider", detail.Provider);
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.ServiceId", detail.ServiceId.ToString());
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.SymbolRate", detail.Symbolrate.ToString());
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.TransportId", detail.TransportId.ToString());
                        if (videoStream != null)
                        {
                            GUIPropertyManager.SetProperty("#TV.TuningDetails.PcrPid", videoStream.PcrPid.ToString());
                        }
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.VideoPid", videoPid);
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.AudioPid", audioPids);
                    }
                }
            }
        }
Exemplo n.º 11
0
        private void DoScan()
        {
            int tvChannelsNew        = 0;
            int radioChannelsNew     = 0;
            int tvChannelsUpdated    = 0;
            int radioChannelsUpdated = 0;

            string buttonText = mpButtonScanTv.Text;
            IUser  user       = new User();

            user.CardId = _cardNumber;
            try
            {
                // First lock the card, because so that other parts of a hybrid card can't be used at the same time
                _isScanning         = true;
                _stopScanning       = false;
                mpButtonScanTv.Text = "Cancel...";
                RemoteControl.Instance.EpgGrabberEnabled = false;
                listViewStatus.Items.Clear();

                PlayList playlist = new PlayList();
                if (mpComboBoxService.SelectedIndex == 0)
                {
                    //TODO read SAP announcements
                }
                else
                {
                    IPlayListIO playlistIO =
                        PlayListFactory.CreateIO(String.Format(@"{0}\TuningParameters\dvbip\{1}.m3u", PathManager.GetDataPath,
                                                               mpComboBoxService.SelectedItem));
                    playlistIO.Load(playlist,
                                    String.Format(@"{0}\TuningParameters\dvbip\{1}.m3u", PathManager.GetDataPath,
                                                  mpComboBoxService.SelectedItem));
                }
                if (playlist.Count == 0)
                {
                    return;
                }

                mpComboBoxService.Enabled    = false;
                checkBoxCreateGroups.Enabled = false;
                checkBoxEnableChannelMoveDetection.Enabled = false;
                TvBusinessLayer layer = new TvBusinessLayer();
                Card            card  = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));

                int index = -1;
                IEnumerator <PlayListItem> enumerator = playlist.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    if (_stopScanning)
                    {
                        return;
                    }
                    index++;
                    float percent = ((float)(index)) / playlist.Count;
                    percent *= 100f;
                    if (percent > 100f)
                    {
                        percent = 100f;
                    }
                    progressBar1.Value = (int)percent;

                    string url  = enumerator.Current.FileName.Substring(enumerator.Current.FileName.LastIndexOf('\\') + 1);
                    string name = enumerator.Current.Description;

                    DVBIPChannel tuneChannel = new DVBIPChannel();
                    tuneChannel.Url  = url;
                    tuneChannel.Name = name;
                    string       line = String.Format("{0}- {1} - {2}", 1 + index, tuneChannel.Name, tuneChannel.Url);
                    ListViewItem item = listViewStatus.Items.Add(new ListViewItem(line));
                    item.EnsureVisible();
                    RemoteControl.Instance.Tune(ref user, tuneChannel, -1);
                    IChannel[] channels;
                    channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);
                    UpdateStatus();
                    if (channels == null || channels.Length == 0)
                    {
                        if (RemoteControl.Instance.TunerLocked(_cardNumber) == false)
                        {
                            line           = String.Format("{0}- {1} :No Signal", 1 + index, tuneChannel.Url);
                            item.Text      = line;
                            item.ForeColor = Color.Red;
                            continue;
                        }
                        else
                        {
                            line           = String.Format("{0}- {1} :Nothing found", 1 + index, tuneChannel.Url);
                            item.Text      = line;
                            item.ForeColor = Color.Red;
                            continue;
                        }
                    }

                    int newChannels     = 0;
                    int updatedChannels = 0;

                    for (int i = 0; i < channels.Length; ++i)
                    {
                        Channel      dbChannel;
                        DVBIPChannel channel = (DVBIPChannel)channels[i];
                        if (channels.Length > 1)
                        {
                            if (channel.Name.IndexOf("Unknown") == 0)
                            {
                                channel.Name = name + (i + 1);
                            }
                        }
                        else
                        {
                            channel.Name = name;
                        }
                        bool         exists;
                        TuningDetail currentDetail;
                        //Check if we already have this tuningdetail. According to DVB-IP specifications there are two ways to identify DVB-IP
                        //services: one ONID + SID based, the other domain/URL based. At this time we don't fully and properly implement the DVB-IP
                        //specifications, so the safest method for service identification is the URL. The user has the option to enable the use of
                        //ONID + SID identification and channel move detection...
                        if (checkBoxEnableChannelMoveDetection.Checked)
                        {
                            currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.ServiceId,
                                                                  TvBusinessLayer.GetChannelType(channel));
                        }
                        else
                        {
                            currentDetail = layer.GetTuningDetail(channel.Url, TvBusinessLayer.GetChannelType(channel));
                        }

                        if (currentDetail == null)
                        {
                            //add new channel
                            exists              = false;
                            dbChannel           = layer.AddNewChannel(channel.Name, channel.LogicalChannelNumber);
                            dbChannel.SortOrder = 10000;
                            if (channel.LogicalChannelNumber >= 1)
                            {
                                dbChannel.SortOrder = channel.LogicalChannelNumber;
                            }
                            dbChannel.IsTv    = channel.IsTv;
                            dbChannel.IsRadio = channel.IsRadio;
                            dbChannel.Persist();
                        }
                        else
                        {
                            exists    = true;
                            dbChannel = currentDetail.ReferencedChannel();
                        }

                        layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);

                        if (checkBoxCreateGroups.Checked)
                        {
                            layer.AddChannelToGroup(dbChannel, channel.Provider);
                        }
                        if (currentDetail == null)
                        {
                            layer.AddTuningDetails(dbChannel, channel);
                        }
                        else
                        {
                            //update tuning details...
                            TuningDetail td = layer.UpdateTuningDetails(dbChannel, channel, currentDetail);
                            td.Persist();
                        }

                        if (channel.IsTv)
                        {
                            if (exists)
                            {
                                tvChannelsUpdated++;
                                updatedChannels++;
                            }
                            else
                            {
                                tvChannelsNew++;
                                newChannels++;
                            }
                        }
                        if (channel.IsRadio)
                        {
                            if (exists)
                            {
                                radioChannelsUpdated++;
                                updatedChannels++;
                            }
                            else
                            {
                                radioChannelsNew++;
                                newChannels++;
                            }
                        }
                        layer.MapChannelToCard(card, dbChannel, false);
                        line = String.Format("{0}- {1} :New:{2} Updated:{3}", 1 + index, tuneChannel.Name, newChannels,
                                             updatedChannels);
                        item.Text = line;
                    }
                }
                //DatabaseManager.Instance.SaveChanges();
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            finally
            {
                RemoteControl.Instance.StopCard(user);
                RemoteControl.Instance.EpgGrabberEnabled = true;
                progressBar1.Value           = 100;
                mpComboBoxService.Enabled    = true;
                checkBoxCreateGroups.Enabled = true;
                checkBoxEnableChannelMoveDetection.Enabled = true;
                mpButtonScanTv.Text = buttonText;
                _isScanning         = false;
            }
            ListViewItem lastItem = listViewStatus.Items.Add(new ListViewItem("Scan done..."));

            lastItem =
                listViewStatus.Items.Add(
                    new ListViewItem(String.Format("Total radio channels new:{0} updated:{1}", radioChannelsNew,
                                                   radioChannelsUpdated)));
            lastItem =
                listViewStatus.Items.Add(
                    new ListViewItem(String.Format("Total tv channels new:{0} updated:{1}", tvChannelsNew, tvChannelsUpdated)));
            lastItem.EnsureVisible();
        }
Exemplo n.º 12
0
        /// <summary>
        /// Play a radio channel
        /// </summary>
        /// <param name="channelId">Id of the channel</param>
        public static void PlayRadioChannel(int channelId)
        {
            if (GUIGraphicsContext.form.InvokeRequired)
            {
                PlayRadioChannelDelegate d = PlayRadioChannel;
                GUIGraphicsContext.form.Invoke(d, channelId);
                return;
            }

            WifiRemote.LogMessage("Start radio channel " + channelId, WifiRemote.LogType.Debug);
            TvDatabase.Channel channel = TvDatabase.Channel.Retrieve(channelId);

            if (channel != null)
            {
                if (GUIWindowManager.ActiveWindow != (int)MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_RADIO)
                {
                    WifiRemote.LogMessage("Radio Window not active, activating it", WifiRemote.LogType.Debug);
                    MediaPortal.GUI.Library.GUIWindowManager.ActivateWindow((int)MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_RADIO);
                }

                GUIPropertyManager.RemovePlayerProperties();
                GUIPropertyManager.SetProperty("#Play.Current.ArtistThumb", channel.DisplayName);
                GUIPropertyManager.SetProperty("#Play.Current.Album", channel.DisplayName);
                GUIPropertyManager.SetProperty("#Play.Current.Title", channel.DisplayName);

                GUIPropertyManager.SetProperty("#Play.Current.Title", channel.DisplayName);
                string strLogo = Utils.GetCoverArt(Thumbs.Radio, channel.DisplayName);
                if (string.IsNullOrEmpty(strLogo))
                {
                    strLogo = "defaultMyRadioBig.png";
                }
                GUIPropertyManager.SetProperty("#Play.Current.Thumb", strLogo);

                if (g_Player.Playing && !channel.IsWebstream())
                {
                    if (!g_Player.IsTimeShifting || (g_Player.IsTimeShifting && channel.IsWebstream()))
                    {
                        WifiRemote.LogMessage("Stopping current media so we can start playing radio", WifiRemote.LogType.Debug);
                        g_Player.Stop();
                    }
                }
                bool success = false;
                if (channel.IsWebstream())
                {
                    IList <TuningDetail> details = channel.ReferringTuningDetail();
                    TuningDetail         detail  = details[0];
                    WifiRemote.LogMessage("Play webStream:" + detail.Name + ", url:" + detail.Url, WifiRemote.LogType.Debug);
                    success = g_Player.PlayAudioStream(detail.Url);
                    GUIPropertyManager.SetProperty("#Play.Current.Title", channel.DisplayName);
                }
                else
                {
                    // TV card radio channel
                    WifiRemote.LogMessage("Play TV card radio channel", WifiRemote.LogType.Debug);
                    //Check if same channel is alrady playing
                    if (g_Player.IsRadio && g_Player.Playing)
                    {
                        Channel currentlyPlaying = TvPlugin.TVHome.Navigator.Channel;
                        if (currentlyPlaying != null && currentlyPlaying.IdChannel == channel.IdChannel)
                        {
                            WifiRemote.LogMessage("Already playing TV card radio channel with id:" + channel.IdChannel + ", do not tune again", WifiRemote.LogType.Debug);
                        }
                        else
                        {
                            success = TvPlugin.TVHome.ViewChannelAndCheck(channel);
                        }
                    }
                    else
                    {
                        success = TvPlugin.TVHome.ViewChannelAndCheck(channel);
                    }
                }
                WifiRemote.LogMessage("Started radio channel " + channelId + " Success: " + success, WifiRemote.LogType.Debug);
            }
            else
            {
                Log.Warn("Couldn't retrieve radio channel for id: " + channelId);
            }
        }
Exemplo n.º 13
0
        protected override void OnPageLoad()
        {
            base.OnPageLoad();
            GUIPropertyManager.SetProperty("#TV.TuningDetails.ChannelName", TVHome.Card.ChannelName);
            GUIPropertyManager.SetProperty("#TV.TuningDetails.RTSPURL", TVHome.Card.RTSPUrl);
            Channel chan = TVHome.Navigator.Channel;

            if (chan != null)
            {
                try
                {
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.HasCiMenuSupport", TVHome.Card.CiMenuSupported().ToString());
                }
                catch (System.Exception ex)
                {
                    Log.Error("Error loading TuningDetails /  HasCiMenuSupport:" + ex.StackTrace);
                }

                IList <TuningDetail> details = chan.ReferringTuningDetail();
                if (details.Count > 0)
                {
                    TuningDetail detail = null;
                    switch (TVHome.Card.Type)
                    {
                    case TvLibrary.Interfaces.CardType.Analog:
                        foreach (TuningDetail t in details)
                        {
                            if (t.ChannelType == 0)
                            {
                                detail = t;
                            }
                        }
                        break;

                    case TvLibrary.Interfaces.CardType.Atsc:
                        foreach (TuningDetail t in details)
                        {
                            if (t.ChannelType == 1)
                            {
                                detail = t;
                            }
                        }
                        break;

                    case TvLibrary.Interfaces.CardType.DvbC:
                        foreach (TuningDetail t in details)
                        {
                            if (t.ChannelType == 2)
                            {
                                detail = t;
                            }
                        }
                        break;

                    case TvLibrary.Interfaces.CardType.DvbS:
                        foreach (TuningDetail t in details)
                        {
                            if (t.ChannelType == 3)
                            {
                                detail = t;
                            }
                        }
                        break;

                    case TvLibrary.Interfaces.CardType.DvbT:
                        foreach (TuningDetail t in details)
                        {
                            if (t.ChannelType == 4)
                            {
                                detail = t;
                            }
                        }
                        break;

                    default:
                        detail = details[0];
                        break;
                    }
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.Band", detail.Band.ToString());
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.BandWidth", detail.Bandwidth.ToString());
                    switch (detail.ChannelType)
                    {
                    case 0:
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.ChannelType", "Analog");
                        break;

                    case 1:
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.ChannelType", "Atsc");
                        break;

                    case 2:
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.ChannelType", "DVB-C");
                        break;

                    case 3:
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.ChannelType", "DVB-S");
                        break;

                    case 4:
                        GUIPropertyManager.SetProperty("#TV.TuningDetails.ChannelType", "DVB-T");
                        break;
                    }

                    IUser          user         = TVHome.Card.User;
                    IVideoStream   videoStream  = TVHome.Card.GetCurrentVideoStream((User)user);
                    IAudioStream[] audioStreams = TVHome.Card.AvailableAudioStreams;

                    String audioPids = String.Empty;
                    String videoPid  = String.Empty;

                    foreach (IAudioStream stream in audioStreams)
                    {
                        audioPids += stream.Pid + " (" + stream.StreamType + ") ";
                    }

                    videoPid = videoStream.Pid.ToString() + " (" + videoStream.StreamType + ")";

                    GUIPropertyManager.SetProperty("#TV.TuningDetails.CountryId", detail.CountryId.ToString());
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.FreeToAir", detail.FreeToAir.ToString());
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.Frequency", detail.Frequency.ToString());
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.InnerFecRate", detail.InnerFecRate.ToString());
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.Modulation", detail.Modulation.ToString());
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.NetworkId", detail.NetworkId.ToString());
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.PmtPid", detail.PmtPid.ToString());
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.Polarisation", detail.Polarisation.ToString());
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.Provider", detail.Provider);
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.ServiceId", detail.ServiceId.ToString());
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.SymbolRate", detail.Symbolrate.ToString());
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.TransportId", detail.TransportId.ToString());
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.PcrPid", videoStream.PcrPid.ToString());
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.VideoPid", videoPid);
                    GUIPropertyManager.SetProperty("#TV.TuningDetails.AudioPid", audioPids);
                }
            }
        }
Exemplo n.º 14
0
        public int Compare(GUIListItem item1, GUIListItem item2)
        {
            if (item1 == item2)
            {
                return(0);
            }
            if (item1 == null)
            {
                return(-1);
            }
            if (item2 == null)
            {
                return(-1);
            }
            if (item1.IsFolder && item1.Label == "..")
            {
                return(-1);
            }
            if (item2.IsFolder && item2.Label == "..")
            {
                return(1);
            }
            if (item1.IsFolder && !item2.IsFolder)
            {
                return(-1);
            }
            if (!item1.IsFolder && item2.IsFolder)
            {
                return(1);
            }


            SortMethod method     = currentSortMethod;
            bool       bAscending = m_bSortAscending;
            Channel    channel1   = item1.MusicTag as Channel;
            Channel    channel2   = item2.MusicTag as Channel;

            switch (method)
            {
            case SortMethod.Name:
                if (bAscending)
                {
                    return(String.Compare(item1.Label, item2.Label, true));
                }
                return(String.Compare(item2.Label, item1.Label, true));

            case SortMethod.Type:
                string strURL1 = "0";
                string strURL2 = "0";
                if (item1.IconImage.ToLower().Equals("defaultmyradiostream.png"))
                {
                    strURL1 = "1";
                }
                if (item2.IconImage.ToLower().Equals("defaultmyradiostream.png"))
                {
                    strURL2 = "1";
                }
                if (strURL1.Equals(strURL2))
                {
                    if (bAscending)
                    {
                        return(String.Compare(item1.Label, item2.Label, true));
                    }
                    return(String.Compare(item2.Label, item1.Label, true));
                }
                if (bAscending)
                {
                    if (strURL1.Length > 0)
                    {
                        return(1);
                    }
                    return(-1);
                }
                if (strURL1.Length > 0)
                {
                    return(-1);
                }
                return(1);

            //break;

            case SortMethod.Number:
                if (channel1 != null && channel2 != null)
                {
                    RadioGroupMap channel1GroupMap  = (RadioGroupMap)item1.AlbumInfoTag;
                    RadioGroupMap channel2GroupMap  = (RadioGroupMap)item2.AlbumInfoTag;
                    int           channel1GroupSort = channel1GroupMap.SortOrder;
                    int           channel2GroupSort = channel2GroupMap.SortOrder;
                    if (bAscending)
                    {
                        if (channel1GroupSort > channel2GroupSort)
                        {
                            return(1);
                        }
                        return(-1);
                    }
                    if (channel2GroupSort > channel1GroupSort)
                    {
                        return(1);
                    }
                    return(-1);
                }

                if (channel1 != null)
                {
                    return(-1);
                }
                return(channel2 != null ? 1 : 0);

            //break;
            case SortMethod.Bitrate:
                IList <TuningDetail> details1 = channel1.ReferringTuningDetail();
                TuningDetail         detail1  = details1[0];
                IList <TuningDetail> details2 = channel2.ReferringTuningDetail();
                TuningDetail         detail2  = details2[0];
                if (detail1 != null && detail2 != null)
                {
                    if (bAscending)
                    {
                        if (detail1.Bitrate > detail2.Bitrate)
                        {
                            return(1);
                        }
                        return(-1);
                    }
                    if (detail2.Bitrate > detail1.Bitrate)
                    {
                        return(1);
                    }
                    return(-1);
                }
                return(0);
            }
            return(0);
        }
Exemplo n.º 15
0
        private void DoScan()
        {
            int    tvChannelsNew        = 0;
            int    radioChannelsNew     = 0;
            int    tvChannelsUpdated    = 0;
            int    radioChannelsUpdated = 0;
            string buttonText           = mpButtonScanTv.Text;

            try
            {
                _isScanning         = true;
                _stopScanning       = false;
                mpButtonScanTv.Text = "Cancel...";
                RemoteControl.Instance.EpgGrabberEnabled = false;
                if (_atscChannels.Count == 0)
                {
                    return;
                }
                mpComboBoxFrequencies.Enabled = false;
                listViewStatus.Items.Clear();
                TvBusinessLayer layer = new TvBusinessLayer();
                Card            card  = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
                IUser           user  = new User();
                user.CardId = _cardNumber;
                int minchan = 2;
                int maxchan = 69 + 1;
                if ((string)mpComboBoxTuningMode.SelectedItem == "Clear QAM Cable")
                {
                    minchan = 1;
                    maxchan = _atscChannels.Count + 1;
                }
                else if ((string)mpComboBoxTuningMode.SelectedItem == "Digital Cable")
                {
                    minchan = 0;
                    maxchan = 1;
                }
                for (int index = minchan; index < maxchan; ++index)
                {
                    if (_stopScanning)
                    {
                        return;
                    }
                    float percent = ((float)(index)) / (maxchan - minchan);
                    percent *= 100f;
                    if (percent > 100f)
                    {
                        percent = 100f;
                    }
                    progressBar1.Value = (int)percent;
                    ATSCChannel tuneChannel = new ATSCChannel();
                    tuneChannel.NetworkId    = -1;
                    tuneChannel.TransportId  = -1;
                    tuneChannel.ServiceId    = -1;
                    tuneChannel.MinorChannel = -1;
                    tuneChannel.MajorChannel = -1;
                    string line;
                    if ((string)mpComboBoxTuningMode.SelectedItem == "Clear QAM Cable")
                    {
                        tuneChannel.PhysicalChannel = index;
                        tuneChannel.Frequency       = _atscChannels[index - 1].frequency;
                        if (tuneChannel.Frequency < 10000)
                        {
                            continue;
                        }
                        tuneChannel.ModulationType = ModulationType.Mod256Qam;
                        line = string.Format("physical channel = {0}, frequency = {1} kHz, modulation = 256 QAM", tuneChannel.PhysicalChannel, tuneChannel.Frequency);
                        Log.Info("ATSC: scanning clear QAM cable, {0}, frequency plan = {1}", line, mpComboBoxFrequencies.SelectedItem);
                    }
                    else if ((string)mpComboBoxTuningMode.SelectedItem == "ATSC Digital Terrestrial")
                    {
                        tuneChannel.PhysicalChannel = index;
                        tuneChannel.Frequency       = -1;
                        tuneChannel.ModulationType  = ModulationType.Mod8Vsb;
                        line = string.Format("physical channel = {0}, modulation = 8 VSB", tuneChannel.PhysicalChannel);
                        Log.Info("ATSC: scanning ATSC over-the-air, {0}", line);
                    }
                    else
                    {
                        tuneChannel.PhysicalChannel = 0;
                        tuneChannel.ModulationType  = ModulationType.Mod256Qam;
                        line = "out-of-band service information";
                        Log.Info("ATSC: scanning digital cable, {0}", line);
                    }
                    line += "... ";
                    ListViewItem item = listViewStatus.Items.Add(new ListViewItem(line));
                    item.EnsureVisible();
                    if (index == minchan)
                    {
                        RemoteControl.Instance.Scan(ref user, tuneChannel, -1);
                    }
                    IChannel[] channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);
                    UpdateStatus();
                    if (channels == null || channels.Length == 0)
                    {
                        if (tuneChannel.PhysicalChannel > 0 && !RemoteControl.Instance.TunerLocked(_cardNumber))
                        {
                            line += "no signal";
                        }
                        else
                        {
                            line += "signal locked, no channels found";
                        }
                        item.Text      = line;
                        item.ForeColor = Color.Red;
                        continue;
                    }
                    int newChannels     = 0;
                    int updatedChannels = 0;
                    for (int i = 0; i < channels.Length; ++i)
                    {
                        Channel     dbChannel;
                        ATSCChannel channel = (ATSCChannel)channels[i];
                        //No support for channel moving, or merging with existing channels here.
                        //We do not know how ATSC works to correctly implement this.
                        TuningDetail currentDetail = layer.GetTuningDetail(channel);
                        if (currentDetail != null)
                        {
                            if (channel.IsDifferentTransponder(layer.GetTuningChannel(currentDetail)))
                            {
                                currentDetail = null;
                            }
                        }
                        bool exists;
                        if (currentDetail == null)
                        {
                            //add new channel
                            exists              = false;
                            dbChannel           = layer.AddNewChannel(channel.Name, channel.LogicalChannelNumber);
                            dbChannel.SortOrder = 10000;
                            if (channel.LogicalChannelNumber >= 1)
                            {
                                dbChannel.SortOrder = channel.LogicalChannelNumber;
                            }
                        }
                        else
                        {
                            exists    = true;
                            dbChannel = currentDetail.ReferencedChannel();
                        }
                        dbChannel.IsTv    = channel.IsTv;
                        dbChannel.IsRadio = channel.IsRadio;
                        dbChannel.Persist();
                        if (dbChannel.IsTv)
                        {
                            layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
                        }
                        if (dbChannel.IsRadio)
                        {
                            layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.AllChannels);
                        }
                        if (currentDetail == null)
                        {
                            layer.AddTuningDetails(dbChannel, channel);
                        }
                        else
                        {
                            //update tuning details...
                            TuningDetail td = layer.UpdateTuningDetails(dbChannel, channel, currentDetail);
                            td.Persist();
                        }
                        if (channel.IsTv)
                        {
                            if (exists)
                            {
                                tvChannelsUpdated++;
                                updatedChannels++;
                            }
                            else
                            {
                                tvChannelsNew++;
                                newChannels++;
                            }
                        }
                        if (channel.IsRadio)
                        {
                            if (exists)
                            {
                                radioChannelsUpdated++;
                                updatedChannels++;
                            }
                            else
                            {
                                radioChannelsNew++;
                                newChannels++;
                            }
                        }
                        layer.MapChannelToCard(card, dbChannel, false);
                    }
                    line     += string.Format("new = {0}, updated = {1}", newChannels, updatedChannels);
                    item.Text = line;
                    Log.Info("ATSC: scan result, new = {0}, updated = {1}", newChannels, updatedChannels);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            finally
            {
                IUser user = new User();
                user.CardId = _cardNumber;
                RemoteControl.Instance.StopCard(user);
                RemoteControl.Instance.EpgGrabberEnabled = true;
                progressBar1.Value           = 100;
                mpComboBoxTuningMode.Enabled = true;
                UpdateQamFrequencyFieldAvailability();
                mpButtonScanTv.Text = buttonText;
                _isScanning         = false;
            }
            listViewStatus.Items.Add(
                new ListViewItem(String.Format("Total radio channels, new = {0}, updated = {1}", radioChannelsNew,
                                               radioChannelsUpdated)));
            listViewStatus.Items.Add(
                new ListViewItem(String.Format("Total TV channels, new = {0} updated = {1}", tvChannelsNew, tvChannelsUpdated)));
            ListViewItem lastItem = listViewStatus.Items.Add(new ListViewItem("Scan done!"));

            lastItem.EnsureVisible();
            Log.Info("ATSC: scan summary, new TV = {0}, updated TV = {1}, new radio = {2}, updated radio = {3}", tvChannelsNew, tvChannelsUpdated, radioChannelsNew, radioChannelsUpdated);
        }
Exemplo n.º 16
0
        private void DoScan()
        {
            int    tvChannelsNew        = 0;
            int    radioChannelsNew     = 0;
            int    tvChannelsUpdated    = 0;
            int    radioChannelsUpdated = 0;
            string buttonText           = mpButtonScanTv.Text;

            try
            {
                _isScanning         = true;
                _stopScanning       = false;
                mpButtonScanTv.Text = "Cancel...";
                RemoteControl.Instance.EpgGrabberEnabled = false;
                if (_atscChannels.Count == 0)
                {
                    return;
                }
                mpComboBoxFrequencies.Enabled = false;
                listViewStatus.Items.Clear();
                TvBusinessLayer layer = new TvBusinessLayer();
                Card            card  = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));
                IUser           user  = new User();
                user.CardId = _cardNumber;
                int minchan = 2;
                int maxchan = 69;
                //Check if QAM if so then the number of channels varies
                if (checkBoxQAM.Checked)
                {
                    minchan = 0;
                    maxchan = _atscChannels.Count;
                }
                for (int index = minchan; index < maxchan; ++index)
                {
                    if (_stopScanning)
                    {
                        return;
                    }
                    float percent = ((float)(index)) / (maxchan - minchan);
                    percent *= 100f;
                    if (percent > 100f)
                    {
                        percent = 100f;
                    }
                    progressBar1.Value = (int)percent;
                    ATSCChannel tuneChannel = new ATSCChannel();
                    tuneChannel.NetworkId    = -1;
                    tuneChannel.TransportId  = -1;
                    tuneChannel.ServiceId    = -1;
                    tuneChannel.MinorChannel = -1;
                    tuneChannel.MajorChannel = -1;
                    if (checkBoxQAM.Checked)
                    {
                        Log.WriteFile("ATSC tune: QAM checkbox selected... using Modulation 256Qam");
                        tuneChannel.PhysicalChannel = index + 1;
                        tuneChannel.Frequency       = _atscChannels[index].frequency;
                        tuneChannel.ModulationType  = ModulationType.Mod256Qam;
                    }
                    else
                    {
                        Log.WriteFile("ATSC tune: QAM checkbox not selected... using Modulation 8Vsb");
                        tuneChannel.PhysicalChannel = index;
                        tuneChannel.Frequency       = -1;
                        tuneChannel.ModulationType  = ModulationType.Mod8Vsb;
                    }
                    Log.WriteFile("ATSC tune: PhysicalChannel: {0} Frequency: {1} Modulation: {2}", tuneChannel.PhysicalChannel,
                                  tuneChannel.Frequency, tuneChannel.ModulationType);
                    string line = String.Format("physical channel:{0} frequency:{1} modulation:{2}", tuneChannel.PhysicalChannel,
                                                tuneChannel.Frequency, tuneChannel.ModulationType);
                    ListViewItem item = listViewStatus.Items.Add(new ListViewItem(line));
                    item.EnsureVisible();
                    if (index == minchan)
                    {
                        RemoteControl.Instance.Scan(ref user, tuneChannel, -1);
                    }
                    IChannel[] channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);
                    UpdateStatus();

                    /*if (channels == null || channels.Length == 0)
                     * {
                     * if (checkBoxQAM.Checked)
                     * {
                     *  //try Modulation 64Qam now
                     *  tuneChannel.PhysicalChannel = index + 1;
                     *  tuneChannel.Frequency = _atscChannels[index].frequency;
                     *  tuneChannel.ModulationType = ModulationType.Mod64Qam;
                     *  line = String.Format("physical channel:{0} frequency:{1} modulation:{2}: No signal", tuneChannel.PhysicalChannel, tuneChannel.Frequency, tuneChannel.ModulationType);
                     *  item.Text = line;
                     *  channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);
                     * }
                     * }*/
                    UpdateStatus();
                    if (channels == null || channels.Length == 0)
                    {
                        if (RemoteControl.Instance.TunerLocked(_cardNumber) == false)
                        {
                            line = String.Format("physical channel:{0} frequency:{1} modulation:{2}: No signal",
                                                 tuneChannel.PhysicalChannel, tuneChannel.Frequency, tuneChannel.ModulationType);
                            item.Text      = line;
                            item.ForeColor = Color.Red;
                            continue;
                        }
                        line = String.Format("physical channel:{0} frequency:{1} modulation:{2}: Nothing found",
                                             tuneChannel.PhysicalChannel, tuneChannel.Frequency, tuneChannel.ModulationType);
                        item.Text      = line;
                        item.ForeColor = Color.Red;
                        continue;
                    }
                    int newChannels     = 0;
                    int updatedChannels = 0;
                    for (int i = 0; i < channels.Length; ++i)
                    {
                        Channel     dbChannel;
                        ATSCChannel channel = (ATSCChannel)channels[i];
                        //No support for channel moving, or merging with existing channels here.
                        //We do not know how ATSC works to correctly implement this.
                        TuningDetail currentDetail = layer.GetTuningDetail(channel);
                        if (currentDetail != null)
                        {
                            if (channel.Frequency != currentDetail.Frequency)
                            {
                                currentDetail = null;
                            }
                        }
                        bool exists;
                        if (currentDetail == null)
                        {
                            //add new channel
                            exists              = false;
                            dbChannel           = layer.AddNewChannel(channel.Name);
                            dbChannel.SortOrder = 10000;
                            if (channel.LogicalChannelNumber >= 1)
                            {
                                dbChannel.SortOrder = channel.LogicalChannelNumber;
                            }
                        }
                        else
                        {
                            exists    = true;
                            dbChannel = currentDetail.ReferencedChannel();
                        }
                        dbChannel.IsTv    = channel.IsTv;
                        dbChannel.IsRadio = channel.IsRadio;
                        dbChannel.Persist();
                        if (dbChannel.IsTv)
                        {
                            layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);
                        }
                        if (dbChannel.IsRadio)
                        {
                            layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.AllChannels);
                        }
                        if (currentDetail == null)
                        {
                            layer.AddTuningDetails(dbChannel, channel);
                        }
                        else
                        {
                            //update tuning details...
                            TuningDetail td = layer.UpdateTuningDetails(dbChannel, channel, currentDetail);
                            td.Persist();
                        }
                        if (channel.IsTv)
                        {
                            if (exists)
                            {
                                tvChannelsUpdated++;
                                updatedChannels++;
                            }
                            else
                            {
                                tvChannelsNew++;
                                newChannels++;
                            }
                        }
                        if (channel.IsRadio)
                        {
                            if (exists)
                            {
                                radioChannelsUpdated++;
                                updatedChannels++;
                            }
                            else
                            {
                                radioChannelsNew++;
                                newChannels++;
                            }
                        }
                        layer.MapChannelToCard(card, dbChannel, false);
                        line = String.Format("physical channel:{0} frequency:{1} modulation:{2} New:{3} Updated:{4}",
                                             tuneChannel.PhysicalChannel, tuneChannel.Frequency, tuneChannel.ModulationType,
                                             newChannels, updatedChannels);
                        item.Text = line;
                    }
                }
                //DatabaseManager.Instance.SaveChanges();
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            finally
            {
                IUser user = new User();
                user.CardId = _cardNumber;
                RemoteControl.Instance.StopCard(user);
                RemoteControl.Instance.EpgGrabberEnabled = true;
                progressBar1.Value            = 100;
                checkBoxQAM.Enabled           = true;
                mpComboBoxFrequencies.Enabled = true;
                mpButtonScanTv.Text           = buttonText;
                _isScanning = false;
            }
            listViewStatus.Items.Add(
                new ListViewItem(String.Format("Total radio channels new:{0} updated:{1}", radioChannelsNew,
                                               radioChannelsUpdated)));
            listViewStatus.Items.Add(
                new ListViewItem(String.Format("Total tv channels new:{0} updated:{1}", tvChannelsNew, tvChannelsUpdated)));
            ListViewItem lastItem = listViewStatus.Items.Add(new ListViewItem("Scan done..."));

            lastItem.EnsureVisible();
        }
Exemplo n.º 17
0
        private void DoScan()
        {
            suminfo tv    = new suminfo();
            suminfo radio = new suminfo();
            IUser   user  = new User();

            user.CardId = _cardNumber;

            try
            {
                if (_DVBCChannels.Count == 0)
                {
                    return;
                }

                TvBusinessLayer layer = new TvBusinessLayer();
                Card            card  = layer.GetCardByDevicePath(RemoteControl.Instance.CardDevice(_cardNumber));

                for (int index = 0; index < _DVBCChannels.Count; ++index)
                {
                    DVBCTuning  curTuning   = _DVBCChannels[index];
                    DVBCChannel tuneChannel = new DVBCChannel(curTuning);
                    string      line        = String.Format("{0}tp- {1}", 1 + index, tuneChannel.TuningInfo.ToString());
                    Log.Debug(line);

                    if (index == 0)
                    {
                        RemoteControl.Instance.Scan(ref user, tuneChannel, -1);
                    }

                    IChannel[] channels = RemoteControl.Instance.Scan(_cardNumber, tuneChannel);

                    if (channels == null || channels.Length == 0)
                    {
                        if (RemoteControl.Instance.TunerLocked(_cardNumber) == false)
                        {
                            line = String.Format("{0}tp- {1} {2} {3}:No signal", 1 + index, tuneChannel.Frequency,
                                                 tuneChannel.ModulationType, tuneChannel.SymbolRate);

                            Log.Error(line);
                            continue;
                        }
                        line = String.Format("{0}tp- {1} {2} {3}:Nothing found", 1 + index, tuneChannel.Frequency,
                                             tuneChannel.ModulationType, tuneChannel.SymbolRate);

                        Log.Error(line);
                        continue;
                    }

                    radio.newChannel = 0;
                    radio.updChannel = 0;
                    tv.newChannel    = 0;
                    tv.updChannel    = 0;

                    for (int i = 0; i < channels.Length; ++i)
                    {
                        Channel      dbChannel;
                        DVBCChannel  channel = (DVBCChannel)channels[i];
                        bool         exists;
                        TuningDetail currentDetail;
                        //Check if we already have this tuningdetail. The user has the option to enable channel move detection...
                        if (true)
                        {
                            //According to the DVB specs ONID + SID is unique, therefore we do not need to use the TSID to identify a service.
                            //The DVB spec recommends that the SID should not change if a service moves. This theoretically allows us to
                            //track channel movements.
                            currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.ServiceId,
                                                                  TvBusinessLayer.GetChannelType(channel));
                        }
                        else
                        {
                            //There are certain providers that do not maintain unique ONID + SID combinations.
                            //In those cases, ONID + TSID + SID is generally unique. The consequence of using the TSID to identify
                            //a service is that channel movement tracking won't work (each transponder/mux should have its own TSID).
                            currentDetail = layer.GetTuningDetail(channel.NetworkId, channel.TransportId, channel.ServiceId,
                                                                  TvBusinessLayer.GetChannelType(channel));
                        }

                        if (currentDetail == null)
                        {
                            //add new channel
                            exists              = false;
                            dbChannel           = layer.AddNewChannel(channel.Name, channel.LogicalChannelNumber);
                            dbChannel.SortOrder = 10000;
                            if (channel.LogicalChannelNumber >= 1)
                            {
                                dbChannel.SortOrder = channel.LogicalChannelNumber;
                            }
                            dbChannel.IsTv    = channel.IsTv;
                            dbChannel.IsRadio = channel.IsRadio;
                            dbChannel.GrabEpg = true;
                            dbChannel.Persist();

                            if (dbChannel.IsTv)
                            {
                                layer.AddChannelToGroup(dbChannel, TvConstants.TvGroupNames.AllChannels);

                                if (_defaultTVGroup != "")
                                {
                                    layer.AddChannelToGroup(dbChannel, _defaultTVGroup);
                                }
                            }
                            if (dbChannel.IsRadio)
                            {
                                layer.AddChannelToRadioGroup(dbChannel, TvConstants.RadioGroupNames.AllChannels);

                                if (_defaultTVGroup != "")
                                {
                                    layer.AddChannelToRadioGroup(dbChannel, _defaultTVGroup);
                                }
                            }
                        }
                        else
                        {
                            exists    = true;
                            dbChannel = currentDetail.ReferencedChannel();
                        }

                        if (currentDetail == null)
                        {
                            layer.AddTuningDetails(dbChannel, channel);
                        }
                        else
                        {
                            //update tuning details...
                            TuningDetail td = layer.UpdateTuningDetails(dbChannel, channel, currentDetail);
                            td.Persist();
                        }

                        if (channel.IsTv)
                        {
                            if (exists)
                            {
                                tv.updChannel++;
                            }
                            else
                            {
                                tv.newChannel++;
                                tv.newChannels.Add(channel);
                            }
                        }
                        if (channel.IsRadio)
                        {
                            if (exists)
                            {
                                radio.updChannel++;
                            }
                            else
                            {
                                radio.newChannel++;
                                radio.newChannels.Add(channel);
                            }
                        }
                        layer.MapChannelToCard(card, dbChannel, false);
                        line = String.Format("{0}tp- {1} {2} {3}:New TV/Radio:{4}/{5} Updated TV/Radio:{6}/{7}", 1 + index,
                                             tuneChannel.Frequency, tuneChannel.ModulationType, tuneChannel.SymbolRate,
                                             tv.newChannel, radio.newChannel, tv.updChannel, radio.updChannel);
                        Log.Debug(line);
                    }
                    tv.updChannelSum    += tv.updChannel;
                    radio.updChannelSum += radio.updChannel;
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            finally
            {
                RemoteControl.Instance.StopCard(user);
            }

            if (radio.newChannels.Count == 0)
            {
                Log.Debug("No new radio channels");
            }
            else
            {
                foreach (IChannel newChannel in radio.newChannels)
                {
                    String line = String.Format("Radio  -> new channel: {0}", newChannel.Name);
                    Log.Debug(line);
                }
            }

            if (tv.newChannels.Count == 0)
            {
                Log.Debug("No new TV channels");
            }
            else
            {
                foreach (IChannel newChannel in tv.newChannels)
                {
                    String line = String.Format("TV  -> new channel: {0}", newChannel.Name);
                    Log.Debug(line);
                }
            }
        }