Add SPS parser and AVC/HVC conf encoders

This commit is contained in:
Alexey Khit
2023-08-14 11:55:08 +03:00
parent 3a40515a90
commit de6bb33f01
12 changed files with 302 additions and 599 deletions
+25 -12
View File
@@ -1,10 +1,12 @@
package bits
type Reader struct {
buf []byte // packets buffer
byte byte
bits byte
pos int
EOF bool // if end of buffer raised during reading
buf []byte // total buf
byte byte // current byte
bits byte // bits left in byte
pos int // current pos in buf
}
func NewReader(b []byte) *Reader {
@@ -14,6 +16,11 @@ func NewReader(b []byte) *Reader {
//goland:noinspection GoStandardMethods
func (r *Reader) ReadByte() byte {
if r.bits == 0 {
if r.pos >= len(r.buf) {
r.EOF = true
return 0
}
b := r.buf[r.pos]
r.pos++
return b
@@ -54,14 +61,20 @@ func (r *Reader) ReadBits16(n byte) (res uint16) {
return
}
func (r *Reader) SkipBits(n int) {
for i := 0; i < n; i++ {
if r.bits == 0 {
r.byte = r.buf[r.pos]
r.pos++
r.bits = 7
} else {
r.bits--
func (r *Reader) ReadUEGolomb() uint32 {
var size byte
for size = 0; size < 32; size++ {
if b := r.ReadBit(); b != 0 || r.EOF {
break
}
}
return r.ReadBits(size) + (1 << size) - 1
}
func (r *Reader) ReadSEGolomb() int32 {
if b := r.ReadUEGolomb(); b%2 == 0 {
return -int32(b >> 1)
} else {
return int32(b >> 1)
}
}