Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scte35 creation #94

Merged
merged 32 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2660fec
PSI struct added
alextarasov1 Jul 13, 2018
831779d
added PSI tests and stuffing
alextarasov1 Jul 13, 2018
db52015
PSI fix, added more tests
alextarasov1 Jul 16, 2018
65f37eb
SCTE35 modification added
alextarasov1 Jul 16, 2018
48acb27
Splicecommand to byte slice conversion added
alextarasov1 Jul 16, 2018
90e22a2
added scte modify test and changed PSI reserved bits
alextarasov1 Jul 16, 2018
159e8c1
Added support for segmentation descriptor creation
alextarasov1 Jul 17, 2018
8c2cad1
Added functions to interfaces to access new fields
alextarasov1 Jul 18, 2018
94cf2be
Added flag to update scte35 data only when it is changed
alextarasov1 Jul 18, 2018
70530ca
split PSI struct into two parts Pointer and TableHeader
alextarasov1 Jul 18, 2018
b7eed4b
Added more functions to interfaces
alextarasov1 Jul 19, 2018
2962902
Implemented new interface functions
alextarasov1 Jul 19, 2018
80d845f
updated scte35 CRC
alextarasov1 Jul 19, 2018
29010b6
Added subtraction capability to PTS
alextarasov1 Jul 20, 2018
a292ddd
removed pointer field from data function
alextarasov1 Jul 20, 2018
95b8a94
added String function
alextarasov1 Jul 20, 2018
c679248
added get and set functions
alextarasov1 Jul 20, 2018
2ab4407
added test to create packet
alextarasov1 Jul 20, 2018
f560291
added documentation. changed some function names.
alextarasov1 Jul 24, 2018
25c9bd5
added more tests
alextarasov1 Jul 24, 2018
a4aeac2
Merge branch 'master' into scte35-creation
alextarasov1 Jul 24, 2018
fe91f68
fixed hasSubSegments
alextarasov1 Jul 25, 2018
d490224
Fixed segmentation_duration to be a 40 bit unsigned integer, not PTS
alextarasov1 Jul 26, 2018
08d2a0b
Fixed PTS subtraction.
alextarasov1 Jul 26, 2018
c7b9819
Fixed comments, added MIT license.
alextarasov1 Jul 26, 2018
20ec6a0
segmentation_duration switched back to a pts.
alextarasov1 Jul 26, 2018
480b309
Added UpdateData function
alextarasov1 Jul 26, 2018
74c1af9
Removed updateBytes flag in favor of UpdateData()
alextarasov1 Jul 27, 2018
ca9f9ee
Fixed godocs
alextarasov1 Aug 14, 2018
2beea68
SpliceInfo is set in descriptors
alextarasov1 Aug 14, 2018
22fd220
Merge branch 'master' into scte35-creation
alextarasov1 Aug 14, 2018
443b566
Moved structs back to original files from doc.go
alextarasov1 Aug 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions psi/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ const (
CrcLen uint16 = 4
)

// PSI interface represents operations available on all PSI
type PSI interface {
PointerField() uint8
TableID() uint8
SectionSyntaxIndicator() bool
PrivateIndicator() bool
SectionLength() uint16
// TableHeader struct represents operations available on all PSI
type TableHeader struct {
TableID uint8
SectionSyntaxIndicator bool
PrivateIndicator bool
SectionLength uint16
}

// PmtStreamType is used to represent elementary steam type inside a PMT
Expand Down
51 changes: 51 additions & 0 deletions psi/psi.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,54 @@ func sectionSyntaxIndicator(psi []byte) bool {
func sectionLength(psi []byte) uint16 {
return uint16(psi[1]&3)<<8 | uint16(psi[2])
}

// NewPointerField will return a new pointer field with stuffing as raw bytes.
// The pointer field specifies where the TableHeader should start.
// Everything in between the pointer field and table header should
// be bytes with the value 0xFF.
func NewPointerField(size int) []byte {
data := make([]byte, size+1)
data[0] = byte(size)
for i := 1; i < size+1; i++ {
data[i] = 0xFF
}
return data
}

// PSIFromBytes returns the PSI struct from a byte slice
func TableHeaderFromBytes(data []byte) TableHeader {
th := TableHeader{}

th.TableID = data[0]
th.SectionSyntaxIndicator = data[1]&0x80 != 0
th.PrivateIndicator = data[1]&0x40 != 0
th.SectionLength = uint16(data[1]&0x03 /* 0000 0011 */)<<8 | uint16(data[2])

return th
}

// Data returns the byte representation of the PSI struct.
func (th TableHeader) Data() []byte {
data := make([]byte, 3)

data[0] = th.TableID
if th.SectionSyntaxIndicator {
data[1] |= 0x80
}
if th.PrivateIndicator {
data[1] |= 0x40
}

// set reserved bits to 11
data[1] |= 0x30 // 0011 0000

data[1] |= byte(th.SectionLength>>8) & 0x03 // 0000 0011
data[2] = byte(th.SectionLength)

return data
}

// NewPSI will create a PSI with default values of zero and false for everything
func NewTableHeader() TableHeader {
return TableHeader{}
}
75 changes: 75 additions & 0 deletions psi/psi_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
MIT License

Copyright 2016 Comcast Cable Communications Management, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package psi

import (
"bytes"
"testing"
)

func TestDefaultPSIData(t *testing.T) {
th := NewTableHeader()
generated := th.Data()
target := []byte{0x00, 0x30, 0x00}
if !bytes.Equal(target, generated) {
t.Errorf("NewTableHeader does not produce expected Data. \nExpected: %X \n Got: %X ", target, generated)
}
}

func TestPSIFromBytes(t *testing.T) {
target := []byte{0x04, 0xFF, 0xFF, 0xFF, 0xFF, 0x18, 0xB1, 0xFF}
th := TableHeaderFromBytes(target[5:])

if th.TableID != 0x18 {
t.Errorf("TableHeaderFromBytes does not produce expected TableID. \nExpected: %X \n Got: %X ", 0x18, th.TableID)
}
if th.SectionLength != 0x1FF {
t.Errorf("TableHeaderFromBytes does not produce expected SectionLength. \nExpected: %X \n Got: %X ", 0x1FF, th.SectionLength)
}
if th.PrivateIndicator {
t.Errorf("TableHeaderFromBytes does not produce expected PrivateIndicator. \nExpected: %t \n Got: %t ", true, th.PrivateIndicator)
}
if !th.SectionSyntaxIndicator {
t.Errorf("TableHeaderFromBytes does not produce expected SectionSyntaxIndicator. \nExpected: %t \n Got: %t ", false, th.SectionSyntaxIndicator)
}
generated := append(NewPointerField(4), th.Data()...)
if !bytes.Equal(target, generated) {
t.Errorf("Data does not produce same bytes. \nExpected: %X \n Got: %X ", target, generated)
}
}

func TestPSICreate(t *testing.T) {
target := []byte{0x05, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x18, 0x70, 0xFF}
th := NewTableHeader()

th.TableID = 0x18
th.SectionLength = 0x0FF
th.PrivateIndicator = true
th.SectionSyntaxIndicator = false
generated := append(NewPointerField(5), th.Data()...)

if !bytes.Equal(target, generated) {
t.Errorf("Pointer field and TableHeader do not produce expected bytes. \nExpected: %X \n Got: %X ", target, generated)
}
}
Loading