Skip to content

Commit 9799558

Browse files
Merge pull request #140 from Comcast/filter_packets
Ignore PAT and PMT pids when filtering packets
2 parents 5b55db8 + 97779c2 commit 9799558

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

psi/pmt.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ package psi
2727
import (
2828
"bytes"
2929
"encoding/binary"
30-
"errors"
3130
"fmt"
3231
"io"
3332

@@ -258,17 +257,19 @@ func FilterPMTPacketsToPids(packets []*packet.Packet, pids []uint16) ([]*packet.
258257
// Determine if any of the given PIDs aren't in the PMT.
259258
unfilteredPMT, _ := NewPMT(pmtPayload)
260259

260+
pmtPid := packet.Pid(packets[0])
261261
var missingPids []uint16
262262
for _, pid := range pids {
263-
if !unfilteredPMT.PIDExists(pid) {
263+
// Ignore PAT and PMT PIDS if they are included.
264+
if !unfilteredPMT.PIDExists(pid) && pid != PatPid && pid != pmtPid {
264265
missingPids = append(missingPids, pid)
265266
}
266267
}
267268

268269
// Return an error if any of the given PIDs is not present in the PMT.
269270
var returnError error
270271
if len(missingPids) > 0 {
271-
returnError = errors.New(fmt.Sprintf(gots.ErrPIDNotInPMT.Error(), missingPids))
272+
returnError = fmt.Errorf(gots.ErrPIDNotInPMT.Error(), missingPids)
272273
}
273274

274275
// Return nil packets and an error if none of the PIDs being filtered exist in the PMT.
@@ -358,8 +359,8 @@ func IsPMT(pkt *packet.Packet, pat PAT) (bool, error) {
358359
pmtMap := pat.ProgramMap()
359360
pid := packet.Pid(pkt)
360361

361-
for _, map_pid := range pmtMap {
362-
if pid == map_pid {
362+
for _, mapPID := range pmtMap {
363+
if pid == mapPID {
363364
return true, nil
364365
}
365366
}

0 commit comments

Comments
 (0)