Example #1
0
        private void _packetLoop()
        {
            _packets = new List <Packet>();
            _flv     = new File(_flvStream);

            while (!Stop)
            {
                Packet packet;
                if ((packet = _wedge.Parse()) != null)
                {
                    //packets.Add(packet);
                    var media = packet.Payload as IMedia;
                    if (media != null)
                    {
                        IMedia im = media;

                        if (!(im.FlvTag.Type == TagType.VIDEO && im.FlvTag.PayloadSize <= 5) &&
                            !(im.FlvTag.Type == TagType.AUDIO && im.FlvTag.PayloadSize <= 1))
                        {
                            _flv.AddTag(im.FlvTag);
                        }
                    }
                    if (packet.Type == PayloadType.AGGREGATE)
                    {
                        var  a                = (Aggregate)packet.Payload;
                        long baseTimestamp    = 0;
                        bool setBaseTimestamp = false;

                        foreach (AggregateMessage message in a.Messages)
                        {
                            if (!setBaseTimestamp)
                            {
                                setBaseTimestamp = true;
                                baseTimestamp    = message.Timestamp;
                            }

                            message.Payload.FlvTag.TimeStamp =
                                (uint)(packet.TimeStamp + (int)message.Payload.FlvTag.TimeStamp - baseTimestamp);
                            _flv.AddTag(message.Payload.FlvTag);
                        }
                    }

                    if (_wedge.Operations.ContainsKey(packet.ChunkStreamId) &&
                        _wedge.Operations[packet.ChunkStreamId].Call == null)
                    {
                        _wedge.Operations.Remove(packet.ChunkStreamId);
                    }

                    if (OnPacketReceived != null)
                    {
                        OnPacketReceived(packet, new EventArgs());
                    }
                }
            }
        }
Example #2
0
        private void _packetLoop()
        {
            _packets = new List<Packet>();
            _flv = new File(_flvStream);

            while (!Stop)
            {
                Packet packet;
                if ((packet = _wedge.Parse()) != null)
                {
                    //packets.Add(packet);
                    var media = packet.Payload as IMedia;
                    if (media != null)
                    {
                        IMedia im = media;

                        if (!(im.FlvTag.Type == TagType.VIDEO && im.FlvTag.PayloadSize <= 5) &&
                            !(im.FlvTag.Type == TagType.AUDIO && im.FlvTag.PayloadSize <= 1))
                        {
                            _flv.AddTag(im.FlvTag);
                        }
                    }
                    if (packet.Type == PayloadType.AGGREGATE)
                    {
                        var a = (Aggregate) packet.Payload;
                        long baseTimestamp = 0;
                        bool setBaseTimestamp = false;

                        foreach (AggregateMessage message in a.Messages)
                        {
                            if (!setBaseTimestamp)
                            {
                                setBaseTimestamp = true;
                                baseTimestamp = message.Timestamp;
                            }

                            message.Payload.FlvTag.TimeStamp =
                                (uint) (packet.TimeStamp + (int) message.Payload.FlvTag.TimeStamp - baseTimestamp);
                            _flv.AddTag(message.Payload.FlvTag);
                        }
                    }

                    if (_wedge.Operations.ContainsKey(packet.ChunkStreamId) &&
                        _wedge.Operations[packet.ChunkStreamId].Call == null)
                        _wedge.Operations.Remove(packet.ChunkStreamId);

                    if (OnPacketReceived != null)
                    {
                        OnPacketReceived(packet, new EventArgs());
                    }
                }
            }
        }