/// <summary> /// Process a single TS packet. /// </summary> /// <param name="i">The offset in our buffer where the packet lives.</param> private void Process(int i) { // Corrupted //if (0 == Buffer[i]) return; // Test if ( 0x47 != Buffer[i++] ) throw new ArgumentException("not a TS package at " + i.ToString(), "i"); // Decode all (slow) bool terr = (0x80 == (0x80&Buffer[i])); bool fstp = (0x40 == (0x40&Buffer[i])); bool prio = (0x20 == (0x20&Buffer[i])); int pidh = Buffer[i++]&0x1f; int pidl = Buffer[i++]; int pid = pidl + 256 * pidh; int scram = (Buffer[i]>>6)&0x3; int adap = (Buffer[i]>>4)&0x3; int count = Buffer[i++]&0xf; // Skip padding if (0x1fff == pid) return; // Not supported by VCR.NET if ( terr ) throw new ArgumentException("unexpected transmission error at " + i.ToString(), "i"); //if ( prio ) throw new ArgumentException("unexpected priority at " + i.ToString(), "i"); //if ( 0 != scram ) throw new ArgumentException("unexpected scrambling at " + i.ToString(), "i"); if ( 0 == adap ) throw new ArgumentException("expected adaption at " + i.ToString(), "i"); // Split again bool adaption = (2 == (2&adap)); bool payload = (1 == (1&adap)); // Find the handler TSStream stream = (TSStream)Streams[pid]; // Create if ( null == stream ) { // New one stream = new TSStream(File, pid); // Remember Streams[pid] = stream; } // Forward bool hasData = stream.Process(Buffer, i, adaption, payload, fstp, count, LogFile); // Report if ( (0 != pid) && (256 != pid) ) if ( (pid == LogPID) && hasData && !fstp ) { // Count hits ++LogCount; } else { // Report if ( LogCount > 0 ) LogFile.WriteLine("{0}\t{1}\t{2}", LogPID, LogCount, LogStartsClosed ? "+" : "-"); // Reset LogStartsClosed = fstp; LogPID = pid; LogCount = 1; // Again if filler if ( !hasData ) { // Debug only PCRDecode(Buffer, i); // Report LogFile.WriteLine("{0}\t1\t{1}\t*", LogPID, LogStartsClosed ? "+" : "-"); // Reset LogCount = 0; LogPID = -1; } } }
/// <summary> /// Process a single TS packet. /// </summary> /// <param name="i">The offset in our buffer where the packet lives.</param> private void Process(int i) { // Corrupted //if (0 == Buffer[i]) return; // Test if (0x47 != Buffer[i++]) { throw new ArgumentException("not a TS package at " + i.ToString(), "i"); } // Decode all (slow) bool terr = (0x80 == (0x80 & Buffer[i])); bool fstp = (0x40 == (0x40 & Buffer[i])); bool prio = (0x20 == (0x20 & Buffer[i])); int pidh = Buffer[i++] & 0x1f; int pidl = Buffer[i++]; int pid = pidl + 256 * pidh; int scram = (Buffer[i] >> 6) & 0x3; int adap = (Buffer[i] >> 4) & 0x3; int count = Buffer[i++] & 0xf; // Skip padding if (0x1fff == pid) { return; } // Not supported by VCR.NET if (terr) { throw new ArgumentException("unexpected transmission error at " + i.ToString(), "i"); } //if ( prio ) throw new ArgumentException("unexpected priority at " + i.ToString(), "i"); //if ( 0 != scram ) throw new ArgumentException("unexpected scrambling at " + i.ToString(), "i"); if (0 == adap) { throw new ArgumentException("expected adaption at " + i.ToString(), "i"); } // Split again bool adaption = (2 == (2 & adap)); bool payload = (1 == (1 & adap)); // Find the handler TSStream stream = (TSStream)Streams[pid]; // Create if (null == stream) { // New one stream = new TSStream(File, pid); // Remember Streams[pid] = stream; } // Forward bool hasData = stream.Process(Buffer, i, adaption, payload, fstp, count, LogFile); // Report if ((0 != pid) && (256 != pid)) { if ((pid == LogPID) && hasData && !fstp) { // Count hits ++LogCount; } else { // Report if (LogCount > 0) { LogFile.WriteLine("{0}\t{1}\t{2}", LogPID, LogCount, LogStartsClosed ? "+" : "-"); } // Reset LogStartsClosed = fstp; LogPID = pid; LogCount = 1; // Again if filler if (!hasData) { // Debug only PCRDecode(Buffer, i); // Report LogFile.WriteLine("{0}\t1\t{1}\t*", LogPID, LogStartsClosed ? "+" : "-"); // Reset LogCount = 0; LogPID = -1; } } } }