mirror of https://bitbucket.org/ausocean/av.git
stream/mts: added general FindPID func and FindPAT func.
This commit is contained in:
parent
bfdefa97f8
commit
b96df6d3a7
|
@ -159,18 +159,30 @@ type Packet struct {
|
|||
|
||||
// FindPMT will take a clip of mpegts and try to find a PMT table - if one
|
||||
// is found, then it is returned along with its index, otherwise nil, -1 and an error is returned.
|
||||
func FindPMT(d []byte) (p []byte, i int, err error) {
|
||||
func FindPMT(d []byte) ([]byte, int, error) {
|
||||
return FindPID(d, PmtPid)
|
||||
}
|
||||
|
||||
// FindPAT will take a clip of mpegts and try to find a PAT table - if one
|
||||
// is found, then it is returned along with its index, otherwise nil, -1 and an error is returned.
|
||||
func FindPAT(d []byte) ([]byte, int, error) {
|
||||
return FindPID(d, PatPid)
|
||||
}
|
||||
|
||||
// FindPID will take a clip of mpegts and try to find a packet with given PID - if one
|
||||
// is found, then it is returned along with its index, otherwise nil, -1 and an error is returned.
|
||||
func FindPID(d []byte, pid uint16) (pkt []byte, i int, err error) {
|
||||
if len(d) < PacketSize {
|
||||
return nil, -1, errors.New("Mmpegts data not of valid length")
|
||||
}
|
||||
for i = 0; i < len(d); i += PacketSize {
|
||||
pid := (uint16(d[i+1]&0x1f) << 8) | uint16(d[i+2])
|
||||
if pid == pmtPid {
|
||||
p = d[i+4 : i+PacketSize]
|
||||
p := (uint16(d[i+1]&0x1f) << 8) | uint16(d[i+2])
|
||||
if p == pid {
|
||||
pkt = d[i+4 : i+PacketSize]
|
||||
return
|
||||
}
|
||||
}
|
||||
return nil, -1, errors.New("Could not find pmt table in mpegts data")
|
||||
return nil, -1, errors.New("Could not find packet with given pid in mpegts data")
|
||||
}
|
||||
|
||||
// FillPayload takes a channel and fills the packets Payload field until the
|
||||
|
|
Loading…
Reference in New Issue