Fix IndexPid.

This commit is contained in:
scruzin 2019-07-11 17:33:16 +09:30
parent 4b57407e36
commit c8a0b7df07
1 changed files with 4 additions and 7 deletions

View File

@ -221,7 +221,7 @@ func LastPid(d []byte, pid uint16) (pkt []byte, i int, err error) {
// along with optional metadata if present. Commonly used to find a
// PAT immediately followed by a PMT.
func IndexPid(d []byte, pids ...uint16) (idx int, m map[string]string, err error) {
prev := 0
idx = -1
for _, pid := range pids {
pkt, i, _err := FindPid(d, pid)
if err != nil {
@ -231,16 +231,13 @@ func IndexPid(d []byte, pids ...uint16) (idx int, m map[string]string, err error
if pid == PmtPid {
m, _ = metaFromPMT(pkt)
}
if prev == 0 {
if idx == -1 {
idx = i
prev = i
continue
}
if i != prev+PacketSize {
} else if i != 0 {
err = errors.New("PIDs not consecutive")
return
}
prev = i
d = d[i+PacketSize:]
}
return
}