Esempio n. 1
0
        public void Write(FLVTag tag)
        {
            if (tag == null || tag.Data == null || tag.Data.Length == 0)
            {
                return;
            }

            if (tag.Filter)
            {
                throw new InvalidOperationException("This media encrypted with Adobe Access DRM. Not supported. Sorry. :`(");
            }

            lock (lock4write) {
                if (!FLVHeaderWritten)
                {
                    WriteFlvHeader();
                }

                if (tag is FLVTagAudio)
                {
                    var tagAudio = tag as FLVTagAudio;
                    if (!AAC_HeaderWritten && tagAudio.IsAACSequenceHeader)
                    {
                        AAC_HeaderWritten = true;
                    }
                    else if (AAC_HeaderWritten && tagAudio.IsAACSequenceHeader)
                    {
                        return;
                    }

                    SizeAudio += tag.DataSize;
                }
                else if (tag is FLVTagVideo)
                {
                    var tagVideo = tag as FLVTagVideo;
                    if (!AVC_HeaderWritten && tagVideo.CodecID == FLVTagVideo.Codec.AVC && tagVideo.AvcPacketType == FLVTagVideo.AVCPacket.SEQUENCE_HEADER)
                    {
                        AVC_HeaderWritten = true;
                    }
                    else if (AVC_HeaderWritten && tagVideo.CodecID == FLVTagVideo.Codec.AVC && tagVideo.AvcPacketType == FLVTagVideo.AVCPacket.SEQUENCE_HEADER)
                    {
                        return;
                    }

                    SizeVideo += tag.DataSize;
                }

                HDSDumper.FixTimestamp(DecoderState, tag);

                if (LastTimestamp < tag.Timestamp)
                {
                    LastTimestamp = tag.Timestamp;
                }

                WriteData(tag.GetBytes());

                Frames++;
            }
        }
Esempio n. 2
0
        public void GetLastTimestampFromExistingFile()
        {
            LastTimestamp = 0;
            string sFile = Program.outDir + outFile;

            if (play || Program.redir2Prog != null || usePipe || !File.Exists(sFile))
            {
                return;
            }
            int b1, b2, b3, b4;

            using (FileStream fs = new FileStream(sFile, FileMode.Open)) {
                if (fs.Length > 600)
                {
                    fs.Position = fs.Length - 4;
                    b1          = fs.ReadByte();
                    b2          = fs.ReadByte();
                    b3          = fs.ReadByte();
                    b4          = fs.ReadByte();
                    int blockLength = b2 * 256 * 256 + b3 * 256 + b4;
                    if (fs.Length - blockLength > 600)
                    {
                        fs.Position      = fs.Length - blockLength;
                        b1               = fs.ReadByte();
                        b2               = fs.ReadByte();
                        b3               = fs.ReadByte();
                        LastTimestamp    = (uint)(b1 * 256 * 256 + b2 * 256 + b3);
                        FLVHeaderWritten = true;
                        Filesize         = (uint)fs.Length;
                        //this.FLVContinue = true;
                        Program.Message("<c:DarkYellow>Continue downloading with exiting file from timestamp: " + HDSDumper.FormatTS(LastTimestamp, true));
                        if (DecoderState == null)
                        {
                            DecoderState = new DecoderLastState();
                        }
                        DecoderState.baseTS = 0;
                    }
                }
            }
        }