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

Add muxer #16

Merged
merged 57 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d07a182
starting
Jan 25, 2021
0798d32
pcr write
Jan 27, 2021
c9e1bff
go-astikit replacement until PR is merged
Jan 28, 2021
9c4fa08
packet header, adaptation field, dts write
Jan 28, 2021
8741f0c
dependency cleanup
Feb 1, 2021
905064d
get rid of panic/recover for writing
Feb 2, 2021
f298e1e
make writePCR code more adequate
Feb 2, 2021
5c71b25
writePacket and adaptation field length calculation
Feb 2, 2021
278fce9
writePacket and adaptation field length calculation
Feb 2, 2021
4047b66
s/188/MpegTsPacketSize/
Feb 2, 2021
7dc14a4
writePATSection
Feb 2, 2021
28edb16
Try* -> BitsWriterBatch
Feb 3, 2021
b4a87e9
descriptors WIP
Feb 3, 2021
e7a5601
go-astikit version bump
Feb 3, 2021
3dae8fc
descriptors WIP
Feb 4, 2021
b06993f
descriptor parsing tests refactored to allow reuse for descriptor wri…
Feb 5, 2021
3e5341d
descriptors writing tested
Feb 5, 2021
8aa5b6c
descriptors writing refactoring
Feb 5, 2021
e4788ba
descriptors done, PMT WIP
Feb 5, 2021
28a686e
write PMT section fix
Feb 11, 2021
fc82353
writePSIData works
Feb 12, 2021
f82bc07
WIP
Feb 17, 2021
db031e6
PES WIP
Feb 18, 2021
05b66f0
PES functions pass tests
Feb 19, 2021
705a8d3
minor fix
Feb 20, 2021
9391d51
muxer: pat & pmt
Feb 26, 2021
78bebcd
muxer: more tests
Feb 26, 2021
2475c9b
muxer: payload writing
Feb 27, 2021
05cec28
es-split WIP
Feb 27, 2021
69ec742
es-split seems to work
Feb 28, 2021
f060240
es-split PCR sync; some style fixes
Mar 2, 2021
9191588
Data.Kind cleanup
Mar 2, 2021
074bd9b
comment update
Mar 2, 2021
881e1c3
cleanup
Mar 2, 2021
de205b4
cleanup
Mar 2, 2021
ca51287
go-astikit dep replace removed
Mar 3, 2021
b07932b
comment fix
Mar 3, 2021
e98cd9e
minor fix
Mar 3, 2021
583de87
flush on pid change removed as it seems to be unnecessary
Mar 3, 2021
449222b
added some streamtype info funcs
Mar 4, 2021
3916b58
StreamType and PSITableTypeID are special types now
Mar 5, 2021
b069beb
comment cleanup
Mar 6, 2021
72ce363
use PSITableTypeId more instead of comparing strings
Mar 6, 2021
40fd6af
comment cleanup
Mar 6, 2021
6b7966e
PSITableTypeId -> PSITableTypeID
Mar 9, 2021
a6249bb
PESIsVideoStreamId -> PESIsVideoStreamID
Mar 9, 2021
5064bcb
PSITableTypeID.String() -> PSITableTypeID.Type()
Mar 9, 2021
2abf745
review fixes: first pack: constants and stuff
Mar 22, 2021
5d7277f
packet_buffer read() renamed to peek()
Mar 23, 2021
6af7b0b
tools are moved to cmd directory
Mar 24, 2021
a5c45f3
correct prefixes for muxer and demuxer opts
Mar 24, 2021
18725af
SetPCRPID instead of isPCRPID of AddElementaryStream
Mar 24, 2021
432588a
test fix and some comments
Mar 24, 2021
135fae5
muxer WritePacket export
Mar 24, 2021
f2a492a
`astits.New` renamed to `NewDemuxer`
Mar 24, 2021
e943295
astikit version bump; writeBytesN removed in favor of one in BitsWriter
Mar 24, 2021
bc4c488
WritePayload -> WriteData with MuxerData
Mar 24, 2021
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
8 changes: 4 additions & 4 deletions astits/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ type Program struct {

// Stream represents a stream
type Stream struct {
Descriptors []string `json:"descriptors,omitempty"`
ID uint16 `json:"id,omitempty"`
Type uint8 `json:"type,omitempty"`
Descriptors []string `json:"descriptors,omitempty"`
ID uint16 `json:"id,omitempty"`
Type astits.StreamType `json:"type,omitempty"`
}

func newProgram(id, mapID uint16) *Program {
Expand All @@ -359,7 +359,7 @@ func newProgram(id, mapID uint16) *Program {
}
}

func newStream(id uint16, _type uint8) *Stream {
func newStream(id uint16, _type astits.StreamType) *Stream {
return &Stream{
ID: id,
Type: _type,
Expand Down
25 changes: 25 additions & 0 deletions crc32.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package astits

const (
CRC32Polynomial = uint32(0xffffffff)
asticode marked this conversation as resolved.
Show resolved Hide resolved
)

// computeCRC32 computes a CRC32
// https://stackoverflow.com/questions/35034042/how-to-calculate-crc32-in-psi-si-packet
func computeCRC32(bs []byte) uint32 {
return updateCRC32(CRC32Polynomial, bs)
}

func updateCRC32(crc32 uint32, bs []byte) uint32 {
for _, b := range bs {
for i := 0; i < 8; i++ {
if (crc32 >= uint32(0x80000000)) != (b >= uint8(0x80)) {
crc32 = (crc32 << 1) ^ 0x04C11DB7
} else {
crc32 = crc32 << 1
}
b <<= 1
}
}
return crc32
}
8 changes: 4 additions & 4 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

// PIDs
const (
PIDPAT = 0x0 // Program Association Table (PAT) contains a directory listing of all Program Map Tables.
PIDCAT = 0x1 // Conditional Access Table (CAT) contains a directory listing of all ITU-T Rec. H.222 entitlement management message streams used by Program Map Tables.
PIDTSDT = 0x2 // Transport Stream Description Table (TSDT) contains descriptors related to the overall transport stream
PIDNull = 0x1fff // Null Packet (used for fixed bandwidth padding)
PIDPAT uint16 = 0x0 // Program Association Table (PAT) contains a directory listing of all Program Map Tables.
PIDCAT uint16 = 0x1 // Conditional Access Table (CAT) contains a directory listing of all ITU-T Rec. H.222 entitlement management message streams used by Program Map Tables.
PIDTSDT uint16 = 0x2 // Transport Stream Description Table (TSDT) contains descriptors related to the overall transport stream
PIDNull uint16 = 0x1fff // Null Packet (used for fixed bandwidth padding)
)

// Data represents a data
Expand Down
1 change: 1 addition & 0 deletions data_eit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

// EITData represents an EIT data
// Page: 36 | Chapter: 5.2.4 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf
// (barbashov) the link above can be broken, alternative: https://dvb.org/wp-content/uploads/2019/12/a038_tm1217r37_en300468v1_17_1_-_rev-134_-_si_specification.pdf
type EITData struct {
Events []*EITDataEvent
LastTableID uint8
Expand Down
1 change: 1 addition & 0 deletions data_nit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

// NITData represents a NIT data
// Page: 29 | Chapter: 5.2.1 | Link: https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf
// (barbashov) the link above can be broken, alternative: https://dvb.org/wp-content/uploads/2019/12/a038_tm1217r37_en300468v1_17_1_-_rev-134_-_si_specification.pdf
type NITData struct {
NetworkDescriptors []*Descriptor
NetworkID uint16
Expand Down
20 changes: 20 additions & 0 deletions data_pat.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import (
"github.com/asticode/go-astikit"
)

const (
PATSectionEntryBytesSize = 4 // 16 bits + 3 reserved + 13 bits = 32 bits
asticode marked this conversation as resolved.
Show resolved Hide resolved
)

// PATData represents a PAT data
// https://en.wikipedia.org/wiki/Program-specific_information
type PATData struct {
Expand Down Expand Up @@ -41,3 +45,19 @@ func parsePATSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt
}
return
}

func calcPATSectionLength(d *PATData) uint16 {
return uint16(4 * len(d.Programs))
}

func writePATSection(w *astikit.BitsWriter, d *PATData) (int, error) {
b := astikit.NewBitsWriterBatch(w)

for _, p := range d.Programs {
b.Write(p.ProgramNumber)
b.WriteN(uint8(0xff), 3)
b.WriteN(p.ProgramMapID, 13)
}

return len(d.Programs) * PATSectionEntryBytesSize, b.Err()
}
10 changes: 10 additions & 0 deletions data_pat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ func TestParsePATSection(t *testing.T) {
assert.Equal(t, d, pat)
assert.NoError(t, err)
}

func TestWritePatSection(t *testing.T) {
bw := &bytes.Buffer{}
w := astikit.NewBitsWriter(astikit.BitsWriterOptions{Writer: bw})
n, err := writePATSection(w, pat)
assert.NoError(t, err)
assert.Equal(t, n, 8)
assert.Equal(t, n, bw.Len())
assert.Equal(t, patBytes(), bw.Bytes())
}
Loading