add WalkNALUsAVCC() modify SplitNALUs return params order

This commit is contained in:
nareix 2016-04-19 11:40:23 +08:00
parent c22c2411f1
commit fbc251923c
2 changed files with 17 additions and 6 deletions

View File

@ -195,9 +195,18 @@ func WalkNALUsAnnexb(nalus [][]byte, write func([]byte)) {
return
}
func SplitNALUs(b []byte) (ok bool, nalus [][]byte) {
func WalkNALUsAVCC(nalus [][]byte, write func([]byte)) {
for _, nalu := range(nalus) {
var b [4]byte
bits.PutUIntBE(b[:], uint(len(nalu)), 32)
write(b[:])
write(nalu)
}
}
func SplitNALUs(b []byte) (nalus [][]byte, ok bool) {
if len(b) < 4 {
return
return [][]byte{b}, false
}
val3 := bits.GetUIntBE(b, 24)
@ -262,10 +271,12 @@ func SplitNALUs(b []byte) (ok bool, nalus [][]byte) {
}
if len(b) == 0 {
ok = true
return
} else {
return [][]byte{b}, false
}
return
}
return
return [][]byte{b}, false
}

View File

@ -11,13 +11,13 @@ func TestParser(t *testing.T) {
var nalus [][]byte
annexbFrame, _ := hex.DecodeString("000001223322330000000122332233223300000133000001000001")
ok, nalus = SplitNALUs(annexbFrame)
nalus, ok = SplitNALUs(annexbFrame)
t.Log(ok, len(nalus))
avccFrame, _ := hex.DecodeString(
"00000008aabbccaabbccaabb00000001aa",
)
ok, nalus = SplitNALUs(avccFrame)
nalus, ok = SplitNALUs(avccFrame)
t.Log(ok, len(nalus))
}