Пример #1
0
 public SectionReceivedEventArgs(DvbStpHeader header, SegmentAssembler assembler)
     : base(header)
 {
     ReceivedSections  = assembler.ReceivedSections;
     RemainingSections = assembler.RemainingSections;
     ReceivedBytes     = assembler.ReceivedBytes;
     RemainingBytes    = header.TotalSegmentSize - ReceivedBytes;
 } // constructor
Пример #2
0
        } // AddSection

        private void OnSegmentStarted(DvbStpHeader header)
        {
            if (SegmentStarted == null)
            {
                return;
            }

            var args = new PayloadStorage.SegmentStartedEventArgs(header);

            SegmentStarted(this, args);
        } // OnSegmentStarted
Пример #3
0
        } // OnSegmentStarted

        private void OnSectionReceived(DvbStpHeader header, SegmentAssembler assembler)
        {
            if (SectionReceived == null)
            {
                return;
            }

            var args = new PayloadStorage.SectionReceivedEventArgs(header, assembler);

            SectionReceived(this, args);
        } // OnSectionReceived
Пример #4
0
        } // constructor

        public void ExploreMulticastStream()
        {
            try
            {
                Connect();

                CancelRequested    = false;
                EndLoop            = false;
                StartSectionNumber = -1;
                while (!(CancelRequested || EndLoop))
                {
                    Receive(true);

                    if (StartSectionNumber == -1)
                    {
                        LastHeader = Header.Clone();
                        LastHeader.SectionNumber--;
                        InitRun();
                    } // if

                    if (Header.Version != 0)
                    {
                        OnUnexpectedHeaderVersionReceived();
                    }
                    else
                    {
                        OnSectionReceived();
                    } // if-else

                    if ((Header.PayloadId != LastHeader.PayloadId) ||
                        (Header.SegmentId != LastHeader.SegmentId) ||
                        (Header.SegmentVersion != LastHeader.SegmentVersion) ||
                        (Header.SectionNumber != LastHeader.SectionNumber + 1))
                    {
                        OnRunEnded();
                        InitRun();
                    } // if

                    ReceivedPayloadBytes += Header.PayloadSize;
                    ReceivedHeaders.Add(Header.Clone());
                    LastHeader = Header.Clone();
                } // while

                if (!CancelRequested)
                {
                    OnRunEnded();
                } // if
            }
            finally
            {
                Close();
            } //
        }     // ExplorerMulticastStream
Пример #5
0
        } // Connect

        protected void Receive(bool decodeHeader = false)
        {
            ReceivedBytes  = Socket.Receive(DatagramData);
            DatagramCount += 1;

            if (ReceivedBytes < DvbStpHeader.MinHeaderLength)
            {
                throw new InvalidDataException("ReceivedBytes < MinHeaderLength");
            }

            Header = (decodeHeader)? DvbStpHeader.Decode(DatagramData, ReceivedBytes) : DvbStpHeader.PartialDecode(DatagramData);
        } // Receive
Пример #6
0
        } // constructor

        public bool AddSection(DvbStpHeader header, byte[] data, bool isRawData)
        {
            var p   = (int)header.PayloadId;
            var s   = header.SegmentId;
            var key = ((p << 16) | s);

            if (!_sections.TryGetValue(key, out var versions))
            {
                versions       = CreateNewVersions(header);
                _sections[key] = versions;
            } // if

            return(versions.AddSection(header, data, isRawData));
        } // AddSection
Пример #7
0
        }     // Receive

        protected void DecodeBasicHeader()
        {
            Header         = new DvbStpHeader();
            Header.Version = (byte)(DatagramData[0] & DvbStpHeaderMasks.Version);

            // byte 4
            Header.PayloadId = DatagramData[4];

            // byte 5-6
            Header.SegmentIdNetworkLo = DatagramData[5];
            Header.SegmentIdNetworkHi = DatagramData[6];

            // byte 7
            Header.SegmentVersion = DatagramData[7];
        } // DecodeBasicHeader
Пример #8
0
        } // enum CompressionMethod

        public static DvbStpHeader PartialDecode(byte[] headerData)
        {
            var header = new DvbStpHeader
            {
                Version = (byte)(headerData[0] & DvbStpHeaderMasks.Version),

                // byte 4
                PayloadId = headerData[4],

                // byte 5-6
                SegmentIdNetworkLo = headerData[5],
                SegmentIdNetworkHi = headerData[6],

                // byte 7
                SegmentVersion = headerData[7]
            };

            return(header);
        } // PartialDecode
Пример #9
0
        } // constructor

        public bool AddSection(DvbStpHeader header, byte[] data, bool isRawData)
        {
            SegmentAssembler assembler;
            bool             newSection;

            if (!Versions.TryGetValue(header.SegmentVersion, out assembler))
            {
                assembler = new SegmentAssembler(new DvbStpSegmentIdentity(header), header.LastSectionNumber);
                Versions[header.SegmentVersion] = assembler;
                OnSegmentStarted(header);
            } // if

            if (SaveData)
            {
                if (isRawData)
                {
                    newSection = assembler.AddSectionData(header.SectionNumber, data, header.PayloadOffset, header.PayloadSize);
                }
                else
                {
                    newSection = assembler.AddSectionData(header.SectionNumber, data, 0, data.Length);
                } // if-else
            }
            else
            {
                newSection = assembler.AddSectionData(header.SectionNumber, PayloadStorage.EmptyData, 0, 0);
            } // if-else

            if (newSection)
            {
                OnSectionReceived(header, assembler);
                if (assembler.IsSegmentComplete)
                {
                    OnSegmentReceived(assembler);
                    // discard data
                    assembler = null;
                    Versions.Remove(header.SegmentVersion);
                } // if
            }     // if

            return(newSection);
        } // AddSection
Пример #10
0
        } // AddSection

        private VersionStorage CreateNewVersions(DvbStpHeader header)
        {
            VersionStorage versions;

            versions = new VersionStorage(header.PayloadId, header.SegmentId, SaveData);
            if (SegmentStarted != null)
            {
                versions.SegmentStarted += Versions_SegmentStarted;
            } // if
            if (SectionReceived != null)
            {
                versions.SectionReceived += Versions_SectionReceived;
            } // if
            if (SegmentReceived != null)
            {
                versions.SegmentReceived += Versions_SegmentReceived;
            } // if
            if (SegmentPayloadReceived != null)
            {
                versions.SegmentPayloadReceived += Versions_SegmentPayloadReceived;
            } // if

            return(versions);
        } // CreateNewVersions
Пример #11
0
 public SegmentStartedEventArgs(DvbStpHeader header)
     : base(header)
 {
 } // constructor
Пример #12
0
 public StorageHeaderEventArgs(DvbStpHeader header)
 {
     Header = header.Clone();
 } // constructor
Пример #13
0
        } // constructor

        public DvbStpSegmentIdentity(DvbStpHeader header)
            : this(header.PayloadId, header.SegmentId, header.SegmentVersion)
        {
        } // constructor