CodeTV.WizardForm.UpdateDVBChannelPids C# (CSharp) Method

UpdateDVBChannelPids() static private method

static private UpdateDVBChannelPids ( IMpeg2Data mpeg2Data, ushort pmtPid, ChannelDVB channelDVB ) : void
mpeg2Data IMpeg2Data
pmtPid ushort
channelDVB ChannelDVB
return void
        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];
        }

Usage Example

コード例 #1
0
        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;
                                }
                            }
                        }
                    }
                }
            }
        }