Skip to content

Commit

Permalink
Merge pull request #140 from Comcast/filter_packets
Browse files Browse the repository at this point in the history
Ignore PAT and PMT pids when filtering packets
  • Loading branch information
LimitlessEarth authored Feb 13, 2020
2 parents 5b55db8 + 97779c2 commit 9799558
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions psi/pmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ package psi
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"

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

pmtPid := packet.Pid(packets[0])
var missingPids []uint16
for _, pid := range pids {
if !unfilteredPMT.PIDExists(pid) {
// Ignore PAT and PMT PIDS if they are included.
if !unfilteredPMT.PIDExists(pid) && pid != PatPid && pid != pmtPid {
missingPids = append(missingPids, pid)
}
}

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

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

for _, map_pid := range pmtMap {
if pid == map_pid {
for _, mapPID := range pmtMap {
if pid == mapPID {
return true, nil
}
}
Expand Down

0 comments on commit 9799558

Please sign in to comment.