private static void dumpTSPackets(ReadableByteChannel _in) throws IOException { ByteBuffer buf = ByteBuffer.allocate(188 * 1024); while (_in.read(buf) != -1) { buf.flip(); buf.limit((buf.limit() / 188) * 188); int pmtPid = -1; for (int pkt = 0; buf.hasRemaining(); ++pkt) { ByteBuffer tsBuf = NIOUtils.read(buf, 188); Assert.assertEquals(0x47, tsBuf.get() & 0xff); int guidFlags = ((tsBuf.get() & 0xff) << 8) | (tsBuf.get() & 0xff); int guid = (int) guidFlags & 0x1fff; int payloadStart = (guidFlags >> 14) & 0x1; int b0 = tsBuf.get() & 0xff; int counter = b0 & 0xf; if ((b0 & 0x20) != 0) { NIOUtils.skip(tsBuf, (tsBuf.get() & 0xff)); } System.out.print( "#" + pkt + "[guid: " + guid + ", cnt: " + counter + ", start: " + (payloadStart == 1 ? "y" : "-")); if (guid == 0 || guid == pmtPid) { System.out.print(", PSI]: "); if (payloadStart == 1) { NIOUtils.skip(tsBuf, (tsBuf.get() & 0xff)); } if (guid == 0) { PATSection pat = PATSection.parsePAT(tsBuf); IntIntMap programs = pat.getPrograms(); pmtPid = programs.values()[0]; printPat(pat); } else if (guid == pmtPid) { PMTSection pmt = PMTSection.parsePMT(tsBuf); printPmt(pmt); } } else { System.out.print("]: " + tsBuf.remaining()); } System.out.println(); } buf.clear(); } }