package tools // mp2tDumpProgram dumps MPEG-TS Program Association Table (PAT) and Program Map Tables (PMT). func mp2tDumpProgram(clip []byte) error { // NB: Comcast API requires a buffered reader reader := bufio.NewReader(bytes.NewReader(clip)) _, err := packet.Sync(reader) if err != nil { return fmt.Errorf("Error reading sync byte: %s", err) } pat, err := psi.ReadPAT(reader) if err != nil { return fmt.Errorf("Error reading PAT: %s", err) } mp2tDumpPat(pat) var pmts []psi.PMT pm := pat.ProgramMap() for pn, pid := range pm { pmt, err := psi.ReadPMT(reader, pid) if err != nil { return fmt.Errorf("Error reading PMT: %s", err) } pmts = append(pmts, pmt) mp2tDumpPmt(pn, pmt) } return nil } func mp2tDumpPat(pat psi.PAT) { fmt.Printf("Pat\n") fmt.Printf("\tPMT PIDs %v\n", pat.ProgramMap()) fmt.Printf("\tNumber of Programs %v\n", pat.NumPrograms()) } func mp2tDumpPmt(pn uint16, pmt psi.PMT) { // pn = program number fmt.Printf("Program #%v PMT\n", pn) fmt.Printf("\tPIDs %v\n", pmt.Pids()) fmt.Printf("\tElementary Streams") for _, es := range pmt.ElementaryStreams() { fmt.Printf("\t\tPID %v : StreamType %v\n", es.ElementaryPid(), es.StreamType()) for _, d := range es.Descriptors() { fmt.Printf("\t\t\t%+v\n", d) } } }