Beispiel #1
0
        private bool GetSDT(UdpClient client, IPEndPoint endpoint, out SDTParser sdt)
        {
            sdt = new SDTParser();
            bool retval = false;

            while (!retval)
            {
                var       receivedbytes = client.Receive(ref endpoint);
                RtpPacket h             = RtpPacket.Decode(receivedbytes);

                if ((receivedbytes.Length > 12) && ((receivedbytes.Length - 12) % 188) == 0)
                {
                    double num9 = (((double)(receivedbytes.Length - 12)) / 188.0) - 1.0;
                    for (double j = 0.0; j <= num9; j++)
                    {
                        byte[] destinationarray = (byte[])Array.CreateInstance(typeof(byte), 188);
                        Array.Copy(receivedbytes, (int)Math.Round((double)(12.0 + (j * 188))), destinationarray, 0, 188);

                        sdt.OnTsPacket(destinationarray);
                        if (sdt.IsReady)
                        {
                            retval = true;
                        }
                    }
                }
            }

            return(retval);
        }
Beispiel #2
0
        private void RtpListenerThread()
        {
            try
            {
                try
                {
                    while (!_rtpListenerThreadStopEvent.WaitOne(1))
                    {
                        var receivedbytes = _udpClient.Receive(ref _serverEndPoint);
                        var packet        = RtpPacket.Decode(receivedbytes);
                        OnPacketReceived(new RtpPacketReceivedArgs(packet));
                    }
                }
                finally
                {
                    switch (_transmissionMode)
                    {
                    case TransmissionMode.Multicast:
                        _udpClient.DropMulticastGroup(_multicastEndPoint.Address);
                        _udpClient.Close();
                        break;

                    case TransmissionMode.Unicast:
                        _udpClient.Close();
                        break;
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                Logger.Error("SAT>IP : RTP listener thread exception", ex);
                return;
            }

            Logger.Warn("SAT>IP : RTP listener thread stopping");
        }
Beispiel #3
0
        private void DoScan()
        {
            _decoder.TableChangeDetected += _decoder_TableChangeDetected;
            List <ProgramMapTable> programMapTables = new List <ProgramMapTable>();

            _isScanning   = true;
            _stopScanning = false;
            SetControlPropertyThreadSafe(btnScan, "Text", "Stop Search");
            foreach (var mapping in _mappings)
            {
                IniReader reader = new IniReader(mapping.Mapping.File);
                var       Count  = reader.ReadInteger("DVB", "0", 0);
                try
                {
                    var    Index  = 1;
                    string source = mapping.Source;
                    string tuning;
                    while (Index <= Count)
                    {
                        programMapTables.Clear();
                        patfound  = false;
                        pmtsfound = false;
                        nitfound  = false;
                        sdtfound  = false;
                        SetControlPropertyThreadSafe(lblPat, "BackColor", Color.LightGreen);
                        SetControlPropertyThreadSafe(lblPmt, "BackColor", Color.LightGreen);
                        SetControlPropertyThreadSafe(lblSdt, "BackColor", Color.LightGreen);
                        SetControlPropertyThreadSafe(lblNit, "BackColor", Color.LightGreen);
                        if (_stopScanning)
                        {
                            return;
                        }
                        float percent = ((float)(Index)) / Count;
                        percent *= 100f;
                        if (percent > 100f)
                        {
                            percent = 100f;
                        }
                        SetControlPropertyThreadSafe(pgbSearchResult, "Value", (int)percent);
                        string[] strArray = reader.ReadString("DVB", Index.ToString()).Split(new char[] { ',' });

                        if (strArray[4] == "C2")
                        {
                            //rtsp://192.168.128.5/?freq=793.982&bw=8&msys=dvbc2&c2tft=0&ds=0&plp=0&pids=0,16,100,308,256
                            tuning = string.Format("freq={0}&bw={1}&msys=dvbc2&c2tft={2}&ds={3}&plp={4}&pids=0", source, strArray[0].ToString(), strArray[1].ToLower().ToString(), strArray[2].ToLower().ToString(), strArray[3].ToString(), strArray[5].ToLower().ToString());
                        }
                        else
                        {
                            //rtsp://192.168.128.5/?freq=623.25&msys=dvbc&mtype=256qam&sr=6900&specinv=0&pids=0,16,50,201,301
                            tuning = string.Format("freq={0}&msys=dvbc&mtype={1}&sr={2}&specinv={3}&pids=0", source, strArray[0].ToString(), strArray[1].ToLower().ToString(), strArray[2].ToString(), strArray[3].ToString(), strArray[5].ToLower().ToString());
                        }

                        RtspStatusCode statuscode;
                        if (string.IsNullOrEmpty(_device.RtspSession.SessionID))
                        {
                            _device.RtspSession.Options();
                            _device.RtspSession.Setup(tuning, TransmissionMode.Unicast);
                            _device.RtspSession.Play(string.Empty);
                            _udpclient      = new UdpClient(_device.RtspSession.RtpPort);
                            _remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
                            _device.RtspSession.RecieptionInfoChanged += RtspSession_RecieptionInfoChanged;
                            _device.RtspSession.Play(tuning);
                        }
                        else
                        {
                            _device.RtspSession.Play(tuning);
                        }
                        /* Say the Sat>IP server we want Receives the Recieption Details SDP */
                        statuscode = _device.RtspSession.Describe();
                        if (_locked)
                        {
                            while ((!patfound) || (!pmtsfound) || (!sdtfound))
                            {
                                var       receivedbytes = _udpclient.Receive(ref _remoteEndPoint);
                                RtpPacket rtp           = RtpPacket.Decode(receivedbytes);
                                if (rtp.HasPayload)
                                {
                                    Logger.Write(Utils.ToHexString(rtp.Payload));
                                    _decoder.AddData(receivedbytes);
                                }
                            }
                            lock (_decoder)
                            {
                                programMapTables = _decoder?.ProgramMapTables.OrderBy(p => p.ProgramNumber).ToList();
                                foreach (var programMapTable in programMapTables)
                                {
                                    short videoPid = -1;
                                    short audioPid = -1;
                                    short ac3pid   = -1;
                                    short ttxpid   = -1;
                                    short subpid   = -1;
                                    short aacpid   = -1;
                                    short dtspid   = -1;
                                    short eac3pid  = -1;
                                    var   desc     = _decoder.GetServiceDescriptorForProgramNumber(programMapTable?.ProgramNumber);
                                    if (desc != null)
                                    {
                                        if (programMapTable?.EsStreams != null)
                                        {
                                            foreach (var stream in programMapTable.EsStreams)
                                            {
                                                if (stream != null)
                                                {
                                                    if (stream.Descriptors.OfType <Ac3Descriptor>().Any())
                                                    {
                                                        ac3pid = stream.ElementaryPid;
                                                    }
                                                    if (stream.Descriptors.OfType <Eac3Descriptor>().Any())
                                                    {
                                                        eac3pid = stream.ElementaryPid;
                                                    }
                                                    if (stream.Descriptors.OfType <AACDescriptor>().Any())
                                                    {
                                                        aacpid = stream.ElementaryPid;
                                                    }
                                                    if (stream.Descriptors.OfType <DTSDescriptor>().Any())
                                                    {
                                                        dtspid = stream.ElementaryPid;
                                                    }
                                                    if (stream.Descriptors.OfType <SubtitlingDescriptor>().Any())
                                                    {
                                                        subpid = stream.ElementaryPid;
                                                    }
                                                    if (stream.Descriptors.OfType <TeletextDescriptor>().Any())
                                                    {
                                                        ttxpid = stream.ElementaryPid;
                                                    }
                                                    switch (stream.StreamType)
                                                    {
                                                    case 0x01:     // ISO/IEC 11172-2 (MPEG-1 video) in a packetized stream
                                                    case 0x02:     // ITU-T Rec. H.262 and ISO/IEC 13818-2 (MPEG-2 higher rate interlaced video) in a packetized stream
                                                    case 0x1B:     // ITU-T Rec. H.264 and ISO/IEC 14496-10 (lower bit-rate video) in a packetized stream
                                                    case 0x24:     // ITU - T Rec.H.265 and ISO/ IEC 23008 - 2(Ultra HD video) in a packetized stream
                                                    {
                                                        videoPid = stream.ElementaryPid;
                                                        break;
                                                    }

                                                    case 0x03:     // ISO/IEC 11172-3 (MPEG-1 audio) in a packetized stream
                                                    case 0x04:     // ISO/IEC 13818-3 (MPEG-2 halved sample rate audio) in a packetized stream

                                                    {
                                                        audioPid = stream.ElementaryPid;
                                                        break;
                                                    }

                                                    default:
                                                    { Console.Write(stream.StreamType.ToString()); break; }
                                                    }
                                                }
                                            }
                                        }

                                        var chan = new Channel
                                        {
                                            ServiceType             = desc.ServiceType,
                                            ServiceName             = desc.ServiceName.Value,
                                            ServiceProvider         = desc.ServiceProviderName.Value,
                                            ServiceId               = programMapTable.ProgramNumber,
                                            ProgramClockReferenceId = programMapTable.PcrPid,
                                            AudioPid    = audioPid,
                                            VideoPid    = videoPid,
                                            AC3Pid      = ac3pid,
                                            EAC3Pid     = eac3pid,
                                            AACPid      = aacpid,
                                            DTSPid      = dtspid,
                                            TTXPid      = ttxpid,
                                            SubTitlePid = subpid
                                        };
                                        AddResults(chan);
                                    }
                                }
                            }
                        }
                        Thread.Sleep(5000);
                        Index++;
                    }
                }
                catch
                {
                }
            }
            _device.RtspSession.TearDown();
            SetControlPropertyThreadSafe(pgbSearchResult, "Value", 100);
            _isScanning = false;
            SetControlPropertyThreadSafe(btnScan, "Text", "Start Search");
            StopScanThread();
        }
Beispiel #4
0
        private void btnScan_Click(object sender, EventArgs e)
        {
            if (lvResult.Items.Count > 0)
            {
                lvResult.Items.Clear();
            }
            //StartScanThread();
            _decoder.TableChangeDetected += _decoder_TableChangeDetected;
            var programMapTables = new List <ProgramMapTable>();

            _isScanning   = true;
            _stopScanning = false;
            SetControlPropertyThreadSafe(btnScan, "Text", "Stop Search");
            programMapTables.Clear();
            patfound  = false;
            pmtsfound = false;
            nitfound  = false;
            sdtfound  = false;
            SetControlPropertyThreadSafe(lblPat, "BackColor", Color.LightGreen);
            SetControlPropertyThreadSafe(lblPmt, "BackColor", Color.LightGreen);
            SetControlPropertyThreadSafe(lblSdt, "BackColor", Color.LightGreen);
            SetControlPropertyThreadSafe(lblNit, "BackColor", Color.LightGreen);
            if (_stopScanning)
            {
                return;
            }

            RtspStatusCode statuscode;

            if (string.IsNullOrEmpty(_device.RtspSession.SessionID))
            {
                _device.RtspSession.Options();
                _device.RtspSession.Setup(_currenttunestring, TransmissionMode.Unicast);
                _device.RtspSession.Play(_currenttunestring);
                _udpclient      = new UdpClient(_device.RtspSession.RtpPort);
                _remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
                _device.RtspSession.RecieptionInfoChanged += RtspSession_RecieptionInfoChanged;
            }
            else
            {
                _device.RtspSession.Play(_currenttunestring);
            }

            /* Say the Sat>IP server we want Receives the Recieption Details SDP */
            statuscode = _device.RtspSession.Describe();

            if (_locked)
            {
                while (!patfound || !pmtsfound || !sdtfound || !nitfound)
                {
                    var receivedbytes = _udpclient.Receive(ref _remoteEndPoint);
                    var rtp           = RtpPacket.Decode(receivedbytes);
                    if (rtp.HasPayload)
                    {
                        var packets = packetFactory.GetTsPacketsFromData(rtp.Payload);

                        Logger.Write(rtp.Payload.ToHexString());
                        _decoder.AddData(receivedbytes);
                    }

                    //}
                    lock (_decoder)
                    {
                        programMapTables = _decoder?.ProgramMapTables.OrderBy(p => p.ProgramNumber).ToList();
                        foreach (var programMapTable in programMapTables)
                        {
                            short videoPid = -1;
                            short audioPid = -1;
                            short ac3pid   = -1;
                            short ttxpid   = -1;
                            short subpid   = -1;
                            var   desc     = _decoder.GetServiceDescriptorForProgramNumber(programMapTable?.ProgramNumber);
                            if (desc != null)
                            {
                                if (programMapTable?.EsStreams != null)
                                {
                                    foreach (var stream in programMapTable.EsStreams)
                                    {
                                        if (stream != null)
                                        {
                                            if (stream.Descriptors.OfType <Ac3Descriptor>().Any())
                                            {
                                                ac3pid = stream.ElementaryPid;
                                            }
                                            if (stream.Descriptors.OfType <Eac3Descriptor>().Any())
                                            {
                                                ac3pid = stream.ElementaryPid;
                                            }
                                            if (stream.Descriptors.OfType <SubtitlingDescriptor>().Any())
                                            {
                                                subpid = stream.ElementaryPid;
                                            }
                                            if (stream.Descriptors.OfType <TeletextDescriptor>().Any())
                                            {
                                                ttxpid = stream.ElementaryPid;
                                            }
                                            switch (stream.StreamType)
                                            {
                                            case 0x01: // ISO/IEC 11172-2 (MPEG-1 video) in a packetized stream
                                            case 0x02
                                                :      // ITU-T Rec. H.262 and ISO/IEC 13818-2 (MPEG-2 higher rate interlaced video) in a packetized stream
                                            case 0x1B
                                                :      // ITU-T Rec. H.264 and ISO/IEC 14496-10 (lower bit-rate video) in a packetized stream
                                            case 0x24
                                                :      // ITU - T Rec.H.265 and ISO/ IEC 23008 - 2(Ultra HD video) in a packetized stream
                                            {
                                                videoPid = stream.ElementaryPid;
                                                break;
                                            }

                                            case 0x03: // ISO/IEC 11172-3 (MPEG-1 audio) in a packetized stream
                                            case 0x04
                                                :      // ISO/IEC 13818-3 (MPEG-2 halved sample rate audio) in a packetized stream

                                            {
                                                audioPid = stream.ElementaryPid;
                                                break;
                                            }

                                            default:
                                            {
                                                Console.Write(stream.StreamType.ToString());
                                                break;
                                            }
                                            }
                                        }
                                    }
                                }

                                var chan = new Channel
                                {
                                    ServiceType             = desc.ServiceType,
                                    ServiceName             = desc.ServiceName.Value,
                                    ServiceProvider         = desc.ServiceProviderName.Value,
                                    ServiceId               = programMapTable.ProgramNumber,
                                    ProgramClockReferenceId = programMapTable.PcrPid,
                                    AudioPid    = audioPid,
                                    VideoPid    = videoPid,
                                    AC3Pid      = ac3pid,
                                    TTXPid      = ttxpid,
                                    SubTitlePid = subpid
                                };
                                AddResults(chan);
                            }
                        }
                    }
                }

                //Thread.Sleep(55000);
                _device.RtspSession.TearDown();
                SetControlPropertyThreadSafe(pgbSearchResult, "Value", 100);
                _isScanning = false;
                SetControlPropertyThreadSafe(btnScan, "Text", "Start Search");
            }
        }