av/packets/Pes.go

79 lines
2.3 KiB
Go

/*
NAME
PES.go -
DESCRIPTION
See Readme.md
AUTHOR
Saxon Nelson-Milton <saxon.milton@gmail.com>
LICENSE
PES.go is Copyright (C) 2017 the Australian Ocean Lab (AusOcean)
It is free software: you can redistribute it and/or modify them
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
It is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with revid in gpl.txt. If not, see [GNU licenses](http://www.gnu.org/licenses).
*/
package packets
type PESPacket struct {
StreamID byte
Length uint16
ScramblingControl byte
Priority bool
DAI bool // data alginment indicator
Copyright bool
Original bool
PDI byte // PTS DTS indicator
ESCR bool
ESRate bool
DSMTrickMode bool
ACI bool // additional copy info flag
CRC bool
Ext bool
HeaderLength byte
OptFields []byte
Stuffing []byte
Data []byte
}
func (p *PESPacket) ToByteSlice() (output []byte) {
output = make([]byte, 6+p.Length)
output[0] = 0x00
output[1] = 0x00
output[2] = 0x01
output[3] = p.StreamID
output[4] = byte(( p.Length & 0xFF00 ) >> 8)
output[5] = byte( p.Length & 0x00FF )
output[6] = 0x2 << 6 |
p.ScramblingControl << 4 |
boolToByte(p.Priority) << 3 |
boolToByte(p.DAI) << 2 |
boolToByte(p.Copyright) << 1 |
boolToByte(p.Original)
output[7] = p.PDI << 6 |
boolToByte(p.ESCR) << 5 |
boolToByte(p.ESRate) << 4 |
boolToByte(p.DSMTrickMode) << 3 |
boolToByte(p.ACI) << 2 |
boolToByte(p.CRC) << 1 |
boolToByte(p.Ext)
output[8] = p.HeaderLength
optFieldsOffset := 9+len(p.OptFields)
copy(output[9:optFieldsOffset],p.OptFields)
copy(output[optFieldsOffset:optFieldsOffset + len(p.Stuffing)],p.Stuffing)
dataOffset := 9+int(p.HeaderLength)
copy(output[dataOffset:dataOffset+len(p.Data)],p.Data)
return
}