Exemple #1
0
        private Int64 GetCurrentPcrFromFile()
        {
            int packetSize = 0;
            if (fileType == TsFileType.TS)
                packetSize = Constants.TS_SIZE;
            else if (fileType == TsFileType.M2TS)
                packetSize = Constants.STRIDE_SIZE;
            byte[] inBuff = new byte[packetSize];
            TsPacket tp = new TsPacket();
            Int64 filePos = fs.Position;

            while (fs.Read(inBuff, 0, packetSize) == packetSize && fs.Position < (filePos + 1000000))
            {
                if (packetSize == Constants.STRIDE_SIZE)
                    tp.SetData(inBuff, 4);
                else if (packetSize == Constants.TS_SIZE)
                    tp.SetData(inBuff, 0);
                if (tp.HasPcr)
                {
                    fs.Seek(filePos, SeekOrigin.Begin);
                    return tp.Pcr;
                }
            }
            return -1;
        }
Exemple #2
0
        private void MuxPesPacketToTs(PesPacket pp, bool priority)
        {
            byte[] data = new byte[Constants.TS_SIZE];
            int j = 0;
            int i = 0;
            byte[] pes = pp.GetData();

            // take care of the first packet
            data[0] = Constants.SYNC_BYTE;
            data[1] = 0x40; // payload start
            data[2] = 0;
            if (pes.Length < Constants.TS_PAYLOAD_SIZE)
            {
                data[3] = 0x30; // adaptation and payload
                int stufLength = Constants.TS_PAYLOAD_SIZE - pes.Length - 1;
                data[4] = (byte)stufLength;
                i = 5;
                if (stufLength > 0)
                {
                    data[i] = 0;
                    i++;
                    stufLength--;
                }
                for (; i < (6 + stufLength); i++)
                    data[i] = 0xff;
                for (; i < Constants.TS_SIZE; i++)
                {
                    data[i] = pes[j];
                    j++;
                }
            }
            else
            {
                data[3] = 0x10; // no adaptation, payload only
                for (i = 4; i < data.Length; i++)
                {
                    data[i] = pes[j];
                    j++;
                }
            }
            TsPacket ts = new TsPacket();
            ts.SetData(data, 0);
            ushort pid = pidMappings[pp.PID];
            ts.PID = pid;
            ts.Priority = priority;
            ts.ContinuityCounter = Continuities[pid];
            ts.IncrementContinuityCounter();
            Continuities[pid] = ts.ContinuityCounter;
            buffer.Add(ts);
            while (j < ((pes.Length / Constants.TS_PAYLOAD_SIZE) * Constants.TS_PAYLOAD_SIZE))
            {
                // take care of the other packets
                data[0] = Constants.SYNC_BYTE;
                data[1] = 0x00; // no payload start
                data[2] = 0;
                data[3] = 0x10; // no adaptation, payload only
                for (i = 4; i < data.Length; i++)
                {
                    data[i] = pes[j];
                    j++;
                }
                ts = new TsPacket();
                ts.SetData(data, 0);
                ts.PID = pid;
                ts.Priority = priority;
                ts.ContinuityCounter = Continuities[pid];
                ts.IncrementContinuityCounter();
                Continuities[pid] = ts.ContinuityCounter;
                buffer.Add(ts);
            }
            // take care of the last packet
            if (j < pes.Length)
            {
                data[0] = Constants.SYNC_BYTE;
                data[1] = 0x00; // no payload start
                data[2] = 0;
                data[3] = 0x30; // adaptation and payload
                int stufLength = Constants.TS_PAYLOAD_SIZE - (pes.Length - j) - 1;
                data[4] = (byte)stufLength;
                i = 5;
                if (stufLength > 0)
                {
                    data[i] = 0;
                    i++;
                    stufLength--;
                    for (; i < (6 + stufLength); i++)
                        data[i] = 0xff;
                }
                for (; i < Constants.TS_SIZE; i++)
                {
                    data[i] = pes[j];
                    j++;
                }
                ts = new TsPacket();
                ts.SetData(data, 0);
                ts.PID = pid;
                ts.Priority = priority;
                ts.ContinuityCounter = Continuities[pid];
                ts.IncrementContinuityCounter();
                Continuities[pid] = ts.ContinuityCounter;
                buffer.Add(ts);
            }
        }
Exemple #3
0
 public TsPesFile(BackgroundWorker bw, int offset)
     : base(bw)
 {
     stride = offset;
     tsPack = new byte[Constants.TS_SIZE + offset];
     ts = new TsPacket();
     PesPackets = new Dictionary<ushort, PesPacket>();
     dt = null;
     pcrPID = 0xffff;
 }