mirror of https://bitbucket.org/ausocean/av.git
70 lines
1.8 KiB
Go
70 lines
1.8 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 NALUnit struct {
|
|
ThreeNUBs byte
|
|
FragmentType byte
|
|
Start bool
|
|
End bool
|
|
Reserved bool
|
|
FiveNUBs byte
|
|
Data []byte
|
|
}
|
|
|
|
/*
|
|
First byte: [ 3 NAL UNIT BITS | 5 FRAGMENT TYPE BITS]
|
|
Second byte: [ START BIT | END BIT | RESERVED BIT | 5 NAL UNIT BITS]
|
|
Other bytes: [... VIDEO FRAGMENT DATA...]
|
|
*/
|
|
func ParseNALUnit(unit []byte) (u *NALUnit) {
|
|
u = new(NALUnit)
|
|
u.ThreeNUBS = (unit[0] & 0xE0) >> 5
|
|
u.FragmentType = unit[0] & 0x1F
|
|
u.Start = (unit[1] & 0x80) != 0
|
|
u.End = (unit[1] & 0x40) != 0
|
|
u.Reserved = (unit[1] & 0x20) != 0
|
|
u.FiveNUBs = unit[1] & 0x1F
|
|
u.Data = unit[2:]
|
|
return
|
|
}
|
|
|
|
func GetNalType(unit []byte) byte {
|
|
return unit[0] & 0x1F
|
|
}
|
|
|
|
func (u *NALUnit) ToByteSlice() (output []byte) {
|
|
output = make([]byte, 2+len(u.Data))
|
|
output[0] = ( u.ThreeNUBs << 5 ) | u.FragmentType
|
|
output[1] = boolToByte( u.Start ) << 7 |
|
|
boolToByte( u.End ) << 6 |
|
|
boolToByte( u.Reserved ) << 5 |
|
|
u.FiveNUBs
|
|
copy(output[2:],u.Data)
|
|
return
|
|
}
|