-
Notifications
You must be signed in to change notification settings - Fork 119
/
util.go
72 lines (60 loc) · 994 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package mediaserver
import (
"errors"
)
const ssrcMin uint = 1000000000
const ssrcMax uint = 4294967295
var ssrcValue = ssrcMin
func Min(x, y int) int {
if x < y {
return x
}
return y
}
func Max(x, y int) int {
if x < y {
return y
}
return x
}
func NextSSRC() uint {
if ssrcValue == ssrcMax {
ssrcValue = ssrcMin
}
ssrcValue = ssrcValue + 1
return ssrcValue
}
func u32be(b []byte) (i uint32) {
i = uint32(b[0])
i <<= 8
i |= uint32(b[1])
i <<= 8
i |= uint32(b[2])
i <<= 8
i |= uint32(b[3])
return
}
var nalu_prefix = []byte{0, 0, 0, 1}
func annexbConvert(avc []byte) ([]byte, error) {
if len(avc) < 4 {
return nil, errors.New("too short")
}
val4 := u32be(avc)
_val4 := val4
_b := avc[4:]
annexb := []byte{}
for {
annexb = append(annexb, nalu_prefix...)
annexb = append(annexb, _b[:_val4]...)
_b = _b[_val4:]
if len(_b) < 4 {
break
}
_val4 = u32be(_b)
_b = _b[4:]
if _val4 > uint32(len(_b)) {
break
}
}
return annexb, nil
}