mirror of https://bitbucket.org/ausocean/av.git
Merged in add-findpid (pull request #145)
stream/mts: added general FindPID func and FindPAT func.
This commit is contained in:
commit
6228123f7d
|
@ -30,6 +30,7 @@ package mts
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// General mpegts packet properties.
|
||||
|
@ -157,20 +158,32 @@ type Packet struct {
|
|||
Payload []byte // Mpeg ts Payload
|
||||
}
|
||||
|
||||
// FindPMT will take a clip of mpegts and try to find a PMT table - if one
|
||||
// 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, fmt.Errorf("could not find packet with pid: %d", pid)
|
||||
}
|
||||
|
||||
// FillPayload takes a channel and fills the packets Payload field until the
|
||||
|
|
Loading…
Reference in New Issue