Beispiel #1
0
        /// <summary>
        /// Constructs the AtscPsip Parser
        /// </summary>
        /// <remarks>
        /// The associated DirectShow graph should probably be running to get valid data.
        /// </remarks>
        /// <param name="mpeg2DataInterface">the IMpeg2Data interface to the MPEG-2 Sections and Tables filter</param>
        public Parser(IMpeg2Data mpeg2DataInterface)
        {
            if (mpeg2DataInterface == null)
            {
                throw new ArgumentNullException("mpeg2DataInterface");
            }

            mpeg2Data = mpeg2DataInterface;
        }
        private void buttonChannelUpdatePid_Click(object sender, EventArgs e)
        {
            if (this.propertyGridChannel.SelectedObject is ChannelDVB)
            {
                ChannelDVB           currentChannelTV = this.propertyGridChannel.SelectedObject as ChannelDVB;
                ChannelDVB.VideoType videoType        = currentChannelTV.VideoDecoderType;
                if (videoType != ChannelDVB.VideoType.MPEG2)
                {
                    currentChannelTV.VideoDecoderType = ChannelDVB.VideoType.MPEG2;
                }
                MainForm.TuneChannelGUI(currentChannelTV);
                if (MainForm.GraphBuilder is GraphBuilderBDA)
                {
                    IMpeg2Data mpeg2Data = (MainForm.GraphBuilder as GraphBuilderBDA).SectionsAndTables as IMpeg2Data;
                    if (mpeg2Data == null)
                    {
                        MessageBox.Show(Properties.Resources.CannotUpdatePidChannel);
                        return;
                    }

                    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());

                            foreach (PSIPAT.Data program in pat.ProgramIds)
                            {
                                if (program.ProgramNumber == currentChannelTV.SID)
                                {
                                    WizardForm.UpdateDVBChannelPids(mpeg2Data, program.Pid, currentChannelTV);
                                    this.propertyGridChannel.SelectedObject = currentChannelTV;
                                    if (videoType != ChannelDVB.VideoType.MPEG2)
                                    {
                                        currentChannelTV.VideoDecoderType = videoType;
                                    }
                                    MainForm.TuneChannelGUI(currentChannelTV);
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public static PSISection[] GetPSITable(int pid, int tableId, IMpeg2Data mpeg2Data)
        {
            ArrayList    al = new ArrayList();
            ISectionList ppSectionList;
            int          hr = mpeg2Data.GetTable((short)pid, (byte)tableId, null, 5000, out ppSectionList);

            if (ppSectionList != null)
            {
                short pidFound = -1;
                ppSectionList.GetProgramIdentifier(out pidFound);
                if (pidFound == (short)pid)
                {
                    byte tableIdFound = 0;
                    ppSectionList.GetTableIdentifier(out tableIdFound);
                    if (tableIdFound == (byte)tableId)
                    {
                        short sectionCount = -1;
                        ppSectionList.GetNumberOfSections(out sectionCount);

                        short sectionNumber = 0;
                        for (sectionNumber = 0; sectionNumber < sectionCount; sectionNumber++)
                        {
                            try
                            {
                                int    pdwRawPacketLength;
                                IntPtr ppSection;
                                ppSectionList.GetSectionData(sectionNumber, out pdwRawPacketLength, out ppSection);

                                byte[] data = new byte[pdwRawPacketLength];
                                Marshal.Copy(ppSection, data, 0, pdwRawPacketLength);

                                PSISection table = ParseTable(tableId, data);
                                Marshal.ReleaseComObject(ppSectionList);

                                al.Add(table);
                            }
                            catch { }
                        }
                    }
                }
                Marshal.ReleaseComObject(ppSectionList);
            }
            return((PSISection[])al.ToArray(typeof(PSISection)));
        }
        private void BuildSinkGraph(ITuningSpace tuningSpace)
        {
            this.graphBuilder = (IFilterGraph2) new FilterGraph();
            this.rot          = new DsROTEntry(this.graphBuilder);

            this.epg = new EPG(this.hostingControl);

            this.cookiesSink = this.hostingControl.SubscribeEvents(this as VideoControl.IVideoEventHandler, this.graphBuilder as IMediaEventEx);

            AddNetworkProviderFilter(this.objTuningSpace);
            AddMPEG2DemuxFilter();
            AddMpeg2VideoStreamAnalyzerFilter();
            CreateMPEG2DemuxPins();

            AddAndConnectBDABoardFilters();
            if (this.tuner == null && this.capture == null)
            {
                throw new ApplicationException("No BDA devices found!");
            }

            if (this.H264DecoderDevice != null || !isH264ElecardSpecialMode)
            {
                //+++ This order is to avoid a bug from the DirectShow
                AddAndConnectSectionsAndTablesFilterToGraph();

                IMpeg2Data   mpeg2Data = this.bdaSecTab as IMpeg2Data;
                ISectionList ppSectionList;
                int          hr2 = mpeg2Data.GetTable(0, 0, null, 0, out ppSectionList);

                AddAndConnectTIFToGraph();
                //---
            }

            ConfigureTimeShiftingRegistry();

            AddStreamBufferSinkFilter();
            ConnectStreamBufferSinkFilter();

            this.epg.RegisterEvent(TransportInformationFilter as IConnectionPointContainer);
        }
Beispiel #5
0
        internal static void UpdateDVBChannelPids(IMpeg2Data mpeg2Data, ushort pmtPid, ChannelDVB channelDVB)
        {
            Hashtable hashtableEcmPids = new Hashtable();

            channelDVB.PmtPid = pmtPid;

            PSISection[] psiPmts = PSISection.GetPSITable(pmtPid, (int)TABLE_IDS.PMT, mpeg2Data);
            for (int i2 = 0; i2 < psiPmts.Length; i2++)
            {
                PSISection psiPmt = psiPmts[i2];
                if (psiPmt != null && psiPmt is PSIPMT)
                {
                    PSIPMT pmt = (PSIPMT)psiPmt;

                    channelDVB.PcrPid = pmt.PcrPid;
                    if (pmt.Descriptors != null)
                    {
                        foreach (PSIDescriptor descriptor in pmt.Descriptors)
                        {
                            switch (descriptor.DescriptorTag)
                            {
                            case DESCRIPTOR_TAGS.DESCR_CA:
                                hashtableEcmPids[(descriptor as PSIDescriptorCA).CaPid] = (descriptor as PSIDescriptorCA).CaSystemId;
                                break;
                            }
                        }
                    }

                    channelDVB.VideoPid  = -1;
                    channelDVB.AudioPid  = -1;
                    channelDVB.AudioPids = new int[0];
                    channelDVB.EcmPids   = new int[0];

                    foreach (PSIPMT.Data data in pmt.Streams)
                    {
                        switch ((int)data.StreamType)
                        {
                        case (int)STREAM_TYPES.STREAMTYPE_11172_VIDEO:
                        case (int)STREAM_TYPES.STREAMTYPE_13818_VIDEO:
                            //channelDVB.VideoDecoderType = ChannelDVB.VideoType.MPEG2;
                            channelDVB.VideoPid = data.Pid;
                            if (data.Descriptors != null)
                            {
                                foreach (PSIDescriptor descriptor in data.Descriptors)
                                {
                                    if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_CA)
                                    {
                                        hashtableEcmPids[(descriptor as PSIDescriptorCA).CaPid] = (descriptor as PSIDescriptorCA).CaSystemId;
                                    }
                                }
                            }
                            break;

                        case 27:                                 //H264
                            channelDVB.VideoDecoderType = ChannelDVB.VideoType.H264;
                            channelDVB.VideoPid         = data.Pid;
                            if (data.Descriptors != null)
                            {
                                foreach (PSIDescriptor descriptor in data.Descriptors)
                                {
                                    if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_CA)
                                    {
                                        hashtableEcmPids[(descriptor as PSIDescriptorCA).CaPid] = (descriptor as PSIDescriptorCA).CaSystemId;
                                    }
                                }
                            }
                            break;

                        case (int)STREAM_TYPES.STREAMTYPE_11172_AUDIO:
                        case (int)STREAM_TYPES.STREAMTYPE_13818_AUDIO:
                        {
                            int[] audioPids = new int[channelDVB.AudioPids.Length + 1];
                            Array.Copy(channelDVB.AudioPids, audioPids, channelDVB.AudioPids.Length);
                            audioPids[channelDVB.AudioPids.Length] = data.Pid;
                            channelDVB.AudioPids = audioPids;
                            if (audioPids.Length == 1)         // If it is the first one
                            {
                                channelDVB.AudioPid         = data.Pid;
                                channelDVB.AudioDecoderType = ChannelDVB.AudioType.MPEG2;
                            }

                            foreach (PSIDescriptor descriptor in data.Descriptors)
                            {
                                if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_CA)
                                {
                                    hashtableEcmPids[(descriptor as PSIDescriptorCA).CaPid] = (descriptor as PSIDescriptorCA).CaSystemId;
                                }
                            }
                        }
                        break;

                        case (int)STREAM_TYPES.STREAMTYPE_13818_PES_PRIVATE:
                            if (data.Descriptors != null)
                            {
                                foreach (PSIDescriptor descriptor in data.Descriptors)
                                {
                                    if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_TELETEXT)
                                    {
                                        channelDVB.TeletextPid = data.Pid;
                                    }
                                    else if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_AC3 || descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_ENHANCED_AC3)
                                    {
                                        //Audio again
                                        int[] audioPids = new int[channelDVB.AudioPids.Length + 1];
                                        Array.Copy(channelDVB.AudioPids, audioPids, channelDVB.AudioPids.Length);
                                        audioPids[channelDVB.AudioPids.Length] = data.Pid;
                                        channelDVB.AudioPids = audioPids;
                                        if (audioPids.Length == 1)     // If it is the first one
                                        {
                                            channelDVB.AudioPid = data.Pid;
                                            if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_AC3)
                                            {
                                                channelDVB.AudioDecoderType = ChannelDVB.AudioType.AC3;
                                            }
                                            if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_ENHANCED_AC3)
                                            {
                                                channelDVB.AudioDecoderType = ChannelDVB.AudioType.EAC3;
                                            }
                                        }
                                    }
                                    else if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_ISO_639_LANGUAGE)
                                    {
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }

            channelDVB.EcmPids = new int[hashtableEcmPids.Count];
            hashtableEcmPids.Keys.CopyTo(channelDVB.EcmPids, 0);
            if (channelDVB.EcmPids.Length > 0)
            {
                channelDVB.EcmPid = channelDVB.EcmPids[0];
            }
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public static PSISection[] GetPSITable(int pid, int tableId, IMpeg2Data mpeg2Data)
        {
            ArrayList al = new ArrayList();
            ISectionList ppSectionList;
            int hr = mpeg2Data.GetTable((short)pid, (byte)tableId, null, 5000, out ppSectionList);
            if (ppSectionList != null)
            {
                short pidFound = -1;
                ppSectionList.GetProgramIdentifier(out pidFound);
                if (pidFound == (short)pid)
                {
                    byte tableIdFound = 0;
                    ppSectionList.GetTableIdentifier(out tableIdFound);
                    if (tableIdFound == (byte)tableId)
                    {
                        short sectionCount = -1;
                        ppSectionList.GetNumberOfSections(out sectionCount);

                        short sectionNumber = 0;
                        for (; sectionNumber < sectionCount; sectionNumber++)
                        {
                            int pdwRawPacketLength;
                            IntPtr ppSection;
                            ppSectionList.GetSectionData(sectionNumber, out pdwRawPacketLength, out ppSection);

                            byte[] data = new byte[pdwRawPacketLength];
                            Marshal.Copy(ppSection, data, 0, pdwRawPacketLength);

                            PSISection table = ParseTable(tableId, data);
                            Marshal.ReleaseComObject(ppSectionList);

                            al.Add(table);
                        }
                    }
                }
                Marshal.ReleaseComObject(ppSectionList);
            }
            return (PSISection[])al.ToArray(typeof(PSISection));
        }
Beispiel #8
0
        public WinTV418ATSC(StreamSourceInfo sourceConfig, OpenGraphRequest openGraphRequest)
            : base(sourceConfig, openGraphRequest)
        {
            if (SourceConfig.TVTuner == null)
            {
                throw new SourceConfigException("TVTuner config section not found!");
            }

            _deviceIndex = sourceConfig.TVTuner.DeviceIndex;

            tuningSpace = GetTuningSpace();

            Guid networkType;

            tuningSpace.get__NetworkType(out networkType);
            if (networkType.Equals(Guid.Empty))
            {
                throw new Exception("Not a digital Network Type!");
            }

            networkProvider = (IBaseFilter)Activator.CreateInstance(Type.GetTypeFromCLSID(networkType));
            int hr = _graphBuilder.AddFilter(networkProvider, "Network Provider");

            DsError.ThrowExceptionForHR(hr);
            tuner = (ITuner)networkProvider;

            //add MPEG2 Demux
            mpeg2Demux = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.LegacyAmFilterCategory, "MPEG-2 Demultiplexer");

            //add BDA MPEG-2 Transport Information Filter
            bdaTransportInfo = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDATransportInformationRenderersCategory, "BDA MPEG2 Transport Information Filter");
            //add MPEG-2 Sections and Tables Filter
            mpeg2SectionsAndTables = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDATransportInformationRenderersCategory, "MPEG-2 Sections and Tables");

            //tunerFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDASourceFiltersCategory, "Hauppauge WinTV 418 BDA Tuner");
            DsDevice tunerDevice = FindDevice(FilterCategory.BDASourceFiltersCategory, "Hauppauge WinTV 418 BDA Tuner");

            tunerFilter = FilterGraphTools.AddFilterByDevicePath(_graphBuilder, tunerDevice.DevicePath, tunerDevice.Name);
            //captureFilter = FilterGraphTools.AddFilterByName(_graphBuilder, FilterCategory.BDAReceiverComponentsCategory, "Hauppauge WinTV 418 TS Capture");
            DsDevice captureDevice = FindDevice(FilterCategory.BDAReceiverComponentsCategory, "Hauppauge WinTV 418 TS Capture");

            captureFilter = FilterGraphTools.AddFilterByDevicePath(_graphBuilder, captureDevice.DevicePath, captureDevice.Name);

            //connect network provider to BDA tuner
            ConnectFilters(networkProvider, "Antenna Out", (IBaseFilter)tunerFilter, "Input0", false);
            ConnectFilters((IBaseFilter)tunerFilter, "MPEG2 Transport", captureFilter, "MPEG2 Transport", false);

            //These filters need to be connected via their explicit pins,
            //  because Hauppauge saw fit to name all the pins on the capture filter the same name.
            IPin captureFilterOut = DsFindPin.ByDirection(captureFilter, PinDirection.Output, 0);
            IPin mpeg2DemuxIn     = DsFindPin.ByDirection(mpeg2Demux, PinDirection.Input, 0);

            FilterGraphTools.ConnectFilters(_graphBuilder, captureFilterOut, mpeg2DemuxIn, false);
            //clean up the two pins
            Marshal.ReleaseComObject(captureFilterOut);
            Marshal.ReleaseComObject(mpeg2DemuxIn);

            //add and connect meta data filters and connect them to the Demux
            ConnectFilters(mpeg2Demux, "1", bdaTransportInfo, "Input", false);
            ConnectFilters(mpeg2Demux, "5", mpeg2SectionsAndTables, "In", false);

            //this interface must be queried after the S&T filter has been connected.
            mpeg2Data  = (IMpeg2Data)mpeg2SectionsAndTables;
            _vctParser = new Parser(mpeg2Data);

            //build out the rest of the graph for the given source config / profile
            BuildForProfile();

            ConnectNetMuxToNetSnk();

            if (KnownChannels.Count > 0)
            {
                this.Channel = KnownChannels.Items[0];
            }

            SaveGraphFile("WinTV418ATSC.grf");
        }
Beispiel #9
0
        private void BuildGraph()
        {
            int hr = 0;

            graphBuilder = (IFilterGraph2) new FilterGraph();
            rot          = new DsROTEntry(graphBuilder);

            ICaptureGraphBuilder2 capBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            capBuilder.SetFiltergraph(graphBuilder);

            // Get the BDA network provider specific for this given network type
            networkProvider = BDAUtils.GetNetworkProvider(networkType);

            hr = graphBuilder.AddFilter(networkProvider, "BDA Network Provider");
            DsError.ThrowExceptionForHR(hr);

            tuner = (ITuner)networkProvider;

            // Get a tuning space for this network type
            tuningSpace = BDAUtils.GetTuningSpace(networkType);

            hr = tuner.put_TuningSpace(tuningSpace);
            DsError.ThrowExceptionForHR(hr);

            // Create a tune request from this tuning space
            tuneRequest = BDAUtils.CreateTuneRequest(tuningSpace);

            // Is it okay ?
            hr = tuner.Validate(tuneRequest);
            if (hr == 0)
            {
                // Set it
                hr = tuner.put_TuneRequest(tuneRequest);
                DsError.ThrowExceptionForHR(hr);

                // found a BDA Tuner and a BDA Capture that can connect to this network provider
                BDAUtils.AddBDATunerAndDemodulatorToGraph(graphBuilder, networkProvider, out bdaTuner, out bdaCapture);

                if ((bdaTuner != null) && (bdaCapture != null))
                {
                    // Create and add the mpeg2 demux
                    mpeg2Demux = (IBaseFilter) new MPEG2Demultiplexer();

                    hr = graphBuilder.AddFilter(mpeg2Demux, "MPEG2 Demultiplexer");
                    DsError.ThrowExceptionForHR(hr);

                    // connect it to the BDA Capture
                    hr = capBuilder.RenderStream(null, null, bdaCapture, null, mpeg2Demux);
                    DsError.ThrowExceptionForHR(hr);

                    // Add the two mpeg2 transport stream helper filters
                    BDAUtils.AddTransportStreamFiltersToGraph(graphBuilder, out bdaTIF, out bdaSecTab);

                    if ((bdaTIF != null) && (bdaSecTab != null))
                    {
                        // Render all the output pins of the demux (missing filters are added)
                        for (int i = 0; i < 5; i++)
                        {
                            IPin pin = DsFindPin.ByDirection(mpeg2Demux, PinDirection.Output, i);

                            hr = graphBuilder.Render(pin);
                            Marshal.ReleaseComObject(pin);
                        }

                        mpeg2Data = (IMpeg2Data)bdaSecTab;
                    }
                }
            }
        }
Beispiel #10
0
        internal static void UpdateDVBChannelPids(IMpeg2Data mpeg2Data, ushort pmtPid, ChannelDVB channelDVB)
        {
            Hashtable hashtableEcmPids = new Hashtable();

            channelDVB.PmtPid = pmtPid;

            PSISection[] psiPmts = PSISection.GetPSITable(pmtPid, (int)TABLE_IDS.PMT, mpeg2Data);
            for (int i2 = 0; i2 < psiPmts.Length; i2++)
            {
                PSISection psiPmt = psiPmts[i2];
                if (psiPmt != null && psiPmt is PSIPMT)
                {
                    PSIPMT pmt = (PSIPMT)psiPmt;

                    channelDVB.PcrPid = pmt.PcrPid;
                    if (pmt.Descriptors != null)
                    {
                        foreach (PSIDescriptor descriptor in pmt.Descriptors)
                        {
                            switch (descriptor.DescriptorTag)
                            {
                                case DESCRIPTOR_TAGS.DESCR_CA:
                                    hashtableEcmPids[(descriptor as PSIDescriptorCA).CaPid] = (descriptor as PSIDescriptorCA).CaSystemId;
                                    break;
                            }
                        }
                    }

                    channelDVB.VideoPid = -1;
                    channelDVB.AudioPid = -1;
                    channelDVB.AudioPids = new int[0];
                    channelDVB.EcmPids = new int[0];

                    foreach (PSIPMT.Data data in pmt.Streams)
                    {
                        switch ((int)data.StreamType)
                        {
                            case (int)STREAM_TYPES.STREAMTYPE_11172_VIDEO:
                            case (int)STREAM_TYPES.STREAMTYPE_13818_VIDEO:
                                //channelDVB.VideoDecoderType = ChannelDVB.VideoType.MPEG2;
                                channelDVB.VideoPid = data.Pid;
                                if (data.Descriptors != null)
                                {
                                    foreach (PSIDescriptor descriptor in data.Descriptors)
                                        if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_CA)
                                            hashtableEcmPids[(descriptor as PSIDescriptorCA).CaPid] = (descriptor as PSIDescriptorCA).CaSystemId;
                                }
                                break;
                            case 27: //H264
                                channelDVB.VideoDecoderType = ChannelDVB.VideoType.H264;
                                channelDVB.VideoPid = data.Pid;
                                if (data.Descriptors != null)
                                {
                                    foreach (PSIDescriptor descriptor in data.Descriptors)
                                        if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_CA)
                                            hashtableEcmPids[(descriptor as PSIDescriptorCA).CaPid] = (descriptor as PSIDescriptorCA).CaSystemId;
                                }
                                break;
                            case (int)STREAM_TYPES.STREAMTYPE_11172_AUDIO:
                            case (int)STREAM_TYPES.STREAMTYPE_13818_AUDIO:
                                {
                                    int[] audioPids = new int[channelDVB.AudioPids.Length + 1];
                                    Array.Copy(channelDVB.AudioPids, audioPids, channelDVB.AudioPids.Length);
                                    audioPids[channelDVB.AudioPids.Length] = data.Pid;
                                    channelDVB.AudioPids = audioPids;
                                    if (audioPids.Length == 1) // If it is the first one
                                    {
                                        channelDVB.AudioPid = data.Pid;
                                        channelDVB.AudioDecoderType = ChannelDVB.AudioType.MPEG2;
                                    }

                                    foreach (PSIDescriptor descriptor in data.Descriptors)
                                        if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_CA)
                                            hashtableEcmPids[(descriptor as PSIDescriptorCA).CaPid] = (descriptor as PSIDescriptorCA).CaSystemId;
                                }
                                break;
                            case (int)STREAM_TYPES.STREAMTYPE_13818_PES_PRIVATE:
                                if (data.Descriptors != null)
                                {
                                    foreach (PSIDescriptor descriptor in data.Descriptors)
                                    {
                                        if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_TELETEXT)
                                        {
                                            channelDVB.TeletextPid = data.Pid;
                                        }
                                        else if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_AC3 || descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_ENHANCED_AC3)
                                        {
                                            //Audio again
                                            int[] audioPids = new int[channelDVB.AudioPids.Length + 1];
                                            Array.Copy(channelDVB.AudioPids, audioPids, channelDVB.AudioPids.Length);
                                            audioPids[channelDVB.AudioPids.Length] = data.Pid;
                                            channelDVB.AudioPids = audioPids;
                                            if (audioPids.Length == 1) // If it is the first one
                                            {
                                                channelDVB.AudioPid = data.Pid;
                                                if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_AC3)
                                                    channelDVB.AudioDecoderType = ChannelDVB.AudioType.AC3;
                                                if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_ENHANCED_AC3)
                                                    channelDVB.AudioDecoderType = ChannelDVB.AudioType.EAC3;
                                            }
                                        }
                                        else if (descriptor.DescriptorTag == DESCRIPTOR_TAGS.DESCR_ISO_639_LANGUAGE)
                                        {
                                        }
                                    }
                                }
                                break;
                        }
                    }
                }
            }

            channelDVB.EcmPids = new int[hashtableEcmPids.Count];
            hashtableEcmPids.Keys.CopyTo(channelDVB.EcmPids, 0);
            if (channelDVB.EcmPids.Length > 0)
                channelDVB.EcmPid = channelDVB.EcmPids[0];
        }