Inheritance: GraphBuilderTV, IWDM
Ejemplo n.º 1
0
        private bool ScanProbeFrequency(ChannelTV currentChannelTV, bool needRebuild)
        {
            this.propertyGridChannel.SelectedObject = currentChannelTV;
            Application.DoEvents();

            MainForm.videoControl.BackColor = Color.Transparent;
            try
            {
                MainForm.TuneChannel(currentChannelTV, needRebuild);
                needRebuild            = false;
                textBoxScanStatus.Text = Properties.Resources.Scanning;
                if (currentChannelTV is ChannelDVB)
                {
                    textBoxScanFrequency.Text = string.Format(Properties.Resources.ScanningFrequency, (currentChannelTV as ChannelDVB).Frequency);
                }
                else if (currentChannelTV is ChannelAnalogic)
                {
                    textBoxScanFrequency.Text = string.Format(Properties.Resources.ScanningChannel, (currentChannelTV as ChannelAnalogic).Channel);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLineIf(MainForm.trace.TraceError, ex.ToString());
                textBoxScanStatus.Text          = Properties.Resources.Error + " " + ex.Message;
                textBoxScanFrequency.Text       = Properties.Resources.ScanningError;
                MainForm.videoControl.BackColor = MainForm.Settings.VideoBackgroundColor;
            }

            if (currentChannelTV is ChannelDVB)
            {
                if (MainForm.GraphBuilder is IBDA)
                {
                    IBDA graphBuilderBDA = MainForm.GraphBuilder as IBDA;
                    bool locked, present;
                    int  strength, quality;
                    System.Threading.Thread.Sleep(500);
                    if ((graphBuilderBDA as ITV).GetSignalStatistics(out locked, out present, out strength, out quality))
                    {
                        if (locked && present)
                        {
                            IMpeg2Data mpeg2Data = graphBuilderBDA.SectionsAndTables as IMpeg2Data;

                            short     originalNetworkId      = -1;
                            Hashtable serviceNameByServiceId = new Hashtable();
                            // Hervé Stalin : Ajout d'une hashtable pour le services_type d'un service
                            Hashtable    serviceTypeByServiceID = new Hashtable();
                            PSISection[] psiSdts = PSISection.GetPSITable((int)PIDS.SDT, (int)TABLE_IDS.SDT_ACTUAL, mpeg2Data);
                            for (int i = 0; i < psiSdts.Length; i++)
                            {
                                PSISection psiSdt = psiSdts[i];
                                if (psiSdt != null && psiSdt is PSISDT)
                                {
                                    PSISDT sdt = (PSISDT)psiSdt;
                                    Trace.WriteLineIf(MainForm.trace.TraceVerbose, "PSI Table " + i + "/" + psiSdts.Length + "\r\n");
                                    Trace.WriteLineIf(MainForm.trace.TraceVerbose, sdt.ToString());

                                    originalNetworkId = (short)sdt.OriginalNetworkId;
                                    foreach (PSISDT.Data service in sdt.Services)
                                    {
                                        serviceNameByServiceId[service.ServiceId] = service.GetServiceName();
                                        //Hervé Stalin : remplissage du hashtable du service_type
                                        serviceTypeByServiceID[service.ServiceId] = service.GetServiceType();
                                    }
                                }
                            }

                            //Hervé Stalin : Code pode pour créér un hashtable de lcn
                            Hashtable    logicalChannelNumberByServiceId = new Hashtable();
                            PSISection[] psiNits = PSISection.GetPSITable((int)PIDS.NIT, (int)TABLE_IDS.NIT_ACTUAL, mpeg2Data);
                            for (int i = 0; i < psiNits.Length; i++)
                            {
                                PSISection psinit = psiNits[i];
                                if (psinit != null && psinit is PSINIT)
                                {
                                    PSINIT nit = (PSINIT)psinit;
                                    Trace.WriteLineIf(MainForm.trace.TraceVerbose, "PSI Table " + i + "/" + psiNits.Length + "\r\n");
                                    Trace.WriteLineIf(MainForm.trace.TraceVerbose, nit.ToString());

                                    foreach (PSINIT.Data data in nit.Streams)
                                    {
                                        foreach (PSIDescriptor psiDescriptorData in data.Descriptors)
                                        {
                                            if (psiDescriptorData.DescriptorTag == DESCRIPTOR_TAGS.DESCR_LOGICAL_CHANNEL)
                                            {
                                                PSIDescriptorLogicalChannel psiDescriptorLogicalChannel = (PSIDescriptorLogicalChannel)psiDescriptorData;
                                                foreach (PSIDescriptorLogicalChannel.ChannelNumber f in psiDescriptorLogicalChannel.LogicalChannelNumbers)
                                                {
                                                    logicalChannelNumberByServiceId[f.ServiceID] = f.LogicalChannelNumber;
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            PSISection[] psis = PSISection.GetPSITable((int)PIDS.PAT, (int)TABLE_IDS.PAT, mpeg2Data);
                            for (int i = 0; i < psis.Length; i++)
                            {
                                PSISection psi = psis[i];
                                if (psi != null && psi is PSIPAT)
                                {
                                    PSIPAT pat = (PSIPAT)psi;
                                    Trace.WriteLineIf(MainForm.trace.TraceVerbose, "PSI Table " + i + "/" + psis.Length + "\r\n");
                                    Trace.WriteLineIf(MainForm.trace.TraceVerbose, pat.ToString());

                                    ChannelDVB newTemplateChannelDVB = (MainForm.GraphBuilder as ITV).CurrentChannel.MakeCopy() as ChannelDVB;
                                    newTemplateChannelDVB.ONID = originalNetworkId;
                                    newTemplateChannelDVB.TSID = pat.TransportStreamId;

                                    foreach (PSIPAT.Data program in pat.ProgramIds)
                                    {
                                        if (!program.IsNetworkPID)                                         // Hervé Stalin : est encore utile ?
                                        {
                                            //Hervé Stalin: discrimination par le service type
                                            SERVICE_TYPES st;
                                            try
                                            {
                                                st = (SERVICE_TYPES)serviceTypeByServiceID[program.ProgramNumber];
                                            }
                                            catch
                                            {
                                                st = SERVICE_TYPES.DIGITAL_TELEVISION_SERVICE;                                                  // bypass en cas de probleme de parsing (mauvaise réception dans mon cas)
                                            }

                                            if (st == SERVICE_TYPES.DIGITAL_TELEVISION_SERVICE ||                                                                   // TV SD MPEG2
                                                st == SERVICE_TYPES.ADVANCE_CODEC_HD_DIGITAL_SERVICE ||                                                             // TV HD H264
                                                st == SERVICE_TYPES.ADVANCE_CODEC_SD_DIGITAL_SERVICE ||                                                             // TV SD H264
                                                st == SERVICE_TYPES.MPEG2_HD_DIGITAL_TELEVISION_SERVICE ||                                                          // TV HD MPEG2
                                                st == SERVICE_TYPES.DIGITAL_RADIO_SOUND_SERVICE ||                                                                  // Radio MP2
                                                st == SERVICE_TYPES.ADVANCED_CODEC_DIGITAL_RADIO_SOUND_SERVICE ||                                                   // Radio AC3/E-AC3/AAC
                                                st == SERVICE_TYPES.MOSAIC_SERVICE ||                                                                               // Mosaic MPEG2
                                                st == SERVICE_TYPES.ADVANCED_CODEC_MOSAIC_SERVICE)                                                                  // Mosaic H264

                                            {
                                                ChannelDVB newChannelDVB = newTemplateChannelDVB.MakeCopy() as ChannelDVB;
                                                newChannelDVB.SID  = program.ProgramNumber;
                                                newChannelDVB.Name = (string)serviceNameByServiceId[program.ProgramNumber];
                                                //Hervé Stalin: ajout du LCN
                                                newChannelDVB.ChannelNumber = Convert.ToInt16(logicalChannelNumberByServiceId[program.ProgramNumber]);

                                                if (newChannelDVB.Name == null)
                                                {
                                                    newChannelDVB.Name = Properties.Resources.NoName;
                                                }

                                                UpdateDVBChannelPids(mpeg2Data, program.Pid, newChannelDVB);

                                                ListViewItem lvi = new ListViewItem(newChannelDVB.Name, "LogoTVDefault");
                                                lvi.SubItems.Add(newChannelDVB.Frequency.ToString());
                                                lvi.SubItems.Add(newChannelDVB.ChannelNumber.ToString());
                                                lvi.Tag = newChannelDVB;
                                                //this.listViewScanResult.SmallImageList = MainForm.imageListLogoTV;
                                                this.listViewScanResult.Items.Add(lvi);
                                                this.buttonScanClear.Enabled = true;

                                                try
                                                {
                                                    var extensions = new HashSet <string>(StringComparer.OrdinalIgnoreCase)
                                                    {
                                                        ".gif", ".png", ".jpg", ".jpeg", ".bmp"
                                                    };
                                                    //var files = Directory.EnumerateFiles(@".\Logos\", "*");
                                                    var files = Directory.GetFiles(@".\Logos\", "*");
                                                    foreach (var logo in files)
                                                    {
                                                        string extension = Path.GetExtension(logo).ToLowerInvariant();
                                                        if (extensions.Contains(extension))
                                                        {
                                                            string filename = Path.GetFileNameWithoutExtension(logo).ToLowerInvariant();
                                                            if (newChannelDVB.Name.ToLowerInvariant().IndexOf(filename) != -1)
                                                            {
                                                                newChannelDVB.Logo = logo;
                                                                //MainForm.panelChannel.AdjustTVLogo(newChannelDVB);
                                                                if (MainForm.imageListLogoTV.Images.ContainsKey(logo))
                                                                {
                                                                    lvi.ImageKey = logo;
                                                                }
                                                                else
                                                                {
                                                                    try
                                                                    {
                                                                        string path = FileUtils.GetAbsolutePath(logo);
                                                                        if (File.Exists(path))
                                                                        {
                                                                            Bitmap bitmap = new Bitmap(path);
                                                                            //if (!Bitmap.IsAlphaPixelFormat(bitmap.PixelFormat))
                                                                            //    bitmap.MakeTransparent(Color.White);
                                                                            Image thumbnail = Utils.ResizeImage(bitmap, 16, 16, false);
                                                                            MainForm.imageListLogoTV.Images.Add(logo, thumbnail);
                                                                            lvi.ImageKey = logo;
                                                                            thumbnail.Dispose();
                                                                            bitmap.Dispose();
                                                                            break;
                                                                        }
                                                                    }
                                                                    catch (ArgumentException) { }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                catch (Exception)
                                                {
                                                }

                                                //PSISection[] psis2 = PSISection.GetPSITable(program.Pid, (int)TABLE_IDS.PMT, mpeg2Data);
                                                //for (int i2 = 0; i2 < psis2.Length; i2++)
                                                //{
                                                //    PSISection psi2 = psis2[i2];
                                                //    if (psi2 != null && psi2 is PSIPMT)
                                                //    {
                                                //        PSIPMT pmt = (PSIPMT)psi2;
                                                //        Trace.WriteLineIf(trace.TraceVerbose, "PSI Table " + i2 + "/" + psis2.Length + "\r\n");
                                                //        Trace.WriteLineIf(trace.TraceVerbose, pmt.ToString());
                                                //    }
                                                //}
                                            }
                                        }
                                    }

                                    Application.DoEvents();
                                }
                            }
                        }
                    }
                }
            }
            else if (currentChannelTV is ChannelAnalogic)
            {
                GraphBuilderWDM graphBuilderWDM = MainForm.GraphBuilder as GraphBuilderWDM;
                if (graphBuilderWDM.CurrentChannel != null)
                {
                    bool locked, present;
                    int  strength, quality;
                    if (graphBuilderWDM.GetSignalStatistics(out locked, out present, out strength, out quality))
                    {
                        if (locked && present)
                        {
                            ChannelAnalogic newChannel = graphBuilderWDM.CurrentChannel.MakeCopy() as ChannelAnalogic;
                            newChannel.Name = Properties.Resources.NewChannelName + " " + newChannel.Channel.ToString();

                            ListViewItem lvi = new ListViewItem(newChannel.Name, "LogoTVDefault");
                            lvi.SubItems.Add(newChannel.Channel.ToString());
                            lvi.Tag = newChannel;
                            this.listViewScanResult.Items.Add(lvi);
                            this.buttonScanClear.Enabled = true;
                        }
                    }
                }
            }
            return(needRebuild);
        }
Ejemplo n.º 2
0
        public GraphBuilderTV TuneChannel(Channel channel, bool needRebuild, GraphBuilderBase currentGraph, VideoControl hostingControl)
        {
            if (needRebuild && currentGraph != null)
            {
                ClearGraph();
                //OnGraphStop();
                //currentGraph.Dispose();
                //currentGraph = null;
            }

            GraphBuilderTV currentGraphTV = currentGraph as GraphBuilderTV;

            if (channel is ChannelDVB)
            {
                ChannelDVB channelDVB = channel as ChannelDVB;

                if (needRebuild)
                {
                    GraphBuilderBDA newGraph = null;
                    switch(this.graphBuilderType)
                    {
                        case GraphBuilderType.BDA:
                            newGraph = new GraphBuilderBDA(hostingControl);
                            break;
                        case GraphBuilderType.BDATimeShifting:
                            newGraph = new GraphBuilderBDATimeShifting(hostingControl);
                            break;
                        case GraphBuilderType.BDAMosaic:
                            newGraph = new GraphBuilderBDAMosaic(hostingControl);
                            break;
                    }
                    newGraph.GraphStarted += new EventHandler(newGraph_GraphStarted);
                    newGraph.GraphEnded += new EventHandler(newGraph_GraphEnded);
                    newGraph.PossibleChanged += new EventHandler<GraphBuilderBase.PossibleEventArgs>(newGraph_PossibleChanged);
                    newGraph.Settings = Settings;
                    currentGraphTV = newGraph;

                    newGraph.ReferenceClock = channelDVB.ReferenceClock;

                    newGraph.AudioDecoderType = channelDVB.AudioDecoderType;
                    DsDevice device;
                    if (!string.IsNullOrEmpty(channelDVB.AudioDecoderDevice))
                    {
                        if (GraphBuilderBDA.AudioDecoderDevices.TryGetValue(channelDVB.AudioDecoderDevice, out device))
                            newGraph.AudioDecoderDevice = device;
                        else
                            throw new Exception(string.Format(Properties.Resources.AudioDeviceNotFound, channelDVB.AudioDecoderDevice));
                    }
                    if (channelDVB.VideoDecoderType == ChannelDVB.VideoType.MPEG2)
                    {
                        if (!string.IsNullOrEmpty(channelDVB.MPEG2DecoderDevice))
                        {
                            if (GraphBuilderBDA.MPEG2DecoderDevices.TryGetValue(channelDVB.MPEG2DecoderDevice, out device))
                                newGraph.Mpeg2DecoderDevice = device;
                            else
                                throw new Exception(string.Format(Properties.Resources.MPEG2DecoderDeviceNotFound, channelDVB.MPEG2DecoderDevice));
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(channelDVB.H264DecoderDevice))
                        {
                            if (GraphBuilderBDA.H264DecoderDevices.TryGetValue(channelDVB.H264DecoderDevice, out device))
                                newGraph.H264DecoderDevice = device;
                            else
                                throw new Exception(string.Format(Properties.Resources.H264DecoderDeviceNotFound, channelDVB.H264DecoderDevice));
                        }
                    }
                    if (!string.IsNullOrEmpty(channelDVB.AudioRendererDevice))
                    {
                        if (GraphBuilderBDA.AudioRendererDevices.TryGetValue(channelDVB.AudioRendererDevice, out device))
                            newGraph.AudioRendererDevice = device;
                        else
                            throw new Exception(string.Format(Properties.Resources.AudioRendererDeviceNotFound, channelDVB.AudioRendererDevice));
                    }
                    if (!string.IsNullOrEmpty(channelDVB.TunerDevice))
                    {
                        if (GraphBuilderBDA.TunerDevices.TryGetValue(channelDVB.TunerDevice, out device))
                            newGraph.TunerDevice = device;
                        else
                            throw new Exception(string.Format(Properties.Resources.TunerDeviceNotFound, channelDVB.TunerDevice));
                    }
                    if (!string.IsNullOrEmpty(channelDVB.CaptureDevice))
                    {
                        if (GraphBuilderBDA.CaptureDevices.TryGetValue(channelDVB.CaptureDevice, out device))
                            newGraph.CaptureDevice = device;
                        else
                            throw new Exception(string.Format(Properties.Resources.CaptureDeviceNotFound, channelDVB.CaptureDevice));
                    }

                    IDVBTuningSpace tuningSpace = (IDVBTuningSpace)new DVBTuningSpace();
                    if (channel is ChannelDVBT)
                    {
                        tuningSpace.put_UniqueName("DVBT TuningSpace");
                        tuningSpace.put_FriendlyName("DVBT TuningSpace");
                        tuningSpace.put_NetworkType(CLSID.DVBTNetworkProvider);
                        tuningSpace.put_SystemType(DVBSystemType.Terrestrial);
                    }
                    else if (channel is ChannelDVBC)
                    {
                        tuningSpace.put_UniqueName("DVBC TuningSpace");
                        tuningSpace.put_FriendlyName("DVBC TuningSpace");
                        tuningSpace.put_NetworkType(CLSID.DVBCNetworkProvider);
                        tuningSpace.put_SystemType(DVBSystemType.Cable);
                    }
                    else if (channel is ChannelDVBS)
                    {
                        tuningSpace.put_UniqueName("DVBS TuningSpace");
                        tuningSpace.put_FriendlyName("DVBS TuningSpace");
                        tuningSpace.put_NetworkType(CLSID.DVBSNetworkProvider);
                        tuningSpace.put_SystemType(DVBSystemType.Satellite);
                    }
                    newGraph.TuningSpace = tuningSpace as ITuningSpace;
                    newGraph.BuildGraph();
                }

                currentGraphTV.SubmitTuneRequest(channel);

                currentGraphTV.VideoZoomMode = channelDVB.VideoZoomMode;
                currentGraphTV.VideoKeepAspectRatio = channelDVB.VideoKeepAspectRatio;
                currentGraphTV.VideoOffset = channelDVB.VideoOffset;
                currentGraphTV.VideoZoom = channelDVB.VideoZoom;
                currentGraphTV.VideoAspectRatioFactor = channelDVB.VideoAspectRatioFactor;

                currentGraphTV.RunGraph();
                //currentGraph.VideoResizer();
                currentGraphTV.CurrentChannel = channel;
            }
            else if (channel is ChannelAnalogic)
            {
                ChannelAnalogic channelAnalogic = channel as ChannelAnalogic;

                if (needRebuild)
                {
                    GraphBuilderWDM newGraph = new GraphBuilderWDM(hostingControl);
                    newGraph.GraphStarted += new EventHandler(newGraph_GraphStarted);
                    newGraph.GraphEnded += new EventHandler(newGraph_GraphEnded);
                    newGraph.PossibleChanged += new EventHandler<GraphBuilderBase.PossibleEventArgs>(newGraph_PossibleChanged);
                    newGraph.Settings = Settings;
                    currentGraphTV = newGraph;

                    DsDevice device;
                    if (GraphBuilderWDM.AudioRendererDevices.TryGetValue(channelAnalogic.AudioRendererDevice, out device))
                        newGraph.AudioRendererDevice = device;
                    if (GraphBuilderWDM.VideoInputDevices.TryGetValue(channelAnalogic.VideoCaptureDeviceName, out device))
                        newGraph.VideoCaptureDevice = device;
                    if (GraphBuilderWDM.AudioInputDevices.TryGetValue(channelAnalogic.AudioCaptureDeviceName, out device))
                        newGraph.AudioCaptureDevice = device;

                    newGraph.FormatOfCapture = channelAnalogic.FormatOfCapture;

                    newGraph.BuildGraph();
                }

                bool goodTuning = true;
                try
                {
                    currentGraphTV.SubmitTuneRequest(channel);
                }
                catch (COMException)
                {
                    goodTuning = false;
                }
                if (goodTuning)
                {
                    currentGraphTV.VideoZoomMode = channelAnalogic.VideoZoomMode;
                    currentGraphTV.VideoKeepAspectRatio = channelAnalogic.VideoKeepAspectRatio;
                    currentGraphTV.VideoOffset = channelAnalogic.VideoOffset;
                    currentGraphTV.VideoZoom = channelAnalogic.VideoZoom;
                    currentGraphTV.VideoAspectRatioFactor = channelAnalogic.VideoAspectRatioFactor;

                    currentGraphTV.RunGraph();
                    //currentGraph.VideoResizer();
                    currentGraphTV.CurrentChannel = channel;
                }
                else
                    currentGraphTV.CurrentChannel = null;
            }
            return currentGraphTV;
        }