mirror of https://github.com/ossrs/srs.git
GB28181: Enable regression test for gb28181. v5.0.122
1. Build regression test tool for gb28181.
2. Run regression test for gb28181.
3. Format go code and eliminate logs.
4. Change base docker to ubuntu20.
PICK 7750bdae10
pull/3353/head
parent
bc381a0242
commit
3f7c4a7ff4
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
4
trunk/3rdparty/srs-bench/vendor/github.com/ghettovoice/gosip/sip/parser/error.go
generated
vendored
4
trunk/3rdparty/srs-bench/vendor/github.com/ghettovoice/gosip/sip/parser/error.go
generated
vendored
1
trunk/3rdparty/srs-bench/vendor/github.com/sirupsen/logrus/terminal_check_bsd.go
generated
vendored
1
trunk/3rdparty/srs-bench/vendor/github.com/sirupsen/logrus/terminal_check_bsd.go
generated
vendored
1
trunk/3rdparty/srs-bench/vendor/github.com/sirupsen/logrus/terminal_check_unix.go
generated
vendored
1
trunk/3rdparty/srs-bench/vendor/github.com/sirupsen/logrus/terminal_check_unix.go
generated
vendored
454
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/codec/bitstream.go
generated
vendored
454
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/codec/bitstream.go
generated
vendored
@ -1,358 +1,358 @@
|
||||
package codec
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
var BitMask [8]byte = [8]byte{0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF}
|
||||
|
||||
type BitStream struct {
|
||||
bits []byte
|
||||
bytesOffset int
|
||||
bitsOffset int
|
||||
bitsmark int
|
||||
bytemark int
|
||||
bits []byte
|
||||
bytesOffset int
|
||||
bitsOffset int
|
||||
bitsmark int
|
||||
bytemark int
|
||||
}
|
||||
|
||||
func NewBitStream(buf []byte) *BitStream {
|
||||
return &BitStream{
|
||||
bits: buf,
|
||||
bytesOffset: 0,
|
||||
bitsOffset: 0,
|
||||
bitsmark: 0,
|
||||
bytemark: 0,
|
||||
}
|
||||
return &BitStream{
|
||||
bits: buf,
|
||||
bytesOffset: 0,
|
||||
bitsOffset: 0,
|
||||
bitsmark: 0,
|
||||
bytemark: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (bs *BitStream) Uint8(n int) uint8 {
|
||||
return uint8(bs.GetBits(n))
|
||||
return uint8(bs.GetBits(n))
|
||||
}
|
||||
|
||||
func (bs *BitStream) Uint16(n int) uint16 {
|
||||
return uint16(bs.GetBits(n))
|
||||
return uint16(bs.GetBits(n))
|
||||
}
|
||||
|
||||
func (bs *BitStream) Uint32(n int) uint32 {
|
||||
return uint32(bs.GetBits(n))
|
||||
return uint32(bs.GetBits(n))
|
||||
}
|
||||
|
||||
func (bs *BitStream) GetBytes(n int) []byte {
|
||||
if bs.bytesOffset+n > len(bs.bits) {
|
||||
panic("OUT OF RANGE")
|
||||
}
|
||||
if bs.bitsOffset != 0 {
|
||||
panic("invaild operation")
|
||||
}
|
||||
data := make([]byte, n)
|
||||
copy(data, bs.bits[bs.bytesOffset:bs.bytesOffset+n])
|
||||
bs.bytesOffset += n
|
||||
return data
|
||||
if bs.bytesOffset+n > len(bs.bits) {
|
||||
panic("OUT OF RANGE")
|
||||
}
|
||||
if bs.bitsOffset != 0 {
|
||||
panic("invaild operation")
|
||||
}
|
||||
data := make([]byte, n)
|
||||
copy(data, bs.bits[bs.bytesOffset:bs.bytesOffset+n])
|
||||
bs.bytesOffset += n
|
||||
return data
|
||||
}
|
||||
|
||||
//n <= 64
|
||||
func (bs *BitStream) GetBits(n int) uint64 {
|
||||
if bs.bytesOffset >= len(bs.bits) {
|
||||
panic("OUT OF RANGE")
|
||||
}
|
||||
var ret uint64 = 0
|
||||
if 8-bs.bitsOffset >= n {
|
||||
ret = uint64((bs.bits[bs.bytesOffset] >> (8 - bs.bitsOffset - n)) & BitMask[n-1])
|
||||
bs.bitsOffset += n
|
||||
if bs.bitsOffset == 8 {
|
||||
bs.bytesOffset++
|
||||
bs.bitsOffset = 0
|
||||
}
|
||||
} else {
|
||||
ret = uint64(bs.bits[bs.bytesOffset] & BitMask[8-bs.bitsOffset-1])
|
||||
bs.bytesOffset++
|
||||
n -= 8 - bs.bitsOffset
|
||||
bs.bitsOffset = 0
|
||||
for n > 0 {
|
||||
if bs.bytesOffset >= len(bs.bits) {
|
||||
panic("OUT OF RANGE")
|
||||
}
|
||||
if n >= 8 {
|
||||
ret = ret<<8 | uint64(bs.bits[bs.bytesOffset])
|
||||
bs.bytesOffset++
|
||||
n -= 8
|
||||
} else {
|
||||
ret = (ret << n) | uint64((bs.bits[bs.bytesOffset]>>(8-n))&BitMask[n-1])
|
||||
bs.bitsOffset = n
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret
|
||||
if bs.bytesOffset >= len(bs.bits) {
|
||||
panic("OUT OF RANGE")
|
||||
}
|
||||
var ret uint64 = 0
|
||||
if 8-bs.bitsOffset >= n {
|
||||
ret = uint64((bs.bits[bs.bytesOffset] >> (8 - bs.bitsOffset - n)) & BitMask[n-1])
|
||||
bs.bitsOffset += n
|
||||
if bs.bitsOffset == 8 {
|
||||
bs.bytesOffset++
|
||||
bs.bitsOffset = 0
|
||||
}
|
||||
} else {
|
||||
ret = uint64(bs.bits[bs.bytesOffset] & BitMask[8-bs.bitsOffset-1])
|
||||
bs.bytesOffset++
|
||||
n -= 8 - bs.bitsOffset
|
||||
bs.bitsOffset = 0
|
||||
for n > 0 {
|
||||
if bs.bytesOffset >= len(bs.bits) {
|
||||
panic("OUT OF RANGE")
|
||||
}
|
||||
if n >= 8 {
|
||||
ret = ret<<8 | uint64(bs.bits[bs.bytesOffset])
|
||||
bs.bytesOffset++
|
||||
n -= 8
|
||||
} else {
|
||||
ret = (ret << n) | uint64((bs.bits[bs.bytesOffset]>>(8-n))&BitMask[n-1])
|
||||
bs.bitsOffset = n
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (bs *BitStream) GetBit() uint8 {
|
||||
if bs.bytesOffset >= len(bs.bits) {
|
||||
panic("OUT OF RANGE")
|
||||
}
|
||||
ret := bs.bits[bs.bytesOffset] >> (7 - bs.bitsOffset) & 0x01
|
||||
bs.bitsOffset++
|
||||
if bs.bitsOffset >= 8 {
|
||||
bs.bytesOffset++
|
||||
bs.bitsOffset = 0
|
||||
}
|
||||
return ret
|
||||
if bs.bytesOffset >= len(bs.bits) {
|
||||
panic("OUT OF RANGE")
|
||||
}
|
||||
ret := bs.bits[bs.bytesOffset] >> (7 - bs.bitsOffset) & 0x01
|
||||
bs.bitsOffset++
|
||||
if bs.bitsOffset >= 8 {
|
||||
bs.bytesOffset++
|
||||
bs.bitsOffset = 0
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (bs *BitStream) SkipBits(n int) {
|
||||
bytecount := n / 8
|
||||
bitscount := n % 8
|
||||
bs.bytesOffset += bytecount
|
||||
if bs.bitsOffset+bitscount < 8 {
|
||||
bs.bitsOffset += bitscount
|
||||
} else {
|
||||
bs.bytesOffset += 1
|
||||
bs.bitsOffset += bitscount - 8
|
||||
}
|
||||
bytecount := n / 8
|
||||
bitscount := n % 8
|
||||
bs.bytesOffset += bytecount
|
||||
if bs.bitsOffset+bitscount < 8 {
|
||||
bs.bitsOffset += bitscount
|
||||
} else {
|
||||
bs.bytesOffset += 1
|
||||
bs.bitsOffset += bitscount - 8
|
||||
}
|
||||
}
|
||||
|
||||
func (bs *BitStream) Markdot() {
|
||||
bs.bitsmark = bs.bitsOffset
|
||||
bs.bytemark = bs.bytesOffset
|
||||
bs.bitsmark = bs.bitsOffset
|
||||
bs.bytemark = bs.bytesOffset
|
||||
}
|
||||
|
||||
func (bs *BitStream) DistanceFromMarkDot() int {
|
||||
bytecount := bs.bytesOffset - bs.bytemark - 1
|
||||
bitscount := bs.bitsOffset + (8 - bs.bitsmark)
|
||||
return bytecount*8 + bitscount
|
||||
bytecount := bs.bytesOffset - bs.bytemark - 1
|
||||
bitscount := bs.bitsOffset + (8 - bs.bitsmark)
|
||||
return bytecount*8 + bitscount
|
||||
}
|
||||
|
||||
func (bs *BitStream) RemainBytes() int {
|
||||
if bs.bitsOffset > 0 {
|
||||
return len(bs.bits) - bs.bytesOffset - 1
|
||||
} else {
|
||||
return len(bs.bits) - bs.bytesOffset
|
||||
}
|
||||
if bs.bitsOffset > 0 {
|
||||
return len(bs.bits) - bs.bytesOffset - 1
|
||||
} else {
|
||||
return len(bs.bits) - bs.bytesOffset
|
||||
}
|
||||
}
|
||||
|
||||
func (bs *BitStream) RemainBits() int {
|
||||
if bs.bitsOffset > 0 {
|
||||
return bs.RemainBytes()*8 + 8 - bs.bitsOffset
|
||||
} else {
|
||||
return bs.RemainBytes() * 8
|
||||
}
|
||||
if bs.bitsOffset > 0 {
|
||||
return bs.RemainBytes()*8 + 8 - bs.bitsOffset
|
||||
} else {
|
||||
return bs.RemainBytes() * 8
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (bs *BitStream) Bits() []byte {
|
||||
return bs.bits
|
||||
return bs.bits
|
||||
}
|
||||
|
||||
func (bs *BitStream) RemainData() []byte {
|
||||
return bs.bits[bs.bytesOffset:]
|
||||
return bs.bits[bs.bytesOffset:]
|
||||
}
|
||||
|
||||
//无符号哥伦布熵编码
|
||||
func (bs *BitStream) ReadUE() uint64 {
|
||||
leadingZeroBits := 0
|
||||
for bs.GetBit() == 0 {
|
||||
leadingZeroBits++
|
||||
}
|
||||
if leadingZeroBits == 0 {
|
||||
return 0
|
||||
}
|
||||
info := bs.GetBits(leadingZeroBits)
|
||||
return uint64(1)<<leadingZeroBits - 1 + info
|
||||
leadingZeroBits := 0
|
||||
for bs.GetBit() == 0 {
|
||||
leadingZeroBits++
|
||||
}
|
||||
if leadingZeroBits == 0 {
|
||||
return 0
|
||||
}
|
||||
info := bs.GetBits(leadingZeroBits)
|
||||
return uint64(1)<<leadingZeroBits - 1 + info
|
||||
}
|
||||
|
||||
//有符号哥伦布熵编码
|
||||
func (bs *BitStream) ReadSE() int64 {
|
||||
v := bs.ReadUE()
|
||||
if v%2 == 0 {
|
||||
return -1 * int64(v/2)
|
||||
} else {
|
||||
return int64(v+1) / 2
|
||||
}
|
||||
v := bs.ReadUE()
|
||||
if v%2 == 0 {
|
||||
return -1 * int64(v/2)
|
||||
} else {
|
||||
return int64(v+1) / 2
|
||||
}
|
||||
}
|
||||
|
||||
func (bs *BitStream) ByteOffset() int {
|
||||
return bs.bytesOffset
|
||||
return bs.bytesOffset
|
||||
}
|
||||
|
||||
func (bs *BitStream) UnRead(n int) {
|
||||
if n-bs.bitsOffset <= 0 {
|
||||
bs.bitsOffset -= n
|
||||
} else {
|
||||
least := n - bs.bitsOffset
|
||||
for least >= 8 {
|
||||
bs.bytesOffset--
|
||||
least -= 8
|
||||
}
|
||||
if least > 0 {
|
||||
bs.bytesOffset--
|
||||
bs.bitsOffset = 8 - least
|
||||
}
|
||||
}
|
||||
if n-bs.bitsOffset <= 0 {
|
||||
bs.bitsOffset -= n
|
||||
} else {
|
||||
least := n - bs.bitsOffset
|
||||
for least >= 8 {
|
||||
bs.bytesOffset--
|
||||
least -= 8
|
||||
}
|
||||
if least > 0 {
|
||||
bs.bytesOffset--
|
||||
bs.bitsOffset = 8 - least
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (bs *BitStream) NextBits(n int) uint64 {
|
||||
r := bs.GetBits(n)
|
||||
bs.UnRead(n)
|
||||
return r
|
||||
r := bs.GetBits(n)
|
||||
bs.UnRead(n)
|
||||
return r
|
||||
}
|
||||
|
||||
func (bs *BitStream) EOS() bool {
|
||||
return bs.bytesOffset == len(bs.bits) && bs.bitsOffset == 0
|
||||
return bs.bytesOffset == len(bs.bits) && bs.bitsOffset == 0
|
||||
}
|
||||
|
||||
type BitStreamWriter struct {
|
||||
bits []byte
|
||||
byteoffset int
|
||||
bitsoffset int
|
||||
bitsmark int
|
||||
bytemark int
|
||||
bits []byte
|
||||
byteoffset int
|
||||
bitsoffset int
|
||||
bitsmark int
|
||||
bytemark int
|
||||
}
|
||||
|
||||
func NewBitStreamWriter(n int) *BitStreamWriter {
|
||||
return &BitStreamWriter{
|
||||
bits: make([]byte, n),
|
||||
byteoffset: 0,
|
||||
bitsoffset: 0,
|
||||
bitsmark: 0,
|
||||
bytemark: 0,
|
||||
}
|
||||
return &BitStreamWriter{
|
||||
bits: make([]byte, n),
|
||||
byteoffset: 0,
|
||||
bitsoffset: 0,
|
||||
bitsmark: 0,
|
||||
bytemark: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) expandSpace(n int) {
|
||||
if (len(bsw.bits)-bsw.byteoffset-1)*8+8-bsw.bitsoffset < n {
|
||||
newlen := 0
|
||||
if len(bsw.bits)*8 < n {
|
||||
newlen = len(bsw.bits) + n/8 + 1
|
||||
} else {
|
||||
newlen = len(bsw.bits) * 2
|
||||
}
|
||||
tmp := make([]byte, newlen)
|
||||
copy(tmp, bsw.bits)
|
||||
bsw.bits = tmp
|
||||
}
|
||||
if (len(bsw.bits)-bsw.byteoffset-1)*8+8-bsw.bitsoffset < n {
|
||||
newlen := 0
|
||||
if len(bsw.bits)*8 < n {
|
||||
newlen = len(bsw.bits) + n/8 + 1
|
||||
} else {
|
||||
newlen = len(bsw.bits) * 2
|
||||
}
|
||||
tmp := make([]byte, newlen)
|
||||
copy(tmp, bsw.bits)
|
||||
bsw.bits = tmp
|
||||
}
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) ByteOffset() int {
|
||||
return bsw.byteoffset
|
||||
return bsw.byteoffset
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) BitOffset() int {
|
||||
return bsw.bitsoffset
|
||||
return bsw.bitsoffset
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) Markdot() {
|
||||
bsw.bitsmark = bsw.bitsoffset
|
||||
bsw.bytemark = bsw.byteoffset
|
||||
bsw.bitsmark = bsw.bitsoffset
|
||||
bsw.bytemark = bsw.byteoffset
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) DistanceFromMarkDot() int {
|
||||
bytecount := bsw.byteoffset - bsw.bytemark - 1
|
||||
bitscount := bsw.bitsoffset + (8 - bsw.bitsmark)
|
||||
return bytecount*8 + bitscount
|
||||
bytecount := bsw.byteoffset - bsw.bytemark - 1
|
||||
bitscount := bsw.bitsoffset + (8 - bsw.bitsmark)
|
||||
return bytecount*8 + bitscount
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) PutByte(v byte) {
|
||||
bsw.expandSpace(8)
|
||||
if bsw.bitsoffset == 0 {
|
||||
bsw.bits[bsw.byteoffset] = v
|
||||
bsw.byteoffset++
|
||||
} else {
|
||||
bsw.bits[bsw.byteoffset] |= v >> byte(bsw.bitsoffset)
|
||||
bsw.byteoffset++
|
||||
bsw.bits[bsw.byteoffset] = v & BitMask[bsw.bitsoffset-1]
|
||||
}
|
||||
bsw.expandSpace(8)
|
||||
if bsw.bitsoffset == 0 {
|
||||
bsw.bits[bsw.byteoffset] = v
|
||||
bsw.byteoffset++
|
||||
} else {
|
||||
bsw.bits[bsw.byteoffset] |= v >> byte(bsw.bitsoffset)
|
||||
bsw.byteoffset++
|
||||
bsw.bits[bsw.byteoffset] = v & BitMask[bsw.bitsoffset-1]
|
||||
}
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) PutBytes(v []byte) {
|
||||
if bsw.bitsoffset != 0 {
|
||||
panic("bsw.bitsoffset > 0")
|
||||
}
|
||||
bsw.expandSpace(8 * len(v))
|
||||
copy(bsw.bits[bsw.byteoffset:], v)
|
||||
bsw.byteoffset += len(v)
|
||||
if bsw.bitsoffset != 0 {
|
||||
panic("bsw.bitsoffset > 0")
|
||||
}
|
||||
bsw.expandSpace(8 * len(v))
|
||||
copy(bsw.bits[bsw.byteoffset:], v)
|
||||
bsw.byteoffset += len(v)
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) PutRepetValue(v byte, n int) {
|
||||
if bsw.bitsoffset != 0 {
|
||||
panic("bsw.bitsoffset > 0")
|
||||
}
|
||||
bsw.expandSpace(8 * n)
|
||||
for i := 0; i < n; i++ {
|
||||
bsw.bits[bsw.byteoffset] = v
|
||||
bsw.byteoffset++
|
||||
}
|
||||
if bsw.bitsoffset != 0 {
|
||||
panic("bsw.bitsoffset > 0")
|
||||
}
|
||||
bsw.expandSpace(8 * n)
|
||||
for i := 0; i < n; i++ {
|
||||
bsw.bits[bsw.byteoffset] = v
|
||||
bsw.byteoffset++
|
||||
}
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) PutUint8(v uint8, n int) {
|
||||
bsw.PutUint64(uint64(v), n)
|
||||
bsw.PutUint64(uint64(v), n)
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) PutUint16(v uint16, n int) {
|
||||
bsw.PutUint64(uint64(v), n)
|
||||
bsw.PutUint64(uint64(v), n)
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) PutUint32(v uint32, n int) {
|
||||
bsw.PutUint64(uint64(v), n)
|
||||
bsw.PutUint64(uint64(v), n)
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) PutUint64(v uint64, n int) {
|
||||
bsw.expandSpace(n)
|
||||
if 8-bsw.bitsoffset >= n {
|
||||
bsw.bits[bsw.byteoffset] |= uint8(v) & BitMask[n-1] << (8 - bsw.bitsoffset - n)
|
||||
bsw.bitsoffset += n
|
||||
if bsw.bitsoffset == 8 {
|
||||
bsw.bitsoffset = 0
|
||||
bsw.byteoffset++
|
||||
}
|
||||
} else {
|
||||
bsw.bits[bsw.byteoffset] |= uint8(v>>(n-int(8-bsw.bitsoffset))) & BitMask[8-bsw.bitsoffset-1]
|
||||
bsw.byteoffset++
|
||||
n -= 8 - bsw.bitsoffset
|
||||
for n-8 >= 0 {
|
||||
bsw.bits[bsw.byteoffset] = uint8(v>>(n-8)) & 0xFF
|
||||
bsw.byteoffset++
|
||||
n -= 8
|
||||
}
|
||||
bsw.bitsoffset = n
|
||||
if n > 0 {
|
||||
bsw.bits[bsw.byteoffset] |= (uint8(v) & BitMask[n-1]) << (8 - n)
|
||||
}
|
||||
}
|
||||
bsw.expandSpace(n)
|
||||
if 8-bsw.bitsoffset >= n {
|
||||
bsw.bits[bsw.byteoffset] |= uint8(v) & BitMask[n-1] << (8 - bsw.bitsoffset - n)
|
||||
bsw.bitsoffset += n
|
||||
if bsw.bitsoffset == 8 {
|
||||
bsw.bitsoffset = 0
|
||||
bsw.byteoffset++
|
||||
}
|
||||
} else {
|
||||
bsw.bits[bsw.byteoffset] |= uint8(v>>(n-int(8-bsw.bitsoffset))) & BitMask[8-bsw.bitsoffset-1]
|
||||
bsw.byteoffset++
|
||||
n -= 8 - bsw.bitsoffset
|
||||
for n-8 >= 0 {
|
||||
bsw.bits[bsw.byteoffset] = uint8(v>>(n-8)) & 0xFF
|
||||
bsw.byteoffset++
|
||||
n -= 8
|
||||
}
|
||||
bsw.bitsoffset = n
|
||||
if n > 0 {
|
||||
bsw.bits[bsw.byteoffset] |= (uint8(v) & BitMask[n-1]) << (8 - n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) SetByte(v byte, where int) {
|
||||
bsw.bits[where] = v
|
||||
bsw.bits[where] = v
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) SetUint16(v uint16, where int) {
|
||||
binary.BigEndian.PutUint16(bsw.bits[where:where+2], v)
|
||||
binary.BigEndian.PutUint16(bsw.bits[where:where+2], v)
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) Bits() []byte {
|
||||
if bsw.byteoffset == len(bsw.bits) {
|
||||
return bsw.bits
|
||||
}
|
||||
if bsw.bitsoffset > 0 {
|
||||
return bsw.bits[0 : bsw.byteoffset+1]
|
||||
} else {
|
||||
return bsw.bits[0:bsw.byteoffset]
|
||||
}
|
||||
if bsw.byteoffset == len(bsw.bits) {
|
||||
return bsw.bits
|
||||
}
|
||||
if bsw.bitsoffset > 0 {
|
||||
return bsw.bits[0 : bsw.byteoffset+1]
|
||||
} else {
|
||||
return bsw.bits[0:bsw.byteoffset]
|
||||
}
|
||||
}
|
||||
|
||||
//用v 填充剩余字节
|
||||
func (bsw *BitStreamWriter) FillRemainData(v byte) {
|
||||
for i := bsw.byteoffset; i < len(bsw.bits); i++ {
|
||||
bsw.bits[i] = v
|
||||
}
|
||||
bsw.byteoffset = len(bsw.bits)
|
||||
bsw.bitsoffset = 0
|
||||
for i := bsw.byteoffset; i < len(bsw.bits); i++ {
|
||||
bsw.bits[i] = v
|
||||
}
|
||||
bsw.byteoffset = len(bsw.bits)
|
||||
bsw.bitsoffset = 0
|
||||
}
|
||||
|
||||
func (bsw *BitStreamWriter) Reset() {
|
||||
for i := 0; i < len(bsw.bits); i++ {
|
||||
bsw.bits[i] = 0
|
||||
}
|
||||
bsw.bitsmark = 0
|
||||
bsw.bytemark = 0
|
||||
bsw.bitsoffset = 0
|
||||
bsw.byteoffset = 0
|
||||
for i := 0; i < len(bsw.bits); i++ {
|
||||
bsw.bits[i] = 0
|
||||
}
|
||||
bsw.bitsmark = 0
|
||||
bsw.bytemark = 0
|
||||
bsw.bitsoffset = 0
|
||||
bsw.byteoffset = 0
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
596
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/mpeg2/pes-proto.go
generated
vendored
596
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/mpeg2/pes-proto.go
generated
vendored
482
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/mpeg2/ps-demuxer.go
generated
vendored
482
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/mpeg2/ps-demuxer.go
generated
vendored
264
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/mpeg2/ps-muxer.go
generated
vendored
264
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/mpeg2/ps-muxer.go
generated
vendored
678
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/mpeg2/ps-proto.go
generated
vendored
678
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/mpeg2/ps-proto.go
generated
vendored
356
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/mpeg2/ts-demuxer.go
generated
vendored
356
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/mpeg2/ts-demuxer.go
generated
vendored
@ -1,218 +1,218 @@
|
||||
package mpeg2
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"github.com/yapingcat/gomedia/codec"
|
||||
"github.com/yapingcat/gomedia/codec"
|
||||
)
|
||||
|
||||
type pakcet_t struct {
|
||||
payload []byte
|
||||
pts uint64
|
||||
dts uint64
|
||||
payload []byte
|
||||
pts uint64
|
||||
dts uint64
|
||||
}
|
||||
|
||||
func newPacket_t(size uint32) *pakcet_t {
|
||||
return &pakcet_t{
|
||||
payload: make([]byte, 0, size),
|
||||
pts: 0,
|
||||
dts: 0,
|
||||
}
|
||||
return &pakcet_t{
|
||||
payload: make([]byte, 0, size),
|
||||
pts: 0,
|
||||
dts: 0,
|
||||
}
|
||||
}
|
||||
|
||||
type tsstream struct {
|
||||
cid TS_STREAM_TYPE
|
||||
pes_sid PES_STREMA_ID
|
||||
pes_pkg *PesPacket
|
||||
pkg *pakcet_t
|
||||
cid TS_STREAM_TYPE
|
||||
pes_sid PES_STREMA_ID
|
||||
pes_pkg *PesPacket
|
||||
pkg *pakcet_t
|
||||
}
|
||||
|
||||
type tsprogram struct {
|
||||
pn uint16
|
||||
streams map[uint16]*tsstream
|
||||
pn uint16
|
||||
streams map[uint16]*tsstream
|
||||
}
|
||||
|
||||
type TSDemuxer struct {
|
||||
programs map[uint16]*tsprogram
|
||||
OnFrame func(cid TS_STREAM_TYPE, frame []byte, pts uint64, dts uint64)
|
||||
OnTSPacket func(pkg *TSPacket)
|
||||
programs map[uint16]*tsprogram
|
||||
OnFrame func(cid TS_STREAM_TYPE, frame []byte, pts uint64, dts uint64)
|
||||
OnTSPacket func(pkg *TSPacket)
|
||||
}
|
||||
|
||||
func NewTSDemuxer() *TSDemuxer {
|
||||
return &TSDemuxer{
|
||||
programs: make(map[uint16]*tsprogram),
|
||||
OnFrame: nil,
|
||||
OnTSPacket: nil,
|
||||
}
|
||||
return &TSDemuxer{
|
||||
programs: make(map[uint16]*tsprogram),
|
||||
OnFrame: nil,
|
||||
OnTSPacket: nil,
|
||||
}
|
||||
}
|
||||
|
||||
func (demuxer *TSDemuxer) Input(r io.Reader) error {
|
||||
buf := make([]byte, TS_PAKCET_SIZE)
|
||||
_, err := io.ReadFull(r, buf)
|
||||
if err != nil {
|
||||
return errNeedMore
|
||||
}
|
||||
for {
|
||||
bs := codec.NewBitStream(buf)
|
||||
var pkg TSPacket
|
||||
if err := pkg.DecodeHeader(bs); err != nil {
|
||||
return err
|
||||
}
|
||||
if pkg.PID == uint16(TS_PID_PAT) {
|
||||
if pkg.Payload_unit_start_indicator == 1 {
|
||||
bs.SkipBits(8)
|
||||
}
|
||||
pat := NewPat()
|
||||
if err := pat.Decode(bs); err != nil {
|
||||
return err
|
||||
}
|
||||
pkg.Payload = pat
|
||||
if pat.Table_id != uint8(TS_TID_PAS) {
|
||||
return errors.New("pat table id is wrong")
|
||||
}
|
||||
for _, pmt := range pat.Pmts {
|
||||
if pmt.Program_number != 0x0000 {
|
||||
if _, found := demuxer.programs[pmt.PID]; !found {
|
||||
demuxer.programs[pmt.PID] = &tsprogram{pn: 0, streams: make(map[uint16]*tsstream)}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for p, s := range demuxer.programs {
|
||||
if p == pkg.PID { // pmt table
|
||||
if pkg.Payload_unit_start_indicator == 1 {
|
||||
bs.SkipBits(8) //pointer filed
|
||||
}
|
||||
pmt := NewPmt()
|
||||
if err := pmt.Decode(bs); err != nil {
|
||||
return err
|
||||
}
|
||||
pkg.Payload = pmt
|
||||
s.pn = pmt.Program_number
|
||||
for _, ps := range pmt.Streams {
|
||||
if _, found := s.streams[ps.Elementary_PID]; !found {
|
||||
s.streams[ps.Elementary_PID] = &tsstream{
|
||||
cid: TS_STREAM_TYPE(ps.StreamType),
|
||||
pes_sid: findPESIDByStreamType(TS_STREAM_TYPE(ps.StreamType)),
|
||||
pes_pkg: NewPesPacket(),
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for sid, stream := range s.streams {
|
||||
if sid != pkg.PID {
|
||||
continue
|
||||
}
|
||||
if pkg.Payload_unit_start_indicator == 1 {
|
||||
err := stream.pes_pkg.Decode(bs)
|
||||
// ignore error if it was a short payload read, next ts packet should append missing data
|
||||
if err != nil && !(errors.Is(err, errNeedMore) && stream.pes_pkg.Pes_payload != nil) {
|
||||
return err
|
||||
}
|
||||
pkg.Payload = stream.pes_pkg
|
||||
} else {
|
||||
stream.pes_pkg.Pes_payload = bs.RemainData()
|
||||
pkg.Payload = bs.RemainData()
|
||||
}
|
||||
stype := findPESIDByStreamType(stream.cid)
|
||||
if stype == PES_STREAM_AUDIO {
|
||||
demuxer.doAudioPesPacket(stream, pkg.Payload_unit_start_indicator)
|
||||
} else if stype == PES_STREAM_VIDEO {
|
||||
demuxer.doVideoPesPacket(stream, pkg.Payload_unit_start_indicator)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if demuxer.OnTSPacket != nil {
|
||||
demuxer.OnTSPacket(&pkg)
|
||||
}
|
||||
_, err := io.ReadFull(r, buf)
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
} else {
|
||||
return errNeedMore
|
||||
}
|
||||
}
|
||||
}
|
||||
demuxer.flush()
|
||||
return nil
|
||||
buf := make([]byte, TS_PAKCET_SIZE)
|
||||
_, err := io.ReadFull(r, buf)
|
||||
if err != nil {
|
||||
return errNeedMore
|
||||
}
|
||||
for {
|
||||
bs := codec.NewBitStream(buf)
|
||||
var pkg TSPacket
|
||||
if err := pkg.DecodeHeader(bs); err != nil {
|
||||
return err
|
||||
}
|
||||
if pkg.PID == uint16(TS_PID_PAT) {
|
||||
if pkg.Payload_unit_start_indicator == 1 {
|
||||
bs.SkipBits(8)
|
||||
}
|
||||
pat := NewPat()
|
||||
if err := pat.Decode(bs); err != nil {
|
||||
return err
|
||||
}
|
||||
pkg.Payload = pat
|
||||
if pat.Table_id != uint8(TS_TID_PAS) {
|
||||
return errors.New("pat table id is wrong")
|
||||
}
|
||||
for _, pmt := range pat.Pmts {
|
||||
if pmt.Program_number != 0x0000 {
|
||||
if _, found := demuxer.programs[pmt.PID]; !found {
|
||||
demuxer.programs[pmt.PID] = &tsprogram{pn: 0, streams: make(map[uint16]*tsstream)}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for p, s := range demuxer.programs {
|
||||
if p == pkg.PID { // pmt table
|
||||
if pkg.Payload_unit_start_indicator == 1 {
|
||||
bs.SkipBits(8) //pointer filed
|
||||
}
|
||||
pmt := NewPmt()
|
||||
if err := pmt.Decode(bs); err != nil {
|
||||
return err
|
||||
}
|
||||
pkg.Payload = pmt
|
||||
s.pn = pmt.Program_number
|
||||
for _, ps := range pmt.Streams {
|
||||
if _, found := s.streams[ps.Elementary_PID]; !found {
|
||||
s.streams[ps.Elementary_PID] = &tsstream{
|
||||
cid: TS_STREAM_TYPE(ps.StreamType),
|
||||
pes_sid: findPESIDByStreamType(TS_STREAM_TYPE(ps.StreamType)),
|
||||
pes_pkg: NewPesPacket(),
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for sid, stream := range s.streams {
|
||||
if sid != pkg.PID {
|
||||
continue
|
||||
}
|
||||
if pkg.Payload_unit_start_indicator == 1 {
|
||||
err := stream.pes_pkg.Decode(bs)
|
||||
// ignore error if it was a short payload read, next ts packet should append missing data
|
||||
if err != nil && !(errors.Is(err, errNeedMore) && stream.pes_pkg.Pes_payload != nil) {
|
||||
return err
|
||||
}
|
||||
pkg.Payload = stream.pes_pkg
|
||||
} else {
|
||||
stream.pes_pkg.Pes_payload = bs.RemainData()
|
||||
pkg.Payload = bs.RemainData()
|
||||
}
|
||||
stype := findPESIDByStreamType(stream.cid)
|
||||
if stype == PES_STREAM_AUDIO {
|
||||
demuxer.doAudioPesPacket(stream, pkg.Payload_unit_start_indicator)
|
||||
} else if stype == PES_STREAM_VIDEO {
|
||||
demuxer.doVideoPesPacket(stream, pkg.Payload_unit_start_indicator)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if demuxer.OnTSPacket != nil {
|
||||
demuxer.OnTSPacket(&pkg)
|
||||
}
|
||||
_, err := io.ReadFull(r, buf)
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
} else {
|
||||
return errNeedMore
|
||||
}
|
||||
}
|
||||
}
|
||||
demuxer.flush()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (demuxer *TSDemuxer) flush() {
|
||||
for _, pm := range demuxer.programs {
|
||||
for _, stream := range pm.streams {
|
||||
if stream.pkg == nil || len(stream.pkg.payload) == 0 {
|
||||
continue
|
||||
}
|
||||
if demuxer.OnFrame != nil {
|
||||
demuxer.OnFrame(stream.cid, stream.pkg.payload, stream.pkg.pts/90, stream.pkg.dts/90)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, pm := range demuxer.programs {
|
||||
for _, stream := range pm.streams {
|
||||
if stream.pkg == nil || len(stream.pkg.payload) == 0 {
|
||||
continue
|
||||
}
|
||||
if demuxer.OnFrame != nil {
|
||||
demuxer.OnFrame(stream.cid, stream.pkg.payload, stream.pkg.pts/90, stream.pkg.dts/90)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (demuxer *TSDemuxer) doVideoPesPacket(stream *tsstream, start uint8) {
|
||||
if stream.cid != TS_STREAM_H264 && stream.cid != TS_STREAM_H265 {
|
||||
return
|
||||
}
|
||||
if stream.pkg == nil {
|
||||
stream.pkg = newPacket_t(1024)
|
||||
stream.pkg.pts = stream.pes_pkg.Pts
|
||||
stream.pkg.dts = stream.pes_pkg.Dts
|
||||
}
|
||||
stream.pkg.payload = append(stream.pkg.payload, stream.pes_pkg.Pes_payload...)
|
||||
demuxer.splitH26XFrame(stream)
|
||||
stream.pkg.pts = stream.pes_pkg.Pts
|
||||
stream.pkg.dts = stream.pes_pkg.Dts
|
||||
if stream.cid != TS_STREAM_H264 && stream.cid != TS_STREAM_H265 {
|
||||
return
|
||||
}
|
||||
if stream.pkg == nil {
|
||||
stream.pkg = newPacket_t(1024)
|
||||
stream.pkg.pts = stream.pes_pkg.Pts
|
||||
stream.pkg.dts = stream.pes_pkg.Dts
|
||||
}
|
||||
stream.pkg.payload = append(stream.pkg.payload, stream.pes_pkg.Pes_payload...)
|
||||
demuxer.splitH26XFrame(stream)
|
||||
stream.pkg.pts = stream.pes_pkg.Pts
|
||||
stream.pkg.dts = stream.pes_pkg.Dts
|
||||
}
|
||||
|
||||
func (demuxer *TSDemuxer) doAudioPesPacket(stream *tsstream, start uint8) {
|
||||
if stream.cid != TS_STREAM_AAC {
|
||||
return
|
||||
}
|
||||
if stream.cid != TS_STREAM_AAC {
|
||||
return
|
||||
}
|
||||
|
||||
if stream.pkg == nil {
|
||||
stream.pkg = newPacket_t(1024)
|
||||
stream.pkg.pts = stream.pes_pkg.Pts
|
||||
stream.pkg.dts = stream.pes_pkg.Dts
|
||||
}
|
||||
if stream.pkg == nil {
|
||||
stream.pkg = newPacket_t(1024)
|
||||
stream.pkg.pts = stream.pes_pkg.Pts
|
||||
stream.pkg.dts = stream.pes_pkg.Dts
|
||||
}
|
||||
|
||||
if len(stream.pkg.payload) > 0 && (start == 1 || stream.pes_pkg.Pts != stream.pkg.pts) {
|
||||
if demuxer.OnFrame != nil {
|
||||
demuxer.OnFrame(stream.cid, stream.pkg.payload, stream.pkg.pts/90, stream.pkg.dts/90)
|
||||
}
|
||||
stream.pkg.payload = stream.pkg.payload[:0]
|
||||
}
|
||||
stream.pkg.payload = append(stream.pkg.payload, stream.pes_pkg.Pes_payload...)
|
||||
stream.pkg.pts = stream.pes_pkg.Pts
|
||||
stream.pkg.dts = stream.pes_pkg.Dts
|
||||
if len(stream.pkg.payload) > 0 && (start == 1 || stream.pes_pkg.Pts != stream.pkg.pts) {
|
||||
if demuxer.OnFrame != nil {
|
||||
demuxer.OnFrame(stream.cid, stream.pkg.payload, stream.pkg.pts/90, stream.pkg.dts/90)
|
||||
}
|
||||
stream.pkg.payload = stream.pkg.payload[:0]
|
||||
}
|
||||
stream.pkg.payload = append(stream.pkg.payload, stream.pes_pkg.Pes_payload...)
|
||||
stream.pkg.pts = stream.pes_pkg.Pts
|
||||
stream.pkg.dts = stream.pes_pkg.Dts
|
||||
}
|
||||
|
||||
func (demuxer *TSDemuxer) splitH26XFrame(stream *tsstream) {
|
||||
data := stream.pkg.payload
|
||||
start, _ := codec.FindStartCode(data, 0)
|
||||
datalen := len(data)
|
||||
for start < datalen {
|
||||
end, _ := codec.FindStartCode(data, start+3)
|
||||
if end < 0 {
|
||||
break
|
||||
}
|
||||
if (stream.cid == TS_STREAM_H264 && codec.H264NaluTypeWithoutStartCode(data[start:end]) == codec.H264_NAL_AUD) ||
|
||||
(stream.cid == TS_STREAM_H265 && codec.H265NaluTypeWithoutStartCode(data[start:end]) == codec.H265_NAL_AUD) {
|
||||
start = end
|
||||
continue
|
||||
}
|
||||
if demuxer.OnFrame != nil {
|
||||
demuxer.OnFrame(stream.cid, data[start:end], stream.pkg.pts/90, stream.pkg.dts/90)
|
||||
}
|
||||
start = end
|
||||
}
|
||||
if start == 0 {
|
||||
return
|
||||
}
|
||||
copy(stream.pkg.payload, data[start:datalen])
|
||||
stream.pkg.payload = stream.pkg.payload[0 : datalen-start]
|
||||
data := stream.pkg.payload
|
||||
start, _ := codec.FindStartCode(data, 0)
|
||||
datalen := len(data)
|
||||
for start < datalen {
|
||||
end, _ := codec.FindStartCode(data, start+3)
|
||||
if end < 0 {
|
||||
break
|
||||
}
|
||||
if (stream.cid == TS_STREAM_H264 && codec.H264NaluTypeWithoutStartCode(data[start:end]) == codec.H264_NAL_AUD) ||
|
||||
(stream.cid == TS_STREAM_H265 && codec.H265NaluTypeWithoutStartCode(data[start:end]) == codec.H265_NAL_AUD) {
|
||||
start = end
|
||||
continue
|
||||
}
|
||||
if demuxer.OnFrame != nil {
|
||||
demuxer.OnFrame(stream.cid, data[start:end], stream.pkg.pts/90, stream.pkg.dts/90)
|
||||
}
|
||||
start = end
|
||||
}
|
||||
if start == 0 {
|
||||
return
|
||||
}
|
||||
copy(stream.pkg.payload, data[start:datalen])
|
||||
stream.pkg.payload = stream.pkg.payload[0 : datalen-start]
|
||||
}
|
||||
|
548
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/mpeg2/ts-muxer.go
generated
vendored
548
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/mpeg2/ts-muxer.go
generated
vendored
866
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/mpeg2/ts-proto.go
generated
vendored
866
trunk/3rdparty/srs-bench/vendor/github.com/yapingcat/gomedia/mpeg2/ts-proto.go
generated
vendored
@ -1,12 +1,21 @@
|
||||
FROM ossrs/srs:dev-gcc7-cache
|
||||
FROM ossrs/srs:ubuntu20-cache
|
||||
|
||||
# Install depends tools.
|
||||
RUN yum install -y gcc make gcc-c++ patch unzip perl git
|
||||
ARG MAKEARGS
|
||||
RUN echo "MAKEARGS: ${MAKEARGS}"
|
||||
|
||||
# https://serverfault.com/questions/949991/how-to-install-tzdata-on-a-ubuntu-docker-image
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
|
||||
# For go to build and run utest.
|
||||
ENV PATH $PATH:/usr/local/go/bin
|
||||
|
||||
RUN apt update -y && apt install -y gcc make g++ patch unzip perl git libasan5
|
||||
|
||||
# Build and install SRS.
|
||||
COPY . /srs
|
||||
WORKDIR /srs/trunk
|
||||
|
||||
# Note that we must enable the gcc7 or link failed.
|
||||
RUN scl enable devtoolset-7 -- ./configure --srt=on --gb28181=on --apm=on --h265=on --utest=on --gcov=on --sanitizer=off
|
||||
RUN scl enable devtoolset-7 -- make utest
|
||||
RUN ./configure --srt=on --gb28181=on --apm=on --h265=on --utest=on --gcov=on --sanitizer=off
|
||||
RUN make utest ${MAKEARGS}
|
||||
|
||||
|
Loading…
Reference in New Issue