Ejemplo n.º 1
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            int bytesRead = 0;
            long internalBufferPos;

            if (_readBuffer.Length - _readBuffer.Position >= count)
            {
                return _readBuffer.Read(buffer, offset, count);
            }

            byte[] packetBuffer = new byte[_asfConfig.AsfPacketSize];

            internalBufferPos = _readBuffer.Position;
            _readBuffer.Seek(0, SeekOrigin.End);

            while (_readBuffer.Length - internalBufferPos < count)
            {
                //fill buffer
                if (!_isHeaderStreamed && StreamType != AsfStreamType.asfUnaltered)
                {
                    byte[] headerData = _asfFile.GetStreamingHeader();
                     _readBuffer.Write(headerData, 0, headerData.Length);
                    _isHeaderStreamed = true;
                }
                else
                {
                    bytesRead = _asfFile.Read(packetBuffer, 0,  (int)_asfConfig.AsfPacketSize);
                    if (bytesRead == _asfConfig.AsfPacketSize)
                    {
                        AsfPacket currentPacket = new AsfPacket(_asfConfig, packetBuffer);
                        if (_isFirstPacket)
                        {
                            _streamInfo.ResetMediaObjects();
                            _streamInfo.StartSendTime = currentPacket.SendTime;
                            currentPacket.SetStart(Configuration, _streamInfo);
                            _isFirstPacket = false;
                        }
                        currentPacket.SetFollowup(Configuration, _streamInfo);
                        _readBuffer.Write(packetBuffer, 0, bytesRead);
                    }
                    else
                        break;
                }
            }

            //the memory buffer now contains enough bytes to satisfy the request
            _readBuffer.Seek(internalBufferPos, SeekOrigin.Begin);
            bytesRead = _readBuffer.Read(buffer, offset, count);

            if (_readBuffer.Length > _maxInternalBufferLength)
            {
                int bytesLeft = (int)(_readBuffer.Length - _readBuffer.Position);

                byte[] tempStreamBuffer = new byte[bytesLeft];

                _readBuffer.Read(tempStreamBuffer, 0, bytesLeft);
                _readBuffer = new MemoryStream();
                _readBuffer.Write(tempStreamBuffer, 0, bytesLeft);
                _readBuffer.Seek(0, SeekOrigin.Begin);
                _allowSeekBack = false;
            }
            return bytesRead;
        }
Ejemplo n.º 2
0
        public void TryCreateInvalidPacket()
        {
            AsfFile asfFile = new AsfFile(testVideoFileName);
            long offsetFirstPacket = asfFile.PacketConfiguration.AsfHeaderSize;

            using (FileStream fs = new FileStream(testVideoFileName, FileMode.Open, FileAccess.Read))
            {
                fs.Seek(offsetFirstPacket, SeekOrigin.Begin);
                byte[] packetData = new byte[asfFile.PacketConfiguration.AsfPacketSize];
                fs.Read(packetData, 0, (int)asfFile.PacketConfiguration.AsfPacketSize);
                packetData[0] = 1;
                packetData[1] = 1;
                AsfPacket packet = new AsfPacket(asfFile.PacketConfiguration, packetData);
            }
        }
Ejemplo n.º 3
0
        public void CompareFirstDataPacket()
        {
            AsfFile asfFile = new AsfFile(testVideoFileName);
            long offsetFirstPacket = asfFile.PacketConfiguration.AsfHeaderSize;

            using (FileStream fs = new FileStream(testVideoFileName, FileMode.Open, FileAccess.Read))
            {
                fs.Seek(offsetFirstPacket, SeekOrigin.Begin);
                byte[] packetData = new byte[asfFile.PacketConfiguration.AsfPacketSize];
                fs.Read(packetData, 0, (int)asfFile.PacketConfiguration.AsfPacketSize);

                AsfPacket packet = new AsfPacket(asfFile.PacketConfiguration, packetData);

                Assert.AreEqual(packet.SendTime, asfFile.PacketConfiguration.Packets[0].SendTime);
                Assert.AreEqual(packet.Payload.Count, asfFile.PacketConfiguration.Packets[0].Payload.Count);
                for(int i=0;i< packet.Payload.Count;i++)
                {
                    Assert.AreEqual(packet.Payload[i].PresentationTimeOffset, asfFile.PacketConfiguration.Packets[0].Payload[i].PresentationTimeOffset);
                    Assert.AreEqual(packet.Payload[i].PresentationTime, asfFile.PacketConfiguration.Packets[0].Payload[i].PresentationTime);
                    Assert.AreEqual(packet.Payload[i].StreamIDOffset, asfFile.PacketConfiguration.Packets[0].Payload[i].StreamIDOffset);
                    Assert.AreEqual(packet.Payload[i].StreamId, asfFile.PacketConfiguration.Packets[0].Payload[i].StreamId);
                }
            }
        }
Ejemplo n.º 4
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            int  bytesRead = 0;
            long internalBufferPos;

            if (_readBuffer.Length - _readBuffer.Position >= count)
            {
                return(_readBuffer.Read(buffer, offset, count));
            }

            byte[] packetBuffer = new byte[_asfConfig.AsfPacketSize];

            internalBufferPos = _readBuffer.Position;
            _readBuffer.Seek(0, SeekOrigin.End);

            while (_readBuffer.Length - internalBufferPos < count)
            {
                //fill buffer
                if (!_isHeaderStreamed && StreamType != AsfStreamType.asfUnaltered)
                {
                    byte[] headerData = _asfFile.GetStreamingHeader();
                    _readBuffer.Write(headerData, 0, headerData.Length);
                    _isHeaderStreamed = true;
                }
                else
                {
                    bytesRead = _asfFile.Read(packetBuffer, 0, (int)_asfConfig.AsfPacketSize);
                    if (bytesRead == _asfConfig.AsfPacketSize)
                    {
                        AsfPacket currentPacket = new AsfPacket(_asfConfig, packetBuffer);
                        if (_isFirstPacket)
                        {
                            _streamInfo.ResetMediaObjects();
                            _streamInfo.StartSendTime = currentPacket.SendTime;
                            currentPacket.SetStart(Configuration, _streamInfo);
                            _isFirstPacket = false;
                        }
                        currentPacket.SetFollowup(Configuration, _streamInfo);
                        _readBuffer.Write(packetBuffer, 0, bytesRead);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            //the memory buffer now contains enough bytes to satisfy the request
            _readBuffer.Seek(internalBufferPos, SeekOrigin.Begin);
            bytesRead = _readBuffer.Read(buffer, offset, count);

            if (_readBuffer.Length > _maxInternalBufferLength)
            {
                int bytesLeft = (int)(_readBuffer.Length - _readBuffer.Position);

                byte[] tempStreamBuffer = new byte[bytesLeft];

                _readBuffer.Read(tempStreamBuffer, 0, bytesLeft);
                _readBuffer = new MemoryStream();
                _readBuffer.Write(tempStreamBuffer, 0, bytesLeft);
                _readBuffer.Seek(0, SeekOrigin.Begin);
                _allowSeekBack = false;
            }
            return(bytesRead);
        }