From b96df6d3a70293ec5d4895fb20476ae1e247bcf6 Mon Sep 17 00:00:00 2001 From: saxon Date: Wed, 13 Feb 2019 14:40:58 +1030 Subject: [PATCH 1/6] stream/mts: added general FindPID func and FindPAT func. --- stream/mts/mpegts.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/stream/mts/mpegts.go b/stream/mts/mpegts.go index 08791af7..012a912c 100644 --- a/stream/mts/mpegts.go +++ b/stream/mts/mpegts.go @@ -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 From 947f818bc626f3a1430f50b7749335148076998e Mon Sep 17 00:00:00 2001 From: Saxon Date: Wed, 27 Feb 2019 16:36:59 +1030 Subject: [PATCH 2/6] stream/mts: modified error in FindPid in the case that we can't a packet with given pid so that we show pid --- stream/mts/mpegts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream/mts/mpegts.go b/stream/mts/mpegts.go index 012a912c..6d51a0b0 100644 --- a/stream/mts/mpegts.go +++ b/stream/mts/mpegts.go @@ -182,7 +182,7 @@ func FindPID(d []byte, pid uint16) (pkt []byte, i int, err error) { return } } - return nil, -1, errors.New("Could not find packet with given pid in mpegts data") + return nil, -1, errors.New(fmt.Sprintf("could not find packet with pid: %v",pid)) } // FillPayload takes a channel and fills the packets Payload field until the From 1e9fcda47c377c4f88dab30a2a40fc26f15d2800 Mon Sep 17 00:00:00 2001 From: Saxon Date: Wed, 27 Feb 2019 17:12:52 +1030 Subject: [PATCH 3/6] stream/mts: %v to %d in fmt.Sprintf usage in error message --- stream/mts/mpegts.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stream/mts/mpegts.go b/stream/mts/mpegts.go index 6d51a0b0..8173d2ce 100644 --- a/stream/mts/mpegts.go +++ b/stream/mts/mpegts.go @@ -30,6 +30,7 @@ package mts import ( "errors" + "fmt" ) // General mpegts packet properties. @@ -182,7 +183,7 @@ func FindPID(d []byte, pid uint16) (pkt []byte, i int, err error) { return } } - return nil, -1, errors.New(fmt.Sprintf("could not find packet with pid: %v",pid)) + return nil, -1, errors.New(fmt.Sprintf("could not find packet with pid: %d",pid)) } // FillPayload takes a channel and fills the packets Payload field until the From c1f7497078d0468fefdb5daf5ee3d3f9772d9042 Mon Sep 17 00:00:00 2001 From: Saxon Date: Wed, 27 Feb 2019 17:16:15 +1030 Subject: [PATCH 4/6] stream/mts: using fmt.Errorf instead of fmt.Sprintf inside errors.New --- stream/mts/mpegts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream/mts/mpegts.go b/stream/mts/mpegts.go index 8173d2ce..e9bbf0e1 100644 --- a/stream/mts/mpegts.go +++ b/stream/mts/mpegts.go @@ -183,7 +183,7 @@ func FindPID(d []byte, pid uint16) (pkt []byte, i int, err error) { return } } - return nil, -1, errors.New(fmt.Sprintf("could not find packet with pid: %d",pid)) + 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 From 1e9b6c25c9d4f1757edc7b8abd210727e229bef0 Mon Sep 17 00:00:00 2001 From: Saxon Date: Thu, 28 Feb 2019 11:04:40 +1030 Subject: [PATCH 5/6] stream/mts: lowercase PID PAT and PMT in func names --- stream/mts/mpegts.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stream/mts/mpegts.go b/stream/mts/mpegts.go index e9bbf0e1..c3c0d390 100644 --- a/stream/mts/mpegts.go +++ b/stream/mts/mpegts.go @@ -160,19 +160,19 @@ 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) ([]byte, int, error) { - return FindPID(d, PmtPid) +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) +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) { +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") } @@ -183,7 +183,7 @@ func FindPID(d []byte, pid uint16) (pkt []byte, i int, err error) { return } } - return nil, -1, fmt.Errorf("could not find packet with pid: %d",pid) + 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 From a7989955ca84d713a59f99fe40c8e60f8fc9f48a Mon Sep 17 00:00:00 2001 From: Saxon Date: Thu, 28 Feb 2019 11:06:27 +1030 Subject: [PATCH 6/6] stream/mts: corrected func comments for FindPat, FindPmt and FindPid --- stream/mts/mpegts.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stream/mts/mpegts.go b/stream/mts/mpegts.go index c3c0d390..705f88de 100644 --- a/stream/mts/mpegts.go +++ b/stream/mts/mpegts.go @@ -158,19 +158,19 @@ 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) ([]byte, int, error) { return FindPid(d, PmtPid) } -// FindPAT will take a clip of mpegts and try to find a PAT table - if one +// 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 +// 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 {