Exemplo n.º 1
0
 public void OnNewSection(TsSection section)
 {
     _programcount = (section.section_length - 9) / 4;
     for (var i = 9; i < _programcount; ++i)
     {
         var prgId = (section.Data[i * 4] << 8) + section.Data[(i * 4) + 1];
         var pmtId = ((section.Data[(i * 4) + 2] & 0x1F) << 8) + section.Data[(i * 4) + 3];
         if (pmtId == 0)
         {
             NetworkPid = prgId;
         }
         if (!_programNumbers.ContainsKey(prgId))
         {
             _programNumbers.Add(prgId, pmtId);
         }
     }
     IsReady = true;
 }
Exemplo n.º 2
0
        public void OnNewSection(TsSection section)
        {
            TransportStreamId = section.table_id_extension;
            var offset = 0;
            int network_descriptors_length = ((section.Data[8] & 0x0F) << 8) + section.Data[9];

            int descOffset = offset + 2;

            while (descOffset < 10 + network_descriptors_length)
            {
                byte descriptor_tag    = section.Data[descOffset];
                byte descriptor_length = section.Data[descOffset + 1];

                switch (descriptor_tag)
                {
                case 0x40:
                    networkName = ReadString(section.Data, descOffset + 2, descriptor_length);
                    Console.WriteLine("Network Name: " + networkName);
                    break;

                case 0x4A:     // linkage descriptor
                    break;

                case 0x5F:     // private_data_specifier_descriptor
                    break;

                default:
                    Console.WriteLine("NIT Descriptor UNKNOWN: 0x{0:X2}", descriptor_tag);
                    break;
                }

                descOffset += descriptor_length + 2;
            }

            offset = 10 + network_descriptors_length;

            int transport_stream_loop_length = ((section.Data[offset] & 0x0F) << 8) +
                                               section.Data[offset + 1];

            offset    += 2;
            descOffset = offset;
            offset    += transport_stream_loop_length;
            while (descOffset < transport_stream_loop_length)
            {
                int transport_stream_id          = (section.Data[descOffset] << 8) + section.Data[descOffset + 1];
                int original_network_id          = (section.Data[descOffset + 2] << 8) + section.Data[descOffset + 3];
                int transport_descriptors_length = ((section.Data[descOffset + 4] & 0x0F) << 8) +
                                                   section.Data[descOffset + 5];

                _currentNetwork = new NetworkInformation
                                  (
                    transport_stream_id,
                    original_network_id,
                    networkName
                                  );
                if (!_networkInformations.ContainsKey(transport_stream_id))
                {
                    _networkInformations.Add(transport_stream_id, _currentNetwork);
                }

                descOffset += 6;
                int transOffset = descOffset;
                descOffset += transport_descriptors_length;
                while (transOffset < descOffset)
                {
                    byte descriptor_tag    = section.Data[transOffset];
                    byte descriptor_length = section.Data[transOffset + 1];

                    switch (descriptor_tag)
                    {
                    case 0x40:     // network name descriptor
                        networkName = ReadString(section.Data, descOffset + 2, descriptor_length);
                        break;

                    case 0x41:     // service list descriptor
                        break;

                    case 0x42:     // stuffing descriptor
                        break;

                    case 0x43:     // satellite delivery system descriptor
                        ReadSatelliteDeliverySystem(section.Data, transOffset + 2, descriptor_length);
                        break;

                    case 0x44:     // cable delivery system descriptor
                        break;

                    case 0x5A:     //terrestrial_delivery_system_descriptor
                        ReadTerrestrialDeliverySystem(section.Data, transOffset + 2, descriptor_length);
                        break;

                    case 0x5B:     // multilingual_network_name_descriptor
                        break;

                    case 0x62:     // frequency_list_descriptor
                        break;

                    case 0x6C:     // cell_list_descriptor
                        break;

                    case 0x6D:     // cell_frequency_link_descriptor
                        break;

                    case 0x73:     // default_authority_descriptor
                        break;

                    case 0x77:     // time_slice_fec_identifier_descriptor
                        break;

                    case 0x79:     // S2_satellite_delivery_system_descriptor
                        break;

                    case 0x7D:     // XAIT location descriptor
                        break;

                    case 0x7E:     // FTA_content_management_descriptor
                        break;

                    case 0x7F:     // extension descriptor
                        break;

                    case 0x83:
                        ReadLCN(section.Data, transOffset + 2, descriptor_length);
                        break;

                    default:
                        break;
                    }

                    transOffset += 2 + descriptor_length;
                }
            }
            IsReady = true;
        }
Exemplo n.º 3
0
        public void OnNewSection(TsSection section)
        {
            ProgramNumber = section.table_id_extension;
            PcrPID        = (ushort)((section.Data[8] & 0x1F) << 8 | section.Data[9]);
            int program_info_length = ((section.Data[10] & 0x0F) << 8) + section.Data[11];
            var offset = 12 + program_info_length;

            while (offset < (section.section_length - 4))
            {
                byte stream_type    = section.Data[offset];
                int  elementary_PID = ((section.Data[offset + 1] & 0x1F) << 8) + section.Data[offset + 2];
                var  pm             = new ProgramMap(elementary_PID, stream_type);
                int  ES_info_length = ((section.Data[offset + 3] & 0x0F) << 8) + section.Data[offset + 4];

                offset += 5;
                int descOffset = offset;
                offset += ES_info_length;
                if (offset > section.section_length)
                {
                    // Oops something must have gone wrong for this to happen
                    //Log.Write(LogLevel.ERROR, "PMTTable: Offset larger than section size");
                    //_pids.Add(pid);
                    return;
                }
                while (descOffset < offset)
                {
                    var descriptor_tag    = section.Data[descOffset];
                    var descriptor_length = section.Data[descOffset];
                    switch (descriptor_tag)
                    {
                    case 0x0A:     // ISO 639 language descriptor
                        int langOffset = descOffset + 2;
                        while (langOffset < descOffset + 2 + descriptor_length)
                        {
                            pm.Language  = ReadString(section.Data, langOffset, 3);
                            pm.AudioType = section.Data[3 + langOffset];
                            langOffset  += 4;
                        }
                        break;

                    case 0x09:     // CA Descriptor
                        var SystemId = section.Data[descOffset + 2] + section.Data[descOffset + 3];
                        var CaPid    = section.Data[descOffset + 4] + section.Data[descOffset + 5];
                        break;

                    case 0x45:     // VBI_data_descriptor
                        break;

                    case 0x46:     // VBI_teletext_descriptor
                        break;

                    case 0x51:     // mosaic_descriptor
                        break;

                    case 0x52:     // stream_identifier_descriptor
                        byte component_tag = section.Data[descOffset + 2];
                        break;

                    case 0x56:     // teletext_descriptor
                        break;

                    case 0x59:     // subtitling_descriptor
                        int lanOffset = descOffset + 2;
                        while (lanOffset < descOffset + 2 + descriptor_length)
                        {
                            var Language            = ReadString(section.Data, lanOffset, 3);
                            var SubtitlingType      = ReadString(section.Data, 3 + lanOffset, 1);
                            var composition_page_id = ReadString(section.Data, 4 + lanOffset, 2);
                            var ancillary_page_id   = ReadString(section.Data, 6 + lanOffset, 2);
                            lanOffset += 8;
                        }
                        break;

                    case 0x5F:     // private_data_specifier_descriptor
                        ReadPrivateDataSpecifierDescriptor(section.Data, descOffset + 2, descriptor_length);
                        break;

                    case 0x60:     // service_move_descriptor
                        break;

                    case 0x65:     // scrambling_descriptor
                        break;

                    case 0x66:     // data_broadcast_id_descriptor
                        break;

                    case 0x6A:     // AC-3_descriptor
                        break;

                    case 0x6B:     // ancillary_data_descriptor
                        break;

                    case 0x6F:     // application_signalling_descriptor
                        break;

                    case 0x70:     // adaptation_field_data_descriptor
                        break;

                    case 0x74:     // related_content_descriptor
                        break;

                    case 0x78:     // ECM_repetition_rate_descriptor
                        break;

                    case 0x7A:     // enhanced_AC-3_descriptor
                        break;

                    case 0x7B:     // DTS® descriptor
                        break;

                    case 0x7C:     // AAC descriptor
                        break;

                    case 0x7D:     // XAIT location descriptor
                        break;

                    case 0x7F:     // extension descriptor
                        break;

                    default:
                        break;
                    }
                    descOffset += descriptor_length + 2;
                }
                //_pids.Add(pm);
            }

            IsReady = true;
        }
Exemplo n.º 4
0
        public override void OnNewSection(TsSection sections)
        {
            if (IsReady)
            {
                return;
            }

            if (sections.table_id_extension != service_id)
            {
                return;
            }
            if (sections.table_id_extension == 6033)
            {
                int xc = 564;
            }
            byte[] section             = sections.Data;
            int    section_length      = sections.section_length;
            int    pcrPid              = ((section[8] & 0x1F) << 8) + section[9];
            int    program_info_length = ((section[10] & 0xF) << 8) + section[11];
            // Skip the descriptors (if any).
            int ndx = 12;

            ndx += program_info_length;
            // Now we have the actual program data.
            while (ndx < section_length - 3)
            {
                int stream_type           = section[ndx++];
                int pid                   = ((section[ndx++] & 0x1f) << 8) + section[ndx++];
                int es_descriptors_length = ((section[ndx++] & 0x0f) << 8) + section[ndx++];
                if (es_descriptors_length > 0)
                {
                    int off = 0;
                    while (off < es_descriptors_length)
                    {
                        int descriptor_tag = section[ndx + off];
                        int descriptor_len = section[ndx + off + 1];
                        switch (descriptor_tag)
                        {
                        case 0x5:
                            //node.Nodes.Add("0x" + descriptor_tag.ToString("x") + " - Registration descriptor: " + StringUtils.getString468A(section, ndx + off + 2, descriptor_len));
                            break;

                        case 0x9:         // CA Descriptor
                            int ca_system_id = (section[ndx + off + 2] << 8) + section[ndx + off + 3];
                            int ca_pid       = ((section[ndx + off + 4] & 0x1f) << 8) + section[ndx + off + 5];
                            //node.Nodes.Add("CA: Pid: 0x" + ca_pid.ToString("x") + " " + StringUtils.CA_System_ID2Str(ca_system_id));
                            break;

                        case 0x0A:         // ISO_639_language
                            //node.Nodes.Add("ISO_639_language: " + StringUtils.getString468A(section, ndx + off + 2, 3));
                            break;

                        case 0x52:
                            //node.Nodes.Add("0x" + descriptor_tag.ToString("x") + " - stream identifier descriptor 0x" + section[ndx + off + 2].ToString("x"));
                            break;

                        case 0x56:         // Teletext
                            //node.Text = "pid: 0x" + pid.ToString("x") + " [Teletext] " + StringUtils.StreamTypeToStr(stream_type);
                            break;

                        case 0x59:         // Subtitles
                            //node.Text = "pid: 0x" + pid.ToString("x") + " [Subtitles] " + StringUtils.StreamTypeToStr(stream_type);
                            break;

                        case 0x6A:         // AC3
                            //node.Text = "pid: 0x" + pid.ToString("x") + " [AC3-Audio] " + StringUtils.StreamTypeToStr(stream_type);
                            break;

                        case 0x5F:         // private data
                            //node.Text = "pid: 0x" + pid.ToString("x") + " [Private Data] " + StringUtils.StreamTypeToStr(stream_type);
                            break;

                        case 0xA1:
                            //node.Nodes.Add("0x" + descriptor_tag.ToString("x") + " - ATSC: service location");
                            break;

                        case 0xA2:
                            //node.Nodes.Add("0x" + descriptor_tag.ToString("x") + " - ATSC: time shifted service");
                            break;

                        case 0xA3:
                            //node.Nodes.Add("0x" + descriptor_tag.ToString("x") + " - ATSC: component name");
                            break;

                        default:
                            //node.Nodes.Add("0x" + descriptor_tag.ToString("x"));
                            break;
                        }
                        off += descriptor_len + 2;
                    }
                }
                ndx += es_descriptors_length;
                if (!streamPids.Contains((ushort)pid))
                {
                    streamPids.Add((ushort)pid);
                }
            }
            IsReady = true;
        }
Exemplo n.º 5
0
        public void OnNewSection(TsSection section)
        {
            TransportStreamId = section.table_id_extension;
            int OriginalNetworkID = (section.Data[8] << 8) + section.Data[9];
            int offset            = 11;

            while (offset < section.section_length - 4)
            {
                _serviceDescription                         = new ServiceDescription();
                _serviceDescription.ServiceID               = (ushort)((section.Data[offset] << 8) + section.Data[offset + 1]);
                _serviceDescription.EitScheduleFlag         = ((section.Data[offset + 2] & 0x02) != 0);
                _serviceDescription.EitPresentFollowingFlag = ((section.Data[offset + 2] & 0x01) != 0);
                _serviceDescription.RunningStatus           = (RunningStatus)((section.Data[offset + 3] >> 5) & 0x07);
                _serviceDescription.FreeCaMode              = (((section.Data[offset + 3] >> 4) & 0x01) != 0);
                var DescriptorsLoopLength = (ushort)(((section.Data[offset + 3] << 8) | section.Data[offset + 4]) & 0xfff);
                offset += 5;
                int descOffset = offset;
                offset += DescriptorsLoopLength;
                while (descOffset < offset)
                {
                    var descriptor_tag    = section.Data[descOffset];
                    var descriptor_length = section.Data[descOffset];
                    switch (descriptor_tag)
                    {
                    case 0x42:     // stuffing_descriptor
                        break;

                    case 0x48:     // service_descriptor
                        ReadServiceDescriptor(section.Data, descOffset + 2);
                        break;

                    case 0x49:     // country_availability_descriptor
                        break;

                    case 0x4A:     // linkage_descriptor
                        break;

                    case 0x4B:     // NVOD_reference_descriptor
                        break;

                    case 0x4C:     // time_shifted_service_descriptor
                        break;

                    case 0x50:     // component_descriptor
                        ReadComponentDescriptor(section.Data, descOffset + 2, descriptor_length);
                        break;

                    case 0x51:     // mosaic_descriptor
                        break;

                    case 0x53:     // CA_identifier_descriptor
                        break;

                    case 0x57:     // telephone_descriptor
                        break;

                    case 0x5D:     // multilingual_service_name_descriptor
                        break;

                    case 0x5F:     // private_data_specifier_descriptor
                        ReadPrivateDataSpecifierDescriptor(section.Data, descOffset + 2, descriptor_length);
                        break;

                    case 0x64:     // data_broadcast_descriptor
                        break;

                    case 0x6E:     // announcement_support_descriptor
                        break;

                    case 0x71:     // service_identifier_descriptor
                        break;

                    case 0x72:     // service_availability_descriptor
                        break;

                    case 0x73:     // default_authority_descriptor
                        break;

                    case 0x7D:     // XAIT location descriptor
                        break;

                    case 0x7E:     // FTA_content_management_descriptor
                        break;

                    case 0x7F:     // extension descriptor
                        break;

                    default:
                        break;
                    }
                    descOffset += descriptor_length + 2;
                }
                if (!_serviceDescriptions.ContainsKey(_serviceDescription.ServiceID))
                {
                    _serviceDescriptions.Add(_serviceDescription.ServiceID, _serviceDescription);
                }
            }
            IsReady = true;
        }
Exemplo n.º 6
0
 public virtual void OnNewSection(TsSection section)
 {
 }
Exemplo n.º 7
0
 public TsSectionDecoder(ushort pid, int table_id)
 {
     _pid     = pid;
     _tableId = table_id;
     _section = new TsSection();
 }
Exemplo n.º 8
0
 public TsSectionDecoder()
 {
     _pid     = 8191;
     _tableId = -1;
     _section = new TsSection();
 }
Exemplo n.º 9
0
        public void OnNewSection(TsSection section)
        {
            TransportStreamId = section.table_id_extension;

            int network_descriptor_length = ((section.Data[8] & 0xF) << 8) + section.Data[9];

            int    l1           = network_descriptor_length;
            int    pointer      = 10;
            string network_name = "";

            while (l1 > 0)
            {
                int descriptor_tag = section.Data[pointer];
                int x = section.Data[pointer + 1] + 2;
                if (descriptor_tag == 0x40)
                {
                    network_name = Utils.ReadString(section.Data, pointer + 2, x - 2);
                }
                l1      -= x;
                pointer += x;
            }

            pointer = 10 + network_descriptor_length;

            if (pointer > section.section_length)
            {
                return;
            }

            int transport_stream_loop_length = ((section.Data[pointer] & 0xF) << 8) + section.Data[pointer + 1];

            l1       = transport_stream_loop_length;
            pointer += 2;

            while (l1 > 0)
            {
                if (pointer + 2 > section.section_length)
                {
                    return;
                }

                int transport_stream_id = (section.Data[pointer] << 8) + section.Data[pointer + 1];
                int original_network_id = (section.Data[pointer + 2] << 8) + section.Data[pointer + 3];

                ulong key = (ulong)(original_network_id << 16);
                key += (ulong)transport_stream_id;

                int transport_descriptor_length = ((section.Data[pointer + 4] & 0xF) << 8) + section.Data[pointer + 5];
                netInfo  = new NetworkInfo(network_name, transport_stream_id, original_network_id);
                pointer += 6;
                l1      -= 6;
                int l2 = transport_descriptor_length;

                while (l2 > 0)
                {
                    if (pointer + 2 > section.section_length)
                    {
                        return;
                    }

                    int descriptor_tag    = section.Data[pointer];
                    int descriptor_length = section.Data[pointer + 1] + 2;

                    switch (descriptor_tag)
                    {
                    case 0x43:     // sat
                        DVB_GetSatDelivSys(section.Data, pointer, descriptor_length);
                        break;

                    case 0x44:     // cable
                        DVB_GetCableDelivSys(section.Data, pointer, descriptor_length);
                        break;

                    case 0x5A:     // terrestrial
                        DVB_GetTerrestrialDelivSys(section.Data, pointer, descriptor_length);
                        break;

                    case 0x83:     // logical channel number
                        DVB_GetLogicalChannelNumber(original_network_id, transport_stream_id, section.Data, pointer);
                        break;
                    }
                    pointer += descriptor_length;
                    l2      -= descriptor_length;
                    l1      -= descriptor_length;
                    if (!_networkInformations.ContainsKey(transport_stream_id))
                    {
                        _networkInformations.Add(transport_stream_id, netInfo);
                    }
                }
                //if (netInfo.netType != NetworkType.Unknown)
                //    baseNode.Text = "NIT " + netInfo.netType.ToString();
                //if (!seenNITs.Contains(netInfo.frequency))
                //{
                //    netInfo.AddToNode(baseNode, (section.table_id == 0x41));
                //    seenNITs.Add(netInfo.frequency);
                //}
            }
            IsReady = true;
        }
Exemplo n.º 10
0
 public TsSectionDecoder()
 {
     m_pid     = 0x1fff;
     m_tableId = -1;
     m_section = new TsSection();
 }