From 1728c3a531919d84f636e873b83bce8334b76f01 Mon Sep 17 00:00:00 2001 From: scruzin Date: Wed, 10 Jul 2019 09:26:54 +0930 Subject: [PATCH 1/3] Export StandardPAT, StandardPMT and MaxPTS. --- container/mts/encoder.go | 70 +++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/container/mts/encoder.go b/container/mts/encoder.go index a1598dd8..c47537bf 100644 --- a/container/mts/encoder.go +++ b/container/mts/encoder.go @@ -34,10 +34,10 @@ import ( "bitbucket.org/ausocean/av/container/mts/psi" ) -// Some common manifestations of PSI +// Some common manifestations of PSI. var ( - // standardPat is a minimal PAT. - standardPat = psi.PSI{ + // StandardPAT is a minimal PAT. + StandardPAT = psi.PSI{ Pf: 0x00, Tid: 0x00, Ssi: true, @@ -55,6 +55,30 @@ var ( }, }, } + + // Standard PMT is a minimal PMT. + StandardPMT = psi.PSI{ + Pf: 0x00, + Tid: 0x02, + Ssi: true, + Sl: 0x12, + Tss: &psi.TSS{ + Tide: 0x01, + V: 0, + Cni: true, + Sn: 0, + Lsn: 0, + Sd: &psi.PMT{ + Pcrpid: 0x0100, + Pil: 0, + Essd: &psi.ESSD{ + St: H264ID, + Epid: 0x0100, + Esil: 0x00, + }, + }, + }, + } ) const ( @@ -69,7 +93,7 @@ const ( var Meta *meta.Data var ( - patTable = standardPat.Bytes() + patTable = StandardPAT.Bytes() pmtTable []byte ) @@ -102,6 +126,9 @@ const ( // PTSFrequency is the presentation timestamp frequency in Hz. PTSFrequency = 90000 + + // MaxPTS is the largest PTS value (i.e., for a 33-bit unsigned integer). + MaxPTS = (1 << 33) - 1 ) // Encoder encapsulates properties of an MPEG-TS generator. @@ -143,29 +170,20 @@ func NewEncoder(dst io.WriteCloser, rate float64, mediaType int) *Encoder { sid = H264ID } - // standardPmt is a minimal PMT, without descriptors for metadata. - pmtTable = (&psi.PSI{ - Pf: 0x00, - Tid: 0x02, - Ssi: true, - Sl: 0x12, - Tss: &psi.TSS{ - Tide: 0x01, - V: 0, - Cni: true, - Sn: 0, - Lsn: 0, - Sd: &psi.PMT{ - Pcrpid: 0x0100, - Pil: 0, - Essd: &psi.ESSD{ - St: byte(sid), - Epid: 0x0100, - Esil: 0x00, - }, + // StandardPmt is a minimal PMT, without descriptors for metadata. + pmt := StandardPMT + if sid != H264ID { + pmt.Tss.Sd = &psi.PMT{ + Pcrpid: 0x0100, + Pil: 0, + Essd: &psi.ESSD{ + St: byte(sid), + Epid: 0x0100, + Esil: 0x00, }, - }, - }).Bytes() + } + } + pmtTable = pmt.Bytes() return &Encoder{ dst: dst, From 74143174292e0a26d332745b3d1f27a5ef46153a Mon Sep 17 00:00:00 2001 From: scruzin Date: Wed, 10 Jul 2019 09:45:55 +0930 Subject: [PATCH 2/3] Skip TestFromFrame if RTMP_TEST_FRAME env var not defined. --- protocol/rtmp/rtmp_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/protocol/rtmp/rtmp_test.go b/protocol/rtmp/rtmp_test.go index e1e79796..f1b44554 100644 --- a/protocol/rtmp/rtmp_test.go +++ b/protocol/rtmp/rtmp_test.go @@ -173,6 +173,10 @@ func TestErorHandling(t *testing.T) { // TestFromFrame tests streaming from a single H.264 frame which is repeated. func TestFromFrame(t *testing.T) { testLog(0, "TestFromFrame") + testFrame := os.Getenv("RTMP_TEST_FRAME") + if testFrame == "" { + t.Skip("Skipping TestFromFrame since no RTMP_TEST_FRAME") + } if testKey == "" { t.Skip("Skipping TestFromFrame since no RTMP_TEST_KEY") } @@ -181,7 +185,6 @@ func TestFromFrame(t *testing.T) { t.Errorf("Dial failed with error: %v", err) } - testFrame := os.Getenv("RTMP_TEST_FRAME") b, err := ioutil.ReadFile(testFrame) if err != nil { t.Errorf("ReadFile failed with error: %v", err) From 90efebdc91d17a2d9d37b21e519c3f2262f4d818 Mon Sep 17 00:00:00 2001 From: scruzin Date: Wed, 10 Jul 2019 10:17:34 +0930 Subject: [PATCH 3/3] Added BasePMT which is a PMT without specific data, and removed StandardPMT. --- container/mts/encoder.go | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/container/mts/encoder.go b/container/mts/encoder.go index c47537bf..883e3a5e 100644 --- a/container/mts/encoder.go +++ b/container/mts/encoder.go @@ -56,8 +56,8 @@ var ( }, } - // Standard PMT is a minimal PMT. - StandardPMT = psi.PSI{ + // Base PMT is a minimal PMT without specific data. + BasePMT = psi.PSI{ Pf: 0x00, Tid: 0x02, Ssi: true, @@ -68,15 +68,6 @@ var ( Cni: true, Sn: 0, Lsn: 0, - Sd: &psi.PMT{ - Pcrpid: 0x0100, - Pil: 0, - Essd: &psi.ESSD{ - St: H264ID, - Epid: 0x0100, - Esil: 0x00, - }, - }, }, } ) @@ -170,18 +161,15 @@ func NewEncoder(dst io.WriteCloser, rate float64, mediaType int) *Encoder { sid = H264ID } - // StandardPmt is a minimal PMT, without descriptors for metadata. - pmt := StandardPMT - if sid != H264ID { - pmt.Tss.Sd = &psi.PMT{ - Pcrpid: 0x0100, - Pil: 0, - Essd: &psi.ESSD{ - St: byte(sid), - Epid: 0x0100, - Esil: 0x00, - }, - } + pmt := BasePMT + pmt.Tss.Sd = &psi.PMT{ + Pcrpid: 0x0100, + Pil: 0, + Essd: &psi.ESSD{ + St: byte(sid), + Epid: 0x0100, + Esil: 0x00, + }, } pmtTable = pmt.Bytes()