public override Tag ReadTag() { var bytes = FlvReader._binaryReader.ReadBytes(4); if (bytes.Length == 0) { return(null); } if (bytes.Length != 4) { throw new InvalidOperationException(string.Format("Tag consists of at least 11 bytes, but only {0} bytes were read from Stream.", bytes.Length)); } var payloadSize = new UInt24(bytes.Skip(1).Take(3), Endianness.BigEndian); var numberOfAdditionalBytesToRead = 7 + (int)payloadSize.Value; var additionalBytes = FlvReader._binaryReader.ReadBytes(numberOfAdditionalBytesToRead); if (additionalBytes.Length != numberOfAdditionalBytesToRead) { throw new InvalidOperationException(string.Format("Tag consists of {0} bytes, but only {1} bytes were read from Stream.", bytes.Length + numberOfAdditionalBytesToRead, bytes.Length + additionalBytes.Length)); } FlvReader.MoveToBeforeBackpointerState(); return(new Tag(bytes.Concat(additionalBytes).ToArray())); }
protected FlvReaderState(FlvReader flvReader) { if (flvReader == null) { throw new ArgumentNullException("flvReader"); } FlvReader = flvReader; }
public override Backpointer ReadBackpointer() { var bytes = FlvReader._binaryReader.ReadBytes(4); if (bytes.Length != 4) { throw new InvalidOperationException(string.Format("Backpointer consists of 4 bytes, but only {0} bytes were read from Stream.", bytes.Length)); } FlvReader.MoveToBeforeTagState(); return(new Backpointer(bytes)); }
public BeforeTagState(FlvReader flvReader) : base(flvReader) { }
public BeforeHeaderState(FlvReader flvReader) : base(flvReader) { }
public BeforeBackpointerState(FlvReader flvReader) : base(flvReader) { }
protected FlvReaderState(FlvReader flvReader) { if (flvReader == null) throw new ArgumentNullException("flvReader"); FlvReader = flvReader; }
public void Download(string path) { if (path == null) throw new ArgumentNullException("path"); var drNuRtmpStream = _drNuRtmpStreamFactory.CreateDrNuRtmpStream(RtmpUri); drNuRtmpStream.Duration += (sender, args) => OnDuration(args); drNuRtmpStream.Elapsed += (sender, args) => OnElapsed(args); using (var flvReader = new FlvReader(drNuRtmpStream)) using (var flvWriter = new FlvWriter(_fileWrapper.Create(path))) { IFlvPart flvPart; while ((flvPart = flvReader.Read()) != null) { flvWriter.Write(flvPart); } } }